[llvm] 80cd610 - LoongArch: Respect the target-abi module flag in the ELF header (#226498)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 29 03:33:12 PDT 2026


Author: Matt Arsenault
Date: 2026-09-29T12:33:05+02:00
New Revision: 80cd6102a79c02763034fbf1b6a1473930b1d4ab

URL: https://github.com/llvm/llvm-project/commit/80cd6102a79c02763034fbf1b6a1473930b1d4ab
DIFF: https://github.com/llvm/llvm-project/commit/80cd6102a79c02763034fbf1b6a1473930b1d4ab.diff

LOG: LoongArch: Respect the target-abi module flag in the ELF header (#226498)

The target streamer read the ABI from MCTargetOptions when constructed,
so the e_flags recorded the command line -target-abi and ignored the
module flag.

Co-authored-by: Claude Opus 5 <noreply at anthropic.com>

Added: 
    llvm/test/CodeGen/LoongArch/module-target-abi.ll

Modified: 
    llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
    llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp b/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
index 52afb2a8af199..38ee358a4de6c 100644
--- a/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
@@ -21,6 +21,7 @@
 #include "llvm/CodeGen/AsmPrinter.h"
 #include "llvm/CodeGen/MachineJumpTableInfo.h"
 #include "llvm/CodeGen/MachineModuleInfoImpls.h"
+#include "llvm/IR/Module.h"
 #include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCInstBuilder.h"
@@ -47,6 +48,15 @@ LoongArchTargetStreamer &LoongArchAsmPrinter::getTargetStreamer() const {
       *OutStreamer->getTargetStreamer());
 }
 
+void LoongArchAsmPrinter::emitStartOfAsmFile(Module &M) {
+  StringRef ABIName = M.getTargetABIFromMD();
+  if (!ABIName.empty()) {
+    getTargetStreamer().setTargetABI(LoongArchABI::computeTargetABI(
+        TM.getTargetTriple(), TM.getMCSubtargetInfo().getFeatureBits(),
+        ABIName));
+  }
+}
+
 void LoongArchAsmPrinter::emitInstruction(const MachineInstr *MI) {
   LoongArch_MC::verifyInstructionPredicates(
       MI->getOpcode(), getSubtargetInfo().getFeatureBits());

diff  --git a/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h b/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
index bc8145386474d..09d8a36b86d9c 100644
--- a/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
+++ b/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
@@ -43,6 +43,8 @@ class LLVM_LIBRARY_VISIBILITY LoongArchAsmPrinter : public AsmPrinter {
 
   bool runOnMachineFunction(MachineFunction &MF) override;
 
+  void emitStartOfAsmFile(Module &M) override;
+
   void emitInstruction(const MachineInstr *MI) override;
 
   bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,

diff  --git a/llvm/test/CodeGen/LoongArch/module-target-abi.ll b/llvm/test/CodeGen/LoongArch/module-target-abi.ll
new file mode 100644
index 0000000000000..306ca8b650a23
--- /dev/null
+++ b/llvm/test/CodeGen/LoongArch/module-target-abi.ll
@@ -0,0 +1,13 @@
+; The "target-abi" module flag selects the ABI used for codegen, and must also
+; drive the ABI recorded in the ELF header e_flags.
+; RUN: llc --mtriple=loongarch64 --mattr=+d --filetype=obj < %s -o %t.o
+; RUN: llvm-readobj -h %t.o | FileCheck %s
+
+; CHECK: EF_LOONGARCH_ABI_SOFT_FLOAT
+
+define void @nothing() nounwind {
+  ret void
+}
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"target-abi", !"lp64s"}


        


More information about the llvm-commits mailing list