Commit Graph

547 Commits

Author SHA1 Message Date
Peter Collingbourne c1ded7dcef COFF: Cache the result of library searches.
File system operations were still dominating the profile on Windows. In this
case we were spending a significant amount of our time repeatedly searching
for libraries as a result of processing linker directives. Address this
by caching whether we have already found a library with a given name. For
chrome_child.dll:

Before: 10.53s
After: 6.88s

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

llvm-svn: 289915
2016-12-16 03:45:59 +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
Saleem Abdulrasool f1af26ddf2 build: add support for standalone lld build
Enable building lld as a standalone project. This is motivated by the desire to
package lld for inclusion in a linux distribution. This allows building lld
against an existing paired llvm installation. Now that lld is usable on x86_64,
it makes sense to revive this configuration to allow distributions to package
it.

llvm-svn: 289421
2016-12-12 05:47:40 +00:00
Peter Collingbourne 4b5a7ac831 COFF: Remove an unused mutex declaration.
llvm-svn: 289415
2016-12-12 03:16:18 +00:00
Peter Collingbourne 8155dfa8f3 COFF: Use a DenseSet instead of a map to atomic_flag to track which archive members have been read.
Differential Revision: https://reviews.llvm.org/D27667

llvm-svn: 289414
2016-12-12 03:16:14 +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 99111287fc COFF: Use a bit in SymbolBody to track which symbols are written to the symbol table.
Using a set here caused us to take about 1 second longer to write the symbol
table when linking chrome_child.dll. With this I consistently get better
performance on Windows with the new symbol table.

Before r289280 and with r289183 reverted (median of 5 runs): 17.65s
After this change: 17.33s

On Linux things look even better:

Before: 10.700480444s
After: 5.735681610s

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

llvm-svn: 289408
2016-12-11 22:15:20 +00:00
Rui Ueyama 327705d17d Create a TPI stream only when /debugpdb is given.
Adding type records to TPI stream is too time consuming.
It is reported that linking chrome_child.dll took 5 minutes.

llvm-svn: 289330
2016-12-10 17:23:23 +00:00
Ismail Donmez 85588fa2b0 Fix shared library build
llvm-svn: 289320
2016-12-10 09:29:47 +00:00
Peter Collingbourne 6baa5d276d COFF: Fix test failure on Windows.
llvm-svn: 289289
2016-12-09 23:34:49 +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
Hans Wennborg 1818e65aad COFF: Support both /lldmap and /lldmap:<file>
The former option bases the filename on the output name, e.g. if the
link output is a.exe, the map will be written to a.map. This matches the
behaviour of link.exe's /MAP option and is useful for creating a map
file of each executable when building a large project.

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

llvm-svn: 289271
2016-12-09 20:54:44 +00:00
Peter Collingbourne fa7f393714 COFF: Move a call to toString() out of the hot path.
Profiling revealed that we were spending 5% of our time linking
chrome_child.dll just in this call to toString().

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

llvm-svn: 289270
2016-12-09 20:51:33 +00:00
Rui Ueyama 26186c7e0f Add type records to TPI stream.
I don't think the data I add to a TPI stream in this patch is correct,
but at least it can be displayed using llvm-pdbdump. Until I add more
streams to a PDB file, I'm not able to know whether the data will be
accepted by MSVC tools or not.

llvm-svn: 289183
2016-12-09 04:46:54 +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 968468033c Fix -Wunused-private-field.
llvm-svn: 289112
2016-12-08 21:49:18 +00:00
Rui Ueyama 8d433d71f5 COFF: Use a string saver in Memory.h in Driver.
llvm-svn: 289104
2016-12-08 21:27:09 +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 7fed58cd9f Start using make() in COFF (with a smaller change.)
llvm-svn: 289089
2016-12-08 19:10:28 +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 332e02a164 Fix Windows buildbots.
clang-format-diff sorted these #include's in the asciibetical order,
but they need to be in this order.

llvm-svn: 288995
2016-12-07 23:24:32 +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
Rui Ueyama 3a618e5606 Port parallel ICF to COFF.
LLD used to take 11.73 seconds to link Clang. Now it is 6.94 seconds.
MSVC link takes 83.02 seconds. Note that ICF is enabled by default on
Windows, so a low latency ICF is more important than in ELF.

llvm-svn: 288487
2016-12-02 08:03:58 +00:00
Rui Ueyama 27498b5dd5 Fix a bug in ICF involving COFF associative sections.
Associative sections are sections that need to be linked if their associated
sections are linked. Associative sections are used to append auxiliary data
such as debug info.

Previously, we compared all associative sections when comparing two comdat
sections. Because usually assocative sections are not mergeable sections,
we missed a lot of mergeable sections. MSVC linker doesn't seem to check
the identity of associative sections.

This patch makes LLD to ignore associative sections when doing ICF.

