Commit Graph

348 Commits

Author SHA1 Message Date
Nico Weber f06ae4f3b4 Make lld-link shout at me less.
This makes the output of some flag names in warning messages consistent with
the output of /? and the output of flags in most other diagnostics.

https://reviews.llvm.org/D44307

llvm-svn: 327261
2018-03-12 12:45:40 +00:00
Nico Weber 11a6db3027 [lld-link] For suppressible warnings, print the warning number.
The warning can be suppressed by passing the number to /ignore:.
https://reviews.llvm.org/D44297

llvm-svn: 327257
2018-03-12 12:04:17 +00:00
Nico Weber 0771c604c9 [lld-link] Add support for /ignore:4037.
Fixes PR36657.
https://reviews.llvm.org/D44286

llvm-svn: 327124
2018-03-09 12:41:04 +00:00
Rui Ueyama cdd5fb5087 Report an error if you try to link against .dll instead of .lib.
It is a usage error to feed a .dll file instead of a .dll to COFF linker.
Previously, lld failed with a mysterious error message. Now we reject
it at the driver.

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

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

llvm-svn: 326507
2018-03-01 23:11:30 +00:00
Sam Clegg f187c4d2e5 Consistent use of header file for ICF and MarkLive
Previously wasm used a separate header to declare markLive
and ELF used to declare ICF.  This change makes each backend
consistently declare these in their own headers.

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

llvm-svn: 325631
2018-02-20 22:09:59 +00:00
Sam Clegg 3141ddc58d Consistent (non) use of empty lines in include blocks
The profailing style in lld seem to be to not include such empty lines.
Clang-tidy/clang-format seem to handle this just fine.

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

llvm-svn: 325629
2018-02-20 21:53:18 +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
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
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 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 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
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
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
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 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 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
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
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
Rui Ueyama 2017d52b54 Move Memory.{h,cpp} to Common.
Differential Revision: https://reviews.llvm.org/D40571

llvm-svn: 319221
2017-11-28 20:39:17 +00:00
Peter Collingbourne f874bd67d8 COFF: Emit a COFF symbol table if /debug:dwarf is specified.
This effectively reverts r318548 and r318635 while keeping the
functionality behind the flag and preserving the bug fix from r318548.

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

llvm-svn: 318721
2017-11-21 01:14:14 +00:00
Reid Kleckner 95cc796cf1 Merge .xdata into .rdata by default
Summary: MSVC does this. The user can override it with their own /merge: flag.

Reviewers: ruiu, pcc

Subscribers: llvm-commits

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

llvm-svn: 318699
2017-11-20 21:49:35 +00:00
Peter Collingbourne 5e80bdebd2 COFF: Stop emitting a non-standard COFF symbol table into PEs.
Now that our support for PDB emission is reasonably good, there is
no longer a need to emit a COFF symbol table.

Also fix a bug where we would fail to emit a string table for long
section names if /debug was not specified.

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

llvm-svn: 318548
2017-11-17 19:51:20 +00:00
Reid Kleckner 5883989e51 Remove a std::map and std::set that show up in LLD profiles
For GC roots, add a bit to SymbolBody to ensure that we don't add the
same root twice, and switch to a vector. In addition to being faster,
this may also fix some latent non-determinism. We iterate the GCRoot
list later and it the order should be deterministic.

For fixupExports, we can just use DenseMap. This is a simple string
uniquing task, and we don't iterate the map.

Reviewers: ruiu

Subscribers: llvm-commits

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

llvm-svn: 318072
2017-11-13 18:38:53 +00:00
Reid Kleckner c2dcdd852b Disable GC and ICF when /debug is present
ICF and GC impair debugging, so MSVC disables these optimizations when
/debug is passed. They are still on by default when no PDB is produced.

This change also makes /opt:ref enable ICF, which is consistent with
MSVC: https://msdn.microsoft.com/en-us/library/bxwfs976.aspx

