/// \brief Get the offset of the given symbol, as computed in the current
/// layout.
/// \return True on success.
- bool getSymbolOffset(const MCSymbolData *SD, uint64_t &Val) const;
+ bool getSymbolOffset(const MCSymbol &S, uint64_t &Val) const;
/// \brief Variant that reports a fatal error if the offset is not computable.
- uint64_t getSymbolOffset(const MCSymbolData *SD) const;
+ uint64_t getSymbolOffset(const MCSymbol &S) const;
/// \brief If this symbol is equivalent to A + Constant, return A.
const MCSymbol *getBaseSymbol(const MCSymbol &Symbol) const;
return Data.getCommonAlignment();
uint64_t Res;
- if (!Layout.getSymbolOffset(&Data, Res))
+ if (!Layout.getSymbolOffset(Data.getSymbol(), Res))
return 0;
if (Layout.getAssembler().isThumbFunc(&Data.getSymbol()))
Asm.getContext().reportFatalError(
Fixup.getLoc(), "Cannot represent a difference across sections");
- const MCSymbolData &SymBD = Asm.getSymbolData(SymB);
- if (::isWeak(SymBD))
+ if (::isWeak(SymB.getData()))
Asm.getContext().reportFatalError(
Fixup.getLoc(), "Cannot represent a subtraction with a weak symbol");
- uint64_t SymBOffset = Layout.getSymbolOffset(&SymBD);
+ uint64_t SymBOffset = Layout.getSymbolOffset(SymB);
uint64_t K = SymBOffset - FixupOffset;
IsPCRel = true;
C -= K;
unsigned Type = GetRelocType(Target, Fixup, IsPCRel);
bool RelocateWithSymbol = shouldRelocateWithSymbol(Asm, RefA, SymAD, C, Type);
if (!RelocateWithSymbol && SymA && !SymA->isUndefined())
- C += Layout.getSymbolOffset(SymAD);
+ C += Layout.getSymbolOffset(*SymA);
uint64_t Addend = 0;
if (hasRelocationAddend()) {
return true;
}
-static bool getSymbolOffsetImpl(const MCAsmLayout &Layout,
- const MCSymbolData *SD, bool ReportError,
- uint64_t &Val) {
- const MCSymbol &S = SD->getSymbol();
-
+static bool getSymbolOffsetImpl(const MCAsmLayout &Layout, const MCSymbol &S,
+ bool ReportError, uint64_t &Val) {
if (!S.isVariable())
- return getLabelOffset(Layout, *SD, ReportError, Val);
+ return getLabelOffset(Layout, S.getData(), ReportError, Val);
// If SD is a variable, evaluate it.
MCValue Target;
return true;
}
-bool MCAsmLayout::getSymbolOffset(const MCSymbolData *SD, uint64_t &Val) const {
- return getSymbolOffsetImpl(*this, SD, false, Val);
+bool MCAsmLayout::getSymbolOffset(const MCSymbol &S, uint64_t &Val) const {
+ return getSymbolOffsetImpl(*this, S, false, Val);
}
-uint64_t MCAsmLayout::getSymbolOffset(const MCSymbolData *SD) const {
+uint64_t MCAsmLayout::getSymbolOffset(const MCSymbol &S) const {
uint64_t Val;
- getSymbolOffsetImpl(*this, SD, true, Val);
+ getSymbolOffsetImpl(*this, S, true, Val);
return Val;
}
if (const MCSymbolRefExpr *A = Target.getSymA()) {
const MCSymbol &Sym = A->getSymbol();
if (Sym.isDefined())
- Value += Layout.getSymbolOffset(&getSymbolData(Sym));
+ Value += Layout.getSymbolOffset(Sym);
}
if (const MCSymbolRefExpr *B = Target.getSymB()) {
const MCSymbol &Sym = B->getSymbol();
if (Sym.isDefined())
- Value -= Layout.getSymbolOffset(&getSymbolData(Sym));
+ Value -= Layout.getSymbolOffset(Sym);
}
return;
// Eagerly evaluate.
- Addend += (Layout->getSymbolOffset(&Asm->getSymbolData(A->getSymbol())) -
- Layout->getSymbolOffset(&Asm->getSymbolData(B->getSymbol())));
+ Addend += Layout->getSymbolOffset(A->getSymbol()) -
+ Layout->getSymbolOffset(B->getSymbol());
if (Addrs && (&SecA != &SecB))
Addend += (Addrs->lookup(&SecA) - Addrs->lookup(&SecB));
}
return getSectionAddress(SD->getFragment()->getParent()) +
- Layout.getSymbolOffset(SD);
+ Layout.getSymbolOffset(S);
}
uint64_t MachObjectWriter::getPaddingSize(const MCSectionData *SD,
return Data.getCommonSize();
uint64_t Res;
- if (!Layout.getSymbolOffset(&Data, Res))
+ if (!Layout.getSymbolOffset(Data.getSymbol(), Res))
return 0;
return Res;
CrossSection = &Symbol.getSection() != &B->getSection();
// Offset of the symbol in the section
- int64_t OffsetOfB = Layout.getSymbolOffset(&B_SD);
+ int64_t OffsetOfB = Layout.getSymbolOffset(*B);
// In the case where we have SymbA and SymB, we just need to store the delta
// between the two symbols. Update FixedValue to account for the delta, and
// skip recording the relocation.
if (!CrossSection) {
- int64_t OffsetOfA = Layout.getSymbolOffset(&A_SD);
+ int64_t OffsetOfA = Layout.getSymbolOffset(A);
FixedValue = (OffsetOfA - OffsetOfB) + Target.getConstant();
return;
}
// ... _foo@got - Ltmp0
if (Target.getSymA()->getKind() == MCSymbolRefExpr::VK_GOT &&
Target.getSymB()->getKind() == MCSymbolRefExpr::VK_None &&
- Layout.getSymbolOffset(&B_SD) ==
+ Layout.getSymbolOffset(*B) ==
Layout.getFragmentOffset(Fragment) + Fixup.getOffset()) {
// SymB is the PC, so use a PC-rel pointer-to-GOT relocation.
Type = MachO::ARM64_RELOC_POINTER_TO_GOT;
RelSymbol = Base;
// Add the local offset, if needed.
- if (&Base->getData() != &SD)
- Value += Layout.getSymbolOffset(&SD) -
- Layout.getSymbolOffset(&Base->getData());
+ if (Base != Symbol)
+ Value +=
+ Layout.getSymbolOffset(*Symbol) - Layout.getSymbolOffset(*Base);
} else if (Symbol->isInSection()) {
if (!CanUseLocalRelocation)
Asm.getContext().reportFatalError(
// compensate for the addend of the symbol address, if it was
// undefined. This occurs with weak definitions, for example.
if (!SD->getSymbol().isUndefined())
- FixedValue -= Layout.getSymbolOffset(SD);
+ FixedValue -= Layout.getSymbolOffset(SD->getSymbol());
} else {
// The index is the section ordinal (1-based).
const MCSectionData &SymSD = Asm.getSectionData(
// compensate for the addend of the symbol address, if it was
// undefined. This occurs with weak definitions, for example.
if (!SD->getSymbol().isUndefined())
- FixedValue -= Layout.getSymbolOffset(SD);
+ FixedValue -= Layout.getSymbolOffset(SD->getSymbol());
} else {
// The index is the section ordinal (1-based).
const MCSectionData &SymSD =
// non-local symbol).
if (RelSymbol) {
// Add the local offset, if needed.
- if (&RelSymbol->getData() != &SD)
- Value += Layout.getSymbolOffset(&SD) -
- Layout.getSymbolOffset(&RelSymbol->getData());
+ if (RelSymbol != Symbol)
+ Value += Layout.getSymbolOffset(*Symbol) -
+ Layout.getSymbolOffset(*RelSymbol);
} else if (Symbol->isInSection() && !Symbol->isVariable()) {
// The index is the section ordinal (1-based).
Index = SD.getFragment()->getParent()->getOrdinal() + 1;
// compensate for the addend of the symbol address, if it was
// undefined. This occurs with weak definitions, for example.
if (!SD->getSymbol().isUndefined())
- FixedValue -= Layout.getSymbolOffset(SD);
+ FixedValue -= Layout.getSymbolOffset(SD->getSymbol());
} else {
// The index is the section ordinal (1-based).
const MCSectionData &SymSD = Asm.getSectionData(