Commit Graph

93 Commits

Author SHA1 Message Date
Martin Storsjö 248e3450fb [LLD] [MinGW] Pass the --demangle and --no-demangle options to the COFF linker
Differential Revision: https://reviews.llvm.org/D93950
2021-01-07 10:02:19 +02:00
Martin Storsjö 3785a413fe Reapply [LLD] [COFF] Implement a GNU/ELF like -wrap option
Add a simple forwarding option in the MinGW frontend, and implement
the private -wrap option in the COFF linker.

The feature in lld-link isn't gated by the -lldmingw option, but
the option is left as a private, undocumented option primarily
used by the MinGW driver.

The implementation is significantly based on the support for --wrap
in the ELF linker, but many small nuance details are different
between the ELF and COFF linkers, ending up with more than a few
implementation differences.

This fixes https://bugs.llvm.org/show_bug.cgi?id=47384.

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

Reapplied with the bitfield member canInline fixed so it doesn't break
builds targeting windows.
2020-10-15 22:14:02 +03:00
Arthur Eubanks 3d338f6813 Revert "[LLD] [COFF] Implement a GNU/ELF like -wrap option"
This reverts commit a012c704b5.

Breaks Windows builds.

C:\src\llvm-mint\lld\COFF\Symbols.cpp(26,1): error: static_assert failed due to requirement 'sizeof(lld::coff::SymbolUnion) <= 48' "symbols should be optimized for memory usage"
static_assert(sizeof(SymbolUnion) <= 48,
2020-10-15 10:27:25 -07:00
Martin Storsjö a012c704b5 [LLD] [COFF] Implement a GNU/ELF like -wrap option
Add a simple forwarding option in the MinGW frontend, and implement
the private -wrap option in the COFF linker.

The feature in lld-link isn't gated by the -lldmingw option, but
the option is left as a private, undocumented option primarily
used by the MinGW driver.

The implementation is significantly based on the support for --wrap
in the ELF linker, but many small nuance details are different
between the ELF and COFF linkers, ending up with more than a few
implementation differences.

This fixes https://bugs.llvm.org/show_bug.cgi?id=47384.

Differential Revision: https://reviews.llvm.org/D89004
2020-10-15 18:34:02 +03:00
Martin Storsjö 6e6a5acf00 [LLD] [MinGW] Move an option definitions to alphabetical order, wrap a line. NFC. 2020-10-07 15:14:07 +03:00
Martin Storsjö 61e2f9fa2e [LLD] [MinGW] Support setting the subsystem version via the subsystem argument
If a version is specified both with --{major,minor}-subsystem-version and
with --subsystem <name>:<version>, the one specified last (that actually
sets a version) takes precedance in GNU ld; thus doing the same here.

Differential Revision: https://reviews.llvm.org/D88804
2020-10-05 23:08:08 +03:00
Martin Storsjö bc8f3b424c [LLD] [MinGW] Simplify handling of os/subsystem version
As they can be set independently after D88802, we can get rid of a bit
of extra code - simplifying the logic here before adding more
complication to it later.

Differential Revision: https://reviews.llvm.org/D88803
2020-10-05 23:08:02 +03:00
Martin Storsjö e72403f96d [LLD] [MinGW] Enable dynamicbase by default
This matches lld-link's own default.

Add a new command line option --no-dynamicbase for disabling it.
(Unfortunately, GNU ld doesn't yet have a matching --no-dynamicbase
option, as that's the default there.)

Differential Revision: https://reviews.llvm.org/D86654
2020-08-27 15:08:53 +03:00
Mateusz Mikuła c82078b5d7 [LLD][MinGW] Handle allow-multiple-definition flag
Basically copied from ELF driver.

Differential Revision: https://reviews.llvm.org/D86512
2020-08-26 09:38:11 +03:00
Mateusz Mikuła dcb1ce61b8 [LLD][MinGW] Cleanup Options.td file. NFC.
Based on ELF driver Options.td.

Differential Revision: https://reviews.llvm.org/D86509
2020-08-26 09:38:11 +03:00
Martin Storsjö 745eb02496 [LLD] [MinGW] Implement the --no-seh flag
Previously this flag was just ignored. If set, set the
IMAGE_DLL_CHARACTERISTICS_NO_SEH bit, regardless of the normal safeSEH
machinery.

In mingw configurations, the safeSEH bit might not be set in e.g. object
files built from handwritten assembly, making it impossible to use the
normal safeseh flag. As mingw setups don't generally use SEH on 32 bit
x86 at all, it should be fine to set that flag bit though - hook up
the existing GNU ld flag for controlling that.

Differential Revision: https://reviews.llvm.org/D84701
2020-07-28 21:08:37 +03:00
Michele Scandale 53880b8cb9 [CMake] Make `intrinsics_gen` dependency unconditional.
The `intrinsics_gen` target exists in the CMake exports since r309389
(see LLVMConfig.cmake.in), hence projects can depend on `intrinsics_gen`
even it they are built separately from LLVM.

Reviewed By: MaskRay, JDevlieghere

Differential Revision: https://reviews.llvm.org/D83454
2020-07-17 16:43:17 -07:00
Martin Storsjö 92f7bd3a39 [LLD] [MinGW] Implement the --file-alignment and --section-alignment options
Differential Revision: https://reviews.llvm.org/D83720
2020-07-15 08:34:08 +03:00
Tobias Hieta f794808bb9 [LLD/MinGW]: Expose --thinlto-cache-dir
Differential Revision: https://reviews.llvm.org/D80438
2020-05-24 12:30:56 +03:00
Martin Storsjö 7f0e6c31c2 [LLD] [COFF] Add options for disabling auto import and runtime pseudo relocs
Allow disabling either the full auto import feature, or just
forbidding the cases that require runtime fixups.

As long as all auto imported variables are referenced from separate
.refptr$<name> sections, we can alias them on top of the IAT entries
and don't actually need any runtime fixups via pseudo relocations.
LLVM generates references to variables in .refptr stubs, if it
isn't known that the variable for sure is defined in the same object
module. Runtime pseudo relocs are needed if the addresses of auto
imported variables are used in constant initializers though.

Fixing up runtime pseudo relocations requires the use of
VirtualProtect (which is disallowed in WinStore/UWP apps) or
VirtualProtectFromApp. To allow any risk of ambiguity, allow
rejecting cases that would require this at the linker stage.

This adds support for the --disable-runtime-pseudo-reloc and
--disable-auto-import options in the MinGW driver (matching GNU ld.bfd)
with corresponding lld private options in the COFF driver.

Differential Revision: https://reviews.llvm.org/D78923
2020-05-14 13:05:14 +03:00
Reid Kleckner 213aea4c58 Remove unused Endian.h includes, NFC
Mainly avoids including Host.h everywhere:

$ diff -u <(sort thedeps-before.txt) <(sort thedeps-after.txt) \
    | grep '^[-+] ' | sort | uniq -c | sort -nr
   3141 - /usr/local/google/home/rnk/llvm-project/llvm/include/llvm/Support/Host.h
2020-03-11 15:45:34 -07:00
Jonas Devlieghere 3e24242a7d [lld] Replace SmallStr.str().str() with std::string conversion operator.
Use the std::string conversion operator introduced in
d7049213d0.
2020-01-29 21:30:21 -08:00
James Y Knight d3fec7fb45 LLD: Don't use the stderrOS stream in link before it's reassigned.
Remove the lld::enableColors function, as it just obscures which
stream it's affecting, and replace with explicit calls to the stream's
enable_colors.

Also, assign the stderrOS and stdoutOS globals first in link function,
just to ensure nothing might use them.

(Either change individually fixes the issue of using the old
stream, but both together seems best.)

Follow-up to b11386f9be.

Differential Revision: https://reviews.llvm.org/D70492
2019-11-21 10:55:03 -05:00
Rui Ueyama b11386f9be Make it possible to redirect not only errs() but also outs()
This change is for those who use lld as a library. Context:
https://reviews.llvm.org/D70287

This patch adds a new parmeter to lld::*::link() so that we can pass
an raw_ostream object representing stdout. Previously, lld::*::link()
took only an stderr object.

Justification for making stdoutOS and stderrOS mandatory: I wanted to
make link() functions to take stdout and stderr in that order.
However, if we change the function signature from

  bool link(ArrayRef<const char *> args, bool canExitEarly,
            raw_ostream &stderrOS = llvm::errs());

to

  bool link(ArrayRef<const char *> args, bool canExitEarly,
            raw_ostream &stdoutOS = llvm::outs(),
            raw_ostream &stderrOS = llvm::errs());

, then the meaning of existing code that passes stderrOS silently
changes (stderrOS would be interpreted as stdoutOS). So, I chose to
make existing code not to compile, so that developers can fix their
code.

Differential Revision: https://reviews.llvm.org/D70292
2019-11-18 11:18:06 +09:00
Rui Ueyama 37bf9bb405 Use error instead of fatal to report usage errors
Differential Revision: https://reviews.llvm.org/D68768

llvm-svn: 374297
2019-10-10 09:46:41 +00:00
Martin Storsjo 0226c35262 [LLD] [MinGW] Look for other library patterns with -l
GNU ld looks for a number of other patterns than just lib<name>.dll.a
and lib<name>.a.

GNU ld does support linking directly against a DLL without using an
import library. If that's the only match for a -l argument, point out
that the user needs to use an import library, instead of leaving the
user with a puzzling message about the -l argument not being found
at all.

Also convert an existing case of fatal() into error().

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

llvm-svn: 374292
2019-10-10 08:52:39 +00:00
Rui Ueyama e4758a5c27 [MinGW] Add --reproduce option
Differential Revision: https://reviews.llvm.org/D68382

llvm-svn: 373705
2019-10-04 07:27:45 +00:00
Martin Storsjo 0e5530abfc [MinGW] Correct handling different forms of a few options
Support the equals form of the long --entry=<symbol> option,
add a test for the -e<symbol> form.

Add tests for single dash forms of -exclude-all-symbols and
-export-all-symbols.

Support single-dash forms of -out-implib and -output-def, support
the equals form of --output-def=<file>. (We previously had a test
to explicitly disallow -out-implib, but it turns out that GNU ld
actually does support it just fine, despite also matching the
-o<file> option.)

Disallow the double-dashed --u form, add a test for -u<symbol>.

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

llvm-svn: 368816
2019-08-14 09:35:44 +00:00
Martin Storsjo ce26ad7a9d [MinGW] Restructure Options.td to use multiclass where sensible. NFC.
Differential Revision: https://reviews.llvm.org/D66065

llvm-svn: 368815
2019-08-14 09:35:40 +00:00
Martin Storsjo c92b3563c6 [MinGW] Add an lld specific option for requesting to delay load libraries
With GNU tools, delayload is handled completely differently. (One
creates a specific delayload import library using dlltool and then
links against it instead of the normal import library.)

Instead of requiring using -Xlink=-delayload:lib.dll, we can provide
an lld specific option for this.

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

llvm-svn: 367837
2019-08-05 11:57:06 +00:00
Rui Ueyama 136d27ab4d [Coding style change][lld] Rename variables for non-ELF ports
This patch does the same thing as r365595 to other subdirectories,
which completes the naming style change for the entire lld directory.

With this, the naming style conversion is complete for lld.

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

llvm-svn: 365730
2019-07-11 05:40:30 +00:00
Nico Weber a780276301 lld, llvm-dlltool, llvm-lib: Use getAsString() instead of getSpelling() for printing unknown args
Since OPT_UNKNOWN args never have any values and consist only of
spelling (and are never aliased), this doesn't make any difference in
practice, but it's more consistent with Arg's guidance to use
getAsString() for diagnostics, and it matches what clang does.

Also tweak two tests to use an unknown option that contains '=' for
additional coverage while here. (The new tests pass fine with the old
code too though.)

llvm-svn: 365200
2019-07-05 12:31:32 +00:00
Nico Weber cf1a11ded2 Make joined instances of JoinedOrSeparate flags point to the unaliased args, like all other arg types do
This fixes an 8-year-old regression. r105763 made it so that aliases
always refer to the unaliased option – but it missed the "joined" branch
of JoinedOrSeparate flags. (r162231 then made the Args classes
non-virtual, and r169344 moved them from clang to llvm.)

Back then, there was no JoinedOrSeparate flag that was an alias, so it
wasn't observable. Now /U in CLCompatOptions is a JoinedOrSeparate alias
in clang, and warn_slash_u_filename incorrectly used the aliased arg id
(using the unaliased one isn't really a regression since that warning
checks if the undefined macro contains slash or backslash and only then
emits the warning – and no valid use will pass "-Ufoo/bar" or similar).

Also, lld has many JoinedOrSeparate aliases, and due to this bug it had
to explicitly call `getUnaliasedOption()` in a bunch of places, even
though that shouldn't be necessary by design. After this fix in Option,
these calls really don't have an effect any more, so remove them.

No intended behavior change.

(I accidentally fixed this bug while working on PR29106 but then
wondered why the warn_slash_u_filename broke. When I figured it out, I
thought it would make sense to land this in a separate commit.)

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

llvm-svn: 365186
2019-07-05 11:45:24 +00:00
Martin Storsjo ff4e0a9f3e [MinGW] Support the --subsystem=val option in joined form
Differential Revision: https://reviews.llvm.org/D63250

llvm-svn: 363433
2019-06-14 17:50:39 +00:00
Martin Storsjo 6f047ae58b [MinGW] Support the --{major,minor}-{os,subsystem}-version options
This fixes PR42218.

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

llvm-svn: 363432
2019-06-14 17:50:35 +00:00
Martin Storsjo bb12396f91 [Driver] Look for -m in response files as well
Also expand response files in the MinGW driver.

This should fix PR42135.

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

llvm-svn: 362977
2019-06-10 20:10:10 +00:00
Martin Storsjo 4962f9464d [MinGW] Support the -u/--undefined option.
This is implemented by the lld-link option -include:, just like
--require-defined. Contrary to --require-defined, the -u/--undefined
option allows the symbol to remain undefined in the end.

This should fix PR42121.

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

llvm-svn: 362882
2019-06-08 18:26:24 +00:00
Martin Storsjo 5fab538e2a [MinGW] Set the right updated option help for the updated pdb option. NFC
I forgot to amend this change before committing it in SVN r361014, this
is what was agreed upon in the review.

llvm-svn: 361093
2019-05-18 04:20:31 +00:00
Martin Storsjo 6ff6a8f656 [MinGW] Include --enable-auto-import in the help listing
Libtool concludes that the linker doesn't support shared libraries,
unless this flag is listed in the output of --help.

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

llvm-svn: 361017
2019-05-17 11:07:46 +00:00
Martin Storsjo 6863dfaa21 [MinGW] Implement the -v and --version flags for the MinGW driver
Differential Revision: https://reviews.llvm.org/D62030

llvm-svn: 361016
2019-05-17 11:07:42 +00:00
Martin Storsjo 9ae0d222dc [MinGW] Implement --help for the MinGW driver
Differential Revision: https://reviews.llvm.org/D62029

llvm-svn: 361015
2019-05-17 11:07:38 +00:00
Martin Storsjo 2c52ddf31f [MinGW] Allow requesting PDB output without giving a file name
When integrating PDB output in mingw targeting build systems, it
might be a lot of extra work to specify unique file names for
the pdb output. Therefore allow omitting the actual file name
and let it implicitly be the same name as the linker output, with
a pdb extension.

As the current form of the pdb option takes a separate parameter value,
e.g. "-pdb out.pdb", it is impractical to leave out the parameter value.

Therefore, introduce a second syntax for the option, with an equals
sign, like -pdb=out.pdb, where the value easily can be omitted.

The form -pdb= for requesting pdb files with an implicit name should
work fine, even though it looks a bit unconventional in that form.

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

llvm-svn: 361014
2019-05-17 11:07:33 +00:00
Martin Storsjo 2c1f3ea538 [MinGW] Add an --appcontainer flag, passed through to lld-link
GNU ld doesn't have such a flag though, so this is a lld specific
option.

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

llvm-svn: 358759
2019-04-19 13:50:43 +00:00
Martin Storsjo 9705898bf3 [MinGW] Hook up the --exclude-all-symbols option
Differential Revision: https://reviews.llvm.org/D58380

llvm-svn: 354387
2019-02-19 21:57:49 +00:00
Martin Storsjo dfb2fcd224 [MinGW] Add --insert-timestamp as complement to the --no-insert-timestamp option
Differential Revision: https://reviews.llvm.org/D57808

llvm-svn: 353342
2019-02-06 21:05:29 +00:00
Martin Storsjo 537a718fcb [MinGW] Hook up the --no-insert-timestamp option
This fixes PR40582.

Patch by Georg Koppen!

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

llvm-svn: 353145
2019-02-05 08:16:06 +00:00
Martin Storsjo d79a4b7ad7 [MinGW] Don't define names for ignored options. NFC.
Move them to the same section as the newly added ignored options
without a defined name.

Also move options that actually weren't ignored to the right section.

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

llvm-svn: 352529
2019-01-29 19:24:32 +00:00
Martin Storsjo 5d1862b76c [MinGW] Ignore the --plugin and --plugin-opt option
GCC can use LLD with -fuse-ld=lld for MinGW these days, but by
default these options are passed to the linker (unless -fno-lto
is passed to the GCC driver).

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

llvm-svn: 352459
2019-01-29 08:38:48 +00:00
Chandler Carruth 2946cd7010 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351636
2019-01-19 08:50:56 +00:00
Martin Storsjo 5abe10ac21 [MinGW] Expand comment for MinGW driver. NFC.
Originally authored by Rui Ueyama.

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

llvm-svn: 350464
2019-01-05 10:43:59 +00:00
Martin Storsjo 803b37ad5d [MinGW] Pass libpath to the COFF linker
This is necessary for handling defaultlib directives embedded in
object files, unless they use an absolute path.

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

llvm-svn: 344123
2018-10-10 09:00:03 +00:00
Martin Storsjo db62913f28 [MinGW] Hook up the --require-defined option to -include:
Differential Revision: https://reviews.llvm.org/D51840

llvm-svn: 341846
2018-09-10 17:41:40 +00:00
Martin Storsjo c0826745cf [MinGW] Implement the GNU ld options -S/--strip-debug
In this mode, we retain the symbol table, but skip the actual debug
information.

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

llvm-svn: 335947
2018-06-29 06:08:31 +00:00
Martin Storsjo 0366155500 [MinGW] Handle the GNU ld option -Map for outputting a linker map
Differential Revision: https://reviews.llvm.org/D46872

llvm-svn: 332398
2018-05-15 21:12:29 +00:00
Martin Storsjo b7d50115ba [MinGW] Add a LLD specific option -pdb
This allows producing pdb debug info. This is an LLD specific option
since GCC and GNU binutils doesn't support the PDB file format.

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

llvm-svn: 332327
2018-05-15 06:34:18 +00:00