We should consider making /opt:icf fold readonly data in the near
future. LLD used to do this, but we disabled it because it breaks too
many programs. MSVC only does this if the user explicitly passes
/opt:icf.

Reviewers: ruiu, pcc

Subscribers: llvm-commits

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

llvm-svn: 318071
2017-11-13 18:38:25 +00:00
Martin Storsjo 068512dfb9 [MinGW] Output debug info by default, unless the -s parameter is passed
Differential Revision: https://reviews.llvm.org/D39541

llvm-svn: 317376
2017-11-03 22:10:37 +00:00
Rui Ueyama f52496e1e0 Rename SymbolBody -> Symbol
Now that we have only SymbolBody as the symbol class. So, "SymbolBody"
is a bit strange name now. This is a mechanical change generated by

  perl -i -pe s/SymbolBody/Symbol/g $(git grep -l SymbolBody lld/ELF lld/COFF)

nd clang-format-diff.

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

llvm-svn: 317370
2017-11-03 21:21:47 +00:00
Martin Storsjo dc95dbfcab [COFF] Autoexport symbols as data if they don't point to an executable section
This was already taken care of for the output def file.

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

llvm-svn: 317367
2017-11-03 20:58:20 +00:00
Rui Ueyama 616cd99194 [COFF] Merge Symbol and SymbolBody.
llvm-svn: 317007
2017-10-31 16:10:24 +00:00
Bob Haarman b8a59c8aa5 [lld] unified COFF and ELF error handling on new Common/ErrorHandler
Summary:
The COFF linker and the ELF linker have long had similar but separate
Error.h and Error.cpp files to implement error handling. This change
introduces new error handling code in Common/ErrorHandler.h, changes the
COFF and ELF linkers to use it, and removes the old, separate
implementations.

Reviewers: ruiu

Reviewed By: ruiu

Subscribers: smeenai, jyknight, emaste, sdardis, nemanjai, nhaehnle, mgorny, javed.absar, kbarton, fedor.sergeev, llvm-commits

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

llvm-svn: 316624
2017-10-25 22:28:38 +00:00
Peter Collingbourne acc3baaea1 COFF: Don't add /manifest* flags to the response file.
If /manifest:embed is enabled we're already creating a resource file
out of these flags and adding it to the linkrepro, and it doesn't
seem worth being able to repro side-by-side manifests.

Includes a test that covers this commit as well as r315948.

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

llvm-svn: 316547
2017-10-25 05:00:54 +00:00
Shoaib Meenai 59bf362974 [COFF] Clean up boolean flag handling
LLD's handling of boolean flags is suboptimal:
* All boolean flags have a corresponding `:no` flag to turn the flag
  off, and the linker should scan for both the non-suffixed and suffixed
  flags (and the last one should win), but right now it only scans for
  either the suffixed or non-suffixed flag (depending on the default
  flag value).
* The `B` multiclass only allows specifying help text for the suffixed
  (`:no`) flag, but for some flags (e.g. `/appcontainer`) the help text
  should be associated with the non-suffixed flag instead.

Extend the `B` multiclass to have help text for both non-suffixed and
suffixed flag variants, and alter the existing help text accordingly in
some cases. Scan for both the non-suffixed and suffixed variants in the
driver and set config values accordingly.

This should mostly have no behavior change, apart from the added help
text and the modified argument scanning. Some flags are handled slightly
differently now, however; for example, LLD would previously always treat
64-bit images as large address aware, whereas `/largeaddressaware:no` is
now respected for 64-bit images (which is also how link.exe behaves).

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

llvm-svn: 316501
2017-10-24 21:17:16 +00:00
Rui Ueyama 6f4e255219 lld::COFF: better behavior when using as a library
Previously, the COFF driver would call exit(0) when called
as a library.  Now it takes `ExitEarly` option, and if it
is false, it doesn't exit.  So it is now more library-friendly.

