1# REQUIRES: x86 2# RUN: llvm-mc -triple i686-pc-win32 %s -filetype=obj -o %t.obj 3# RUN: lld-link -safeseh:no %t.obj -guard:cf -out:%t.exe -entry:main 4# RUN: llvm-readobj --coff-load-config %t.exe | FileCheck %s --check-prefix=CHECK 5 6# Only f and _main should go in the table. 7# (use /lldmap:map.txt to check their addresses). 8# 9# CHECK: GuardFidTable [ 10# CHECK-NEXT: 0x401000 11# CHECK-NEXT: 0x401030 12# CHECK-NEXT: ] 13 14# The input was loosly based on studying this program: 15# 16# void foo() { return; } 17# void bar() { return; } 18# int main() { 19# foo(); 20# void (*arr[])() = { &bar }; 21# (*arr[0])(); 22# return 0; 23# } 24# cl /c a.cc && dumpbin /disasm a.obj > a.txt && 25# link a.obj /guard:cf /map:map.txt && dumpbin /loadconfig a.exe 26 27 28 29 .def f; 30 .scl 3; 31 .type 32; 32 .endef 33 .section .text,"xr",one_only,f 34 .p2align 4 35f: movl $1, %eax 36 ret 37 38 39 .def g; 40 .scl 3; 41 .type 32; 42 .endef 43 .section .text,"xr",one_only,g 44 .p2align 4 45g: movl $2, %eax 46 ret 47 48 49 .def label; 50 .scl 6; # StorageClass: Label 51 .type 0; # Type: Not a function. 52 .endef 53 .section .text,"xr",one_only,label 54 .p2align 4 55label: ret 56 57 58 .data 59 .globl fp 60 .p2align 4 61fp: .long f # DIR32 relocation to function 62 .long label # DIR32 relocation to label 63 64 65 .def _main; 66 .scl 2; 67 .type 32; 68 .endef 69 .section .text,"xr",one_only,_main 70 .globl _main 71 .p2align 4 72_main: call *fp # DIR32 relocation to data 73 call g # REL32 relocation to function 74 ret 75 76 77# Load configuration directory entry (winnt.h _IMAGE_LOAD_CONFIG_DIRECTORY32). 78# The linker will define the ___guard_* symbols. 79 .section .rdata,"dr" 80.globl __load_config_used 81__load_config_used: 82 .long 104 # Size. 83 .fill 76, 1, 0 84 .long ___guard_fids_table 85 .long ___guard_fids_count 86 .long ___guard_flags 87 .fill 12, 1, 0 88