1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

MC/Mach-O: Update getSymbolAddress() to support evaluation of variables.

llvm-svn: 130522
This commit is contained in:
Daniel Dunbar 2011-04-29 18:13:42 +00:00
parent f419ec6362
commit 32545135b1

View File

@ -121,6 +121,33 @@ private:
}
uint64_t getSymbolAddress(const MCSymbolData* SD,
const MCAsmLayout &Layout) const {
const MCSymbol &S = SD->getSymbol();
// If this is a variable, then recursively evaluate now.
if (S.isVariable()) {
MCValue Target;
if (!S.getVariableValue()->EvaluateAsRelocatable(Target, Layout))
report_fatal_error("unable to evaluate offset for variable '" +
S.getName() + "'");
// Verify that any used symbols are defined.
if (Target.getSymA() && Target.getSymA()->getSymbol().isUndefined())
report_fatal_error("unable to evaluate offset to undefined symbol '" +
Target.getSymA()->getSymbol().getName() + "'");
if (Target.getSymB() && Target.getSymB()->getSymbol().isUndefined())
report_fatal_error("unable to evaluate offset to undefined symbol '" +
Target.getSymB()->getSymbol().getName() + "'");
uint64_t Address = Target.getConstant();
if (Target.getSymA())
Address += getSymbolAddress(&Layout.getAssembler().getSymbolData(
Target.getSymA()->getSymbol()), Layout);
if (Target.getSymB())
Address += getSymbolAddress(&Layout.getAssembler().getSymbolData(
Target.getSymB()->getSymbol()), Layout);
return Address;
}
return getSectionAddress(SD->getFragment()->getParent()) +
Layout.getSymbolOffset(SD);
}