Furthermore, link() calls freeArena() before returning, to
clean up resources.

Based on an Andrew Kelley's patch.

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

llvm-svn: 316370
2017-10-23 20:03:32 +00:00
Rui Ueyama a4cf97bc9c Add the --version option.
Differential Revision: https://reviews.llvm.org/D38972

llvm-svn: 316329
2017-10-23 14:57:53 +00:00
Martin Storsjo ddb094ad36 [COFF] Fix exporting of functions starting with underscores, etc
This fixes exporting functions in the following cases:
- functions starting with an underscore in def files
- functions starting with an underscore, via dllexport attributes, for mingw
- fastcall and vectorcall functions when declared undecorated in def files
- vectorcall functions when declared decorated in def files
- stdcall functions when declared decorated in def files for mingw

This still exports the stdcall functions with the wrong name
in the normal msvc/link.exe mode, if declared with decoration in
the def file though (this is not a regression though). Exporting
functions via def files including decoration is not something I
believe is routinely done though, but is tested to try to match
link.exe's behaviour as far as easily possible.

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

llvm-svn: 316317
2017-10-23 09:08:24 +00:00
Martin Storsjo e1f894d59e [COFF] Move MinGW specific functions/classes to a separate file. NFC.
Differential Revision: https://reviews.llvm.org/D39067

llvm-svn: 316178
2017-10-19 19:49:38 +00:00
Martin Storsjo b40ccc1c58 [COFF] Exclude certain static libraries and object files when exporting all symbols
This more or less matches what GNU ld does.

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

llvm-svn: 316148
2017-10-19 06:56:04 +00:00
Peter Collingbourne 9362ac60bc COFF: Add resource files to linkrepro instead of the cvtres object file.
Now that we have our own implementation of cvtres, we can add resource
files directly to the linkrepro.

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

llvm-svn: 315954
2017-10-16 23:15:04 +00:00
Martin Storsjo 6e8acc25d0 [COFF] Fix indentation. NFC.
llvm-svn: 315879
2017-10-15 21:09:46 +00:00
Martin Storsjo e401aa93c8 [COFF] Fix the description of the data type in a comment. NFC.
This was missed when changing data types back and forth during
review.

llvm-svn: 315878
2017-10-15 21:09:43 +00:00
Martin Storsjo 7f71acdcd7 [COFF] Add support for automatically exporting all symbols
GNU ld automatically exports all symbols if no symbols have
been chosen to export via either def files or dllexport attributes.
The same behaviour can also be enabled via the GNU ld option
--export-all-symbols, in case some symbols are marked for export
via a def file or dllexport attribute.

The list of excluded symbols is from GNU ld, minus the
cygwin specific symbols.

Also add support for outputting the actual list of exported
symbols in a def file, as in the GNU ld option --output-def.

These options in GNU ld are documented in
https://sourceware.org/binutils/docs/ld/WIN32.html.

This currently exports all symbols from object files pulled in
from libmingw32 and libmingwex and other static libraries
that are linked in.

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

llvm-svn: 315562
2017-10-12 05:37:13 +00:00
Rui Ueyama cc6738a439 Use error() instead of warn() to report undefined symbols.
I believe the reason why we used warn() instead of error() to report
undefined symbols is because the older implementation of error() exitted
immediately. Here, we want to find as many undefined symbols as we can,
so I chose to use warn() instead of error().

Now error() does not exit immediately, so it doesn't make sense to keep
them as warnings.

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

llvm-svn: 315131
2017-10-06 23:43:54 +00:00
Rui Ueyama 3f851704c1 Move new lld's code to Common subdirectory.
New lld's files are spread under lib subdirectory, and it isn't easy
to find which files are actually maintained. This patch moves maintained
files to Common subdirectory.

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

