Commit Graph

112 Commits

Author SHA1 Message Date
Bob Haarman ac8f7fc07b [COFF] support /ERRORLIMIT option
Summary:
This adds support for reporting multiple errors in a single invocation of lld-link. The limit defaults to 20 and can be changed with the /ERRORLIMIT command line parameter, or set to unlimited by passing a value of 0.

This is a new attempt after r295507, which was reverted because opening files raced with exiting early, causing the test to be flaky. This version avoids the race by exiting before calling enqueuePath.

Reviewers: pcc, ruiu

Reviewed By: ruiu

Subscribers: llvm-commits, dblaikie

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

llvm-svn: 299496
2017-04-05 00:43:54 +00:00
Rui Ueyama e6e206d4b4 Do not use errs() or outs() directly. Instead use message(), log() or error()
LLD is a multi-threaded program. errs() or outs() are not guaranteed
to be thread-safe (they are actually not).

LLD's message(), log() or error() are thread-safe. We should use them.

llvm-svn: 295787
2017-02-21 23:22:56 +00:00
David Blaikie 4cdfe69982 Revert "[COFF] support /ERRORLIMIT option"
Behavior races on ErrorCount. If the enqueued paths are evaluated
eagerly (in enqueuePath) then the behavior is as the test expects. But
they may not be evaluated until the future is waited on, in run() -
which is after the early return/exit on ErrorCount. (this causes the
test to fail (because in the "/ERRORCOUNT:XYZ" test, no other errors
are printed), at least for me, on linux)

This reverts commit r295507.

llvm-svn: 295590
2017-02-19 02:25:47 +00:00
Bob Haarman b96b10102a [COFF] support /ERRORLIMIT option
Summary: This adds support for reporting multiple errors in a single invocation of lld-link. The limit defaults to 20 and can be changed with the /ERRORLIMIT command line parameter, or set to unlimited by passing a value of 0.

Reviewers: pcc, ruiu

Reviewed By: ruiu

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

llvm-svn: 295507
2017-02-17 22:46:06 +00:00
Rui Ueyama 1e0b158dbd Add an option to use the MSVC linker to link LTO-generated object files.
This patch defines a new command line option, /MSVCLTO, to LLD.
If that option is given, LLD invokes link.exe to link LTO-generated
object files. This is hacky but useful because link.exe can create
PDB files.

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

llvm-svn: 294234
2017-02-06 20:47:55 +00:00
Bob Haarman cde5e5b600 refactor COFF linker to use new LTO API
Summary: The COFF linker previously implemented link-time optimization using an API which has now been marked as legacy. This change refactors the COFF linker to use the new LTO API, which is also used by the ELF linker.

Reviewers: pcc, ruiu

Reviewed By: pcc

Subscribers: mgorny, mehdi_amini

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

llvm-svn: 293967
2017-02-02 23:58:14 +00:00
Peter Collingbourne 6f24fdb6a0 COFF: Change the /lldmap output format to be more like the ELF linker.
Differential Revision: https://reviews.llvm.org/D28717

llvm-svn: 291990
2017-01-14 03:14:46 +00:00
Rui Ueyama 9381eb1045 Remove lld/Support/Memory.h.
I thought for a while about how to remove it, but it looks like we
can just copy the file for now. Of course I'm not happy about that,
but it's just less than 50 lines of code, and we already have
duplicate code in Error.h and some other places. I want to solve
them all at once later.

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

llvm-svn: 290062
2016-12-18 14:06:06 +00:00
Peter Collingbourne 6ee0b4e9f5 COFF: Open and map input files asynchronously on Windows.
Profiling revealed that the majority of lld's execution time on Windows was
spent opening and mapping input files. We can reduce this cost significantly
by performing these operations asynchronously.

This change introduces a queue for all operations on input file data. When
we discover that we need to load a file (for example, when we find a lazy
archive for an undefined symbol, or when we read a linker directive to
load a file from disk), the file operation is launched using a future and
the symbol resolution operation is enqueued.  This implies another change
to symbol resolution semantics, but it seems to be harmless ("ninja All"
in Chromium still succeeds).

To measure the perf impact of this change I linked Chromium's chrome_child.dll
with both thin and fat archives.

Thin archives:

Before (median of 5 runs): 19.50s
After: 10.93s

Fat archives:

Before: 12.00s
After: 9.90s

On Linux I found that doing this asynchronously had a negative effect on
performance, probably because the cost of mapping a file is small enough that
it becomes outweighed by the cost of managing the futures. So on non-Windows
platforms I use the deferred execution strategy.

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

llvm-svn: 289760
2016-12-15 04:02:23 +00:00
Peter Collingbourne e50f4854c2 COFF: Fix memory leaks reported by lsan.
llvm-svn: 289451
2016-12-12 18:42:09 +00:00
Peter Collingbourne 3f530938f6 COFF: Use CachedHashStringRef in the symbol table.
This resulted in about a 1% perf improvement linking chrome_child.dll.

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

