Bug 24015

Summary: glibc-2.28 on little-endian mips32 broken due to commit 2bf2bf23da
Product: binutils Reporter: Manuel Lauss <manuel.lauss>
Component: ldAssignee: Alan Modra <amodra>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 2.32   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed: 2018-12-27 00:00:00
Attachments: archive of working and broken libraries

Description Manuel Lauss 2018-12-20 20:54:08 UTC
Created attachment 11480 [details]
archive of working and broken libraries

On MIPS32 little-endian softfloat target ("mipsel-softfloat-linux-gnu"), commit 2bf2bf23da5237f465fdbb759657aeb7825a08a3 ("ELF ld -r scripts") creates a corrupt MIPS32 ld.so binary (glibc-2.28), which segfaults somehere in dl_main().
I see however no issues in other packages.

I attach a tar archive with a working and broken ld-2.28.so file.  The good one was built with binutils commit 	8bca297856, the broken one with 2bf2bf23da.
They seem to differ in only 2 bytes:

# cmp -b -l ld-2.28.so.GOOD ld-2.28.so.BAD 
154657   0 ^@    34 ^\
154661   0 ^@     2 ^B

Please take a look!

Thanks!
     Manuel
Comment 1 Alan Modra 2018-12-23 08:02:19 UTC
The differences are in .sbss, which is oddly made PROGBITS rather than NOBITS.

ld-2.28.so.BAD:     file format elf32-tradlittlemips

Contents of section .sbss:
 35c20 1c000000 02000000                    ........        

ld-2.28.so.GOOD:     file format elf32-tradlittlemips

Contents of section .sbss:
 35c20 00000000 00000000                    ........
Comment 2 Sourceware Commits 2018-12-28 04:34:11 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0e41bebb938dbe9eae7063f5321429194bfc5ab7

commit 0e41bebb938dbe9eae7063f5321429194bfc5ab7
Author: Alan Modra <amodra@gmail.com>
Date:   Fri Dec 28 09:41:44 2018 +1030

    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.
Comment 3 Alan Modra 2018-12-28 05:13:18 UTC
Should now be fixed.
Comment 4 Manuel Lauss 2018-12-28 09:56:19 UTC
Thanks, yes it's fixed now.  Final binary is even 8 bytes smaller now.