llvm-svn: 314719
2017-10-02 21:00:41 +00:00
Rafael Espindola 474f2bdabe Update for llvm change.
llvm-svn: 313938
2017-09-21 23:13:40 +00:00
Shoaib Meenai 4aa7f8a30f [COFF] Check for sections larger than 4 GiB
Sections are limited to 4 GiB. Error out early if a section exceeds this
size, rather than overflowing the section size and getting confusing
assertion failures/segfaults later.

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

llvm-svn: 313699
2017-09-19 23:58:05 +00:00
Rui Ueyama eef6b2a5c9 Revert r303378: Set IMAGE_DLL_CHARACTERISTICS_NO_BIND.
r303378 was submitted because r303374 (Merge IAT and ILT) made lld's
output incompatible with the Binding feature. Now that r303374 was
reverted, we do not need to keep this change.

Pointed out by pcc.

llvm-svn: 313414
2017-09-15 22:49:13 +00:00
Rui Ueyama cfc2f80df6 Remove {get,set}Align accessor functions and use Alignment member variable instead.
llvm-svn: 313204
2017-09-13 21:54:55 +00:00
Rui Ueyama a835babef9 Do not use hasArgNoClaim().
Arg instances can be claimed. After claimed, its `isClaimed` function
returns true. We do not use that notion in lld, so using NoClaim
versions of functions is just confusing. This patch is to just use
hasArg instead of hasArgNoClaim.

llvm-svn: 313187
2017-09-13 20:30:59 +00:00
Martin Storsjo 31fe4cd25d [MinGW] Support dllexport on i386
In MinGW configurations (GCC, or clang with a *-windows-gnu target),
the -export directives in the object file contains the undecorated
symbol name, while it is decorated in MSVC configurations. (On the
command line, link.exe takes an undecorated symbol name for the
-export argument though.)

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

llvm-svn: 313174
2017-09-13 19:29:39 +00:00
Martin Storsjo 8278ba51d3 [COFF] Add support for the -wholearchive option
This fixes PR31824.

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

llvm-svn: 313123
2017-09-13 07:28:03 +00:00
Rui Ueyama 9d9bdabee3 Ignore /natvis option for now.
/natvis is a new command line option introduced by MSVC 2017.
We eventually have to support it, but for now, let's ignore it so that
we can at least link stuff instead of printing out an error.

Patch by Michael Rickert.

llvm-svn: 312966
2017-09-11 22:24:13 +00:00
Peter Collingbourne 052e855e2b COFF: Implement ThinLTO cache and cache pruning support.
Differential Revision: https://reviews.llvm.org/D37607

llvm-svn: 312770
2017-09-08 00:50:50 +00:00
Peter Collingbourne cef809938d COFF: Remove unnecessary casts. NFCI.
llvm-svn: 312762
2017-09-07 23:49:09 +00:00
Nico Weber a05cbb8b95 lld-link: Add --rsp-quoting= flag.
This ports https://reviews.llvm.org/D19425 from clang /
https://reviews.llvm.org/D22015 from the ELF port to COFF lld. This can be
useful when linking COFF files on a posix host.

https://reviews.llvm.org/D37452

llvm-svn: 312594
2017-09-05 23:46:45 +00:00
Rui Ueyama 01d0265106 Simplify writeArchive return type.
writeArchive returned a pair, but the first element of the pair is always
its first argument on failure, so it doesn't make sense to return it from
the function. This patch change the return type so that it does't return it.

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

llvm-svn: 312177
2017-08-30 22:11:03 +00:00
Rui Ueyama f59b709ae4 Move a function from Driver.cpp to InputFile.cpp.
This patch doesn't improve code per se, but it should make the following
patch's diff easier to read.

llvm-svn: 312170
2017-08-30 20:55:18 +00:00
Rui Ueyama cbf969eb20 Remove Symtab aliases.
Various classes have `Symtab` member variables even though we have
lld::coff::Symtab variable because previous attempts to make COFF lld's
internal structure resemble to ELF's was incomplete. This patch finishes
that job by removing member variables.

