Commit Graph

75 Commits

Author SHA1 Message Date
Peter Smith 97c6d78f3e [ELF] Add support for thunks to undefined non-weak symbols
In a shared library an undefined symbol is implicitly imported. If the
symbol is called as a function a PLT entry is generated for it. When the
caller is a Thumb b.w a thunk to the PLT entry is needed as all PLT
entries are in ARM state.
    
This change allows undefined symbols to have thunks in the same way that
shared symbols may have thunks.

llvm-svn: 290951
2017-01-04 09:45:45 +00:00
Rui Ueyama a13efc2a73 Introduce StringRefZ class to represent null-terminated strings.
StringRefZ is a class to represent a null-terminated string. String
length is computed lazily, so it's more efficient than StringRef to
represent strings in string table.

The motivation of defining this new class is to merge functions
that only differ in string types; we have many constructors that takes
`const char *` or `StringRef`. With StringRefZ, we can merge them.

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

llvm-svn: 288172
2016-11-29 18:05:04 +00:00
Davide Italiano 3bfa081aa9 [ELF] Be compliant with LLVM and rename Lto into LTO. NFCI.
llvm-svn: 287967
2016-11-26 05:37:04 +00:00
Davide Italiano f4de3b68bb [LTO] Remove a check on datalayout.
Now that lld switched to lib/LTO, which always calls setDataLayout(),
we don't need this check anymore.
Thanks to Peter for pointing out!

llvm-svn: 287699
2016-11-22 20:37:37 +00:00
Mehdi Amini c1edf566b9 Prevent at compile time converting from Error::success() to Expected<T>
This would trigger an assertion at runtime otherwise.

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

llvm-svn: 286562
2016-11-11 04:29:25 +00:00
Rui Ueyama 8c6a5aaf15 Create a vector containing all input sections.
Previously, we do this piece of code to iterate over all input sections.

  for (elf::ObjectFile<ELFT> *F : Symtab.getObjectFiles())
    for (InputSectionBase<ELFT> *S : F->getSections())

It turned out that this mechanisms doesn't work well with synthetic
input sections because synthetic input sections don't belong to any
input file.

This patch defines a vector that contains all input sections including
synthetic ones.

llvm-svn: 286051
2016-11-05 22:37:59 +00:00
Eugene Zelenko 22886a2853 Fix some Clang-tidy modernize-use-default and Include What You Use warnings; other minor fixes.
Differential revision: https://reviews.llvm.org/D26320

llvm-svn: 286030
2016-11-05 01:00:56 +00:00
Rui Ueyama 55518e7dd8 Consolidate BumpPtrAllocators.
Previously, we have a lot of BumpPtrAllocators, but all these
allocators virtually have the same lifetime because they are
not freed until the linker finishes its job. This patch aggregates
them into a single allocator.

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

llvm-svn: 285452
2016-10-28 20:57:25 +00:00
Rafael Espindola 5da1d88492 Reduce the number of allocators.
We used to have one allocator per file, which reduces the advantage of
using an allocator in the first place.

This is a small speed up is most cases. The largest speedup was in
1.014X in chromium no-gc. The largest slowdown was scylla at 1.003X.

llvm-svn: 285205
2016-10-26 15:34:24 +00:00
George Rimar a4c7e74d4b [ELF] - Applied clang format. NFC.
llvm-svn: 284705
2016-10-20 08:36:42 +00:00
Davide Italiano b6e6e4a074 [LTO] Split the options for ThinLTO jobs and Regular LTO partitions
Differential Revision:   https://reviews.llvm.org/D25452

llvm-svn: 283817
2016-10-10 23:12:14 +00:00
Davide Italiano 7a7b35ae3b [LTO/Thin] Make the number of threads to run in the BE configurable.
Before the default was whatever number hardware_concurrency() returned.
Users can specify the number of threads via --lto-jobs=X option.

llvm-svn: 283787
2016-10-10 18:12:53 +00:00
Rui Ueyama 5b8a3b3262 Remove HasError check after lto::LTO::run.
Because LTO::run doesn't change HasError, it doesn't make
sense to check that value.

