summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC/MCSymbol.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-03-14 20:09:04 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-03-14 20:09:04 +0000
commit8953f81f671fc6077b46ac1f600b4d29456aa265 (patch)
treee9e39ed279c17c796b695d730f3f810a92581cd4 /llvm/lib/MC/MCSymbol.cpp
parent622831b7399d0672d390c3ada9726febf8d86e6a (diff)
downloadbcm5719-llvm-8953f81f671fc6077b46ac1f600b4d29456aa265.tar.gz
bcm5719-llvm-8953f81f671fc6077b46ac1f600b4d29456aa265.zip
Correctly handle an ELF symbol defined with "a = b + expr".
We were marking the symbol as absolute instead of computing b's offset + the expression value. This fixes pr19126. llvm-svn: 203962
Diffstat (limited to 'llvm/lib/MC/MCSymbol.cpp')
-rw-r--r--llvm/lib/MC/MCSymbol.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/MC/MCSymbol.cpp b/llvm/lib/MC/MCSymbol.cpp
index 24165254e56..d0283a635be 100644
--- a/llvm/lib/MC/MCSymbol.cpp
+++ b/llvm/lib/MC/MCSymbol.cpp
@@ -9,6 +9,7 @@
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCExpr.h"
+#include "llvm/MC/MCValue.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
@@ -51,6 +52,22 @@ const MCSymbol &MCSymbol::AliasedSymbol() const {
return *S;
}
+const MCSymbol *MCSymbol::getBaseSymbol(const MCAsmLayout &Layout) const {
+ if (!isVariable())
+ return this;
+
+ const MCExpr *Expr = getVariableValue();
+ MCValue Value;
+ if (!Expr->EvaluateAsRelocatable(Value, &Layout))
+ return nullptr;
+
+ if (Value.getSymB())
+ return nullptr;
+ if (const MCSymbolRefExpr *A = Value.getSymA())
+ return &A->getSymbol();
+ return nullptr;
+}
+
void MCSymbol::setVariableValue(const MCExpr *Value) {
assert(!IsUsed && "Cannot set a variable that has already been used.");
assert(Value && "Invalid variable value!");
OpenPOWER on IntegriCloud