From 0e41bebb938dbe9eae7063f5321429194bfc5ab7 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Fri, 28 Dec 2018 09:41:44 +1030 Subject: [PATCH] PR24015, glibc-2.28 on little-endian mips32 broken Commit 2bf2bf23da exposed a bug on targets that create common sections other than the standard ELF SHN_COMMON. If these are output by ld -r, then their type becomes SHT_PROGBITS unless the target handles them specially (eg. by elf_backend_special_sections), and if they are merged into .bss/.sbss by ld -r then that section becomes SHT_PROGBITS. Worse, if they are output by ld -r, then their size is increased by bfd_generic_define_common_symbol during final link, which leads to bogus file contents being copied to output. For mips, it seems to me that the .scommon section should not be output for ld -r, but I haven't made that change in this patch. PR 24015 * elf.c (bfd_elf_get_default_section_type): Make common sections SHT_NOBITS. * linker.c (bfd_generic_define_common_symbol): Clear SEC_HAS_CONTENTS. --- bfd/ChangeLog | 8 ++++++++ bfd/elf.c | 2 +- bfd/linker.c | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 8a073f6844..1396c7034e 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,11 @@ +2018-12-28 Alan Modra + + PR 24015 + * elf.c (bfd_elf_get_default_section_type): Make common sections + SHT_NOBITS. + * linker.c (bfd_generic_define_common_symbol): Clear + SEC_HAS_CONTENTS. + 2018-12-28 Alan Modra PR 23966 diff --git a/bfd/elf.c b/bfd/elf.c index b10dcd83c5..d3e391e182 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -3127,7 +3127,7 @@ _bfd_elf_init_reloc_shdr (bfd *abfd, int bfd_elf_get_default_section_type (flagword flags) { - if ((flags & SEC_ALLOC) != 0 + if ((flags & (SEC_ALLOC | SEC_IS_COMMON)) != 0 && (flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0) return SHT_NOBITS; return SHT_PROGBITS; diff --git a/bfd/linker.c b/bfd/linker.c index 9fee90d101..fff9d9b349 100644 --- a/bfd/linker.c +++ b/bfd/linker.c @@ -3119,7 +3119,7 @@ bfd_generic_define_common_symbol (bfd *output_bfd, /* Make sure the section is allocated in memory, and make sure that it is no longer a common section. */ section->flags |= SEC_ALLOC; - section->flags &= ~SEC_IS_COMMON; + section->flags &= ~(SEC_IS_COMMON | SEC_HAS_CONTENTS); return TRUE; } -- 2.34.1