llvm-svn: 311938
2017-08-28 21:51:07 +00:00
Rui Ueyama affb40e9d2 Keep an instance of COFFOptTable alive as long as InputArgList is alive.
Summary:
ArgParser created an instance of COFFOptTable on stack to use it to
parser command line arguments. Parsed arguments were then returned from
the function as InputArgList. This was safe because InputArgList referred
only statically-allocated InfoTable.

That is not a safe assumption after https://reviews.llvm.org/D36782,
which changes the type of its internal table from ArrayRef to std::vector.
To make lld work with that patch, we need to keep an instance of
COFFOptTable at least as long as an InputArgList is alive. This patch
does that.

Reviewers: yamaguchi

Subscribers: llvm-commits

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

llvm-svn: 311930
2017-08-28 20:46:30 +00:00
Rui Ueyama 8bee41e423 Simplify. NFC.
llvm-svn: 311700
2017-08-24 20:32:58 +00:00
Rui Ueyama 9f7032aaf0 Minor refactoring. NFC.
llvm-svn: 311696
2017-08-24 20:26:54 +00:00
Martin Storsjo 92f32d0c53 [COFF] Don't produce weak aliases in import libraries
When creating an import library from lld, the cases with
Name != ExtName shouldn't end up as a weak alias, but as a real
export of the new name, which is what actually is exported from
the DLL.

This restores the behaviour of renamed exports to what it was in
4.0.

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

llvm-svn: 310992
2017-08-16 05:23:00 +00:00
Martin Storsjo a50275cfe5 [COFF] Fix the name type for stdcall functions in import libraries
Since SVN r303491 and r304573, LLD used the COFFImportLibrary
functions from LLVM. These only had two names, Name and ExtName,
which wasn't enough to convey all the details of stdcall functions.

Stdcall functions got the wrong symbol name in the import library
itself in r303491, which is why it was reverted in r304561. When
re-landed and fixed in r304573 (after adding a test in r304572),
the symbol name itself in the import library ended up right, but the
name type of the import library entry was wrong.

This had the effect that linking to the import library succeeded
(contrary to in r303491, where linking to such an import library
failed), but at runtime, the symbol wouldn't be found in the DLL
(since the caller linked to the stdcall decorated name).

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

llvm-svn: 310989
2017-08-16 05:13:25 +00:00
Martin Storsjo d2752aa9ec [COFF] Add support for aligncomm directives
These are emitted for comm symbols in object files, when targeting
a GNU environment.

Alternatively, just ignore them since we already align CommonChunk
to the natural size of the content (up to 32 bytes). That would only
trade away the possibility to overalign small symbols, which doesn't
sound like something that might not need to be handled?

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

llvm-svn: 310871
2017-08-14 19:07:27 +00:00
Rui Ueyama acd632d338 Add {Obj,Import,Bitcode}File::Instances to COFF input files.
We did the same thing for ELF in r309152, and I want to maintain
COFF and ELF as close as possible.

llvm-svn: 309239
2017-07-27 00:45:26 +00:00
Rui Ueyama e1b48e099c Rename ObjectFile ObjFile for COFF as well.
llvm-svn: 309228
2017-07-26 23:05:24 +00:00
Nico Weber a7a2c44e70 lld: only write .manifest files if /manifest is passed, PR33925
Also emit an error if /manifestinput: is used without /manifest:embed.
Increases compatibility with link.exe

https://reviews.llvm.org/D35842

llvm-svn: 308998
2017-07-25 18:08:03 +00:00
Rui Ueyama 12234f8093 Use StringRef::contains().
llvm-svn: 308526
2017-07-19 21:40:26 +00:00
Rui Ueyama 38b0f4a1f2 Handle option aliases in a better way.
In this way, we don't need to know which options have aliases.

