Commit Graph

918 Commits

Author SHA1 Message Date
Rui Ueyama af7242a385 Use reinterpret_cast<> instead of C-style cast. NFC.
It is currently interpreted as reinterpret_cast<>. Make it explicit.

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

llvm-svn: 325033
2018-02-13 18:11:42 +00:00
Sam Clegg 38f52b2eb8 Check that Symbol types are trivially destructible
This adds an extra level of static safety to our use of placement
new to allocate Symbol types.  It prevents the accidental addition
on a non-trivially-destructible member that could allocate and
leak memory.

From the spec: Storage occupied by trivially destructible objects
may be reused without calling the destructor.

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

llvm-svn: 325025
2018-02-13 17:32:31 +00:00
Benjamin Kramer 6400a97418 [COFF] LTO does not require a disassembler.
llvm-svn: 324355
2018-02-06 15:42:41 +00:00
Reid Kleckner af2f7da74c [COFF] Add minimal support for /guard:cf
Summary:
This patch adds some initial support for Windows control flow guard. At
the end of the day, the linker needs to synthesize a table of RVAs very
similar to the structured exception handler table (/safeseh).

Both /safeseh and /guard:cf take sections of symbol table indices
(.sxdata and .gfids$y) and turn them into RVA tables referenced by the
load config struct in the CRT through special symbols.

Reviewers: ruiu, amccarth

Subscribers: llvm-commits

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

llvm-svn: 324306
2018-02-06 01:58:26 +00:00
Bob Haarman 5ec448516d [COFF] make /incremental control overwriting unchanged import libraries
Summary:
r323164 made lld-link not overwrite import libraries when their
contents haven't changed. MSVC's link.exe does this only when
performing incremental linking. This change makes lld-link's import
library overwriting similarly dependent on whether or not incremental
linking is being performed. This is controlled by the /incremental or
/incremental:no options. In addition, /opt:icf, /opt:ref, and /order
turn off /incremental and issue a warning if /incremental was
specified on the command line.

Reviewers: rnk, ruiu, zturner

Reviewed By: ruiu

Subscribers: llvm-commits

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

llvm-svn: 323930
2018-01-31 23:44:00 +00:00
Colden Cullen b9b6ed9ae6 [LLD][PDB] Implement FIXME: Warn on missing TypeServer PDB rather than error
Summary: Instead of fatal-ing out when missing a type server PDB, insead warn and cache the miss.

Reviewers: rnk, zturner

Reviewed By: rnk

Subscribers: llvm-commits

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

llvm-svn: 323893
2018-01-31 17:48:04 +00:00
Martin Storsjo cf47b046f9 [COFF] Remove the temporary file if not updating the import library
Differential Revision: https://reviews.llvm.org/D42621

llvm-svn: 323725
2018-01-30 07:26:01 +00:00
Rui Ueyama b6d3a93594 Warn on nonexistent comdat sections in an /order file.
I didn't implement the feature in the original patch because I didn't
come up with an idea to do that easily and efficiently. Turned out that
that is actually easy to implement.

In this patch, we collect comdat sections before gc is run and warn on
nonexistent symbols in an order file.

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

llvm-svn: 323699
2018-01-29 21:50:53 +00:00
Rui Ueyama d73479ba12 Remove trailing space.
llvm-svn: 323682
2018-01-29 19:55:55 +00:00
Shoaib Meenai 34a1101b06 [COFF] Update comment to reflect link.exe behavior. NFC
In my experimentation with link.exe from both VS 2015 and 2017, it
always produces images with truncated section names. Update the comment
accordingly.

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

llvm-svn: 323598
2018-01-27 18:17:08 +00:00
Rui Ueyama 57175aa1e9 Add the /order option.
With the /order option, you can give an order file. An order file
contains symbol names, one per line, and the linker places comdat
sections in that given order. The option is used often to optimize
an output binary for (in particular, startup) speed by improving
locality.

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

llvm-svn: 323579
2018-01-27 00:34:46 +00:00
Bob Haarman 4ce341ffb6 [COFF] don't replace import library if contents are unchanged
Summary:
This detects when an import library is about to be overwritten with a
newly built one with the same contents, and keeps the old library
instead. The use case for this is to avoid needlessly rebuilding
targets that depend on the import library in build systems that rely
on timestamps to determine whether a target requires rebuilding.

This feature was requested in PR35917.

Reviewers: rnk, ruiu, zturner, pcc

Reviewed By: ruiu

Subscribers: llvm-commits

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

