[llvm] 0e80be8 - SystemZ: Replace Ctx.reportError with reportError
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat May 24 21:06:14 PDT 2025
Author: Fangrui Song
Date: 2025-05-24T21:06:09-07:00
New Revision: 0e80be84fae34b6acbb237ea0ae8ea854dea2931
URL: https://github.com/llvm/llvm-project/commit/0e80be84fae34b6acbb237ea0ae8ea854dea2931
DIFF: https://github.com/llvm/llvm-project/commit/0e80be84fae34b6acbb237ea0ae8ea854dea2931.diff
LOG: SystemZ: Replace Ctx.reportError with reportError
Prepare for removing MCContext from getRelocType functions.
For simplicy, we inline the static functions into the only user.
Added:
Modified:
llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp
index ea9d42080b9ec..d87f8d6485c0b 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp
@@ -36,6 +36,8 @@ class SystemZELFObjectWriter : public MCELFObjectTargetWriter {
const MCFixup &Fixup, bool IsPCRel) const override;
bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
unsigned Type) const override;
+ unsigned getAbsoluteReloc(SMLoc Loc, unsigned Kind) const;
+ unsigned getPCRelReloc(SMLoc Loc, unsigned Kind) const;
};
} // end anonymous namespace
@@ -45,7 +47,8 @@ SystemZELFObjectWriter::SystemZELFObjectWriter(uint8_t OSABI)
/*HasRelocationAddend_=*/true) {}
// Return the relocation type for an absolute value of MCFixupKind Kind.
-static unsigned getAbsoluteReloc(MCContext &Ctx, SMLoc Loc, unsigned Kind) {
+unsigned SystemZELFObjectWriter::getAbsoluteReloc(SMLoc Loc,
+ unsigned Kind) const {
switch (Kind) {
case FK_Data_1:
case SystemZ::FK_390_U8Imm:
@@ -66,12 +69,12 @@ static unsigned getAbsoluteReloc(MCContext &Ctx, SMLoc Loc, unsigned Kind) {
case FK_Data_8:
return ELF::R_390_64;
}
- Ctx.reportError(Loc, "Unsupported absolute address");
+ reportError(Loc, "Unsupported absolute address");
return 0;
}
// Return the relocation type for a PC-relative value of MCFixupKind Kind.
-static unsigned getPCRelReloc(MCContext &Ctx, SMLoc Loc, unsigned Kind) {
+unsigned SystemZELFObjectWriter::getPCRelReloc(SMLoc Loc, unsigned Kind) const {
switch (Kind) {
case FK_Data_2:
case SystemZ::FK_390_U16Imm:
@@ -92,61 +95,7 @@ static unsigned getPCRelReloc(MCContext &Ctx, SMLoc Loc, unsigned Kind) {
case SystemZ::FK_390_PC32DBL:
return ELF::R_390_PC32DBL;
}
- Ctx.reportError(Loc, "Unsupported PC-relative address");
- return 0;
-}
-
-// Return the R_390_TLS_LE* relocation type for MCFixupKind Kind.
-static unsigned getTLSLEReloc(MCContext &Ctx, SMLoc Loc, unsigned Kind) {
- switch (Kind) {
- case FK_Data_4: return ELF::R_390_TLS_LE32;
- case FK_Data_8: return ELF::R_390_TLS_LE64;
- }
- Ctx.reportError(Loc, "Unsupported thread-local address (local-exec)");
- return 0;
-}
-
-// Return the R_390_TLS_LDO* relocation type for MCFixupKind Kind.
-static unsigned getTLSLDOReloc(MCContext &Ctx, SMLoc Loc, unsigned Kind) {
- switch (Kind) {
- case FK_Data_4: return ELF::R_390_TLS_LDO32;
- case FK_Data_8: return ELF::R_390_TLS_LDO64;
- }
- Ctx.reportError(Loc, "Unsupported thread-local address (local-dynamic)");
- return 0;
-}
-
-// Return the R_390_TLS_LDM* relocation type for MCFixupKind Kind.
-static unsigned getTLSLDMReloc(MCContext &Ctx, SMLoc Loc, unsigned Kind) {
- switch (Kind) {
- case FK_Data_4: return ELF::R_390_TLS_LDM32;
- case FK_Data_8: return ELF::R_390_TLS_LDM64;
- case SystemZ::FK_390_TLS_CALL: return ELF::R_390_TLS_LDCALL;
- }
- Ctx.reportError(Loc, "Unsupported thread-local address (local-dynamic)");
- return 0;
-}
-
-// Return the R_390_TLS_GD* relocation type for MCFixupKind Kind.
-static unsigned getTLSGDReloc(MCContext &Ctx, SMLoc Loc, unsigned Kind) {
- switch (Kind) {
- case FK_Data_4: return ELF::R_390_TLS_GD32;
- case FK_Data_8: return ELF::R_390_TLS_GD64;
- case SystemZ::FK_390_TLS_CALL: return ELF::R_390_TLS_GDCALL;
- }
- Ctx.reportError(Loc, "Unsupported thread-local address (general-dynamic)");
- return 0;
-}
-
-// Return the PLT relocation counterpart of MCFixupKind Kind.
-static unsigned getPLTReloc(MCContext &Ctx, SMLoc Loc, unsigned Kind) {
- switch (Kind) {
- case SystemZ::FK_390_PC12DBL: return ELF::R_390_PLT12DBL;
- case SystemZ::FK_390_PC16DBL: return ELF::R_390_PLT16DBL;
- case SystemZ::FK_390_PC24DBL: return ELF::R_390_PLT24DBL;
- case SystemZ::FK_390_PC32DBL: return ELF::R_390_PLT32DBL;
- }
- Ctx.reportError(Loc, "Unsupported PC-relative PLT address");
+ reportError(Loc, "Unsupported PC-relative address");
return 0;
}
@@ -174,41 +123,85 @@ unsigned SystemZELFObjectWriter::getRelocType(MCContext &Ctx,
switch (Specifier) {
case SystemZMCExpr::VK_None:
if (IsPCRel)
- return getPCRelReloc(Ctx, Loc, Kind);
- return getAbsoluteReloc(Ctx, Loc, Kind);
+ return getPCRelReloc(Loc, Kind);
+ return getAbsoluteReloc(Loc, Kind);
case SystemZMCExpr::VK_NTPOFF:
assert(!IsPCRel && "NTPOFF shouldn't be PC-relative");
- return getTLSLEReloc(Ctx, Loc, Kind);
+ switch (Kind) {
+ case FK_Data_4:
+ return ELF::R_390_TLS_LE32;
+ case FK_Data_8:
+ return ELF::R_390_TLS_LE64;
+ }
+ reportError(Loc, "Unsupported thread-local address (local-exec)");
+ return 0;
case SystemZMCExpr::VK_INDNTPOFF:
if (IsPCRel && Kind == SystemZ::FK_390_PC32DBL)
return ELF::R_390_TLS_IEENT;
- Ctx.reportError(Loc, "Only PC-relative INDNTPOFF accesses are supported for now");
+ reportError(Loc,
+ "Only PC-relative INDNTPOFF accesses are supported for now");
return 0;
case SystemZMCExpr::VK_DTPOFF:
assert(!IsPCRel && "DTPOFF shouldn't be PC-relative");
- return getTLSLDOReloc(Ctx, Loc, Kind);
+ switch (Kind) {
+ case FK_Data_4:
+ return ELF::R_390_TLS_LDO32;
+ case FK_Data_8:
+ return ELF::R_390_TLS_LDO64;
+ }
+ reportError(Loc, "Unsupported thread-local address (local-dynamic)");
+ return 0;
case SystemZMCExpr::VK_TLSLDM:
assert(!IsPCRel && "TLSLDM shouldn't be PC-relative");
- return getTLSLDMReloc(Ctx, Loc, Kind);
+ switch (Kind) {
+ case FK_Data_4:
+ return ELF::R_390_TLS_LDM32;
+ case FK_Data_8:
+ return ELF::R_390_TLS_LDM64;
+ case SystemZ::FK_390_TLS_CALL:
+ return ELF::R_390_TLS_LDCALL;
+ }
+ reportError(Loc, "Unsupported thread-local address (local-dynamic)");
+ return 0;
case SystemZMCExpr::VK_TLSGD:
assert(!IsPCRel && "TLSGD shouldn't be PC-relative");
- return getTLSGDReloc(Ctx, Loc, Kind);
+ switch (Kind) {
+ case FK_Data_4:
+ return ELF::R_390_TLS_GD32;
+ case FK_Data_8:
+ return ELF::R_390_TLS_GD64;
+ case SystemZ::FK_390_TLS_CALL:
+ return ELF::R_390_TLS_GDCALL;
+ }
+ reportError(Loc, "Unsupported thread-local address (general-dynamic)");
+ return 0;
case SystemZMCExpr::VK_GOT:
case SystemZMCExpr::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");
+ reportError(Loc, "Only PC-relative GOT accesses are supported for now");
return 0;
case SystemZMCExpr::VK_PLT:
assert(IsPCRel && "@PLT shouldn't be PC-relative");
- return getPLTReloc(Ctx, Loc, Kind);
+ switch (Kind) {
+ case SystemZ::FK_390_PC12DBL:
+ return ELF::R_390_PLT12DBL;
+ case SystemZ::FK_390_PC16DBL:
+ return ELF::R_390_PLT16DBL;
+ case SystemZ::FK_390_PC24DBL:
+ return ELF::R_390_PLT24DBL;
+ case SystemZ::FK_390_PC32DBL:
+ return ELF::R_390_PLT32DBL;
+ }
+ reportError(Loc, "Unsupported PC-relative PLT address");
+ return 0;
default:
llvm_unreachable("Modifier not supported");
More information about the llvm-commits
mailing list