This is an archive of the discontinued LLVM Phabricator instance.

[lld] Implement --dynamic-list
AbandonedPublic

Authored by zatrazz on Apr 4 2016, 1:28 PM.

Details

Reviewers
ruiu
rafael
Summary

This patch implements the --dynamic-list option, which adds a list of
global symbol that either should not be bounded by default definition
when creating shared libraries, or add in dynamic symbol table in the
case of creating executables.

The patch modifies the ScriptParserBase class to use a list of Token
instead of StringRef, which contains information if the token is a
quoted or unquoted strings. It is used to use a faster search for
exact match symbol name.

The input file follow a similar format of linker script with some
simplifications (it does not have scope or node names). It leads
to a simplified parser define in DynamicList.{cpp,h}.

Symbol match is done by consulting two lists: first a StringSet
for exact match names (defined in quoted strings) and then each
glob definition (in the order of definition).

This patch depends on http://reviews.llvm.org/D18771

Diff Detail

Event Timeline

zatrazz updated this revision to Diff 52613.Apr 4 2016, 1:28 PM
zatrazz retitled this revision from to [lld] Implement --dynamic-list.
zatrazz updated this object.
zatrazz added reviewers: ruiu, rafael.
zatrazz set the repository for this revision to rL LLVM.
zatrazz added subscribers: llvm-commits, rengolin.
ruiu added inline comments.Apr 4 2016, 2:18 PM
ELF/DynamicList.cpp
35

I also don't like to support C++ mangled names now. There's a chance that we might want that later, but this patch is already too large, so please remove that feature.

ELF/ScriptParser.cpp
23–25 ↗(On Diff #52613)

At least for now, I don't want to support glob patterns at all. Glob pattern can have huge performance impact on the linking speed. In most cases users pass a list of complete symbol names, so we should reject any patterns that contains glob metacharacters and do simple hash table lookup instead of glob pattern matching.

zatrazz added inline comments.Apr 4 2016, 2:33 PM
ELF/DynamicList.cpp
35

Although llvm itself does not use, I see no direct reason to not support. It does not interfere significantly with default matching rules (for glob patterns it will first check the language mangling and only applying the damangling in such case) if the script does not use it.

ELF/ScriptParser.cpp
23–25 ↗(On Diff #52613)

As stated in http://llvm.org/pr26693 it is required for the sanitizers and at least from LLVm side it the main motivator for this patch. I think we can add an additional check on DynamicList to check if an dynamic list and fast return if it is not the case.

ruiu added inline comments.Apr 4 2016, 2:44 PM
ELF/DynamicList.cpp
35

Apparently this part of linker script was not designed with speed in mind, and I think the gnu linker went a bit too far on this front. How many users are really using this feature? Is this really what we want to have? We need to think carefully to decide whether we want to do the same thing as the gnu linker for mangled names.

ELF/ScriptParser.cpp
23–25 ↗(On Diff #52613)

Do you need the glob pattern fro the sanitizer?

pcc added a subscriber: pcc.Apr 4 2016, 2:55 PM
pcc added inline comments.
ELF/ScriptParser.cpp
23–25 ↗(On Diff #52613)

FWIW, I think it should be pretty trivial to avoid using glob patterns in the sanitizer dynamic lists.

zatrazz added inline comments.Apr 4 2016, 2:57 PM
ELF/DynamicList.cpp
35

I would say it was designed for flexibility, since the idea is to define C++ (or any other supported language) symbols without tie to mangling reles for an specific ABI. It is possible to just use the mangled name instead, but since GNU ld supports multiples system with different mangling name schemes, this seems the solution to avoid such trap.

Anyway, I think performance-wise I it won't hurt default case, since demangling will just be used if 'extern...' is actually issued in the script. About the users, I am not sure since sanitizers itself does not make use of this (since it exports its API as C). However I expect that C++ libraries may use this instead of using mangling names.

ELF/ScriptParser.cpp
23–25 ↗(On Diff #52613)

Yes, sanitizers uses dynamic list entries with '*' patterns.

zatrazz updated this revision to Diff 52729.Apr 5 2016, 1:10 PM
zatrazz removed rL LLVM as the repository for this revision.

This is an update of previous patch where I added an option
which makes lld check if --dynamic-list options is used before
trying to match a symbols. This should be faster for common
usage (building without the option).

ruiu added inline comments.Apr 5 2016, 1:53 PM
ELF/DynamicList.cpp
36

I don't want to support them until it is proved that we absolutely have to do that because it has huge performance impact if the option is enabled. The reason that "because gnu ld/gold do this" is too weak to justify. Even if it wouldn't hurt the default case, I wouldn't like to land a patch C++ name mangling and glob patterns right now, particularly as a part of the other large patch (I meant this patch which implements --dynamic-list.)

jbulow added a subscriber: jbulow.Apr 6 2016, 2:04 AM

To be compatible with GNU ld the syntax should be --dynamic-list=dynamic-list-file. The current patch does not accept the equal sign before the file name.

zatrazz updated this revision to Diff 52795.Apr 6 2016, 7:42 AM

Updated patch based on previous comments:

  • Different from ld/gold neither glob pattern nor mangled names (extern 'C++') are currently supported.
  • Added alias for -dynamic-list= and --dynamic-list=

Ping, are the dynamic-list support ok for inclusion now? I am currently adjusting the compiler-rt dynamic list to be compatible with entries without glob chars.

zatrazz abandoned this revision.Apr 11 2016, 5:35 AM