[PATCH] D132901: [LLD] Imply "longjmp" in `/guard:cf`

Phoebe Wang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 29 18:09:56 PDT 2022


pengfei created this revision.
pengfei added reviewers: alvinhochun, rnk, mstorsjo.
Herald added subscribers: ormris, steven_wu, hiraditya.
Herald added a project: All.
pengfei requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This is MSVC's behaviour. LLD was matching it before D99078 <https://reviews.llvm.org/D99078>. Let's go back this way.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132901

Files:
  lld/COFF/DriverUtils.cpp
  lld/test/COFF/gfids-corrupt.s
  lld/test/COFF/gfids-fallback.s
  lld/test/COFF/gfids-gc.s
  lld/test/COFF/gfids-icf.s
  lld/test/COFF/guard-longjmp.s
  lld/test/COFF/guardcf-lto.ll


Index: lld/test/COFF/guardcf-lto.ll
===================================================================
--- lld/test/COFF/guardcf-lto.ll
+++ lld/test/COFF/guardcf-lto.ll
@@ -8,7 +8,7 @@
 ; RUN: llvm-mc -triple x86_64-windows-msvc -filetype=obj %S/Inputs/loadconfig-cfg-x64.s -o %t.ldcfg.obj
 
 ; RUN: llvm-as %s -o %t.bc
-; RUN: lld-link -entry:main -guard:cf -guard:longjmp -dll %t.bc %t.lib %t.ldcfg.obj -out:%t2.dll
+; RUN: lld-link -entry:main -guard:cf -dll %t.bc %t.lib %t.ldcfg.obj -out:%t2.dll
 ; RUN: llvm-readobj --coff-load-config %t2.dll | FileCheck %s
 
 ; There must be *two* entries in the table: DLL entry point, and my_handler.
Index: lld/test/COFF/guard-longjmp.s
===================================================================
--- lld/test/COFF/guard-longjmp.s
+++ lld/test/COFF/guard-longjmp.s
@@ -1,6 +1,6 @@
 # REQUIRES: x86
 # RUN: llvm-mc -triple x86_64-windows-msvc %s -filetype=obj -o %t.obj
-# RUN: lld-link %t.obj -guard:cf -guard:longjmp -out:%t.exe -entry:main
+# RUN: lld-link %t.obj -guard:cf -out:%t.exe -entry:main
 # RUN: llvm-readobj --file-headers --coff-load-config %t.exe | FileCheck %s
 
 # CHECK: ImageBase: 0x140000000
Index: lld/test/COFF/gfids-icf.s
===================================================================
--- lld/test/COFF/gfids-icf.s
+++ lld/test/COFF/gfids-icf.s
@@ -1,6 +1,6 @@
 # REQUIRES: x86
 # RUN: llvm-mc -triple x86_64-windows-msvc %s -filetype=obj -o %t.obj
-# RUN: lld-link %t.obj -guard:cf -out:%t.exe -opt:icf -entry:main
+# RUN: lld-link %t.obj -guard:cf,nolongjmp -out:%t.exe -opt:icf -entry:main
 # RUN: llvm-readobj --file-headers --coff-load-config %t.exe | FileCheck %s --check-prefix=CHECK
 
 # This assembly is meant to mimic what CL emits for this kind of C code:
Index: lld/test/COFF/gfids-gc.s
===================================================================
--- lld/test/COFF/gfids-gc.s
+++ lld/test/COFF/gfids-gc.s
@@ -1,10 +1,10 @@
 # REQUIRES: x86
 # RUN: llvm-mc -triple x86_64-windows-msvc %s -filetype=obj -o %t.obj
-# RUN: lld-link %t.obj -guard:cf -out:%t.exe -opt:noref -entry:main
+# RUN: lld-link %t.obj -guard:cf,nolongjmp -out:%t.exe -opt:noref -entry:main
 # RUN: llvm-readobj --file-headers --coff-load-config %t.exe | FileCheck %s --check-prefix=CHECK-NOGC
