aboutsummaryrefslogtreecommitdiffstats
path: root/lib/MC
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2010-10-05 21:02:45 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2010-10-05 21:02:45 +0000
commit62fed8bd380b67f47bde3ff2a437db0951c7d186 (patch)
treef68ce414732974420fde2310b68851f21b84760c /lib/MC
parent748a2fe9171842e6f999badf84d08c43bd8585ba (diff)
downloadexternal_llvm-62fed8bd380b67f47bde3ff2a437db0951c7d186.zip
external_llvm-62fed8bd380b67f47bde3ff2a437db0951c7d186.tar.gz
external_llvm-62fed8bd380b67f47bde3ff2a437db0951c7d186.tar.bz2
Don't crash in a strange .size directive.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115684 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC')
-rw-r--r--lib/MC/ELFObjectWriter.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp
index 72a6cbd..faba61e 100644
--- a/lib/MC/ELFObjectWriter.cpp
+++ b/lib/MC/ELFObjectWriter.cpp
@@ -445,12 +445,22 @@ void ELFObjectWriterImpl::WriteSymbol(MCDataFragment *F, ELFSymbolData &MSD,
const MCBinaryExpr *BE = static_cast<const MCBinaryExpr *>(ESize);
if (BE->EvaluateAsRelocatable(Res, &Layout)) {
- MCSymbolData &A =
- Layout.getAssembler().getSymbolData(Res.getSymA()->getSymbol());
- MCSymbolData &B =
- Layout.getAssembler().getSymbolData(Res.getSymB()->getSymbol());
+ uint64_t AddressA = 0;
+ uint64_t AddressB = 0;
+ const MCSymbol &SymA = Res.getSymA()->getSymbol();
+ const MCSymbol &SymB = Res.getSymB()->getSymbol();
+
+ if (SymA.isDefined()) {
+ MCSymbolData &A = Layout.getAssembler().getSymbolData(SymA);
+ AddressA = Layout.getSymbolAddress(&A);
+ }
+
+ if (SymB.isDefined()) {
+ MCSymbolData &B = Layout.getAssembler().getSymbolData(SymB);
+ AddressB = Layout.getSymbolAddress(&B);
+ }
- Size = Layout.getSymbolAddress(&A) - Layout.getSymbolAddress(&B);
+ Size = AddressA - AddressB;
}
} else if (ESize->getKind() == MCExpr::Constant) {
Size = static_cast<const MCConstantExpr *>(ESize)->getValue();