llvm-svn: 282801
2016-09-29 22:50:37 +00:00
Rui Ueyama 1375a9bdc6 Remove a return type that can be trivially easily.
llvm-svn: 282795
2016-09-29 22:14:20 +00:00
Rui Ueyama 6c5cbff97e Rename "void check(Error)".
We have a few "check" functions in Error.h. All of them are to
check for an error and strip an error object if there was no error,
except "void check(Error E)", which doesn't return anything.
This patch renames it and moves it to the .cpp file where it is used.

llvm-svn: 282764
2016-09-29 21:00:26 +00:00
Rui Ueyama d31e13f287 Rename warning -> warn.
It's better because it's a verb.

llvm-svn: 282763
2016-09-29 21:00:23 +00:00
Rui Ueyama e8b2df47a3 Remove unused #includes.
llvm-svn: 282668
2016-09-29 01:45:22 +00:00
Davide Italiano c985e8b341 [LTO] Fully qualify make_unique to make MSVC happy.
llvm-svn: 282662
2016-09-29 01:13:32 +00:00
Davide Italiano 786d8e33db [ELF/LTO] Switch to the new resolution-based API.
Differential Revision:  https://reviews.llvm.org/D24492

llvm-svn: 282656
2016-09-29 00:40:08 +00:00
Davide Italiano c79d196c8e [LTO] Add a test for invalid alias analysis pipelines.
I found out this wasn't tested when looking at Vedant's coverage bot
numbers, so, thanks to him. While I'm here, switch the error message
to be lld-compliant (first letter lowercase).

llvm-svn: 282335
2016-09-24 20:05:52 +00:00
Rui Ueyama 38dbd3eea9 Simplify InputFile ownership management.
Previously, all input files were owned by the symbol table.
Files were created at various places, such as the Driver, the lazy
symbols, or the bitcode compiler, and the ownership of new files
was transferred to the symbol table using std::unique_ptr.
All input files were then free'd when the symbol table is freed
which is on program exit.

I think we don't have to transfer ownership just to free all
instance at once on exit.

In this patch, all instances are automatically collected to a
vector and freed on exit. In this way, we no longer have to
use std::unique_ptr.

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

llvm-svn: 281425
2016-09-14 00:05:51 +00:00
Rafael Espindola 8db87291ef Internalize common variables.
Before this lld was always creating common symbols itself. It worked,
but prevented them from being internalized when possible.

Now it preserves common symbols is the bitcode and they are internalized.

Fixes pr30184.

llvm-svn: 280242
2016-08-31 13:42:08 +00:00
Rafael Espindola a6c9744a6c Delete DefinedBitcode.
Given that we almost always want to handle it as DefinedRegular, just
use DefinedRegular.

llvm-svn: 280226
2016-08-31 12:30:34 +00:00
Davide Italiano 30ed8106ad [LTO] Simplify unnamed_addr handling logic. NFCI.
llvm-svn: 280224
2016-08-31 12:20:46 +00:00
Davide Italiano 35af5b3d21 [LTO] Fix the logic for dropping unnamed_addr.
Differential Revision:  https://reviews.llvm.org/D24037

llvm-svn: 280144
2016-08-30 20:15:03 +00:00
Rui Ueyama 434b56179e Add a pointer to a source file to SymbolBody.
Previously, each subclass of SymbolBody had a pointer to a source
file from which it was created. So, there was no single way to get
a source file for a symbol. We had getSourceFile<ELFT>(), but the
function was a bit inconvenient as it's a template.

This patch makes SymbolBody have a pointer to a source file.
If a symbol is not created from a file, the pointer has a nullptr.

llvm-svn: 275701
2016-07-17 03:11:46 +00:00
Rui Ueyama 818bb2f8dc Remove redundant namespace specifiers.
llvm-svn: 275694
2016-07-16 18:55:47 +00:00
Rui Ueyama 601b07c7f5 ELF: Remove member variables that are used only in one function.
Differential Revision: https://reviews.llvm.org/D22396

