[llvm] [llvm][SystemZ] Recognize `@GOTENT` modifier in assembler. (PR #107038)
Alex Rønne Petersen via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 2 18:52:10 PDT 2024
https://github.com/alexrp updated https://github.com/llvm/llvm-project/pull/107038
>From 65e15432ad44ec51b0e76b69ff1cbe6d3569fabb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= <alex at alexrp.com>
Date: Tue, 3 Sep 2024 03:42:43 +0200
Subject: [PATCH] [llvm][SystemZ] Recognize @GOTENT modifier in assembler.
Closes #105918.
---
llvm/include/llvm/MC/MCExpr.h | 1 +
llvm/lib/MC/MCExpr.cpp | 264 +++++++++---------
.../MCTargetDesc/SystemZELFObjectWriter.cpp | 1 +
llvm/test/MC/SystemZ/fixups.s | 6 +
4 files changed, 141 insertions(+), 131 deletions(-)
diff --git a/llvm/include/llvm/MC/MCExpr.h b/llvm/include/llvm/MC/MCExpr.h
index 118b1dd88525ab..10bc6ebd6fe506 100644
--- a/llvm/include/llvm/MC/MCExpr.h
+++ b/llvm/include/llvm/MC/MCExpr.h
@@ -192,6 +192,7 @@ class MCSymbolRefExpr : public MCExpr {
VK_Invalid,
VK_GOT,
+ VK_GOTENT,
VK_GOTOFF,
VK_GOTREL,
VK_PCREL,
diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp
index e4ca431c3d25f9..c9d5f6580fda4c 100644
--- a/llvm/lib/MC/MCExpr.cpp
+++ b/llvm/lib/MC/MCExpr.cpp
@@ -226,6 +226,7 @@ StringRef MCSymbolRefExpr::getVariantKindName(VariantKind Kind) {
case VK_DTPOFF: return "DTPOFF";
case VK_DTPREL: return "DTPREL";
case VK_GOT: return "GOT";
+ case VK_GOTENT: return "GOTENT";
case VK_GOTOFF: return "GOTOFF";
case VK_GOTREL: return "GOTREL";
case VK_PCREL: return "PCREL";
@@ -404,137 +405,138 @@ StringRef MCSymbolRefExpr::getVariantKindName(VariantKind Kind) {
MCSymbolRefExpr::VariantKind
MCSymbolRefExpr::getVariantKindForName(StringRef Name) {
return StringSwitch<VariantKind>(Name.lower())
- .Case("dtprel", VK_DTPREL)
- .Case("dtpoff", VK_DTPOFF)
- .Case("got", VK_GOT)
- .Case("gotoff", VK_GOTOFF)
- .Case("gotrel", VK_GOTREL)
- .Case("pcrel", VK_PCREL)
- .Case("gotpcrel", VK_GOTPCREL)
- .Case("gotpcrel_norelax", VK_GOTPCREL_NORELAX)
- .Case("gottpoff", VK_GOTTPOFF)
- .Case("indntpoff", VK_INDNTPOFF)
- .Case("ntpoff", VK_NTPOFF)
- .Case("gotntpoff", VK_GOTNTPOFF)
- .Case("plt", VK_PLT)
- .Case("tlscall", VK_TLSCALL)
- .Case("tlsdesc", VK_TLSDESC)
- .Case("tlsgd", VK_TLSGD)
- .Case("tlsld", VK_TLSLD)
- .Case("tlsldm", VK_TLSLDM)
- .Case("tpoff", VK_TPOFF)
- .Case("tprel", VK_TPREL)
- .Case("tlvp", VK_TLVP)
- .Case("tlvppage", VK_TLVPPAGE)
- .Case("tlvppageoff", VK_TLVPPAGEOFF)
- .Case("page", VK_PAGE)
- .Case("pageoff", VK_PAGEOFF)
- .Case("gotpage", VK_GOTPAGE)
- .Case("gotpageoff", VK_GOTPAGEOFF)
- .Case("imgrel", VK_COFF_IMGREL32)
- .Case("secrel32", VK_SECREL)
- .Case("size", VK_SIZE)
- .Case("abs8", VK_X86_ABS8)
- .Case("pltoff", VK_X86_PLTOFF)
- .Case("l", VK_PPC_LO)
- .Case("h", VK_PPC_HI)
- .Case("ha", VK_PPC_HA)
- .Case("high", VK_PPC_HIGH)
- .Case("higha", VK_PPC_HIGHA)
- .Case("higher", VK_PPC_HIGHER)
- .Case("highera", VK_PPC_HIGHERA)
- .Case("highest", VK_PPC_HIGHEST)
- .Case("highesta", VK_PPC_HIGHESTA)
- .Case("got at l", VK_PPC_GOT_LO)
- .Case("got at h", VK_PPC_GOT_HI)
- .Case("got at ha", VK_PPC_GOT_HA)
- .Case("local", VK_PPC_LOCAL)
- .Case("tocbase", VK_PPC_TOCBASE)
- .Case("toc", VK_PPC_TOC)
- .Case("toc at l", VK_PPC_TOC_LO)
- .Case("toc at h", VK_PPC_TOC_HI)
- .Case("toc at ha", VK_PPC_TOC_HA)
- .Case("u", VK_PPC_U)
- .Case("l", VK_PPC_L)
- .Case("tls", VK_PPC_TLS)
- .Case("dtpmod", VK_PPC_DTPMOD)
- .Case("tprel at l", VK_PPC_TPREL_LO)
- .Case("tprel at h", VK_PPC_TPREL_HI)
- .Case("tprel at ha", VK_PPC_TPREL_HA)
- .Case("tprel at high", VK_PPC_TPREL_HIGH)
- .Case("tprel at higha", VK_PPC_TPREL_HIGHA)
- .Case("tprel at higher", VK_PPC_TPREL_HIGHER)
- .Case("tprel at highera", VK_PPC_TPREL_HIGHERA)
- .Case("tprel at highest", VK_PPC_TPREL_HIGHEST)
- .Case("tprel at highesta", VK_PPC_TPREL_HIGHESTA)
- .Case("dtprel at l", VK_PPC_DTPREL_LO)
- .Case("dtprel at h", VK_PPC_DTPREL_HI)
- .Case("dtprel at ha", VK_PPC_DTPREL_HA)
- .Case("dtprel at high", VK_PPC_DTPREL_HIGH)
- .Case("dtprel at higha", VK_PPC_DTPREL_HIGHA)
- .Case("dtprel at higher", VK_PPC_DTPREL_HIGHER)
- .Case("dtprel at highera", VK_PPC_DTPREL_HIGHERA)
- .Case("dtprel at highest", VK_PPC_DTPREL_HIGHEST)
- .Case("dtprel at highesta", VK_PPC_DTPREL_HIGHESTA)
- .Case("got at tprel", VK_PPC_GOT_TPREL)
- .Case("got at tprel@l", VK_PPC_GOT_TPREL_LO)
- .Case("got at tprel@h", VK_PPC_GOT_TPREL_HI)
- .Case("got at tprel@ha", VK_PPC_GOT_TPREL_HA)
- .Case("got at dtprel", VK_PPC_GOT_DTPREL)
- .Case("got at dtprel@l", VK_PPC_GOT_DTPREL_LO)
- .Case("got at dtprel@h", VK_PPC_GOT_DTPREL_HI)
- .Case("got at dtprel@ha", VK_PPC_GOT_DTPREL_HA)
- .Case("got at tlsgd", VK_PPC_GOT_TLSGD)
- .Case("got at tlsgd@l", VK_PPC_GOT_TLSGD_LO)
- .Case("got at tlsgd@h", VK_PPC_GOT_TLSGD_HI)
- .Case("got at tlsgd@ha", VK_PPC_GOT_TLSGD_HA)
- .Case("got at tlsld", VK_PPC_GOT_TLSLD)
- .Case("got at tlsld@l", VK_PPC_GOT_TLSLD_LO)
- .Case("got at tlsld@h", VK_PPC_GOT_TLSLD_HI)
- .Case("got at tlsld@ha", VK_PPC_GOT_TLSLD_HA)
- .Case("got at pcrel", VK_PPC_GOT_PCREL)
- .Case("got at tlsgd@pcrel", VK_PPC_GOT_TLSGD_PCREL)
- .Case("got at tlsld@pcrel", VK_PPC_GOT_TLSLD_PCREL)
- .Case("got at tprel@pcrel", VK_PPC_GOT_TPREL_PCREL)
- .Case("tls at pcrel", VK_PPC_TLS_PCREL)
- .Case("notoc", VK_PPC_NOTOC)
- .Case("gdgot", VK_Hexagon_GD_GOT)
- .Case("gdplt", VK_Hexagon_GD_PLT)
- .Case("iegot", VK_Hexagon_IE_GOT)
- .Case("ie", VK_Hexagon_IE)
- .Case("ldgot", VK_Hexagon_LD_GOT)
- .Case("ldplt", VK_Hexagon_LD_PLT)
- .Case("lo8", VK_AVR_LO8)
- .Case("hi8", VK_AVR_HI8)
- .Case("hlo8", VK_AVR_HLO8)
- .Case("typeindex", VK_WASM_TYPEINDEX)
- .Case("tbrel", VK_WASM_TBREL)
- .Case("mbrel", VK_WASM_MBREL)
- .Case("tlsrel", VK_WASM_TLSREL)
- .Case("got at tls", VK_WASM_GOT_TLS)
- .Case("funcindex", VK_WASM_FUNCINDEX)
- .Case("gotpcrel32 at lo", VK_AMDGPU_GOTPCREL32_LO)
- .Case("gotpcrel32 at hi", VK_AMDGPU_GOTPCREL32_HI)
- .Case("rel32 at lo", VK_AMDGPU_REL32_LO)
- .Case("rel32 at hi", VK_AMDGPU_REL32_HI)
- .Case("rel64", VK_AMDGPU_REL64)
- .Case("abs32 at lo", VK_AMDGPU_ABS32_LO)
- .Case("abs32 at hi", VK_AMDGPU_ABS32_HI)
- .Case("hi", VK_VE_HI32)
- .Case("lo", VK_VE_LO32)
- .Case("pc_hi", VK_VE_PC_HI32)
- .Case("pc_lo", VK_VE_PC_LO32)
- .Case("got_hi", VK_VE_GOT_HI32)
- .Case("got_lo", VK_VE_GOT_LO32)
- .Case("gotoff_hi", VK_VE_GOTOFF_HI32)
- .Case("gotoff_lo", VK_VE_GOTOFF_LO32)
- .Case("plt_hi", VK_VE_PLT_HI32)
- .Case("plt_lo", VK_VE_PLT_LO32)
- .Case("tls_gd_hi", VK_VE_TLS_GD_HI32)
- .Case("tls_gd_lo", VK_VE_TLS_GD_LO32)
- .Case("tpoff_hi", VK_VE_TPOFF_HI32)
- .Case("tpoff_lo", VK_VE_TPOFF_LO32)
- .Default(VK_Invalid);
+ .Case("dtprel", VK_DTPREL)
+ .Case("dtpoff", VK_DTPOFF)
+ .Case("got", VK_GOT)
+ .Case("gotent", VK_GOTENT)
+ .Case("gotoff", VK_GOTOFF)
+ .Case("gotrel", VK_GOTREL)
+ .Case("pcrel", VK_PCREL)
+ .Case("gotpcrel", VK_GOTPCREL)
+ .Case("gotpcrel_norelax", VK_GOTPCREL_NORELAX)
+ .Case("gottpoff", VK_GOTTPOFF)
+ .Case("indntpoff", VK_INDNTPOFF)
+ .Case("ntpoff", VK_NTPOFF)
+ .Case("gotntpoff", VK_GOTNTPOFF)
+ .Case("plt", VK_PLT)
+ .Case("tlscall", VK_TLSCALL)
+ .Case("tlsdesc", VK_TLSDESC)
+ .Case("tlsgd", VK_TLSGD)
+ .Case("tlsld", VK_TLSLD)
+ .Case("tlsldm", VK_TLSLDM)
+ .Case("tpoff", VK_TPOFF)
+ .Case("tprel", VK_TPREL)
+ .Case("tlvp", VK_TLVP)
+ .Case("tlvppage", VK_TLVPPAGE)
+ .Case("tlvppageoff", VK_TLVPPAGEOFF)
+ .Case("page", VK_PAGE)
+ .Case("pageoff", VK_PAGEOFF)
+ .Case("gotpage", VK_GOTPAGE)
+ .Case("gotpageoff", VK_GOTPAGEOFF)
+ .Case("imgrel", VK_COFF_IMGREL32)
+ .Case("secrel32", VK_SECREL)
+ .Case("size", VK_SIZE)
+ .Case("abs8", VK_X86_ABS8)
+ .Case("pltoff", VK_X86_PLTOFF)
+ .Case("l", VK_PPC_LO)
+ .Case("h", VK_PPC_HI)
+ .Case("ha", VK_PPC_HA)
+ .Case("high", VK_PPC_HIGH)
+ .Case("higha", VK_PPC_HIGHA)
+ .Case("higher", VK_PPC_HIGHER)
+ .Case("highera", VK_PPC_HIGHERA)
+ .Case("highest", VK_PPC_HIGHEST)
+ .Case("highesta", VK_PPC_HIGHESTA)
+ .Case("got at l", VK_PPC_GOT_LO)
+ .Case("got at h", VK_PPC_GOT_HI)
+ .Case("got at ha", VK_PPC_GOT_HA)
+ .Case("local", VK_PPC_LOCAL)
+ .Case("tocbase", VK_PPC_TOCBASE)
+ .Case("toc", VK_PPC_TOC)
+ .Case("toc at l", VK_PPC_TOC_LO)
+ .Case("toc at h", VK_PPC_TOC_HI)
+ .Case("toc at ha", VK_PPC_TOC_HA)
+ .Case("u", VK_PPC_U)
+ .Case("l", VK_PPC_L)
+ .Case("tls", VK_PPC_TLS)
+ .Case("dtpmod", VK_PPC_DTPMOD)
+ .Case("tprel at l", VK_PPC_TPREL_LO)
+ .Case("tprel at h", VK_PPC_TPREL_HI)
+ .Case("tprel at ha", VK_PPC_TPREL_HA)
+ .Case("tprel at high", VK_PPC_TPREL_HIGH)
+ .Case("tprel at higha", VK_PPC_TPREL_HIGHA)
+ .Case("tprel at higher", VK_PPC_TPREL_HIGHER)
+ .Case("tprel at highera", VK_PPC_TPREL_HIGHERA)
+ .Case("tprel at highest", VK_PPC_TPREL_HIGHEST)
+ .Case("tprel at highesta", VK_PPC_TPREL_HIGHESTA)
+ .Case("dtprel at l", VK_PPC_DTPREL_LO)
+ .Case("dtprel at h", VK_PPC_DTPREL_HI)
+ .Case("dtprel at ha", VK_PPC_DTPREL_HA)
+ .Case("dtprel at high", VK_PPC_DTPREL_HIGH)
+ .Case("dtprel at higha", VK_PPC_DTPREL_HIGHA)
+ .Case("dtprel at higher", VK_PPC_DTPREL_HIGHER)
+ .Case("dtprel at highera", VK_PPC_DTPREL_HIGHERA)
+ .Case("dtprel at highest", VK_PPC_DTPREL_HIGHEST)
+ .Case("dtprel at highesta", VK_PPC_DTPREL_HIGHESTA)
+ .Case("got at tprel", VK_PPC_GOT_TPREL)
+ .Case("got at tprel@l", VK_PPC_GOT_TPREL_LO)
+ .Case("got at tprel@h", VK_PPC_GOT_TPREL_HI)
+ .Case("got at tprel@ha", VK_PPC_GOT_TPREL_HA)
+ .Case("got at dtprel", VK_PPC_GOT_DTPREL)
+ .Case("got at dtprel@l", VK_PPC_GOT_DTPREL_LO)
+ .Case("got at dtprel@h", VK_PPC_GOT_DTPREL_HI)
+ .Case("got at dtprel@ha", VK_PPC_GOT_DTPREL_HA)
+ .Case("got at tlsgd", VK_PPC_GOT_TLSGD)
+ .Case("got at tlsgd@l", VK_PPC_GOT_TLSGD_LO)
+ .Case("got at tlsgd@h", VK_PPC_GOT_TLSGD_HI)
+ .Case("got at tlsgd@ha", VK_PPC_GOT_TLSGD_HA)
+ .Case("got at tlsld", VK_PPC_GOT_TLSLD)
+ .Case("got at tlsld@l", VK_PPC_GOT_TLSLD_LO)
+ .Case("got at tlsld@h", VK_PPC_GOT_TLSLD_HI)
+ .Case("got at tlsld@ha", VK_PPC_GOT_TLSLD_HA)
+ .Case("got at pcrel", VK_PPC_GOT_PCREL)
+ .Case("got at tlsgd@pcrel", VK_PPC_GOT_TLSGD_PCREL)
+ .Case("got at tlsld@pcrel", VK_PPC_GOT_TLSLD_PCREL)
+ .Case("got at tprel@pcrel", VK_PPC_GOT_TPREL_PCREL)
+ .Case("tls at pcrel", VK_PPC_TLS_PCREL)
+ .Case("notoc", VK_PPC_NOTOC)
+ .Case("gdgot", VK_Hexagon_GD_GOT)
+ .Case("gdplt", VK_Hexagon_GD_PLT)
+ .Case("iegot", VK_Hexagon_IE_GOT)
+ .Case("ie", VK_Hexagon_IE)
+ .Case("ldgot", VK_Hexagon_LD_GOT)
+ .Case("ldplt", VK_Hexagon_LD_PLT)
+ .Case("lo8", VK_AVR_LO8)
+ .Case("hi8", VK_AVR_HI8)
+ .Case("hlo8", VK_AVR_HLO8)
+ .Case("typeindex", VK_WASM_TYPEINDEX)
+ .Case("tbrel", VK_WASM_TBREL)
+ .Case("mbrel", VK_WASM_MBREL)
+ .Case("tlsrel", VK_WASM_TLSREL)
+ .Case("got at tls", VK_WASM_GOT_TLS)
+ .Case("funcindex", VK_WASM_FUNCINDEX)
+ .Case("gotpcrel32 at lo", VK_AMDGPU_GOTPCREL32_LO)
+ .Case("gotpcrel32 at hi", VK_AMDGPU_GOTPCREL32_HI)
+ .Case("rel32 at lo", VK_AMDGPU_REL32_LO)
+ .Case("rel32 at hi", VK_AMDGPU_REL32_HI)
+ .Case("rel64", VK_AMDGPU_REL64)
+ .Case("abs32 at lo", VK_AMDGPU_ABS32_LO)
+ .Case("abs32 at hi", VK_AMDGPU_ABS32_HI)
+ .Case("hi", VK_VE_HI32)
+ .Case("lo", VK_VE_LO32)
+ .Case("pc_hi", VK_VE_PC_HI32)
+ .Case("pc_lo", VK_VE_PC_LO32)
+ .Case("got_hi", VK_VE_GOT_HI32)
+ .Case("got_lo", VK_VE_GOT_LO32)
+ .Case("gotoff_hi", VK_VE_GOTOFF_HI32)
+ .Case("gotoff_lo", VK_VE_GOTOFF_LO32)
+ .Case("plt_hi", VK_VE_PLT_HI32)
+ .Case("plt_lo", VK_VE_PLT_LO32)
+ .Case("tls_gd_hi", VK_VE_TLS_GD_HI32)
+ .Case("tls_gd_lo", VK_VE_TLS_GD_LO32)
+ .Case("tpoff_hi", VK_VE_TPOFF_HI32)
+ .Case("tpoff_lo", VK_VE_TPOFF_LO32)
+ .Default(VK_Invalid);
}
/* *** */
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp
index de1eedb8daff62..e44b4a52369153 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp
@@ -185,6 +185,7 @@ unsigned SystemZELFObjectWriter::getRelocType(MCContext &Ctx,
return getTLSGDReloc(Ctx, Loc, Kind);
case MCSymbolRefExpr::VK_GOT:
+ case MCSymbolRefExpr::VK_GOTENT:
if (IsPCRel && Kind == SystemZ::FK_390_PC32DBL)
return ELF::R_390_GOTENT;
Ctx.reportError(Loc, "Only PC-relative GOT accesses are supported for now");
diff --git a/llvm/test/MC/SystemZ/fixups.s b/llvm/test/MC/SystemZ/fixups.s
index ad0b1f18cdcfd4..0d59e60fc59579 100644
--- a/llvm/test/MC/SystemZ/fixups.s
+++ b/llvm/test/MC/SystemZ/fixups.s
@@ -19,6 +19,12 @@
.align 16
larl %r14, target at got
+# CHECK: larl %r14, target at GOTENT # encoding: [0xc0,0xe0,A,A,A,A]
+# CHECK-NEXT: # fixup A - offset: 2, value: target at GOTENT+2, kind: FK_390_PC32DBL
+# CHECK-REL: 0x{{[0-9A-F]*2}} R_390_GOTENT target 0x2
+ .align 16
+ larl %r14, target at gotent
+
# CHECK: larl %r14, target at INDNTPOFF # encoding: [0xc0,0xe0,A,A,A,A]
# CHECK-NEXT: # fixup A - offset: 2, value: target at INDNTPOFF+2, kind: FK_390_PC32DBL
# CHECK-REL: 0x{{[0-9A-F]*2}} R_390_TLS_IEENT target 0x2
More information about the llvm-commits
mailing list