Bug 23194 - Building glibc 2.27 on 32-bit Intel with binutils 2.30 segfaults in elf subdir
Summary: Building glibc 2.27 on 32-bit Intel with binutils 2.30 segfaults in elf subdir
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.30
: P2 normal
Target Milestone: 2.31
Assignee: H.J. Lu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-17 11:32 UTC by Andreas Baumann
Modified: 2018-05-26 11:32 UTC (History)
1 user (show)

See Also:
Host:
Target: x86_64-*-*, i?86-*-*
Build:
Last reconfirmed: 2018-05-17 00:00:00


Attachments
ld.map (354 bytes, text/plain)
2018-05-18 19:43 UTC, Andreas Baumann
Details
librtld.os (96.94 KB, application/octet-stream)
2018-05-18 19:45 UTC, Andreas Baumann
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Baumann 2018-05-17 11:32:21 UTC
Building in glibc-2.27/elf/:

make[3]: Leaving directory '/root/glibc/src/glibc-2.27/elf'
gcc   -nostdlib -nostartfiles -shared -o /root/glibc/src/glibc-build/elf/ld.so.new              \
          -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both -Wl,-z,defs -Wl,-z,now    \
          /root/glibc/src/glibc-build/elf/librtld.os -Wl,--version-script=/root/glibc/src/glibc-build/ld.map             \
          -Wl,-soname=ld-linux.so.2                     \
          -Wl,-defsym=_begin=0
collect2: fatal error: ld terminated with signal 11 [Segmentation fault], core dumped
compilation terminated.
make[2]: *** [Makefile:478: /root/glibc/src/glibc-build/elf/ld.so] Error 1