llvm-svn: 275526
2016-07-15 03:06:42 +00:00
Rui Ueyama a9d9eda0ce Inline a vairable that is used only once. NFC.
llvm-svn: 275524
2016-07-15 02:42:18 +00:00
Rui Ueyama 48da5cf236 ELF: Simplify path constructions for -save-temps. NFC.
llvm-svn: 275523
2016-07-15 02:17:13 +00:00
Rui Ueyama f8292e9ac9 ELF: Make check() always return a value.
This patch corresponds to r275511 for COFF.

llvm-svn: 275521
2016-07-15 02:01:03 +00:00
Peter Collingbourne 6ccb257925 ELF: Update #include path for D22173.
llvm-svn: 275477
2016-07-14 21:21:20 +00:00
Davide Italiano 30afae1a75 [LTO] Update after API change in LLVM. NFC.
llvm-svn: 273462
2016-06-22 19:51:05 +00:00
Davide Italiano 595ee8cb9c [LTO] Include ASM undefs in llvm.compiler_used.
This fixes PR28218. Thanks to Rafael for spotting a failure in
the SHARED_LIBS build!

Differential Revision:  http://reviews.llvm.org/D21577

llvm-svn: 273451
2016-06-22 18:09:23 +00:00
Rafael Espindola 254b58dfe3 Revert "Revert "Add a test showing that lto produces relaxable relocations.""
This reverts commit r273247.

lld should always use the new relocations.

llvm-svn: 273266
2016-06-21 14:47:43 +00:00
Davide Italiano 3935690433 Merge two if(s) into one, simplifying the code.
llvm-svn: 272475
2016-06-11 14:21:38 +00:00
Davide Italiano df24d5b8c8 [LTO] Add --lto-aa-pipeline.
Differential Revision:  http://reviews.llvm.org/D20888

llvm-svn: 271605
2016-06-02 22:58:11 +00:00
Davide Italiano 64ebf32ef3 [LTO] Fix (incorrect) TLS attribute mismatch.
When we undefine, we also preserve type of symbol so that we get
it right in the combined LTO object.

Differential Revision:  http://reviews.llvm.org/D20851

llvm-svn: 271403
2016-06-01 16:38:13 +00:00
Peter Collingbourne 5079f3b727 Update LLD for D20550.
Differential Revision: http://reviews.llvm.org/D20704

llvm-svn: 270968
2016-05-27 05:21:45 +00:00
Davide Italiano 5020d2ade5 Sort includes, and don't look into system headers.
llvm-svn: 269607
2016-05-15 19:43:02 +00:00
Davide Italiano d26c4a14ca [LTO] Add the ability to specify a subset of passes to run.
Differential Revision:  http://reviews.llvm.org/D20267

llvm-svn: 269605
2016-05-15 19:29:38 +00:00
Peter Collingbourne 0ef3874de3 Move undefine to a separate function.
llvm-svn: 269331
2016-05-12 19:46:14 +00:00
Davide Italiano 334fce92d9 [LTO] Don't crash on old DebugInfo.
Drop them and produce a graceful warning instead.

llvm-svn: 269149
2016-05-11 01:07:22 +00:00
Peter Collingbourne 3ad1c1e242 ELF: Undefine all symbols, not just those that we expect to be defined.
This allows the combined LTO object to provide a definition with the same
name as a symbol that was internalized without causing a duplicate symbol
error. This normally happens during parallel codegen which externalizes
originally-internal symbols, for example.

In order to make this work, I needed to relax the undefined symbol error to
only report an error for symbols that are used in regular objects.

Differential Revision: http://reviews.llvm.org/D19954

llvm-svn: 268649
2016-05-05 17:13:49 +00:00
Peter Collingbourne 4f9527065c ELF: New symbol table design.
This patch implements a new design for the symbol table that stores
SymbolBodies within a memory region of the Symbol object. Symbols are mutated
by constructing SymbolBodies in place over existing SymbolBodies, rather
than by mutating pointers. As mentioned in the initial proposal [1], this
memory layout helps reduce the cache miss rate by improving memory locality.

