* [PATCH] elf: Don't merge sections with different SHF_LINK_ORDER
@ 2023-08-30 17:31 H.J. Lu
2023-08-30 23:50 ` Alan Modra
2023-08-31 8:54 ` Alan Modra
0 siblings, 2 replies; 5+ messages in thread
From: H.J. Lu @ 2023-08-30 17:31 UTC (permalink / raw)
To: binutils
For relocatable link, don't merge 2 SHF_LINK_ORDER sections if output
sections of their linked to sections are different.
* ldelf.c (elf_orphan_compatible): Don't merge sections with
different SHF_LINK_ORDER.
* testsuite/ld-elf/pr30791a.d: New file.
* testsuite/ld-elf/pr30791a.s: Likewise.
* testsuite/ld-elf/pr30791b.d: Likewise.
* testsuite/ld-elf/pr30791b.s: Likewise.
* testsuite/ld-elf/pr30791c.s: Likewise.
* testsuite/ld-elf/pr30791d.s: Likewise.
---
ld/ldelf.c | 7 ++++++-
ld/testsuite/ld-elf/pr30791a.d | 16 ++++++++++++++++
ld/testsuite/ld-elf/pr30791a.s | 20 ++++++++++++++++++++
ld/testsuite/ld-elf/pr30791b.d | 11 +++++++++++
ld/testsuite/ld-elf/pr30791b.s | 20 ++++++++++++++++++++
ld/testsuite/ld-elf/pr30791c.s | 20 ++++++++++++++++++++
ld/testsuite/ld-elf/pr30791d.s | 20 ++++++++++++++++++++
7 files changed, 113 insertions(+), 1 deletion(-)
create mode 100644 ld/testsuite/ld-elf/pr30791a.d
create mode 100644 ld/testsuite/ld-elf/pr30791a.s
create mode 100644 ld/testsuite/ld-elf/pr30791b.d
create mode 100644 ld/testsuite/ld-elf/pr30791b.s
create mode 100644 ld/testsuite/ld-elf/pr30791c.s
create mode 100644 ld/testsuite/ld-elf/pr30791d.s
diff --git a/ld/ldelf.c b/ld/ldelf.c
index 4212075a0e2..d74354a9622 100644
--- a/ld/ldelf.c
+++ b/ld/ldelf.c
@@ -2080,9 +2080,14 @@ elf_orphan_compatible (asection *in, asection *out)
return false;
/* We can't merge with a member of an output section group or merge
two sections with differing SHF_EXCLUDE or other processor and OS
- specific flags when doing a relocatable link. */
+ specific flags or with different SHF_LINK_ORDER when doing a
+ relocatable link. */
if (bfd_link_relocatable (&link_info)
&& (elf_next_in_group (out) != NULL
+ || ((elf_section_flags (in) & SHF_LINK_ORDER) != 0
+ && (elf_section_flags (out) & SHF_LINK_ORDER) != 0
+ && (elf_linked_to_section (in)->output_section
+ != elf_linked_to_section (out)->output_section))
|| ((elf_section_flags (out) ^ elf_section_flags (in))
& (SHF_MASKPROC | SHF_MASKOS)) != 0))
return false;
diff --git a/ld/testsuite/ld-elf/pr30791a.d b/ld/testsuite/ld-elf/pr30791a.d
new file mode 100644
index 00000000000..2446b525fa9
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr30791a.d
@@ -0,0 +1,16 @@
+#source: pr30791a.s
+#source: pr30791b.s
+#ld: -r
+#readelf: -S --wide
+
+#...
+Section Headers:
+#...
+ \[[ 0-9]+\] __patchable_function_entries[ \t]+PROGBITS[ \t0-9a-f]+WAL.*
+#...
+ \[[ 0-9]+\] __patchable_function_entries[ \t]+PROGBITS[ \t0-9a-f]+WAL.*
+#...
+ \[[ 0-9]+\] __patchable_function_entries[ \t]+PROGBITS[ \t0-9a-f]+WAL.*
+#...
+ \[[ 0-9]+\] __patchable_function_entries[ \t]+PROGBITS[ \t0-9a-f]+WAL.*
+#pass
diff --git a/ld/testsuite/ld-elf/pr30791a.s b/ld/testsuite/ld-elf/pr30791a.s
new file mode 100644
index 00000000000..44b75db87d8
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr30791a.s
@@ -0,0 +1,20 @@
+ .section .text.a,"ax",%progbits
+ .globl a
+ .type a, %function
+a:
+.LFB0:
+ .section __patchable_function_entries,"awo",%progbits,.LPFE0
+ .dc.a .LPFE0
+ .section .text.a
+.LPFE0:
+ .byte 0
+ .section .text.b,"ax",%progbits
+ .globl b
+ .type b, %function
+b:
+.LFB1:
+ .section __patchable_function_entries,"awo",%progbits,.LPFE1
+ .dc.a .LPFE1
+ .section .text.b
+.LPFE1:
+ .byte 0
diff --git a/ld/testsuite/ld-elf/pr30791b.d b/ld/testsuite/ld-elf/pr30791b.d
new file mode 100644
index 00000000000..5013c240f8a
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr30791b.d
@@ -0,0 +1,11 @@
+#source: pr30791c.s
+#source: pr30791d.s
+#ld: -r
+#readelf: -S --wide
+
+#failif
+#...
+ \[[ 0-9]+\] __patchable_function_entries[ \t]+PROGBITS[ \t0-9a-f]+WAL.*
+#...
+ \[[ 0-9]+\] __patchable_function_entries[ \t]+PROGBITS[ \t0-9a-f]+WAL.*
+#...
diff --git a/ld/testsuite/ld-elf/pr30791b.s b/ld/testsuite/ld-elf/pr30791b.s
new file mode 100644
index 00000000000..3f97f6c979f
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr30791b.s
@@ -0,0 +1,20 @@
+ .section .text.c,"ax",%progbits
+ .globl c
+ .type c, %function
+c:
+.LFB0:
+ .section __patchable_function_entries,"awo",%progbits,.LPFE0
+ .dc.a .LPFE0
+ .section .text.c
+.LPFE0:
+ .byte 0
+ .section .text.d,"ax",%progbits
+ .globl d
+ .type d, %function
+d:
+.LFB1:
+ .section __patchable_function_entries,"awo",%progbits,.LPFE1
+ .dc.a .LPFE1
+ .section .text.d
+.LPFE1:
+ .byte 0
diff --git a/ld/testsuite/ld-elf/pr30791c.s b/ld/testsuite/ld-elf/pr30791c.s
new file mode 100644
index 00000000000..71ef77bf5e9
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr30791c.s
@@ -0,0 +1,20 @@
+ .text
+ .globl a
+ .type a, %function
+a:
+.LFB0:
+ .section __patchable_function_entries,"awo",%progbits,.LPFE0
+ .dc.a .LPFE0
+ .text
+.LPFE0:
+ .byte 0
+ .text
+ .globl b
+ .type b, %function
+b:
+.LFB1:
+ .section __patchable_function_entries,"awo",%progbits,.LPFE1
+ .dc.a .LPFE1
+ .text
+.LPFE1:
+ .byte 0
diff --git a/ld/testsuite/ld-elf/pr30791d.s b/ld/testsuite/ld-elf/pr30791d.s
new file mode 100644
index 00000000000..5ca1c60bdb9
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr30791d.s
@@ -0,0 +1,20 @@
+ .text
+ .globl c
+ .type c, %function
+c:
+.LFB0:
+ .section __patchable_function_entries,"awo",%progbits,.LPFE0
+ .dc.a .LPFE0
+ .text
+.LPFE0:
+ .byte 0
+ .text
+ .globl d
+ .type d, %function
+d:
+.LFB1:
+ .section __patchable_function_entries,"awo",%progbits,.LPFE1
+ .dc.a .LPFE1
+ .text
+.LPFE1:
+ .byte 0
--
2.41.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] elf: Don't merge sections with different SHF_LINK_ORDER
2023-08-30 17:31 [PATCH] elf: Don't merge sections with different SHF_LINK_ORDER H.J. Lu
@ 2023-08-30 23:50 ` Alan Modra
2023-08-31 8:54 ` Alan Modra
1 sibling, 0 replies; 5+ messages in thread
From: Alan Modra @ 2023-08-30 23:50 UTC (permalink / raw)
To: H.J. Lu; +Cc: binutils
On Wed, Aug 30, 2023 at 10:31:49AM -0700, H.J. Lu via Binutils wrote:
> For relocatable link, don't merge 2 SHF_LINK_ORDER sections if output
> sections of their linked to sections are different.
>
> * ldelf.c (elf_orphan_compatible): Don't merge sections with
> different SHF_LINK_ORDER.
> * testsuite/ld-elf/pr30791a.d: New file.
> * testsuite/ld-elf/pr30791a.s: Likewise.
> * testsuite/ld-elf/pr30791b.d: Likewise.
> * testsuite/ld-elf/pr30791b.s: Likewise.
> * testsuite/ld-elf/pr30791c.s: Likewise.
> * testsuite/ld-elf/pr30791d.s: Likewise.
OK, thanks.
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] elf: Don't merge sections with different SHF_LINK_ORDER
2023-08-30 17:31 [PATCH] elf: Don't merge sections with different SHF_LINK_ORDER H.J. Lu
2023-08-30 23:50 ` Alan Modra
@ 2023-08-31 8:54 ` Alan Modra
2023-08-31 15:44 ` [PATCH] elf: Adjust PR ld/30791 tests H.J. Lu
1 sibling, 1 reply; 5+ messages in thread
From: Alan Modra @ 2023-08-31 8:54 UTC (permalink / raw)
To: H.J. Lu; +Cc: binutils
On Wed, Aug 30, 2023 at 10:31:49AM -0700, H.J. Lu via Binutils wrote:
> For relocatable link, don't merge 2 SHF_LINK_ORDER sections if output
> sections of their linked to sections are different.
d30v-elf +FAIL: ld-elf/pr30791a
dlx-elf +FAIL: ld-elf/pr30791a
fr30-elf +FAIL: ld-elf/pr30791a
frv-elf +FAIL: ld-elf/pr30791a
ft32-elf +FAIL: ld-elf/pr30791a
hppa-linux-gnu +FAIL: ld-elf/pr30791b
iq2000-elf +FAIL: ld-elf/pr30791a
mn10200-elf +FAIL: ld-elf/pr30791a
msp430-elf +FAIL: ld-elf/pr30791a
mt-elf +FAIL: ld-elf/pr30791a
pj-elf +FAIL: ld-elf/pr30791a
s12z-elf +FAIL: ld-elf/pr30791a
xgate-elf +FAIL: ld-elf/pr30791a
z80-elf +FAIL: ld-elf/pr30791a
z80-elf +FAIL: ld-elf/pr30791b
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] elf: Adjust PR ld/30791 tests
2023-08-31 8:54 ` Alan Modra
@ 2023-08-31 15:44 ` H.J. Lu
2023-08-31 22:00 ` Alan Modra
0 siblings, 1 reply; 5+ messages in thread
From: H.J. Lu @ 2023-08-31 15:44 UTC (permalink / raw)
To: Alan Modra; +Cc: Binutils
[-- Attachment #1: Type: text/plain, Size: 1143 bytes --]
On Thu, Aug 31, 2023 at 1:54 AM Alan Modra <amodra@gmail.com> wrote:
>
> On Wed, Aug 30, 2023 at 10:31:49AM -0700, H.J. Lu via Binutils wrote:
> > For relocatable link, don't merge 2 SHF_LINK_ORDER sections if output
> > sections of their linked to sections are different.
>
> d30v-elf +FAIL: ld-elf/pr30791a
> dlx-elf +FAIL: ld-elf/pr30791a
> fr30-elf +FAIL: ld-elf/pr30791a
> frv-elf +FAIL: ld-elf/pr30791a
> ft32-elf +FAIL: ld-elf/pr30791a
> hppa-linux-gnu +FAIL: ld-elf/pr30791b
> iq2000-elf +FAIL: ld-elf/pr30791a
> mn10200-elf +FAIL: ld-elf/pr30791a
> msp430-elf +FAIL: ld-elf/pr30791a
> mt-elf +FAIL: ld-elf/pr30791a
> pj-elf +FAIL: ld-elf/pr30791a
> s12z-elf +FAIL: ld-elf/pr30791a
> xgate-elf +FAIL: ld-elf/pr30791a
> z80-elf +FAIL: ld-elf/pr30791a
> z80-elf +FAIL: ld-elf/pr30791b
>
> --
> Alan Modra
> Australia Development Lab, IBM
Here is a patch to adjust tests.
1. Generic linker targets don't comply with all orhpan section merging
rules.
2. z80 fails since a, b, c, d are registers for z80.
3. hppa fails since .text sections aren't merged for relocatable link.
--
H.J.
[-- Attachment #2: 0001-elf-Adjust-PR-ld-30791-tests.patch --]
[-- Type: text/x-patch, Size: 1646 bytes --]
From 4c41d6f07eb9ea529bbc0d153bfcd8e1b49020ec Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 31 Aug 2023 08:38:10 -0700
Subject: [PATCH] elf: Adjust PR ld/30791 tests
Adjust PR ld/30791 tests:
1. Generic linker targets don't comply with all orhpan section merging
rules.
2. z80 fails since a, b, c, d are registers for z80.
3. hppa fails since .text sections aren't merged for relocatable link.
PR ld/30791
* testsuite/ld-elf/pr30791a.d: Xfail for generic and z80
targets.
* testsuite/ld-elf/pr30791b.d: Xfail for hppa and z80 targets.
---
ld/testsuite/ld-elf/pr30791a.d | 4 ++++
ld/testsuite/ld-elf/pr30791b.d | 3 +++
2 files changed, 7 insertions(+)
diff --git a/ld/testsuite/ld-elf/pr30791a.d b/ld/testsuite/ld-elf/pr30791a.d
index 2446b525fa9..a699f2ab207 100644
--- a/ld/testsuite/ld-elf/pr30791a.d
+++ b/ld/testsuite/ld-elf/pr30791a.d
@@ -2,6 +2,10 @@
#source: pr30791b.s
#ld: -r
#readelf: -S --wide
+#xfail: [is_generic] fr30-*-* frv-*-elf ft32-*-* iq2000-*-* mn10200-*-*
+#xfail: msp430-* mt-*-* z80-*-*
+# Generic linker targets don't comply with all orhpan section merging
+# rules. z80 fails since a, b, c, d are registers for z80.
#...
Section Headers:
diff --git a/ld/testsuite/ld-elf/pr30791b.d b/ld/testsuite/ld-elf/pr30791b.d
index 5013c240f8a..bb8e19e9468 100644
--- a/ld/testsuite/ld-elf/pr30791b.d
+++ b/ld/testsuite/ld-elf/pr30791b.d
@@ -2,6 +2,9 @@
#source: pr30791d.s
#ld: -r
#readelf: -S --wide
+#xfail: hppa-*-* z80-*-*
+# hppa fails since .text sections aren't merged for relocatable link.
+# z80 fails since a, b, c, d are registers for z80.
#failif
#...
--
2.41.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] elf: Adjust PR ld/30791 tests
2023-08-31 15:44 ` [PATCH] elf: Adjust PR ld/30791 tests H.J. Lu
@ 2023-08-31 22:00 ` Alan Modra
0 siblings, 0 replies; 5+ messages in thread
From: Alan Modra @ 2023-08-31 22:00 UTC (permalink / raw)
To: H.J. Lu; +Cc: Binutils
On Thu, Aug 31, 2023 at 08:44:45AM -0700, H.J. Lu wrote:
> On Thu, Aug 31, 2023 at 1:54 AM Alan Modra <amodra@gmail.com> wrote:
> >
> > On Wed, Aug 30, 2023 at 10:31:49AM -0700, H.J. Lu via Binutils wrote:
> > > For relocatable link, don't merge 2 SHF_LINK_ORDER sections if output
> > > sections of their linked to sections are different.
> >
> > d30v-elf +FAIL: ld-elf/pr30791a
> > dlx-elf +FAIL: ld-elf/pr30791a
> > fr30-elf +FAIL: ld-elf/pr30791a
> > frv-elf +FAIL: ld-elf/pr30791a
> > ft32-elf +FAIL: ld-elf/pr30791a
> > hppa-linux-gnu +FAIL: ld-elf/pr30791b
> > iq2000-elf +FAIL: ld-elf/pr30791a
> > mn10200-elf +FAIL: ld-elf/pr30791a
> > msp430-elf +FAIL: ld-elf/pr30791a
> > mt-elf +FAIL: ld-elf/pr30791a
> > pj-elf +FAIL: ld-elf/pr30791a
> > s12z-elf +FAIL: ld-elf/pr30791a
> > xgate-elf +FAIL: ld-elf/pr30791a
> > z80-elf +FAIL: ld-elf/pr30791a
> > z80-elf +FAIL: ld-elf/pr30791b
> >
> Here is a patch to adjust tests.
>
> 1. Generic linker targets don't comply with all orhpan section merging
> rules.
> 2. z80 fails since a, b, c, d are registers for z80.
> 3. hppa fails since .text sections aren't merged for relocatable link.
Thanks for fixing this.
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-08-31 22:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-30 17:31 [PATCH] elf: Don't merge sections with different SHF_LINK_ORDER H.J. Lu
2023-08-30 23:50 ` Alan Modra
2023-08-31 8:54 ` Alan Modra
2023-08-31 15:44 ` [PATCH] elf: Adjust PR ld/30791 tests H.J. Lu
2023-08-31 22:00 ` Alan Modra
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).