mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-26 21:32:10 +00:00
MCAsmLayout: Add support for computing the symbol offset of variables. Not
currently used, because variables don't get reported as being "defined". git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130524 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
90604ab725
commit
c8497b6a25
@ -102,6 +102,33 @@ uint64_t MCAsmLayout::getFragmentOffset(const MCFragment *F) const {
|
||||
}
|
||||
|
||||
uint64_t MCAsmLayout::getSymbolOffset(const MCSymbolData *SD) 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, *this))
|
||||
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 Offset = Target.getConstant();
|
||||
if (Target.getSymA())
|
||||
Offset += getSymbolOffset(&Assembler.getSymbolData(
|
||||
Target.getSymA()->getSymbol()));
|
||||
if (Target.getSymB())
|
||||
Offset -= getSymbolOffset(&Assembler.getSymbolData(
|
||||
Target.getSymB()->getSymbol()));
|
||||
return Offset;
|
||||
}
|
||||
|
||||
assert(SD->getFragment() && "Invalid getOffset() on undefined symbol!");
|
||||
return getFragmentOffset(SD->getFragment()) + SD->getOffset();
|
||||
}
|
||||
|
8
test/MC/MachO/variable-errors.s
Normal file
8
test/MC/MachO/variable-errors.s
Normal file
@ -0,0 +1,8 @@
|
||||
// RUN: not llvm-mc -triple x86_64-apple-darwin10 %s -filetype=obj -o %t.o 2> %t.err
|
||||
// RUN: FileCheck < %t.err %s
|
||||
|
||||
.data
|
||||
t0_a:
|
||||
t0_x = t0_a - t0_b
|
||||
// CHECK: unable to evaluate offset to undefined symbol 't0_b'
|
||||
.long t0_x
|
Loading…
Reference in New Issue
Block a user