[llvm] r207674 - Simplify ELFObjectWriter::SymbolValue.
Rafael Espindola
rafael.espindola at gmail.com
Wed Apr 30 09:59:36 PDT 2014
Author: rafael
Date: Wed Apr 30 11:59:35 2014
New Revision: 207674
URL: http://llvm.org/viewvc/llvm-project?rev=207674&view=rev
Log:
Simplify ELFObjectWriter::SymbolValue.
It now defers all offset computation to getSymbolOffset.
Modified:
llvm/trunk/lib/MC/ELFObjectWriter.cpp
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=207674&r1=207673&r2=207674&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Wed Apr 30 11:59:35 2014
@@ -488,41 +488,33 @@ void ELFObjectWriter::WriteHeader(const
uint64_t ELFObjectWriter::SymbolValue(MCSymbolData &OrigData,
const MCAsmLayout &Layout) {
- const MCSymbol &OrigSymbol = OrigData.getSymbol();
MCSymbolData *Data = &OrigData;
if (Data->isCommon() && Data->isExternal())
return Data->getCommonAlignment();
const MCSymbol *Symbol = &Data->getSymbol();
+ MCAssembler &Asm = Layout.getAssembler();
+ bool IsThumb = Asm.isThumbFunc(Symbol);
- uint64_t Res = 0;
+ // Given how we implement symver, we can end up with an symbol reference
+ // to an undefined symbol. Walk past it first.
if (Symbol->isVariable()) {
const MCExpr *Expr = Symbol->getVariableValue();
- MCValue Value;
- if (!Expr->EvaluateAsValue(Value, &Layout))
- llvm_unreachable("Invalid expression");
-
- assert(!Value.getSymB());
-
- Res = Value.getConstant();
-
- if (const MCSymbolRefExpr *A = Value.getSymA()) {
- Symbol = &A->getSymbol();
- Data = &Layout.getAssembler().getSymbolData(*Symbol);
- } else {
- Symbol = nullptr;
- Data = nullptr;
+ if (auto *Ref = dyn_cast<MCSymbolRefExpr>(Expr)) {
+ if (Ref->getKind() == MCSymbolRefExpr::VK_None) {
+ Symbol = &Ref->getSymbol();
+ Data = &Asm.getOrCreateSymbolData(*Symbol);
+ }
}
}
- const MCAssembler &Asm = Layout.getAssembler();
- if (Asm.isThumbFunc(&OrigSymbol))
- Res |= 1;
+ if (!Symbol->isVariable() && !Data->getFragment())
+ return 0;
- if (!Symbol || !Symbol->isInSection())
- return Res;
+ uint64_t Res = Layout.getSymbolOffset(Data);
- Res += Layout.getSymbolOffset(Data);
+ if (IsThumb)
+ Res |= 1;
return Res;
}
More information about the llvm-commits
mailing list