public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Szabolcs Nagy <szabolcs.nagy@arm.com>
To: <binutils@sourceware.org>
Subject: [PATCH 5/5] ld: aarch64: Add BTI stub insertion test PR30930
Date: Fri, 3 Nov 2023 13:22:22 +0000	[thread overview]
Message-ID: <a3d13aae87880260e293ea2a9b351f1232261a6e.1699016830.git.szabolcs.nagy@arm.com> (raw)
In-Reply-To: <cover.1699016830.git.szabolcs.nagy@arm.com>

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..4c076985a0e
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/bti-far-3.d
@@ -0,0 +1,87 @@
+#name: Check linker stubs with indirect calls handle BTI (exe).
+#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 <extern_func@plt>:
+   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 <extern_func@plt>
+
+Disassembly of section \.text:
+
+0000000000030000 <a_func>:
+       30000:	15c00004 	b	7030010 <__b_func_veneer>
+       30004:	17ffc007 	b	20020 <extern_func@plt>
+	\.\.\.
+     7030008:	1400000a 	b	7030030 <__a_func_bti_veneer\+0x8>
+     703000c:	d503201f 	nop
+
+0000000007030010 <__b_func_veneer>:
+     7030010:	90040010 	adrp	x16, f030000 <b_func\+0x6ffffd0>
+     7030014:	9101e210 	add	x16, x16, #0x78
+     7030018:	d61f0200 	br	x16
+	\.\.\.
+
+0000000007030028 <__a_func_bti_veneer>:
+     7030028:	d503245f 	bti	c
+     703002c:	163ffff5 	b	30000 <a_func>
+	\.\.\.
+
+0000000008030030 <b_func>:
+     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 <c_func>
+
+000000000f030048 <__a_func_veneer>:
+     f030048:	90fc0010 	adrp	x16, 7030000 <a_func\+0x7000000>
+     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 <b_func>
+	\.\.\.
+
+0000000010030080 <c_func>:
+    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.25.1


WARNING: multiple messages have this Message-ID
From: Szabolcs Nagy <szabolcs.nagy@arm.com>
To: <binutils@sourceware.org>
Subject: [PATCH 5/5] ld: aarch64: Add BTI stub insertion test PR30930
Date: Fri, 3 Nov 2023 13:15:56 +0000	[thread overview]
Message-ID: <a3d13aae87880260e293ea2a9b351f1232261a6e.1699016830.git.szabolcs.nagy@arm.com> (raw)
Message-ID: <20231103131556.HRJm2E8LaFX78YZpaI4QtQrHKgGHDUgKeCA4SSmUeXA@z> (raw)
In-Reply-To: <cover.1699016830.git.szabolcs.nagy@arm.com>

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..4c076985a0e
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/bti-far-3.d
@@ -0,0 +1,87 @@
+#name: Check linker stubs with indirect calls handle BTI (exe).
+#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 <extern_func@plt>:
+   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 <extern_func@plt>
+
+Disassembly of section \.text:
+
+0000000000030000 <a_func>:
+       30000:	15c00004 	b	7030010 <__b_func_veneer>
+       30004:	17ffc007 	b	20020 <extern_func@plt>
+	\.\.\.
+     7030008:	1400000a 	b	7030030 <__a_func_bti_veneer\+0x8>
+     703000c:	d503201f 	nop
+
+0000000007030010 <__b_func_veneer>:
+     7030010:	90040010 	adrp	x16, f030000 <b_func\+0x6ffffd0>
+     7030014:	9101e210 	add	x16, x16, #0x78
+     7030018:	d61f0200 	br	x16
+	\.\.\.
+
+0000000007030028 <__a_func_bti_veneer>:
+     7030028:	d503245f 	bti	c
+     703002c:	163ffff5 	b	30000 <a_func>
+	\.\.\.
+
+0000000008030030 <b_func>:
+     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 <c_func>
+
+000000000f030048 <__a_func_veneer>:
+     f030048:	90fc0010 	adrp	x16, 7030000 <a_func\+0x7000000>
+     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 <b_func>
+	\.\.\.
+
+0000000010030080 <c_func>:
+    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.25.1


  parent reply	other threads:[~2023-11-03 13:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-03 13:15 [PATCH 0/5] aarch64 BTI stub fixes Szabolcs Nagy
2023-11-03 13:15 ` [PATCH 1/5] bfd: aarch64: Fix BTI stub optimization PR30957 Szabolcs Nagy
2023-11-03 13:15 ` [PATCH 2/5] bfd: aarch64: Fix broken BTI stub PR30930 Szabolcs Nagy
2023-11-03 13:15 ` [PATCH 3/5] bfd: aarch64: Fix leaks in case of BTI stub reuse Szabolcs Nagy
2023-11-03 13:15 ` [PATCH 4/5] bfd: aarch64: Avoid BTI stub for a PLT that has BTI Szabolcs Nagy
2023-11-03 13:22 ` Szabolcs Nagy [this message]
2023-11-03 13:15   ` [PATCH 5/5] ld: aarch64: Add BTI stub insertion test PR30930 Szabolcs Nagy
2023-11-07 11:38 ` [PATCH 0/5] aarch64 BTI stub fixes Nick Clifton
2023-11-07 13:08   ` Szabolcs Nagy
2023-11-09 14:58     ` Szabolcs Nagy
2023-11-17  8:42       ` Fangrui Song
     [not found]       ` <DS7PR12MB5765CE9DC452CD430E68B89BCBB7A@DS7PR12MB5765.namprd12.prod.outlook.com>
2023-11-20 14:56         ` Szabolcs Nagy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a3d13aae87880260e293ea2a9b351f1232261a6e.1699016830.git.szabolcs.nagy@arm.com \
    --to=szabolcs.nagy@arm.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).