This fixes the https://llvm.org/bugs/show_bug.cgi?id=26360.
If code is unreferenced and is about to be pruned away by --gc-sections, it is allowed to contain references to undefined symbols.
Differential D17252
[ELF, Bug 26360] - allows undefines that are referenced from garbage collected sections. grimar on Feb 14 2016, 10:48 PM. Authored by
Details This fixes the https://llvm.org/bugs/show_bug.cgi?id=26360. If code is unreferenced and is about to be pruned away by --gc-sections, it is allowed to contain references to undefined symbols.
Diff Detail Event TimelineComment Actions Is this really desirable? It looks like an optimization option changing the semantics. What do Cheers, Comment Actions Hi Rafael, gold and ld has the same behavior and allows such undefines, I checked that first before started to implement the patch and it seems logical to me: if section is excluded it is no need to error the undefines from it. main.cpp: void undefined_function(); void unreferenced_function() { undefined_function(); } int main(int argc, char **argv) { return 0; } clang -ffunction-sections main.cpp -S -o main.s ld -e main --gc-sections main.o -o test gold -e main --gc-sections main.o -o test ld.lld -e main --gc-sections main.o -o test Comment Actions I think that we don't want it until it is proved that this "feature" is really needed. It is not hard to imagine that this is _not_ a feature of gold's or GNU ld's. Depending on your internal data structure, this behavior could naturally arise. If the same behavior naturally occurred in our linker, it'd be okay, but this patch intentionally mimic the obscure behavior of the other linkers. I think it needs more justification than "because GNU gold/ld do that" to add this code. Comment Actions It was hard to imagine for me though, I was and still thinking about it as about feature. It is not logical for me to keep dependency on code that is dead itself. Keep errors because of undefines that are actually no longer exist because whole section is GCollected. |
Are the semantics the same as CanKeepUndefined? Could you use a single bool?