* [PATCH v2 0/2] aarch64: fix DT_RELR with discarded sections
@ 2024-06-04 17:41 Szabolcs Nagy
2024-06-04 17:41 ` [PATCH v2 1/2] aarch64: Fix DT_RELR support " Szabolcs Nagy
2024-06-04 17:41 ` [PATCH v2 2/2] aarch64: Test DT_RELR " Szabolcs Nagy
0 siblings, 2 replies; 7+ messages in thread
From: Szabolcs Nagy @ 2024-06-04 17:41 UTC (permalink / raw)
To: binutils
v2:
- update commit msg
- simplify the testcase
Szabolcs Nagy (2):
aarch64: Fix DT_RELR support with discarded sections
aarch64: Test DT_RELR with discarded sections
bfd/elfnn-aarch64.c | 4 ++
ld/testsuite/ld-aarch64/aarch64-elf.exp | 2 +
ld/testsuite/ld-aarch64/relr-discard-pie.d | 15 +++++
ld/testsuite/ld-aarch64/relr-discard-shared.d | 15 +++++
ld/testsuite/ld-aarch64/relr-discard.ld | 13 ++++
ld/testsuite/ld-aarch64/relr-discard.s | 63 +++++++++++++++++++
6 files changed, 112 insertions(+)
create mode 100644 ld/testsuite/ld-aarch64/relr-discard-pie.d
create mode 100644 ld/testsuite/ld-aarch64/relr-discard-shared.d
create mode 100644 ld/testsuite/ld-aarch64/relr-discard.ld
create mode 100644 ld/testsuite/ld-aarch64/relr-discard.s
--
2.25.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 1/2] aarch64: Fix DT_RELR support with discarded sections
2024-06-04 17:41 [PATCH v2 0/2] aarch64: fix DT_RELR with discarded sections Szabolcs Nagy
@ 2024-06-04 17:41 ` Szabolcs Nagy
2024-06-06 1:17 ` Alan Modra
2024-06-04 17:41 ` [PATCH v2 2/2] aarch64: Test DT_RELR " Szabolcs Nagy
1 sibling, 1 reply; 7+ messages in thread
From: Szabolcs Nagy @ 2024-06-04 17:41 UTC (permalink / raw)
To: binutils
In case of discarded sections, via /DISCARD/ or .gnu.linkonce,
relr relocation accounting was wrong. This broke building linux.
The issue was that the *_relocate_section logic was copied to
*_late_size_sections to record relative relocations that can
be packed, however *_relocate_section is not called on sections
that are discarded, while record_relr_non_got_relocs is called
for all input sections. The fix is to filter out the discarded
sections with the same logic that is used to count non-GOT
relocs for local symbols earlier.
GOT relocations are affected too if all sections are discarded
that reference the GOT entry of a particular symbol, however
this can cause unused GOT entries independently of DT_RELR, and
the only difference with DT_RELR is that a relative reloc may be
emitted instead of a R_AARCH64_NONE for the unused GOT entry
which is acceptable. A proper fix would require redoing the GOT
refcounting after we know the discarded sections.
---
v2:
- only commit msg update: i realized that the GOT case is not
handled right when DT_RELR is disabled so there is no point
trying to fix that here and unnecessary relative relocation
in such corner-case is acceptable. i updated the test case
patch to cover the GOT cases that currently work.
---
bfd/elfnn-aarch64.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 81f1a646125..02873f2ceb2 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -9327,6 +9327,10 @@ record_relr_non_got_relocs (bfd *input_bfd, struct bfd_link_info *info,
return true;
if (sec->alignment_power == 0)
return true;
+ if (!bfd_is_abs_section (sec)
+ && bfd_is_abs_section (sec->output_section))
+ /* Input section has been discarded. */
+ return true;
sreloc = elf_section_data (sec)->sreloc;
if (sreloc == NULL)
return true;
--
2.25.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 2/2] aarch64: Test DT_RELR with discarded sections
2024-06-04 17:41 [PATCH v2 0/2] aarch64: fix DT_RELR with discarded sections Szabolcs Nagy
2024-06-04 17:41 ` [PATCH v2 1/2] aarch64: Fix DT_RELR support " Szabolcs Nagy
@ 2024-06-04 17:41 ` Szabolcs Nagy
2024-06-06 1:23 ` Alan Modra
1 sibling, 1 reply; 7+ messages in thread
From: Szabolcs Nagy @ 2024-06-04 17:41 UTC (permalink / raw)
To: binutils
---
ld/testsuite/ld-aarch64/aarch64-elf.exp | 2 +
ld/testsuite/ld-aarch64/relr-discard-pie.d | 15 +++++
ld/testsuite/ld-aarch64/relr-discard-shared.d | 15 +++++
ld/testsuite/ld-aarch64/relr-discard.ld | 13 ++++
ld/testsuite/ld-aarch64/relr-discard.s | 63 +++++++++++++++++++
5 files changed, 108 insertions(+)
create mode 100644 ld/testsuite/ld-aarch64/relr-discard-pie.d
create mode 100644 ld/testsuite/ld-aarch64/relr-discard-shared.d
create mode 100644 ld/testsuite/ld-aarch64/relr-discard.ld
create mode 100644 ld/testsuite/ld-aarch64/relr-discard.s
diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp
index 38929ffc3c6..0e70ca3e028 100644
--- a/ld/testsuite/ld-aarch64/aarch64-elf.exp
+++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp
@@ -475,6 +475,8 @@ run_dump_test_lp64 "relr-got-pie"
run_dump_test_lp64 "relr-got-shared"
run_dump_test_lp64 "relr-text-pie"
run_dump_test_lp64 "relr-text-shared"
+run_dump_test_lp64 "relr-discard-pie"
+run_dump_test_lp64 "relr-discard-shared"
if { ![skip_sframe_tests] } {
run_dump_test "sframe-simple-1"
diff --git a/ld/testsuite/ld-aarch64/relr-discard-pie.d b/ld/testsuite/ld-aarch64/relr-discard-pie.d
new file mode 100644
index 00000000000..b1d16e30bc9
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/relr-discard-pie.d
@@ -0,0 +1,15 @@
+#source: relr-discard.s
+#ld: -pie --no-apply-dynamic-relocs -z pack-relative-relocs -T relr-discard.ld
+#readelf: -rW
+
+Relocation section '\.rela\.dyn' at offset 0x1.* contains 4 entries:
+ Offset Info Type Symbol's Value Symbol's Name \+ Addend
+0000000000000000 0000000000000000 R_AARCH64_NONE 0
+0000000000000000 0000000000000000 R_AARCH64_NONE 0
+0000000000000000 0000000000000000 R_AARCH64_NONE 0
+0000000000000000 0000000000000000 R_AARCH64_NONE 0
+
+Relocation section '\.relr\.dyn' at offset 0x1.* contains 2 entries which relocate 2 locations:
+Index: Entry Address Symbolic Address
+0000: 0000000000020008 0000000000020008 _GLOBAL_OFFSET_TABLE_ \+ 0x8
+0001: 0000000000000003 0000000000020010 _GLOBAL_OFFSET_TABLE_ \+ 0x10
diff --git a/ld/testsuite/ld-aarch64/relr-discard-shared.d b/ld/testsuite/ld-aarch64/relr-discard-shared.d
new file mode 100644
index 00000000000..b5f3ad87666
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/relr-discard-shared.d
@@ -0,0 +1,15 @@
+#source: relr-discard.s
+#ld: -shared --no-apply-dynamic-relocs -z pack-relative-relocs -T relr-discard.ld
+#readelf: -rW
+
+Relocation section '\.rela\.dyn' at offset 0x1.* contains 5 entries:
+ Offset Info Type Symbol's Value Symbol's Name \+ Addend
+0000000000000000 0000000000000000 R_AARCH64_NONE 0
+0000000000000000 0000000000000000 R_AARCH64_NONE 0
+0000000000000000 0000000000000000 R_AARCH64_NONE 0
+0000000000000000 0000000000000000 R_AARCH64_NONE 0
+0000000000020010 .*00000401 R_AARCH64_GLOB_DAT 000000000001000c sym_global \+ 0
+
+Relocation section '\.relr\.dyn' at offset 0x1.* contains 1 entry which relocates 1 location:
+Index: Entry Address Symbolic Address
+0000: 0000000000020008 0000000000020008 _GLOBAL_OFFSET_TABLE_ \+ 0x8
diff --git a/ld/testsuite/ld-aarch64/relr-discard.ld b/ld/testsuite/ld-aarch64/relr-discard.ld
new file mode 100644
index 00000000000..288ba23e11c
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/relr-discard.ld
@@ -0,0 +1,13 @@
+OUTPUT_ARCH(aarch64)
+ENTRY(_start)
+SECTIONS
+{
+ /DISCARD/ : { *(.discard.*) }
+
+ . = 0x10000;
+ .text : { *(.text) }
+ . = 0x20000;
+ .got : { *(.got) *(.got.plt)}
+ . = 0x30000;
+ .data : { *(.data) *(.data.*) }
+}
diff --git a/ld/testsuite/ld-aarch64/relr-discard.s b/ld/testsuite/ld-aarch64/relr-discard.s
new file mode 100644
index 00000000000..0ed9b4a9098
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/relr-discard.s
@@ -0,0 +1,63 @@
+// Test DT_RELR with references in discarded sections.
+
+.text
+.p2align 3
+.global _start
+_start:
+ nop
+
+sym_local:
+ nop
+
+.global sym_hidden
+.hidden sym_hidden
+sym_hidden:
+ nop
+
+.global sym_global
+sym_global:
+ nop
+
+.global sym_global_abs
+.set sym_global_abs, 42
+
+.global sym_weak_undef
+.weak sym_weak_undef
+
+.section .discard.got_local,"ax"
+ adrp x0, :got:sym_local
+ ldr x0, [x0, :got_lo12:sym_local]
+
+.section .discard.got_global,"ax"
+ adrp x0, :got:sym_global
+ ldr x0, [x0, :got_lo12:sym_global]
+
+.section .discard.local,"a"
+.p2align 1
+discard_local:
+.xword sym_local
+
+.section .discard.hidden,"a"
+.p2align 1
+discard_hidden:
+.xword sym_hidden
+
+.section .discard.global,"a"
+.p2align 1
+discard_global:
+.xword sym_global
+
+.section .discard.global_abs,"a"
+.p2align 1
+discard_global_abs:
+.xword sym_global_abs
+
+.section .discard.weak_undef,"a"
+.p2align 1
+discard_weak_undef:
+.xword sym_weak_undef
+
+.section .discard._DYNAMIC,"a"
+.p2align 1
+discard_DYNAMIC:
+.xword _DYNAMIC
--
2.25.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/2] aarch64: Fix DT_RELR support with discarded sections
2024-06-04 17:41 ` [PATCH v2 1/2] aarch64: Fix DT_RELR support " Szabolcs Nagy
@ 2024-06-06 1:17 ` Alan Modra
2024-06-06 7:57 ` Szabolcs Nagy
0 siblings, 1 reply; 7+ messages in thread
From: Alan Modra @ 2024-06-06 1:17 UTC (permalink / raw)
To: Szabolcs Nagy; +Cc: binutils
On Tue, Jun 04, 2024 at 06:41:34PM +0100, Szabolcs Nagy wrote:
> --- a/bfd/elfnn-aarch64.c
> +++ b/bfd/elfnn-aarch64.c
> @@ -9327,6 +9327,10 @@ record_relr_non_got_relocs (bfd *input_bfd, struct bfd_link_info *info,
> return true;
> if (sec->alignment_power == 0)
> return true;
> + if (!bfd_is_abs_section (sec)
> + && bfd_is_abs_section (sec->output_section))
> + /* Input section has been discarded. */
> + return true;
I think you should be using discarded_section here and in
elfNN_aarch64_late_size_sections.
> sreloc = elf_section_data (sec)->sreloc;
> if (sreloc == NULL)
> return true;
> --
> 2.25.1
--
Alan Modra
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/2] aarch64: Test DT_RELR with discarded sections
2024-06-04 17:41 ` [PATCH v2 2/2] aarch64: Test DT_RELR " Szabolcs Nagy
@ 2024-06-06 1:23 ` Alan Modra
2024-06-06 8:08 ` Szabolcs Nagy
0 siblings, 1 reply; 7+ messages in thread
From: Alan Modra @ 2024-06-06 1:23 UTC (permalink / raw)
To: Szabolcs Nagy; +Cc: binutils
On Tue, Jun 04, 2024 at 06:41:45PM +0100, Szabolcs Nagy wrote:
> ---
> ld/testsuite/ld-aarch64/aarch64-elf.exp | 2 +
> ld/testsuite/ld-aarch64/relr-discard-pie.d | 15 +++++
> ld/testsuite/ld-aarch64/relr-discard-shared.d | 15 +++++
> ld/testsuite/ld-aarch64/relr-discard.ld | 13 ++++
> ld/testsuite/ld-aarch64/relr-discard.s | 63 +++++++++++++++++++
> 5 files changed, 108 insertions(+)
> create mode 100644 ld/testsuite/ld-aarch64/relr-discard-pie.d
> create mode 100644 ld/testsuite/ld-aarch64/relr-discard-shared.d
> create mode 100644 ld/testsuite/ld-aarch64/relr-discard.ld
> create mode 100644 ld/testsuite/ld-aarch64/relr-discard.s
>
> diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp
> index 38929ffc3c6..0e70ca3e028 100644
> --- a/ld/testsuite/ld-aarch64/aarch64-elf.exp
> +++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp
> @@ -475,6 +475,8 @@ run_dump_test_lp64 "relr-got-pie"
> run_dump_test_lp64 "relr-got-shared"
> run_dump_test_lp64 "relr-text-pie"
> run_dump_test_lp64 "relr-text-shared"
> +run_dump_test_lp64 "relr-discard-pie"
> +run_dump_test_lp64 "relr-discard-shared"
>
> if { ![skip_sframe_tests] } {
> run_dump_test "sframe-simple-1"
> diff --git a/ld/testsuite/ld-aarch64/relr-discard-pie.d b/ld/testsuite/ld-aarch64/relr-discard-pie.d
> new file mode 100644
> index 00000000000..b1d16e30bc9
> --- /dev/null
> +++ b/ld/testsuite/ld-aarch64/relr-discard-pie.d
> @@ -0,0 +1,15 @@
> +#source: relr-discard.s
> +#ld: -pie --no-apply-dynamic-relocs -z pack-relative-relocs -T relr-discard.ld
> +#readelf: -rW
> +
> +Relocation section '\.rela\.dyn' at offset 0x1.* contains 4 entries:
> + Offset Info Type Symbol's Value Symbol's Name \+ Addend
> +0000000000000000 0000000000000000 R_AARCH64_NONE 0
> +0000000000000000 0000000000000000 R_AARCH64_NONE 0
> +0000000000000000 0000000000000000 R_AARCH64_NONE 0
> +0000000000000000 0000000000000000 R_AARCH64_NONE 0
> +
I must say I don't really like matching bad behaviour in a test, but I
guess this ensures you don't have both .rela.dyn and .relr.dyn relocs
against G_O_T, so OK.
> +Relocation section '\.relr\.dyn' at offset 0x1.* contains 2 entries which relocate 2 locations:
> +Index: Entry Address Symbolic Address
> +0000: 0000000000020008 0000000000020008 _GLOBAL_OFFSET_TABLE_ \+ 0x8
> +0001: 0000000000000003 0000000000020010 _GLOBAL_OFFSET_TABLE_ \+ 0x10
> diff --git a/ld/testsuite/ld-aarch64/relr-discard-shared.d b/ld/testsuite/ld-aarch64/relr-discard-shared.d
> new file mode 100644
> index 00000000000..b5f3ad87666
> --- /dev/null
> +++ b/ld/testsuite/ld-aarch64/relr-discard-shared.d
> @@ -0,0 +1,15 @@
> +#source: relr-discard.s
> +#ld: -shared --no-apply-dynamic-relocs -z pack-relative-relocs -T relr-discard.ld
> +#readelf: -rW
> +
> +Relocation section '\.rela\.dyn' at offset 0x1.* contains 5 entries:
> + Offset Info Type Symbol's Value Symbol's Name \+ Addend
> +0000000000000000 0000000000000000 R_AARCH64_NONE 0
> +0000000000000000 0000000000000000 R_AARCH64_NONE 0
> +0000000000000000 0000000000000000 R_AARCH64_NONE 0
> +0000000000000000 0000000000000000 R_AARCH64_NONE 0
> +0000000000020010 .*00000401 R_AARCH64_GLOB_DAT 000000000001000c sym_global \+ 0
> +
> +Relocation section '\.relr\.dyn' at offset 0x1.* contains 1 entry which relocates 1 location:
> +Index: Entry Address Symbolic Address
> +0000: 0000000000020008 0000000000020008 _GLOBAL_OFFSET_TABLE_ \+ 0x8
> diff --git a/ld/testsuite/ld-aarch64/relr-discard.ld b/ld/testsuite/ld-aarch64/relr-discard.ld
> new file mode 100644
> index 00000000000..288ba23e11c
> --- /dev/null
> +++ b/ld/testsuite/ld-aarch64/relr-discard.ld
> @@ -0,0 +1,13 @@
> +OUTPUT_ARCH(aarch64)
> +ENTRY(_start)
> +SECTIONS
> +{
> + /DISCARD/ : { *(.discard.*) }
> +
> + . = 0x10000;
> + .text : { *(.text) }
> + . = 0x20000;
> + .got : { *(.got) *(.got.plt)}
> + . = 0x30000;
> + .data : { *(.data) *(.data.*) }
> +}
> diff --git a/ld/testsuite/ld-aarch64/relr-discard.s b/ld/testsuite/ld-aarch64/relr-discard.s
> new file mode 100644
> index 00000000000..0ed9b4a9098
> --- /dev/null
> +++ b/ld/testsuite/ld-aarch64/relr-discard.s
> @@ -0,0 +1,63 @@
> +// Test DT_RELR with references in discarded sections.
> +
> +.text
> +.p2align 3
> +.global _start
> +_start:
> + nop
> +
> +sym_local:
> + nop
> +
> +.global sym_hidden
> +.hidden sym_hidden
> +sym_hidden:
> + nop
> +
> +.global sym_global
> +sym_global:
> + nop
> +
> +.global sym_global_abs
> +.set sym_global_abs, 42
> +
> +.global sym_weak_undef
> +.weak sym_weak_undef
> +
> +.section .discard.got_local,"ax"
> + adrp x0, :got:sym_local
> + ldr x0, [x0, :got_lo12:sym_local]
> +
> +.section .discard.got_global,"ax"
> + adrp x0, :got:sym_global
> + ldr x0, [x0, :got_lo12:sym_global]
> +
> +.section .discard.local,"a"
> +.p2align 1
> +discard_local:
> +.xword sym_local
> +
> +.section .discard.hidden,"a"
> +.p2align 1
> +discard_hidden:
> +.xword sym_hidden
> +
> +.section .discard.global,"a"
> +.p2align 1
> +discard_global:
> +.xword sym_global
> +
> +.section .discard.global_abs,"a"
> +.p2align 1
> +discard_global_abs:
> +.xword sym_global_abs
> +
> +.section .discard.weak_undef,"a"
> +.p2align 1
> +discard_weak_undef:
> +.xword sym_weak_undef
> +
> +.section .discard._DYNAMIC,"a"
> +.p2align 1
> +discard_DYNAMIC:
> +.xword _DYNAMIC
> --
> 2.25.1
--
Alan Modra
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/2] aarch64: Fix DT_RELR support with discarded sections
2024-06-06 1:17 ` Alan Modra
@ 2024-06-06 7:57 ` Szabolcs Nagy
0 siblings, 0 replies; 7+ messages in thread
From: Szabolcs Nagy @ 2024-06-06 7:57 UTC (permalink / raw)
To: Alan Modra; +Cc: binutils
The 06/06/2024 10:47, Alan Modra wrote:
> On Tue, Jun 04, 2024 at 06:41:34PM +0100, Szabolcs Nagy wrote:
> > --- a/bfd/elfnn-aarch64.c
> > +++ b/bfd/elfnn-aarch64.c
> > @@ -9327,6 +9327,10 @@ record_relr_non_got_relocs (bfd *input_bfd, struct bfd_link_info *info,
> > return true;
> > if (sec->alignment_power == 0)
> > return true;
> > + if (!bfd_is_abs_section (sec)
> > + && bfd_is_abs_section (sec->output_section))
> > + /* Input section has been discarded. */
> > + return true;
>
> I think you should be using discarded_section here and in
> elfNN_aarch64_late_size_sections.
i was not sure why late_size_sections did it this way.
i will fix it.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/2] aarch64: Test DT_RELR with discarded sections
2024-06-06 1:23 ` Alan Modra
@ 2024-06-06 8:08 ` Szabolcs Nagy
0 siblings, 0 replies; 7+ messages in thread
From: Szabolcs Nagy @ 2024-06-06 8:08 UTC (permalink / raw)
To: Alan Modra; +Cc: binutils
The 06/06/2024 10:53, Alan Modra wrote:
> On Tue, Jun 04, 2024 at 06:41:45PM +0100, Szabolcs Nagy wrote:
> > --- /dev/null
> > +++ b/ld/testsuite/ld-aarch64/relr-discard-pie.d
> > @@ -0,0 +1,15 @@
> > +#source: relr-discard.s
> > +#ld: -pie --no-apply-dynamic-relocs -z pack-relative-relocs -T relr-discard.ld
> > +#readelf: -rW
> > +
> > +Relocation section '\.rela\.dyn' at offset 0x1.* contains 4 entries:
> > + Offset Info Type Symbol's Value Symbol's Name \+ Addend
> > +0000000000000000 0000000000000000 R_AARCH64_NONE 0
> > +0000000000000000 0000000000000000 R_AARCH64_NONE 0
> > +0000000000000000 0000000000000000 R_AARCH64_NONE 0
> > +0000000000000000 0000000000000000 R_AARCH64_NONE 0
> > +
>
> I must say I don't really like matching bad behaviour in a test, but I
> guess this ensures you don't have both .rela.dyn and .relr.dyn relocs
> against G_O_T, so OK.
i think we can fix relr behaviour and the test once
https://sourceware.org/bugzilla/show_bug.cgi?id=31847
is fixed, i will add a comment.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-06-06 8:09 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-04 17:41 [PATCH v2 0/2] aarch64: fix DT_RELR with discarded sections Szabolcs Nagy
2024-06-04 17:41 ` [PATCH v2 1/2] aarch64: Fix DT_RELR support " Szabolcs Nagy
2024-06-06 1:17 ` Alan Modra
2024-06-06 7:57 ` Szabolcs Nagy
2024-06-04 17:41 ` [PATCH v2 2/2] aarch64: Test DT_RELR " Szabolcs Nagy
2024-06-06 1:23 ` Alan Modra
2024-06-06 8:08 ` Szabolcs Nagy
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).