[PATCH] D47391: [COFF] Don't crash when emitting symbol table for SafeSEH input files

Shoaib Meenai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 25 13:47:06 PDT 2018


smeenai created this revision.
smeenai added reviewers: pcc, rnk, ruiu.
Herald added subscribers: JDevlieghere, aprantl.
smeenai added inline comments.


================
Comment at: COFF/Writer.cpp:614
   if (auto *D = dyn_cast<DefinedRegular>(Def))
-    if (D->getChunk()->isCodeView())
+    if (D->getChunk()->isCodeView() || D->getChunk()->isSXData())
       return None;
----------------
Does this need to be generalized to all RVA table sections, e.g. the control flow guard sections? We aren't using that right now, so it's not an immediate concern, but just wondering in general.


.sxdata sections aren't included in the output file, so their RVA is 0.
We would attempt to include them in the symbol table, but we wouldn't
find a corresponding output section for them, resulting in a segfault.
Ignore sxdata sections when writing to the symbol table to fix this,
similar to the existing handling for CodeView sections. Extend an
existing SafeSEH test to also check the -debug:dwarf case (and loosen an
address check in the test to account for differences in this case).

Fixes PR37584.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D47391

Files:
  COFF/Chunks.h
  COFF/Writer.cpp
  test/COFF/safeseh.s


Index: test/COFF/safeseh.s
===================================================================
--- test/COFF/safeseh.s
+++ test/COFF/safeseh.s
@@ -1,6 +1,8 @@
 # RUN: llvm-mc -triple i686-windows-msvc %s -filetype=obj -o %t.obj
 # RUN: lld-link %t.obj -safeseh -out:%t.exe -opt:noref -entry:main
 # RUN: llvm-readobj -coff-basereloc -coff-load-config -file-headers %t.exe | FileCheck %s --check-prefix=CHECK-NOGC
+# RUN: lld-link %t.obj -safeseh -out:%t.exe -opt:noref -entry:main -debug:dwarf
+# RUN: llvm-readobj -coff-basereloc -coff-load-config -file-headers %t.exe | FileCheck %s --check-prefix=CHECK-NOGC
 # RUN: lld-link %t.obj -safeseh -out:%t.exe -opt:ref -entry:main
 # RUN: llvm-readobj -coff-basereloc -coff-load-config -file-headers %t.exe | FileCheck %s --check-prefix=CHECK-GC
 
@@ -13,7 +15,7 @@
 # CHECK-NOGC:     Type: HIGHLOW
 # CHECK-NOGC: LoadConfig [
 # CHECK-NOGC:   Size: 0x48
-# CHECK-NOGC:   SEHandlerTable: 0x402048
+# CHECK-NOGC:   SEHandlerTable: 0x
 # CHECK-NOGC:   SEHandlerCount: 1
 # CHECK-NOGC: ]
 # CHECK-NOGC: SEHTable [
Index: COFF/Writer.cpp
===================================================================
--- COFF/Writer.cpp
+++ COFF/Writer.cpp
@@ -606,12 +606,12 @@
   if (isa<DefinedSynthetic>(Def))
     return None;
 
-  // Don't write dead symbols or symbols in codeview sections to the symbol
-  // table.
+  // Don't write dead symbols or symbols in codeview or sxdata sections to the
+  // symbol table.
   if (!Def->isLive())
     return None;
   if (auto *D = dyn_cast<DefinedRegular>(Def))
-    if (D->getChunk()->isCodeView())
+    if (D->getChunk()->isCodeView() || D->getChunk()->isSXData())
       return None;
 
   coff_symbol16 Sym;
Index: COFF/Chunks.h
===================================================================
--- COFF/Chunks.h
+++ COFF/Chunks.h
@@ -188,6 +188,9 @@
     return SectionName.startswith(".debug_") || SectionName == ".eh_frame";
   }
 
+  // True if this is a SEH handler registration chunk.
+  bool isSXData() const { return SectionName == ".sxdata"; }
+
   // Allow iteration over the bodies of this chunk's relocated symbols.
   llvm::iterator_range<symbol_iterator> symbols() const {
     return llvm::make_range(symbol_iterator(File, Relocs.begin()),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47391.148664.patch
Type: text/x-patch
Size: 2242 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180525/a9830514/attachment.bin>


More information about the llvm-commits mailing list