Bug 18845 - Using emit-relocs and icf ends in assert fail.
Summary: Using emit-relocs and icf ends in assert fail.
Status: ASSIGNED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.25
: P2 normal
Target Milestone: ---
Assignee: Cary Coutant
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-08-18 08:56 UTC by Johan Karlsson
Modified: 2015-08-20 02:21 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
The patch that is described in the comment. (466 bytes, patch)
2015-08-18 08:56 UTC, Johan Karlsson
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Johan Karlsson 2015-08-18 08:56:36 UTC
Created attachment 8529 [details]
The patch that is described in the comment.

test.c:
main(){ return 0; }


CFLAGS="-fuse-ld=gold -Wl,--emit-relocs -Wl,--icf=safe" make test

cc -fuse-ld=gold -Wl,--emit-relocs -Wl,--icf=safe    test.c   -o test
/usr/bin/ld.gold: internal error in do_layout, at ../../gold/object.cc:1723
collect2: error: ld returned 1 exit status
make: *** [test] Error 1


I'm attaching a patch that fixes this problem. It changes so that the relocation sections are not added until the second pass in do_layout().

I also changed the assert to what I believe is the intended behavior, it is more in line with the handling of the eh_frame section.
Comment 1 Cary Coutant 2015-08-19 05:10:09 UTC
We never actually intended to support --gc-sections or --icf with -r links, but we don't do anything to disallow the combination, leading to the internal error. Gold should have some code in General_options::finalize() to disallow it.

With --emit-relocs, however, there really is no reason to disallow the combination, so we should make it work.

(Out of curiosity, what are you using --emit-relocs for? I'm not complaining -- hardly anyone uses the option, so it hasn't had much real-world testing.)
Comment 2 Johan Karlsson 2015-08-19 08:14:32 UTC
Right now there is a check for the -r/--gc-section/--icf combination in queue_initial_tasks(), however I think I saw a PR about it generating lots of error afterwards. Can't find it though.

I don't think the patch I attached would end in an assert failing when using -r in combination with --gc-section or --icf.

I'm using it to relocate a program when loading it on an embedded system.
Why not an relocatable ELF is used would be due to legacy, however it works quite well to do it this way. The only drawback would be that most of the relocation entries are unnecessary.
Comment 3 Alan Modra 2015-08-20 02:21:02 UTC
IBMs FDPR tool http://www.haifa.ibm.com/projects/systems/cot/fdpr/ uses --emit-relocs.  Which is why powerpc is probably the only target to fuss over emitting relocs that make sense on edited code, eg. we translate tls relocs as well as tls code sequences.