[lld] r327559 - [COFF] Add integration test for LTO + /guard:cf

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 14 12:49:28 PDT 2018


Author: rnk
Date: Wed Mar 14 12:49:28 2018
New Revision: 327559

URL: http://llvm.org/viewvc/llvm-project?rev=327559&view=rev
Log:
[COFF] Add integration test for LTO + /guard:cf

This tests that LLVM emits the relocations that /guard:cf needs to
identify address taken.

This was PR36624, which was fixed in r327557.

Added:
    lld/trunk/test/COFF/Inputs/loadconfig-cfg-x64.s
    lld/trunk/test/COFF/guardcf-lto.ll

Added: lld/trunk/test/COFF/Inputs/loadconfig-cfg-x64.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/Inputs/loadconfig-cfg-x64.s?rev=327559&view=auto
==============================================================================
--- lld/trunk/test/COFF/Inputs/loadconfig-cfg-x64.s (added)
+++ lld/trunk/test/COFF/Inputs/loadconfig-cfg-x64.s Wed Mar 14 12:49:28 2018
@@ -0,0 +1,11 @@
+# This is the _load_config_used definition needed for /guard:cf tests.
+
+        .section .rdata,"dr"
+.globl _load_config_used
+_load_config_used:
+        .long 256
+        .fill 124, 1, 0
+        .quad __guard_fids_table
+        .quad __guard_fids_count
+        .long __guard_flags
+        .fill 128, 1, 0

Added: lld/trunk/test/COFF/guardcf-lto.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/guardcf-lto.ll?rev=327559&view=auto
==============================================================================
--- lld/trunk/test/COFF/guardcf-lto.ll (added)
+++ lld/trunk/test/COFF/guardcf-lto.ll Wed Mar 14 12:49:28 2018
@@ -0,0 +1,39 @@
+; Set up an import library for a DLL that will do the indirect call.
+; RUN: echo -e 'LIBRARY library\nEXPORTS\n  do_indirect_call\n' > %t.def
+; RUN: lld-link -lib -def:%t.def -out:%t.lib -machine:x64
+
+; Generate an object that will have the load configuration normally provided by
+; the CRT.
+; 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 -dll %t.bc %t.lib %t.ldcfg.obj -out:%t.dll
+; RUN: llvm-readobj -coff-load-config %t.dll | FileCheck %s
+
+; There must be *two* entries in the table: DLL entry point, and my_handler.
+
+; CHECK:      LoadConfig [
+; CHECK:        GuardCFFunctionTable: 0x{{[^0].*}}
+; CHECK-NEXT:   GuardCFFunctionCount: 2
+; CHECK-NEXT:   GuardFlags: 0x10500
+; CHECK:      ]
+; CHECK:      GuardFidTable [
+; CHECK-NEXT:   0x180{{.*}}
+; CHECK-NEXT:   0x180{{.*}}
+; CHECK-NEXT: ]
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc19.12.25835"
+
+declare dllimport void @do_indirect_call(void ()*)
+
+define dso_local i32 @main() local_unnamed_addr {
+entry:
+  tail call void @do_indirect_call(void ()* nonnull @my_handler)
+  ret i32 0
+}
+
+define dso_local void @my_handler() {
+entry:
+  ret void
+}




More information about the llvm-commits mailing list