Skip to content

Commit c39d393

Browse files
committed
ELFObjectWriter: Remove relocation specifier test from shouldRelocateWithSymbol
It's the decision of backend needsRelocateWithSymbol whether the STT_SECTION adjustment should be suppressed. test/MC/AArch64/data-directive-specifier.s demonstrates how to test this property.
1 parent e396681 commit c39d393

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,21 +1257,6 @@ bool ELFObjectWriter::shouldRelocateWithSymbol(const MCAssembler &Asm,
12571257
if (!RefA)
12581258
return false;
12591259

1260-
MCSymbolRefExpr::VariantKind Kind = RefA->getKind();
1261-
switch (Kind) {
1262-
default:
1263-
break;
1264-
1265-
// These VariantKind cause the relocation to refer to something other than
1266-
// the symbol itself, like a linker generated table. Since the address of
1267-
// symbol is not relevant, we cannot replace the symbol with the
1268-
// section and patch the difference in the addend.
1269-
case MCSymbolRefExpr::VK_GOT:
1270-
case MCSymbolRefExpr::VK_PLT:
1271-
case MCSymbolRefExpr::VK_GOTPCREL:
1272-
return true;
1273-
}
1274-
12751260
// An undefined symbol is not in any section, so the relocation has to point
12761261
// to the symbol itself.
12771262
assert(Sym && "Expected a symbol");

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,10 @@ unsigned AArch64ELFObjectWriter::getRelocType(MCContext &Ctx,
543543
bool AArch64ELFObjectWriter::needsRelocateWithSymbol(const MCValue &Val,
544544
const MCSymbol &,
545545
unsigned) const {
546-
return (Val.getRefKind() & AArch64MCExpr::VK_GOT) == AArch64MCExpr::VK_GOT;
546+
if ((Val.getRefKind() & AArch64MCExpr::VK_GOT) == AArch64MCExpr::VK_GOT)
547+
return true;
548+
return is_contained({MCSymbolRefExpr::VK_GOTPCREL, MCSymbolRefExpr::VK_PLT},
549+
Val.getAccessVariant());
547550
}
548551

549552
std::unique_ptr<MCObjectTargetWriter>

0 commit comments

Comments
 (0)