[llvm] r207761 - Move getBaseSymbol somewhere the COFF writer can use.
Rafael Espindola
rafael.espindola at gmail.com
Thu May 1 06:24:26 PDT 2014
Author: rafael
Date: Thu May 1 08:24:25 2014
New Revision: 207761
URL: http://llvm.org/viewvc/llvm-project?rev=207761&view=rev
Log:
Move getBaseSymbol somewhere the COFF writer can use.
I will use it there in a second.
Modified:
llvm/trunk/include/llvm/MC/MCAsmLayout.h
llvm/trunk/lib/MC/ELFObjectWriter.cpp
llvm/trunk/lib/MC/MCAssembler.cpp
Modified: llvm/trunk/include/llvm/MC/MCAsmLayout.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAsmLayout.h?rev=207761&r1=207760&r2=207761&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAsmLayout.h (original)
+++ llvm/trunk/include/llvm/MC/MCAsmLayout.h Thu May 1 08:24:25 2014
@@ -17,6 +17,7 @@ namespace llvm {
class MCAssembler;
class MCFragment;
class MCSectionData;
+class MCSymbol;
class MCSymbolData;
/// Encapsulates the layout of an assembly file at a particular point in time.
@@ -108,6 +109,9 @@ public:
/// \brief Variant that reports a fatal error if the offset is not computable.
uint64_t getSymbolOffset(const MCSymbolData *SD) const;
+ /// \brief If this symbol is equivalent to A + Constant, return A.
+ const MCSymbol *getBaseSymbol(const MCSymbol &Symbol) const;
+
/// @}
};
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=207761&r1=207760&r2=207761&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Thu May 1 08:24:25 2014
@@ -576,29 +576,6 @@ static uint8_t mergeTypeForSet(uint8_t o
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(Symbol
(&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 M
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(MCAs
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.
Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=207761&r1=207760&r2=207761&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Thu May 1 08:24:25 2014
@@ -180,6 +180,28 @@ uint64_t MCAsmLayout::getSymbolOffset(co
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();
More information about the llvm-commits
mailing list