diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-05-01 13:24:25 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-05-01 13:24:25 +0000 |
commit | f2b88ce2fd0d204b981f2c6cc70f8112f563fd7c (patch) | |
tree | 0b5d21dc57fa71aa073667a661e53b3e26763381 /lib | |
parent | b378cacf1de326bfba3c784b6d6d848fce6c7ae0 (diff) | |
download | llvm-f2b88ce2fd0d204b981f2c6cc70f8112f563fd7c.tar.gz llvm-f2b88ce2fd0d204b981f2c6cc70f8112f563fd7c.tar.bz2 llvm-f2b88ce2fd0d204b981f2c6cc70f8112f563fd7c.tar.xz |
Move getBaseSymbol somewhere the COFF writer can use.
I will use it there in a second.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207761 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/MC/ELFObjectWriter.cpp | 29 | ||||
-rw-r--r-- | lib/MC/MCAssembler.cpp | 22 |
2 files changed, 25 insertions, 26 deletions
diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index 5e24f91482..3bce121192 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -576,29 +576,6 @@ static uint8_t mergeTypeForSet(uint8_t origType, uint8_t newType) { return Type; } -static const MCSymbol *getBaseSymbol(const MCAsmLayout &Layout, - const MCSymbol &Symbol) { - if (!Symbol.isVariable()) - return &Symbol; - - const MCExpr *Expr = Symbol.getVariableValue(); - MCValue Value; - if (!Expr->EvaluateAsValue(Value, &Layout)) - llvm_unreachable("Invalid Expression"); - - const MCSymbolRefExpr *RefB = Value.getSymB(); - if (RefB) - Layout.getAssembler().getContext().FatalError( - SMLoc(), Twine("symbol '") + RefB->getSymbol().getName() + - "' could not be evaluated in a subtraction expression"); - - const MCSymbolRefExpr *A = Value.getSymA(); - if (!A) - return nullptr; - - return &A->getSymbol(); -} - void ELFObjectWriter::WriteSymbol(SymbolTableWriter &Writer, ELFSymbolData &MSD, const MCAsmLayout &Layout) { MCSymbolData &OrigData = *MSD.SymbolData; @@ -606,7 +583,7 @@ void ELFObjectWriter::WriteSymbol(SymbolTableWriter &Writer, ELFSymbolData &MSD, (&OrigData.getFragment()->getParent()->getSection() == &OrigData.getSymbol().getSection())) && "The symbol's section doesn't match the fragment's symbol"); - const MCSymbol *Base = getBaseSymbol(Layout, OrigData.getSymbol()); + const MCSymbol *Base = Layout.getBaseSymbol(OrigData.getSymbol()); // This has to be in sync with when computeSymbolTable uses SHN_ABS or // SHN_COMMON. @@ -935,7 +912,7 @@ bool ELFObjectWriter::isInSymtab(const MCAsmLayout &Layout, return true; if (Symbol.isVariable()) { - const MCSymbol *Base = getBaseSymbol(Layout, Symbol); + const MCSymbol *Base = Layout.getBaseSymbol(Symbol); if (Base && Base->isUndefined()) return false; } @@ -1022,7 +999,7 @@ ELFObjectWriter::computeSymbolTable(MCAssembler &Asm, const MCAsmLayout &Layout, ELFSymbolData MSD; MSD.SymbolData = &SD; - const MCSymbol *BaseSymbol = getBaseSymbol(Layout, Symbol); + const MCSymbol *BaseSymbol = Layout.getBaseSymbol(Symbol); // Undefined symbols are global, but this is the first place we // are able to set it. diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index c65e44e531..886a5f5545 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -180,6 +180,28 @@ uint64_t MCAsmLayout::getSymbolOffset(const MCSymbolData *SD) const { return Val; } +const MCSymbol *MCAsmLayout::getBaseSymbol(const MCSymbol &Symbol) const { + if (!Symbol.isVariable()) + return &Symbol; + + const MCExpr *Expr = Symbol.getVariableValue(); + MCValue Value; + if (!Expr->EvaluateAsValue(Value, this)) + llvm_unreachable("Invalid Expression"); + + const MCSymbolRefExpr *RefB = Value.getSymB(); + if (RefB) + Assembler.getContext().FatalError( + SMLoc(), Twine("symbol '") + RefB->getSymbol().getName() + + "' could not be evaluated in a subtraction expression"); + + const MCSymbolRefExpr *A = Value.getSymA(); + if (!A) + return nullptr; + + return &A->getSymbol(); +} + uint64_t MCAsmLayout::getSectionAddressSize(const MCSectionData *SD) const { // The size is the last fragment's end offset. const MCFragment &F = SD->getFragmentList().back(); |