summaryrefslogtreecommitdiffstats
path: root/lld/COFF
Commit message (Collapse)AuthorAgeFilesLines
* Fix alignment of thunks for ARM/ARM64Martin Storsjö2020-06-172-7/+19
| | | | | | | | | | | | | | The alignment of ARM64 range extension thunks was fixed in 7c816492197a, but ARM range extension thunks, and import and delay import thunks also need aligning (like all code on ARM platforms). I'm adding a test for alignment of ARM64 import thunks - not specifically adding tests for misalignment of all of them though. Differential Revision: https://reviews.llvm.org/D77796 (cherry picked from commit 12c9e2f1110a4fc73562214cf5dd0194b31e87cf)
* [COFF] Don't treat DWARF sections as GC rootsReid Kleckner2020-04-131-2/+4
| | | | | | | | | | | | | | DWARF sections are typically live and not COMDAT, so they would be treated as GC roots. Enabling DWARF would essentially keep all code with debug info alive, preventing any section GC. Fixes PR45273 Reviewed By: mstorsjo, MaskRay Differential Revision: https://reviews.llvm.org/D76935 (cherry picked from commit c579a5b1d92a9bc2046d00ee2d427832e0f5ddec)
* [LLD][COFF] Enable linking of __declspec(selectany) symbols from Clang and GCCMarkus Böck2020-01-231-0/+11
| | | | | | | | | | | | When annotating a symbol with __declspec(selectany), Clang assigns it comdat 2 while GCC assigns it comdat 3. This patch enables two object files that contain a __declspec(selectany) symbol, one created by gcc and the other by clang, to be linked together instead of issuing a duplicate symbol error. Differential Revision: https://reviews.llvm.org/D73139 (cherry picked from commit 9dbc1ab23268abce5db98ad9a1e3aef89c371524)
* [COFF] Align ARM64 range extension thunks at instruction boundaryTom Tan2020-01-101-1/+1
| | | | | | | | | | | | | | | RangeExtensionThunkARM64 is created for out-of-range branches on Windows ARM64 because branch instructions has limited bits to encode target address. Currently, RangeExtensionThunkARM64 is appended to its referencing COFF section from object file at link time without any alignment requirement, so if size of the preceding COFF section is not aligned to instruction boundary (4 bytes), RangeExtensionThunkARM64 will emit thunk instructions at unaligned address which is never a valid branch target on ARM64, and usually triggers invalid instruction exception when branching to it. This PR fixes it by requiring such thunks to align at 4 bytes. Differential revision: https://reviews.llvm.org/D72473
* [ThinLTO] Pass CodeGenOpts like UnrollLoops/VectorizeLoop/VectorizeSLPWei Mi2020-01-091-0/+1
| | | | | | | | | | | | | down to pass builder in ltobackend. Currently CodeGenOpts like UnrollLoops/VectorizeLoop/VectorizeSLP in clang are not passed down to pass builder in ltobackend when new pass manager is used. This is inconsistent with the behavior when new pass manager is used and thinlto is not used. Such inconsistency causes slp vectorization pass not being enabled in ltobackend for O3 + thinlto right now. This patch fixes that. Differential Revision: https://reviews.llvm.org/D72386
* [LLD] [COFF] Fix post-commit suggestions for absolute symbol equalityMartin Storsjö2020-01-082-10/+3
| | | | Differential Revision: https://reviews.llvm.org/D72252
* [LLD] [COFF] Don't error out on duplicate absolute symbols with the same valueMartin Storsjö2020-01-042-2/+16
| | | | | | | | | Both MS link.exe and GNU ld.bfd handle it this way; one can have multiple object files defining the same absolute symbols, as long as it defines it to the same value. But if there are multiple absolute symbols with differing values, it is treated as an error. Differential Revision: https://reviews.llvm.org/D71981
* [PDB] Print the most redundant type record indices with /summaryReid Kleckner2020-01-021-1/+90
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: I used this information to motivate splitting up the Intrinsic::ID enum (5d986953c8b917bacfaa1f800fc1e242559f76be) and adding a key method to clang::Sema (586f65d31f32ca6bc8cfdb8a4f61bee5057bf6c8) which saved a fair amount of object file size. Example output for clang.pdb: Top 10 types responsible for the most TPI input bytes: index total bytes count size 0x3890: 8,671,220 = 1,805 * 4,804 0xE13BE: 5,634,720 = 252 * 22,360 0x6874C: 5,181,600 = 408 * 12,700 0x2A1F: 4,520,528 = 1,574 * 2,872 0x64BFF: 4,024,020 = 469 * 8,580 0x1123: 4,012,020 = 2,157 * 1,860 0x6952: 3,753,792 = 912 * 4,116 0xC16F: 3,630,888 = 633 * 5,736 0x69DD: 3,601,160 = 985 * 3,656 0x678D: 3,577,904 = 319 * 11,216 In this case, we can see that record 0x3890 is responsible for ~8MB of total object file size for objects in clang. The user can then use llvm-pdbutil to find out what the record is: $ llvm-pdbutil dump -types -type-index 0x3890 Types (TPI Stream) ============================================================ Showing 1 records. 0x3890 | LF_FIELDLIST [size = 4804] - LF_STMEMBER [name = `WORDTYPE_MAX`, type = 0x1001, attrs = public] - LF_MEMBER [name = `U`, Type = 0x37F0, offset = 0, attrs = private] - LF_MEMBER [name = `BitWidth`, Type = 0x0075 (unsigned), offset = 8, attrs = private] - LF_METHOD [name = `APInt`, # overloads = 8, overload list = 0x3805] ... In this case, we can see that these are members of the APInt class, which is emitted in 1805 object files. The next largest type is ASTContext: $ llvm-pdbutil dump -types -type-index 0xE13BE bin/clang.pdb 0xE13BE | LF_FIELDLIST [size = 22360] - LF_BCLASS type = 0x653EA, offset = 0, attrs = public - LF_MEMBER [name = `Types`, Type = 0x653EB, offset = 8, attrs = private] - LF_MEMBER [name = `ExtQualNodes`, Type = 0x653EC, offset = 24, attrs = private] - LF_MEMBER [name = `ComplexTypes`, Type = 0x653ED, offset = 48, attrs = private] - LF_MEMBER [name = `PointerTypes`, Type = 0x653EE, offset = 72, attrs = private] ... ASTContext only appears 252 times, but the list of members is long, and must be repeated everywhere it is used. This was the output before I split Intrinsic::ID: Top 10 types responsible for the most TPI input: 0x686C: 69,823,920 = 1,070 * 65,256 0x686D: 69,819,640 = 1,070 * 65,252 0x686E: 69,819,640 = 1,070 * 65,252 0x686B: 16,371,000 = 1,070 * 15,300 ... These records were all lists of intrinsic enums. Reviewers: MaskRay, ruiu Subscribers: mgrang, zturner, thakis, hans, akhuang, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D71437
* [lld] Fix -Wrange-loop-analysis warningsFangrui Song2020-01-011-4/+1
| | | | | | | | | | One instance looks like a false positive: lld/ELF/Relocations.cpp:1622:14: note: use reference type 'const std::pair<ThunkSection *, uint32_t> &' (aka 'cons t pair<lld::elf::ThunkSection *, unsigned int> &') to prevent copying for (const std::pair<ThunkSection *, uint32_t> ts : isd->thunkSections) It is not changed in this commit.
* lld: Remove explicit copy ops from AssociatedIterator, relying on implicit ↵David Blaikie2019-12-271-5/+0
| | | | operators
* [LLD] [COFF] Fix reporting duplicate errors for absolute symbolsMartin Storsjö2019-12-191-1/+3
| | | | | | | | | | | | | | Previously this caused crashes in the reportDuplicate method. A DefinedAbsolute doesn't have any InputFile attached to it, so we can't report the file for the original symbol. We could add an InputFile argument to SymbolTable::addAbsolute only for the sake of error reporting, but even then it'd be assymetrical, only pointing out the file containing the new conflicting definition, not the original one. Differential Revision: https://reviews.llvm.org/D71679
* [LLD] Add a default copy constructor to avoid warningsNemanja Ivanovic2019-11-251-0/+1
| | | | This should fix the failure on the PPC64LE LLD bot.
* LLD: Don't use the stderrOS stream in link before it's reassigned.James Y Knight2019-11-212-8/+8
| | | | | | | | | | | | | | | | 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
* Use lld::make<T> to make TpiSource objectsRui Ueyama2019-11-201-10/+7
| | | | | | | | In lld we rarely use std::unique_ptr but instead allocate new instances using lld::make<T>() so that they are deallocated at the end of linking. This patch changes existing code so that that follows the convention. Differential Revision: https://reviews.llvm.org/D70420
* Make it possible to redirect not only errs() but also outs()Rui Ueyama2019-11-183-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
* [COFF] Don't error if the only inputs are from /wholearchive:Reid Kleckner2019-11-151-4/+4
| | | | | | Fixes PR43744 Differential Revision: https://reviews.llvm.org/D69968
* Add missing includes needed to prune LLVMContext.h include, NFCReid Kleckner2019-11-141-0/+1
| | | | | These are a pre-requisite to removing #include "llvm/Support/Options.h" from LLVMContext.h: https://reviews.llvm.org/D70280
* [COFF] Avoid CodeView include in headerReid Kleckner2019-11-143-6/+8
| | | | | Most LLD/COFF files don't care about CodeView. Avoid using CodeView types in InputFiles.h.
* Forward declare the DWARFCache to avoid including LLVM DWARF detailsReid Kleckner2019-11-142-1/+3
| | | | | LLD's DWARF.h header leaks a lot of LLVM DWARF includes that LLD doesn't need. For Chunks.cpp, I see a compile time decrease of 3.1s to 2.7s.
* [COFF] Don't include llvm/LTO/LTO.h in a headerReid Kleckner2019-11-145-3/+15
| | | | | LLVM's LTO header includes all of llvm/IR, which most of the COFF linker doesn't need.
* Warn on /align if used without /driverRui Ueyama2019-11-141-0/+2
| | | | | | | /align is not supposed to be used without /driver, so it makes sense to warn if only /align is passed. MSVC link.exe warns on this too. Differential Revision: https://reviews.llvm.org/D70163
* Implement /driver, /driver:wdm and /driver:uponlyRui Ueyama2019-11-144-3/+36
| | | | | | | | This patch implements /driver, /driver:wdm and /driver:uponly as described in https://docs.microsoft.com/en-us/cpp/build/reference/driver-windows-nt-kernel-mode-driver?view=vs-2019. Differential Revision: https://reviews.llvm.org/D70162
* [LLD] [COFF] Fix automatically importing data symbols from DLLs with LTOMartin Storsjö2019-11-131-2/+0
| | | | | | | | | | | | | | | | This broke in 51dcb292cc002, "[lld-link] diagnose undefined symbols before LTO when possible" (very soon after the 9.0 branch, so luckily the 9.0 release is unaffected). The code for loading objects we believe might be needed for autoimport (loadMinGWAutomaticImports()) does run before the new reportUnresolvable() function, but it had a condition to only operate on symbols from regular object files. This condition came from resolveRemainingUndefines(), but as loadMinGWAutomaticImports() now has to operate before the LTO, it has to operate on undefineds from LTO objects as well. Differential Revision: https://reviews.llvm.org/D70166
* Warn when an output section name is longer than 8 charactersReid Kleckner2019-11-013-0/+13
| | | | | | | | | | | | | | Recent versions of Microsoft's dumpbin tool cannot handle such PE files. LLVM tools and GNU tools can, and use this to encode long section names like ".debug_info", which is commonly used for DWARF. Don't do this in mingw mode or when -debug:dwarf is passed, since the user probably wants long section names for DWARF sections. PR43754 Reviewers: ruiu, mstorsjo Differential Revision: https://reviews.llvm.org/D69594
* lld/COFF: Simplify getOutputPath() using sys::path functions.Nico Weber2019-10-281-4/+1
| | | | | | | | | | Also mention "basename" and "dirname" in Path.h since I tried to find these functions by looking for these strings. It might help others find them faster if the comments contain these strings. No behavior change. Differential Revision: https://reviews.llvm.org/D69458
* [LLD] [COFF] Fix use of uninitialized memory since SVN r375390Martin Storsjo2019-10-211-1/+1
| | | | llvm-svn: 375400
* [LLD] [COFF] Use the local dwarf code instead of Symbolizer for resolving ↵Martin Storsjo2019-10-215-15/+21
| | | | | | | | | | | | code locations. NFC. As we now have code that parses the dwarf info for variable locations, we can use that instead of relying on the higher level Symbolizer library, reducing the previous two different dwarf codepaths into one. Differential Revision: https://reviews.llvm.org/D69198 llvm-svn: 375391
* [LLD] Move duplicated dwarf parsing code to the Common library. NFC.Martin Storsjo2019-10-212-79/+6
| | | | | | Differential Revision: https://reviews.llvm.org/D69197 llvm-svn: 375390
* [lld][coff] Add missing dependency to fix build.Michael Liao2019-10-181-0/+1
| | | | llvm-svn: 375238
* [LLD] [COFF] Try to report source locations for duplicate symbolsMartin Storsjo2019-10-184-13/+167
| | | | | | | | | | | | | | | | | | | | | | | This fixes the second part of PR42407. For files with dwarf debug info, it manually loads and iterates .debug_info to find the declared location of variables, to allow reporting them. (This matches the corresponding code in the ELF linker.) For functions, it uses the existing getFileLineDwarf which uses LLVMSymbolizer for translating addresses to file lines. In object files with codeview debug info, only the source location of duplicate functions is printed. (And even there, only for the first input file. The getFileLineCodeView function requires the object file to be fully loaded and initialized to properly resolve source locations, but duplicate symbols are reported at a stage when the second object file isn't fully loaded yet.) Differential Revision: https://reviews.llvm.org/D68975 llvm-svn: 375218
* [LLD] [COFF] Update a leftover comment after SVN r374869. NFC.Martin Storsjo2019-10-151-1/+1
| | | | llvm-svn: 374874
* [LLD] [COFF] Fix -Wmissing-field-initializers warnings. NFC.Martin Storsjo2019-10-151-1/+1
| | | | llvm-svn: 374873
* [LLD] [COFF] Wrap file location pair<StringRef,int> in Optional<>. NFC.Martin Storsjo2019-10-153-22/+26
| | | | | | | | | This makes use of it slightly clearer, and makes it match the same construct in the lld ELF linker. Differential Revision: https://reviews.llvm.org/D68935 llvm-svn: 374869
* [PDB] Fix bug when using multiple PCH header objects with the same name.Zachary Turner2019-10-101-17/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | A common pattern in Windows is to have all your precompiled headers use an object named stdafx.obj. If you've got a project with many different static libs, you might use a separate PCH for each one of these. During the final link step, a file from A might reference the PCH object from A, but it will have the same name (stdafx.obj) as any other PCH from another project. The only difference will be the path. For example, A might be A/stdafx.obj while B is B/stdafx.obj. The existing algorithm checks only the filename that was passed on the command line (or stored in archive), but this is insufficient in the case where relative paths are used, because depending on the command line object file / library order, it might find the wrong PCH object first resulting in a signature mismatch. The fix here is to simply check whether the absolute path of the PCH object (which is stored in the input obj file for the file that references the PCH) *ends with* the full relative path of whatever is specified on the command line (or is in the archive). Differential Revision: https://reviews.llvm.org/D66431 llvm-svn: 374442
* [COFF] Wrap definitions in namespace lld { namespace coff {. NFCFangrui Song2019-10-107-50/+63
| | | | | | | | | | | Similar to D67323, but for COFF. Many lld/COFF/ files already use `namespace lld { namespace coff {`. Only a few need changing. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D68772 llvm-svn: 374314
* dummy comment typo fix commit to cycle the botsNico Weber2019-10-105-9/+8
| | | | llvm-svn: 374270
* Unify the two CRC implementationsHans Wennborg2019-10-091-4/+2
| | | | | | | | | | | | | | | | | | | | | David added the JamCRC implementation in r246590. More recently, Eugene added a CRC-32 implementation in r357901, which falls back to zlib's crc32 function if present. These checksums are essentially the same, so having multiple implementations seems unnecessary. This replaces the CRC-32 implementation with the simpler one from JamCRC, and implements the JamCRC interface in terms of CRC-32 since this means it can use zlib's implementation when available, saving a few bytes and potentially making it faster. JamCRC took an ArrayRef<char> argument, and CRC-32 took a StringRef. This patch changes it to ArrayRef<uint8_t> which I think is the best choice, and simplifies a few of the callers nicely. Differential revision: https://reviews.llvm.org/D68570 llvm-svn: 374148
* [lld] Don't create hints-section if Hint/Name Table is emptyRui Ueyama2019-10-091-1/+2
| | | | | | | | | | | Fixes assert in addLinkerModuleCoffGroup() when using by-ordinal imports only. Patch by Stefan Schmidt. Differential revision: https://reviews.llvm.org/D68352 llvm-svn: 374140
* [LLD] [COFF] Always demangle the __imp_ prefix to __declspec(dllimport)Martin Storsjo2019-10-041-3/+5
| | | | | | Differential Revision: https://reviews.llvm.org/D68017 llvm-svn: 373781
* Add /reproduce option to lld/COFFRui Ueyama2019-10-042-6/+27
| | | | | | | | | | | This patch adds /reproduce:<path> option to lld/COFF. This is an lld-specific option, so we can name it freely. I chose /reproduce over other names (e.g. /lldlinkrepro) for consistency with other lld ports. Differential Revision: https://reviews.llvm.org/D68381 llvm-svn: 373704
* Revert r371729: lld-link: Make /linkrepro: take a filename, not a directory.Rui Ueyama2019-10-041-5/+7
| | | | | | | | | | This reverts commit r371729 because /linkrepro option also exists in Microsoft link.exe and their linker takes not a filename but a directory name as an argument for /linkrepro. Differential Revision: https://reviews.llvm.org/D68378 llvm-svn: 373703
* [LLD] [COFF] Use the unified llvm demangle frontend function. NFC.Martin Storsjo2019-09-272-15/+16
| | | | | | | | Add test cases for some cases where we don't want demangling to happen. Differential Revision: https://reviews.llvm.org/D67301 llvm-svn: 373075
* [LLD] [COFF] Resolve source locations for undefined references using dwarfMartin Storsjo2019-09-255-4/+38
| | | | | | | | This fixes PR42407. Differential Revision: https://reviews.llvm.org/D67053 llvm-svn: 372843
* [NFC][COFF] fix typo in comment ("algortihm" -> "algorithm")Bob Haarman2019-09-241-1/+1
| | | | llvm-svn: 372776
* [lld] Update lld driver to use new LTO APIs to handle libcall symbolsSteven Wu2019-09-161-7/+2
| | | | | | | NFC. Remove duplicated code in ELF/COFF driver and libLTO legacy interfaces. llvm-svn: 372022
* lld-link: Make Options.td formatting more self-consistent.Nico Weber2019-09-141-13/+19
| | | | | | | | Also tighten up help strings for /force, --start-lib, and --end-lib. Differential Revision: https://reviews.llvm.org/D67457 llvm-svn: 371927
* lld-link: Add a flag /lldignoreenv that makes lld-link ignore env vars.Nico Weber2019-09-134-11/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | This is useful for enforcing that builds are independent of the environment; it can be used when all system library paths are added via /libpath: already. It's similar ot cl.exe's /X flag. Since it should also affect %LINK% (the other caller of `Process::GetEnv` in lld/COFF), the early-option-parsing needs to move around a bit. The options are: - Add a manual loop over the argv ArrayRef and look for "/lldignoreenv". This repeats the name of the flag in both Options.td and in DriverUtils.cpp. - Add yet another table.ParseArgs() call just for /lldignoreenv before adding %LINK%. - Use the existing early ParseArgs() that's there for --rsp-quoting and use it for /lldignoreenv for %LINK% as well. This means --rsp-quoting and /lldignoreenv can't be passed via %LINK%. I went with the third approach. Differential Revision: https://reviews.llvm.org/D67456 llvm-svn: 371852
* [COFF] Fix to not add archive name to buffer identifiers when they comeAmy Huang2019-09-121-2/+3
| | | | | | | | | | | | from thin archives. Currently lld adds the archive name to MemoryBufferRef identifiers in order to ensure they are unique. For thin archives, since the file name is already unique and we want to keep the original path to the file, don't add the archive name. Differential Revision: https://reviews.llvm.org/D67295 llvm-svn: 371778
* lld-link: Make /linkrepro: take a filename, not a directory.Nico Weber2019-09-121-7/+5
| | | | | | | | | | | | This makes lld-link behave like ld.lld. I don't see a reason for the two drivers to have different behavior here. While here, also make lld-link add a version.txt to the tar, like ld.lld does. Differential Revision: https://reviews.llvm.org/D67461 llvm-svn: 371729
* [LLD][COFF] Add index to disambiguate archive members when using -wholearchiveRui Ueyama2019-09-101-1/+2
| | | | | | | | | | | | | Patch by Markus Böck. PR42951: When linking an archive with members that have the same name linking fails when using the -wholearchive option. This patch passes the index of the member in the archive to the offset parameter to disambiguate the member. Differential Revision: https://reviews.llvm.org/D66239 llvm-svn: 371509
OpenPOWER on IntegriCloud