Commit Graph

281 Commits

Author SHA1 Message Date
Reid Kleckner 7668182e44 [COFF] Don't let /def override /out filename
Summary:
This also delays setting the output filename based on the first input
argument until after processing /def.

Fixes PR32354

Reviewers: ruiu, pcc

Subscribers: llvm-commits

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

llvm-svn: 298327
2017-03-21 00:12:51 +00:00
Peter Collingbourne db7447deed COFF: Do not create empty temporary archives for /msvclto.
The MSVC linker doesn't support them.

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

llvm-svn: 298034
2017-03-17 02:04:22 +00:00
Rui Ueyama e1bf1365d7 Do not pass archive files containing non-native object files.
The MSVC linker doesn't like archive files containing non-native object
files.

When we are doing an LTO build, we may create archive files containing
both LLVM bitcode files and native object files. For example, if a
project contains assembly files and C++ files, we create native object
files for the assembly files and LLVM bitcode files for the C++ files.

With the /msvclto option, LLD passes archive files to the MSVC linker.
Previously, we didn't pass archive files if they contain at least one
bitcode files. That wasn't correct because the native object files that
weren't passed to the MSVC linker may be needed to complete linking.

In this patch, we create new temporary archive files to strip bitcode
files.

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

llvm-svn: 297997
2017-03-16 21:19:36 +00:00
Zachary Turner 337e884643 Fix lld pdb test.
It was assuming various things about the PDB like file size
which are going to be too high maintenance to maintain in
a test.

llvm-svn: 297908
2017-03-15 22:58:10 +00:00
Rui Ueyama 7d271ae21d Fix wrong assertion failure.
Previously, if you have foo=bar in a definition file, this assertion
could fire because when symbols are read from file they could be mangled.
It seems that due to historical reasons underscore mangling scheme is
really ad-hoc, and I cannot find a clean way to handle this. I had
to just de-mangle symbols to search again.

llvm-svn: 297357
2017-03-09 04:47:33 +00:00
Rui Ueyama 9accea6feb Pass archive files to link.exe if they contain at least one native object file.
Some archive files created during chromium build contains both BC
and native files. If that's the case, we want to pass the archive
file to link.exe. Otherwise, the MSVC linker would complain that
there's an unresolved symbol in a given set of files.

I cannot explain why link.exe doesn't complain about the presence
of bitcode files in this case, but it seems link.exe doesn't touch BC.

llvm-svn: 297229
2017-03-07 21:26:10 +00:00
Rui Ueyama e0341db179 Do not pass archive files containing bitcode files to the MSVC Linker.
If /msvclto is specified, we compile bitcode files and pass it to the
MSVC linker, stripping all bitcode files. We haven't stripped archive
files, because I was thinking that the MSVC linker wouldn't touch files
in archive files. When we pass an object file to link.exe, all symbols
have been resolved already, so link.exe shoulnd't need any of the files
in archives.

It turns out that even though link.exe doesn't need to do that, it
seems to try to read each file in all archives. And if there's a non-
COFF file in an archive, it exists with an error message. So we need
to remove archives from the command line too.

llvm-svn: 297191
2017-03-07 19:45:53 +00:00
Bob Haarman 851b1f866b [COFF] added test for thinlto
Summary: Creates bitcode files suitable for use with ThinLTO, then checks that the linker can build an executable from them.

Reviewers: ruiu, pcc

Reviewed By: pcc

Subscribers: mehdi_amini, Prazek, llvm-commits

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

llvm-svn: 296042
2017-02-23 23:42:24 +00:00
Rui Ueyama 85d54b050e Fix /msvclto.
Previously, bitcode files in library paths were passed to the MSVC linker.
This patch strips them.

llvm-svn: 295913
2017-02-23 00:26:42 +00:00
Rui Ueyama 99861f4730 Attempt to placate MSVC buildbot.
I really do not understand what is going on on some Windows buildbots,
but FileCheck command on some buildbot behaves like long lines were
truncated. I'll try to find a cause of the issue, but let me relax the
test so that they'll succeed on all buildbots.

llvm-svn: 295798
2017-02-22 00:32: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
Bob Haarman c87da86707 added missing "savetemps/" in test/COFF/savetemps.ll
llvm-svn: 294664
2017-02-09 23:31:47 +00:00
Bob Haarman 751f169657 list paths explicitly instead of using * in
test/COFF/savetemps.ll

Reviewers: dyung, ruiu

Reviewed By: dyung, ruiu

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

llvm-svn: 294643
2017-02-09 22:52:21 +00:00
Rui Ueyama 7a6f391451 Attempt to fix lld-x86_64-win7 bot.
The test is failing on the bot because "/subsystem:console" was
truncated for some reason. I don't know why that is happening on
that machine (it is not reproducible on my Windows machine).
In this patch, I'm trying to tame it by making the output shorter.

llvm-svn: 294502
2017-02-08 19:22:34 +00:00
Bob Haarman 69b196dd91 [COFF] added support for /lldsavetemps
Summary: This adds an option to save temporary files generated during link-time optimization. This can be useful for debugging.

Reviewers: ruiu, pcc

Reviewed By: ruiu, pcc

Subscribers: mehdi_amini

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

