[llvm-branch-commits] [clang] [RISCV][Driver] Add riscv emulation mode to linker job of BareMetal toolchain (PR #134442)

Petr Hosek via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Apr 24 01:01:36 PDT 2025


================
@@ -534,8 +534,18 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA,
 
   CmdArgs.push_back("-Bstatic");
 
-  if (TC.getTriple().isRISCV() && Args.hasArg(options::OPT_mno_relax))
-    CmdArgs.push_back("--no-relax");
+  if (Triple.isRISCV()) {
+    CmdArgs.push_back("-X");
+    if (Args.hasArg(options::OPT_mno_relax))
+      CmdArgs.push_back("--no-relax");
+    if (const char *LDMOption = getLDMOption(TC.getTriple(), Args)) {
+      CmdArgs.push_back("-m");
+      CmdArgs.push_back(LDMOption);
+    } else {
+      D.Diag(diag::err_target_unknown_triple) << Triple.str();
+      return;
+    }
----------------
petrhosek wrote:

Can you also swap the order of the `-m` option to be the same as in the `Gnu` driver? 
```suggestion
    if (const char *LDMOption = getLDMOption(TC.getTriple(), Args)) {
      CmdArgs.push_back("-m");
      CmdArgs.push_back(LDMOption);
    } else {
      D.Diag(diag::err_target_unknown_triple) << Triple.str();
      return;
    }
    
    CmdArgs.push_back("-X");
    if (Args.hasArg(options::OPT_mno_relax))
      CmdArgs.push_back("--no-relax");
```
In a follow up change, I'd like to move the `-m` out of this condition since it'd be also beneficial for other targets.

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


More information about the llvm-branch-commits mailing list