Skip to content

Commit 0e80be8

Browse files
committed
SystemZ: Replace Ctx.reportError with reportError
Prepare for removing MCContext from getRelocType functions. For simplicy, we inline the static functions into the only user.
1 parent 9d3ea92 commit 0e80be8

File tree

1 file changed

+60
-67
lines changed

1 file changed

+60
-67
lines changed

llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp

Lines changed: 60 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class SystemZELFObjectWriter : public MCELFObjectTargetWriter {
3636
const MCFixup &Fixup, bool IsPCRel) const override;
3737
bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
3838
unsigned Type) const override;
39+
unsigned getAbsoluteReloc(SMLoc Loc, unsigned Kind) const;
40+
unsigned getPCRelReloc(SMLoc Loc, unsigned Kind) const;
3941
};
4042

4143
} // end anonymous namespace
@@ -45,7 +47,8 @@ SystemZELFObjectWriter::SystemZELFObjectWriter(uint8_t OSABI)
4547
/*HasRelocationAddend_=*/true) {}
4648

4749
// Return the relocation type for an absolute value of MCFixupKind Kind.
48-
static unsigned getAbsoluteReloc(MCContext &Ctx, SMLoc Loc, unsigned Kind) {
50+
unsigned SystemZELFObjectWriter::getAbsoluteReloc(SMLoc Loc,
51+
unsigned Kind) const {
4952
switch (Kind) {
5053
case FK_Data_1:
5154
case SystemZ::FK_390_U8Imm:
@@ -66,12 +69,12 @@ static unsigned getAbsoluteReloc(MCContext &Ctx, SMLoc Loc, unsigned Kind) {
6669
case FK_Data_8:
6770
return ELF::R_390_64;
6871
}
69-
Ctx.reportError(Loc, "Unsupported absolute address");
72+
reportError(Loc, "Unsupported absolute address");
7073
return 0;
7174
}
7275

7376
// Return the relocation type for a PC-relative value of MCFixupKind Kind.
74-
static unsigned getPCRelReloc(MCContext &Ctx, SMLoc Loc, unsigned Kind) {
77+
unsigned SystemZELFObjectWriter::getPCRelReloc(SMLoc Loc, unsigned Kind) const {
7578
switch (Kind) {
7679
case FK_Data_2:
7780
case SystemZ::FK_390_U16Imm:
@@ -92,61 +95,7 @@ static unsigned getPCRelReloc(MCContext &Ctx, SMLoc Loc, unsigned Kind) {
9295
case SystemZ::FK_390_PC32DBL:
9396
return ELF::R_390_PC32DBL;
9497
}
95-
Ctx.reportError(Loc, "Unsupported PC-relative address");
96-
return 0;
97-
}
98-
99-
// Return the R_390_TLS_LE* relocation type for MCFixupKind Kind.
100-
static unsigned getTLSLEReloc(MCContext &Ctx, SMLoc Loc, unsigned Kind) {
101-
switch (Kind) {
102-
case FK_Data_4: return ELF::R_390_TLS_LE32;
103-
case FK_Data_8: return ELF::R_390_TLS_LE64;
104-
}
105-
Ctx.reportError(Loc, "Unsupported thread-local address (local-exec)");
106-
return 0;
107-
}
108-
109-
// Return the R_390_TLS_LDO* relocation type for MCFixupKind Kind.
110-
static unsigned getTLSLDOReloc(MCContext &Ctx, SMLoc Loc, unsigned Kind) {
111-
switch (Kind) {
112-
case FK_Data_4: return ELF::R_390_TLS_LDO32;
113-
case FK_Data_8: return ELF::R_390_TLS_LDO64;
114-
}
115-
Ctx.reportError(Loc, "Unsupported thread-local address (local-dynamic)");
116-
return 0;
117-
}
118-
119-
// Return the R_390_TLS_LDM* relocation type for MCFixupKind Kind.
120-
static unsigned getTLSLDMReloc(MCContext &Ctx, SMLoc Loc, unsigned Kind) {
121-
switch (Kind) {
122-
case FK_Data_4: return ELF::R_390_TLS_LDM32;
123-
case FK_Data_8: return ELF::R_390_TLS_LDM64;
124-
case SystemZ::FK_390_TLS_CALL: return ELF::R_390_TLS_LDCALL;
125-
}
126-
Ctx.reportError(Loc, "Unsupported thread-local address (local-dynamic)");
127-
return 0;
128-
}
129-
130-
// Return the R_390_TLS_GD* relocation type for MCFixupKind Kind.
131-
static unsigned getTLSGDReloc(MCContext &Ctx, SMLoc Loc, unsigned Kind) {
132-
switch (Kind) {
133-
case FK_Data_4: return ELF::R_390_TLS_GD32;
134-
case FK_Data_8: return ELF::R_390_TLS_GD64;
135-
case SystemZ::FK_390_TLS_CALL: return ELF::R_390_TLS_GDCALL;
136-
}
137-
Ctx.reportError(Loc, "Unsupported thread-local address (general-dynamic)");
138-
return 0;
139-
}
140-
141-
// Return the PLT relocation counterpart of MCFixupKind Kind.
142-
static unsigned getPLTReloc(MCContext &Ctx, SMLoc Loc, unsigned Kind) {
143-
switch (Kind) {
144-
case SystemZ::FK_390_PC12DBL: return ELF::R_390_PLT12DBL;
145-
case SystemZ::FK_390_PC16DBL: return ELF::R_390_PLT16DBL;
146-
case SystemZ::FK_390_PC24DBL: return ELF::R_390_PLT24DBL;
147-
case SystemZ::FK_390_PC32DBL: return ELF::R_390_PLT32DBL;
148-
}
149-
Ctx.reportError(Loc, "Unsupported PC-relative PLT address");
98+
reportError(Loc, "Unsupported PC-relative address");
15099
return 0;
151100
}
152101

@@ -174,41 +123,85 @@ unsigned SystemZELFObjectWriter::getRelocType(MCContext &Ctx,
174123
switch (Specifier) {
175124
case SystemZMCExpr::VK_None:
176125
if (IsPCRel)
177-
return getPCRelReloc(Ctx, Loc, Kind);
178-
return getAbsoluteReloc(Ctx, Loc, Kind);
126+
return getPCRelReloc(Loc, Kind);
127+
return getAbsoluteReloc(Loc, Kind);
179128

180129
case SystemZMCExpr::VK_NTPOFF:
181130
assert(!IsPCRel && "NTPOFF shouldn't be PC-relative");
182-
return getTLSLEReloc(Ctx, Loc, Kind);
131+
switch (Kind) {
132+
case FK_Data_4:
133+
return ELF::R_390_TLS_LE32;
134+
case FK_Data_8:
135+
return ELF::R_390_TLS_LE64;
136+
}
137+
reportError(Loc, "Unsupported thread-local address (local-exec)");
138+
return 0;
183139

184140
case SystemZMCExpr::VK_INDNTPOFF:
185141
if (IsPCRel && Kind == SystemZ::FK_390_PC32DBL)
186142
return ELF::R_390_TLS_IEENT;
187-
Ctx.reportError(Loc, "Only PC-relative INDNTPOFF accesses are supported for now");
143+
reportError(Loc,
144+
"Only PC-relative INDNTPOFF accesses are supported for now");
188145
return 0;
189146

190147
case SystemZMCExpr::VK_DTPOFF:
191148
assert(!IsPCRel && "DTPOFF shouldn't be PC-relative");
192-
return getTLSLDOReloc(Ctx, Loc, Kind);
149+
switch (Kind) {
150+
case FK_Data_4:
151+
return ELF::R_390_TLS_LDO32;
152+
case FK_Data_8:
153+
return ELF::R_390_TLS_LDO64;
154+
}
155+
reportError(Loc, "Unsupported thread-local address (local-dynamic)");
156+
return 0;
193157

194158
case SystemZMCExpr::VK_TLSLDM:
195159
assert(!IsPCRel && "TLSLDM shouldn't be PC-relative");
196-
return getTLSLDMReloc(Ctx, Loc, Kind);
160+
switch (Kind) {
161+
case FK_Data_4:
162+
return ELF::R_390_TLS_LDM32;
163+
case FK_Data_8:
164+
return ELF::R_390_TLS_LDM64;
165+
case SystemZ::FK_390_TLS_CALL:
166+
return ELF::R_390_TLS_LDCALL;
167+
}
168+
reportError(Loc, "Unsupported thread-local address (local-dynamic)");
169+
return 0;
197170

198171
case SystemZMCExpr::VK_TLSGD:
199172
assert(!IsPCRel && "TLSGD shouldn't be PC-relative");
200-
return getTLSGDReloc(Ctx, Loc, Kind);
173+
switch (Kind) {
174+
case FK_Data_4:
175+
return ELF::R_390_TLS_GD32;
176+
case FK_Data_8:
177+
return ELF::R_390_TLS_GD64;
178+
case SystemZ::FK_390_TLS_CALL:
179+
return ELF::R_390_TLS_GDCALL;
180+
}
181+
reportError(Loc, "Unsupported thread-local address (general-dynamic)");
182+
return 0;
201183

202184
case SystemZMCExpr::VK_GOT:
203185
case SystemZMCExpr::VK_GOTENT:
204186
if (IsPCRel && Kind == SystemZ::FK_390_PC32DBL)
205187
return ELF::R_390_GOTENT;
206-
Ctx.reportError(Loc, "Only PC-relative GOT accesses are supported for now");
188+
reportError(Loc, "Only PC-relative GOT accesses are supported for now");
207189
return 0;
208190

209191
case SystemZMCExpr::VK_PLT:
210192
assert(IsPCRel && "@PLT shouldn't be PC-relative");
211-
return getPLTReloc(Ctx, Loc, Kind);
193+
switch (Kind) {
194+
case SystemZ::FK_390_PC12DBL:
195+
return ELF::R_390_PLT12DBL;
196+
case SystemZ::FK_390_PC16DBL:
197+
return ELF::R_390_PLT16DBL;
198+
case SystemZ::FK_390_PC24DBL:
199+
return ELF::R_390_PLT24DBL;
200+
case SystemZ::FK_390_PC32DBL:
201+
return ELF::R_390_PLT32DBL;
202+
}
203+
reportError(Loc, "Unsupported PC-relative PLT address");
204+
return 0;
212205

213206
default:
214207
llvm_unreachable("Modifier not supported");

0 commit comments

Comments
 (0)