[llvm] e3e949c - MCELFObjectTargetWriter::needsRelocateWithSymbol: Remove MCSymbol argument
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat May 24 23:55:32 PDT 2025
Author: Fangrui Song
Date: 2025-05-24T23:55:26-07:00
New Revision: e3e949cf5b9d9d6647b27aafd6aebf3fe02378b5
URL: https://github.com/llvm/llvm-project/commit/e3e949cf5b9d9d6647b27aafd6aebf3fe02378b5
DIFF: https://github.com/llvm/llvm-project/commit/e3e949cf5b9d9d6647b27aafd6aebf3fe02378b5.diff
LOG: 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.
Added:
Modified:
llvm/include/llvm/MC/MCELFObjectWriter.h
llvm/lib/MC/ELFObjectWriter.cpp
llvm/lib/MC/MCELFObjectTargetWriter.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFObjectWriter.cpp
llvm/lib/Target/Lanai/MCTargetDesc/LanaiELFObjectWriter.cpp
llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp
llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp
llvm/lib/Target/VE/MCTargetDesc/VEELFObjectWriter.cpp
llvm/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp
llvm/lib/Target/Xtensa/MCTargetDesc/XtensaELFObjectWriter.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCELFObjectWriter.h b/llvm/include/llvm/MC/MCELFObjectWriter.h
index e4b1940498a0b..143979fa189df 100644
--- a/llvm/include/llvm/MC/MCELFObjectWriter.h
+++ b/llvm/include/llvm/MC/MCELFObjectWriter.h
@@ -88,8 +88,9 @@ class MCELFObjectTargetWriter : public MCObjectTargetWriter {
virtual unsigned getRelocType(const MCFixup &Fixup, const MCValue &Target,
bool IsPCRel) const = 0;
- virtual bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
- unsigned Type) const;
+ virtual bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const {
+ return false;
+ }
virtual void sortRelocs(std::vector<ELFRelocationEntry> &Relocs);
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index ed3663056f0e0..77b3d074f0208 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -1298,7 +1298,7 @@ bool ELFObjectWriter::useSectionSymbol(const MCValue &Val,
return false;
}
- return !TargetObjectWriter->needsRelocateWithSymbol(Val, *Sym, Type);
+ return !TargetObjectWriter->needsRelocateWithSymbol(Val, Type);
}
bool ELFObjectWriter::checkRelocation(SMLoc Loc, const MCSectionELF *From,
diff --git a/llvm/lib/MC/MCELFObjectTargetWriter.cpp b/llvm/lib/MC/MCELFObjectTargetWriter.cpp
index 39894d3736f14..b3cb1e001621a 100644
--- a/llvm/lib/MC/MCELFObjectTargetWriter.cpp
+++ b/llvm/lib/MC/MCELFObjectTargetWriter.cpp
@@ -17,11 +17,5 @@ MCELFObjectTargetWriter::MCELFObjectTargetWriter(bool Is64Bit_, uint8_t OSABI_,
: OSABI(OSABI_), ABIVersion(ABIVersion_), EMachine(EMachine_),
HasRelocationAddend(HasRelocationAddend_), Is64Bit(Is64Bit_) {}
-bool MCELFObjectTargetWriter::needsRelocateWithSymbol(const MCValue &,
- const MCSymbol &,
- unsigned Type) const {
- return false;
-}
-
void MCELFObjectTargetWriter::sortRelocs(
std::vector<ELFRelocationEntry> &Relocs) {}
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
index 992c9d9105ae7..df2e13a35dcbd 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
@@ -38,8 +38,7 @@ class AArch64ELFObjectWriter : public MCELFObjectTargetWriter {
protected:
unsigned getRelocType(const MCFixup &, const MCValue &,
bool IsPCRel) const override;
- bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
- unsigned Type) const override;
+ bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
bool isNonILP32reloc(const MCFixup &Fixup,
AArch64MCExpr::Specifier RefKind) const;
@@ -490,7 +489,6 @@ unsigned AArch64ELFObjectWriter::getRelocType(const MCFixup &Fixup,
}
bool AArch64ELFObjectWriter::needsRelocateWithSymbol(const MCValue &Val,
- const MCSymbol &,
unsigned) const {
// For memory-tagged symbols, ensure that the relocation uses the symbol. For
// tagged symbols, we emit an empty relocation (R_AARCH64_NONE) in a special
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
index dcf98659fe8a8..5398a43dd1ca0 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
@@ -37,7 +37,7 @@ class ARMELFObjectWriter : public MCELFObjectTargetWriter {
unsigned getRelocType(const MCFixup &, const MCValue &,
bool IsPCRel) const override;
- bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
+ bool needsRelocateWithSymbol(const MCValue &Val,
unsigned Type) const override;
};
@@ -48,14 +48,13 @@ ARMELFObjectWriter::ARMELFObjectWriter(uint8_t OSABI)
ELF::EM_ARM,
/*HasRelocationAddend*/ false) {}
-bool ARMELFObjectWriter::needsRelocateWithSymbol(const MCValue &Val,
- const MCSymbol &Sym,
+bool ARMELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
unsigned Type) const {
// If the symbol is a thumb function the final relocation must set the lowest
// bit. With a symbol that is done by just having the symbol have that bit
// set, so we would lose the bit if we relocated with the section.
// We could use the section but add the bit to the relocation value.
- if (Asm->isThumbFunc(Val.getAddSym()))
+ if (Asm->isThumbFunc(V.getAddSym()))
return true;
// FIXME: This is extremely conservative. This really needs to use an
diff --git a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFObjectWriter.cpp b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFObjectWriter.cpp
index 6bdd5e53cafdb..0a2087db3fee4 100644
--- a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFObjectWriter.cpp
+++ b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYELFObjectWriter.cpp
@@ -29,8 +29,7 @@ class CSKYELFObjectWriter : public MCELFObjectTargetWriter {
unsigned getRelocType(const MCFixup &, const MCValue &,
bool IsPCRel) const override;
- bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
- unsigned Type) const override;
+ bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
};
} // namespace
@@ -166,7 +165,6 @@ unsigned CSKYELFObjectWriter::getRelocType(const MCFixup &Fixup,
}
bool CSKYELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
- const MCSymbol &,
unsigned Type) const {
switch (V.getSpecifier()) {
case CSKYMCExpr::VK_PLT:
diff --git a/llvm/lib/Target/Lanai/MCTargetDesc/LanaiELFObjectWriter.cpp b/llvm/lib/Target/Lanai/MCTargetDesc/LanaiELFObjectWriter.cpp
index eeb99e86602af..b81cdff917ea5 100644
--- a/llvm/lib/Target/Lanai/MCTargetDesc/LanaiELFObjectWriter.cpp
+++ b/llvm/lib/Target/Lanai/MCTargetDesc/LanaiELFObjectWriter.cpp
@@ -26,8 +26,7 @@ class LanaiELFObjectWriter : public MCELFObjectTargetWriter {
protected:
unsigned getRelocType(const MCFixup &, const MCValue &,
bool IsPCRel) const override;
- bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
- unsigned Type) const override;
+ bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
};
} // end anonymous namespace
@@ -71,7 +70,6 @@ unsigned LanaiELFObjectWriter::getRelocType(const MCFixup &Fixup,
}
bool LanaiELFObjectWriter::needsRelocateWithSymbol(const MCValue &,
- const MCSymbol &,
unsigned Type) const {
switch (Type) {
case ELF::R_LANAI_21:
diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
index 0ee354c3cfd57..c1cb8ed1f14d0 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
@@ -26,8 +26,7 @@ class LoongArchELFObjectWriter : public MCELFObjectTargetWriter {
~LoongArchELFObjectWriter() override;
- bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
- unsigned Type) const override {
+ bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override {
return EnableRelax;
}
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
index 549f342f493f5..d5e19ccaa1689 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
@@ -50,8 +50,7 @@ class MipsELFObjectWriter : public MCELFObjectTargetWriter {
unsigned getRelocType(const MCFixup &, const MCValue &,
bool IsPCRel) const override;
- bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
- unsigned Type) const override;
+ bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
void sortRelocs(std::vector<ELFRelocationEntry> &Relocs) override;
};
@@ -440,15 +439,14 @@ void MipsELFObjectWriter::sortRelocs(std::vector<ELFRelocationEntry> &Relocs) {
Relocs[CopyTo++] = R.R;
}
-bool MipsELFObjectWriter::needsRelocateWithSymbol(const MCValue &Val,
- const MCSymbol &Sym,
+bool MipsELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
unsigned Type) const {
// If it's a compound relocation for N64 then we need the relocation if any
// sub-relocation needs it.
if (!isUInt<8>(Type))
- return needsRelocateWithSymbol(Val, Sym, Type & 0xff) ||
- needsRelocateWithSymbol(Val, Sym, (Type >> 8) & 0xff) ||
- needsRelocateWithSymbol(Val, Sym, (Type >> 16) & 0xff);
+ return needsRelocateWithSymbol(V, Type & 0xff) ||
+ needsRelocateWithSymbol(V, (Type >> 8) & 0xff) ||
+ needsRelocateWithSymbol(V, (Type >> 16) & 0xff);
switch (Type) {
default:
@@ -481,7 +479,7 @@ bool MipsELFObjectWriter::needsRelocateWithSymbol(const MCValue &Val,
// FIXME: It should be safe to return false for the STO_MIPS_MICROMIPS but
// we neglect to handle the adjustment to the LSB of the addend that
// it causes in applyFixup() and similar.
- if (cast<MCSymbolELF>(Sym).getOther() & ELF::STO_MIPS_MICROMIPS)
+ if (cast<MCSymbolELF>(V.getAddSym())->getOther() & ELF::STO_MIPS_MICROMIPS)
return true;
return false;
@@ -492,7 +490,7 @@ bool MipsELFObjectWriter::needsRelocateWithSymbol(const MCValue &Val,
case ELF::R_MIPS_16:
case ELF::R_MIPS_32:
case ELF::R_MIPS_GPREL32:
- if (cast<MCSymbolELF>(Sym).getOther() & ELF::STO_MIPS_MICROMIPS)
+ if (cast<MCSymbolELF>(V.getAddSym())->getOther() & ELF::STO_MIPS_MICROMIPS)
return true;
[[fallthrough]];
case ELF::R_MIPS_26:
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
index 5f6815d949474..096c019f8556e 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
@@ -28,8 +28,7 @@ namespace {
unsigned getRelocType(const MCFixup &Fixup, const MCValue &Target,
bool IsPCRel) const override;
- bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
- unsigned Type) const override;
+ bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
};
}
@@ -487,7 +486,6 @@ unsigned PPCELFObjectWriter::getRelocType(const MCFixup &Fixup,
}
bool PPCELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
- const MCSymbol &,
unsigned Type) const {
switch (Type) {
default:
@@ -500,7 +498,7 @@ bool PPCELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
// The "other" values are stored in the last 6 bits of the second byte.
// The traditional defines for STO values assume the full byte and thus
// the shift to pack it.
- unsigned Other = cast<MCSymbolELF>(*V.getAddSym()).getOther() << 2;
+ unsigned Other = cast<MCSymbolELF>(V.getAddSym())->getOther() << 2;
return (Other & ELF::STO_PPC64_LOCAL_MASK) != 0;
}
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
index 3955e97feca33..378554adc803d 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
@@ -27,8 +27,7 @@ class RISCVELFObjectWriter : public MCELFObjectTargetWriter {
// Return true if the given relocation must be with a symbol rather than
// section plus offset.
- bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
- unsigned Type) const override {
+ bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override {
// TODO: this is very conservative, update once RISC-V psABI requirements
// are clarified.
return true;
diff --git a/llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp b/llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp
index 40bc484a48532..bef7f3c02dae3 100644
--- a/llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp
+++ b/llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp
@@ -35,8 +35,7 @@ namespace {
unsigned getRelocType(const MCFixup &Fixup, const MCValue &Target,
bool IsPCRel) const override;
- bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
- unsigned Type) const override;
+ bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
};
}
@@ -119,7 +118,6 @@ unsigned SparcELFObjectWriter::getRelocType(const MCFixup &Fixup,
}
bool SparcELFObjectWriter::needsRelocateWithSymbol(const MCValue &,
- const MCSymbol &,
unsigned Type) const {
switch (Type) {
default:
diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp
index 94bf2cadb1901..b44859d75df0f 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZELFObjectWriter.cpp
@@ -34,8 +34,7 @@ class SystemZELFObjectWriter : public MCELFObjectTargetWriter {
// Override MCELFObjectTargetWriter.
unsigned getRelocType(const MCFixup &, const MCValue &,
bool IsPCRel) const override;
- bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
- unsigned Type) const override;
+ bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
unsigned getAbsoluteReloc(SMLoc Loc, unsigned Kind) const;
unsigned getPCRelReloc(SMLoc Loc, unsigned Kind) const;
};
@@ -208,7 +207,6 @@ unsigned SystemZELFObjectWriter::getRelocType(const MCFixup &Fixup,
}
bool SystemZELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
- const MCSymbol &Sym,
unsigned Type) const {
switch (V.getSpecifier()) {
case SystemZMCExpr::VK_GOT:
diff --git a/llvm/lib/Target/VE/MCTargetDesc/VEELFObjectWriter.cpp b/llvm/lib/Target/VE/MCTargetDesc/VEELFObjectWriter.cpp
index 2984c862c4bc6..e707bb2fe3e1d 100644
--- a/llvm/lib/Target/VE/MCTargetDesc/VEELFObjectWriter.cpp
+++ b/llvm/lib/Target/VE/MCTargetDesc/VEELFObjectWriter.cpp
@@ -32,8 +32,7 @@ class VEELFObjectWriter : public MCELFObjectTargetWriter {
unsigned getRelocType(const MCFixup &, const MCValue &,
bool IsPCRel) const override;
- bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
- unsigned Type) const override;
+ bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
};
} // namespace
@@ -145,7 +144,6 @@ unsigned VEELFObjectWriter::getRelocType(const MCFixup &Fixup,
}
bool VEELFObjectWriter::needsRelocateWithSymbol(const MCValue &,
- const MCSymbol &,
unsigned Type) const {
switch (Type) {
default:
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp
index b2451511e363f..13f2a76051df9 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp
@@ -35,8 +35,7 @@ class X86ELFObjectWriter : public MCELFObjectTargetWriter {
protected:
unsigned getRelocType(const MCFixup &, const MCValue &,
bool IsPCRel) const override;
- bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
- unsigned Type) const override;
+ bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
void checkIs32(SMLoc Loc, X86_64RelType Type) const;
void checkIs64(SMLoc Loc, X86_64RelType Type) const;
@@ -392,7 +391,6 @@ unsigned X86ELFObjectWriter::getRelocType(const MCFixup &Fixup,
}
bool X86ELFObjectWriter::needsRelocateWithSymbol(const MCValue &V,
- const MCSymbol &Sym,
unsigned Type) const {
switch (V.getSpecifier()) {
case X86MCExpr::VK_GOT:
diff --git a/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaELFObjectWriter.cpp b/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaELFObjectWriter.cpp
index 68cf5d999254c..f2c391b03bd4e 100644
--- a/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaELFObjectWriter.cpp
+++ b/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaELFObjectWriter.cpp
@@ -32,8 +32,7 @@ class XtensaObjectWriter : public MCELFObjectTargetWriter {
protected:
unsigned getRelocType(const MCFixup &, const MCValue &,
bool IsPCRel) const override;
- bool needsRelocateWithSymbol(const MCValue &Val, const MCSymbol &Sym,
- unsigned Type) const override;
+ bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const override;
};
} // namespace
@@ -61,7 +60,6 @@ llvm::createXtensaObjectWriter(uint8_t OSABI, bool IsLittleEndian) {
}
bool XtensaObjectWriter::needsRelocateWithSymbol(const MCValue &,
- const MCSymbol &,
unsigned Type) const {
return false;
}
More information about the llvm-commits
mailing list