llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-driver

Author: Kostiantyn Lazukin (Sunday111)

<details>
<summary>Changes</summary>

This patch improves support for embedded Linux toolchains with multiple 
sysroots, each containing different built-in libraries. If compiler-rt 
libraries are not found in the resource directory, the Clang driver will 
fallback to searching in the sysroot/lib directory.

This change preserves the standard behavior for regular Linux toolchains while 
allowing greater flexibility in toolchains with multiple sysroots.

---
Full diff: https://github.com/llvm/llvm-project/pull/132443.diff


9 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Linux.cpp (+2) 
- (added) clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/Scrt1.o () 
- (added) 
clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/clang_rt.crtbegin.o () 
- (added) 
clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/clang_rt.crtend.o () 
- (added) clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/crti.o () 
- (added) clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/crtn.o () 
- (added) 
clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/libclang_rt.builtins.a 
() 
- (added) clang/test/Driver/Inputs/resource_dir_empty/keep () 
- (added) clang/test/Driver/linux-musl-library-search.cpp (+14) 


``````````diff
diff --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index 1e9bd3de75f04..1bd8daafa8091 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -354,6 +354,8 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, 
const ArgList &Args)
 
   addPathIfExists(D, concat(SysRoot, "/lib"), Paths);
   addPathIfExists(D, concat(SysRoot, "/usr/lib"), Paths);
+
+  addPathIfExists(D, concat(SysRoot, "/lib"), getLibraryPaths());
 }
 
 ToolChain::RuntimeLibType Linux::GetDefaultRuntimeLibType() const {
diff --git a/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/Scrt1.o 
b/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/Scrt1.o
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git 
a/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/clang_rt.crtbegin.o 
b/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/clang_rt.crtbegin.o
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git 
a/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/clang_rt.crtend.o 
b/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/clang_rt.crtend.o
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/crti.o 
b/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/crti.o
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/crtn.o 
b/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/crtn.o
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git 
a/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/libclang_rt.builtins.a
 
b/clang/test/Driver/Inputs/musl_sysroot_with_builtins/lib/libclang_rt.builtins.a
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/Inputs/resource_dir_empty/keep 
b/clang/test/Driver/Inputs/resource_dir_empty/keep
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/linux-musl-library-search.cpp 
b/clang/test/Driver/linux-musl-library-search.cpp
new file mode 100644
index 0000000000000..a8125aef73ab1
--- /dev/null
+++ b/clang/test/Driver/linux-musl-library-search.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang -### %s 2>&1 \
+// RUN:     --target=aarch64-unknown-linux-musl \
+// RUN:     -ccc-install-dir %S/Inputs/basic_linux_tree/usr/bin \
+// RUN:     -resource-dir=%S/Inputs/resource_dir_empty \
+// RUN:     --sysroot=%S/Inputs/musl_sysroot_with_builtins \
+// RUN:   | FileCheck %s
+
+// CHECK-DAG: "--sysroot={{[^"]+}}/Inputs/musl_sysroot_with_builtins"
+// CHECK-DAG: "{{[^"]+}}/Inputs/musl_sysroot_with_builtins/lib/Scrt1.o"
+// CHECK-DAG: "{{[^"]+}}/Inputs/musl_sysroot_with_builtins/lib/crti.o"
+// CHECK-DAG: 
"{{[^"]+}}/Inputs/musl_sysroot_with_builtins/lib/clang_rt.crtbegin.o"
+// CHECK-DAG: 
"{{[^"]+}}/Inputs/musl_sysroot_with_builtins/lib/libclang_rt.builtins.a"
+// CHECK-DAG: 
"{{[^"]+}}/Inputs/musl_sysroot_with_builtins/lib/clang_rt.crtend.o"
+// CHECK-DAG: "{{[^"]+}}/Inputs/musl_sysroot_with_builtins/lib/crtn.o"

``````````

</details>


https://github.com/llvm/llvm-project/pull/132443
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to