llvm-svn: 289410
2016-12-11 22:15:30 +00:00
Peter Collingbourne 8b65e51b73 COFF: Load inputs immediately instead of adding them to a queue.
This patch replaces the symbol table's object and archive queues, as well as
the convergent loop in the linker driver, with a design more similar to the
ELF linker where symbol resolution directly causes input files to be added to
the link, including input files arising from linker directives. Effectively
this removes the last vestiges of the old parallel input file loader.

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

llvm-svn: 289409
2016-12-11 22:15:25 +00:00
Peter Collingbourne 79a5e6b1b7 COFF: New symbol table design.
This ports the ELF linker's symbol table design, introduced in r268178,
to the COFF linker.

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

llvm-svn: 289280
2016-12-09 21:55:24 +00:00
Rui Ueyama 7a0a076e40 COFF: Use make() in SymbolTable and Writer.
llvm-svn: 289170
2016-12-09 02:13:12 +00:00
Rui Ueyama 8fe1767cdd Remove unnecessary `llvm::`.
llvm-svn: 289102
2016-12-08 20:50:47 +00:00
Rui Ueyama bf4ad1d63d COFF: Use make() to create a new file object in createFile.
llvm-svn: 289097
2016-12-08 20:20:22 +00:00
Rui Ueyama aa4f4450af Revert r289084: Start using make() in COFF.
This reverts commit r289084 to appease buildbots.

llvm-svn: 289086
2016-12-08 18:49:04 +00:00
Rui Ueyama 843233b920 Start using make() in COFF.
We don't want ELF and COFF to diverge too much.

llvm-svn: 289085
2016-12-08 18:31:18 +00:00
Rui Ueyama a45d45e231 COFF: Define overloaded toString functions.
Previously, we had different way to stringize SymbolBody and InputFile
to construct error messages. This patch defines overloaded function
toString() so that we don't need to memorize all these different
function names.

With that change, it is now easy to include demangled names in error
messages. Now, if there is a symbol name conflict, we'll print out
both mangled and demangled names.

llvm-svn: 288992
2016-12-07 23:17:02 +00:00
Hans Wennborg cb8f2ef644 LTO: Don't follow lazy references when seeing new definitions in the combined LTO object
Following the lazy reference might bring in an object file that depends
on bitcode files that weren't part of the LTO step.

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

llvm-svn: 283989
2016-10-12 09:00:06 +00:00
Rui Ueyama bb57954241 COFF: Update error messages so that they start with lowercase letters.
llvm-svn: 275513
2016-07-15 01:12:24 +00:00
Rui Ueyama 5694ebbc8b Remove unnecessary explicit call of Twine ctor.
llvm-svn: 275512
2016-07-15 01:06:40 +00:00
Rui Ueyama 606047939c COFF: Rename noreturn error -> fatal.
This new name is also consistent with ELF.

llvm-svn: 275500
2016-07-14 23:37:14 +00:00
Peter Collingbourne 765aa2d1c2 COFF: Update remaining #include paths.
llvm-svn: 275480
2016-07-14 21:30:37 +00:00
Rafael Espindola a5cefffc33 Update for llvm change.
llvm-svn: 270907
2016-05-26 20:31:06 +00:00
Rui Ueyama 34b60f1c40 Do not use llvm::getGlobalContext().
llvm-svn: 266375
2016-04-14 21:41:44 +00:00
Mehdi Amini 03a5042e4c Revert "Do not use llvm::getGlobalContext(), trying to nuke it from LLVM"
This reverts commit r266365 and r266367, the contexts in the two
places have to match.

From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 266373
2016-04-14 21:31:46 +00:00
Mehdi Amini f1e7ff9d0e Do not use llvm::getGlobalContext(), trying to nuke it from LLVM
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 266365
2016-04-14 20:53:39 +00:00
Davide Italiano 3774afba07 [COFF] Simplify the code leveraging implicit conversion.
Suggested by: David Blaikie!

llvm-svn: 266140
2016-04-12 22:05:38 +00:00
Davide Italiano eeae124faf [COFF] SmallVector<char, 0> -> SmallString<0>.
This way we're consistent between ELF and COFF.

llvm-svn: 265885
2016-04-09 23:00:31 +00:00
Rafael Espindola 35dad13714 Update for LLVM api change.
llvm-svn: 254697
2015-12-04 02:42:47 +00:00
Peter Collingbourne 70507e59fe COFF: Destroy LTOModules as they are linked.
This should help reduce memory consumption during LTO.

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

llvm-svn: 253397
2015-11-17 23:30:59 +00:00
Yunzhong Gao fbee89263f Fixing build failures caused by r253367. Sorry for breaking the build.
llvm-svn: 253374
2015-11-17 20:48:12 +00:00
Rui Ueyama 98a98cffb6 COFF: Do not call std::async with std::launch::async if multithreading is disabled.
llvm-svn: 248193
2015-09-21 19:12:36 +00:00
Rui Ueyama 997b357ac1 COFF: Run InputFile::parse() in background using std::async().
Previously, InputFile::parse() was run in batch. We construct a list
of all input files and call parse() on each file using parallel_for_each.
That means we cannot start parsing files until we get a complete list
of input files, although InputFile::parse() is safe to call from anywhere.

