[clang] [Clang] Forward -rpath flag in the correct format in CPU offloading (PR #95763)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 17 03:37:11 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-driver

Author: None (mikaoP)

<details>
<summary>Changes</summary>

`clang-linker-wrapper` gets flags in linker format. In CPU offloading we need to format some of them as compiler flags, like it is already done with `--no-whole-archine`. This patch does the same with `-rpath`

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


3 Files Affected:

- (added) clang/test/Driver/Inputs/linker-wrapper/.keep () 
- (modified) clang/test/Driver/linker-wrapper.c (+1) 
- (modified) clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp (+2) 


``````````diff
diff --git a/clang/test/Driver/Inputs/linker-wrapper/.keep b/clang/test/Driver/Inputs/linker-wrapper/.keep
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/linker-wrapper.c b/clang/test/Driver/linker-wrapper.c
index 0d05f913aad63..9ed43343bf8d7 100644
--- a/clang/test/Driver/linker-wrapper.c
+++ b/clang/test/Driver/linker-wrapper.c
@@ -57,6 +57,7 @@ __attribute__((visibility("protected"), used)) int x;
 // RUN: llvm-ar rcs %t.a %t.o
 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
 // RUN:   --linker-path=/usr/bin/ld.lld --whole-archive %t.a --no-whole-archive \
+// RUN:   -rpath %S/Inputs/linker-wrapper
 // RUN:   %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=CPU-LINK
 
 // CPU-LINK: clang{{.*}} -o {{.*}}.img --target=x86_64-unknown-linux-gnu -march=native -O2 -Wl,--no-undefined {{.*}}.o {{.*}}.o -Wl,-Bsymbolic -shared -Wl,--whole-archive {{.*}}.a -Wl,--no-whole-archive
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 07a8d53c04b16..0023899513dd9 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -500,6 +500,8 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args) {
         LinkerArgs.push_back(Args.MakeArgString("-Wl,--whole-archive"));
       else if (Arg->getOption().matches(OPT_no_whole_archive))
         LinkerArgs.push_back(Args.MakeArgString("-Wl,--no-whole-archive"));
+      else if (Arg->getOption().matches(OPT_rpath))
+        LinkerArgs.push_back(Args.MakeArgString("-Wl,-rpath," + Twine(Arg->getValue())));
       else
         Arg->render(Args, LinkerArgs);
     }

``````````

</details>


https://github.com/llvm/llvm-project/pull/95763


More information about the cfe-commits mailing list