This is an archive of the discontinued LLVM Phabricator instance.

ELF2: Implement --as-needed.
ClosedPublic

Authored by ruiu on Oct 8 2015, 7:56 PM.

Details

Reviewers
rafael
Summary

This patch adds AsNeeded and IsUsed bool fields to SharedFile. AsNeeded bit
is set if the DSO is enclosed with --as-needed and --no-as-needed. IsUsed
bit is off by default. When we adds a symbol to the symbol table for dynamic
linking, we set its SharedFile's IsUsed bit.

If AsNeeded is set but IsUsed is not set, we don't want to write that
file's SO name to DT_NEEDED field.

Diff Detail

Event Timeline

ruiu updated this revision to Diff 36922.Oct 8 2015, 7:56 PM
ruiu retitled this revision from to ELF2: Implement --as-needed..
ruiu updated this object.
ruiu added a reviewer: rafael.
ruiu added a subscriber: llvm-commits.
rafael added inline comments.Oct 9 2015, 2:18 PM
ELF/Writer.cpp
207

I don't think this correctly handles weak symbols.

It should not set the bit if the symbol is only used to satisfy a weak undefined. For that it looks like you need to fetch the original SymbolBody, not the replacement.

test/elf2/as-needed.s
9

Please also add a test for the weak undefined case.

ruiu updated this revision to Diff 37061.Oct 11 2015, 11:10 AM

Did you mean this?

rafael accepted this revision.Oct 11 2015, 1:25 PM
rafael edited edge metadata.

LGTM with an additional testcase showing the handling of weak undefined symbols.

This revision is now accepted and ready to land.Oct 11 2015, 1:25 PM
Eugene.Zelenko added a subscriber: Eugene.Zelenko.

Committed in r249998.