mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-07 14:33:15 +00:00
Simplify ELFObjectWriter::SymbolValue.
It now defers all offset computation to getSymbolOffset. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207674 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1afb0ccb40
commit
1c37cbdf54
@ -488,42 +488,34 @@ void ELFObjectWriter::WriteHeader(const MCAssembler &Asm,
|
||||
|
||||
uint64_t ELFObjectWriter::SymbolValue(MCSymbolData &OrigData,
|
||||
const MCAsmLayout &Layout) {
|
||||
const MCSymbol &OrigSymbol = OrigData.getSymbol();
|
||||
MCSymbolData *Data = &OrigData;
|
||||
if (Data->isCommon() && Data->isExternal())
|
||||
return Data->getCommonAlignment();
|
||||
|
||||
const MCSymbol *Symbol = &Data->getSymbol();
|
||||
MCAssembler &Asm = Layout.getAssembler();
|
||||
bool IsThumb = Asm.isThumbFunc(Symbol);
|
||||
|
||||
uint64_t Res = 0;
|
||||
// Given how we implement symver, we can end up with an symbol reference
|
||||
// to an undefined symbol. Walk past it first.
|
||||
if (Symbol->isVariable()) {
|
||||
const MCExpr *Expr = Symbol->getVariableValue();
|
||||
MCValue Value;
|
||||
if (!Expr->EvaluateAsValue(Value, &Layout))
|
||||
llvm_unreachable("Invalid expression");
|
||||
|
||||
assert(!Value.getSymB());
|
||||
|
||||
Res = Value.getConstant();
|
||||
|
||||
if (const MCSymbolRefExpr *A = Value.getSymA()) {
|
||||
Symbol = &A->getSymbol();
|
||||
Data = &Layout.getAssembler().getSymbolData(*Symbol);
|
||||
} else {
|
||||
Symbol = nullptr;
|
||||
Data = nullptr;
|
||||
if (auto *Ref = dyn_cast<MCSymbolRefExpr>(Expr)) {
|
||||
if (Ref->getKind() == MCSymbolRefExpr::VK_None) {
|
||||
Symbol = &Ref->getSymbol();
|
||||
Data = &Asm.getOrCreateSymbolData(*Symbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const MCAssembler &Asm = Layout.getAssembler();
|
||||
if (Asm.isThumbFunc(&OrigSymbol))
|
||||
if (!Symbol->isVariable() && !Data->getFragment())
|
||||
return 0;
|
||||
|
||||
uint64_t Res = Layout.getSymbolOffset(Data);
|
||||
|
||||
if (IsThumb)
|
||||
Res |= 1;
|
||||
|
||||
if (!Symbol || !Symbol->isInSection())
|
||||
return Res;
|
||||
|
||||
Res += Layout.getSymbolOffset(Data);
|
||||
|
||||
return Res;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user