llvm-svn: 323164
2018-01-23 00:36:42 +00:00
Martin Storsjo 3b611fa93f [COFF] Keep the underscore on exported decorated stdcall functions in MSVC mode
This fixes PR35733.

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

llvm-svn: 323036
2018-01-20 11:44:42 +00:00
Zachary Turner 1bc2ce6b9b Speed up iteration of CodeView record streams.
There's some abstraction overhead in the underlying
mechanisms that were being used, and it was leading to an
abundance of small but not-free copies being made.  This
showed up on a profile.  Eliminating this and going back to
a low-level byte-based implementation speeds up lld with
/DEBUG between 10 and 15%.

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

llvm-svn: 322871
2018-01-18 18:35:01 +00:00
Zachary Turner 727f153b6f [coff] Print detailed timing information with /TIME.
The classes used to print and update time information are in
common, so other linkers could use this as well if desired.

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

llvm-svn: 322736
2018-01-17 19:16:26 +00:00
Rui Ueyama 2c95e798a0 [LLD][COFF] Report error when file will exceed Windows maximum image size (4GB)
Patch by Colden Cullen.

Currently, when a large PE (>4 GiB) is to be produced, a crash occurs
because:

1. Calling setOffset with a number greater than UINT32_MAX causes the
   PointerToRawData to overflow

2. When adding the symbol table to the end of the file, the last section's
   offset was used to calculate file size. Because this had overflowed,
   this number was too low, and the file created would not be large enough.
   This lead to the actual crash I saw, which was a buffer overrun.

This change:

1. Adds comment to setOffset, clarifying that overflow can occur, but it's
   somewhat safe because the error will be handled elsewhere

2. Adds file size check after all output data has been created This matches
   the MS link.exe error, which looks prints as: "LINK : fatal error
   LNK1248: image size (10000EFC9) exceeds maximum allowable size
   (FFFFFFFF)"

3. Changes calculate of the symbol table offset to just use the existing
   FileSize. This should match the previous calculations, but doesn't rely
   on the use of a u32 that can overflow.

4. Removes trivial usage of a magic number that bugged me while I was
   debugging the issue

I'm not sure how to add a test for this outside of adding 4GB of object
files to the repo. If there's an easier way, let me know and I'll be
happy to add a test.

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

llvm-svn: 322605
2018-01-17 01:08:02 +00:00
Pavel Labath a006baa620 Attempt to fix FreeBSD build broken by the previous commit
The compiler could not find the conversion from
unique_ptr<WritableMemoryBuffer> to unique_ptr<MemoryBuffer>. This will
hopefully help it along.

llvm-svn: 322365
2018-01-12 10:09:10 +00:00
Pavel Labath 1c1e24ad96 [lld/COFF] Use WritableMemoryBuffer for creating the manifest
This avoids the need for const_casting the memory buffer contents in
order to write to it.

NFCI.

llvm-svn: 322363
2018-01-12 09:48:41 +00:00
Rui Ueyama 5fa0d6e4a2 [COFF] Process /EXPORT option in fastpath
Patch by Takuto Ikuta.

This patch reduces lld link time of chromium's blink_core.dll in
component build.

Total size of input argument in .directives become nearly 300MB in the
build and almost all its content are /EXPORT.

To reduce time of parsing too many /EXPORT option in the build, I
introduce fastpath for /EXPORT in ArgParser::parseDirectives.

On my desktop machine, 4 times stats of the link time are like below.
Improved around 20%.

This patch
TotalSeconds : 8.6217627
TotalSeconds : 8.5402175
TotalSeconds : 8.6855853
TotalSeconds : 8.3624441
Ave : 8.5525024

master
TotalSeconds : 10.9975031
TotalSeconds : 11.3409428
TotalSeconds : 10.6332897
TotalSeconds : 10.7650687
Ave : 10.934201075

llvm-svn: 322117
2018-01-09 20:36:42 +00:00
Shoaib Meenai 7e3e28f968 [COFF] Delete CanExitEarly
It was being set but never used, and its value is only ever needed
locally in lld::coff::link.

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

llvm-svn: 322026
2018-01-08 21:14:51 +00:00
Shoaib Meenai fd3e4b0ea1 [COFF] Initalize ErrorHandler with CanExitEarly value
Previously, the COFF driver would call exit(1) from the
ErrorHandler in the case of a link error, even if
CanExitEarly=false was specified. Now it initializes
the ErrorHandler in the same way that the ELF driver does.

Patch by Andrew Kelley.

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