-# RUN: lld-link %t.obj -guard:cf -out:%t.exe -opt:noref -entry:main -debug:dwarf
+# RUN: lld-link %t.obj -guard:cf,nolongjmp -out:%t.exe -opt:noref -entry:main -debug:dwarf
 # RUN: llvm-readobj --file-headers --coff-load-config %t.exe | FileCheck %s --check-prefix=CHECK-NOGC
-# RUN: lld-link %t.obj -guard:cf -out:%t.exe -opt:ref -entry:main
+# RUN: lld-link %t.obj -guard:cf,nolongjmp -out:%t.exe -opt:ref -entry:main
 # RUN: llvm-readobj --file-headers --coff-load-config %t.exe | FileCheck %s --check-prefix=CHECK-GC
 
 # This assembly is meant to mimic what CL emits for this kind of C code when
Index: lld/test/COFF/gfids-fallback.s
===================================================================
--- lld/test/COFF/gfids-fallback.s
+++ lld/test/COFF/gfids-fallback.s
@@ -1,7 +1,7 @@
 # REQUIRES: x86
 # RUN: grep -B99999 [S]PLITMARKER %s | llvm-mc -triple x86_64-windows-msvc -filetype=obj -o %t1.obj
 # RUN: grep -A99999 [S]PLITMARKER %s | llvm-mc -triple x86_64-windows-msvc -filetype=obj -o %t2.obj
-# RUN: lld-link %t1.obj %t2.obj -guard:cf -out:%t.exe -entry:main -opt:noref
+# RUN: lld-link %t1.obj %t2.obj -guard:cf,nolongjmp -out:%t.exe -entry:main -opt:noref
 # RUN: llvm-readobj --file-headers --coff-load-config %t.exe | FileCheck %s
 
 # CHECK: ImageBase: 0x140000000
Index: lld/test/COFF/gfids-corrupt.s
===================================================================
--- lld/test/COFF/gfids-corrupt.s
+++ lld/test/COFF/gfids-corrupt.s
@@ -1,6 +1,6 @@
 # REQUIRES: x86
 # RUN: llvm-mc -triple x86_64-windows-msvc %s -filetype=obj -o %t.obj
-# RUN: lld-link %t.obj -opt:noref -guard:cf -out:%t.exe -entry:main 2>&1 | FileCheck %s --check-prefix=ERRS
+# RUN: lld-link %t.obj -opt:noref -guard:cf,nolongjmp -out:%t.exe -entry:main 2>&1 | FileCheck %s --check-prefix=ERRS
 # RUN: llvm-readobj --file-headers --coff-load-config %t.exe | FileCheck %s
 
 # ERRS: warning: ignoring .gfids$y symbol table index section in object {{.*}}gfids-corrupt{{.*}}
Index: lld/COFF/DriverUtils.cpp
===================================================================
--- lld/COFF/DriverUtils.cpp
+++ lld/COFF/DriverUtils.cpp
@@ -104,9 +104,7 @@
       config->guardCF &= ~GuardCFLevel::LongJmp;
     else if (arg.equals_insensitive("noehcont"))
       config->guardCF &= ~GuardCFLevel::EHCont;
-    else if (arg.equals_insensitive("cf"))
-      config->guardCF = GuardCFLevel::CF;
-    else if (arg.equals_insensitive("longjmp"))
+    else if (arg.equals_insensitive("cf") || arg.equals_insensitive("longjmp"))
       config->guardCF |= GuardCFLevel::CF | GuardCFLevel::LongJmp;
     else if (arg.equals_insensitive("ehcont"))
       config->guardCF |= GuardCFLevel::CF | GuardCFLevel::EHCont;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132901.456510.patch
Type: text/x-patch
Size: 4964 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220830/8c398eae/attachment.bin>


More information about the llvm-commits mailing list