1# REQUIRES: x86 2# RUN: llvm-mc -triple x86_64-windows-msvc %s -filetype=obj -o %t.obj 3# RUN: lld-link %t.obj -guard:cf -out:%t.exe -entry:main 4# RUN: llvm-readobj --file-headers --coff-load-config %t.exe | FileCheck %s 5 6# CHECK: ImageBase: 0x140000000 7# CHECK: LoadConfig [ 8# CHECK: SEHandlerTable: 0x0 9# CHECK: SEHandlerCount: 0 10# CHECK: GuardCFCheckFunction: 0x0 11# CHECK: GuardCFCheckDispatch: 0x0 12# CHECK: GuardCFFunctionTable: 0x14000{{.*}} 13# CHECK: GuardCFFunctionCount: 1 14# CHECK: GuardFlags: 0x10500 15# CHECK: GuardAddressTakenIatEntryTable: 0x0 16# CHECK: GuardAddressTakenIatEntryCount: 0 17# CHECK: GuardLongJumpTargetTable: 0x14000{{.*}} 18# CHECK: GuardLongJumpTargetCount: 1 19# CHECK: ] 20# CHECK: GuardLJmpTable [ 21# CHECK-NEXT: 0x14000{{.*}} 22# CHECK-NEXT: ] 23 24 25# This assembly is reduced from C code like: 26# #include <setjmp.h> 27# jmp_buf buf; 28# void g() { longjmp(buf, 1); } 29# void f() { 30# if (setjmp(buf)) 31# return; 32# g(); 33# } 34# int main() { f(); } 35 36# We need @feat.00 to have 0x800 to indicate /guard:cf. 37 .def @feat.00; 38 .scl 3; 39 .type 0; 40 .endef 41 .globl @feat.00 42@feat.00 = 0x801 43 .def f; .scl 2; .type 32; .endef 44 .globl f 45f: 46 pushq %rbp 47 subq $32, %rsp 48 leaq 32(%rsp), %rbp 49 leaq buf(%rip), %rcx 50 leaq -32(%rbp), %rdx 51 callq _setjmp 52.Lljmp1: 53 testl %eax, %eax 54 je .LBB1_1 55 addq $32, %rsp 56 popq %rbp 57 retq 58.LBB1_1: # %if.end 59 leaq buf(%rip), %rcx 60 movl $1, %edx 61 callq longjmp 62 ud2 63 64 # Record the longjmp target. 65 .section .gljmp$y,"dr" 66 .symidx .Lljmp1 67 .text 68 69 # Provide setjmp/longjmp stubs. 70 .def _setjmp; .scl 2; .type 32; .endef 71 .globl _setjmp 72_setjmp: 73 retq 74 75 .def longjmp; .scl 2; .type 32; .endef 76 .globl longjmp 77longjmp: 78 retq 79 80 .def main; .scl 2; .type 32; .endef 81 .globl main # -- Begin function main 82main: # @main 83 subq $40, %rsp 84 callq f 85 xorl %eax, %eax 86 addq $40, %rsp 87 retq 88 89 .comm buf,256,4 # @buf 90 91 .section .rdata,"dr" 92.globl _load_config_used 93_load_config_used: 94 .long 256 95 .fill 124, 1, 0 96 .quad __guard_fids_table 97 .quad __guard_fids_count 98 .long __guard_flags 99 .fill 12, 1, 0 100 .quad __guard_iat_table 101 .quad __guard_iat_count 102 .quad __guard_longjmp_table 103 .quad __guard_fids_count 104 .fill 84, 1, 0 105