[lld] 64fb629 - [LLD] Imply "longjmp" in `/guard:cf`

Phoebe Wang via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 8 19:47:35 PDT 2022


Author: Phoebe Wang
Date: 2022-09-09T10:38:18+08:00
New Revision: 64fb629a06f1bd31ece19335b799eb17bff75a09

URL: https://github.com/llvm/llvm-project/commit/64fb629a06f1bd31ece19335b799eb17bff75a09
DIFF: https://github.com/llvm/llvm-project/commit/64fb629a06f1bd31ece19335b799eb17bff75a09.diff

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

This is MSVC's behaviour. LLD was matching it before D99078. Let's go back this way.

Reviewed By: rnk

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

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp
index ab69551034b92..eceb539942342 100644
--- a/lld/COFF/DriverUtils.cpp
+++ b/lld/COFF/DriverUtils.cpp
@@ -104,9 +104,7 @@ void parseGuard(StringRef fullArg) {
       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;

diff  --git a/lld/test/COFF/gfids-corrupt.s b/lld/test/COFF/gfids-corrupt.s
index a97eaf0aa18a5..a3e06a840bf78 100644
--- a/lld/test/COFF/gfids-corrupt.s
+++ b/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{{.*}}

diff  --git a/lld/test/COFF/gfids-fallback.s b/lld/test/COFF/gfids-fallback.s
index a743542cf0078..50a90c34a2399 100644
--- a/lld/test/COFF/gfids-fallback.s
+++ b/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

diff  --git a/lld/test/COFF/gfids-gc.s b/lld/test/COFF/gfids-gc.s
index 44b337cb58264..c64295aea113b 100644
--- a/lld/test/COFF/gfids-gc.s
+++ b/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

diff  --git a/lld/test/COFF/gfids-icf.s b/lld/test/COFF/gfids-icf.s
index e4e331bc0d46f..62ffd615e0837 100644
--- a/lld/test/COFF/gfids-icf.s
+++ b/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:

diff  --git a/lld/test/COFF/guard-longjmp.s b/lld/test/COFF/guard-longjmp.s
index d604d5b4d827a..86665aace67c9 100644
--- a/lld/test/COFF/guard-longjmp.s
+++ b/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

diff  --git a/lld/test/COFF/guardcf-lto.ll b/lld/test/COFF/guardcf-lto.ll
index bd0956b47d792..44d538ccfe159 100644
--- a/lld/test/COFF/guardcf-lto.ll
+++ b/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.


        


More information about the llvm-commits mailing list