[PATCH] Fix PR18381 - print a minimal diagnostic rather than assert on unresolved .secidx target

Timur Iskhodzhanov timurrrr at google.com
Wed Jan 29 20:27:39 PST 2014


Hi echristo, rnk,

For more details see http://llvm.org/bugs/show_bug.cgi?id=18381
As of ToT, such an input crashes with
  Assertion failed: Entry && "Missing symbol data!", file include/llvm/MC/MCAssembler.h, line 1158

With the patch applied, the diagnostic looks like this:
  LLVM ERROR: Can't resolve the 'bar' symbol
  Stack dump:
  0.      Program arguments: bin\llvm-mc.EXE -filetype=obj -triple i686-pc-win32 C:\src\llvm\test\MC\COFF\secidx_diagnostic.s

Should I bother to remove the stack dump part?
The debug info-specific `.secidx` directive is supposed to be generated only by LLVM, not by hand.
If yes, pointers are welcome.

http://llvm-reviews.chandlerc.com/D2653

Files:
  include/llvm/MC/MCAssembler.h
  lib/MC/WinCOFFObjectWriter.cpp
  test/MC/COFF/secidx_diagnostic.s

Index: include/llvm/MC/MCAssembler.h
===================================================================
--- include/llvm/MC/MCAssembler.h
+++ include/llvm/MC/MCAssembler.h
@@ -1153,6 +1153,10 @@
     return *Entry;
   }
 
+  bool hasSymbolData(const MCSymbol &Symbol) const {
+    return SymbolMap.lookup(&Symbol) != 0;
+  }
+
   MCSymbolData &getSymbolData(const MCSymbol &Symbol) const {
     MCSymbolData *Entry = SymbolMap.lookup(&Symbol);
     assert(Entry && "Missing symbol data!");
Index: lib/MC/WinCOFFObjectWriter.cpp
===================================================================
--- lib/MC/WinCOFFObjectWriter.cpp
+++ lib/MC/WinCOFFObjectWriter.cpp
@@ -636,6 +636,11 @@
 
   const MCSymbol &Symbol = Target.getSymA()->getSymbol();
   const MCSymbol &A = Symbol.AliasedSymbol();
+  if (!Asm.hasSymbolData(A))
+    Asm.getContext().FatalError(
+        Fixup.getLoc(),
+        Twine("Can't resolve the '") + A.getName() + "' symbol");
+
   MCSymbolData &A_SD = Asm.getSymbolData(A);
 
   MCSectionData const *SectionData = Fragment->getParent();
Index: test/MC/COFF/secidx_diagnostic.s
===================================================================
--- /dev/null
+++ test/MC/COFF/secidx_diagnostic.s
@@ -0,0 +1,8 @@
+// RUN: not llvm-mc -filetype=obj -triple i686-pc-win32 %s 2>%t
+// RUN: FileCheck %s < %t
+
+// CHECK: Can't resolve the 'bar' symbol
+
+.data
+foo:
+        .secidx bar
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2653.1.patch
Type: text/x-patch
Size: 1410 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140129/7a552f02/attachment.bin>


More information about the llvm-commits mailing list