llvm-svn: 308519
2017-07-19 20:30:04 +00:00
Saleem Abdulrasool ace2fa7da4 COFF: improve link conformance for import names
Improve the link conformance for the import name embedded into the
import library.  This requires the associated change to the LLVM portion
for the DEF file parser.  The import file generation embeds a different
name based on whether the driver is invoked as "link" or "lib".
Furthermore, the LIBRARY keyword in the DEF file influences the import
name.  The behaviour can be summarised according to the following table:

      | LIBRARY w/ ext |   LIBRARY w/o ext   | no LIBRARY
 -----+----------------+---------------------+------------------
 LINK | {value}        | {value}.{.dll/.exe} | {output name}
  LIB | {value}        | {value}.dll         | {output name}.dll

llvm-svn: 308407
2017-07-19 02:01:27 +00:00
Zachary Turner 6708e0b45e [lld/pdb] Add some basic linker module symbols.
Differential Revision: https://reviews.llvm.org/D35152

llvm-svn: 307590
2017-07-10 21:01:37 +00:00
Reid Kleckner 502d4ce2e4 [COFF] Improve synthetic symbol handling
Summary:
The main change is that we can have SECREL and SECTION relocations
against ___safe_se_handler_table, which is important for handling the
debug info in the MSVCRT.

Previously we were using DefinedRelative for __safe_se_handler_table and
__ImageBase, and after we implement CFGuard, we plan to extend it to
handle __guard_fids_table, __guard_longjmp_table, and more.  However,
DefinedRelative is really only suitable for implementing __ImageBase,
because it lacks a Chunk, which you need in order to figure out the
output section index and output section offset when resolving SECREl and
SECTION relocations.

This change renames DefinedRelative to DefinedSynthetic and gives it a
Chunk. One wart is that __ImageBase doesn't have a chunk. It points to
the PE header, effectively. We could split DefinedRelative and
DefinedSynthetic if we think that's cleaner and creates fewer special
cases.

I also added safeseh.s, which checks that we don't emit a safe seh table
entries pointing to garbage collected handlers and that we don't emit a
table at all when there are no handlers.

Reviewers: ruiu

Reviewed By: ruiu

Subscribers: inglorion, pcc, llvm-commits, aprantl

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

llvm-svn: 306293
2017-06-26 15:39:52 +00:00
Rui Ueyama 2f740f74bb Define __guard_{iat,longjmp}_{count,table} symbols.
VC2017 contains these new symbols as undefined symobls. They are used
for /guard:cf. Since we do not support the control flow guard, but we
want to at least ignore these symbols so that we can link against VS2017
libraries.

Fixes https://bugs.chromium.org/p/chromium/issues/detail?id=727193.

llvm-svn: 305876
2017-06-21 02:26:19 +00:00
Eric Beckmann 9e19d790a6 Update documentation to reflection disuse of external cvtres.
Subscribers: llvm-commits

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

llvm-svn: 305631
2017-06-17 02:26:27 +00:00
Zachary Turner 7ba50b7151 Remove /dumppdb option from LLD.
This option is no longer needed.

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

llvm-svn: 305610
2017-06-16 23:41:44 +00:00
Saleem Abdulrasool bc7ff7027e COFF: add support for lib mode usage
When link is invoked with `/def:` and no input files, it behaves as if
`lib.exe` was invoked.  Emulate this behaviour, generating the import
library from the def file that was passed.  Because there is no input to
actually generate the dll, we simply process the def file early and exit
once we have created the import library.

llvm-svn: 305502
2017-06-15 20:39:58 +00:00
Rui Ueyama 2aecdde512 Inline a small function. NFC.
llvm-svn: 305428
2017-06-14 23:37:37 +00:00
Rui Ueyama 67aea737f3 Use check() to report an error.
llvm-svn: 305033
2017-06-08 23:43:44 +00:00
Zachary Turner 264b5d9e88 Move Object format code to lib/BinaryFormat.
This creates a new library called BinaryFormat that has all of
the headers from llvm/Support containing structure and layout
definitions for various types of binary formats like dwarf, coff,
elf, etc as well as the code for identifying a file from its
magic.

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

