1# REQUIRES: x86 2# RUN: llvm-mc -filetype=obj -triple=i386 %s -o %t.o 3# RUN: llvm-mc -filetype=obj -triple=i386 %p/Inputs/i386-cet1.s -o %t1.o 4# RUN: llvm-mc -filetype=obj -triple=i386 %p/Inputs/i386-cet2.s -o %t2.o 5# RUN: llvm-mc -filetype=obj -triple=i386 %p/Inputs/i386-cet3.s -o %t3.o 6# RUN: llvm-mc -filetype=obj -triple=i386 %p/Inputs/i386-cet4.s -o %t4.o 7 8# RUN: ld.lld -e func1 %t.o %t1.o -o %t 9# RUN: llvm-readelf -n %t | FileCheck --check-prefix=CET --match-full-lines %s 10 11# RUN: ld.lld -e func1 %t.o %t2.o -o %t 12# RUN: llvm-readelf -n %t | FileCheck --check-prefix=CET --match-full-lines %s 13 14# CET: Properties: x86 feature: IBT, SHSTK 15 16# RUN: ld.lld -e func1 %t.o %t3.o -o %t 17# RUN: llvm-readelf -S %t | FileCheck --check-prefix=NOCET %s 18 19# NOCET: Section Headers 20# NOCET-NOT: .note.gnu.property 21 22# RUN: ld.lld -e func1 %t.o %t3.o -o %t -z force-ibt 2>&1 \ 23# RUN: | FileCheck --check-prefix=WARN %s 24# WARN: {{.*}}.o: -z force-ibt: file does not have GNU_PROPERTY_X86_FEATURE_1_IBT property 25 26# RUN: not ld.lld -e func1 %t.o %t3.o -o /dev/null -z cet-report=something 2>&1 \ 27# RUN: | FileCheck --check-prefix=REPORT_INVALID %s 28# REPORT_INVALID: error: -z cet-report= parameter something is not recognized 29# REPORT_INVALID-EMPTY: 30 31# RUN: ld.lld -e func1 %t.o %t3.o -o /dev/null -z cet-report=warning 2>&1 \ 32# RUN: | FileCheck --check-prefix=CET_REPORT_WARN %s 33# CET_REPORT_WARN: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_IBT property 34# CET_REPORT_WARN: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_SHSTK property 35# CET_REPORT_WARN-EMPTY: 36 37# RUN: not ld.lld -e func1 %t.o %t3.o -o /dev/null -z cet-report=error 2>&1 \ 38# RUN: | FileCheck --check-prefix=CET_REPORT_ERROR %s 39# CET_REPORT_ERROR: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_IBT property 40# CET_REPORT_ERROR: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_SHSTK property 41# CET_REPORT_ERROR-EMPTY: 42 43# RUN: ld.lld -e func1 %t.o %t4.o -o %t 44# RUN: llvm-readelf -n %t | FileCheck --check-prefix=NOSHSTK %s 45 46# Check .note.gnu.protery without property SHSTK. 47# NOSHSTK: Properties: x86 feature: IBT{{$}} 48 49# RUN: ld.lld -shared %t1.o -soname=so -o %t1.so 50# RUN: ld.lld -e func1 %t.o %t1.so -o %t 51# RUN: llvm-readelf -n %t | FileCheck --check-prefix=CET --match-full-lines %s 52# RUN: llvm-readelf -x .got.plt %t | FileCheck --check-prefix=GOTPLT %s 53# RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex %t | FileCheck --check-prefix=DISASM %s 54 55# GOTPLT: Hex dump of section '.got.plt': 56# GOTPLT-NEXT: 0x004032d0 50224000 00000000 00000000 20124000 57# GOTPLT-NEXT: 0x004032e0 0b124000 58 59# DISASM: Disassembly of section .text: 60# DISASM: 00401200 <func1>: 61# DISASM-NEXT: 401200: calll 0x401230 <func2+0x401230> 62# DISASM-NEXT: 401205: calll 0x401240 <ifunc> 63# DISASM-NEXT: retl 64 65# DISASM: Disassembly of section .plt: 66# DISASM: 00401210 <.plt>: 67# DISASM-NEXT: 401210: pushl 0x4032d4 68# DISASM-NEXT: jmpl *0x4032d8 69# DISASM-NEXT: nop 70# DISASM-NEXT: nop 71# DISASM-NEXT: nop 72# DISASM-NEXT: nop 73# DISASM-NEXT: endbr32 74# DISASM-NEXT: pushl $0x0 75# DISASM-NEXT: jmp 0x401210 <.plt> 76# DISASM-NEXT: nop 77 78# DISASM: Disassembly of section .plt.sec: 79# DISASM: 00401230 <.plt.sec>: 80# DISASM-NEXT: 401230: endbr32 81# DISASM-NEXT: jmpl *0x4032dc 82# DISASM-NEXT: nopw (%eax,%eax) 83 84# DISASM: Disassembly of section .iplt: 85# DISASM: 00401240 <ifunc>: 86# DISASM-NEXT: 401240: endbr32 87# DISASM-NEXT: jmpl *0x4032e0 88# DISASM-NEXT: nopw (%eax,%eax) 89 90.section ".note.gnu.property", "a" 91.long 4 92.long 0xc 93.long 0x5 94.asciz "GNU" 95 96.long 0xc0000002 # GNU_PROPERTY_X86_FEATURE_1_AND 97.long 4 98.long 3 # GNU_PROPERTY_X86_FEATURE_1_IBT and SHSTK 99 100.text 101.globl func1 102.type func1,@function 103func1: 104 call func2 105 call ifunc 106 ret 107 108.type ifunc,@gnu_indirect_function 109ifunc: 110 ret 111