Performance numbers:

           old(s) new(s)
Without debug info:
chrome      7.178  6.432 (-11.5%)
LLVMgold.so 0.505  0.502 (-0.5%)
clang       0.954  0.827 (-15.4%)
llvm-as     0.052  0.045 (-15.5%)
With debug info:
scylla      5.695  5.613 (-1.5%)
clang      14.396 14.143 (-1.8%)

Performance counter results show that the fewer required indirections is
indeed the cause of the improved performance. For example, when linking
chrome, stalled cycles decreases from 14,556,444,002 to 12,959,238,310, and
instructions per cycle increases from 0.78 to 0.83. We are also executing
many fewer instructions (15,516,401,933 down to 15,002,434,310), probably
because we spend less time allocating SymbolBodies.

The new mechanism by which symbols are added to the symbol table is by calling
add* functions on the SymbolTable.

In this patch, I handle local symbols by storing them inside "unparented"
SymbolBodies. This is suboptimal, but if we do want to try to avoid allocating
these SymbolBodies, we can probably do that separately.

I also removed a few members from the SymbolBody class that were only being
used to pass information from the input file to the symbol table.

This patch implements the new design for the ELF linker only. I intend to
prepare a similar patch for the COFF linker.

[1] http://lists.llvm.org/pipermail/llvm-dev/2016-April/098832.html

Differential Revision: http://reviews.llvm.org/D19752

llvm-svn: 268178
2016-05-01 04:55:03 +00:00
Rafael Espindola 156f4ee1c0 Use a single context for lto.
Using multiple context used to be a really big memory saving because we
could free memory from each file while the linker proceeded with the
symbol resolution. We are getting lazier about reading data from the
bitcode, so I was curious if this was still a good tradeoff.

One thing that is a bit annoying is that we still have to copy the
symbol names. The problem is that the names are stored in the Module and
get freed when we move the module bits during linking.

Long term I think the solution is to add a symbol table to the bitcode.
That way IRObject file will not need to use a Module or a Context and we
can drop it while still keeping a StringRef to the names.

This patch is still be an interesting medium term improvement.

When linking llvm-as without debug info this patch is a small speedup:

master: 29.861877513 seconds
patch: 29.814533787 seconds

With debug info the numbers are

master: 34.765181469 seconds
patch: 34.563351584 seconds

The peak memory usage when linking llvm-as with debug info was

master: 599.10MB
patch: 600.13MB
llvm-svn: 267921
2016-04-28 19:30:41 +00:00
Rafael Espindola 9fdd071d01 Sort includes. NFC.
llvm-svn: 267821
2016-04-27 23:54:04 +00:00
Rui Ueyama 1e9e615f92 LTO: Merge -lto-no-discard-value-names with -save-temps.
This patch is to remove -lto-no-discard-value-names flag and
instead to use -save-temps as we discussed in the post-commit
review thread for r267020.

Differential Revision: http://reviews.llvm.org/D19437

llvm-svn: 267230
2016-04-22 21:43:10 +00:00
Rui Ueyama 412c802bda Move BitcodeCompiler constructor to the .cpp file. NFC.
llvm-svn: 267221
2016-04-22 21:16:18 +00:00
Peter Collingbourne dadcc17ead ELF: Move Visibility, IsUsedInRegularObj and MustBeInDynSym flags to Symbol.
These are properties of a symbol name, rather than a particular instance
of a symbol in an object file. We can simplify the code by collecting these
properties in Symbol.

The MustBeInDynSym flag has been renamed ExportDynamic, as its semantics
have been changed to be the same as those of --dynamic-list and
--export-dynamic-symbol, which do not cause hidden symbols to be exported.

Differential Revision: http://reviews.llvm.org/D19400

llvm-svn: 267183
2016-04-22 18:42:48 +00:00