This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Set up initial live symbol(s) to avoid incorrect reclaim of atoms
ClosedPublic

Authored by davide on Feb 26 2015, 5:25 PM.

Details

Summary

If no initial live symbols are set up, and deadStrip() == true, the Resolver ends up reclaiming all the symbols that aren't absolute. This is wrong.
This patch fixes the issue by setting entrySymbolName() as live, and this allows us to self-host lld when --gc-sections is enabled.
There are still quite a few problems with --gc-sections (quite a few tests failing), so the option can't be enabled by default.

P.S. This particular change depends on --gc-section so can't be tested easily. I would like to commit it as is and start looking at the test failures. I'll eventually add an unit test for this when --gc-sections will be enabled.

Diff Detail

Event Timeline

davide updated this revision to Diff 20812.Feb 26 2015, 5:25 PM
davide retitled this revision from to [ELF] Set up initial live symbol(s) to avoid incorrect reclaim of atoms.
davide updated this object.
davide edited the test plan for this revision. (Show Details)
davide added reviewers: ruiu, shankarke, Bigcheese, kledzik.
davide set the repository for this revision to rL LLVM.
davide added a project: lld.
davide added subscribers: Unknown Object (MLST), emaste.
ruiu accepted this revision.Feb 26 2015, 5:34 PM
ruiu edited edge metadata.

I think this is okay for now, but we should treat entry symbol name as a dead strip root unconditionally regardless of architecture or configuration. Curentlly, I believe if you call addDeadStripRoot and dead stripping is not enabled, it will fail because of an assertion error. That's a silly assertion -- that prevented us from add atoms to the root set "just in case". We should remove that assert and copy an entry symbol to the root set unconditionally.

Protip: run "svn diff --diff-cmd=diff -x -u100000" or "git show -U100000" to include an entire file to a patch, so that we can see all code on Phab.

lib/ReaderWriter/ELF/ELFLinkingContext.cpp
112

Remove this comment.

This revision is now accepted and ready to land.Feb 26 2015, 5:34 PM

Thank you for the info re patch context. I think we should remove the assertion as well, and I'll do in a subsequent change. Do you think it makes sense to remove the assertion also in the other methods, i.e. deadStripRoots() and globalsAreDeadStripRoots() ?

ruiu added a comment.Feb 26 2015, 5:53 PM

Yes, I think we should remove them as well.

ruiu added a comment.Feb 26 2015, 7:03 PM

Anyways, let's go ahead with this patch. LGTM.

shankarke accepted this revision.Feb 26 2015, 7:48 PM
shankarke edited edge metadata.
davide closed this revision.Mar 1 2015, 9:04 PM