[LinkerWrapper] Fix passing `-rpath` directly to clang
authorJoseph Huber <jhuber6@vols.utk.edu>
Wed, 1 Feb 2023 18:01:44 +0000 (12:01 -0600)
committerJoseph Huber <jhuber6@vols.utk.edu>
Wed, 1 Feb 2023 18:03:03 +0000 (12:03 -0600)
Summary:
This code passed the value of `-rpath` directly to the clang invocation.
If we're using the linker then it'll be fine. However, if the linker is
`gcc` as is the case when doing `-fopenmp-targets=x86_64` then this will
cause problems.  This patch adds the `-Wl,-rpath,` to feed it to the
linker correctly.

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

index 6981e12..2980044 100644 (file)
@@ -396,9 +396,11 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args) {
     CmdArgs.push_back("-Wl,-Bsymbolic");
     CmdArgs.push_back("-shared");
     ArgStringList LinkerArgs;
-    for (const opt::Arg *Arg :
-         Args.filtered(OPT_library, OPT_rpath, OPT_library_path))
+    for (const opt::Arg *Arg : Args.filtered(OPT_library, OPT_library_path))
       Arg->render(Args, LinkerArgs);
+    for (const opt::Arg *Arg : Args.filtered(OPT_rpath))
+      LinkerArgs.push_back(
+          Args.MakeArgString("-Wl,-rpath," + StringRef(Arg->getValue())));
     llvm::copy(LinkerArgs, std::back_inserter(CmdArgs));
   }