[PATCH] D41252: [COFF] Set the IMAGE_DLL_CHARACTERISTICS_NO_SEH flag automatically

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 15 00:05:28 PST 2017


mstorsjo updated this revision to Diff 127073.
mstorsjo retitled this revision from "[MinGW] Implement the --no-seh flag" to "[COFF] Set the IMAGE_DLL_CHARACTERISTICS_NO_SEH flag automatically".
mstorsjo edited the summary of this revision.
mstorsjo added a comment.

Split out the MinGW part, made it set the flag automatically based on Reid's suggestion.


https://reviews.llvm.org/D41252

Files:
  COFF/Writer.cpp
  test/COFF/hello32.test
  test/COFF/loadcfg.test
  test/COFF/safeseh.s


Index: test/COFF/safeseh.s
===================================================================
--- test/COFF/safeseh.s
+++ test/COFF/safeseh.s
@@ -1,11 +1,12 @@
 # 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 %t.exe | FileCheck %s --check-prefix=CHECK-NOGC
+# 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 %t.exe | FileCheck %s --check-prefix=CHECK-GC
+# RUN: llvm-readobj -coff-basereloc -coff-load-config -file-headers %t.exe | FileCheck %s --check-prefix=CHECK-GC
 
 # __safe_se_handler_table needs to be relocated against ImageBase.
 # check that the relocation is present.
+# CHECK-NOGC-NOT: IMAGE_DLL_CHARACTERISTICS_NO_SEH
 # CHECK-NOGC: BaseReloc [
 # CHECK-NOGC:   Entry {
 # CHECK-NOGC:     Type: HIGHLOW
@@ -20,6 +21,7 @@
 
 # Without the SEH table, the address is absolute, so check that we do
 # not have a relocation for it.
+# CHECK-GC-NOT: IMAGE_DLL_CHARACTERISTICS_NO_SEH
 # CHECK-GC: BaseReloc [
 # CHECK-GC-NEXT: ]
 # CHECK-GC: LoadConfig [
Index: test/COFF/loadcfg.test
===================================================================
--- test/COFF/loadcfg.test
+++ test/COFF/loadcfg.test
@@ -2,6 +2,7 @@
 # RUN: lld-link /out:%t.exe %t.obj /entry:main /subsystem:console
 # RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
 
+# CHECK-NOT: IMAGE_DLL_CHARACTERISTICS_NO_SEH
 # CHECK: LoadConfigTableRVA: 0x1000
 # CHECK: LoadConfigTableSize: 0x70
 
Index: test/COFF/hello32.test
===================================================================
--- test/COFF/hello32.test
+++ test/COFF/hello32.test
@@ -42,9 +42,10 @@
 HEADER-NEXT:   SizeOfImage: 20480
 HEADER-NEXT:   SizeOfHeaders: 512
 HEADER-NEXT:   Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI (0x3)
-HEADER-NEXT:   Characteristics [ (0x9140)
+HEADER-NEXT:   Characteristics [ (0x9540)
 HEADER-NEXT:     IMAGE_DLL_CHARACTERISTICS_APPCONTAINER (0x1000)
 HEADER-NEXT:     IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE (0x40)
+HEADER-NEXT:     IMAGE_DLL_CHARACTERISTICS_NO_SEH (0x400)
 HEADER-NEXT:     IMAGE_DLL_CHARACTERISTICS_NX_COMPAT (0x100)
 HEADER-NEXT:     IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE (0x8000)
 HEADER-NEXT:   ]
Index: COFF/Writer.cpp
===================================================================
--- COFF/Writer.cpp
+++ COFF/Writer.cpp
@@ -688,6 +688,8 @@
     PE->DLLCharacteristics |= IMAGE_DLL_CHARACTERISTICS_NX_COMPAT;
   if (!Config->AllowIsolation)
     PE->DLLCharacteristics |= IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION;
+  if (!SEHTable && !Symtab->findUnderscore("_load_config_used"))
+    PE->DLLCharacteristics |= IMAGE_DLL_CHARACTERISTICS_NO_SEH;
   if (Config->TerminalServerAware)
     PE->DLLCharacteristics |= IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE;
   PE->NumberOfRvaAndSize = NumberfOfDataDirectory;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41252.127073.patch
Type: text/x-patch
Size: 3062 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171215/7ee3f17c/attachment.bin>


More information about the llvm-commits mailing list