summaryrefslogtreecommitdiffstats
path: root/lld/COFF
Commit message (Collapse)AuthorAgeFilesLines
...
* [LLD] [COFF] Implement MinGW default manifest handlingMartin Storsjo2019-09-041-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In mingw environments, resources are normally compiled to resource object files directly, instead of letting the linker convert them to COFF format. Since some time, GCC supports the notion of a default manifest object. When invoking the linker, GCC looks for the default manifest object file, and if found in the expected path, it is added to linker commands. The default manifest is one that indicates support for the latest known versions of windows, to implicitly unlock the modern behaviours of certain APIs. Not all mingw/gcc distributions include this file, but e.g. in msys2, the default manifest object is distributed in a separate package (which can be but might not always be installed). This means that even if user projects only use one single resource object file, the linker can end up with two resource object files, and thus needs to support merging them. The default manifest has a language id of zero, and GNU ld has got logic for dropping a manifest with a zero language id, if there's another manifest present with a nonzero language id. If there are multiple manifests with a nonzero language id, the merging process errors out. Differential Revision: https://reviews.llvm.org/D66825 llvm-svn: 370974
* reland "[lld-link] implement -start-lib and -end-lib"Bob Haarman2019-09-0311-70/+232
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This is a re-land of r370487 with a fix for the use-after-free bug that rev contained. This implements -start-lib and -end-lib flags for lld-link, analogous to the similarly named options in ld.lld. Object files after -start-lib are included in the link only when needed to resolve undefined symbols. The -end-lib flag goes back to the normal behavior of always including object files in the link. This mimics the semantics of static libraries, but without needing to actually create the archive file. Reviewers: ruiu, smeenai, MaskRay Reviewed By: ruiu, MaskRay Subscribers: akhuang, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66848 llvm-svn: 370816
* [LLD] [COFF] Demangle itanium symbols in mingw modeMartin Storsjo2019-09-021-1/+12
| | | | | | Differential Revision: https://reviews.llvm.org/D67051 llvm-svn: 370654
* Revert "[lld-link] implement -start-lib and -end-lib"Vlad Tsyrklevich2019-08-3011-232/+70
| | | | | | | This reverts commit r370487 as it is causing ASan/MSan failures on sanitizer-x86_64-linux-fast llvm-svn: 370550
* [lld-link] implement -start-lib and -end-libBob Haarman2019-08-3011-70/+232
| | | | | | | | | | | | | | | | | | | | | | | Summary: This implements -start-lib and -end-lib flags for lld-link, analogous to the similarly named options in ld.lld. Object files after -start-lib are included in the link only when needed to resolve undefined symbols. The -end-lib flag goes back to the normal behavior of always including object files in the link. This mimics the semantics of static libraries, but without needing to actually create the archive file. Reviewers: ruiu, smeenai, MaskRay Reviewed By: ruiu, MaskRay Subscribers: akhuang, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66848 llvm-svn: 370487
* [LLD] [COFF] Support merging resource object filesMartin Storsjo2019-08-305-41/+66
| | | | | | | | | | | | | | | | | | | | | | | | Extend WindowsResourceParser to support using a ResourceSectionRef for loading resources from an object file. Only allow merging resource object files in mingw mode; keep the existing error on multiple resource objects in link mode. If there only is one resource object file and no .res resources, don't parse and recreate the .rsrc section, but just link it in without inspecting it. This allows users to produce any .rsrc section (outside of what the parser supports), just like before. (I don't have a specific need for this, but it reduces the risk of this new feature.) Separate out the .rsrc section chunks in InputFiles.cpp, and only include them in the list of section chunks to link if we've determined that there only was one single resource object. (We need to keep other chunks from those object files, as they can legitimately contain other sections as well, in addition to .rsrc section chunks.) Differential Revision: https://reviews.llvm.org/D66824 llvm-svn: 370436
* Fight a bit against global initializers. NFC.Benjamin Kramer2019-08-221-2/+2
| | | | llvm-svn: 369695
* [COFF] Add libcall symbols to the link when LTO is being usedAmy Huang2019-08-225-0/+39
| | | | llvm-svn: 369694
* [lld-link] implement -lto-obj-pathBob Haarman2019-08-214-0/+9
| | | | | | | | | | | | | | | | | | | Summary: This adds the -lto-obj-path option to lld-link. This can be used to specify a path at which to write a native object file for the full LTO part when using LTO unit splitting. Reviewers: ruiu, tejohnson, pcc, rnk Reviewed By: ruiu, rnk Subscribers: mehdi_amini, steven_wu, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65964 llvm-svn: 369559
* [COFF] Check errorCount before committing the output fileMartin Storsjo2019-08-201-0/+3
| | | | | | | | | | | | This avoids producing an output file if errors appeared late in the linking process (e.g. while fixing relocations, or as in the test, while checking for multiple resources). If an output file is produced, build tools might not retry building it on rebuilds, even if a previous build failed due to the error return code. Differential Revision: https://reviews.llvm.org/D66491 llvm-svn: 369445
* [COFF] Print the file name on errors writing the pdb fileMartin Storsjo2019-08-201-0/+1
| | | | | | | | | | | This avoids confusing contextless error messages such as "No such file or directory" if e.g. the pdb output file should be written to a nonexistent directory. (This can happen with linkrepro scripts, at least old ones.) Differential Revision: https://reviews.llvm.org/D66466 llvm-svn: 369425
* [COFF] Require an explicit -implib option for creating implibs in mingw modeMartin Storsjo2019-08-201-2/+4
| | | | | | | | GNU ld doesn't produce implibs unless explicitly requested. Differential Revision: https://reviews.llvm.org/D66367 llvm-svn: 369363
* [COFF] Allow using custom .edata from input object filesMartin Storsjo2019-08-203-7/+22
| | | | | | | | | | | | | | | | | | | | This is used by Wine for manually crafting export tables. If the input object contains .edata sections, GNU ld references them in the export directory instead of synthesizing an export table using either export directives or the normal auto export mechanism. (AFAIK, historically, way way back, GNU ld didn't support synthesizing the export table - one was supposed to generate it using dlltool and link it in instead.) If faced with --out-implib and --output-def, GNU ld still populates those output files with the same export info as it would have generated otherwise, disregarding the input .edata. As this isn't an intended usage combination, I'm not adding checks for that in tests. Differential Revision: https://reviews.llvm.org/D65903 llvm-svn: 369358
* [LLD] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere2019-08-142-5/+5
| | | | | | | | | | Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. Differential revision: https://reviews.llvm.org/D66259 llvm-svn: 368936
* [lld] Remove unnecessary "class Lazy"Bob Haarman2019-08-131-1/+0
| | | | llvm-svn: 368644
* Handle /align option.Rui Ueyama2019-08-073-4/+15
| | | | | | Differential Revision: https://reviews.llvm.org/D65736 llvm-svn: 368145
* Re-submit r367649: Improve raw_ostream so that you can "write" colors using ↵Rui Ueyama2019-08-072-7/+7
| | | | | | | | | operator<< The original patch broke buildbots, perhaps because it changed the default setting whether colors are enabled or not. llvm-svn: 368131
* [COFF] Omit automatically imported symbols from the symbol tableMartin Storsjo2019-08-051-0/+7
| | | | | | | | | | | | | | | | | | | | These symbols actually point to the symbol's IAT entry, which obviously is different from the symbol itself (which is imported from a different module and doesn't exist in the current one). Omitting this symbol helps gdb inspect automatically imported symbols, see https://sourceware.org/bugzilla/show_bug.cgi?id=24574 for discussion on the matter. Surprisingly, those extra symbols don't seem to be an issue for gdb when the sources have been built with clang, only with gcc. The actual logic in gdb that this depends on still is unknown, but omitting these symbols from the symbol table is the right thing to do in any case. Differential Revision: https://reviews.llvm.org/D65727 llvm-svn: 367836
* Rename F_{None,Text,Append} to OF_{None,Text,Append}. NFCFangrui Song2019-08-054-6/+6
| | | | | | F_{None,Text,Append} are kept for compatibility since r334221. llvm-svn: 367800
* [COFF] Clarify a comment. NFC.Martin Storsjo2019-08-021-1/+1
| | | | | | | It's the __delayLoadHelper2 function that overwrites the jump table slot, not this thunk. llvm-svn: 367674
* [COFF] Avoid loading objects for mingw autoimport, when a defined alias existsMartin Storsjo2019-08-021-0/+2
| | | | | | | | | This avoids a spurious and confusing log message in cases where both e.g. "alias" and "__imp_alias" exist. Differential Revision: https://reviews.llvm.org/D65598 llvm-svn: 367673
* Revert r367649: Improve raw_ostream so that you can "write" colors using ↵Rui Ueyama2019-08-022-5/+5
| | | | | | | | operator<< This reverts commit r367649 in an attempt to unbreak Windows bots. llvm-svn: 367658
* Improve raw_ostream so that you can "write" colors using operator<<Rui Ueyama2019-08-022-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1. raw_ostream supports ANSI colors so that you can write messages to the termina with colors. Previously, in order to change and reset color, you had to call `changeColor` and `resetColor` functions, respectively. So, if you print out "error: " in red, for example, you had to do something like this: OS.changeColor(raw_ostream::RED); OS << "error: "; OS.resetColor(); With this patch, you can write the same code as follows: OS << raw_ostream::RED << "error: " << raw_ostream::RESET; 2. Add a boolean flag to raw_ostream so that you can disable colored output. If you disable colors, changeColor, operator<<(Color), resetColor and other color-related functions have no effect. Most LLVM tools automatically prints out messages using colors, and you can disable it by passing a flag such as `--disable-colors`. This new flag makes it easy to write code that works that way. Differential Revision: https://reviews.llvm.org/D65564 llvm-svn: 367649
* Fix an unused variable warning.Rui Ueyama2019-08-021-1/+1
| | | | llvm-svn: 367643
* [COFF] Fix wholearchive with thin archivesMartin Storsjo2019-08-011-1/+3
| | | | | | | | | | | | | | | | | | | | | The Archive object created when loading an archive specified with wholearchive got cleaned up immediately, when the owning std::unique_ptr went out of scope, even if persisted StringRefs pointed to memory that belonged to the archive, which no longer was mapped in memory. This hasn't been an issue with regular (as opposed to thin) archives, as references to the member objects has kept the mapping for the whole archive file alive - but with thin archives, all such references point to other files. Add the std::unique_ptr to the arena allocator, to retain it as long as necessary. This fixes (the last issue raised in) PR42388. Differential Revision: https://reviews.llvm.org/D65565 llvm-svn: 367599
* [lld-link] diagnose undefined symbols before LTO when possibleBob Haarman2019-07-263-70/+159
| | | | | | | | | | | | | | | | | | | | | | Summary: This allows reporting undefined symbols before LTO codegen is run. Since LTO codegen can take a long time, this improves user experience by avoiding that time spend if the link is going to fail with undefined symbols anyway. Fixes PR32400. Reviewers: ruiu Reviewed By: ruiu Subscribers: mehdi_amini, steven_wu, dexonsmith, mstorsjo, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D62434 llvm-svn: 367136
* ld.lld: Demangle symbols from archives in diagnosticsNico Weber2019-07-234-9/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | This ports r366573 from COFF to ELF. There are now to toString(Archive::Symbol), one doing MSVC demangling in COFF and one doing Itanium demangling in ELF, so rename these two to toCOFFString() and to toELFString() to not get a duplicate symbol. Nothing ever passes a raw Archive::Symbol to CHECK(), so these not being part of the normal toString() machinery seems ok. There are two code paths in the ELF linker that emits this type of diagnostic: 1. The "normal" one in InputFiles.cpp. This is covered by the tweaked test. 2. An additional one that's only used for libcalls if there's at least one bitcode in the link, and if the libcall symbol is lazy, and lazily loaded from an archive (i.e. not from a lazy .o file). (This code path was added in r339301.) Since all libcall names so far are C symbols and never mangled, the change there is not observable and hence not covered by tests. Differential Revision: https://reviews.llvm.org/D65095 llvm-svn: 366836
* [COFF] Unbreak sorting of mingw comdat .tls sections after SVN r363457Martin Storsjo2019-07-231-4/+23
| | | | | | | | | | | | | | | | | | | | | | | | Code built for mingw with -fdata-sections will store each TLS variable in a comdat section, named .tls$$<varname>. Normal TLS variables are stored in sections named .tls$ with a trailing dollar, which are sorted after a starter marker (in a later linked object file) in a section named ".tls" (with no dollar suffix), before an ending marker in a section named ".tls$ZZZ". The mingw comdat section suffix stripping introduced in SVN r363457 broke sorting of such tls sections, ending up sorting the stripped .tls$$<varname> sections (stripped to ".tls") before the start marker in the section named ".tls". We could add exceptions to the section name suffix stripping for .tls (and .CRT, where suffixes always should be honored), but the more conservative option is probably the reverse; to only apply the stripping for the normal sections where sorting shouldn't have any effect. Differential Revision: https://reviews.llvm.org/D65018 llvm-svn: 366780
* lld-link: Demangle symbols from archives in diagnosticsNico Weber2019-07-198-24/+26
| | | | | | | | | Also add test coverage for thin archives (which are the only way I could come up with to test at least some of the diagnostic changes). Differential Revision: https://reviews.llvm.org/D64927 llvm-svn: 366573
* [COFF] Implement /safeseh:no and check @feat.00 flags by defaultReid Kleckner2019-07-163-21/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Fixes PR41828. Before this, LLD always emitted SafeSEH chunks and defined __safe_se_handler_table & size. Now, /safeseh:no leaves those undefined. Additionally, we were checking for the safeseh @feat.00 flag in two places: once to emit errors, and once during safeseh table construction. The error was set up to be off by default, but safeseh is supposed to be on by default. I combined the two checks, so now LLD emits an error if an input object lacks @feat.00 and safeseh is enabled. This caused the majority of 32-bit LLD tests to fail, since many test input object files lack @feat.00 symbols. I explicitly added -safeseh:no to those tests to preserve behavior. Finally, LLD no longer sets IMAGE_DLL_CHARACTERISTICS_NO_SEH if any input file wasn't compiled for safeseh. Reviewers: mstorsjo, ruiu, thakis Reviewed By: ruiu, thakis Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63570 llvm-svn: 366238
* [COFF] Rename variale references in comments after VariableName -> ↵Fangrui Song2019-07-1611-24/+24
| | | | | | variableName change llvm-svn: 366193
* Fix parameter name comments using clang-tidy. NFC.Rui Ueyama2019-07-162-3/+3
| | | | | | | | | | | | | | | | | | | | | This patch applies clang-tidy's bugprone-argument-comment tool to LLVM, clang and lld source trees. Here is how I created this patch: $ git clone https://github.com/llvm/llvm-project.git $ cd llvm-project $ mkdir build $ cd build $ cmake -GNinja -DCMAKE_BUILD_TYPE=Debug \ -DLLVM_ENABLE_PROJECTS='clang;lld;clang-tools-extra' \ -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DLLVM_ENABLE_LLD=On \ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ../llvm $ ninja $ parallel clang-tidy -checks='-*,bugprone-argument-comment' \ -config='{CheckOptions: [{key: StrictMode, value: 1}]}' -fix \ ::: ../llvm/lib/**/*.{cpp,h} ../clang/lib/**/*.{cpp,h} ../lld/**/*.{cpp,h} llvm-svn: 366177
* Reland "[COFF] Add null check in case of symbols defined in LTO blobs"Reid Kleckner2019-07-151-1/+1
| | | | | | | | | | This reverts r365990 (git commit 1a6053ebc61cb0b8146f5ca27b74859a9a91e0a3) The test no longer depends on the Visual C++ libraries. I confirmed that the crash still reproduces with the new test case if I remove the null check. llvm-svn: 366095
* Revert "[COFF] Add null check in case of symbols defined in LTO blobs"Petr Hosek2019-07-131-1/+1
| | | | | | This reverts commit r365979: COFF/undefined-symbol-lto.test is failing. llvm-svn: 365990
* [COFF] Add null check in case of symbols defined in LTO blobsReid Kleckner2019-07-131-1/+1
| | | | | | | | | The test case could probably be improved further if the failure path was better understood. Fixes PR42536 llvm-svn: 365979
* Fix odd variable names.Rui Ueyama2019-07-125-7/+7
| | | | llvm-svn: 365875
* [COFF] Share the tail in delayimport symbol thunksMartin Storsjo2019-07-112-31/+126
| | | | | | | | | | | | | E.g. for x86_64, previously each symbol's thunk was 87 bytes. Now there's a 12 byte thunk per symbol, plus a shared 83 byte tail function. This is similar to what both MS link.exe and GNU tools do for delay imports. Differential Revision: https://reviews.llvm.org/D64288 llvm-svn: 365823
* [lld-link] implement -thinlto-{prefix,object-suffix}-replaceBob Haarman2019-07-116-5/+55
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: Adds the following two options to lld-link: -thinlto-prefix-replace: allows replacing a prefix in paths generated for ThinLTO. This can be used to ensure index files and native object files are stored in unique directories, allowing multiple distributed ThinLTO links to proceed concurrently. -thinlto-object-suffix-replace: allows replacing a suffix in object file paths involved in ThinLTO. This allows minimized index files to be used for the thin link while storing the paths to the full bitcode files for subsequent steps (code generation and final linking). Reviewers: ruiu, tejohnson, pcc, rnk Subscribers: mehdi_amini, steven_wu, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64542 llvm-svn: 365807
* [lld-link] implement -thinlto-index-onlyBob Haarman2019-07-115-7/+86
| | | | | | | | | | | | | | | | | | | | | | | Summary: This implements -thinlto-index-only, -thinlto-index-only:, and -thinlto-emit-imports-files options in lld-link. They are analogous to their counterparts in ld.lld: -thinlto-index-only causes us to perform ThinLTO's thin link and write index files, but not perform code generation. -thinlto-index-only: does the same, but also writes a text file listing the native object files expected to be generated. -thinlto-emit-imports-files creates a text file next to each index file, listing the files to import from. Reviewers: ruiu, tejohnson, pcc, rnk Subscribers: mehdi_amini, steven_wu, dexonsmith, arphaman, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64461 llvm-svn: 365800
* Fix build breakage on Win32.Rui Ueyama2019-07-111-1/+1
| | | | llvm-svn: 365737
* Update comments for r365730. NFC.Rui Ueyama2019-07-111-1/+1
| | | | llvm-svn: 365733
* [Coding style change][lld] Rename variables for non-ELF portsRui Ueyama2019-07-1131-5781/+5781
| | | | | | | | | | | 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
* Make functions and member variables distinguishable even after the name ↵Rui Ueyama2019-07-107-19/+14
| | | | | | style change. NFC. llvm-svn: 365605
* lld-link: Stop accepting /natvis and /fastfail in .drectve sectionsNico Weber2019-07-091-2/+2
| | | | | | | | link.exe doesn't accept them either. Differential Revision: https://reviews.llvm.org/D64352 llvm-svn: 365478
* lld, llvm-dlltool, llvm-lib: Use getAsString() instead of getSpelling() for ↵Nico Weber2019-07-051-3/+3
| | | | | | | | | | | | | | | 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
* Make joined instances of JoinedOrSeparate flags point to the unaliased args, ↵Nico Weber2019-07-051-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
* lld-link: Make /debugtype: option work betterNico Weber2019-07-051-2/+3
| | | | | | | | | | | | | | | | | | | - The code tried to pass false to split()'s KeepEmpty parameter, but instead passed it to MaxSplit. As a result, it would never split on commas. This has been broken since the flag was added in r278056. - The code used getSpelling() for getting the argument's values, but getSpelling() always returns the `/debugtype:` prefix without any values. So if any /debugtype: flag was passed, it always resulted in an "unknown option:" warning. (The warning code then used the correct getValue() for printing the invalid option, so the warning looked kind of like it made sense.) This regressed in r342894. Slightly improve the test coverage of this feature (but since I don't know what this flag actually does, there's still no test for the correct semantics), and add a comment to getSpelling() explaining what it does. llvm-svn: 365182
* [COFF] Fix .rsrc sections with differing permissionsMartin Storsjo2019-06-281-11/+21
| | | | | | | | | | | GNU windres, and MS cvtres (unless the /readonly option is passed) produce read-write .rsrc sections, when creating resource object files. This caused the sections to not be added to the precreated RsrcSec, and therefore not be added to the data directory. Differential Revision: https://reviews.llvm.org/D63837 llvm-svn: 364660
* Fix lld build on Windows with MSVC due to C2461Michael Liao2019-06-271-2/+2
| | | | | | | | - It seems the same name of class and one of its fields confuses MSVC, https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2461?view=vs-2019 - Patch from Andryeyev, German <german.andryeyev@amd.com> llvm-svn: 364567
* [LLD][COFF] Case insensitive compares for /nodefaultlibAlexandre Ganea2019-06-262-4/+4
| | | | | | Differential Revision: https://reviews.llvm.org/D63775 llvm-svn: 364438
OpenPOWER on IntegriCloud