Skip to content

Commit e3e949c

Browse files
committed
MCELFObjectTargetWriter::needsRelocateWithSymbol: Remove MCSymbol argument
Replace MCSymbol argument with MCValue::AddSym. The minor difference in .weakref handling is negligible, as our implementation may not fully align with GAS, and .weakref is not used in practice.
1 parent f64f4f5 commit e3e949c

File tree

16 files changed

+26
-54
lines changed

16 files changed

+26
-54
lines changed

llvm/include/llvm/MC/MCELFObjectWriter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ class MCELFObjectTargetWriter : public MCObjectTargetWriter {
8888
virtual unsigned getRelocType(const MCFixup &Fixup, const MCValue &Target,
8989
bool IsPCRel) const = 0;
9090

91-
virtual bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
92-
unsigned Type) const;
91+
virtual bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const {
92+
return false;
93+
}
9394

9495
virtual void sortRelocs(std::vector<ELFRelocationEntry> &Relocs);
9596

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,7 @@ bool ELFObjectWriter::useSectionSymbol(const MCValue &Val,
12981298
return false;
12991299
}
13001300

1301-
return !TargetObjectWriter->needsRelocateWithSymbol(Val, *Sym, Type);
1301+
return !TargetObjectWriter->needsRelocateWithSymbol(Val, Type);
13021302
}
13031303

13041304
bool ELFObjectWriter::checkRelocation(SMLoc Loc, const MCSectionELF *From,

llvm/lib/MC/MCELFObjectTargetWriter.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,5 @@ MCELFObjectTargetWriter::MCELFObjectTargetWriter(bool Is64Bit_, uint8_t OSABI_,
1717
: OSABI(OSABI_), ABIVersion(ABIVersion_), EMachine(EMachine_),
1818
HasRelocationAddend(HasRelocationAddend_), Is64Bit(Is64Bit_) {}
1919

20-
bool MCELFObjectTargetWriter::needsRelocateWithSymbol(const MCValue &,
21-
const MCSymbol &,
22-
unsigned Type) const {
23-
return false;
24-
}
25-
2620
void MCELFObjectTargetWriter::sortRelocs(
2721
std::vector<ELFRelocationEntry> &Relocs) {}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ class AArch64ELFObjectWriter : public MCELFObjectTargetWriter {
3838
protected:
3939
unsigned getRelocType(const MCFixup &, const MCValue &,
4040
bool IsPCRel) const override;
41-
bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
42-
unsigned Type) const override;
41+
bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
4342
bool isNonILP32reloc(const MCFixup &Fixup,
4443
AArch64MCExpr::Specifier RefKind) const;
4544

@@ -490,7 +489,6 @@ unsigned AArch64ELFObjectWriter::getRelocType(const MCFixup &Fixup,
490489
}
491490

492491
bool AArch64ELFObjectWriter::needsRelocateWithSymbol(const MCValue &Val,
493-
const MCSymbol &,
494492
unsigned) const {
495493
// For memory-tagged symbols, ensure that the relocation uses the symbol. For
496494
// tagged symbols, we emit an empty relocation (R_AARCH64_NONE) in a special

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ARMELFObjectWriter : public MCELFObjectTargetWriter {
3737
unsigned getRelocType(const MCFixup &, const MCValue &,
3838
bool IsPCRel) const override;
3939

40-
bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
40+
bool needsRelocateWithSymbol(const MCValue &Val,
4141
unsigned Type) const override;
4242
};
4343

@@ -48,14 +48,13 @@ ARMELFObjectWriter::ARMELFObjectWriter(uint8_t OSABI)
4848
ELF::EM_ARM,
4949
/*HasRelocationAddend*/ false) {}
5050

51-
bool ARMELFObjectWriter::needsRelocateWithSymbol(const MCValue &Val,
52-
const MCSymbol &Sym,
51+
bool ARMELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
5352
unsigned Type) const {
5453
// If the symbol is a thumb function the final relocation must set the lowest
5554
// bit. With a symbol that is done by just having the symbol have that bit
5655
// set, so we would lose the bit if we relocated with the section.
5756
// We could use the section but add the bit to the relocation value.
58-
if (Asm->isThumbFunc(Val.getAddSym()))
57+
if (Asm->isThumbFunc(V.getAddSym()))
5958
return true;
6059

6160
// FIXME: This is extremely conservative. This really needs to use an

llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFObjectWriter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ class CSKYELFObjectWriter : public MCELFObjectTargetWriter {
2929

3030
unsigned getRelocType(const MCFixup &, const MCValue &,
3131
bool IsPCRel) const override;
32-
bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
33-
unsigned Type) const override;
32+
bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
3433
};
3534

3635
} // namespace
@@ -166,7 +165,6 @@ unsigned CSKYELFObjectWriter::getRelocType(const MCFixup &Fixup,
166165
}
167166

168167
bool CSKYELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
169-
const MCSymbol &,
170168
unsigned Type) const {
171169
switch (V.getSpecifier()) {
172170
case CSKYMCExpr::VK_PLT:

llvm/lib/Target/Lanai/MCTargetDesc/LanaiELFObjectWriter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ class LanaiELFObjectWriter : public MCELFObjectTargetWriter {
2626
protected:
2727
unsigned getRelocType(const MCFixup &, const MCValue &,
2828
bool IsPCRel) const override;
29-
bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
30-
unsigned Type) const override;
29+
bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
3130
};
3231

3332
} // end anonymous namespace
@@ -71,7 +70,6 @@ unsigned LanaiELFObjectWriter::getRelocType(const MCFixup &Fixup,
7170
}
7271