llvm-svn: 294498
2017-02-08 18:36:41 +00:00
Saleem Abdulrasool b6394287e2 COFF: ensure that we handle bad arguments
The parameter to /debugtype is user provided and may be invalid.  Ensure
that we gracefully handle bad input.

llvm-svn: 294280
2017-02-07 04:28:05 +00:00
Saleem Abdulrasool 0acd6dd6ce COFF: prevent nullptr dereference
If `/debugtypes` is used to omit the codeview information, we would not
have constructed the debug info codeview record which is used to tie the
PDB to the binary.  In such a case, rub out the GUID and Age fields.

llvm-svn: 294279
2017-02-07 04:28:02 +00:00
Rui Ueyama a5ed3226d6 Attempt to fix a flakey test.
I believe that the test is flakey because the order of stdout
and stderr is not deterministic.

llvm-svn: 294238
2017-02-06 21:11:33 +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
Rui Ueyama eb1ad400f9 Print alignment in decimal instead of hexadecimal.
Previously, we were printing out something like this for
sections/symbols with alignment 16

  0000000000201000 0000000000000182    10 .data

which I think confusing. I think printing it in decimal is better.

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

llvm-svn: 293685
2017-01-31 20:42:34 +00:00
Bob Haarman 25c731874d COFF: add test for /INCLUDE directives specified in bitcode
Summary: MSVC allows linker options to be specified in source code. One of these is the /INCLUDE directive, which specifies that a symbol must be added to the symbol table, even if it otherwise wouldn't be. Existing tests cover the case where the linker is given an object file with an /INCLUDE directive, but we also need to cover the case where /INCLUDE is specified in a bitcode file (as would happen when using LTO). This new test covers that case.

Reviewers: pcc, ruiu

Reviewed By: ruiu

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

llvm-svn: 293107
2017-01-25 23:07:40 +00:00
Zachary Turner 18de36bc90 Fix failing lld pdb test.
llvm-svn: 292673
2017-01-20 22:57:24 +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 5289662e4a PDB: Merge type info.
This patch is to merge type info in multiple .debug$T sections.

One mystery that needs to be solved is that it is not clear how
the MSVC linker uses TPI and IPI streams. Both streams contain
type info, and it is not obvious what kind of record should go
which.

dumppdb command in microsoft-pdb repository prints out IPI stream
contents as "IDs" and TPI stream as "TYPES", but looks like the tool
don't really care about which stream type recrods were read from.

For now, in this patch, I emit all type records to TPI stream.
It might just work with other tools. If not, we need to investigate
it more.

llvm-svn: 291739
2017-01-12 03:09:25 +00:00
Rui Ueyama 0697ae2ad9 Revert r291526: Re-enable /linkrepro test on Windows.
This broke the following two bots:

lld-x86_64-win7: the test failed because a diff command is not available
on that bot. That's a configuration error of the bot and will be fixed soon.

llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast: "tar xf" failed on that
bot. I suspect that it is due to the maximum path limitation on Windows.
A build directory contains a buildbot name, so it's longer than usual on
that machine. On Windows, many filesystem operations fail if a path is
longer than 255 characters. I'll try to address that in another patch.

llvm-svn: 291527
2017-01-10 02:08:37 +00:00
Rui Ueyama e98516ff99 Re-enable /linkrepro test on Windows.
I think generated tar files are more compatible with old tar commands
because of r291494 and r291340, so I want to enable this test on buildbots.

llvm-svn: 291526
2017-01-10 01:37:37 +00:00
Simon Pilgrim bb643ab5bc Attempt to fix windows buildbot
llvm-svn: 291348
2017-01-07 15:44:27 +00:00
Rui Ueyama 7f1f912794 Use TarWriter to create tar archives instead of cpio.
This is how we use TarWriter in LLD. Now LLD does not append
a file extension, so you need to pass `--reproduce foo.tar`
instead of `--reproduce foo`.

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

llvm-svn: 291210
2017-01-06 02:33:53 +00:00
Saleem Abdulrasool 8d29e62de7 test: loosen a test for the time being
The GUID should match between the RSDS and the PDB.  This should repair
the build bots, though we should be ensuring that the GUIDs match.
Unfortunately, different build bots seem to be getting different GUIDs.

llvm-svn: 290981
2017-01-04 18:17:28 +00:00
Saleem Abdulrasool df8a13b257 COFF: tie the execute and the PDB together
The PDB GUID, Age, and version are tied together by the RSDS record in
the binary.  Pass along the BuildId information into the createPDB to
allow us to tie the binary and the PDB together.

llvm-svn: 290975
2017-01-04 17:56:54 +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 c4e9482164 COFF: We no longer require lib.exe to test DLL exports.
llvm-svn: 289745
2016-12-15 00:11:17 +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
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
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
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 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 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 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
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 569851f1d6 Partially revert r287009: Remove trailing whitespace.
This reverts part of r287009 because I accidentally changed binary files.

llvm-svn: 287010
2016-11-15 19:09:13 +00:00
Rui Ueyama d7cfb1b6dd Remove trailing whitespace.
llvm-svn: 287009
2016-11-15 19:07:17 +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
Rui Ueyama ec2595d2e1 Attempt to fix freaky bot.
I don't really understand what is failing on lld-x86_64-darwin13 bot,
but this patch should at least reduces the number of moving parts.

llvm-svn: 286876
2016-11-14 19:50:10 +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