mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-20 16:17:38 +00:00
Fix pr19645.
The fix itself is fairly simple: move getAccessVariant to MCValue so that we replace the old weak expression evaluation with the far more general EvaluateAsRelocatable. This then requires that EvaluateAsRelocatable stop when it finds a non trivial reference kind. And that in turn requires the ELF writer to look harder for weak references. Last but not least, this found a case where we were being bug by bug compatible with gas and accepting an invalid input. I reported pr19647 to track it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207920 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -787,6 +787,25 @@ bool ELFObjectWriter::shouldRelocateWithSymbol(const MCAssembler &Asm,
|
||||
return false;
|
||||
}
|
||||
|
||||
static const MCSymbol *getWeakRef(const MCSymbolRefExpr &Ref) {
|
||||
const MCSymbol &Sym = Ref.getSymbol();
|
||||
|
||||
if (Ref.getKind() == MCSymbolRefExpr::VK_WEAKREF)
|
||||
return &Sym;
|
||||
|
||||
if (!Sym.isVariable())
|
||||
return nullptr;
|
||||
|
||||
const MCExpr *Expr = Sym.getVariableValue();
|
||||
const auto *Inner = dyn_cast<MCSymbolRefExpr>(Expr);
|
||||
if (!Inner)
|
||||
return nullptr;
|
||||
|
||||
if (Inner->getKind() == MCSymbolRefExpr::VK_WEAKREF)
|
||||
return &Inner->getSymbol();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
|
||||
const MCAsmLayout &Layout,
|
||||
const MCFragment *Fragment,
|
||||
@@ -872,8 +891,8 @@ void ELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
|
||||
if (const MCSymbol *R = Renames.lookup(SymA))
|
||||
SymA = R;
|
||||
|
||||
if (RefA->getKind() == MCSymbolRefExpr::VK_WEAKREF)
|
||||
WeakrefUsedInReloc.insert(SymA);
|
||||
if (const MCSymbol *WeakRef = getWeakRef(*RefA))
|
||||
WeakrefUsedInReloc.insert(WeakRef);
|
||||
else
|
||||
UsedInReloc.insert(SymA);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user