Bug 18930

Summary: internal error in sized_write_symbol, at symtab.cc:3133
Product: binutils Reporter: Markus Trippelsdorf <markus>
Component: goldAssignee: Cary Coutant <ccoutant>
Status: RESOLVED FIXED    
Severity: normal CC: hjl.tools, ian
Priority: P2    
Version: 2.26   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Markus Trippelsdorf 2015-09-07 09:20:35 UTC
trippels@gcc2-power8 app % cat nsBrowserApp.ii
extern "C" int strcasecmp(const char *, const char *);
int main() { return strcasecmp(0, 0); }

trippels@gcc2-power8 app % g++ nsBrowserApp.ii
trippels@gcc2-power8 app % g++ -flto nsBrowserApp.ii
/home/trippels/bin/ld: internal error in sized_write_symbol, at symtab.cc:3133
collect2: error: ld returned 1 exit status

Started with:

commit 358de98820c5e9caa222846ba8b646de6cc091c8
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Sep 2 04:14:21 2015 -0700

    Turn IFUNC symbols from shared libraries into normal FUNC symbols

    Turn IFUNC symbols from shared libraries into normal FUNC symbols when
    we are resolving symbol references, instead of when we are writing out
    the symbol table.
Comment 1 Markus Trippelsdorf 2015-09-07 10:05:40 UTC
Also happens on x86_64, e.g. trying to build perf:

...
  CC       util/parse-events.o
  CC       util/parse-events-flex.o
  CC       util/pmu.o
  CC       util/pmu-flex.o
  LD       util/libperf-in.o
  LD       libperf-in.o
  AR       libperf.a
  LINK     perf
  LINK     libperf-gtk.so
/usr/lib/gcc/x86_64-pc-linux-gnu/5.2.1/../../../../x86_64-pc-linux-gnu/bin/ld: internal error in sized_write_symbol, at /var/tmp/portage/sys-devel/binutils-9999/work/binutils/gold/symtab.cc:3133
collect2: error: ld returned 1 exit status
Makefile.perf:306: recipe for target 'perf' failed
Comment 2 Markus Trippelsdorf 2015-09-07 12:33:34 UTC
markus@x4 gold % cat pex-unix.i
pex_unix_exec_child() { vfork(); }
markus@x4 gold % gcc -w -c pex-unix.i
markus@x4 gold % ./ld-new pex-unix.o -lpthread -lc
./ld-new: internal error in sized_write_symbol, at symtab.cc:3133
Comment 3 Markus Trippelsdorf 2015-09-07 12:52:44 UTC
Breakpoint 1, gold::Symbol_table::sized_write_symbol<64, false> (this=0x7fffffff5f40, sym=0x94c5c0, value=4194928, shndx=9, binding=elfcpp::STB_GLOBAL, pool=0x7fffffff6248, 
    p=0x7ffff7fe04f0 "+") at symtab.cc:3133
3133      gold_assert(type != elfcpp::STT_GNU_IFUNC || !sym->is_from_dynobj());
(gdb) p sym->type()                                                                                                                                                           
$1 = elfcpp::STT_FUNC
(gdb) p sym->is_from_dynobj()                                                                                                                                                 
$2 = false
(gdb) bt
#0  gold::Symbol_table::sized_write_symbol<64, false> (this=0x7fffffff5f40, sym=0x94c5c0, value=4194928, shndx=9, binding=elfcpp::STB_GLOBAL, pool=0x7fffffff6248, 
    p=0x7ffff7fe04f0 "+") at symtab.cc:3133
#1  0x00000000006943b4 in gold::Symbol_table::sized_write_globals<64, false> (this=0x7fffffff5f40, sympool=0x7fffffff6248, dynpool=0x7fffffff62d0, symtab_xindex=0x0, 
    dynsym_xindex=0x0, of=0xa4a100) at symtab.cc:3087
#2  0x000000000068890e in gold::Symbol_table::write_globals (this=0x7fffffff5f40, sympool=0x7fffffff6248, dynpool=0x7fffffff62d0, symtab_xindex=0x0, dynsym_xindex=0x0, 
    of=0xa4a100) at symtab.cc:2886
#3  0x00000000006ae710 in gold::Workqueue::find_and_run_task (this=this@entry=0x7fffffff5c30, thread_number=thread_number@entry=0) at workqueue.cc:319
#4  0x00000000006aeaaa in gold::Workqueue::process (this=this@entry=0x7fffffff5c30, thread_number=thread_number@entry=0) at workqueue.cc:495
#5  0x0000000000407e73 in main (argc=4, argv=0x7fffffffe2a8) at main.cc:252

resolve.cc isn't used at all in this case.
Comment 4 Sourceware Commits 2015-09-07 16:44:57 UTC
The master branch has been updated by Cary Coutant <ccoutant@sourceware.org>:

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

commit 3d4fde6974a1237d79055ee734d99cc49c6fd3f9
Author: Cary Coutant <ccoutant@gmail.com>
Date:   Mon Sep 7 09:44:11 2015 -0700

    Fix internal error caused by IFUNC patch.
    
    The previous commit to fix PR gold/18886 converted STT_IFUNC
    to STT_FUNC when resolving to a symbol defined in a shared library.
    This leads to an internal error if the shared library symbol is
    seen first, as we do not convert the symbol at all.
    
    We need to override the STT_IFUNC in add_from_dynobj() instead of
    in override_base().
    
    gold/
    	PR gold/18930
    	PR gold/18886
    	* resolve.cc (Symbol::override_base): Don't convert IFUNC symbols here.
    	* symtab.cc (Symbol_table::add_from_dynobj): Convert them here instead.
Comment 5 Cary Coutant 2015-09-07 16:47:16 UTC
Fixed on master.