This is an archive of the discontinued LLVM Phabricator instance.

[Core] Do not reclaim absolute atoms in resolver
ClosedPublic

Authored by davide on Feb 22 2015, 9:09 PM.

Details

Summary

After discussion with Rui, he explained me the Resolver shouldn't reclaim absolute atoms at all.
This was found out while testing --gc-sections for the GNU driver, which cause lld to crash because of reclaim of absolute atoms.
The patch proposed is supposed to fix the problem.
I modified an existing test rather than adding a new one. Let me know if it's fine for you.

Diff Detail

Event Timeline

davide updated this revision to Diff 20485.Feb 22 2015, 9:09 PM
davide retitled this revision from to [Core] Do not reclaim absolute atoms in resolver.
davide updated this object.
davide edited the test plan for this revision. (Show Details)
davide added reviewers: ruiu, shankarke, Bigcheese.
davide added a project: lld.
davide added subscribers: Unknown Object (MLST), emaste.
shankarke added inline comments.Feb 23 2015, 5:06 AM
lib/Core/Resolver.cpp
393–394

Is this something GNU only ?

shankarke added inline comments.Feb 23 2015, 5:08 AM
lib/Core/Resolver.cpp
393–394

If its GNU only, then you need to add a linkingContext get/set function to check for flavors that want to reclaim absolute atoms.

ruiu accepted this revision.Feb 23 2015, 10:51 AM
ruiu edited edge metadata.

LGTM. I don't believe this is really ELF specific, it's harmless on other platforms at least. Let's just go ahead and see how it goes.

This revision is now accepted and ready to land.Feb 23 2015, 10:51 AM
shankarke edited edge metadata.Feb 23 2015, 10:59 AM

I feel its a bug in GNU on why absolute symbols are not reclaimed. Do we want to be bug compatible with lld ?

cat > 1.c << \!
int foo() { return 0; }
!

cat > 2.c << \!
int bar() { return 0; }
!

gcc -c 1.c 2.c
ld 1.o 2.o -e foo --gc-sections

nothing in bar is used, but still there is an absolute symbol, confuses me.

There is a absolute symbol for 2.c symbol.

readelf shows this :-

1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS 2.c
ruiu added a comment.Feb 23 2015, 11:13 AM

Can you elaborate why you think that's a bug of the GNU linker? Note that
absolute symbols are not sections.

nothing from 2.o was really needed in the final object. absolute symbols are specific to a file, its easy to enhance GC to collect them IMO. This is also needed by --defsym too, if there is not a reference to that symbol, ld doesnot generate one.

ruiu added a comment.Feb 23 2015, 11:32 AM

That we can "extend" the existing behavior of the GNU linker doesn't mean
that's a bug of the GNU linker. I don't even agree that it's a reasonable
extension, as --gc-sections means gc'ing sections and absolute symbols
don't belong to any section, but anyways, if you want to do something
different from the GNU linker, we need a really strong justification for
doing that. Making it compatible is the point of creating a compatible
driver.

davide closed this revision.Feb 25 2015, 9:42 PM