summaryrefslogtreecommitdiffstats
path: root/lld/COFF
Commit message (Collapse)AuthorAgeFilesLines
...
* Port r363962 to COFF: Deduplicate undefined symbol diagnosticsNico Weber2019-06-253-11/+69
| | | | | | | | | | | | | | | | | | lld/coff already deduplicated undefined symbols on a TU level: It would group all references to a symbol from a single TU. This makes it so that references from all TUs to a single symbol are grouped together. Since lld/coff almost did what I thought it did already, the patch is much smaller than the elf version. The only not local change is that getSymbolLocations() now returns a vector<string> instead of a string, so that the undefined symbol reporting code can know how many references to a symbol exist in a given TU. Fixes PR42260 for lld/coff. Differential Revision: https://reviews.llvm.org/D63646 llvm-svn: 364285
* [PDB] Ignore .debug$S subsections with high bit setReid Kleckner2019-06-181-0/+5
| | | | | | | | Some versions of the Visual C++ 2015 runtime have line tables with the subsection kind of 0x800000F2. In cvinfo.h, 0x80000000 is documented to be DEBUG_S_IGNORE. This appears to implement the intended behavior. llvm-svn: 363724
* Include the file in the new unknown codeview subsection warningReid Kleckner2019-06-141-1/+1
| | | | llvm-svn: 363466
* [COFF] Strip section name suffix from mingw comdatsMartin Storsjo2019-06-141-1/+7
| | | | | | | | This is the second part of the fix for PR42217. Differential Revision: https://reviews.llvm.org/D63352 llvm-svn: 363457
* [COFF] Handle .eh_frame$symbol as associative comdat for MinGWMartin Storsjo2019-06-141-3/+6
| | | | | | | | | | | | | This matches how it is done for .xdata and .pdata already. On i386, the symbol name in the section name suffix does not contain the extra underscore prefix. This is one part of a fix for PR42217. Differential Revision: https://reviews.llvm.org/D63350 llvm-svn: 363456
* [COFF] Allow setting subsystem versions while inferring the subsystem type ↵Martin Storsjo2019-06-141-2/+4
| | | | | | | | implicitly Differential Revision: https://reviews.llvm.org/D63248 llvm-svn: 363431
* lld/coff: slightly simplify ImportFile::parse()Nico Weber2019-06-141-2/+1
| | | | llvm-svn: 363397
* [lld] Fix type server merging with PDBs without IPI streamReid Kleckner2019-06-121-13/+20
| | | | | | | | | | | | | | | PDBs may not necessarily contain an IPI stream. Handle this case gracefully. The test case was verified to work with MS link.exe. Patch by Vladimir Panteleev, with a small simplification Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D63178 llvm-svn: 363213
* [lld] Allow unrecognized signatures in debug sectionsReid Kleckner2019-06-121-4/+7
| | | | | | | | | | | | | | | | | | An unrecognized signature (magic) at the beginning of a debug section should not be a fatal error; it only means that the debug information is in a format that is not supported by LLD. This can be due to it being in CodeView versions 3 or earlier. These can occur in old import libraries from legacy SDKs. The test case was verified to work with MS link.exe. Patch by Vladimir Panteleev! Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D63177 llvm-svn: 363212
* Share /machine: handling code with llvm-cvtres tooNico Weber2019-06-122-2/+3
| | | | | | | | | | | | | | r363016 let lld-link and llvm-lib share the /machine: parsing code. This lets llvm-cvtres share it as well. Making llvm-cvtres depend on llvm-lib seemed a bit strange (it doesn't need llvm-lib's dependencies on BinaryFormat and BitReader) and I couldn't find a good place to put this code. Since it's just a few lines, put it in lib/Object for now. Differential Revision: https://reviews.llvm.org/D63120 llvm-svn: 363144
* lld-link: Reject more than one resource .obj fileNico Weber2019-06-114-3/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Users are exepcted to pass all .res files to the linker, which then merges all the resource in all .res files into a tree structure and then converts the final tree structure to a .obj file with .rsrc$01 and .rsrc$02 sections and then links that. If the user instead passes several .obj files containing such resources, the correct thing to do would be to have custom code to merge the trees in the resource sections instead of doing normal section merging -- but link.exe rejects if multiple resource obj files are passed in with LNK4078, so let lld-link do that too instead of silently writing broken .rsrc sections in that case. The only real way to run into this is if users manually convert .res files to .obj files by running cvtres and then handing the resulting .obj files to lld-link instead, which in practice likely never happens. (lld-link is slightly stricter than link.exe now: If link.exe is passed one .obj file created by cvtres, and a .res file, for some reason it just emits a warning instead of an error and outputs strange looking data. lld-link now errors out on mixed input like this.) One way users could accidentally run into this is the following scenario: If a .res file is passed to lib.exe, then lib.exe calls cvtres.exe on the .res file before putting it in the output .lib. (llvm-lib currently doesn't do this.) link.exe's /wholearchive seems to only add obj files referenced from the static library index, but lld-link current really adds all files in the archive. So if lld-link /wholearchive is used with .lib files produced by lib.exe and .res files were among the files handed to lib.exe, we previously silently produced invalid output, but now we error out. link.exe's /wholearchive semantics on the other hand mean that it wouldn't load the resource object files from the .lib file at all. Since this scenario is probably still an unlikely corner case, the difference in behavior here seems fine -- and lld-link might have to change to use link.exe's /wholearchive semantics in the future anyways. Vaguely related to PR42180. Differential Revision: https://reviews.llvm.org/D63109 llvm-svn: 363078
* Let writeWindowsResourceCOFF() take a TimeStamp parameterNico Weber2019-06-111-1/+2
| | | | | | | | | | | | | | | | | | | For lld, pass in Config->Timestamp (which is set based on lld's /timestamp: and /Brepro flags). Since the writeWindowsResourceCOFF() data is only used in-memory by LLD and the obj's timestamp isn't used for anything in the output, this doesn't change behavior. For llvm-cvtres, add an optional /timestamp: parameter, and use the current behavior of calling time() if the parameter is not passed in. This doesn't really change observable behavior (unless someone passes /timestamp: to llvm-cvtres, which wasn't possible before), but it removes the last unqualified call to time() from llvm/lib, which seems like a good thing. Differential Revision: https://reviews.llvm.org/D63116 llvm-svn: 363050
* Wrap comment to 80 columnsNico Weber2019-06-111-3/+3
| | | | llvm-svn: 363017
* llvm-lib: Implement /machine: argumentNico Weber2019-06-114-33/+5
| | | | | | | | | | And share some code with lld-link. While here, also add a FIXME about PR42180 and merge r360150 to llvm-lib. Differential Revision: https://reviews.llvm.org/D63021 llvm-svn: 363016
* [LLD][COFF] Fix missing MergeChunk::Instances cleanup in COFF::link()Rui Ueyama2019-06-101-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Patch by Erik McClure with a modification to rebase to HEAD. When calling `COFF::link()` with `CanExitEarly` set to `false`, the function needs to clean up several global variable caches to ensure that the next invocation of the function starts from a clean slate. The `MergeChunk::Instances` cache is missing from this cleanup code, and as a result will create nondeterministic memory access errors and sometimes infinite loops due to invalid memory being referenced on the next call to `COFF::link()`. This fix simply clears `MergeChunk::Instances` before exiting the function. An additional review of the COFF library was made to try and find any other missing global caches, but I was unable to find any other than `MergeChunk`. Someone more familiar with the global variables might want to do their own check. This fix was made to support inNative <https://github.com/innative-sdk/innative>'s `.wast` script compiler, which must build multiple incremental builds. It relies on statically linking LLD because the entire compiler must be a single statically embeddable library, thus preventing it from being able to call LLD as a new process. Differential Revision: https://reviews.llvm.org/D63042 llvm-svn: 362930
* [COFF] Add an lld specific option /includeoptionalMartin Storsjo2019-06-082-0/+10
| | | | | | | | | This works like /include, but is not fatal if the requested symbol wasn't found. This allows implementing the GNU ld option -u. Differential Revision: https://reviews.llvm.org/D62976 llvm-svn: 362881
* [COFF] Fix /export:foo=bar when bar is a weak aliasReid Kleckner2019-06-075-45/+61
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: When handling exports from the command line or from .def files, the linker does a "fuzzy" string lookup to allow finding mangled symbols. However, when the symbol is re-exported under a new name, the linker has to transfer the decorations from the exported symbol over to the new name. This is implemented by taking the mangled symbol that was found in the object and replacing the original symbol name with the export name. Before this patch, LLD implemented the fuzzy search by adding an undefined symbol with the unmangled name, and then during symbol resolution, checking if similar mangled symbols had been added after the last round of symbol resolution. If so, LLD makes the original symbol a weak alias of the mangled symbol. Later, to get the original symbol name, LLD would look through the weak alias and forward it on to the import library writer, which copies the symbol decorations. This approach doesn't work when bar is itself a weak alias, as is the case in asan. It's especially bad when the aliasee of bar contains the string "bar", consider "bar_default". In this case, we would end up exporting the symbol "foo_default" when we should've exported just "foo". To fix this, don't look through weak aliases to find the mangled name. Save the mangled name earlier during fuzzy symbol lookup. Fixes PR42074 Reviewers: mstorsjo, ruiu Subscribers: thakis, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D62984 llvm-svn: 362849
* [LLD][COFF] Don't take into account the 'age' when looking for PDB type serverAlexandre Ganea2019-06-051-2/+2
| | | | | | | | The age field is only there to say how many times an OBJ or a PDB was incrementally linked. It shouldn't be used to validate the link between the OBJ and the PDB. Differential Revision: https://reviews.llvm.org/D62837 llvm-svn: 362572
* [PDB] Copy inlinee lines records into the PDBReid Kleckner2019-06-031-16/+87
| | | | | | | | | | | | | | | | | | Summary: - Fixes inline call frame line table display in windbg. - Improve llvm-pdbutil to dump extra file ids. - Warn on unknown subsections so we don't have this kind of bug in the future. Reviewers: inglorion, akhuang, aganea Subscribers: eraman, zturner, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D62701 llvm-svn: 362429
* Re-land [LLD][COFF] Early load PDB type server filesAlexandre Ganea2019-06-035-139/+234
| | | | | | | | | | We need to have all input files ready before doing debuginfo type merging. This patch is moving the late PDB type server discovery much earlier in the process, when the explicit inputs (OBJs, LIBs) are loaded. The short term goal is to parallelize type merging. Differential Revision: https://reviews.llvm.org/D60095 llvm-svn: 362393
* Revert r361842 as it breaks LLDB :: tools/lldb-mi/exec/exec-finish.testAlexandre Ganea2019-05-285-232/+138
| | | | llvm-svn: 361876
* [COFF] Add ImportChunkThunk, simplify, deduplicateReid Kleckner2019-05-282-48/+32
| | | | | | | | | | | Removes the isHotPatchable faux-virtual and virtual methods. Follow-up to D62362. Reviewers: aganea Differential Revision: https://reviews.llvm.org/D62422 llvm-svn: 361851
* [LLD][COFF] Early load PDB type server filesAlexandre Ganea2019-05-285-138/+232
| | | | | | | | | | We need to have all input files ready before doing debuginfo type merging. This patch is moving the late PDB type server discovery much earlier in the process, when the explicit inputs (OBJs, LIBs) are loaded. The short term goal is to parallelize type merging. Differential Revision: https://reviews.llvm.org/D60095 llvm-svn: 361842
* Fix 'warning: comparison is always true due to limited range of data type ↵Alexandre Ganea2019-05-281-1/+1
| | | | | | [-Wtype-limits]' with GCC 7.3 llvm-svn: 361840
* [COFF] De-virtualize Chunk and SectionChunkReid Kleckner2019-05-244-71/+169
| | | | | | | | | | | | | | | | Shaves another pointer off of SectionChunk, reducing the size from 96 to 88 bytes, down from 144 before I started working on this. Combined with D62356, this reduced peak memory usage when linking chrome_child.dll from 713MB to 675MB, or 5%. Create NonSectionChunk to provide virtual dispatch to the rest of the chunk types. Reviewers: ruiu, aganea Differential Revision: https://reviews.llvm.org/D62362 llvm-svn: 361667
* [COFF] Replace OutputSection* with uint16_t index in ChunkReid Kleckner2019-05-244-22/+45
| | | | | | | | | | | | | | Shaves another 8 bytes off of SectionChunk, the most commonly allocated type in LLD. These indices are only valid after we've assigned chunks to output sections and removed empty sections, so do that in a new pass. Reviewers: ruiu, aganea Differential Revision: https://reviews.llvm.org/D62356 llvm-svn: 361657
* [LLD][COFF] Implement /filealign parameterRui Ueyama2019-05-244-6/+14
| | | | | | | | | | | | | | Patch by Stefan Schmidt. This adds the /filealign parameter to lld, which allows to specify the section alignment in the output file (as it does on Microsoft's link.exe). This is required to be able to load dynamically linked libraries on the original Xbox, where the debugger monitor expects the section alignment in the file to be the same as in memory. llvm-svn: 361634
* [COFF] Remove finalizeContents virtual method from Chunk, NFCReid Kleckner2019-05-243-15/+20
| | | | | | | | | This only needs to be done for MergeChunks, so just do that in a separate pass in the Writer. This is one small step towards eliminating the vtable in Chunk. llvm-svn: 361573
* [COFF] Move KeepUnique bit from Chunk to SectionChunk, NFCReid Kleckner2019-05-232-8/+6
| | | | | | | | The KeepUnique bit is used during ICF, which only operates on SectionChunks, so only SectionChunks need it. This frees up a byte in Chunk, which I plan to use in a follow-up change. llvm-svn: 361549
* lld-link, clang: Treat non-existent input files as possible spellos for ↵Nico Weber2019-05-232-4/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | option flags OptTable treats arguments starting with / that aren't a known option as filenames. This means lld-link's and clang-cl's typo correction for unknown flags didn't do spell checking for misspelled options that start with /. I first tried changing OptTable, but that got pretty messy, see PR41787 comments 2 and 3. Instead, let lld-link's and clang's (including clang-cl's) "file not found" diagnostic check if a non-existent file looks like it could be a mis-spelled option, and if so add a "did you mean" suggestion to the "file not found" diagnostic. While here, make formatting of a few diagnostics a bit more self-consistent. Fixes PR41787. Differential Revision: https://reviews.llvm.org/D62276 llvm-svn: 361518
* Re-land r361206 "[COFF] Store alignment in log2 form, NFC"Reid Kleckner2019-05-227-31/+55
| | | | | | | | | The previous patch lost the call to PowerOf2Ceil, which causes LLD to crash when handling common symbols with a non-power-of-2 size. I tweaked the existing common.test to make the bsspad16 common symbol be 15 bytes to add coverage for this case. llvm-svn: 361426
* Revert r361206 "[COFF] Store alignment in log2 form, NFC"Nico Weber2019-05-217-53/+30
| | | | | | Makes the linker crash when linking nasm.exe. llvm-svn: 361212
* [COFF] Store alignment in log2 form, NFCReid Kleckner2019-05-207-30/+53
| | | | | | | | | | | | | | | | | Summary: Valid section or chunk alignments are powers of 2 in the range [1, 8192]. These can be stored more canonically in log2 form to free up some bits in Chunk. Combined with D61696, SectionChunk gets 8 bytes smaller. Reviewers: ruiu, aganea Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D61698 llvm-svn: 361206
* [Object] Change ObjectFile::getSectionContents to return ↵Fangrui Song2019-05-143-3/+4
| | | | | | | | | | | | | | | | | | | Expected<ArrayRef<uint8_t>> Change std::error_code getSectionContents(DataRefImpl, StringRef &) const; to Expected<ArrayRef<uint8_t>> getSectionContents(DataRefImpl) const; Many object formats use ArrayRef<uint8_t> as the underlying type, which is generally better than StringRef to represent binary data, so change the type to decrease the number of type conversions. Reviewed By: ruiu, sbc100 Differential Revision: https://reviews.llvm.org/D61781 llvm-svn: 360648
* [COFF] Simplify Chunk::writeTo and remove OutputSectionOff, NFCReid Kleckner2019-05-095-83/+78
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Prior to this change, every implementation of writeTo would add OutputSectionOff to the output section buffer start before writing data. Instead, do this math in the caller, so that it can be written once instead of many times. The output section offset is always equivalent to the difference between the chunk RVA and the output section RVA, so we can replace the one remaining usage of OutputSectionOff with that subtraction. This doesn't change the size of SectionChunk because of alignment requirements, but I will rearrange the fields in a follow-up change to accomplish that. Reviewers: ruiu, aganea Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D61696 llvm-svn: 360376
* [lld-link] initialize targets and asmparsers before invoking libBob Haarman2019-05-081-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | Summary: When using lld-link to build static libraries containing object files with module assembly, the program would crash with "Assertion `T && T->hasMCAsmParser()' failed". This change causes the code in lld-link that initialized Targets, TargetInfos, and AsmParsers (which already existed) to be run before entering the lib building path (which needs it). This avoids the error (and is what llvm-lib and llvm-ar do, too). Fixes PR41803. Reviewers: ruiu, rnk, hans Reviewed By: ruiu Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D61699 llvm-svn: 360295
* [COFF] Store Chunk RVAs and section offsets as uint32_tReid Kleckner2019-05-072-9/+15
| | | | | | | Saves 8 bytes on SectionChunk, one of the most commonly allocated data structures. llvm-svn: 360188
* lld-link: Allow /? as option prefix, like -? is allowedNico Weber2019-05-071-9/+12
| | | | | | | | | | link.exe seems to allow `/?foo` and `-?foo` in addition to `/foo` and `-foo`. Since lld-link already supports the `-?foo` spelling, support `/?foo` as well. Differential Revision: https://reviews.llvm.org/D61375 llvm-svn: 360150
* Add typo correction for command-line flags to ELF and COFF lld driversNico Weber2019-05-071-2/+8
| | | | | | | | | | | | For lld-link, unknown '/'-style flags are treated as filenames on POSIX systems, so only '-'-style flags get typo correction for now. This matches clang-cl. PR37006. Differential Revision: https://reviews.llvm.org/D61443 llvm-svn: 360145
* Shrink SectionChunk by combining Relocs and SectionName sizesReid Kleckner2019-05-036-34/+60
| | | | | | | | | | | | | | | | | SectionChunk is one of the most frequently allocated data structures in LLD, since there are about four per function when optimizations and debug info are enabled (.text, .pdata, .xdata, .debug$S). A PE COFF file cannot be larger than 2GB, so there is an inherent limit on the length of the section name and the number of relocations. Decompose the ArrayRef and StringRef into pointer and size, and put them back together in the accessors for section name and relocation list. I plan to gather complete performance numbers later by padding SectionChunk with dead data and measuring performance after all the size optimizations are done. llvm-svn: 359923
* lld-link: Add /force:multipleres extension to make dupe resource diag non-fatalNico Weber2019-05-024-1/+16
| | | | | | | As a side benefit, lld-link now reports more than one duplicate resource entry before exiting with an error even if the new flag is not passed. llvm-svn: 359829
* [Object] Change getSectionName() to return Expected<StringRef>Fangrui Song2019-05-022-4/+8
| | | | | | | | | | Summary: It currently receives an output parameter and returns std::error_code. Expected<StringRef> fits for this purpose perfectly. Differential Revision: https://reviews.llvm.org/D61421 llvm-svn: 359774
* lld-link: Make "duplicate resource" error message a bit more conciseNico Weber2019-05-021-1/+1
| | | | | | | | | | | | | | | | Reduces the error message from: lld-link: error: failed to parse .res file: duplicate resource: type STRINGTABLE (ID 6)/name ID 3/language 1033, in test1.res and in test2.res To: lld-link: error: duplicate resource: type STRINGTABLE (ID 6)/name ID 3/language 1033, in test1.res and in test2.res Make sure every error message emitted by cvtres contains the name of at least one ".res" file, so that removing the "failed to parse .res file" string doesn't lose information. Differential Revision: https://reviews.llvm.org/D61388 llvm-svn: 359749
* lld-link: Implement /swaprun: flagNico Weber2019-04-256-2/+38
| | | | | | | | | | | | | | | | r191276 added this to old LLD, but it never made it to new LLD -- except that the flag was in Options.td, so it was silently ignored. I figured it should be easy to implement, so I did that instead of removing the flags from Options.td. I then discovered that link.exe also supports comma-separated lists of 'cd' and 'net', which made the parsing code a bit annoying. The Alias technique in Options.td is to get nice help output. Differential Revision: https://reviews.llvm.org/D61067 llvm-svn: 359192
* [COFF] Don't emit .gfids sections when CFG is offReid Kleckner2019-04-241-2/+2
| | | | | | | Put them on the list of GuardFidChunks instead of the main Chunks list, even with CFG is off. It will be ignored if CFG is disabled. llvm-svn: 359137
* [LLD][COFF] Fix /linkrepro with output options that take a filename or pathAlexandre Ganea2019-04-231-0/+5
| | | | | | | | The following options: /pdb, /out or /implib now emit in the repro.tar/response.txt only a filename stripped from its path, to avoid non-existent paths on the reproducer's machine. Differential Revision: https://reviews.llvm.org/D59530 llvm-svn: 358980
* Use llvm::stable_sortFangrui Song2019-04-232-17/+14
| | | | | | | | | Make some small adjustment while touching the code: make parameters const, use less_first(), etc. Differential Revision: https://reviews.llvm.org/D60989 llvm-svn: 358943
* [COFF] Pack Name in Symbol as is done in ELFReid Kleckner2019-04-192-8/+20
| | | | | | | | | | | | | | | | | | | | | | Summary: This assumes all symbols are <4GB long, so we can store them as a 32-bit integer. This reorders the fields so the length appears first, packing with the other bitfield data in the base Symbol object. This saved 70MB / 3.60% of heap allocations when linking browser_tests.exe with no PDB. It's not much as a percentage, but worth doing. I didn't do performance measurements, I don't think it will be measurable in time. Reviewers: ruiu, inglorion, amccarth, aganea Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60297 llvm-svn: 358794
* [LLD][COFF] use offset in archive to disambiguate archive membersBob Haarman2019-04-154-10/+32
| | | | | | | | | | | | | | | | | | | | | Summary: Archives can contain multiple members with the same name. This would cause ThinLTO links to fail ("Expected at most one ThinLTO module per bitcode file"). This change implements the same strategy we use in the ELF linker: make the offset in the archive part of the module name so that names are unique. Reviewers: pcc, mehdi_amini, ruiu Reviewed By: ruiu Subscribers: eraman, steven_wu, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60549 llvm-svn: 358440
* [COFF] Link crtend.o as the last object fileMartin Storsjo2019-04-151-3/+30
| | | | | | | | | | | | | | | | | | When faced with command line options such as "crtbegin.o appmain.o -lsomelib crtend.o", GNU ld pulls in all necessary object files from somelib before proceeding to crtend.o. LLD operates differently, only loading object files from any referenced static libraries after processing all input object files. This uses a similar hack as in the ELF linker. Here, it moves crtend.o to the end of the vector of object files. This makes sure that terminator chunks for sections such as .eh_frame gets ordered last, fixing DWARF exception handling for libgcc and gcc's crtend.o. Differential Revision: https://reviews.llvm.org/D60628 llvm-svn: 358394
OpenPOWER on IntegriCloud