* [PATCH] elf/x86: Issue an error on discarded output .plt section
@ 2021-11-18 15:58 H.J. Lu
2021-11-22 0:08 ` Alan Modra
0 siblings, 1 reply; 3+ messages in thread
From: H.J. Lu @ 2021-11-18 15:58 UTC (permalink / raw)
To: binutils
Issue an error, instead of crash, on discarded output .plt section.
bfd/
PR ld/28597
* elf32-i386.c (elf_i386_finish_dynamic_sections): Issue an error
on discarded output .plt section.
* elf64-x86-64.c (elf_x86_64_finish_dynamic_sections): Likewise.
ld/
PR ld/28597
* testsuite/ld-elf/pr28597.d: New file.
* testsuite/ld-elf/pr28597.s: Likewise.
* testsuite/ld-elf/pr28597.t: Likewise.
---
bfd/elf32-i386.c | 8 ++++++++
bfd/elf64-x86-64.c | 8 ++++++++
ld/testsuite/ld-elf/pr28597.d | 3 +++
ld/testsuite/ld-elf/pr28597.s | 4 ++++
ld/testsuite/ld-elf/pr28597.t | 14 ++++++++++++++
5 files changed, 37 insertions(+)
create mode 100644 ld/testsuite/ld-elf/pr28597.d
create mode 100644 ld/testsuite/ld-elf/pr28597.s
create mode 100644 ld/testsuite/ld-elf/pr28597.t
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 9a9e48becdb..0d7f29097e4 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -4017,6 +4017,14 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd,
if (htab->elf.splt && htab->elf.splt->size > 0)
{
+ if (bfd_is_abs_section (htab->elf.splt->output_section))
+ {
+ info->callbacks->einfo
+ (_("%F%P: discarded output section: `%pA'\n"),
+ htab->elf.splt);
+ return false;
+ }
+
/* UnixWare sets the entsize of .plt to 4, although that doesn't
really seem like the right value. */
elf_section_data (htab->elf.splt->output_section)
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index dc416a7f712..25e2bb156e8 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -4677,6 +4677,14 @@ elf_x86_64_finish_dynamic_sections (bfd *output_bfd,
if (htab->elf.splt && htab->elf.splt->size > 0)
{
+ if (bfd_is_abs_section (htab->elf.splt->output_section))
+ {
+ info->callbacks->einfo
+ (_("%F%P: discarded output section: `%pA'\n"),
+ htab->elf.splt);
+ return false;
+ }
+
elf_section_data (htab->elf.splt->output_section)
->this_hdr.sh_entsize = htab->plt.plt_entry_size;
diff --git a/ld/testsuite/ld-elf/pr28597.d b/ld/testsuite/ld-elf/pr28597.d
new file mode 100644
index 00000000000..886182c120d
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr28597.d
@@ -0,0 +1,3 @@
+#ld: -shared -T pr28597.t
+#error: .*: discarded output section: `.plt'
+#target: i?86-*-* x86_64-*-*
diff --git a/ld/testsuite/ld-elf/pr28597.s b/ld/testsuite/ld-elf/pr28597.s
new file mode 100644
index 00000000000..620a6351cae
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr28597.s
@@ -0,0 +1,4 @@
+ .text
+ .globl foo
+foo:
+ jmp bar@PLT
diff --git a/ld/testsuite/ld-elf/pr28597.t b/ld/testsuite/ld-elf/pr28597.t
new file mode 100644
index 00000000000..1f47a4558c7
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr28597.t
@@ -0,0 +1,14 @@
+SECTIONS
+{
+ .text :
+ {
+ *(.text .text.*)
+ }
+ /DISCARD/ : { *(.dynsym) }
+ /DISCARD/ : { *(.dynstr*) }
+ /DISCARD/ : { *(.dynamic*) }
+ /DISCARD/ : { *(.plt*) }
+ /DISCARD/ : { *(.interp*) }
+ /DISCARD/ : { *(.gnu*) }
+ /DISCARD/ : { *(.note.gnu.property) }
+}
--
2.33.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] elf/x86: Issue an error on discarded output .plt section
2021-11-18 15:58 [PATCH] elf/x86: Issue an error on discarded output .plt section H.J. Lu
@ 2021-11-22 0:08 ` Alan Modra
2021-11-22 0:33 ` H.J. Lu
0 siblings, 1 reply; 3+ messages in thread
From: Alan Modra @ 2021-11-22 0:08 UTC (permalink / raw)
To: H.J. Lu; +Cc: binutils
On Thu, Nov 18, 2021 at 07:58:11AM -0800, H.J. Lu via Binutils wrote:
> Issue an error, instead of crash, on discarded output .plt section.
Are you sure you want an error? There may be uses of the linker where
discarding the .plt via a linker script is deliberate. Obviously it
wouldn't be to create a runnable executable, but ld output is used in
weird ways.
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] elf/x86: Issue an error on discarded output .plt section
2021-11-22 0:08 ` Alan Modra
@ 2021-11-22 0:33 ` H.J. Lu
0 siblings, 0 replies; 3+ messages in thread
From: H.J. Lu @ 2021-11-22 0:33 UTC (permalink / raw)
To: Alan Modra; +Cc: Binutils
On Sun, Nov 21, 2021 at 4:09 PM Alan Modra <amodra@gmail.com> wrote:
>
> On Thu, Nov 18, 2021 at 07:58:11AM -0800, H.J. Lu via Binutils wrote:
> > Issue an error, instead of crash, on discarded output .plt section.
>
> Are you sure you want an error? There may be uses of the linker where
> discarding the .plt via a linker script is deliberate. Obviously it
> wouldn't be to create a runnable executable, but ld output is used in
> weird ways.
>
Yes, an error is appropriate here. If one doesn't want a .plt section,
she/he should discard sections which require a .plt section.
--
H.J.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-22 0:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-18 15:58 [PATCH] elf/x86: Issue an error on discarded output .plt section H.J. Lu
2021-11-22 0:08 ` Alan Modra
2021-11-22 0:33 ` H.J. Lu
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).