This patch makes it asynchronous. As soon as we add a file to the symbol
table, we now start parsing the file using std::async().

This change shortens self-hosting time (650 ms) by 28 ms. It's about 4%
improvement.

llvm-svn: 248109
2015-09-20 03:11:16 +00:00
Rui Ueyama 1cce300843 COFF: Change Symbol::Body type from atomic pointer to regular pointer.
I made the field an atomic pointer in hope that we would be able to
parallelize the symbol resolver soon, but that's not going to happen
soon. This patch reverts that change for the sake of readability.

llvm-svn: 248104
2015-09-20 00:00:05 +00:00
Rui Ueyama 0652c59506 COFF: Actually parallelize InputFile::parse().
This is a follow-up patch to r248078.

llvm-svn: 248098
2015-09-19 21:33:26 +00:00
Rui Ueyama 27e9e6540c Remove unused #includes.
llvm-svn: 248081
2015-09-19 02:28:32 +00:00
Rui Ueyama f4d05d7a80 COFF: Parallelize InputFile::parse().
InputFile::parse() can be called in parallel with other calls of
the same function. By doing that, time to self-link improves from
741 ms to 654 ms or 12% faster.

This is probably the last low hanging fruit in terms of parallelism.
Input file parsing and symbol table insertion takes 450 ms in total.
If we want to optimize further, we probably have to parallelize
symbol table insertion using concurrent hashmap or something.
That's doable, but that's not easy, especially if you want to keep
the exact same semantics and linking order. I'm not going to do that
at least soon.

Anyway, compared to r248019 (the change before the first attempt for
parallelism), we achieved 36% performance improvement from 1022 ms
to 654 ms. MSVC linker takes 3.3 seconds to link the same program.
MSVC's ICF feature is very slow for some reason, but even if we
disable the feature, it still takes about 1.2 seconds.
Our number is probably good enough.

llvm-svn: 248078
2015-09-19 01:48:26 +00:00
Rui Ueyama 4151972c22 Enable extra LTO verification only when build type is debug.
llvm-svn: 247956
2015-09-17 22:54:08 +00:00
Rui Ueyama 63dd8766ab COFF: Remove DefinedSymbol::isLive() and markLive(). NFC.
Basically the concept of "liveness" is for sections (or chunks in LLD
terminology) and not for symbols. Symbols are always available or live,
or otherwise it indicates a link failure.

Previously, we had isLive() and markLive() methods for DefinedSymbol.
They are confusing methods. What they actually did is to act as a proxy
to backing section chunks. We can simplify eliminate these methods
and call section chunk's methods directly.

llvm-svn: 247869
2015-09-16 23:55:52 +00:00
Duncan P. N. Exon Smith a11f81973a LTO: Adjust to LLVM r247735
Perhaps lld wants to disable the verifier sometimes during COFF LTO, but
for now just match behaviour from before r247735.

llvm-svn: 247736
2015-09-15 23:06:16 +00:00
Rafael Espindola fb497d79f6 Remove an allocator which was used for just one allocation.
llvm-svn: 246662
2015-09-02 16:07:11 +00:00
Peter Collingbourne df5783b7a5 COFF: Implement parallel LTO code generation.
This is exposed via a new flag /opt:lldltojobs=N, where N is the number of
code generation threads.

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

llvm-svn: 246342
2015-08-28 22:16:09 +00:00
Peter Collingbourne 0bb50d92b6 COFF: Update for LTO API change.
llvm-svn: 245892
2015-08-24 22:22:58 +00:00
Rui Ueyama d2d2360222 COFF: Fix /lldmap option.
isLive returns false if it's not COMDAT, so check for that condition.

llvm-svn: 245676
2015-08-21 07:01:08 +00:00
Peter Collingbourne 526ff15546 COFF: Introduce flag /opt:lldlto=N for controlling LTO optimization level.
Differential Revision: http://reviews.llvm.org/D12024

llvm-svn: 245027
2015-08-14 04:47:07 +00:00
Rafael Espindola b835ae8e4a Port the error functions from ELF to COFF.
This has a few advantages

* Less C++ code (about 300 lines less).
* Less machine code (about 14 KB of text on a linux x86_64 build).
* It is more debugger friendly. Just set a breakpoint on the exit function and
  you get the complete lld stack trace of when the error was found.
* It is a more robust API. The errors are handled early and we don't get a
  std::error_code hot potato being passed around.
* In most cases the error function in a better position to print diagnostics
  (it has more context).

llvm-svn: 244215
2015-08-06 14:58:50 +00:00
Rui Ueyama 506f6d1ae1 COFF: _tls_used is __tls_used on x86.
llvm-svn: 243495
2015-07-28 22:56:02 +00:00
Rui Ueyama 5e706b3ee3 COFF: Use short identifiers. NFC.
llvm-svn: 243229
2015-07-25 21:54:50 +00:00