aboutsummaryrefslogtreecommitdiff
path: root/lld/MinGW
AgeCommit message (Collapse)AuthorFilesLines
2021-08-12[LLD] [MinGW] Add more options for disabling flags in the executableMartin Storsjö2-7/+23
In e72403f96de7f1c681acd5968f72aa986412dfce, we added the flag "--no-dynamicbase" for disabling the dynamicbase flag which we set by default. At the time, ld.bfd didn't have any corresponding option (as ld.bfd defaulted to not setting the flag). Almost at the same time, corresponding options were added to ld.bfd for disabling it (while it was being enabled by default), with a different name, "--disable-dynamicbase". Thus add the "--disable-dynamicbase" option. Make this default one advertised in the help listing, but keep the "--no-dynamicbase" form as an alias. Also improve checking for the last option set if there are multiple ones on the same command line. Also add corresponding disable options for a lot of other flags that we set by default, also added in ld.bfd in the same commit: https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=514b4e191d5f46de8e142fe216e677a35fa9c4bb Differential Revision: https://reviews.llvm.org/D107930
2021-08-03[LLD] [MinGW] Support both "--opt value" and "--opt=value" for more optionsMartin Storsjö1-12/+14
This does the same fix as D107237 but for a couple more options, converting all remaining cases of such options to accept both forms, for consistency. This fixes building e.g. openldap, which uses --image-base=<value>. Differential Revision: https://reviews.llvm.org/D107253
2021-08-01[LLD][MinGW] Accept joined format for --stackMateusz Mikuła1-1/+1
Postgresql uses `--stack=` in its Makefile. Downstream issue: https://github.com/msys2/MINGW-packages/pull/9167 Reviewed By: mstorsjo Differential Revision: https://reviews.llvm.org/D107237
2021-07-02[LLD] [COFF] Fix up missing stdcall decorations in MinGW modeMartin Storsjö2-0/+9
If linking directly against a DLL without an import library, the DLL export symbols might not contain stdcall decorations. If we have an undefined symbol with decoration, and we happen to have a matching undecorated symbol (which either is lazy and can be loaded, or already defined), then alias it against that instead. This matches what's done in reverse, when we have a def file declaring to export a symbol without decoration, but we only have a defined decorated symbol. In that case we do a fuzzy match (SymbolTable::findMangle). This case is more straightforward; if we have a decorated undefined symbol, just strip the decoration and look for the corresponding undecorated symbol name. Add warnings and options for either silencing the warning or disabling the whole feature, corresponding to how ld.bfd does it. (This feature works for any symbol decoration mismatch, not only when linking against a DLL directly; ld.bfd also tolerates it anywhere, and also fixes up mismatches in the other direction, like SymbolTable::findMangle, for any symbol, not only exports. But in practice, at least for lld, it would primarily end up used for linking against DLLs.) Differential Revision: https://reviews.llvm.org/D104532
2021-07-02[LLD] [MinGW] Allow linking to DLLs directlyMartin Storsjö1-10/+4
As the COFF linker is capable of linking directly against a DLL now (after D104530, as long as it is running in mingw mode), don't error out here but successfully load libraries specified with "-l" from DLLs if that's what ld.bfd would have matched. Differential Revision: https://reviews.llvm.org/D104531
2021-06-24[OptTable] Rename PrintHelp to printHelpFangrui Song1-1/+1
To be consistent with other member functions and match the coding standard.
2021-06-25[lld] Rename StringRef _lower() method calls to _insensitive()Martin Storsjö1-1/+1
2021-06-23[LLD] [MinGW] Print the lld-link command to stderrMartin Storsjö1-1/+1
This is consistent with how clang prints its internal commands with -### and -v. When linking with -verbose, we get log messages from the actual linking written to stderr. By printing the command to the same stream, we make sure they appear in a sensible chronological order. Differential Revision: https://reviews.llvm.org/D104527
2021-06-19[LLD] [MinGW] Print errors/warnings in lld-link with a "ld.lld" prefixMartin Storsjö1-0/+3
Pass the original argv[0] to the coff linker, as the coff linker uses the basename of argv[0] as the log prefix. This makes error messages to be printed with a "ld.lld:" prefix instead of "lld-link:". The current "lld-link:" prefix can be confusing to users, as they're invoking the MinGW linker (and might not even have a lld-link executable). Keep the first argument as lld-link when printing the command line, to make it an actually reproducible standalone command. Differential Revision: https://reviews.llvm.org/D104526
2021-05-18[LLD] [MinGW] Pass the canExitEarly parameter through properlyMartin Storsjö1-1/+1
The MinGW driver passed a hardcoded true to this parameter since 6f4e255219f2a7878d3, but when the MinGW driver got the canExitEarly parameter for consistency in b11386f9be9b2dc7276, this call was missed so it wasn't passed on properly.
2021-05-17[lld][MinGW] Introduce aliases for -Bdynamic and -BstaticMarkus Böck1-0/+5
Besides -Bdynamic and -Bstatic, ld documents additional aliases for both of these options. Instead of -Bstatic, one may write -dn, -non_shared or -static. Instead of -Bdynamic one may write -dy or -call_shared. Source: https://sourceware.org/binutils/docs-2.36/ld/Options.html This patch adds those aliases to the MinGW driver of lld for the sake of ld compatibility. Encountered this case while compiling a static Qt 6.1 distribution and got build failures as -static was passed directly to the linker, instead of through the compiler driver. Differential Revision: https://reviews.llvm.org/D102637
2021-05-17[LLD][MinGW] Add --fatal-warnings and --no-fatal-warnings flagsMateusz Mikuła2-0/+8
Differential Revision: https://reviews.llvm.org/D102514
2021-05-14[LLD][MinGW] Ignore --no-undefined flagMateusz Mikuła1-0/+1
AFAIK this is the default behaviour when this flag is not passed. Differential Revision: https://reviews.llvm.org/D102516
2021-01-07[LLD] [MinGW] Pass the --demangle and --no-demangle options to the COFF linkerMartin Storsjö2-0/+8
Differential Revision: https://reviews.llvm.org/D93950
2020-10-15Reapply [LLD] [COFF] Implement a GNU/ELF like -wrap optionMartin Storsjö2-0/+4
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-15Revert "[LLD] [COFF] Implement a GNU/ELF like -wrap option"Arthur Eubanks2-4/+0
This reverts commit a012c704b5e5b60f9d2a7304d27cbc84a3619571. 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[LLD] [COFF] Implement a GNU/ELF like -wrap optionMartin Storsjö2-0/+4
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-07[LLD] [MinGW] Move an option definitions to alphabetical order, wrap a line. ↵Martin Storsjö1-3/+4
NFC.
2020-10-05[LLD] [MinGW] Support setting the subsystem version via the subsystem argumentMartin Storsjö1-6/+34
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[LLD] [MinGW] Simplify handling of os/subsystem versionMartin Storsjö1-18/+6
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-08-27[LLD] [MinGW] Enable dynamicbase by defaultMartin Storsjö2-2/+3
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-26[LLD][MinGW] Handle allow-multiple-definition flagMateusz Mikuła2-0/+7
Basically copied from ELF driver. Differential Revision: https://reviews.llvm.org/D86512
2020-08-26[LLD][MinGW] Cleanup Options.td file. NFC.Mateusz Mikuła1-10/+14
Based on ELF driver Options.td. Differential Revision: https://reviews.llvm.org/D86509
2020-07-28[LLD] [MinGW] Implement the --no-seh flagMartin Storsjö2-1/+3
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-17[CMake] Make `intrinsics_gen` dependency unconditional.Michele Scandale1-5/+1
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-15[LLD] [MinGW] Implement the --file-alignment and --section-alignment optionsMartin Storsjö2-0/+6
Differential Revision: https://reviews.llvm.org/D83720
2020-05-24[LLD/MinGW]: Expose --thinlto-cache-dirTobias Hieta2-0/+4
Differential Revision: https://reviews.llvm.org/D80438
2020-05-14[LLD] [COFF] Add options for disabling auto import and runtime pseudo relocsMartin Storsjö2-1/+18
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-03-11Remove unused Endian.h includes, NFCReid Kleckner1-0/+1
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-01-29[lld] Replace SmallStr.str().str() with std::string conversion operator.Jonas Devlieghere1-1/+1
Use the std::string conversion operator introduced in d7049213d0fcda691c9e79f9b41e357198d99738.
2019-11-21LLD: Don't use the stderrOS stream in link before it's reassigned.James Y Knight1-1/+2
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 b11386f9be9b2dc7276a758d64f66833da10bdea. Differential Revision: https://reviews.llvm.org/D70492
2019-11-18Make it possible to redirect not only errs() but also outs()Rui Ueyama1-6/+9
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-10-10Use error instead of fatal to report usage errorsRui Ueyama1-6/+13
Differential Revision: https://reviews.llvm.org/D68768 llvm-svn: 374297
2019-10-10[LLD] [MinGW] Look for other library patterns with -lMartin Storsjo1-3/+25
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-04[MinGW] Add --reproduce optionRui Ueyama2-0/+3
Differential Revision: https://reviews.llvm.org/D68382 llvm-svn: 373705
2019-08-14[MinGW] Correct handling different forms of a few optionsMartin Storsjo1-5/+4
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[MinGW] Restructure Options.td to use multiclass where sensible. NFC.Martin Storsjo1-33/+29
Differential Revision: https://reviews.llvm.org/D66065 llvm-svn: 368815
2019-08-05[MinGW] Add an lld specific option for requesting to delay load librariesMartin Storsjo2-0/+4
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-07-11[Coding style change][lld] Rename variables for non-ELF portsRui Ueyama1-175/+175
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-05lld, llvm-dlltool, llvm-lib: Use getAsString() instead of getSpelling() for ↵Nico Weber1-1/+1
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-05Make joined instances of JoinedOrSeparate flags point to the unaliased args, ↵Nico Weber1-1/+1
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-06-14[MinGW] Support the --subsystem=val option in joined formMartin Storsjo1-0/+1
Differential Revision: https://reviews.llvm.org/D63250 llvm-svn: 363433
2019-06-14[MinGW] Support the --{major,minor}-{os,subsystem}-version optionsMartin Storsjo2-1/+40
This fixes PR42218. Differential Revision: https://reviews.llvm.org/D63249 llvm-svn: 363432
2019-06-10[Driver] Look for -m in response files as wellMartin Storsjo1-0/+9
Also expand response files in the MinGW driver. This should fix PR42135. Differential Revision: https://reviews.llvm.org/D63024 llvm-svn: 362977
2019-06-08[MinGW] Support the -u/--undefined option.Martin Storsjo2-0/+6
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-05-18[MinGW] Set the right updated option help for the updated pdb option. NFCMartin Storsjo1-2/+1
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-17[MinGW] Include --enable-auto-import in the help listingMartin Storsjo1-1/+1
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[MinGW] Implement the -v and --version flags for the MinGW driverMartin Storsjo2-2/+18
Differential Revision: https://reviews.llvm.org/D62030 llvm-svn: 361016
2019-05-17[MinGW] Implement --help for the MinGW driverMartin Storsjo2-2/+16
Differential Revision: https://reviews.llvm.org/D62029 llvm-svn: 361015
2019-05-17[MinGW] Allow requesting PDB output without giving a file nameMartin Storsjo2-2/+6
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