This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Handle __init_array{start, end} correctly.
AbandonedPublic

Authored by davide on Mar 10 2015, 6:50 PM.

Details

Summary

I noticed that lld handles __init_array{start, end} incorrectly.

GNU ld

% objdump -t ./ld | grep init_array
00000000010cc000 l .ctors 0000000000000000 .hidden
init_array_end
00000000010cc000 l .ctors 0000000000000000 .hidden
__init_array_start

lld

% objdump -t ./bin/lld |grep init_array
0000000000000000 g O *ABS* 0000000000000000
init_array_start
0000000000000000 g O *ABS* 0000000000000000 __init_array_end

This patch is an attempt to fix.
If you agree with the approach, I'll change fini_array and preinit_array as well, and add tests.

Diff Detail

Event Timeline

davide updated this revision to Diff 21669.Mar 10 2015, 6:50 PM
davide retitled this revision from to [ELF] Handle __init_array{start, end} correctly..
davide updated this object.
davide edited the test plan for this revision. (Show Details)
davide added reviewers: ruiu, shankar.easwaran.
davide set the repository for this revision to rL LLVM.
davide added a project: lld.
davide added subscribers: emaste, Unknown Object (MLST).

Just for completeness, the careful reader may notice that visibility isn't handled correctly. As long as this is a general problem in lld, I'll tackle it separately later.

shankarke added inline comments.
lib/ReaderWriter/ELF/Atoms.h
873

It would be nice to add a class LinkerDefinedAtoms, that you can use for the purpose. It would simplify / remove extraneous code.

Another thing apart from visibility that lld doesnot currently do is the symbols get added for executables all the time, even there is no init_array section.

davide added inline comments.Mar 10 2015, 9:27 PM
lib/ReaderWriter/ELF/Atoms.h
873

So if I read correctly your proposal is that of renaming InitArrayAtom to LinkerDefinedAtoms and use that also for preinit/fini/bss etc..?
About --gc-section,. I've already did some ground work for it and fixed bugs (see r230614 and r230737) but still lots of atoms get reclaimed when they shouldn't, making lld not functional. This patch is also part of the ground work because the section is important to understand what can or cannot be stripped (see KEEP directive of GNU ld linker script, which is, unfortunately or not) widely used in FreeBSD default linker script and FreeBSD kernel linker script.

ruiu accepted this revision.Mar 11 2015, 12:30 PM
ruiu edited edge metadata.
ruiu added inline comments.
lib/ReaderWriter/ELF/Atoms.h
873

This is not a complicated class so I think it's ok for now. We may want to clean this up, but that needs to be done in a separate patch. First thing we should do is probably removing blank lines from one-line member function definitions so that they look more like simple struct-like field definitions.

This revision is now accepted and ready to land.Mar 11 2015, 12:30 PM
davide abandoned this revision.May 14 2015, 5:31 PM