-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[Driver] Search for compiler-rt libraries in sysroot/lib if not found in the resource directory #132443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-driver Author: Kostiantyn Lazukin (Sunday111) ChangesThis 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:
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"
|
1ffc0c0 to
9a88ff0
Compare
… in the resource directory 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.
9a88ff0 to
da5c5c6
Compare
|
NAK. (LibraryPaths is primarily intended for compiler-rt libraries.) Maintaining compatibility by itself isn’t sufficient, as each entry could subtly shift library selection precedence, and the code here reflects a certain level of upstream (llvm-project) preference. We should ensure that the items listed align with typical Linux installations. I don’t think that finding compiler-rt libraries in $sysroot/lib warrants changes to the Linux toolchain code. Moreover, we discourage such file hierarchies. This change could be problematic for cross compilation. If your downstream setup demands this, consider installing symlinks. |
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.