109 lines · plain
1# REQUIRES: x862# RUN: llvm-mc -triple x86_64-windows-msvc %s -filetype=obj -o %t.obj3# RUN: lld-link %t.obj -guard:cf -out:%t.exe -entry:main4# RUN: llvm-readobj --file-headers --coff-load-config %t.exe | FileCheck %s5 6# CHECK: ImageBase: 0x1400000007# CHECK: LoadConfig [8# CHECK: SEHandlerTable: 0x09# CHECK: SEHandlerCount: 010# CHECK: GuardCFCheckFunction: 0x011# CHECK: GuardCFCheckDispatch: 0x012# CHECK: GuardCFFunctionTable: 0x14000{{.*}}13# CHECK: GuardCFFunctionCount: 114# CHECK: GuardFlags [ (0x10500)15# CHECK: CF_FUNCTION_TABLE_PRESENT (0x400)16# CHECK: CF_INSTRUMENTED (0x100)17# CHECK: CF_LONGJUMP_TABLE_PRESENT (0x10000)18# CHECK: ]19# CHECK: GuardAddressTakenIatEntryTable: 0x020# CHECK: GuardAddressTakenIatEntryCount: 021# CHECK: GuardLongJumpTargetTable: 0x14000{{.*}}22# CHECK: GuardLongJumpTargetCount: 123# CHECK: ]24# CHECK: GuardLJmpTable [25# CHECK-NEXT: 0x14000{{.*}}26# CHECK-NEXT: ]27 28 29# This assembly is reduced from C code like:30# #include <setjmp.h>31# jmp_buf buf;32# void g() { longjmp(buf, 1); }33# void f() {34# if (setjmp(buf))35# return;36# g();37# }38# int main() { f(); }39 40# We need @feat.00 to have 0x800 to indicate /guard:cf.41 .def @feat.00;42 .scl 3;43 .type 0;44 .endef45 .globl @feat.0046@feat.00 = 0x80147 .def f; .scl 2; .type 32; .endef48 .globl f49f:50 pushq %rbp51 subq $32, %rsp52 leaq 32(%rsp), %rbp53 leaq buf(%rip), %rcx54 leaq -32(%rbp), %rdx55 callq _setjmp56.Lljmp1:57 testl %eax, %eax58 je .LBB1_159 addq $32, %rsp60 popq %rbp61 retq62.LBB1_1: # %if.end63 leaq buf(%rip), %rcx64 movl $1, %edx65 callq longjmp66 ud267 68 # Record the longjmp target.69 .section .gljmp$y,"dr"70 .symidx .Lljmp171 .text72 73 # Provide setjmp/longjmp stubs.74 .def _setjmp; .scl 2; .type 32; .endef75 .globl _setjmp76_setjmp:77 retq78 79 .def longjmp; .scl 2; .type 32; .endef80 .globl longjmp81longjmp:82 retq83 84 .def main; .scl 2; .type 32; .endef85 .globl main # -- Begin function main86main: # @main87 subq $40, %rsp88 callq f89 xorl %eax, %eax90 addq $40, %rsp91 retq92 93 .comm buf,256,4 # @buf94 95 .section .rdata,"dr"96.globl _load_config_used97_load_config_used:98 .long 25699 .fill 124, 1, 0100 .quad __guard_fids_table101 .quad __guard_fids_count102 .long __guard_flags103 .fill 12, 1, 0104 .quad __guard_iat_table105 .quad __guard_iat_count106 .quad __guard_longjmp_table107 .quad __guard_longjmp_count108 .fill 84, 1, 0109