From b418c9d49ece5d503eea35a3ff994e55326da6f9 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Tue, 24 Oct 2023 16:24:22 +0100 Subject: [PATCH] ld: aarch64: Add BTI stub insertion test PR30930 The test creates a large shared library and covers a number of BTI stub insertion cases. --- ld/testsuite/ld-aarch64/aarch64-elf.exp | 1 + ld/testsuite/ld-aarch64/bti-far-3.d | 87 +++++++++++++++++++++++++ ld/testsuite/ld-aarch64/bti-far-3.ld | 12 ++++ ld/testsuite/ld-aarch64/bti-far-3a.s | 23 +++++++ ld/testsuite/ld-aarch64/bti-far-3b.s | 25 +++++++ ld/testsuite/ld-aarch64/bti-far-3c.s | 24 +++++++ 6 files changed, 172 insertions(+) create mode 100644 ld/testsuite/ld-aarch64/bti-far-3.d create mode 100644 ld/testsuite/ld-aarch64/bti-far-3.ld create mode 100644 ld/testsuite/ld-aarch64/bti-far-3a.s create mode 100644 ld/testsuite/ld-aarch64/bti-far-3b.s create mode 100644 ld/testsuite/ld-aarch64/bti-far-3c.s diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp index b025fcbd567..fa5ac3a2cdd 100644 --- a/ld/testsuite/ld-aarch64/aarch64-elf.exp +++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp @@ -466,6 +466,7 @@ run_dump_test "undef-tls" run_dump_test "bti-far-1" run_dump_test "bti-far-2" run_dump_test "bti-far-opt" +run_dump_test "bti-far-3" if { ![skip_sframe_tests] } { run_dump_test "sframe-simple-1" diff --git a/ld/testsuite/ld-aarch64/bti-far-3.d b/ld/testsuite/ld-aarch64/bti-far-3.d new file mode 100644 index 00000000000..1410b1389b2 --- /dev/null +++ b/ld/testsuite/ld-aarch64/bti-far-3.d @@ -0,0 +1,87 @@ +#name: Check indirect call stub to BTI stub relaxation. +#source: bti-far-3a.s +#source: bti-far-3b.s +#source: bti-far-3c.s +#as: -mabi=lp64 +#ld: -shared -T bti-far-3.ld +#objdump: -dr + +[^:]*: *file format elf64-.*aarch64 + + +Disassembly of section \.plt: + +0000000000020000 <\.plt>: + 20000: d503245f bti c + 20004: a9bf7bf0 stp x16, x30, \[sp, #-16\]! + 20008: 900fff10 adrp x16, 20000000 <_GLOBAL_OFFSET_TABLE_> + 2000c: f9400e11 ldr x17, \[x16, #24\] + 20010: 91006210 add x16, x16, #0x18 + 20014: d61f0220 br x17 + 20018: d503201f nop + 2001c: d503201f nop + +0000000000020020 : + 20020: 900fff10 adrp x16, 20000000 <_GLOBAL_OFFSET_TABLE_> + 20024: f9401211 ldr x17, \[x16, #32\] + 20028: 91008210 add x16, x16, #0x20 + 2002c: d61f0220 br x17 + 20030: 14000004 b 20040 <__extern_func_bti_veneer\+0x8> + 20034: d503201f nop + +0000000000020038 <__extern_func_bti_veneer>: + 20038: d503245f bti c + 2003c: 17fffff9 b 20020 + +Disassembly of section \.text: + +0000000000030000 : + 30000: 15c00004 b 7030010 <__b_func_veneer> + 30004: 17ffc007 b 20020 + \.\.\. + 7030008: 1400000a b 7030030 <__a_func_bti_veneer\+0x8> + 703000c: d503201f nop + +0000000007030010 <__b_func_veneer>: + 7030010: 90040010 adrp x16, f030000 + 7030014: 9101e210 add x16, x16, #0x78 + 7030018: d61f0200 br x16 + \.\.\. + +0000000007030028 <__a_func_bti_veneer>: + 7030028: d503245f bti c + 703002c: 163ffff5 b 30000 + \.\.\. + +0000000008030030 : + 8030030: 15c00004 b f030040 <__c_func_veneer> + 8030034: 15c00005 b f030048 <__a_func_veneer> + \.\.\. + f030038: 14000012 b f030080 <__b_func_bti_veneer\+0x8> + f03003c: d503201f nop + +000000000f030040 <__c_func_veneer>: + f030040: d503245f bti c + f030044: 1440000f b 10030080 + +000000000f030048 <__a_func_veneer>: + f030048: 90fc0010 adrp x16, 7030000 + f03004c: 9100a210 add x16, x16, #0x28 + f030050: d61f0200 br x16 + \.\.\. + +000000000f030060 <__extern_func_veneer>: + f030060: 90f87f90 adrp x16, 20000 <\.plt> + f030064: 9100e210 add x16, x16, #0x38 + f030068: d61f0200 br x16 + \.\.\. + +000000000f030078 <__b_func_bti_veneer>: + f030078: d503245f bti c + f03007c: 163fffed b 8030030 + \.\.\. + +0000000010030080 : + 10030080: 17bffff2 b f030048 <__a_func_veneer> + 10030084: 17bffffd b f030078 <__b_func_bti_veneer> + 10030088: 17bffff6 b f030060 <__extern_func_veneer> diff --git a/ld/testsuite/ld-aarch64/bti-far-3.ld b/ld/testsuite/ld-aarch64/bti-far-3.ld new file mode 100644 index 00000000000..3265c55b8cc --- /dev/null +++ b/ld/testsuite/ld-aarch64/bti-far-3.ld @@ -0,0 +1,12 @@ +OUTPUT_ARCH(aarch64) +SECTIONS +{ + . = 0x00010000; + .rela.plt : { *(.rela.plt) *(.rela.iplt) } + . = 0x00020000; + .plt : { *(.plt) *(.iplt) } + . = 0x00030000; + .text : { *(.text) } + . = 0x20000000; + .got : { *(.got) *(.got.plt) } +} diff --git a/ld/testsuite/ld-aarch64/bti-far-3a.s b/ld/testsuite/ld-aarch64/bti-far-3a.s new file mode 100644 index 00000000000..ed53545fed7 --- /dev/null +++ b/ld/testsuite/ld-aarch64/bti-far-3a.s @@ -0,0 +1,23 @@ + .text + .hidden a_func + .hidden b_func + .hidden c_func + + .global a_func + .type a_func, %function +a_func: + b b_func + b extern_func + +.zero 0x07000000 + + .section .note.gnu.property,"a" + .align 3 + .word 4 + .word 16 + .word 5 + .string "GNU" + .word 3221225472 + .word 4 + .word 1 + .align 3 diff --git a/ld/testsuite/ld-aarch64/bti-far-3b.s b/ld/testsuite/ld-aarch64/bti-far-3b.s new file mode 100644 index 00000000000..1f3be3d15cf --- /dev/null +++ b/ld/testsuite/ld-aarch64/bti-far-3b.s @@ -0,0 +1,25 @@ + .text + .hidden a_func + .hidden b_func + .hidden c_func + +.zero 0x01000000 + + .global b_func + .type b_func, %function +b_func: + b c_func + b a_func + +.zero 0x07000000 + + .section .note.gnu.property,"a" + .align 3 + .word 4 + .word 16 + .word 5 + .string "GNU" + .word 3221225472 + .word 4 + .word 1 + .align 3 diff --git a/ld/testsuite/ld-aarch64/bti-far-3c.s b/ld/testsuite/ld-aarch64/bti-far-3c.s new file mode 100644 index 00000000000..8e2361fd771 --- /dev/null +++ b/ld/testsuite/ld-aarch64/bti-far-3c.s @@ -0,0 +1,24 @@ + .text + .hidden a_func + .hidden b_func + .hidden c_func + +.zero 0x01000000 + + .global c_func + .type c_func, %function +c_func: + b a_func + b b_func + b extern_func + + .section .note.gnu.property,"a" + .align 3 + .word 4 + .word 16 + .word 5 + .string "GNU" + .word 3221225472 + .word 4 + .word 1 + .align 3 -- 2.30.2