llvm-svn: 321983
2018-01-08 05:58:36 +00:00
Zachary Turner 9e52e50ac0 Fix unhandled switch values.
llvm-svn: 321885
2018-01-05 19:28:39 +00:00
Zachary Turner 6047858270 [PDB] Correctly link S_FILESTATIC records.
This is not a record type that clang currently generates,
but it is a record that is encountered in object files generated
by cl.  This record is unusual in that it refers directly to
the string table instead of indirectly to the string table via
the FileChecksums table.  Because of this, it was previously
overlooked and we weren't remapping the string indices at all.
This would lead to crashes in MSVC when trying to display a
variable whose debug info involved an S_FILESTATIC.

Original bug report by Alexander Ganea

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

llvm-svn: 321883
2018-01-05 19:12:40 +00:00
Rui Ueyama a63eed0f80 Do not parse the same /export string more than once.
Differential Revision: https://reviews.llvm.org/D41607

llvm-svn: 321513
2017-12-28 07:41:19 +00:00
Bob Haarman e90ac016e7 [COFF] support /ignore:4217
Summary:
lld-link accepts link.exe's /ignore option, but used to ignore
it. This can lead to semantic differences when warnings are treated as
fatal errors. One such case is when we resolve an __imp_ symbol to a
local definition. We emit a warning in that case, which /wx turns into
a fatal. This change makes lld-link accept /ignore:4217 to suppress
that warning, so that code that links with link.exe /wx /ignore:4217
links with lld-link, too.

Fixes PR35762.

Reviewers: rnk, ruiu

Reviewed By: ruiu

Subscribers: llvm-commits

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

llvm-svn: 321512
2017-12-28 07:02:13 +00:00
Rui Ueyama 130eb04689 [COFF] Do not parse args twice if no rsp files exists
Patch by Takuto Ikuta.

This patch reduces link time of chromium's blink_core.dll in component
build. Total size of input argument in .directives become nearly 300MB
in the build and no rsp file is used. Speedup link by skipping duplicate
parsing.

On my desktop machine, 4 times stats are like below. Improved around 15%.

This patch
TotalSeconds : 18.408538
TotalSeconds : 17.2996744
TotalSeconds : 17.1053862
TotalSeconds : 17.809777
avg: 17.6558439

master
TotalSeconds : 20.9290504
TotalSeconds : 19.9158213
TotalSeconds : 21.0643515
TotalSeconds : 20.8775831
avg: 20.696701575

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

llvm-svn: 321470
2017-12-27 06:08:10 +00:00
Martin Storsjo 6528fb8691 [COFF] Don't set the thumb bit in address table entries for data symbols
The thumb bit should only be set for executable code.

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

llvm-svn: 321149
2017-12-20 06:50:45 +00:00
Shoaib Meenai a1f6fba4d1 [COFF] Clean up debug option handling
/debug and /debug:dwarf are orthogonal. An object file can contain both
CodeView and DWARF debug info, so the combination of /debug:dwarf and
/debug should generate both DWARF and a PDB, rather than /debug:dwarf
always suppressing PDB creation.

/nopdb is now redundant and can be removed. /debug /nopdb was previously
used to support DWARF, but specifying /debug:dwarf is entirely
equivalent to that combination now.

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

llvm-svn: 320896
2017-12-16 00:23:24 +00:00
Shoaib Meenai c4fdbca604 [COFF] Update an outdated comment. NFC
This comment dates from when LLD didn't produce actual PDBs, and is very
outdated now.

llvm-svn: 320894
2017-12-15 23:52:46 +00:00
Shoaib Meenai 111db7945d [COFF] Simplify hasArgs calls. NFC
We can just pass multiple options to hasArgs (which will check for any
of those options being present) instead of calling it multiple times.

llvm-svn: 320892
2017-12-15 23:51:14 +00:00
Martin Storsjo a1e9b6e3d2 [COFF] Set the IMAGE_DLL_CHARACTERISTICS_NO_SEH flag automatically
This seems to match how link.exe sets it.

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

llvm-svn: 320860
2017-12-15 20:53:03 +00:00
Shoaib Meenai d0bd40294d [COFF] Warn for locally imported symbols
Locally imported symbols are a very surprising linker feature. link.exe
warns for them, and we should warn too.

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

llvm-svn: 320792
2017-12-15 07:49:21 +00:00
Sam Clegg ea244bf89b Fix -Wreorder warning
Subscribers: aheejin, llvm-commits

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

llvm-svn: 320741
2017-12-14 21:09:31 +00:00
Hans Wennborg dcb2f44424 Fix a -Wreorder warning
llvm-svn: 320738
2017-12-14 19:51:18 +00:00
Zachary Turner 0d07a8e948 [COFF] Teach LLD to use the COFF .debug$H section.
This adds the /DEBUG:GHASH option to LLD which will look for
the existence of .debug$H sections in linker inputs and use them
to accelerate type merging.  The clang-cl side has already been
added, so this completes the work necessary to begin experimenting
with this feature.

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

