[clang] 27edaee - [RISCV][Driver] Make the ordering of CmdArgs consistent between RISCV::Linker and baremetal::Linker

ShihPo Hung via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 18 19:06:13 PDT 2021


Author: ShihPo Hung
Date: 2021-04-18T19:05:20-07:00
New Revision: 27edaee84e3ea4d160f742db0b4a04e236c4e26e

URL: https://github.com/llvm/llvm-project/commit/27edaee84e3ea4d160f742db0b4a04e236c4e26e
DIFF: https://github.com/llvm/llvm-project/commit/27edaee84e3ea4d160f742db0b4a04e236c4e26e.diff

LOG: [RISCV][Driver] Make the ordering of CmdArgs consistent between RISCV::Linker and baremetal::Linker

In baremetal::Linker::ConstructJob, LinkerInput is handled prior to T_Group options,
but on the other side in RISCV::Linker::ConstructJob, it is opposite.

We want it to be consistent whether users are using RISCV::Linker or baremetal::Linker.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D100615

Added: 
    clang/test/Driver/riscv-args.c

Modified: 
    clang/lib/Driver/ToolChains/RISCVToolchain.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
index 9a29cc0985fc9..0b8c52096933d 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -181,14 +181,14 @@ void RISCV::Linker::ConstructJob(Compilation &C, const JobAction &JA,
     CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin)));
   }
 
+  AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
+
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
   Args.AddAllArgs(CmdArgs,
                   {options::OPT_T_Group, options::OPT_e, options::OPT_s,
                    options::OPT_t, options::OPT_Z_Flag, options::OPT_r});
 
-  AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
-
   // TODO: add C++ includes and libs if compiling C++.
 
   if (!Args.hasArg(options::OPT_nostdlib) &&

diff  --git a/clang/test/Driver/riscv-args.c b/clang/test/Driver/riscv-args.c
new file mode 100644
index 0000000000000..7b68df977f7c3
--- /dev/null
+++ b/clang/test/Driver/riscv-args.c
@@ -0,0 +1,7 @@
+// Check the arguments are correctly passed
+
+// Make sure -T is the last with gcc-toolchain option
+// RUN: %clang -### -target riscv32 \
+// RUN:   --gcc-toolchain= -Xlinker --defsym=FOO=10 -T a.lds %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-LD %s
+// CHECK-LD: {{.*}} "--defsym=FOO=10" {{.*}} "-T" "a.lds"


        


More information about the cfe-commits mailing list