llvm-svn: 288483
2016-12-02 07:46:12 +00:00
Rui Ueyama c5cb737584 Dump Codeview type information correctly.
llvm-svn: 288298
2016-12-01 01:22:48 +00:00
Rui Ueyama bf4ddeb97c Style fix.
llvm-svn: 288113
2016-11-29 04:22:57 +00:00
Rui Ueyama c910bc7e19 Simplify "missing argument" error message.
llvm-svn: 288112
2016-11-29 04:17:31 +00:00
Rui Ueyama e5e407beb4 Add comments.
llvm-svn: 288111
2016-11-29 04:17:30 +00:00
Rui Ueyama bd2a812ff0 Print error message header in red.
llvm-svn: 288110
2016-11-29 04:09:08 +00:00
Rui Ueyama bf9523f549 [COFF] Add DebugInfoCodeView dependency
rL287555 introduces a link error when building with BUILD_SHARED_LIBS:

  undefined reference to llvm::codeview::CVSymbolDumper::dump(),
  and more...

The functions are available in libDebugInfoCodeView, from LLVM.

Patch by Visoiu Mistrih Francis!

llvm-svn: 287837
2016-11-23 22:58:25 +00:00
Rui Ueyama 24625fd9b2 Dump not only type records but symbol records.
llvm-svn: 287723
2016-11-22 23:51:34 +00:00
Rui Ueyama be939b3ff6 Do plumbing work for CodeView debug info.
Previously, we discarded .debug$ sections. This patch adds them to
files so that PDB.cpp can access them.

This patch also adds a debug option, /dumppdb, to dump debug info
fed to createPDB so that we can verify that valid data has been passed.

llvm-svn: 287555
2016-11-21 17:22:35 +00:00
Chris Bieneman aeb30257c5 [CMake] NFC. Updating CMake dependency specifications
This patch updates a couple places where add_dependencies was being explicitly called to add dependencies on intrinsics_gen to instead use the DEPENDS named parameter. This cleanup is needed for a patch I'm working on to add a dependency debugging mode to the build system.

llvm-svn: 287205
2016-11-17 04:36:35 +00:00
Rui Ueyama c91f716643 PDB: Add "* Linker *" module.
The added module contains nothing, but it is still useful as a test
to ensure that we are emitting modules that can be read back.

llvm-svn: 287071
2016-11-16 01:10:46 +00:00
Rui Ueyama c3dcf99441 [COFF] Fix manifest resource file creation on Windows.
createManifestRes was generating a MemoryBuffer from a TemporaryFile,
keeping the data but removing the file, before passing the file path
to CVTRES.exe, leading to the following error:

  CVTRES : fatal error CVT1101: cannot open 'C:\Users\user\AppData\
  Local\Temp\lld-output-resource-bfee19.res' for reading

With this, we instead create a new TemporaryFile before passing it to cvtres.

Patch from Rudy Pons!

llvm-svn: 287034
2016-11-15 21:25:20 +00:00
Rui Ueyama f83806a8ad Identify object files compiled with cl.exe /GL.
Object files compiled with cl.exe /GL contain intermediate code for LTO.
We can't (and don't want to) interpret such code, but we should print
out a user-friendly error message.

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

llvm-svn: 286921
2016-11-15 01:01:51 +00:00
Vitaly Buka 4cf112c6f2 Fix heap-use-after-free coff::createPDB
Summary:
getInputSections returns std::vector by value and ArrayRef
pointed to destroyed temporarily.

Reviewers: ruiu

Subscribers: llvm-commits

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

llvm-svn: 286880
2016-11-14 20:21:41 +00:00
Rui Ueyama 09e0b5f2c9 Emit Section Contributions.
Differential Revision: https://reviews.llvm.org/D26211

llvm-svn: 286684
2016-11-12 00:00:51 +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
Davide Italiano c520e18ce0 [lld/COFF] Don't round alignment if it's already a power-of-two.
This matches link.exe behaviour.

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

llvm-svn: 286553
2016-11-11 02:53:48 +00:00
Reid Kleckner f47c3bb8db Make the .idata$4 and .idata$5 import lib sections 8 bytes on x64
The MSVC linker relies on this invariant to produce a valid import
table. More ASan tests pass in a stage 2 build now. They still fail when
using LLD since there are no PDBs for the dynamic ASan runtime.

llvm-svn: 286499
2016-11-10 20:38:58 +00:00
Rui Ueyama 6294a240dc Fix -Wcast-qual warnings.
llvm-svn: 286001
2016-11-04 17:41:29 +00:00
Rui Ueyama 20df4ecf4f Re-commit r285607: Emit Section Map stream."
Removed some test fields that overspecified test conditions.

llvm-svn: 285638
2016-10-31 21:09:21 +00:00
Rui Ueyama e7b54c2ea5 Revert r285607: Emit Section Map stream.
That change broke buildbots.

llvm-svn: 285618
2016-10-31 18:50:13 +00:00
Rui Ueyama 86a1ef388b Emit Section Map stream.
This is how we use DbiStreamBuilder::addSectionMap.

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

llvm-svn: 285607
2016-10-31 17:40:40 +00:00
Chris Bieneman 62113e854a [CMake] Add missing dependency on intrinsics_gen
COFF/InputFiles.h includes LTOModule.h which transitively relies on Attributes.inc.

llvm-svn: 284444
2016-10-18 00:50:39 +00:00