[lld] r318364 - [coff] correctly emit safeseh entries for handlers defined in dlls

Bob Haarman via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 15 17:22:01 PST 2017


Author: inglorion
Date: Wed Nov 15 17:22:01 2017
New Revision: 318364

URL: http://llvm.org/viewvc/llvm-project?rev=318364&view=rev
Log:
[coff] correctly emit safeseh entries for handlers defined in dlls

Summary:
We previously assumed that all SafeSEH handlers are
DefinedRegular symbols. This is not the case for handlers defined in
DLLs. As a result, we were failing to emit entries in the SafeSEH
table for those handlers. This change fixes that.

Fixes PR35324.

Reviewers: rnk, ruiu

Reviewed By: rnk

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D40102

Added:
    lld/trunk/test/COFF/Inputs/except_handler3.lib   (with props)
    lld/trunk/test/COFF/safeseh-md.s
Modified:
    lld/trunk/COFF/Writer.cpp

Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=318364&r1=318363&r2=318364&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Wed Nov 15 17:22:01 2017
@@ -787,11 +787,9 @@ void Writer::createSEHTable(OutputSectio
     if (!File->SEHCompat)
       return;
     for (Symbol *B : File->SEHandlers) {
-      // Make sure the handler is still live. Assume all handlers are regular
-      // symbols.
-      auto *D = dyn_cast<DefinedRegular>(B);
-      if (D && D->getChunk()->isLive())
-        Handlers.insert(D);
+      // Make sure the handler is still live.
+      if (B->isLive())
+        Handlers.insert(cast<Defined>(B));
     }
   }
 

Added: lld/trunk/test/COFF/Inputs/except_handler3.lib
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/Inputs/except_handler3.lib?rev=318364&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lld/trunk/test/COFF/Inputs/except_handler3.lib
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lld/trunk/test/COFF/safeseh-md.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/safeseh-md.s?rev=318364&view=auto
==============================================================================
--- lld/trunk/test/COFF/safeseh-md.s (added)
+++ lld/trunk/test/COFF/safeseh-md.s Wed Nov 15 17:22:01 2017
@@ -0,0 +1,34 @@
+# RUN: llvm-mc -triple i686-windows-msvc %s -filetype=obj -o %t.obj
+# RUN: lld-link %t.obj %S/Inputs/except_handler3.lib -safeseh -out:%t.exe -opt:noref -entry:main
+# RUN: llvm-readobj -coff-load-config %t.exe | FileCheck %s
+
+# CHECK: SEHTable [
+# CHECK-NEXT: 0x
+# CHECK-NEXT: ]
+
+        .def     @feat.00;
+        .scl    3;
+        .type   0;
+        .endef
+        .globl  @feat.00
+ at feat.00 = 1
+
+        .def     _main;
+        .scl    2;
+        .type   32;
+        .endef
+        .section        .text,"xr",one_only,_main
+        .globl  _main
+_main:
+        movl $42, %eax
+        ret
+
+.safeseh __except_handler3
+
+	.section .rdata,"dr"
+.globl __load_config_used
+__load_config_used:
+        .long 72
+        .fill 60, 1, 0
+        .long ___safe_se_handler_table
+        .long ___safe_se_handler_count




More information about the llvm-commits mailing list