[LinkerWrapper] Adjust placement of input files for the linker
authorJoseph Huber <jhuber6@vols.utk.edu>
Wed, 1 Feb 2023 19:48:27 +0000 (13:48 -0600)
committerJoseph Huber <jhuber6@vols.utk.edu>
Wed, 1 Feb 2023 19:49:17 +0000 (13:49 -0600)
Summary:
The placement of input files can change the result of the linker. We
should put the input files earlier to avoid this.

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

index 2980044..6ec089a 100644 (file)
@@ -391,6 +391,9 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args) {
       "-Wl,--no-undefined",
   };
 
+  for (StringRef InputFile : InputFiles)
+    CmdArgs.push_back(InputFile);
+
   // If this is CPU offloading we copy the input libraries.
   if (!Triple.isAMDGPU() && !Triple.isNVPTX()) {
     CmdArgs.push_back("-Wl,-Bsymbolic");
@@ -423,9 +426,6 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args) {
   for (StringRef Arg : Args.getAllArgValues(OPT_linker_arg_EQ))
     CmdArgs.push_back(Args.MakeArgString("-Wl," + Arg));
 
-  for (StringRef InputFile : InputFiles)
-    CmdArgs.push_back(InputFile);
-
   if (Error Err = executeCommands(*ClangPath, CmdArgs))
     return std::move(Err);