[llvm-commits] [llvm] r115684 - in /llvm/trunk: lib/MC/ELFObjectWriter.cpp test/MC/ELF/size.s
Rafael Espindola
rafael.espindola at gmail.com
Tue Oct 5 14:02:45 PDT 2010
Author: rafael
Date: Tue Oct 5 16:02:45 2010
New Revision: 115684
URL: http://llvm.org/viewvc/llvm-project?rev=115684&view=rev
Log:
Don't crash in a strange .size directive.
Added:
llvm/trunk/test/MC/ELF/size.s
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=115684&r1=115683&r2=115684&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Tue Oct 5 16:02:45 2010
@@ -445,12 +445,22 @@
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();
Added: llvm/trunk/test/MC/ELF/size.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/size.s?rev=115684&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/size.s (added)
+++ llvm/trunk/test/MC/ELF/size.s Tue Oct 5 16:02:45 2010
@@ -0,0 +1,9 @@
+// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s
+
+// Mostly a test that this doesn't crash anymore.
+
+// CHECK: # Symbol 4
+// CHECK-NEXT: (('st_name', 1) # 'foo'
+// CHECK-NEXT: ('st_bind', 1)
+
+ .size foo, .Lbar-foo
More information about the llvm-commits
mailing list