Commit Graph

87 Commits

Author SHA1 Message Date
George Rimar 2f5ca59497 Revert r335460 "[ELF] - ICF: Remove dead code. NFC."
My mistake, it was not NFC.

llvm-svn: 335471
2018-06-25 13:46:39 +00:00
George Rimar fb66ad5ea1 [ELF] - ICF: Remove dead code. NFC.
Code is dead. We use only InputSections when building the list of
sections elegible for the ICF:
https://github.com/llvm-mirror/lld/blob/master/ELF/ICF.cpp#L439
And 'isEligible' filters out SyntheticSections as well for us. 

That way the only Kind we have in the Sections vector is SectionBase::Regular,
so we do not need to check sections kind at all, it is always the same.

llvm-svn: 335460
2018-06-25 12:51:55 +00:00
George Rimar 50c6be9630 [ELF] - ICF: remove excessive check. NFC.
Change removes the excessive comparsion of
the relocation arrays sizes.

This code was dead, because at the higer level,
equalsConstant function contains the following check:

`A->NumRelocations != B->NumRelocations`
where NumRelocations contains the size of the relocations array.
So removed check did the same job twice.

This was found with use of code coverage analysis.

llvm-svn: 335346
2018-06-22 13:21:37 +00:00
Benjamin Kramer 88e7be2e6b [ELF] Pass callables by function_ref
No need to create a heavyweight std::function if it's not stored. No
functionality change intended.

llvm-svn: 334885
2018-06-16 12:11:34 +00:00
Peter Collingbourne 7ab7f149b2 ELF: Do not ICF sections named with a C identifier.
A user program may enumerate sections named with a C identifier using
__start_* and __stop_* symbols. We cannot ICF any such sections because
that could change program semantics.

Differential Revision: https://reviews.llvm.org/D47242

llvm-svn: 333054
2018-05-23 02:14:28 +00:00
Peter Collingbourne 11dc7fcae2 ELF: Do not ICF two sections with different output sections.
Note that this doesn't do the right thing in the case where there is
a linker script. We probably need to move output section assignment
before ICF to get the correct behaviour here.

Differential Revision: https://reviews.llvm.org/D47241

llvm-svn: 333052
2018-05-23 01:58:43 +00:00
Peter Collingbourne 3a9e2ca051 ELF: Allow ICF on .data.rel.ro sections.
Differential Revision: https://reviews.llvm.org/D47234

