From: "H.J. Lu" <hjl.tools@gmail.com>
To: binutils@sourceware.org
Subject: [PATCH] elf: Set ELFOSABI_GNU for SHF_GNU_RETAIN only for ld -r
Date: Thu, 17 Dec 2020 06:41:36 -0800 [thread overview]
Message-ID: <20201217144136.1148445-1-hjl.tools@gmail.com> (raw)
Set ELFOSABI_GNU for SHF_GNU_RETAIN sections only when generating
relocatable output since SHF_GNU_RETAIN has no impact on shared object
nor executable.
I will check it in tomorrow if there are no objections.
H.J.
---
bfd/
PR ld/27091
* elf.c (_bfd_elf_final_write_processing): Set ELFOSABI_GNU
for SHF_GNU_RETAIN sections only when generating ET_REL output.
ld/
PR ld/27091
* testsuite/ld-elf/retain7.s: New file.
* testsuite/ld-elf/retain7a.d: Likewise.
* testsuite/ld-elf/retain7b.d: Likewise.
---
bfd/elf.c | 8 +++++---
ld/testsuite/ld-elf/retain7.s | 5 +++++
ld/testsuite/ld-elf/retain7a.d | 11 +++++++++++
ld/testsuite/ld-elf/retain7b.d | 10 ++++++++++
4 files changed, 31 insertions(+), 3 deletions(-)
create mode 100644 ld/testsuite/ld-elf/retain7.s
create mode 100644 ld/testsuite/ld-elf/retain7a.d
create mode 100644 ld/testsuite/ld-elf/retain7b.d
diff --git a/bfd/elf.c b/bfd/elf.c
index 9c82912aeb..e601bfc1de 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -12466,9 +12466,11 @@ _bfd_elf_final_write_processing (bfd *abfd)
i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi;
/* Set the osabi field to ELFOSABI_GNU if the binary contains
- SHF_GNU_MBIND or SHF_GNU_RETAIN sections or symbols of STT_GNU_IFUNC type
- or STB_GNU_UNIQUE binding. */
- if (elf_tdata (abfd)->has_gnu_osabi != 0)
+ SHF_GNU_MBIND sections or symbols of STT_GNU_IFUNC type or
+ or STB_GNU_UNIQUE binding. Set the osabi field to ELFOSABI_GNU
+ for SHF_GNU_RETAIN sections only when generating ET_REL output. */
+ if ((elf_tdata (abfd)->has_gnu_osabi
+ & (i_ehdrp->e_type == ET_REL ? -1 : ~elf_gnu_osabi_retain)) != 0)
{
if (i_ehdrp->e_ident[EI_OSABI] == ELFOSABI_NONE)
i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_GNU;
diff --git a/ld/testsuite/ld-elf/retain7.s b/ld/testsuite/ld-elf/retain7.s
new file mode 100644
index 0000000000..a6cc86988c
--- /dev/null
+++ b/ld/testsuite/ld-elf/retain7.s
@@ -0,0 +1,5 @@
+ .type _start,"function"
+ .section .text,"axR",%progbits
+ .global _start
+_start:
+ .nop
diff --git a/ld/testsuite/ld-elf/retain7a.d b/ld/testsuite/ld-elf/retain7a.d
new file mode 100644
index 0000000000..544ff8a173
--- /dev/null
+++ b/ld/testsuite/ld-elf/retain7a.d
@@ -0,0 +1,11 @@
+#name: SHF_GNU_RETAIN 7a
+#source: retain7.s
+#ld: -e _start --gc-sections
+#notarget: ![supports_gnu_osabi] ![check_gc_sections_available]
+#readelf: -h
+
+#failif
+ELF Header:
+#...
+ OS/ABI: UNIX - GNU
+#pass
diff --git a/ld/testsuite/ld-elf/retain7b.d b/ld/testsuite/ld-elf/retain7b.d
new file mode 100644
index 0000000000..0e5b12b335
--- /dev/null
+++ b/ld/testsuite/ld-elf/retain7b.d
@@ -0,0 +1,10 @@
+#name: SHF_GNU_RETAIN 7a
+#source: retain7.s
+#ld: -r
+#notarget: ![supports_gnu_osabi] ![check_gc_sections_available]
+#readelf: -h
+
+ELF Header:
+#...
+ OS/ABI: UNIX - GNU
+#pass
--
2.29.2
next reply other threads:[~2020-12-17 14:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-17 14:41 H.J. Lu [this message]
2020-12-17 15:03 ` Andreas Schwab
2020-12-17 15:21 ` H.J. Lu
2020-12-17 15:25 ` Andreas Schwab
2020-12-17 15:59 ` [PATCH] elf: Copy elf_gnu_osabi_retain only for relocatable link H.J. Lu
2020-12-18 11:04 ` Alan Modra
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=20201217144136.1148445-1-hjl.tools@gmail.com \
--to=hjl.tools@gmail.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).