Core was generated by `/usr/bin/ld -plugin /usr/lib/gcc/i686-pc-linux-gnu/8.1.0/liblto_plugin.so -plug'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0xb7e70916 in bfd_getl32 (p=0x120c8658) at /root/binutils/src/binutils-2.30/bfd/libbfd.c:561
561       return v;
(gdb) bt
#0  0xb7e70916 in bfd_getl32 (p=0x120c8658) at /root/binutils/src/binutils-2.30/bfd/libbfd.c:561
#1  0xb7e90ecc in bfd_elf32_swap_symbol_in (abfd=0x20c0f40, psrc=0x120c8658, pshn=0x0, dst=0xbfc60d40)
    at /root/binutils/src/binutils-2.30/bfd/elfcode.h:183
#2  0xb7e84383 in elf_i386_reloc_type_class (info=0x5cf0a0 <link_info>, rel_sec=0x20d4264,
    rela=0x218346c) at /root/binutils/src/binutils-2.30/bfd/elf32-i386.c:3965
#3  0xb7ebed3f in elf_link_sort_relocs (psec=<synthetic pointer>, info=0x5cf0a0 <link_info>,
    abfd=0x20c0f40) at /root/binutils/src/binutils-2.30/bfd/elflink.c:9124
#4  bfd_elf_final_link () at /root/binutils/src/binutils-2.30/bfd/elflink.c:12315
#5  0x0043a130 in ldwrite () at /root/binutils/src/binutils-2.30/ld/ldwrite.c:581
#6  0x0042013f in main (argc=<optimized out>, argv=<optimized out>)
    at /root/binutils/src/binutils-2.30/ld/ldmain.c:448
Comment 1 H.J. Lu 2018-05-17 19:47:15 UTC
Please try binutils-2_30-branch
Comment 2 Andreas Baumann 2018-05-18 07:30:49 UTC
(In reply to H.J. Lu from comment #1)
> Please try binutils-2_30-branch

Same effect.
Can I give you the value of some structures or so?
Comment 3 H.J. Lu 2018-05-18 11:03:11 UTC
(In reply to Andreas Baumann from comment #2)
> (In reply to H.J. Lu from comment #1)
> > Please try binutils-2_30-branch
> 
> Same effect.

Please try

https://sourceware.org/ml/binutils/2018-05/msg00182.html
Comment 4 Andreas Baumann 2018-05-18 13:00:08 UTC
(In reply to H.J. Lu from comment #3)
> (In reply to Andreas Baumann from comment #2)
> > (In reply to H.J. Lu from comment #1)
> > > Please try binutils-2_30-branch
> > 
> > Same effect.
> 
> Please try
> 
> https://sourceware.org/ml/binutils/2018-05/msg00182.html

Patched the binutils-2_30-branch with the patch described.
Same effect.
Comment 5 H.J. Lu 2018-05-18 13:28:10 UTC
I can build glibc 2.27 on i686.  Please provide ALL linker inputs
so that I can reproduce it.
Comment 6 Andreas Baumann 2018-05-18 18:07:53 UTC
(In reply to H.J. Lu from comment #5)
> I can build glibc 2.27 on i686.  Please provide ALL linker inputs
> so that I can reproduce it.

Hope this helps:

gcc   -nostdlib -nostartfiles -shared -o /root/glibc/src/glibc-build/elf/ld.so.new             \
          -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both -Wl,-z,defs -Wl,-z,now   \
          /root/glibc/src/glibc-build/elf/librtld.os -Wl,--version-script=/root/glibc/src/glibc-build/ld.map           \
          -Wl,-soname=ld-linux.so.2                     \
          -Wl,-defsym=_begin=0

segfaults, but ommiting '-shared' works:

gcc   -nostdlib -nostartfiles -o /root/glibc/src/glibc-build/elf/ld.so.new             \
          -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both -Wl,-z,defs -Wl,-z,now   \
          /root/glibc/src/glibc-build/elf/librtld.os -Wl,--version-script=/root/glibc/src/glibc-build/ld.map           \
          -Wl,-soname=ld-linux.so.2                     \
          -Wl,-defsym=_begin=0
Comment 7 H.J. Lu 2018-05-18 18:18:50 UTC
(In reply to Andreas Baumann from comment #6)
> (In reply to H.J. Lu from comment #5)
> > I can build glibc 2.27 on i686.  Please provide ALL linker inputs
> > so that I can reproduce it.
> 
> Hope this helps:
> 
> gcc   -nostdlib -nostartfiles -shared -o
> /root/glibc/src/glibc-build/elf/ld.so.new             \
>           -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both -Wl,-z,defs
> -Wl,-z,now   \
>           /root/glibc/src/glibc-build/elf/librtld.os
> -Wl,--version-script=/root/glibc/src/glibc-build/ld.map           \
>           -Wl,-soname=ld-linux.so.2                     \
>           -Wl,-defsym=_begin=0
> 
> segfaults, but ommiting '-shared' works:
> 
> gcc   -nostdlib -nostartfiles -o /root/glibc/src/glibc-build/elf/ld.so.new  
> \
>           -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both -Wl,-z,defs
> -Wl,-z,now   \
>           /root/glibc/src/glibc-build/elf/librtld.os
> -Wl,--version-script=/root/glibc/src/glibc-build/ld.map           \
>           -Wl,-soname=ld-linux.so.2                     \
>           -Wl,-defsym=_begin=0

It doesn't help at all.  Please add -v to gcc and show me the output of

# gcc -v  -nostdlib -nostartfiles -shared -o /root/glibc/src/glibc-build/elf/ld.so.new             \
          -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both -Wl,-z,defs -Wl,-z,now   \
          /root/glibc/src/glibc-build/elf/librtld.os -Wl,--version-script=/root/glibc/src/glibc-build/ld.map           \
          -Wl,-soname=ld-linux.so.2                     \
          -Wl,-defsym=_begin=0
Comment 8 Andreas Baumann 2018-05-18 19:18:15 UTC
(In reply to H.J. Lu from comment #7)
> (In reply to Andreas Baumann from comment #6)
> > (In reply to H.J. Lu from comment #5)
> > > I can build glibc 2.27 on i686.  Please provide ALL linker inputs
> > > so that I can reproduce it.
> > 
> > Hope this helps:
> > 
> > gcc   -nostdlib -nostartfiles -shared -o
> > /root/glibc/src/glibc-build/elf/ld.so.new             \
> >           -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both -Wl,-z,defs
> > -Wl,-z,now   \
> >           /root/glibc/src/glibc-build/elf/librtld.os
> > -Wl,--version-script=/root/glibc/src/glibc-build/ld.map           \
> >           -Wl,-soname=ld-linux.so.2                     \
> >           -Wl,-defsym=_begin=0
> > 
> > segfaults, but ommiting '-shared' works:
> > 
> > gcc   -nostdlib -nostartfiles -o /root/glibc/src/glibc-build/elf/ld.so.new  
> > \
> >           -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both -Wl,-z,defs
> > -Wl,-z,now   \
> >           /root/glibc/src/glibc-build/elf/librtld.os
> > -Wl,--version-script=/root/glibc/src/glibc-build/ld.map           \
> >           -Wl,-soname=ld-linux.so.2                     \
> >           -Wl,-defsym=_begin=0
> 
> It doesn't help at all.  Please add -v to gcc and show me the output of
> 
> # gcc -v  -nostdlib -nostartfiles -shared -o
> /root/glibc/src/glibc-build/elf/ld.so.new             \
>           -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both -Wl,-z,defs
> -Wl,-z,now   \
>           /root/glibc/src/glibc-build/elf/librtld.os
> -Wl,--version-script=/root/glibc/src/glibc-build/ld.map           \
>           -Wl,-soname=ld-linux.so.2                     \
>           -Wl,-defsym=_begin=0

Sorry about that.

COMPILER_PATH=/usr/lib/gcc/i686-pc-linux-gnu/8.1.0/:/usr/lib/gcc/i686-pc-linux-gnu/8.1.0/:/usr/lib/gcc/i686-pc-linux-gnu/:/usr/lib/gcc/i686-pc-linux-gnu/8.1.0/:/usr/lib/gcc/i686-pc-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/i686-pc-linux-gnu/8.1.0/:/usr/lib/gcc/i686-pc-linux-gnu/8.1.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-nostdlib' '-nostartfiles' '-shared' '-o' '/root/glibc/src/glibc-build/elf/ld.so.new' '-mtune=generic' '-march=pentiumpro'
 /usr/lib/gcc/i686-pc-linux-gnu/8.1.0/collect2 -plugin /usr/lib/gcc/i686-pc-linux-gnu/8.1.0/liblto_plugin.so -plugin-opt=/usr/lib/gcc/i686-pc-linux-gnu/8.1.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccDugu2E.res --build-id --eh-frame-hdr --hash-style=gnu -m elf_i386 -shared -o /root/glibc/src/glibc-build/elf/ld.so.new -L/usr/lib/gcc/i686-pc-linux-gnu/8.1.0 -L/usr/lib/gcc/i686-pc-linux-gnu/8.1.0/../../.. -z combreloc -z relro --hash-style=both -z defs -z now /root/glibc/src/glibc-build/elf/librtld.os --version-script=/root/glibc/src/glibc-build/ld.map -soname=ld-linux.so.2 -defsym=_begin=0
collect2: fatal error: ld terminated with signal 11 [Segmentation fault], core dumped
compilation terminated.
Comment 9 H.J. Lu 2018-05-18 19:29:16 UTC
(In reply to Andreas Baumann from comment #8)

> COMPILER_PATH=/usr/lib/gcc/i686-pc-linux-gnu/8.1.0/:/usr/lib/gcc/i686-pc-
> linux-gnu/8.1.0/:/usr/lib/gcc/i686-pc-linux-gnu/:/usr/lib/gcc/i686-pc-linux-
> gnu/8.1.0/:/usr/lib/gcc/i686-pc-linux-gnu/
> LIBRARY_PATH=/usr/lib/gcc/i686-pc-linux-gnu/8.1.0/:/usr/lib/gcc/i686-pc-
> linux-gnu/8.1.0/../../../:/lib/:/usr/lib/
> COLLECT_GCC_OPTIONS='-v' '-nostdlib' '-nostartfiles' '-shared' '-o'
> '/root/glibc/src/glibc-build/elf/ld.so.new' '-mtune=generic'
> '-march=pentiumpro'
>  /usr/lib/gcc/i686-pc-linux-gnu/8.1.0/collect2 -plugin
> /usr/lib/gcc/i686-pc-linux-gnu/8.1.0/liblto_plugin.so
> -plugin-opt=/usr/lib/gcc/i686-pc-linux-gnu/8.1.0/lto-wrapper
> -plugin-opt=-fresolution=/tmp/ccDugu2E.res --build-id --eh-frame-hdr
> --hash-style=gnu -m elf_i386 -shared -o
> /root/glibc/src/glibc-build/elf/ld.so.new
> -L/usr/lib/gcc/i686-pc-linux-gnu/8.1.0
> -L/usr/lib/gcc/i686-pc-linux-gnu/8.1.0/../../.. -z combreloc -z relro
> --hash-style=both -z defs -z now /root/glibc/src/glibc-build/elf/librtld.os
> --version-script=/root/glibc/src/glibc-build/ld.map -soname=ld-linux.so.2
> -defsym=_begin=0
> collect2: fatal error: ld terminated with signal 11 [Segmentation fault],
> core dumped
> compilation terminated.

Please send me /root/glibc/src/glibc-build/ld.map and
/root/glibc/src/glibc-build/elf/librtld.os.
Comment 10 Andreas Baumann 2018-05-18 19:43:17 UTC
Created attachment 11029 [details]
ld.map
Comment 11 Andreas Baumann 2018-05-18 19:45:15 UTC
Created attachment 11030 [details]
librtld.os
Comment 12 H.J. Lu 2018-05-18 21:01:21 UTC
[hjl@gnu-cfl-1 pr23194]$ cat x.c
void
foo (void)
{
}

asm (".symver foo,foo@FOO");

void
bar (void)
{
  foo ();
}
[hjl@gnu-cfl-1 pr23194]$ cat x.map
FOO {
  global: bar;
  local: *;
};
[hjl@gnu-cfl-1 pr23194]$ make
gcc -B./ -O2 -fno-plt -fpic   -c -o x.o x.c
./ld -shared -o ld.so x.o --version-script=x.map
make: *** [Makefile:34: ld.so] Segmentation fault
make: *** Deleting file 'ld.so'
[hjl@gnu-cfl-1 pr23194]$ 

The problem is bfd_find_version_for_sym doesn't match
_bfd_elf_link_assign_sym_version.
Comment 13 Sourceware Commits 2018-05-18 21:37:00 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=97373b2eba6077d5059370a95931b93a8b118813

commit 97373b2eba6077d5059370a95931b93a8b118813
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri May 18 14:23:41 2018 -0700

    x86: Don't set eh->local_ref to 1 for versioned symbol
    
    bfd_hide_sym_by_version can't be used to check if a versioned symbol is
    hidden.  It has to be synced with _bfd_elf_link_assign_sym_version to
    get the correct answer.
    
    bfd/
    
    	PR ld/23194
    	* elfxx-x86.c (_bfd_x86_elf_link_symbol_references_local): Don't
    	set eh->local_ref to 1 if a symbol is versioned and there is a
    	version script.
    
    ld/
    
    	PR ld/23194
    	* testsuite/ld-i386/i386.exp: Run pr23194.
    	* testsuite/ld-x86-64/x86-64.exp: Likewise.
    	* testsuite/ld-i386/pr23194.d: New file.
    	* testsuite/ld-i386/pr23194.map: Likewise.
    	* testsuite/ld-i386/pr23194.s: Likewise.
    	* testsuite/ld-x86-64/pr23194.d: Likewise.
    	* testsuite/ld-x86-64/pr23194.map: Likewise.
    	* testsuite/ld-x86-64/pr23194.s: Likewise.
Comment 14 Andreas Baumann 2018-05-19 12:21:02 UTC
(In reply to cvs-commit@gcc.gnu.org from comment #13)
> The master branch has been updated by H.J. Lu <hjl@sourceware.org>:
> 
> https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;
> h=97373b2eba6077d5059370a95931b93a8b118813
> 
> commit 97373b2eba6077d5059370a95931b93a8b118813
> Author: H.J. Lu <hjl.tools@gmail.com>
> Date:   Fri May 18 14:23:41 2018 -0700
> 
>     x86: Don't set eh->local_ref to 1 for versioned symbol
>     
>     bfd_hide_sym_by_version can't be used to check if a versioned symbol is
>     hidden.  It has to be synced with _bfd_elf_link_assign_sym_version to
>     get the correct answer.
>     
>     bfd/
>     
>     	PR ld/23194
>     	* elfxx-x86.c (_bfd_x86_elf_link_symbol_references_local): Don't
>     	set eh->local_ref to 1 if a symbol is versioned and there is a
>     	version script.
>     
>     ld/
>     
>     	PR ld/23194
>     	* testsuite/ld-i386/i386.exp: Run pr23194.
>     	* testsuite/ld-x86-64/x86-64.exp: Likewise.
>     	* testsuite/ld-i386/pr23194.d: New file.
>     	* testsuite/ld-i386/pr23194.map: Likewise.
>     	* testsuite/ld-i386/pr23194.s: Likewise.
>     	* testsuite/ld-x86-64/pr23194.d: Likewise.
>     	* testsuite/ld-x86-64/pr23194.map: Likewise.
>     	* testsuite/ld-x86-64/pr23194.s: Likewise.

Just patched and tested the master. Works without any problems. Thanks for the
fix.
Comment 15 Sourceware Commits 2018-05-21 15:54:08 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=88193e0fdef1646fec917bd1ebd1f1049cae660e

commit 88193e0fdef1646fec917bd1ebd1f1049cae660e
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri May 18 14:23:41 2018 -0700

    x86: Don't set eh->local_ref to 1 for versioned symbol
    
    bfd_hide_sym_by_version can't be used to check if a versioned symbol is
    hidden.  It has to be synced with _bfd_elf_link_assign_sym_version to
    get the correct answer.
    
    bfd/
    
    	PR ld/23194
    	* elfxx-x86.c (_bfd_x86_elf_link_symbol_references_local): Don't
    	set eh->local_ref to 1 if a symbol is versioned and there is a
    	version script.
    
    ld/
    
    	PR ld/23194
    	* testsuite/ld-i386/i386.exp: Run pr23194.
    	* testsuite/ld-x86-64/x86-64.exp: Likewise.
    	* testsuite/ld-i386/pr23194.d: New file.
    	* testsuite/ld-i386/pr23194.map: Likewise.
    	* testsuite/ld-i386/pr23194.s: Likewise.
    	* testsuite/ld-x86-64/pr23194.d: Likewise.
    	* testsuite/ld-x86-64/pr23194.map: Likewise.
    	* testsuite/ld-x86-64/pr23194.s: Likewise.
    
    (cherry picked from commit 97373b2eba6077d5059370a95931b93a8b118813)
Comment 16 H.J. Lu 2018-05-21 15:56:56 UTC
Fixed for 2.31 and on 2.30 branch.
Comment 17 Sourceware Commits 2018-05-26 11:32:47 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=099bb8fb97d79d03a20926d6014a5fc27a5ca75e

commit 099bb8fb97d79d03a20926d6014a5fc27a5ca75e
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sat May 26 04:27:09 2018 -0700

    ld: Add _bfd_elf_link_hide_sym_by_version
    
    bfd_hide_sym_by_version can't be used to check if a versioned symbol is
    hidden.  This patch adds _bfd_elf_link_hide_sym_by_version to support
    both versioned and unversioned symbols by extracting versioned symbol
    check from _bfd_elf_link_assign_sym_version.
    
    bfd/
    
    	PR ld/23194
    	* elf-bfd.h (_bfd_elf_link_hide_sym_by_version): New.
    	* elflink.c (_bfd_elf_link_hide_versioned_symbol): New function.
    	Extracted from _bfd_elf_link_assign_sym_version.
    	(_bfd_elf_link_hide_sym_by_version): New function.
    	(_bfd_elf_link_assign_sym_version): Use
    	_bfd_elf_link_hide_versioned_symbol.
    	* elfxx-x86.c (_bfd_x86_elf_link_symbol_references_local): Call
    	_bfd_elf_link_hide_sym_by_version instead of
    	bfd_hide_sym_by_version.  Don't check unversioned symbol.
    
    ld/
    
    	PR ld/23194
    	* testsuite/ld-i386/pr23194.d: Expect only R_386_GLOB_DAT
    	against foobar.
    	* testsuite/ld-i386/pr23194.map: Add foobar.
    	* testsuite/ld-x86-64/pr23194.map: Likewise.
    	* testsuite/ld-i386/pr23194.s: Add a common foobar symbol.
    	* testsuite/ld-x86-64/pr23194.s: Likewise.
    	* testsuite/ld-x86-64/pr23194.d: Expect only R_X86_64_GLOB_DAT
    	against foobar.