2 # RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
3 # RUN: llvm-mc -filetype=obj -triple=x86_64 %p/Inputs/x86-64-cet1.s -o %t1.o
4 # RUN: llvm-mc -filetype=obj -triple=x86_64 %p/Inputs/x86-64-cet2.s -o %t2.o
5 # RUN: llvm-mc -filetype=obj -triple=x86_64 %p/Inputs/x86-64-cet3.s -o %t3.o
6 # RUN: llvm-mc -filetype=obj -triple=x86_64 %p/Inputs/x86-64-cet4.s -o %t4.o
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
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
14 # CET: Properties: x86 feature: IBT, SHSTK
16 # RUN: ld.lld -e func1 %t.o %t3.o -o %t
17 # RUN: llvm-readelf -S %t | FileCheck --check-prefix=NOCET %s
19 # NOCET: Section Headers
20 # NOCET-NOT: .note.gnu.property
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
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:
31 # RUN: ld.lld -e func1 %t.o %t3.o -o /dev/null -z force-ibt -z cet-report=warning 2>&1 \
32 # RUN: | FileCheck --check-prefix=REPORT_FORCE %s
33 # REPORT_FORCE: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_IBT property
34 # REPORT_FORCE: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_SHSTK property
37 # RUN: ld.lld -e func1 %t.o %t3.o -o /dev/null -z cet-report=warning 2>&1 \
38 # RUN: | FileCheck --check-prefix=CET_REPORT_WARN %s
39 # CET_REPORT_WARN: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_IBT property
40 # CET_REPORT_WARN: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_SHSTK property
41 # CET_REPORT_WARN-EMPTY:
43 # RUN: not ld.lld -e func1 %t.o %t3.o -o /dev/null -z cet-report=error 2>&1 \
44 # RUN: | FileCheck --check-prefix=CET_REPORT_ERROR %s
45 # CET_REPORT_ERROR: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_IBT property
46 # CET_REPORT_ERROR: {{.*}}.o: -z cet-report: file does not have GNU_PROPERTY_X86_FEATURE_1_SHSTK property
47 # CET_REPORT_ERROR-EMPTY:
49 # RUN: ld.lld -e func1 %t.o %t4.o -o %t
50 # RUN: llvm-readelf -n %t | FileCheck --check-prefix=NOSHSTK %s
52 # Check .note.gnu.protery without property SHSTK.
53 # NOSHSTK: Properties: x86 feature: IBT{{$}}
55 # RUN: ld.lld -shared %t1.o -soname=so -o %t1.so
56 # RUN: ld.lld -e func1 %t.o %t1.so -o %t
57 # RUN: llvm-readelf -n %t | FileCheck --check-prefix=CET --match-full-lines %s
58 # RUN: llvm-readelf -x .got.plt %t | FileCheck --check-prefix=GOTPLT %s
59 # RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex %t | FileCheck --check-prefix=DISASM %s
61 # GOTPLT: Hex dump of section '.got.plt':
62 # GOTPLT-NEXT: 203480 80232000 00000000 00000000 00000000
63 # GOTPLT-NEXT: 203490 00000000 00000000 50132000 00000000
64 # GOTPLT-NEXT: 2034a0 00000000 00000000
66 # DISASM: Disassembly of section .text:
67 # DISASM: 0000000000201330 <func1>:
68 # DISASM-NEXT: 201330: callq 0x201360 <func2+0x201360>
69 # DISASM-NEXT: 201335: callq 0x201370 <func2+0x201370>
72 # DISASM: Disassembly of section .plt:
73 # DISASM: 0000000000201340 <.plt>:
74 # DISASM-NEXT: 201340: pushq 0x2142(%rip)
75 # DISASM-NEXT: jmpq *0x2144(%rip)
76 # DISASM-NEXT: nopl (%rax)
77 # DISASM-NEXT: endbr64
78 # DISASM-NEXT: pushq $0x0
79 # DISASM-NEXT: jmp 0x201340 <.plt>
82 # DISASM: Disassembly of section .plt.sec:
83 # DISASM: 0000000000201360 <.plt.sec>:
84 # DISASM-NEXT: 201360: endbr64
85 # DISASM-NEXT: jmpq *0x212e(%rip)
86 # DISASM-NEXT: nopw (%rax,%rax)
88 # DISASM: Disassembly of section .iplt:
89 # DISASM: 0000000000201370 <.iplt>:
90 # DISASM-NEXT: 201370: endbr64
91 # DISASM-NEXT: jmpq *0x2126(%rip)
92 # DISASM-NEXT: nopw (%rax,%rax)
94 ## If there is no PLT entry, don't create .plt section.
95 # RUN: ld.lld -e 0 %t1.o -o %t.noplt
96 # RUN: llvm-readelf -S %t.noplt | FileCheck %s --check-prefix=NOPLT
97 # RUN: ld.lld -r %t1.o -o %t.noplt
98 # RUN: llvm-readelf -S %t.noplt | FileCheck %s --check-prefix=NOPLT
102 # NOPLT: .note.gnu.property
105 .section ".note.gnu.property", "a"
111 .long 0xc0000002 # GNU_PROPERTY_X86_FEATURE_1_AND
113 .long 3 # GNU_PROPERTY_X86_FEATURE_1_IBT and SHSTK
118 .type func1,@function
124 .type ifunc,@gnu_indirect_function