Bug 18698 - internal error in target, at ../../binutils/gold/parameters.h:105
Summary: internal error in target, at ../../binutils/gold/parameters.h:105
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.26
: P2 normal
Target Milestone: ---
Assignee: Cary Coutant
Depends on:
Reported: 2015-07-20 20:47 UTC by Andrew Senkevich
Modified: 2015-07-21 20:37 UTC (History)
2 users (show)

See Also:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Senkevich 2015-07-20 20:47:25 UTC
cat t.c
int proc( int a)
  return 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)
    at ../../binutils/gold/archive.cc:141
#4  0x0000000000584498 in gold::Archive::add_symbols (this=0xae6c60, symtab=0x7fffffff8170, layout=0x7fffffff83d0, input_objects=0x7fffffff7f80, mapfile=0x0)
    at ../../binutils/gold/archive.cc:802
#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)
    at ../../binutils/gold/workqueue.cc:319
#7  0x00000000006a37da in gold::Workqueue::process (this=this@entry=0x7fffffff7e60, thread_number=thread_number@entry=0)
    at ../../binutils/gold/workqueue.cc:495
#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?
Comment 1 Cary Coutant 2015-07-21 16:05:05 UTC
> 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.
Comment 2 Andrew Senkevich 2015-07-21 17:28:02 UTC
(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?
Comment 3 Cary Coutant 2015-07-21 19:44:07 UTC
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.
Comment 4 cvs-commit@gcc.gnu.org 2015-07-21 19:51:26 UTC
The master branch has been updated by Cary Coutant <ccoutant@sourceware.org>:


commit b8c6c5ef99ef8f07fcea1c777d5084dc6f7232e5
Author: Cary Coutant <ccoutant@gmail.com>
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.
    	PR gold/18698
    	* 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().
Comment 5 Cary Coutant 2015-07-21 19:52:40 UTC
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:

Comment 6 Andrew Senkevich 2015-07-21 20:37:41 UTC
Thank you.