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.
Details
Diff Detail
Event Timeline
lib/Core/Resolver.cpp | ||
---|---|---|
393–394 | Is this something GNU only ? |
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. |
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.
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
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.
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.
Is this something GNU only ?