diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/MC/MCAssembler.cpp | 10 | ||||
-rw-r--r-- | lib/MC/MCExpr.cpp | 22 |
2 files changed, 28 insertions, 4 deletions
diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 21feeedd67..8d0075e93b 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -539,10 +539,10 @@ public: if (Target.isAbsolute()) { // constant // SymbolNum of 0 indicates the absolute section. // - // FIXME: When is this generated? + // FIXME: Currently, these are never generated (see code below). I cannot + // find a case where they are actually emitted. Type = RIT_Vanilla; Value = 0; - llvm_unreachable("FIXME: Not yet implemented!"); } else { const MCSymbol *Symbol = Target.getSymA(); MCSymbolData *SD = &Asm.getSymbolData(*Symbol); @@ -572,6 +572,12 @@ public: if (IsPCRel) Fixup.FixedValue -= Address; + // If the target evaluates to a constant, we don't need a relocation. This + // occurs with absolutized expressions which are not resolved to constants + // until after relaxation. + if (Target.isAbsolute()) + return; + // If this fixup is a vanilla PC relative relocation for a local label, we // don't need a relocation. // diff --git a/lib/MC/MCExpr.cpp b/lib/MC/MCExpr.cpp index e364069151..0ca2ad8761 100644 --- a/lib/MC/MCExpr.cpp +++ b/lib/MC/MCExpr.cpp @@ -8,11 +8,14 @@ //===----------------------------------------------------------------------===// #include "llvm/MC/MCExpr.h" +#include "llvm/MC/MCAsmLayout.h" +#include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCValue.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Target/TargetAsmBackend.h" using namespace llvm; void MCExpr::print(raw_ostream &OS) const { @@ -187,8 +190,23 @@ bool MCExpr::EvaluateAsRelocatable(MCValue &Res, MCAsmLayout *Layout) const { const MCSymbol &Sym = cast<MCSymbolRefExpr>(this)->getSymbol(); // Evaluate recursively if this is a variable. - if (Sym.isVariable()) - return Sym.getValue()->EvaluateAsRelocatable(Res, Layout); + if (Sym.isVariable()) { + if (!Sym.getValue()->EvaluateAsRelocatable(Res, Layout)) + return false; + + // Absolutize symbol differences when we have a layout object and the + // target requests it. + if (Layout && Res.getSymB() && + Layout->getAssembler().getBackend().hasAbsolutizedSet()) { + MCSymbolData &A = Layout->getAssembler().getSymbolData(*Res.getSymA()); + MCSymbolData &B = Layout->getAssembler().getSymbolData(*Res.getSymB()); + Res = MCValue::get(+ A.getFragment()->getAddress() + A.getOffset() + - B.getFragment()->getAddress() - B.getOffset() + + Res.getConstant()); + } + + return true; + } Res = MCValue::get(&Sym, 0, 0); return true; |