Bug 23199 - Strip broken after update to binutils 2.30
Summary: Strip broken after update to binutils 2.30
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.30
: P2 normal
Target Milestone: 2.31
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-18 05:44 UTC by Thomas Mader
Modified: 2018-05-22 10:47 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2018-05-18 00:00:00


Attachments
faulty object file (1.79 KB, application/octet-stream)
2018-05-18 07:05 UTC, Alan Modra
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Mader 2018-05-18 05:44:13 UTC
As suggested in https://sourceware.org/ml/binutils/2018-05/msg00183.html I open this bug.

As already mentioned in my newsgroup question at https://sourceware.org/ml/binutils/2018-05/msg00180.html I wonder how it is possible to have such a bug in NixOS while on Archlinux it works with the same version of binutils (2.30).

Maybe it has something to do with the different configure switches with which the two distributions are building binutils?

NixOS: https://github.com/NixOS/nixpkgs/blob/3027bca02aa2ab50393cb9a8924ad73284d2700b/pkgs/development/tools/misc/binutils/default.nix
Archlinux: https://git.archlinux.org/svntogit/packages.git/plain/trunk/PKGBUILD?h=packages/binutils&id=26c1ad8f31e6c4416d1f83275a586d6afa6167b8
Comment 1 Thomas Mader 2018-05-18 05:59:07 UTC
The problematic static phobos lib can be found under https://drive.google.com/file/d/179Nvnk7D3YLO5iQ3-zNAJl-7TDHw_twU/view?usp=sharing
It was too big to attach directly.
Comment 2 Alan Modra 2018-05-18 07:05:37 UTC
Created attachment 11026 [details]
faulty object file

One of the object files from the library, object_1_257.o, which nm complains about with
object_1_257.o: no group info for section '.text._D6object6Object5opCmpMFCQqZi'

shows the following for the relevant group section
group section [    3] `.group' [_D6object6Object5opCmpMFCQqZi] contains 2 sections:
   [Index]    Name
   [    1]   .group
   [   22]   .text._D6object6Object5opCmpMFCQqZi

Also:
group section [    5] `.group' [_D6object6Object7factoryFAyaZCQv] contains 2 sections:
   [Index]    Name
readelf: Error: section [    1] in group section [    5] already in group section [    3]
   [   29]   .text._D6object6Object7factoryFAyaZCQv


This SHT_GROUP section points at another SHT_GROUP section?  That's bad!
Comment 3 cvs-commit@gcc.gnu.org 2018-05-18 09:07:34 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

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

commit 4bba0fb1c6d391a217c25e44398a7e1c7090155f
Author: Alan Modra <amodra@gmail.com>
Date:   Fri May 18 17:09:45 2018 +0930

    PR23199, Invalid SHT_GROUP entry leads to group confusion
    
    This patch prevents elf_next_in_group list pointer confusion when
    SHT_GROUP sections specify other SHT_GROUP sections in their list of
    group sections.
    
    	PR 23199
    	* elf.c (setup_group): Formatting.  Check that SHT_GROUP entries
    	don't point at other SHT_GROUP sections.  Set shdr corresponding
    	to invalid entry, to NULL rather than section 0.  Identify
    	SHT_GROUP section index when reporting an error.  Cope with NULL
    	shdr pointer.
Comment 4 Alan Modra 2018-05-18 09:18:11 UTC
The patch I've just committed improves the handling of these bad object files.  

The question remains as to how they were created.  Please identify the binutils version used to create object_1_257.o.
Comment 5 Thomas Mader 2018-05-18 17:07:54 UTC
The dmd compiler doesn't seem to be using any binutils except for linking. https://forum.dlang.org/post/lvxvkopqssytuxzzcngj@forum.dlang.org

So it's still a question as to why the problem occurs only with 2.30 and not with 2.28.
Comment 6 Alan Modra 2018-05-18 22:38:41 UTC
OK, so not a binutils bug causing these bad SHT_GROUP section entries.

