This is an archive of the discontinued LLVM Phabricator instance.

[ELF, Bug 26360] - allows undefines that are referenced from garbage collected sections.
AbandonedPublic

Authored by grimar on Feb 14 2016, 10:48 PM.

Details

Reviewers
ruiu
rafael
Summary

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 Timeline

grimar updated this revision to Diff 47947.Feb 14 2016, 10:48 PM
grimar retitled this revision from to [ELF, Bug 26360] - allows undefines that are referenced from garbage collected sections..
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.
rafael edited edge metadata.Feb 15 2016, 8:13 AM
rafael added a subscriber: rafael.

Is this really desirable?

It looks like an optimization option changing the semantics. What do
you get with gold?

Cheers,
Rafael

Is this really desirable?

It looks like an optimization option changing the semantics. What do
you get with gold?

Cheers,
Rafael

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.
Below is the how I got the sample for test cases and the results of linkage using 3 linkers:

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
llvm-mc -filetype=obj -triple=x86_64-pc-linux main.s -o main.o

ld -e main --gc-sections main.o -o test
(ok)

gold -e main --gc-sections main.o -o test
(ok)

ld.lld -e main --gc-sections main.o -o test
undefined symbol: _Z18undefined_functionv in main.o

rafael added inline comments.Feb 16 2016, 5:53 AM
ELF/Symbols.h
258

Are the semantics the same as CanKeepUndefined? Could you use a single bool?

ELF/Writer.cpp
295

Name is not used.

test/ELF/gc-sections-unref-undef.s
4

Should there be an undefined symbol in the output?

Check one way or the other.

ruiu edited edge metadata.Feb 16 2016, 10:38 AM

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.

emaste added a subscriber: emaste.Feb 16 2016, 12:34 PM
In D17252#353691, @ruiu wrote:

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.

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.
Also I found that "It is ok for dead code to reference undefined symbols..." (http://lists.llvm.org/pipermail/llvm-dev/2015-June/086571.html). From my POV it was mentionaed as a expected and desired feature.

grimar abandoned this revision.Feb 29 2016, 2:24 AM

Lets see if anyone really needs that first then.

ed added a subscriber: ed.EditedFeb 29 2016, 5:33 AM
  • Removed comment --

Sorry! I commented on the wrong code review. Never mind!