int proc( int a)
gcc t.c -c
ar r t.a t.o
ld.gold t.a -r
ld.gold: internal error in target, at parameters.h:105
#0 gold::Parameters::target (this=<optimized out>) at ../../binutils/gold/parameters.h:105
#1 0x0000000000653b07 in target (this=<optimized out>) at ../../binutils/gold/parameters.cc:243
#2 gold::Parameters::entry (this=<optimized out>) at ../../binutils/gold/parameters.cc:241
#3 0x00000000005827b4 in gold::Library_base::should_include_member (symtab=symtab@entry=0x7fffffff8170, layout=layout@entry=0x7fffffff83d0, sym_name=0xae6e88 "proc",
symp=symp@entry=0x7fffffff7b88, why=why@entry=0x7fffffff7b60, tmpbufp=tmpbufp@entry=0x7fffffff7b78, tmpbuflen=tmpbuflen@entry=0x7fffffff7b80)
#4 0x0000000000584498 in gold::Archive::add_symbols (this=0xae6c60, symtab=0x7fffffff8170, layout=0x7fffffff83d0, input_objects=0x7fffffff7f80, mapfile=0x0)
#5 0x0000000000584649 in gold::Add_archive_symbols::run (this=0xae6f10, workqueue=0x7fffffff7e60) at ../../binutils/gold/archive.cc:1113
#6 0x00000000006a3475 in gold::Workqueue::find_and_run_task (this=this@entry=0x7fffffff7e60, thread_number=thread_number@entry=0)
#7 0x00000000006a37da in gold::Workqueue::process (this=this@entry=0x7fffffff7e60, thread_number=thread_number@entry=0)
#8 0x00000000004068e6 in main (argc=3, argv=0x7fffffffe568) at ../../binutils/gold/main.cc:252
parameters->target_ is NULL while work with archive.
Where is the proper place for initialization?
> Where is the proper place for initialization?
gold doesn't set the target until it sees its first object file. In the case of an archive library as the first parameter, we have no way of knowing what the default entry point should be (because the entry point symbol is target specific).
Parameters::entry() should first check that target has been set, and if not, simply return NULL.
Library_base::should_include_member() should check for NULL, and either skip the check for the entry symbol, or print a warning that the -e option should be used when there is no startup file.
(In reply to Cary Coutant from comment #1)
> or print a warning that the -e option should
> be used when there is no startup file.
But it could be some incremental linking. And, for example, ld.bfd doesn't print such warning. Also it seems we need additional field to save "entry point found" state while passing all object files. Is it really necessary?
When linking with -r, Gnu ld doesn't use the entry symbol, so gold shouldn't either.
When linking without -r, gold needs to know the target in order to know the entry symbol, so if no target has been established, don't look for an entry symbol.
The master branch has been updated by Cary Coutant <email@example.com>:
Author: Cary Coutant <firstname.lastname@example.org>
Date: Tue Jul 21 12:50:45 2015 -0700
Fix typo in PR number.
Fix internal error when linking an archive library with no preceding objects.
* archive.cc (Library_base::should_include_member): Don't use entry
point for relocatable links, or if target is not yet valid.
* parameters.cc (Parameters::entry): Check target_valid().
Fixed on trunk.
Sorry, I had a typo in the ChangeLog entry when I committed this. The actual commit that fixed the bug is here: