[llvm] [AArch64] Relax binary format switch in AArch64MCInstLower::LowerSymbolOperand to allow non-Darwin Mach-O files (PR #66011)

Kuba Mracek via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 11 14:20:52 PDT 2023


https://github.com/kubamracek created https://github.com/llvm/llvm-project/pull/66011:

Trying to use a arm64-apple-none-macho target triple today crashes with an assertion, this patch fixes that.

>From f59444c5256c4721e8cf5911dc2cf8c040de480f Mon Sep 17 00:00:00 2001
From: Kuba Mracek <mracek at apple.com>
Date: Mon, 11 Sep 2023 14:09:57 -0700
Subject: [PATCH] [AArch64] Relax binary format switch in
 AArch64MCInstLower::LowerSymbolOperand to allow non-Darwin Mach-O files

---
 llvm/lib/Target/AArch64/AArch64MCInstLower.cpp | 8 ++++----
 llvm/lib/Target/AArch64/AArch64MCInstLower.h   | 4 ++--
 llvm/test/CodeGen/AArch64/macho-none.ll        | 9 +++++++++
 3 files changed, 15 insertions(+), 6 deletions(-)
 create mode 100644 llvm/test/CodeGen/AArch64/macho-none.ll

diff --git a/llvm/lib/Target/AArch64/AArch64MCInstLower.cpp b/llvm/lib/Target/AArch64/AArch64MCInstLower.cpp
index 69a66f4335c1cd2..59969f9dc31ce36 100644
--- a/llvm/lib/Target/AArch64/AArch64MCInstLower.cpp
+++ b/llvm/lib/Target/AArch64/AArch64MCInstLower.cpp
@@ -100,8 +100,8 @@ AArch64MCInstLower::GetExternalSymbolSymbol(const MachineOperand &MO) const {
   return Printer.GetExternalSymbolSymbol(MO.getSymbolName());
 }
 
-MCOperand AArch64MCInstLower::lowerSymbolOperandDarwin(const MachineOperand &MO,
-                                                       MCSymbol *Sym) const {
+MCOperand AArch64MCInstLower::lowerSymbolOperandMachO(const MachineOperand &MO,
+                                                      MCSymbol *Sym) const {
   // FIXME: We would like an efficient form for this, so we don't have to do a
   // lot of extra uniquing.
   MCSymbolRefExpr::VariantKind RefKind = MCSymbolRefExpr::VK_None;
@@ -270,8 +270,8 @@ MCOperand AArch64MCInstLower::lowerSymbolOperandCOFF(const MachineOperand &MO,
 
 MCOperand AArch64MCInstLower::LowerSymbolOperand(const MachineOperand &MO,
                                                  MCSymbol *Sym) const {
-  if (Printer.TM.getTargetTriple().isOSDarwin())
-    return lowerSymbolOperandDarwin(MO, Sym);
+  if (Printer.TM.getTargetTriple().isOSBinFormatMachO())
+    return lowerSymbolOperandMachO(MO, Sym);
   if (Printer.TM.getTargetTriple().isOSBinFormatCOFF())
     return lowerSymbolOperandCOFF(MO, Sym);
 
diff --git a/llvm/lib/Target/AArch64/AArch64MCInstLower.h b/llvm/lib/Target/AArch64/AArch64MCInstLower.h
index 8b6abc5c1f23c7c..e4f8a1bc1a31735 100644
--- a/llvm/lib/Target/AArch64/AArch64MCInstLower.h
+++ b/llvm/lib/Target/AArch64/AArch64MCInstLower.h
@@ -34,8 +34,8 @@ class LLVM_LIBRARY_VISIBILITY AArch64MCInstLower {
   bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const;
   void Lower(const MachineInstr *MI, MCInst &OutMI) const;
 
-  MCOperand lowerSymbolOperandDarwin(const MachineOperand &MO,
-                                     MCSymbol *Sym) const;
+  MCOperand lowerSymbolOperandMachO(const MachineOperand &MO,
+                                    MCSymbol *Sym) const;
   MCOperand lowerSymbolOperandELF(const MachineOperand &MO,
                                   MCSymbol *Sym) const;
   MCOperand lowerSymbolOperandCOFF(const MachineOperand &MO,
diff --git a/llvm/test/CodeGen/AArch64/macho-none.ll b/llvm/test/CodeGen/AArch64/macho-none.ll
new file mode 100644
index 000000000000000..81f7bf473aaf6d6
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/macho-none.ll
@@ -0,0 +1,9 @@
+; RUN: llc -mtriple=arm64-apple-none-elf %s -o -
+; RUN: llc -mtriple=arm64-apple-none-macho %s -o -
+
+ at var = global i8 0
+
+define i8 @foo() {
+  %x = load i8, ptr @var
+  ret i8 %x
+}



More information about the llvm-commits mailing list