The same nm error is reported for all binutils I tried back to 2.25 (at which point I stopped looking).  It is possible that your 2.28 binutils had some distro patches that made BFD behave better with these bad object files, but my binutils-2_28-branch version does not.
Comment 7 cvs-commit@gcc.gnu.org 2018-05-18 23:08:04 UTC
The binutils-2_30-branch branch has been updated by Alan Modra <amodra@sourceware.org>:

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

commit e3d435293f0dd45247e8057574389f322f5fe5a2
Author: Alan Modra <amodra@gmail.com>
Date:   Fri May 18 17:09:45 2018 +0930

    PR23199, Invalid SHT_GROUP entry leads to group confusion
    
    This patch prevents elf_next_in_group list pointer confusion when
    SHT_GROUP sections specify other SHT_GROUP sections in their list of
    group sections.
    
    	PR 23199
    	* elf.c (setup_group): Formatting.  Check that SHT_GROUP entries
    	don't point at other SHT_GROUP sections.  Set shdr corresponding
    	to invalid entry, to NULL rather than section 0.  Identify
    	SHT_GROUP section index when reporting an error.  Cope with NULL
    	shdr pointer.
    
    (cherry picked from commit 4bba0fb1c6d391a217c25e44398a7e1c7090155f)
Comment 8 Thomas Mader 2018-05-19 09:51:25 UTC
(In reply to Alan Modra from comment #6)
> OK, so not a binutils bug causing these bad SHT_GROUP section entries.
> 
> The same nm error is reported for all binutils I tried back to 2.25 (at
> which point I stopped looking).  It is possible that your 2.28 binutils had
> some distro patches that made BFD behave better with these bad object files,
> but my binutils-2_28-branch version does not.

I found the problem.
Nix is stripping the libs and binaries on installation and there seems to be a bug introduced in binutils 2.30 with strip.
I disabled the striping and everythings worked fine.
You can find the unstripped lib here: https://drive.google.com/file/d/1fPjoNiQJNE5uzpCvqkRE1G7sMM5LbaNR/view?usp=sharing

Output of nix-build when stripping:

strip is /nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/q674hw91v3605szwhhc8ypwdc2iqxb20-dmdBuild-2.079.1/lib  /nix/store/q674hw91v3605szwhhc8ypwdc2iqxb20-dmdBuild-2.079.1/bin
Comment 9 H.J. Lu 2018-05-20 12:26:59 UTC
It started with

commit db4677b8bd90b49f826807352c6c3c7eb0d57814
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Oct 4 09:53:53 2017 +1030

    PR21167, relocation sections not included in groups
Comment 10 H.J. Lu 2018-05-20 12:39:26 UTC
There are 48 section headers, starting at offset 0x1384:

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        0000000000000000 000040 000000 00  AX  0   0  4
  [ 2] .rela.text        RELA            0000000000000000 000000 000000 18      8   1  8
  [ 3] .data             PROGBITS        0000000000000000 000040 000000 00  WA  0   0  8
  [ 4] .rela.data        RELA            0000000000000000 000000 000000 18      8   3  8
  [ 5] .bss              NOBITS          0000000000000000 000040 000000 00  WA  0   0 16
  [ 6] .rodata           PROGBITS        0000000000000000 000040 000000 00   A  0   0 16
  [ 7] .strtab           STRTAB          0000000000000000 000db0 0002a4 00      0   0  1
  [ 8] .symtab           SYMTAB          0000000000000000 000828 000588 18      7  35  8
  [ 9] .shstrtab         STRTAB          0000000000000000 000468 0003bf 00      0   0  1
  [10] .comment          PROGBITS        0000000000000000 000040 000000 00      0   0  1
  [11] .note             NOTE            0000000000000000 000000 000000 00      0   0  1
  [12] .note.GNU-stack   PROGBITS        0000000000000000 000000 000000 00      0   0  1
  [13] .data.rel.ro      PROGBITS        0000000000000000 000040 000000 00  WA  0   0 16
  [14] .eh_frame         PROGBITS        0000000000000000 000040 0000b8 00   A  0   0  8
  [15] .group            GROUP           0000000000000000 0000f8 000008 04      8  36  4
  [16] .text._D6object6Object8toStringMFZAya PROGBITS        0000000000000000 000100 000014 00 AXG  0   0  4
  [17] .rela.eh_frame    RELA            0000000000000000 001054 000078 18      8  14  8
  [18] .group            GROUP           0000000000000000 000114 000008 04      8  37  4
  [19] .text._D6object6Object6toHashMFNbNeZm PROGBITS        0000000000000000 00011c 00000c 00 AXG  0   0  4
  [20] .rodata.str1.1    PROGBITS        0000000000000000 000128 000023 00 AMS  0   0  1
  [21] .group            GROUP           0000000000000000 00014c 00000c 04      8  38  4
  [22] .text._D6object6Object5opCmpMFCQqZi PROGBITS        0000000000000000 000158 00008c 00 AXG  0   0  4
  [23] .rela.text._D6object6Object5opCmpMFCQqZi RELA            0000000000000000 0010cc 0000c0 18      8  22  8
  [24] .group            GROUP           0000000000000000 0001e4 000008 04      8  39  4
  [25] .text._D6object6Object8opEqualsMFCQtZb PROGBITS        0000000000000000 0001ec 00000c 00 AXG  0   0  4
  [26] .data._D32TypeInfo_C6object6Object7Monitor6__initZ PROGBITS        0000000000000000 000200 000020 00  WA  0   0 16
  [27] .data._D6object6Object7Monitor11__InterfaceZ PROGBITS        0000000000000000 000220 0000b0 00  WA  0   0 16
  [28] .rela.data._D6object6Object7Monitor11__InterfaceZ RELA            0000000000000000 0011bc 000030 18      8  27  8
  [29] .group            GROUP           0000000000000000 0002d0 00000c 04      8  42  4
  [30] .text._D6object6Object7factoryFAyaZCQv PROGBITS        0000000000000000 0002dc 000044 00 AXG  0   0  4
  [31] .data._D6Object6__initZ PROGBITS        0000000000000000 000320 000010 00  WA  0   0 16
  [32] .data._D6Object7__ClassZ PROGBITS        0000000000000000 000330 0000b0 00  WA  0   0 16
  [33] .rela.data._D6Object7__ClassZ RELA            0000000000000000 00121c 000060 18      8  32  8
  [34] .data._D6Object6__vtblZ PROGBITS        0000000000000000 0003e0 000030 00  WA  0   0 16
  [35] .rela.data._D6Object6__vtblZ RELA            0000000000000000 00127c 000078 18      8  34  8
  [36] .rela.data._D32TypeInfo_C6object6Object7Monitor6__initZ RELA            0000000000000000 00118c 000030 18      8  26  8
  [37] .rela.text._D6object6Object7factoryFAyaZCQv RELA            0000000000000000 0011ec 000018 18      8  30  8
  [38] .rela.data._D6Object6__initZ RELA            0000000000000000 001204 000018 18      8  31  8
  [39] minfo             PROGBITS        0000000000000000 000410 000000 00  WA  0   0  8
  [40] .group.d_dso      GROUP           0000000000000000 000410 000014 04      8  31  0
  [41] .data.d_dso_rec   PROGBITS        0000000000000000 000428 000008 00 WAG  0   0  8
  [42] .text.d_dso_init  PROGBITS        0000000000000000 000430 000028 00 AXG  0   0  8
  [43] .rela.text.d_dso_init RELA            0000000000000000 0012f4 000060 18      8  42  8
  [44] .dtors.d_dso_dtor PROGBITS        0000000000000000 000458 000008 00 WAG  0   0  8
  [45] .rela.dtors.d_dso_dtor RELA            0000000000000000 001354 000018 18      8  44  8
  [46] .ctors.d_dso_ctor PROGBITS        0000000000000000 000460 000008 00 WAG  0   0  8
  [47] .rela.ctors.d_dso_ctor RELA            0000000000000000 00136c 000018 18      8  46  8
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  l (large), p (processor specific)

COMDAT group section [   15] `.group' [_D6object6Object8toStringMFZAya] contains 1 sections:
   [Index]    Name
   [   16]   .text._D6object6Object8toStringMFZAya

COMDAT group section [   18] `.group' [_D6object6Object6toHashMFNbNeZm] contains 1 sections:
   [Index]    Name
   [   19]   .text._D6object6Object6toHashMFNbNeZm

COMDAT group section [   21] `.group' [_D6object6Object5opCmpMFCQqZi] contains 2 sections:
   [Index]    Name
   [   22]   .text._D6object6Object5opCmpMFCQqZi
   [   23]   .rela.text._D6object6Object5opCmpMFCQqZi

COMDAT group section [   24] `.group' [_D6object6Object8opEqualsMFCQtZb] contains 1 sections:
   [Index]    Name
   [   25]   .text._D6object6Object8opEqualsMFCQtZb

COMDAT group section [   29] `.group' [_D6object6Object7factoryFAyaZCQv] contains 2 sections:
   [Index]    Name
   [   30]   .text._D6object6Object7factoryFAyaZCQv
   [   37]   .rela.text._D6object6Object7factoryFAyaZCQv

COMDAT group section [   40] `.group.d_dso' [.data.d_dso_rec] contains 4 sections:
   [Index]    Name
   [   41]   .data.d_dso_rec
   [   42]   .text.d_dso_init
   [   44]   .dtors.d_dso_dtor
   [   46]   .ctors.d_dso_ctor

Relocation sections for sections in .group.d_dso group aren't in the group.
Comment 11 H.J. Lu 2018-05-20 13:38:57 UTC
  [22] .text._D6object6Object5opCmpMFCQqZi PROGBITS        0000000000000000 000158 00008c 00 AXG  0   0  4
  [23] .rela.text._D6object6Object5opCmpMFCQqZi RELA            0000000000000000 0010cc 0000c0 18      8  22  8

 COMDAT group section [   21] `.group' [_D6object6Object5opCmpMFCQqZi] contains 2 sections:
   [Index]    Name
   [   22]   .text._D6object6Object5opCmpMFCQqZi
   [   23]   .rela.text._D6object6Object5opCmpMFCQqZi

Relocation is in group section, but not marked with SHF_GROUP.
Comment 12 H.J. Lu 2018-05-20 14:31:49 UTC
A patch is posted at

https://sourceware.org/ml/binutils/2018-05/msg00207.html
Comment 13 cvs-commit@gcc.gnu.org 2018-05-22 02:28:56 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

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

commit bae363f1146378207e1dffe5f23845644a1d0b7a
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon May 21 19:25:19 2018 -0700

    Mark section in a section group with SHF_GROUP
    
    All sections in a section group should be marked with SHF_GROUP.  But
    some tools generate broken objects without SHF_GROUP.  This patch fixes
    them up for objcopy and strip.
    
    	PR binutils/23199
    	* elf.c (setup_group): Mark section in a section group with
    	SHF_GROUP.
Comment 14 cvs-commit@gcc.gnu.org 2018-05-22 10:46:33 UTC
The binutils-2_30-branch branch has been updated by H.J. Lu <hjl@sourceware.org>:

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

commit e2bcabadb8bc02d971b30644d91a70ec4c4b825d
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon May 21 19:25:19 2018 -0700

    Mark section in a section group with SHF_GROUP
    
    All sections in a section group should be marked with SHF_GROUP.  But
    some tools generate broken objects without SHF_GROUP.  This patch fixes
    them up for objcopy and strip.
    
    	PR binutils/23199
    	* elf.c (setup_group): Mark section in a section group with
    	SHF_GROUP.
    
    (cherry picked from commit bae363f1146378207e1dffe5f23845644a1d0b7a)
Comment 15 H.J. Lu 2018-05-22 10:47:19 UTC
Fixed for 2.31 and 2.30 branch.