llvm-svn: 320719
2017-12-14 18:07:04 +00:00
Martin Storsjo 94d72b89d6 [COFF] Error out if 20 bit thumb branches are out of range
This is similar to what was added in SVN r277838 for 24 bit
branch instructions.

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

llvm-svn: 320677
2017-12-14 08:56:36 +00:00
Martin Storsjo 9603b8e3f5 [COFF] Sort .pdata for arm64
This works for linking the output from the MSVC compiler.
The pdata entries for arm64 seem to be 8 bytes in the same
(or at least similar) form to arm.

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

llvm-svn: 320676
2017-12-14 08:56:29 +00:00
Martin Storsjo 6ea167cc43 [COFF] Disallow -dynamicbase:no for arm and arm64
This matches what MSVC link.exe does.

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

llvm-svn: 320517
2017-12-12 19:39:13 +00:00
Martin Storsjo 2b964108a0 [COFF] Don't error out on undefined references to __enclave_config
This is required for linking the CRT from MSVC 2017 15.5.

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

llvm-svn: 320462
2017-12-12 08:22:29 +00:00
Rui Ueyama 6074e6b094 Remove redundant local variables.
llvm-svn: 320436
2017-12-11 23:19:11 +00:00
Rui Ueyama b59ceb1068 Do not read the same .lib file more than once.
In the following command line,

  lld-link foo/bar.lib /defaultlib:bar.lib

"/defaultlib:bar.lib" should be a nop even if a file with the same
name exists in other library search path.

Fixes https://bugs.llvm.org/show_bug.cgi?id=35476

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

llvm-svn: 320434
2017-12-11 23:09:18 +00:00
Sam Clegg 0fb6faa0be Prefer `ArrayRef` over `const std::vector&`
Differential Revision: https://reviews.llvm.org/D40993

llvm-svn: 320125
2017-12-08 01:09:21 +00:00
Rui Ueyama c0081639cc Remove checkToString functions and use toString instead.
Differential Revision: https://reviews.llvm.org/D40928

llvm-svn: 320005
2017-12-07 03:24:57 +00:00
Shoaib Meenai 9a5161e056 [COFF] Stop lowercasing paths in messages
It's pretty annoying to have LLD lowercase paths in error messages when
cross-compiling from a case-sensitive filesystem, since e.g. if I want
to examine the problematic object file, I have to perform some manual
case correction instead of just being able to copy the path from the
error message.

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

llvm-svn: 319996
2017-12-07 01:21:27 +00:00
Rui Ueyama bdc5150984 Always evaluate the second argument for CHECK() lazily.
This patch is to rename check CHECK and make it a C macro, so that
we can evaluate the second argument lazily.

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

llvm-svn: 319974
2017-12-06 22:08:17 +00:00
Sam Clegg 7e7566323d toString function take a const refs where possible
Differential Revision: https://reviews.llvm.org/D40824

llvm-svn: 319787
2017-12-05 16:50:46 +00:00
Reid Kleckner 3e89b08303 Revert "Merge .xdata into .rdata by default"
This reverts commit r318699, it is breaking 32-bit SEH handlers in
Chromium.

llvm-svn: 319508
2017-12-01 01:04:31 +00:00
Zachary Turner ca6dbf1440 Split TypeTableBuilder into two classes.
llvm-svn: 319456
2017-11-30 18:39:50 +00:00
Rui Ueyama 215286f2a4 [LLD] [COFF] Support ENTRY and SUBSYSTEM in .drectve sections
Adds support for "/ENTRY" and "/SUBSYSTEM" linker options in .drectve
sections. Some Mozilla binaries were using these directives and MSVC
link.exe appears to allow them. No attempt is made to reconcile these
with the options on the command line.

Patch by David Major!

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

llvm-svn: 319356
2017-11-29 20:46:13 +00:00
Zachary Turner 3e3936da93 Make TypeTableBuilder inherit from TypeCollection.
A couple of places in LLD were passing references to
TypeTableCollections around, which makes it hard to change the
implementation at runtime.  However, these cases only needed to
iterate over the types in the collection, and TypeCollection
already provides a handy abstract interface for this purpose.

By implementing this interface, we can get rid of the need to
pass TypeTableBuilder references around, which should allow us
to swap the implementation at runtime in subsequent patches.

llvm-svn: 319345
2017-11-29 19:35:21 +00:00