-
Notifications
You must be signed in to change notification settings - Fork 11.3k
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
[Clang] Make '-frtlib-add-rpath' include the standard library directory #86217
Conversation
@llvm/pr-subscribers-clang-driver Author: Joseph Huber (jhuber6) ChangesSummary: Full diff: https://github.com/llvm/llvm-project/pull/86217.diff 2 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 4478865313636d..6b1fbba7abd031 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1142,7 +1142,11 @@ void tools::addArchSpecificRPath(const ToolChain &TC, const ArgList &Args,
options::OPT_fno_rtlib_add_rpath, false))
return;
- for (const auto &CandidateRPath : TC.getArchSpecificLibPaths()) {
+ SmallVector<std::string> CandidateRPaths(TC.getArchSpecificLibPaths());
+ if (const auto CandidateRPath = TC.getStdlibPath())
+ CandidateRPaths.emplace_back(*CandidateRPath);
+
+ for (const auto &CandidateRPath : CandidateRPaths) {
if (TC.getVFS().exists(CandidateRPath)) {
CmdArgs.push_back("-rpath");
CmdArgs.push_back(Args.MakeArgString(CandidateRPath));
diff --git a/clang/test/Driver/arch-specific-libdir-rpath.c b/clang/test/Driver/arch-specific-libdir-rpath.c
index 1e6bbbc5929ac2..e95fb21c0a5fb1 100644
--- a/clang/test/Driver/arch-specific-libdir-rpath.c
+++ b/clang/test/Driver/arch-specific-libdir-rpath.c
@@ -84,6 +84,15 @@
// RUN: -frtlib-add-rpath \
// RUN: | FileCheck --check-prefixes=PERTARGET %s
+// Test that the driver adds an per-target arch-specific subdirectory to the
+// stdlib path.
+//
+// RUN: %clang %s -### 2>&1 --target=x86_64-linux-gnu \
+// RUN: -fsanitize=address -shared-libasan \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -frtlib-add-rpath \
+// RUN: | FileCheck --check-prefixes=STDLIB %s
+
// RESDIR: "-resource-dir" "[[RESDIR:[^"]*]]"
//
// LIBPATH-X86_64: -L[[RESDIR]]{{(/|\\\\)lib(/|\\\\)linux(/|\\\\)x86_64}}
@@ -101,3 +110,7 @@
// PERTARGET: "-resource-dir" "[[PTRESDIR:[^"]*]]"
// PERTARGET: -L[[PTRESDIR]]{{(/|\\\\)lib(/|\\\\)x86_64-unknown-linux-gnu}}
// PERTARGET: "-rpath" "[[PTRESDIR]]{{(/|\\\\)lib(/|\\\\)x86_64-unknown-linux-gnu}}"
+
+// STDLIB: InstalledDir: [[LIBDIR:.+$]]
+// STDLIB: -L[[LIBDIR]]/..{{(/|\\\\)lib(/|\\\\)x86_64-unknown-linux-gnu}}
+// STDLIB: "-rpath" "[[LIBDIR]]/..{{(/|\\\\)lib(/|\\\\)x86_64-unknown-linux-gnu}}"
|
@llvm/pr-subscribers-clang Author: Joseph Huber (jhuber6) ChangesSummary: Full diff: https://github.com/llvm/llvm-project/pull/86217.diff 2 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 4478865313636d..6b1fbba7abd031 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1142,7 +1142,11 @@ void tools::addArchSpecificRPath(const ToolChain &TC, const ArgList &Args,
options::OPT_fno_rtlib_add_rpath, false))
return;
- for (const auto &CandidateRPath : TC.getArchSpecificLibPaths()) {
+ SmallVector<std::string> CandidateRPaths(TC.getArchSpecificLibPaths());
+ if (const auto CandidateRPath = TC.getStdlibPath())
+ CandidateRPaths.emplace_back(*CandidateRPath);
+
+ for (const auto &CandidateRPath : CandidateRPaths) {
if (TC.getVFS().exists(CandidateRPath)) {
CmdArgs.push_back("-rpath");
CmdArgs.push_back(Args.MakeArgString(CandidateRPath));
diff --git a/clang/test/Driver/arch-specific-libdir-rpath.c b/clang/test/Driver/arch-specific-libdir-rpath.c
index 1e6bbbc5929ac2..e95fb21c0a5fb1 100644
--- a/clang/test/Driver/arch-specific-libdir-rpath.c
+++ b/clang/test/Driver/arch-specific-libdir-rpath.c
@@ -84,6 +84,15 @@
// RUN: -frtlib-add-rpath \
// RUN: | FileCheck --check-prefixes=PERTARGET %s
+// Test that the driver adds an per-target arch-specific subdirectory to the
+// stdlib path.
+//
+// RUN: %clang %s -### 2>&1 --target=x86_64-linux-gnu \
+// RUN: -fsanitize=address -shared-libasan \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -frtlib-add-rpath \
+// RUN: | FileCheck --check-prefixes=STDLIB %s
+
// RESDIR: "-resource-dir" "[[RESDIR:[^"]*]]"
//
// LIBPATH-X86_64: -L[[RESDIR]]{{(/|\\\\)lib(/|\\\\)linux(/|\\\\)x86_64}}
@@ -101,3 +110,7 @@
// PERTARGET: "-resource-dir" "[[PTRESDIR:[^"]*]]"
// PERTARGET: -L[[PTRESDIR]]{{(/|\\\\)lib(/|\\\\)x86_64-unknown-linux-gnu}}
// PERTARGET: "-rpath" "[[PTRESDIR]]{{(/|\\\\)lib(/|\\\\)x86_64-unknown-linux-gnu}}"
+
+// STDLIB: InstalledDir: [[LIBDIR:.+$]]
+// STDLIB: -L[[LIBDIR]]/..{{(/|\\\\)lib(/|\\\\)x86_64-unknown-linux-gnu}}
+// STDLIB: "-rpath" "[[LIBDIR]]/..{{(/|\\\\)lib(/|\\\\)x86_64-unknown-linux-gnu}}"
|
Summary: The original intention of the `openmp-add-rpath` option was to add the rpath to the language runtime directory. However, the current implementation only adds it to the compiler's resource directory. This patch adds support for appending the `-rpath` to the compiler's standard library directory as well. Currently this is `<exe>/../lib/<triple>`.
…ry (llvm#86217) Summary: The original intention of the `openmp-add-rpath` option was to add the rpath to the language runtime directory. However, the current implementation only adds it to the compiler's resource directory. This patch adds support for appending the `-rpath` to the compiler's standard library directory as well. Currently this is `<exe>/../lib/<triple>`.
Summary:
The original intention of the
openmp-add-rpath
option was to add therpath to the language runtime directory. However, the current
implementation only adds it to the compiler's resource directory. This
patch adds support for appending the
-rpath
to the compiler's standardlibrary directory as well. Currently this is
<exe>/../lib/<triple>
.