ld: Ignore .note.gnu.build-id when placing orphaned notes
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_binutils_build--master-arm |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 |
success
|
Test passed
|
linaro-tcwg-bot/tcwg_binutils_check--master-arm |
success
|
Test passed
|
Commit Message
The commits:
e8e10743f7b Add --rosegment option to BFD linker to stop the '-z separate-code'
from generating two read-only segments.
bf6d7087de0 ld: Move the .note.build-id section to near the start of the memory
map
place .note.gnu.build-id before text sections when --rosegment is used.
Ignore .note.gnu.build-id when placing orphaned notes if --rosegment and
-z separate-code are used together to avoid putting any note sections
between .note.gnu.build-id and text sections in the same PT_LOAD segment.
PR ld/32191
* ldlang.c (lang_insert_orphan): Ignore .note.gnu.build-id when
placing orphaned notes.
* testsuite/ld-elf/pr23658-1a.d: Pass --no-rosegment to ld.
* testsuite/ld-elf/pr23658-1c.d: Likewise.
* testsuite/ld-i386/i386.exp: Run PR ld/32191 test.
* testsuite/ld-i386/pr32191.d: New file.
* testsuite/ld-x86-64/lam-u48.rd: Updated.
* testsuite/ld-x86-64/lam-u57.rd: Likewise.
* testsuite/ld-x86-64/pr32191-x32.d: New file.
* testsuite/ld-x86-64/pr32191.d: Likewise.
* testsuite/ld-x86-64/pr32191.s: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run PR ld/32191 tests.
Comments
On Sat, Sep 21, 2024, 5:25 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> The commits:
>
> e8e10743f7b Add --rosegment option to BFD linker to stop the '-z
> separate-code'
> from generating two read-only segments.
> bf6d7087de0 ld: Move the .note.build-id section to near the start of the
> memory
> map
>
> place .note.gnu.build-id before text sections when --rosegment is used.
> Ignore .note.gnu.build-id when placing orphaned notes if --rosegment and
> -z separate-code are used together to avoid putting any note sections
> between .note.gnu.build-id and text sections in the same PT_LOAD segment.
>
> PR ld/32191
> * ldlang.c (lang_insert_orphan): Ignore .note.gnu.build-id when
> placing orphaned notes.
> * testsuite/ld-elf/pr23658-1a.d: Pass --no-rosegment to ld.
> * testsuite/ld-elf/pr23658-1c.d: Likewise.
> * testsuite/ld-i386/i386.exp: Run PR ld/32191 test.
> * testsuite/ld-i386/pr32191.d: New file.
> * testsuite/ld-x86-64/lam-u48.rd: Updated.
> * testsuite/ld-x86-64/lam-u57.rd: Likewise.
> * testsuite/ld-x86-64/pr32191-x32.d: New file.
> * testsuite/ld-x86-64/pr32191.d: Likewise.
> * testsuite/ld-x86-64/pr32191.s: Likewise.
> * testsuite/ld-x86-64/x86-64.exp: Run PR ld/32191 tests.
>
PING.
>
> --
> H.J.
>
On 9/20/24 22:25, H.J. Lu wrote:
> The commits:
>
> e8e10743f7b Add --rosegment option to BFD linker to stop the '-z separate-code'
> from generating two read-only segments.
> bf6d7087de0 ld: Move the .note.build-id section to near the start of the memory
> map
>
> place .note.gnu.build-id before text sections when --rosegment is used.
> Ignore .note.gnu.build-id when placing orphaned notes if --rosegment and
> -z separate-code are used together to avoid putting any note sections
> between .note.gnu.build-id and text sections in the same PT_LOAD segment.
>
> PR ld/32191
> * ldlang.c (lang_insert_orphan): Ignore .note.gnu.build-id when
> placing orphaned notes.
> * testsuite/ld-elf/pr23658-1a.d: Pass --no-rosegment to ld.
> * testsuite/ld-elf/pr23658-1c.d: Likewise.
> * testsuite/ld-i386/i386.exp: Run PR ld/32191 test.
> * testsuite/ld-i386/pr32191.d: New file.
> * testsuite/ld-x86-64/lam-u48.rd: Updated.
> * testsuite/ld-x86-64/lam-u57.rd: Likewise.
> * testsuite/ld-x86-64/pr32191-x32.d: New file.
> * testsuite/ld-x86-64/pr32191.d: Likewise.
> * testsuite/ld-x86-64/pr32191.s: Likewise.
> * testsuite/ld-x86-64/x86-64.exp: Run PR ld/32191 tests.
Patch approved - please commit.
Cheers
Nick
arc-elf +FAIL: ld-elf/pr23658-1e
arc-linux-uclibc +FAIL: ld-elf/pr23658-1e
arm-nacl +FAIL: ld-elf/pr23658-1e
avr-elf +FAIL: ld-elf/pr23658-1e
cris-elf +FAIL: ld-elf/pr23658-1e
csky-elf +FAIL: ld-elf/pr23658-1e
d10v-elf +FAIL: ld-elf/pr23658-1e
epiphany-elf +FAIL: ld-elf/pr23658-1e
h8300-elf +FAIL: ld-elf/pr23658-1e
h8300-linux-gnu +FAIL: ld-elf/pr23658-1e
hppa64-hp-hpux11.23 +FAIL: ld-elf/pr23658-1e
ip2k-elf +FAIL: ld-elf/pr23658-1e
lm32-elf +FAIL: ld-elf/pr23658-1e
loongarch32-elf +FAIL: ld-elf/pr23658-1e
m32c-elf +FAIL: ld-elf/pr23658-1e
m32r-elf +FAIL: ld-elf/pr23658-1e
m68hc11-elf +FAIL: ld-elf/pr23658-1e
mcore-elf +FAIL: ld-elf/pr23658-1e
mep-elf +FAIL: ld-elf/pr23658-1e
microblaze-elf +FAIL: ld-elf/pr23658-1e
moxie-elf +FAIL: ld-elf/pr23658-1e
nds32be-elf +FAIL: ld-elf/pr23658-1e
nds32le-linux-gnu +FAIL: ld-elf/pr23658-1e
or1k-elf +FAIL: ld-elf/pr23658-1e
riscv32-elf +FAIL: ld-elf/pr23658-1e
rl78-elf +FAIL: ld-elf/pr23658-1e
rx-elf +FAIL: ld-elf/pr23658-1e
spu-elf +FAIL: ld-elf/pr23658-1e
v850-elf +FAIL: ld-elf/pr23658-1e
xstormy16-elf +FAIL: ld-elf/pr23658-1e
xtensa-lx106-elf +FAIL: ld-elf/pr23658-1e
z80-elf +FAIL: ld-elf/pr23658-1e
On Thu, Sep 26, 2024 at 8:52 PM Alan Modra <amodra@gmail.com> wrote:
>
> arc-elf +FAIL: ld-elf/pr23658-1e
> arc-linux-uclibc +FAIL: ld-elf/pr23658-1e
> arm-nacl +FAIL: ld-elf/pr23658-1e
> avr-elf +FAIL: ld-elf/pr23658-1e
> cris-elf +FAIL: ld-elf/pr23658-1e
> csky-elf +FAIL: ld-elf/pr23658-1e
> d10v-elf +FAIL: ld-elf/pr23658-1e
> epiphany-elf +FAIL: ld-elf/pr23658-1e
> h8300-elf +FAIL: ld-elf/pr23658-1e
> h8300-linux-gnu +FAIL: ld-elf/pr23658-1e
> hppa64-hp-hpux11.23 +FAIL: ld-elf/pr23658-1e
> ip2k-elf +FAIL: ld-elf/pr23658-1e
> lm32-elf +FAIL: ld-elf/pr23658-1e
> loongarch32-elf +FAIL: ld-elf/pr23658-1e
> m32c-elf +FAIL: ld-elf/pr23658-1e
> m32r-elf +FAIL: ld-elf/pr23658-1e
> m68hc11-elf +FAIL: ld-elf/pr23658-1e
> mcore-elf +FAIL: ld-elf/pr23658-1e
> mep-elf +FAIL: ld-elf/pr23658-1e
> microblaze-elf +FAIL: ld-elf/pr23658-1e
> moxie-elf +FAIL: ld-elf/pr23658-1e
> nds32be-elf +FAIL: ld-elf/pr23658-1e
> nds32le-linux-gnu +FAIL: ld-elf/pr23658-1e
> or1k-elf +FAIL: ld-elf/pr23658-1e
> riscv32-elf +FAIL: ld-elf/pr23658-1e
> rl78-elf +FAIL: ld-elf/pr23658-1e
> rx-elf +FAIL: ld-elf/pr23658-1e
> spu-elf +FAIL: ld-elf/pr23658-1e
> v850-elf +FAIL: ld-elf/pr23658-1e
> xstormy16-elf +FAIL: ld-elf/pr23658-1e
> xtensa-lx106-elf +FAIL: ld-elf/pr23658-1e
> z80-elf +FAIL: ld-elf/pr23658-1e
>
> --
> Alan Modra
Here is the patch.
On Fri, Sep 27, 2024 at 07:06:30AM +0800, H.J. Lu wrote:
> Since -z separate-code is only supported with shared library and orphaned
Is there a reason why we don't support "-z separate-code", "-z common",
and "-z text" unless targets also support shared libraries?
It seems to me that there is a misplaced "fi" in elf.em.
On Fri, Sep 27, 2024, 8:04 AM Alan Modra <amodra@gmail.com> wrote:
> On Fri, Sep 27, 2024 at 07:06:30AM +0800, H.J. Lu wrote:
> > Since -z separate-code is only supported with shared library and orphaned
>
> Is there a reason why we don't support "-z separate-code", "-z common",
> and "-z text" unless targets also support shared libraries?
>
> It seems to me that there is a misplaced "fi" in elf.em.
>
Good question. But I don't have an answer for this.
> --
> Alan Modra
>
>
On Fri, Sep 27, 2024 at 08:06:31AM +0800, H.J. Lu wrote:
> On Fri, Sep 27, 2024, 8:04 AM Alan Modra <amodra@gmail.com> wrote:
>
> > On Fri, Sep 27, 2024 at 07:06:30AM +0800, H.J. Lu wrote:
> > > Since -z separate-code is only supported with shared library and orphaned
> >
> > Is there a reason why we don't support "-z separate-code", "-z common",
> > and "-z text" unless targets also support shared libraries?
> >
> > It seems to me that there is a misplaced "fi" in elf.em.
> >
>
> Good question. But I don't have an answer for this.
Well, it seems like the required scripts are generated, so..
From 428f3561bc16dfc2944ee641201acdd166315aa2 Mon Sep 17 00:00:00 2001
From: Alan Modra <amodra@gmail.com>
Date: Fri, 27 Sep 2024 09:53:10 +0930
Subject: Enable -z separate-code, -z common and -z text for more targets
Fix a mis-placed "fi".
diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em
index 863657e12f5..2e865728587 100644
--- a/ld/emultempl/elf.em
+++ b/ld/emultempl/elf.em
@@ -1084,6 +1084,7 @@ fragment <<EOF
link_info.relro = false;
EOF
fi
+fi
fragment <<EOF
else if (strcmp (optarg, "separate-code") == 0)
link_info.separate_code = true;
@@ -1100,7 +1101,6 @@ fragment <<EOF
else if (strcmp (optarg, "textoff") == 0)
link_info.textrel_check = textrel_check_none;
EOF
-fi
if test -n "$PARSE_AND_LIST_ARGS_CASE_Z" ; then
fragment <<EOF
diff --git a/ld/testsuite/ld-elf/pr22393-1e.d b/ld/testsuite/ld-elf/pr22393-1e.d
index 51d74fa1381..55f7e9a6e4e 100644
--- a/ld/testsuite/ld-elf/pr22393-1e.d
+++ b/ld/testsuite/ld-elf/pr22393-1e.d
@@ -2,7 +2,7 @@
#ld: -z separate-code
#readelf: -l --wide
#target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi
-#xfail: h8300-*-* rx-*-linux*
+#xfail: rx-*-linux*
#failif
#...
diff --git a/ld/testsuite/ld-elf/pr22393-1f.d b/ld/testsuite/ld-elf/pr22393-1f.d
index 2a44955d0f1..bc61b639658 100644
--- a/ld/testsuite/ld-elf/pr22393-1f.d
+++ b/ld/testsuite/ld-elf/pr22393-1f.d
@@ -2,7 +2,7 @@
#ld: -z separate-code
#readelf: -l --wide
#target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi
-#xfail: h8300-*-* rx-*-linux*
+#xfail: rx-*-linux*
#failif
#...
diff --git a/ld/testsuite/ld-elf/pr30508.d b/ld/testsuite/ld-elf/pr30508.d
index 325ff40f562..16927809030 100644
--- a/ld/testsuite/ld-elf/pr30508.d
+++ b/ld/testsuite/ld-elf/pr30508.d
@@ -2,7 +2,7 @@
#objcopy_linked_file: -R .foo
#readelf: -lW
#target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi
-#xfail: h8300-*-* mips*-*-* rx-*-linux*
+#xfail: mips*-*-* rx-*-linux*
#...
Section to Segment mapping:
On Fri, Sep 27, 2024 at 8:33 AM Alan Modra <amodra@gmail.com> wrote:
>
> On Fri, Sep 27, 2024 at 08:06:31AM +0800, H.J. Lu wrote:
> > On Fri, Sep 27, 2024, 8:04 AM Alan Modra <amodra@gmail.com> wrote:
> >
> > > On Fri, Sep 27, 2024 at 07:06:30AM +0800, H.J. Lu wrote:
> > > > Since -z separate-code is only supported with shared library and orphaned
> > >
> > > Is there a reason why we don't support "-z separate-code", "-z common",
> > > and "-z text" unless targets also support shared libraries?
> > >
> > > It seems to me that there is a misplaced "fi" in elf.em.
> > >
> >
> > Good question. But I don't have an answer for this.
>
> Well, it seems like the required scripts are generated, so..
>
> From 428f3561bc16dfc2944ee641201acdd166315aa2 Mon Sep 17 00:00:00 2001
> From: Alan Modra <amodra@gmail.com>
> Date: Fri, 27 Sep 2024 09:53:10 +0930
> Subject: Enable -z separate-code, -z common and -z text for more targets
>
> Fix a mis-placed "fi".
>
> diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em
> index 863657e12f5..2e865728587 100644
> --- a/ld/emultempl/elf.em
> +++ b/ld/emultempl/elf.em
> @@ -1084,6 +1084,7 @@ fragment <<EOF
> link_info.relro = false;
> EOF
> fi
> +fi
> fragment <<EOF
> else if (strcmp (optarg, "separate-code") == 0)
> link_info.separate_code = true;
> @@ -1100,7 +1101,6 @@ fragment <<EOF
> else if (strcmp (optarg, "textoff") == 0)
> link_info.textrel_check = textrel_check_none;
> EOF
> -fi
>
> if test -n "$PARSE_AND_LIST_ARGS_CASE_Z" ; then
> fragment <<EOF
I don't think -z separate-code works ASAS for targets without shared
library support. On cris-elf, ld-elf/pr23658-1e passes. But ld-elf/pr23658-1e
generates:
Section to Segment mapping:
Segment Sections...
00 .note.gnu.build-id .text .note.4 .note.1 .note.2 .note.3
^^^^^^^^^^^^^^^^^^^^^^^^^^^
This is wrong for -z separate-code. This may be another
symptom for PR ld/32191.
01 .note.gnu.build-id
02 .note.4 .note.1
03 .note.2 .note.3
> diff --git a/ld/testsuite/ld-elf/pr22393-1e.d b/ld/testsuite/ld-elf/pr22393-1e.d
> index 51d74fa1381..55f7e9a6e4e 100644
> --- a/ld/testsuite/ld-elf/pr22393-1e.d
> +++ b/ld/testsuite/ld-elf/pr22393-1e.d
> @@ -2,7 +2,7 @@
> #ld: -z separate-code
> #readelf: -l --wide
> #target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi
> -#xfail: h8300-*-* rx-*-linux*
> +#xfail: rx-*-linux*
>
> #failif
> #...
> diff --git a/ld/testsuite/ld-elf/pr22393-1f.d b/ld/testsuite/ld-elf/pr22393-1f.d
> index 2a44955d0f1..bc61b639658 100644
> --- a/ld/testsuite/ld-elf/pr22393-1f.d
> +++ b/ld/testsuite/ld-elf/pr22393-1f.d
> @@ -2,7 +2,7 @@
> #ld: -z separate-code
> #readelf: -l --wide
> #target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi
> -#xfail: h8300-*-* rx-*-linux*
> +#xfail: rx-*-linux*
>
> #failif
> #...
> diff --git a/ld/testsuite/ld-elf/pr30508.d b/ld/testsuite/ld-elf/pr30508.d
> index 325ff40f562..16927809030 100644
> --- a/ld/testsuite/ld-elf/pr30508.d
> +++ b/ld/testsuite/ld-elf/pr30508.d
> @@ -2,7 +2,7 @@
> #objcopy_linked_file: -R .foo
> #readelf: -lW
> #target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi
> -#xfail: h8300-*-* mips*-*-* rx-*-linux*
> +#xfail: mips*-*-* rx-*-linux*
>
> #...
> Section to Segment mapping:
>
>
> --
> Alan Modra
On Fri, Sep 27, 2024 at 12:26 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Fri, Sep 27, 2024 at 8:33 AM Alan Modra <amodra@gmail.com> wrote:
> >
> > On Fri, Sep 27, 2024 at 08:06:31AM +0800, H.J. Lu wrote:
> > > On Fri, Sep 27, 2024, 8:04 AM Alan Modra <amodra@gmail.com> wrote:
> > >
> > > > On Fri, Sep 27, 2024 at 07:06:30AM +0800, H.J. Lu wrote:
> > > > > Since -z separate-code is only supported with shared library and orphaned
> > > >
> > > > Is there a reason why we don't support "-z separate-code", "-z common",
> > > > and "-z text" unless targets also support shared libraries?
> > > >
> > > > It seems to me that there is a misplaced "fi" in elf.em.
> > > >
> > >
> > > Good question. But I don't have an answer for this.
> >
> > Well, it seems like the required scripts are generated, so..
> >
> > From 428f3561bc16dfc2944ee641201acdd166315aa2 Mon Sep 17 00:00:00 2001
> > From: Alan Modra <amodra@gmail.com>
> > Date: Fri, 27 Sep 2024 09:53:10 +0930
> > Subject: Enable -z separate-code, -z common and -z text for more targets
> >
> > Fix a mis-placed "fi".
> >
> > diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em
> > index 863657e12f5..2e865728587 100644
> > --- a/ld/emultempl/elf.em
> > +++ b/ld/emultempl/elf.em
> > @@ -1084,6 +1084,7 @@ fragment <<EOF
> > link_info.relro = false;
> > EOF
> > fi
> > +fi
> > fragment <<EOF
> > else if (strcmp (optarg, "separate-code") == 0)
> > link_info.separate_code = true;
> > @@ -1100,7 +1101,6 @@ fragment <<EOF
> > else if (strcmp (optarg, "textoff") == 0)
> > link_info.textrel_check = textrel_check_none;
> > EOF
> > -fi
> >
> > if test -n "$PARSE_AND_LIST_ARGS_CASE_Z" ; then
> > fragment <<EOF
>
> I don't think -z separate-code works ASAS for targets without shared
> library support. On cris-elf, ld-elf/pr23658-1e passes. But ld-elf/pr23658-1e
> generates:
>
> Section to Segment mapping:
> Segment Sections...
> 00 .note.gnu.build-id .text .note.4 .note.1 .note.2 .note.3
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^
> This is wrong for -z separate-code. This may be another
> symptom for PR ld/32191.
>
> 01 .note.gnu.build-id
> 02 .note.4 .note.1
> 03 .note.2 .note.3
>
>
> > diff --git a/ld/testsuite/ld-elf/pr22393-1e.d b/ld/testsuite/ld-elf/pr22393-1e.d
> > index 51d74fa1381..55f7e9a6e4e 100644
> > --- a/ld/testsuite/ld-elf/pr22393-1e.d
> > +++ b/ld/testsuite/ld-elf/pr22393-1e.d
> > @@ -2,7 +2,7 @@
> > #ld: -z separate-code
> > #readelf: -l --wide
> > #target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi
> > -#xfail: h8300-*-* rx-*-linux*
> > +#xfail: rx-*-linux*
> >
> > #failif
> > #...
> > diff --git a/ld/testsuite/ld-elf/pr22393-1f.d b/ld/testsuite/ld-elf/pr22393-1f.d
> > index 2a44955d0f1..bc61b639658 100644
> > --- a/ld/testsuite/ld-elf/pr22393-1f.d
> > +++ b/ld/testsuite/ld-elf/pr22393-1f.d
> > @@ -2,7 +2,7 @@
> > #ld: -z separate-code
> > #readelf: -l --wide
> > #target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi
> > -#xfail: h8300-*-* rx-*-linux*
> > +#xfail: rx-*-linux*
> >
> > #failif
> > #...
> > diff --git a/ld/testsuite/ld-elf/pr30508.d b/ld/testsuite/ld-elf/pr30508.d
> > index 325ff40f562..16927809030 100644
> > --- a/ld/testsuite/ld-elf/pr30508.d
> > +++ b/ld/testsuite/ld-elf/pr30508.d
> > @@ -2,7 +2,7 @@
> > #objcopy_linked_file: -R .foo
> > #readelf: -lW
> > #target: *-*-linux-gnu *-*-gnu* *-*-nacl* arm*-*-uclinuxfdpiceabi
> > -#xfail: h8300-*-* mips*-*-* rx-*-linux*
> > +#xfail: mips*-*-* rx-*-linux*
> >
> > #...
> > Section to Segment mapping:
> >
> >
> > --
> > Alan Modra
>
Since orphaned note section placement doesn't work for targets without
.interp in linker script:
https://sourceware.org/bugzilla/show_bug.cgi?id=32219
and -z separate-code doesn't work correctly for all ELF targets,
limit testsuite/ld-elf/pr23658-1e.d to the known working targets.
On Fri, Sep 27, 2024 at 01:33:19PM +0800, H.J. Lu wrote:
> Since orphaned note section placement doesn't work for targets without
> .interp in linker script:
>
> https://sourceware.org/bugzilla/show_bug.cgi?id=32219
>
> and -z separate-code doesn't work correctly for all ELF targets,
>
> limit testsuite/ld-elf/pr23658-1e.d to the known working targets.
Fine by me.
On Sat, Sep 28, 2024 at 2:44 PM Alan Modra <amodra@gmail.com> wrote:
>
> On Fri, Sep 27, 2024 at 01:33:19PM +0800, H.J. Lu wrote:
> > Since orphaned note section placement doesn't work for targets without
> > .interp in linker script:
> >
> > https://sourceware.org/bugzilla/show_bug.cgi?id=32219
> >
> > and -z separate-code doesn't work correctly for all ELF targets,
> >
> > limit testsuite/ld-elf/pr23658-1e.d to the known working targets.
>
> Fine by me.
>
Nick is woring on a fix for PR 32219. I will wait for his patch.
Hopefully his patch will fix most, if not all, failures.
H.J.
From 07ffe0601da8ef38cbf64acccaee0dd143d7d5da Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Fri, 20 Sep 2024 11:32:26 +0800
Subject: [PATCH] ld: Ignore .note.gnu.build-id when placing orphaned notes
The commits:
e8e10743f7b Add --rosegment option to BFD linker to stop the '-z separate-code' from generating two read-only segments.
bf6d7087de0 ld: Move the .note.build-id section to near the start of the memory map
place .note.gnu.build-id before text sections when --rosegment is used.
Ignore .note.gnu.build-id when placing orphaned notes if --rosegment and
-z separate-code are used together to avoid putting any note sections
between .note.gnu.build-id and text sections in the same PT_LOAD segment.
PR ld/32191
* ldlang.c (lang_insert_orphan): Ignore .note.gnu.build-id when
placing orphaned notes.
* testsuite/ld-elf/pr23658-1a.d: Pass --no-rosegment to ld.
* testsuite/ld-elf/pr23658-1c.d: Likewise.
* testsuite/ld-i386/i386.exp: Run PR ld/32191 test.
* testsuite/ld-i386/pr32191.d: New file.
* testsuite/ld-x86-64/lam-u48.rd: Updated.
* testsuite/ld-x86-64/lam-u57.rd: Likewise.
* testsuite/ld-x86-64/pr32191-x32.d: New file.
* testsuite/ld-x86-64/pr32191.d: Likewise.
* testsuite/ld-x86-64/pr32191.s: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run PR ld/32191 tests.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
ld/ldlang.c | 14 +++++++++++++-
ld/testsuite/ld-elf/pr23658-1a.d | 2 +-
ld/testsuite/ld-elf/pr23658-1c.d | 2 +-
ld/testsuite/ld-i386/i386.exp | 1 +
ld/testsuite/ld-i386/pr32191.d | 9 +++++++++
ld/testsuite/ld-x86-64/lam-u48.rd | 1 +
ld/testsuite/ld-x86-64/lam-u57.rd | 1 +
ld/testsuite/ld-x86-64/pr32191-x32.d | 9 +++++++++
ld/testsuite/ld-x86-64/pr32191.d | 9 +++++++++
ld/testsuite/ld-x86-64/pr32191.s | 5 +++++
ld/testsuite/ld-x86-64/x86-64.exp | 2 ++
11 files changed, 52 insertions(+), 3 deletions(-)
create mode 100644 ld/testsuite/ld-i386/pr32191.d
create mode 100644 ld/testsuite/ld-x86-64/pr32191-x32.d
create mode 100644 ld/testsuite/ld-x86-64/pr32191.d
create mode 100644 ld/testsuite/ld-x86-64/pr32191.s
@@ -2047,13 +2047,25 @@ lang_insert_orphan (asection *s,
place orphan note section after non-note sections. */
first_orphan_note = NULL;
+
+ /* NB: When --rosegment is used, the .note.gnu.build-id
+ section is placed before text sections. Ignore the
+ .note.gnu.build-id section if -z separate-code and
+ --rosegment are used together to avoid putting any
+ note sections between the .note.gnu.build-id section
+ and text sections in the same PT_LOAD segment. */
+ bool ignore_build_id = (link_info.separate_code
+ && link_info.one_rosegment);
+
for (sec = link_info.output_bfd->sections;
(sec != NULL
&& !bfd_is_abs_section (sec));
sec = sec->next)
if (sec != snew
&& elf_section_type (sec) == SHT_NOTE
- && (sec->flags & SEC_LOAD) != 0)
+ && (sec->flags & SEC_LOAD) != 0
+ && (!ignore_build_id
+ || strcmp (sec->name, ".note.gnu.build-id") != 0))
{
if (!first_orphan_note)
first_orphan_note = sec;
@@ -3,7 +3,7 @@
#source: pr23658-1c.s
#source: pr23658-1d.s
#source: start.s
-#ld: --build-id
+#ld: --build-id --no-rosegment
#readelf: -l --wide
# Since generic linker targets don't place SHT_NOTE sections as orphan,
# SHT_NOTE sections aren't grouped nor sorted.
@@ -3,7 +3,7 @@
#source: pr23658-1c.s
#source: pr23658-1d.s
#source: start.s
-#ld: --build-id -shared
+#ld: --build-id --no-rosegment -shared
#readelf: -l --wide
#target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
#xfail: ![check_shared_lib_support]
@@ -514,6 +514,7 @@ run_dump_test "pr28870"
run_dump_test "pr28894"
run_dump_test "pr30787"
run_dump_test "pr31047"
+run_dump_test "pr32191"
if { !([istarget "i?86-*-linux*"]
|| [istarget "i?86-*-gnu*"]
new file mode 100644
@@ -0,0 +1,9 @@
+#source: ../ld-x86-64/pr32191.s
+#as: --32 -mx86-used-note=yes
+#ld: -shared -m elf_i386 -z separate-code --build-id --rosegment
+#readelf: -lW
+
+#...
+ +[0-9]+ +\.note\.gnu\.build-id \.text
+ +[0-9]+ +\..* \.note\.gnu\.property .*
+#pass
@@ -1,3 +1,4 @@
+#...
Displaying notes found in: .note.gnu.property
[ ]+Owner[ ]+Data size[ ]+Description
GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0
@@ -1,3 +1,4 @@
+#...
Displaying notes found in: .note.gnu.property
[ ]+Owner[ ]+Data size[ ]+Description
GNU 0x[0-9a-f]+ NT_GNU_PROPERTY_TYPE_0
new file mode 100644
@@ -0,0 +1,9 @@
+#source: pr32191.s
+#as: --x32 -mx86-used-note=yes
+#ld: -shared -m elf32_x86_64 -z separate-code --build-id --rosegment
+#readelf: -lW
+
+#...
+ +[0-9]+ +\.note\.gnu\.build-id \.text
+ +[0-9]+ +\..* \.note\.gnu\.property .*
+#pass
new file mode 100644
@@ -0,0 +1,9 @@
+#source: pr32191.s
+#as: --64 -mx86-used-note=yes
+#ld: -shared -m elf_x86_64 -z separate-code --build-id --rosegment
+#readelf: -lW
+
+#...
+ +[0-9]+ +\.note\.gnu\.build-id \.text
+ +[0-9]+ +\..* \.note\.gnu\.property .*
+#pass
new file mode 100644
@@ -0,0 +1,5 @@
+ .text
+ .global foo
+foo:
+ .nops 4
+ .section .note.GNU-stack,"",@progbits
@@ -541,6 +541,8 @@ run_dump_test "tlsie5"
run_dump_test "tlsdesc3"
run_dump_test "tlsdesc4"
run_dump_test "tlsdesc5"
+run_dump_test "pr32191"
+run_dump_test "pr32191-x32"
if { ![skip_sframe_tests] } {
run_dump_test "sframe-simple-1"
--
2.46.1