diff options
author | Peter Smith <peter.smith@linaro.org> | 2018-05-15 08:57:21 +0000 |
---|---|---|
committer | Peter Smith <peter.smith@linaro.org> | 2018-05-15 08:57:21 +0000 |
commit | dbef8cc67c9918334c22f03e23e2dfa84ade464b (patch) | |
tree | b5fdfd07c8936ada276396dbbcbfb7284194b919 /lld/ELF/Driver.cpp | |
parent | 559d1e34df710a0c88dc775b014413c8f80804f7 (diff) | |
download | bcm5719-llvm-dbef8cc67c9918334c22f03e23e2dfa84ade464b.tar.gz bcm5719-llvm-dbef8cc67c9918334c22f03e23e2dfa84ade464b.zip |
[ELF] Implement --keep-unique option
The --keep-unique <symbol> option is taken from gold. The intention is that
<symbol> will be prevented from being folded by ICF. Although not
specifically mentioned in the documentation <symbol> only matches
global symbols, with a warning if the symbol is not found.
The implementation finds the Section defining <symbol> and removes it from
the set of sections considered for ICF.
Differential Revision: https://reviews.llvm.org/D46755
llvm-svn: 332332
Diffstat (limited to 'lld/ELF/Driver.cpp')
-rw-r--r-- | lld/ELF/Driver.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 0d6602b767e..c81efb3905d 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -1163,6 +1163,18 @@ template <class ELFT> static void demoteSymbols() { } } +// Record sections that define symbols mentioned in --keep-unique <symbol> +// these sections are inelligible for ICF. +static void findKeepUniqueSections(opt::InputArgList &Args) { + for (auto *Arg : Args.filtered(OPT_keep_unique)) { + StringRef Name = Arg->getValue(); + if (auto *Sym = dyn_cast_or_null<Defined>(Symtab->find(Name))) + Sym->Section->KeepUnique = true; + else + warn("could not find symbol " + Name + " to keep unique"); + } +} + // Do actual linking. Note that when this function is called, // all linker scripts have already been parsed. template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) { @@ -1335,8 +1347,10 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) { markLive<ELFT>(); demoteSymbols<ELFT>(); mergeSections(); - if (Config->ICF) + if (Config->ICF) { + findKeepUniqueSections(Args); doIcf<ELFT>(); + } // Read the callgraph now that we know what was gced or icfed if (auto *Arg = Args.getLastArg(OPT_call_graph_ordering_file)) |