llvm-svn: 333040
2018-05-22 23:22:35 +00:00
Peter Smith dbef8cc67c [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
2018-05-15 08:57:21 +00:00
Bob Haarman 8c63bafdd3 [lld] fix data race in ELF/ICF.cpp
Summary:
r328610 fixed a data race in the COFF linker. This change makes a
similar fix to the ELF linker.

Reviewers: ruiu, pcc, rnk

Reviewed By: ruiu

Subscribers: emaste, llvm-commits, arichardson

Differential Revision: https://reviews.llvm.org/D45192

llvm-svn: 329088
2018-04-03 17:27:39 +00:00
Rui Ueyama 6a1ca2627a Move code so that the code matches with a comment. NFC.
llvm-svn: 328739
2018-03-28 22:47:53 +00:00
Andrew Ng ae0a7735b9 [ELF] Disable ICF for synthetic sections
The Data member of synthetic section's is not valid and empty. The Data
member is required to be valid by ICF as it is used by ICF to determine
the equality of section contents. Therefore, exclude synthetic sections
from ICF.

Fixes bug PR36910.

Differential Revision: https://reviews.llvm.org/D44923

llvm-svn: 328624
2018-03-27 14:10:07 +00:00
George Rimar 2d53967b48 Recommit "[ELF] - Do not crash with --emit-relocs and --icf=all together."
Latest patch version now.

Original commit message:

[ELF] - Do not crash with --emit-relocs and --icf=all together.

Previously we would crash because did not mark .rel[a] sections
as dead and they tried to access parent which was not live
after ICF and therefore was null.

Differential revision: https://reviews.llvm.org/D43241

llvm-svn: 325879
2018-02-23 10:37:33 +00:00
Rui Ueyama 2d9e7a8956 Use toString to stringize sections and files.
Differential Revision: https://reviews.llvm.org/D43251

llvm-svn: 325065
2018-02-13 22:56:49 +00:00
Rui Ueyama cfba0bed26 Fix coding style error.
llvm-svn: 325038
2018-02-13 18:40:52 +00:00
Galina Kistanova c6cd1f0139 Fixed extra ‘;’ warning
llvm-svn: 324830
2018-02-11 02:32:21 +00:00
Rui Ueyama 37a9889309 Make a lambda a static function to make the ICF main function shorter.
llvm-svn: 324756
2018-02-09 18:00:46 +00:00
Rui Ueyama 7b90efbece Do not print out removed ICF sections for -verbose.
GNU gold doesn't print out ICF sections for -verbose. It only shows
them for -print-icf-sections. We printed out them for -verbose because
we didn't have -print-icf-sections. Now that we have the option, there's
no reason to print out for -verbose.

Differential Revision: https://reviews.llvm.org/D43100

llvm-svn: 324755
2018-02-09 17:55:09 +00:00
Rui Ueyama d42b1c0534 Remove Config->Verbose because we have errorHandler().Verbose.
llvm-svn: 324684
2018-02-08 23:52:09 +00:00
Rui Ueyama 153b04f1be Fix --print-icf-sections output.
Previously, multiple chunks of --print-icf-sections messages were interleaved
and didn't make sense. This is because forEachClass is multi-threaded.

llvm-svn: 324683
2018-02-08 23:51:58 +00:00
James Henderson 9c6e2fd5a4 [ELF] Add --print-icf-sections flag
Currently ICF information is output through stderr if the "--verbose"
flag is used. This differs to Gold for example, which uses an explicit
flag to output this to stdout. This commit adds the
"--print-icf-sections" and "--no-print-icf-sections" flags and changes
the output message format for clarity and consistency with
"--print-gc-sections". These messages are still output to stderr if
using the verbose flag. However to avoid intermingled message output to
console, this will not occur when the "--print-icf-sections" flag is
used.

Existing tests have been modified to expect the new message format from
stderr.

Patch by Owen Reynolds.

Differential Revision: https://reviews.llvm.org/D42375

Reviewers: ruiu, rafael

Reviewed by: 

llvm-svn: 323976
2018-02-01 16:00:46 +00:00
Rafael Espindola b5506e6baf Rename --icf-data and add a corresponding flag for functions.
When we have --icf=safe we should be able to define --icf=all as a
shorthand for --icf=safe --ignore-function-address-equality.

For now --ignore-function-address-equality is used only to control
access to non preemptable symbols in shared libraries.

llvm-svn: 322152
2018-01-10 01:37:36 +00:00
Rafael Espindola 814ece6854 Add an option for ICFing data.
An internal linker has support for merging identical data and in some
cases it can be a significant win.

This is behind an off by default flag so it has to be requested
explicitly.

llvm-svn: 320448
2017-12-12 01:36:24 +00:00
Rafael Espindola d26b52fd34 Remove some includes from InputFiles.h.
They were not used in InputFiles.h and it was getting too easy to add
circular includes.

llvm-svn: 320256
2017-12-09 16:56:18 +00:00
Peter Collingbourne e9a9e0a1e7 ELF: Merge DefinedRegular and Defined.
Now that DefinedRegular is the only remaining derived class of
Defined, we can merge the two classes.

Differential Revision: https://reviews.llvm.org/D39667

llvm-svn: 317448
2017-11-06 04:35:31 +00:00
Rui Ueyama f52496e1e0 Rename SymbolBody -> Symbol
Now that we have only SymbolBody as the symbol class. So, "SymbolBody"
is a bit strange name now. This is a mechanical change generated by

  perl -i -pe s/SymbolBody/Symbol/g $(git grep -l SymbolBody lld/ELF lld/COFF)

nd clang-format-diff.

Differential Revision: https://reviews.llvm.org/D39459

llvm-svn: 317370
2017-11-03 21:21:47 +00:00
Bob Haarman 4f5c8c29ac [lld] Move Threads to Common
Summary:
This will allow using the functionality from other linkers. It is also
a prerequisite for sharing the error logging code.

Reviewers: ruiu

Reviewed By: ruiu

Subscribers: emaste, mgorny, llvm-commits

Differential Revision: https://reviews.llvm.org/D38822

llvm-svn: 315725
2017-10-13 18:22:55 +00:00
Rui Ueyama 274aa2fb88 [ICF] Include section contents in section hash values.
Computing section content hashes early seems like a win in terms of
performance. It increases a chance that two different sections will get
different class IDs from the beginning.

Without threads, this patch improves Chromium link time by about 0.3
seconds. With threads, by 0.1 seconds. That's less than 1% time saving
but not bad for a small patch.

llvm-svn: 314644
2017-10-02 01:21:07 +00:00
Rui Ueyama 5ac94e768b Rewrite std::equal as plain for-loops.
Looks like there's no need to use a higher order function. We can simply
use the regular for-loop.

llvm-svn: 311942
2017-08-28 22:28:41 +00:00
Peter Collingbourne bfd5113ca1 ELF: Teach ICF about relocations referring to merge input sections.
Relocations referring to merge sections are considered equal if they
resolve to the same offset in the same output section.

Differential Revision: https://reviews.llvm.org/D34094

llvm-svn: 305177
2017-06-12 00:05:54 +00:00
Zachary Turner 264b5d9e88 Move Object format code to lib/BinaryFormat.
This creates a new library called BinaryFormat that has all of
the headers from llvm/Support containing structure and layout
definitions for various types of binary formats like dwarf, coff,
elf, etc as well as the code for identifying a file from its
magic.

Differential Revision: https://reviews.llvm.org/D33843

llvm-svn: 304864
2017-06-07 03:48:56 +00:00
Rui Ueyama f04c04837c Improve parallelism of ICF.
This is the only place we use threads for ICF. The intention of this code
was to split an input vector into 256 shards and process them in parallel.
What the code was actually doing was to split an input into 257 shards,
process the first 256 shards in parallel, and the remaining one in serial.

That means this code takes ceil(256/n)+1 instead of ceil(256/n) where n
is the number of available CPU cores. The former converges to 2 while
the latter converges to 1.

This patches fixes the above issue.

llvm-svn: 303797
2017-05-24 19:22:34 +00:00
Rui Ueyama 33d903d1b0 Rename parallelFor -> parallelForEachN.
So that it is clear that the function is a wrapper for for_each_n.

llvm-svn: 302718
2017-05-10 20:02:19 +00:00
Peter Smith cec1e260c3 [ELF] Mark ARM Exceptions that refer to folded code as not live
ARM Exception Index Table sections .ARM.exidx have an implicit dependency
on code sections via SHF_LINK_ORDER. When code sections are folded by ICF
we must mark the unique .ARM.exidx table that describes it as not live
to prevent an illegal entry in the exception table.
    
Note that we do not try and follow the relocations from the .ARM.exidx
section to the .ARM.extab sections to mark these as not live. Leaving
these sections is not a correctness problem. In theory these could be
removed via an application of garbage collection.
    
Fixes https://bugs.llvm.org/show_bug.cgi?id=32614

Differential Revision: https://reviews.llvm.org/D31932

llvm-svn: 300182
2017-04-13 08:52:58 +00:00
Rui Ueyama 4995afd943 Rename forEach -> parallelForEach and forLoop -> parallelFor.
"Parallel" is the most important aspect of the functions,
so we shouldn't omit that.

llvm-svn: 298557
2017-03-22 23:03:35 +00:00
Rui Ueyama d57e74b7d3 Compute Config member function return values only once.
We had a few Config member functions that returns configuration values.
For example, we had is64() which returns true if the target is 64-bit.
The return values of these functions are constant and never change.

This patch is to compute them only once to make it clear that they'll
never change.

llvm-svn: 298168
2017-03-17 23:29:01 +00:00
Rafael Espindola 76b6bd355d Remove unnecessary template. NFC.
llvm-svn: 297287
2017-03-08 15:44:30 +00:00
Rui Ueyama df8eb17d21 Remove Config->Mips64EL and define Config->isMips64EL() instead.
llvm-svn: 297107
2017-03-07 00:43:33 +00:00
Rui Ueyama 13ed0b691e ELF ICF: Merge only functions.
Previously, LLD merged all read-only sections. So the following
program prints out "true" if -icf=all is specified.

  static const int foo = 1;
  static const int bar = 1;
  int main() { printf("%s\n", &foo == &bar ? "true" : "false"); }

This is somewhat counter-intuitive, and it actually caused nasty issues.
One example is https://bugs.chromium.org/p/chromium/issues/detail?id=682773#c24.

This patch changes the way how it works. Now ICF merges only functions
(i.e. executable sections).

Differential Revision: https://reviews.llvm.org/D30365

llvm-svn: 296534
2017-02-28 22:42:49 +00:00
Rui Ueyama 80474a26b9 De-template DefinedRegular.
Differential Revision: https://reviews.llvm.org/D30348

llvm-svn: 296508
2017-02-28 19:29:55 +00:00
Rui Ueyama 536a26706f Move SymbolTable<ELFT>::Sections out of the class.
The list of all input sections was defined in SymbolTable class for a
historical reason. The list itself is not a template. However, because
SymbolTable class is a template, we needed to pass around ELFT to access
the list. This patch moves the list out of the class so that it doesn't
need ELFT.

llvm-svn: 296309
2017-02-27 02:32:08 +00:00
Rafael Espindola 774ea7d0a9 Make InputSection a class. NFC.
With the current design an InputSection is basically anything that
goes directly in a OutputSection. That includes plain input section
but also synthetic sections, so this should probably not be a
template.

llvm-svn: 295993
2017-02-23 16:49:07 +00:00
Rafael Espindola b4c9b81aad Convert InputSectionBase to a class.
Removing this template is not a big win by itself, but opens the way
for removing more templates.

llvm-svn: 295923
2017-02-23 02:28:28 +00:00
Peter Collingbourne dbd8d9b5a2 ELF: Fix ICF crash on absolute symbol relocations.
If two sections contained relocations to absolute symbols with the same
value we would crash when trying to access their sections. Add a check that
both symbols point to sections before accessing their sections, and treat
absolute symbols as equal if their values are equal.

Differential Revision: https://reviews.llvm.org/D28935

llvm-svn: 292578
2017-01-20 04:58:12 +00:00
Rui Ueyama c9df172553 Fix typo.
llvm-svn: 292044
2017-01-15 02:34:42 +00:00
Rui Ueyama fcd3fa83ea Use "equivalence class" instead of "color" to describe the concept in ICF.
Also add a citation to GNU gold safe ICF paper.

Differential Revision: https://reviews.llvm.org/D27398

llvm-svn: 288684
2016-12-05 18:11:35 +00:00
Rui Ueyama 5cb712ed3c Simplify ICF alignment handling.
llvm-svn: 288630
2016-12-05 01:31:39 +00:00
Rui Ueyama 045d828158 Re-implement the optimization that I removed in r288527.
I removed a wrong optimization for ICF in r288527. Sean Silva suggested
in a post commit review that the correct algorithm can be implemented
easily. So is this patch.

llvm-svn: 288620
2016-12-04 16:33:13 +00:00
Rui Ueyama 244a435ae3 Factor out common code to a header.
llvm-svn: 288599
2016-12-03 21:24:51 +00:00
Rui Ueyama 5419861a52 Remove a wrong performance optimization.
This is a hack for single thread execution. We are using Color[0] and
Color[1] alternately on each iteration. This optimization is to look
at the next slot as opposted to the current slot to get recent results
early. Turns out that the assumption is wrong, because the other slots
are not always have the most recent values, but instead it may have
stale values of the previous iteration. This patch removes that
performance hack.

llvm-svn: 288527
2016-12-02 18:40:43 +00:00
Rui Ueyama 83ec681a5c Removed a wrong assertion about non-colorable sections.
The assertion asserted that colorable sections can never have
a reference to non-colorable sections, but that was simply wrong.
They can have references to non-colorable sections. If that's the
case, referenced sections must be the same in terms of pointer
comparison.

llvm-svn: 288511
2016-12-02 17:23:58 +00:00