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.
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)
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;
--- /dev/null
+#ld: -shared -T pr28597.t
+#error: .*: discarded output section: `.plt'
+#target: i?86-*-* x86_64-*-*
--- /dev/null
+ .text
+ .globl foo
+foo:
+ jmp bar@PLT
--- /dev/null
+SECTIONS
+{
+ .text :
+ {
+ *(.text .text.*)
+ }
+ /DISCARD/ : { *(.dynsym) }
+ /DISCARD/ : { *(.dynstr*) }
+ /DISCARD/ : { *(.dynamic*) }
+ /DISCARD/ : { *(.plt*) }
+ /DISCARD/ : { *(.interp*) }
+ /DISCARD/ : { *(.gnu*) }
+ /DISCARD/ : { *(.note.gnu.property) }
+}