llvm-svn: 304864
2017-06-07 03:48:56 +00:00
Reid Kleckner 146eb7a65f Re-land "COFF: migrate def parser from LLD to LLVM"
This reverts commit r304561 and re-lands r303490 & co.

The fix was to use "SymbolName" when translating LLD's internal export
list to lib/Object's short export struct. The SymbolName reflects the
actual symbol name, which may include fastcall and stdcall mangling bits
not included in the /EXPORT or .def file EXPORTS name:

@@ -434,8 +434,7 @@ std::vector<COFFShortExport> createCOFFShortExportFromConfig() {
   std::vector<COFFShortExport> Exports;
   for (Export &E1 : Config->Exports) {
     COFFShortExport E2;
-    E2.Name = E1.Name;
+    // Use SymbolName, which will have any stdcall or fastcall qualifiers.
+    E2.Name = E1.SymbolName;
     E2.ExtName = E1.ExtName;
     E2.Ordinal = E1.Ordinal;
     E2.Noname = E1.Noname;

llvm-svn: 304573
2017-06-02 17:53:06 +00:00
Reid Kleckner d249e4a188 Revert "COFF: migrate def parser from LLD to LLVM"
This reverts commits r303490, r303491, r303493, and r303494.

This caused http://crbug.com/728726. Essentially, exporting stdcall
functions doesn't appear to work after this change. Reduced test case
soon.

llvm-svn: 304561
2017-06-02 16:26:24 +00:00
Martell Malone 1e39e5e964 COFF: migrate def parser from LLD to LLVM [2/2]
This is split up into two commits.
This commit removes the DEF parser from LLD
See the previous commit for the creation in LLVM.

Reviewers: ruiu

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

llvm-svn: 303491
2017-05-20 19:56:44 +00:00
Rui Ueyama a674943211 Set IMAGE_DLL_CHARACTERISTICS_NO_BIND.
Our output is not compatible with the Binding feature, so make it
explicit that.

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

llvm-svn: 303378
2017-05-18 20:26:58 +00:00
Rui Ueyama 01f93335a0 Use make<> everywhere in COFF to make it consistent with ELF.
We've been using make<> to allocate new objects in ELF. We have
the same function in COFF, but we didn't use it widely due to
negligence. This patch uses the function in COFF to close the gap
between ELF and COFF.

llvm-svn: 303357
2017-05-18 17:03:49 +00:00
Zachary Turner 8a7508970a [COFF] Fix interaction between /DEBUG and /PDB
When /DEBUG is not specified, /PDB should be ignored.  When
/DEBUG is specified, a PDB should be output regardless of
whether or not /PDB is specified.  /PDB just overrides the
default name.

This patch implements this behavior, and adds some tests, while
also removing a dead option /DEBUGPDB which was unused in any
code.

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

llvm-svn: 303352
2017-05-18 15:15:10 +00:00
Peter Collingbourne c6f07c423d Move lib/LibDriver -> lib/ToolDrivers/llvm-lib. NFCI.
This reorganisation prevents us from cluttering up the top-level lib directory
with more driver libraries such as llvm-dlltool (see D29892).

llvm-svn: 302995
2017-05-13 22:06:46 +00:00
Bob Haarman 4110816253 [coff] for /msvclto, pass archive members with prevailing symbols first
Summary: When using /msvclto, lld and MSVC's linker both do their own symbol resolution. This can cause them to select different archive members, which can result in undefined references. This change avoids that situation by extracting archive members that are selected by lld and passing those to link.exe before any archives, so that MSVC's uses those objects for symbol resolution instead of different archive members.

Reviewers: pcc, rnk, ruiu

Reviewed By: pcc

Subscribers: llvm-commits, mehdi_amini

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

llvm-svn: 301045
2017-04-21 21:38:01 +00:00