From 8d748d1dc56406228c2c76de2563859213364cbf Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Sat, 28 Nov 2020 08:45:02 +1030 Subject: 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/elf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'bfd/elf.c') diff --git a/bfd/elf.c b/bfd/elf.c index 28621da..419c5f4 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)) { -- cgit v1.1