From 8d748d1dc56406228c2c76de2563859213364cbf Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Sat, 28 Nov 2020 08:45:02 +1030 Subject: [PATCH] PR26907, segment contains empty SHT_NOBITS section Section ordering is important for _bfd_elf_map_sections_to_segments and assign_file_positions_for_load_sections, which are only prepared to handle sections in increasing LMA order. When zero size sections are involved it is possible to have multiple sections at the same LMA. In that case the zero size sections must sort before any non-zero size sections regardless of their types. bfd/ PR 26907 * elf.c (elf_sort_sections): Don't sort zero size !load sections after load sections. ld/ * testsuite/ld-elf/pr26907.ld, * testsuite/ld-elf/pr26907.s, * testsuite/ld-elf/pr26907.d: New test. --- bfd/ChangeLog | 6 ++++++ bfd/elf.c | 3 ++- ld/ChangeLog | 6 ++++++ ld/testsuite/ld-elf/pr26907.d | 9 +++++++++ ld/testsuite/ld-elf/pr26907.ld | 7 +++++++ ld/testsuite/ld-elf/pr26907.s | 9 +++++++++ 6 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 ld/testsuite/ld-elf/pr26907.d create mode 100644 ld/testsuite/ld-elf/pr26907.ld create mode 100644 ld/testsuite/ld-elf/pr26907.s diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 1e5e92374de..83eb64543b0 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2020-11-28 Alan Modra + + PR 26907 + * elf.c (elf_sort_sections): Don't sort zero size !load sections + after load sections. + 2020-11-27 Jozef Lawrynowicz * elf.c (special_sections_g): Add .gnu.linkonce.n and .gnu.linkonce.p. diff --git a/bfd/elf.c b/bfd/elf.c index 28621da9158..419c5f4420c 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -5257,7 +5257,8 @@ elf_sort_sections (const void *arg1, const void *arg2) /* Put !SEC_LOAD sections after SEC_LOAD ones. */ -#define TOEND(x) (((x)->flags & (SEC_LOAD | SEC_THREAD_LOCAL)) == 0) +#define TOEND(x) (((x)->flags & (SEC_LOAD | SEC_THREAD_LOCAL)) == 0 \ + && (x)->size != 0) if (TOEND (sec1)) { diff --git a/ld/ChangeLog b/ld/ChangeLog index fbc2d8a6318..b6d1aefdaf3 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,9 @@ +2020-11-28 Alan Modra + + * testsuite/ld-elf/pr26907.ld, + * testsuite/ld-elf/pr26907.s, + * testsuite/ld-elf/pr26907.d: New test. + 2020-11-27 Jozef Lawrynowicz * emulparams/armelf.sh (OTHER_SECTIONS): Remove .noinit section diff --git a/ld/testsuite/ld-elf/pr26907.d b/ld/testsuite/ld-elf/pr26907.d new file mode 100644 index 00000000000..1efb8cc34b1 --- /dev/null +++ b/ld/testsuite/ld-elf/pr26907.d @@ -0,0 +1,9 @@ +#ld: -T pr26907.ld +#readelf: -lW +#xfail: dlx-*-* ft32-*-* h8300-*-* ip2k-*-* m32r*-*-elf* m32r*-*-rtems* +#xfail: moxie-*-* msp430-*-* mt-*-* pru*-*-* visium-*-* + +#failif +#... + +LOAD +0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x0+ 0x0+ .* +#... diff --git a/ld/testsuite/ld-elf/pr26907.ld b/ld/testsuite/ld-elf/pr26907.ld new file mode 100644 index 00000000000..2cce1ee09cf --- /dev/null +++ b/ld/testsuite/ld-elf/pr26907.ld @@ -0,0 +1,7 @@ +ENTRY (_start) +SECTIONS +{ + .text : { *(.text) } + .bss : { . = .; *(.bss) } + .data : { *(.data) } +} diff --git a/ld/testsuite/ld-elf/pr26907.s b/ld/testsuite/ld-elf/pr26907.s new file mode 100644 index 00000000000..13b3a540738 --- /dev/null +++ b/ld/testsuite/ld-elf/pr26907.s @@ -0,0 +1,9 @@ + .text + .global _start +_start: + .quad 0 + + .data + .quad 0 + + .section .bss,"aw",%nobits -- 2.30.2