Skip to content

Commit 843e362

Browse files
committed
MachObjectWriter: Simplify Asm.getContext().reportError
Similar to b65760b for ELF.
1 parent 64390b9 commit 843e362

File tree

5 files changed

+89
-108
lines changed

5 files changed

+89
-108
lines changed

llvm/include/llvm/MC/MCMachObjectWriter.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,8 @@ class MachObjectWriter final : public MCObjectWriter {
184184

185185
const MCSymbol &findAliasedSymbol(const MCSymbol &Sym) const;
186186

187-
/// \name Lifetime management Methods
188-
/// @{
189-
190187
void reset() override;
191-
192-
/// @}
188+
void setAssembler(MCAssembler *Asm) override;
193189

194190
/// \name Utility Methods
195191
/// @{

llvm/lib/MC/MachObjectWriter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ void MachObjectWriter::reset() {
6262
MCObjectWriter::reset();
6363
}
6464

65+
void MachObjectWriter::setAssembler(MCAssembler *Asm) {
66+
MCObjectWriter::setAssembler(Asm);
67+
TargetObjectWriter->setAssembler(Asm);
68+
}
69+
6570
bool MachObjectWriter::doesSymbolRequireExternRelocation(const MCSymbol &S) {
6671
// Undefined symbols are always extern.
6772
if (S.isUndefined())

llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ bool AArch64MachObjectWriter::getAArch64FixupKindMachOInfo(
9999
// This encompasses the relocation for the whole 21-bit value.
100100
switch (Spec) {
101101
default:
102-
Asm.getContext().reportError(Fixup.getLoc(),
103-
"ADR/ADRP relocations must be GOT relative");
102+
reportError(Fixup.getLoc(), "ADR/ADRP relocations must be GOT relative");
104103
return false;
105104
case AArch64MCExpr::M_PAGE:
106105
RelocType = unsigned(MachO::ARM64_RELOC_PAGE21);
@@ -176,25 +175,24 @@ void AArch64MachObjectWriter::recordRelocation(
176175
// assembler local symbols. If we got here, that's not what we have,
177176
// so complain loudly.
178177
if (Kind == AArch64::fixup_aarch64_pcrel_branch19) {
179-
Asm.getContext().reportError(
180-
Fixup.getLoc(), "conditional branch requires assembler-local"
181-
" label. '" +
182-
Target.getAddSym()->getName() + "' is external.");
178+
reportError(Fixup.getLoc(), "conditional branch requires assembler-local"
179+
" label. '" +
180+
Target.getAddSym()->getName() +
181+
"' is external.");
183182
return;
184183
}
185184

186185
// 14-bit branch relocations should only target internal labels, and so
187186
// should never get here.
188187
if (Kind == AArch64::fixup_aarch64_pcrel_branch14) {
189-
Asm.getContext().reportError(Fixup.getLoc(),
190-
"Invalid relocation on conditional branch!");
188+
reportError(Fixup.getLoc(), "Invalid relocation on conditional branch!");
191189
return;
192190
}
193191

194192
if (!getAArch64FixupKindMachOInfo(
195193
Fixup, Type, AArch64MCExpr::Specifier(Target.getSpecifier()),
196194
Log2Size, Asm)) {
197-
Asm.getContext().reportError(Fixup.getLoc(), "unknown AArch64 fixup kind!");
195+
reportError(Fixup.getLoc(), "unknown AArch64 fixup kind!");
198196
return;
199197
}
200198

@@ -206,8 +204,7 @@ void AArch64MachObjectWriter::recordRelocation(
206204
Type = MachO::ARM64_RELOC_UNSIGNED;
207205

208206
if (IsPCRel) {
209-
Asm.getContext().reportError(Fixup.getLoc(),
210-
"PC relative absolute relocation!");
207+
reportError(Fixup.getLoc(), "PC relative absolute relocation!");
211208
return;
212209

213210
// FIXME: x86_64 sets the type to a branch reloc here. Should we do
@@ -234,16 +231,14 @@ void AArch64MachObjectWriter::recordRelocation(
234231
return;
235232
} else if (Target.getSpecifier() != AArch64MCExpr::None) {
236233
// Otherwise, neither symbol can be modified.
237-
Asm.getContext().reportError(Fixup.getLoc(),
238-
"unsupported relocation of modified symbol");
234+
reportError(Fixup.getLoc(), "unsupported relocation of modified symbol");
239235
return;
240236
}
241237

242238
// We don't support PCrel relocations of differences.
243239
if (IsPCRel) {
244-
Asm.getContext().reportError(Fixup.getLoc(),
245-
"unsupported pc-relative relocation of "
246-
"difference");
240+
reportError(Fixup.getLoc(), "unsupported pc-relative relocation of "
241+
"difference");
247242
return;
248243
}
249244

@@ -254,23 +249,20 @@ void AArch64MachObjectWriter::recordRelocation(
254249
// FIXME: We should probably just synthesize an external symbol and use
255250
// that.
256251
if (!A_Base) {
257-
Asm.getContext().reportError(
258-
Fixup.getLoc(),
259-
"unsupported relocation of local symbol '" + A->getName() +
260-
"'. Must have non-local symbol earlier in section.");
252+
reportError(Fixup.getLoc(),
253+
"unsupported relocation of local symbol '" + A->getName() +
254+
"'. Must have non-local symbol earlier in section.");
261255
return;
262256
}
263257
if (!B_Base) {
264-
Asm.getContext().reportError(
265-
Fixup.getLoc(),
266-
"unsupported relocation of local symbol '" + B->getName() +
267-
"'. Must have non-local symbol earlier in section.");
258+
reportError(Fixup.getLoc(),
259+
"unsupported relocation of local symbol '" + B->getName() +
260+
"'. Must have non-local symbol earlier in section.");
268261
return;
269262
}
270263

271264
if (A_Base == B_Base && A_Base) {
272-
Asm.getContext().reportError(
273-
Fixup.getLoc(), "unsupported relocation with identical base");
265+
reportError(Fixup.getLoc(), "unsupported relocation with identical base");
274266
return;
275267
}
276268

@@ -303,10 +295,10 @@ void AArch64MachObjectWriter::recordRelocation(
303295
// Make sure that the symbol is actually in a section here. If it isn't,
304296
// emit an error and exit.
305297
if (!Symbol->isInSection()) {
306-
Asm.getContext().reportError(
307-
Fixup.getLoc(),
308-
"unsupported relocation of local symbol '" + Symbol->getName() +
309-
"'. Must have non-local symbol earlier in section.");
298+
reportError(Fixup.getLoc(),
299+
"unsupported relocation of local symbol '" +
300+
Symbol->getName() +
301+
"'. Must have non-local symbol earlier in section.");
310302
return;
311303
}
312304
const MCSection &Sec = Symbol->getSection();
@@ -340,10 +332,10 @@ void AArch64MachObjectWriter::recordRelocation(
340332
Value += Asm.getSymbolOffset(*Symbol) - Asm.getSymbolOffset(*Base);
341333
} else if (Symbol->isInSection()) {
342334
if (!CanUseLocalRelocation) {
343-
Asm.getContext().reportError(
344-
Fixup.getLoc(),
345-
"unsupported relocation of local symbol '" + Symbol->getName() +
346-
"'. Must have non-local symbol earlier in section.");
335+
reportError(Fixup.getLoc(),
336+
"unsupported relocation of local symbol '" +
337+
Symbol->getName() +
338+
"'. Must have non-local symbol earlier in section.");
347339
return;
348340
}
349341
// Adjust the relocation to be section-relative.
@@ -369,8 +361,7 @@ void AArch64MachObjectWriter::recordRelocation(
369361
Type == MachO::ARM64_RELOC_PAGEOFF12) &&
370362
Value) {
371363
if (!isInt<24>(Value)) {
372-
Asm.getContext().reportError(Fixup.getLoc(),
373-
"addend too big for relocation");
364+
reportError(Fixup.getLoc(), "addend too big for relocation");
374365
return;
375366
}
376367

@@ -398,30 +389,27 @@ void AArch64MachObjectWriter::recordRelocation(
398389
assert(Type == MachO::ARM64_RELOC_UNSIGNED);
399390

400391
if (IsPCRel) {
401-
Asm.getContext().reportError(Fixup.getLoc(),
402-
"invalid PC relative auth relocation");
392+
reportError(Fixup.getLoc(), "invalid PC relative auth relocation");
403393
return;
404394
}
405395

406396
if (Log2Size != 3) {
407-
Asm.getContext().reportError(
408-
Fixup.getLoc(), "invalid auth relocation size, must be 8 bytes");
397+
reportError(Fixup.getLoc(),
398+
"invalid auth relocation size, must be 8 bytes");
409399
return;
410400
}
411401

412402
if (Target.getSubSym()) {
413-
Asm.getContext().reportError(
414-
Fixup.getLoc(),
415-
"invalid auth relocation, can't reference two symbols");
403+
reportError(Fixup.getLoc(),
404+
"invalid auth relocation, can't reference two symbols");
416405
return;
417406
}
418407

419408
uint16_t Discriminator = Expr->getDiscriminator();
420409
AArch64PACKey::ID Key = Expr->getKey();
421410

422411
if (!isInt<32>(Value)) {
423-
Asm.getContext().reportError(Fixup.getLoc(),
424-
"addend too big for relocation");
412+
reportError(Fixup.getLoc(), "addend too big for relocation");
425413
return;
426414
}
427415

llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,9 @@ void ARMMachObjectWriter::recordARMScatteredHalfRelocation(
138138
uint32_t FixupOffset = Asm.getFragmentOffset(*Fragment) + Fixup.getOffset();
139139

140140
if (FixupOffset & 0xff000000) {
141-
Asm.getContext().reportError(Fixup.getLoc(),
142-
"can not encode offset '0x" +
143-
utohexstr(FixupOffset) +
144-
"' in resulting scattered relocation.");
141+
reportError(Fixup.getLoc(), "can not encode offset '0x" +
142+
utohexstr(FixupOffset) +
143+
"' in resulting scattered relocation.");
145144
return;
146145
}
147146

@@ -152,9 +151,9 @@ void ARMMachObjectWriter::recordARMScatteredHalfRelocation(
152151
const MCSymbol *A = Target.getAddSym();
153152

154153
if (!A->getFragment()) {
155-
Asm.getContext().reportError(Fixup.getLoc(),
156-
"symbol '" + A->getName() +
157-
"' can not be undefined in a subtraction expression");
154+
reportError(Fixup.getLoc(),
155+
"symbol '" + A->getName() +
156+
"' can not be undefined in a subtraction expression");
158157
return;
159158
}
160159

@@ -165,10 +164,9 @@ void ARMMachObjectWriter::recordARMScatteredHalfRelocation(
165164

166165
if (const MCSymbol *SB = Target.getSubSym()) {
167166
if (!SB->getFragment()) {
168-
Asm.getContext().reportError(
169-
Fixup.getLoc(),
170-
"symbol '" + SB->getName() +
171-
"' can not be undefined in a subtraction expression");
167+
reportError(Fixup.getLoc(),
168+
"symbol '" + SB->getName() +
169+
"' can not be undefined in a subtraction expression");
172170
return;
173171
}
174172

@@ -247,10 +245,9 @@ void ARMMachObjectWriter::recordARMScatteredRelocation(
247245
uint32_t FixupOffset = Asm.getFragmentOffset(*Fragment) + Fixup.getOffset();
248246

249247
if (FixupOffset & 0xff000000) {
250-
Asm.getContext().reportError(Fixup.getLoc(),
251-
"can not encode offset '0x" +
252-
utohexstr(FixupOffset) +
253-
"' in resulting scattered relocation.");
248+
reportError(Fixup.getLoc(), "can not encode offset '0x" +
249+
utohexstr(FixupOffset) +
250+
"' in resulting scattered relocation.");
254251
return;
255252
}
256253

@@ -260,9 +257,9 @@ void ARMMachObjectWriter::recordARMScatteredRelocation(
260257
const MCSymbol *A = Target.getAddSym();
261258

262259
if (!A->getFragment()) {
263-
Asm.getContext().reportError(Fixup.getLoc(),
264-
"symbol '" + A->getName() +
265-
"' can not be undefined in a subtraction expression");
260+
reportError(Fixup.getLoc(),
261+
"symbol '" + A->getName() +
262+
"' can not be undefined in a subtraction expression");
266263
return;
267264
}
268265

@@ -275,10 +272,9 @@ void ARMMachObjectWriter::recordARMScatteredRelocation(
275272
assert(Type == MachO::ARM_RELOC_VANILLA && "invalid reloc for 2 symbols");
276273

277274
if (!SB->getFragment()) {
278-
Asm.getContext().reportError(
279-
Fixup.getLoc(),
280-
"symbol '" + SB->getName() +
281-
"' can not be undefined in a subtraction expression");
275+
reportError(Fixup.getLoc(),
276+
"symbol '" + SB->getName() +
277+
"' can not be undefined in a subtraction expression");
282278
return;
283279
}
284280

@@ -370,7 +366,7 @@ void ARMMachObjectWriter::recordRelocation(MachObjectWriter *Writer,
370366
// relocation type for the fixup kind. This happens when it's a fixup that's
371367
// expected to always be resolvable at assembly time and not have any
372368
// relocations needed.
373-
Asm.getContext().reportError(Fixup.getLoc(), "unsupported relocation type");
369+
reportError(Fixup.getLoc(), "unsupported relocation type");
374370
return;
375371
}
376372

0 commit comments

Comments
 (0)