7372
bool LanaiELFObjectWriter::needsRelocateWithSymbol(const MCValue &,
74-
const MCSymbol &,
7573
unsigned Type) const {
7674
switch (Type) {
7775
case ELF::R_LANAI_21:

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ class LoongArchELFObjectWriter : public MCELFObjectTargetWriter {
2626

2727
~LoongArchELFObjectWriter() override;
2828

29-
bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
30-
unsigned Type) const override {
29+
bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override {
3130
return EnableRelax;
3231
}
3332

llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ class MipsELFObjectWriter : public MCELFObjectTargetWriter {
5050

5151
unsigned getRelocType(const MCFixup &, const MCValue &,
5252
bool IsPCRel) const override;
53-
bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
54-
unsigned Type) const override;
53+
bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
5554
void sortRelocs(std::vector<ELFRelocationEntry> &Relocs) override;
5655
};
5756

@@ -440,15 +439,14 @@ void MipsELFObjectWriter::sortRelocs(std::vector<ELFRelocationEntry> &Relocs) {
440439
Relocs[CopyTo++] = R.R;
441440
}
442441

443-
bool MipsELFObjectWriter::needsRelocateWithSymbol(const MCValue &Val,
444-
const MCSymbol &Sym,
442+
bool MipsELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
445443
unsigned Type) const {
446444
// If it's a compound relocation for N64 then we need the relocation if any
447445
// sub-relocation needs it.
448446
if (!isUInt<8>(Type))
449-
return needsRelocateWithSymbol(Val, Sym, Type & 0xff) ||
450-
needsRelocateWithSymbol(Val, Sym, (Type >> 8) & 0xff) ||
451-
needsRelocateWithSymbol(Val, Sym, (Type >> 16) & 0xff);
447+
return needsRelocateWithSymbol(V, Type & 0xff) ||
448+
needsRelocateWithSymbol(V, (Type >> 8) & 0xff) ||
449+
needsRelocateWithSymbol(V, (Type >> 16) & 0xff);
452450

453451
switch (Type) {
454452
default:
@@ -481,7 +479,7 @@ bool MipsELFObjectWriter::needsRelocateWithSymbol(const MCValue &Val,
481479
// FIXME: It should be safe to return false for the STO_MIPS_MICROMIPS but
482480
// we neglect to handle the adjustment to the LSB of the addend that
483481
// it causes in applyFixup() and similar.
484-
if (cast<MCSymbolELF>(Sym).getOther() & ELF::STO_MIPS_MICROMIPS)
482+
if (cast<MCSymbolELF>(V.getAddSym())->getOther() & ELF::STO_MIPS_MICROMIPS)
485483
return true;
486484
return false;
487485

@@ -492,7 +490,7 @@ bool MipsELFObjectWriter::needsRelocateWithSymbol(const MCValue &Val,
492490
case ELF::R_MIPS_16:
493491
case ELF::R_MIPS_32:
494492
case ELF::R_MIPS_GPREL32:
495-
if (cast<MCSymbolELF>(Sym).getOther() & ELF::STO_MIPS_MICROMIPS)
493+
if (cast<MCSymbolELF>(V.getAddSym())->getOther() & ELF::STO_MIPS_MICROMIPS)
496494
return true;
497495
[[fallthrough]];
498496
case ELF::R_MIPS_26:

llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ namespace {
2828
unsigned getRelocType(const MCFixup &Fixup, const MCValue &Target,
2929
bool IsPCRel) const override;
3030

31-
bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
32-
unsigned Type) const override;
31+
bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
3332
};
3433
}
3534

@@ -487,7 +486,6 @@ unsigned PPCELFObjectWriter::getRelocType(const MCFixup &Fixup,
487486
}
488487

489488
bool PPCELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
490-
const MCSymbol &,
491489
unsigned Type) const {
492490
switch (Type) {
493491
default:
@@ -500,7 +498,7 @@ bool PPCELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
500498
// The "other" values are stored in the last 6 bits of the second byte.
501499
// The traditional defines for STO values assume the full byte and thus
502500
// the shift to pack it.
503-
unsigned Other = cast<MCSymbolELF>(*V.getAddSym()).getOther() << 2;
501+
unsigned Other = cast<MCSymbolELF>(V.getAddSym())->getOther() << 2;
504502
return (Other & ELF::STO_PPC64_LOCAL_MASK) != 0;
505503
}
506504

llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ class RISCVELFObjectWriter : public MCELFObjectTargetWriter {
2727

2828
// Return true if the given relocation must be with a symbol rather than
2929
// section plus offset.
30-
bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
31-
unsigned Type) const override {
30+
bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override {
3231
// TODO: this is very conservative, update once RISC-V psABI requirements
3332
// are clarified.
3433
return true;

llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ namespace {
3535
unsigned getRelocType(const MCFixup &Fixup, const MCValue &Target,
3636
bool IsPCRel) const override;
3737

38-
bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
39-
unsigned Type) const override;
38+
bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
4039
};
4140
}
4241

@@ -119,7 +118,6 @@ unsigned SparcELFObjectWriter::getRelocType(const MCFixup &Fixup,
119118
}
120119

121120
bool SparcELFObjectWriter::needsRelocateWithSymbol(const MCValue &,
122-
const MCSymbol &,
123121
unsigned Type) const {
124122
switch (Type) {
125123
default:

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ class SystemZELFObjectWriter : public MCELFObjectTargetWriter {
3434
// Override MCELFObjectTargetWriter.
3535
unsigned getRelocType(const MCFixup &, const MCValue &,
3636
bool IsPCRel) const override;
37-
bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
38-
unsigned Type) const override;
37+
bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
3938
unsigned getAbsoluteReloc(SMLoc Loc, unsigned Kind) const;
4039
unsigned getPCRelReloc(SMLoc Loc, unsigned Kind) const;
4140
};
@@ -208,7 +207,6 @@ unsigned SystemZELFObjectWriter::getRelocType(const MCFixup &Fixup,
208207
}
209208

210209
bool SystemZELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
211-
const MCSymbol &Sym,
212210
unsigned Type) const {
213211
switch (V.getSpecifier()) {
214212
case SystemZMCExpr::VK_GOT:

llvm/lib/Target/VE/MCTargetDesc/VEELFObjectWriter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ class VEELFObjectWriter : public MCELFObjectTargetWriter {
3232
unsigned getRelocType(const MCFixup &, const MCValue &,
3333
bool IsPCRel) const override;
3434

35-
bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
36-
unsigned Type) const override;
35+
bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
3736
};
3837
} // namespace
3938

@@ -145,7 +144,6 @@ unsigned VEELFObjectWriter::getRelocType(const MCFixup &Fixup,
145144
}
146145

147146
bool VEELFObjectWriter::needsRelocateWithSymbol(const MCValue &,
148-
const MCSymbol &,
149147
unsigned Type) const {
150148
switch (Type) {
151149
default:

llvm/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ class X86ELFObjectWriter : public MCELFObjectTargetWriter {
3535
protected:
3636
unsigned getRelocType(const MCFixup &, const MCValue &,
3737
bool IsPCRel) const override;
38-
bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
39-
unsigned Type) const override;
38+
bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
4039

4140
void checkIs32(SMLoc Loc, X86_64RelType Type) const;
4241
void checkIs64(SMLoc Loc, X86_64RelType Type) const;
@@ -392,7 +391,6 @@ unsigned X86ELFObjectWriter::getRelocType(const MCFixup &Fixup,
392391
}
393392

394393
bool X86ELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
395-
const MCSymbol &Sym,
396394
unsigned Type) const {
397395
switch (V.getSpecifier()) {
398396
case X86MCExpr::VK_GOT:

llvm/lib/Target/Xtensa/MCTargetDesc/XtensaELFObjectWriter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ class XtensaObjectWriter : public MCELFObjectTargetWriter {
3232
protected:
3333
unsigned getRelocType(const MCFixup &, const MCValue &,
3434
bool IsPCRel) const override;
35-
bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
36-
unsigned Type) const override;
35+
bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
3736
};
3837
} // namespace
3938

@@ -61,7 +60,6 @@ llvm::createXtensaObjectWriter(uint8_t OSABI, bool IsLittleEndian) {
6160
}
6261

6362
bool XtensaObjectWriter::needsRelocateWithSymbol(const MCValue &,
64-
const MCSymbol &,
6563
unsigned Type) const {
6664
return false;
6765
}

0 commit comments

Comments
 (0)