summaryrefslogtreecommitdiffstats
path: root/lld/COFF/DLL.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Fix alignment of thunks for ARM/ARM64Martin Storsjö2020-06-171-4/+12
| | | | | | | | | | | | | | 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)
* dummy comment typo fix commit to cycle the botsNico Weber2019-10-101-1/+1
| | | | llvm-svn: 374270
* [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] Rename variale references in comments after VariableName -> ↵Fangrui Song2019-07-161-1/+1
| | | | | | variableName change llvm-svn: 366193
* [COFF] Share the tail in delayimport symbol thunksMartin Storsjo2019-07-111-30/+124
| | | | | | | | | | | | | 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
* [Coding style change][lld] Rename variables for non-ELF portsRui Ueyama2019-07-111-282/+282
| | | | | | | | | | | 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
* [COFF] De-virtualize Chunk and SectionChunkReid Kleckner2019-05-241-17/+16
| | | | | | | | | | | | | | | | 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
* Re-land r361206 "[COFF] Store alignment in log2 form, NFC"Reid Kleckner2019-05-221-4/+6
| | | | | | | | | 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-211-6/+4
| | | | | | Makes the linker crash when linking nasm.exe. llvm-svn: 361212
* [COFF] Store alignment in log2 form, NFCReid Kleckner2019-05-201-4/+6
| | | | | | | | | | | | | | | | | 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
* [COFF] Simplify Chunk::writeTo and remove OutputSectionOff, NFCReid Kleckner2019-05-091-43/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Fix broken export table if .rdata is merged with .text.Rui Ueyama2019-01-241-1/+15
| | | | | | | | | | | | | | | | | | Previously, we assumed that .rdata is zero-filled, so when writing an COFF import table, we didn't write anything if the data is zero. That assumption was wrong because .rdata can be merged with .text. If .rdata is merged with .text, they are initialized with 0xcc which is a trap instruction. This patch removes that assumption from code. Should be merged to 8.0 branch as this is a regression. Fixes https://bugs.llvm.org/show_bug.cgi?id=39826 Differential Revision: https://reviews.llvm.org/D57168 llvm-svn: 352082
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* Do not assume .idata is zero-initialized.Rui Ueyama2018-11-301-0/+2
| | | | | | | | | | | | | We initialize .text section with 0xcc (INT3 instruction), so we need to explicitly write data even if it is zero if it can be in a .text section. If you specify /merge:.rdata=.text, .rdata (which contains .idata) is put to .text, so we need to do this. Fixes https://bugs.llvm.org/show_bug.cgi?id=39826 Differential Revision: https://reviews.llvm.org/D55098 llvm-svn: 348000
* [COFF] Add and use a Wordsize field in Config. NFCI.Martin Storsjo2018-10-111-10/+12
| | | | | | Differential Revision: https://reviews.llvm.org/D53143 llvm-svn: 344265
* [COFF] Support linking to import libraries from GNU binutilsMartin Storsjo2018-09-211-24/+0
| | | | | | | | | | | | | | | | | | | | | | | | GNU binutils import libraries aren't the same kind of short import libraries as link.exe and LLD produce, but are a plain static library containing .idata section chunks. MSVC link.exe can successfully link to them. In order for imports from GNU import libraries to mix properly with the normal import chunks, the chunks from the existing mechanism needs to be added into named sections like .idata$2. These GNU import libraries consist of one header object, a number of object files, one for each imported function/variable, and one trailer. Within the import libraries, the object files are ordered alphabetically in this order. The chunks stemming from these libraries have to be grouped by what library they originate from and sorted, to make sure the section chunks for headers and trailers for the lists are ordered as intended. This is done on all sections named .idata$*, before adding the synthesized chunks to them. Differential Revision: https://reviews.llvm.org/D38513 llvm-svn: 342777
* [COFF] Add support for delay loading DLLs for ARM64Martin Storsjo2018-09-181-0/+54
| | | | | | Differential Revision: https://reviews.llvm.org/D52190 llvm-svn: 342447
* Consistent (non) use of empty lines in include blocksSam Clegg2018-02-201-1/+1
| | | | | | | | | The profailing style in lld seem to be to not include such empty lines. Clang-tidy/clang-format seem to handle this just fine. Differential Revision: https://reviews.llvm.org/D43528 llvm-svn: 325629
* [COFF] Don't set the thumb bit in address table entries for data symbolsMartin Storsjo2017-12-201-5/+5
| | | | | | | | The thumb bit should only be set for executable code. Differential Revision: https://reviews.llvm.org/D41379 llvm-svn: 321149
* Remove {get,set}Align accessor functions and use Alignment member variable ↵Rui Ueyama2017-09-131-5/+4
| | | | | | instead. llvm-svn: 313204
* [COFF] Add support for delay loading DLLs on ARMMartin Storsjo2017-07-251-1/+47
| | | | | | Differential Revision: https://reviews.llvm.org/D35768 llvm-svn: 309017
* [COFF] Correctly set the thumb bit in DLL export addressesMartin Storsjo2017-07-251-2/+6
| | | | | | | | | | The same adjustment is already done for the entry point in Writer.cpp and for relocations that point to executable code in Chunks.cpp. Differential Revision: https://reviews.llvm.org/D35767 llvm-svn: 308953
* [COFF] Align import address chunks to the pointer sizeMartin Storsjo2017-07-201-3/+3
| | | | | | | | | | | | | | This fixes cases on ARM64 when importing from more than one DLL, in case the imports from the first DLL ended up unaligned. When fixing up a IMAGE_REL_ARM64_PAGEOFFSET_12L, which shifts the offset by the load/store size, check that the shift doesn't discard any bits. (This would also detect if the import address chunks were unaligned.) Differential revision: https://reviews.llvm.org/D35640 llvm-svn: 308585
* Revert "Merge IAT and ILT."Reid Kleckner2017-06-021-7/+8
| | | | | | | This reverts r303374. It breaks Chrome's IAT patching code: http://crbug.com/729077 llvm-svn: 304584
* Merge IAT and ILT.Rui Ueyama2017-05-181-8/+7
| | | | | | | | | | | | | | | | | | Previously, LLD-produced executables had IAT (Import Address Table) and ILT (Import Lookup Table) as separate chunks of data, although their contents are identical. My interpretation of the COFF spec when I wrote the COFF linker is that they need to be separate tables even though they are the same. But Peter found that the Windows loader is fine with executables in which IAT and ILT are merged. This is a patch to merge IAT and ILT. I confirmed that an lld-link self-hosted with this patch works fine. Fixes https://bugs.llvm.org/show_bug.cgi?id=33064 Differential Revision: https://reviews.llvm.org/D33326 llvm-svn: 303374
* COFF: Replace DLLNames maps with vectors.Peter Collingbourne2017-05-181-14/+6
| | | | | | | | | The import lists are already binned by DLL name, so there's no need to deduplicate here. Differential Revision: https://reviews.llvm.org/D33330 llvm-svn: 303371
* Use make<> everywhere in COFF to make it consistent with ELF.Rui Ueyama2017-05-181-83/+68
| | | | | | | | | We've been using make<> to allocate new objects in ELF. We have the same function in COFF, but we didn't use it widely due to negligence. This patch uses the function in COFF to close the gap between ELF and COFF. llvm-svn: 303357
* COFF: New symbol table design.Peter Collingbourne2016-12-091-1/+1
| | | | | | | | | This ports the ELF linker's symbol table design, introduced in r268178, to the COFF linker. Differential Revision: http://reviews.llvm.org/D21166 llvm-svn: 289280
* Update for LLVM function name change.Rui Ueyama2016-01-141-1/+1
| | | | llvm-svn: 257801
* COFF: Implement DLL symbol forwarding.Rui Ueyama2016-01-091-2/+17
| | | | | | | | | | | | | | | | DLL export tables usually contain dllexport'ed symbol RVAs so that applications which use the DLLs can find symbols from the DLLs. However, there's a minor feature to "forward" DLL symbols to other DLLs. If you set an RVA to a string whose form is "<dllname>.<symbolname>" (e.g. "KERNEL32.ExitProcess") instead of symbol RVA to the export table, the loader interprets that as a forwarder symbol, and resolve that symbol from the specified DLL. This patch implements that feature. llvm-svn: 257243
* COFF: Rename RoundUpToAlignment -> align.Rui Ueyama2016-01-081-1/+1
| | | | llvm-svn: 257220
* COFF: Make Chunk::writeTo() const. NFC.Rui Ueyama2015-09-191-12/+12
| | | | | | | This should improve code readability especially because this function is called inside parallel_for_each. llvm-svn: 248103
* Remove unused #includes.Rui Ueyama2015-09-191-1/+0
| | | | llvm-svn: 248081
* COFF: Preserve original spelling of DLL file name.Rui Ueyama2015-09-021-4/+4
| | | | | | | | | | | This patch fixes a subtle incompatibility with MSVC linker. MSVC linker preserves the original spelling of a DLL in the import descriptor table. LLD previously converted all characters to lowercase. Usually this difference is benign, but if a program explicitly checks for DLL file names, the program could fail. llvm-svn: 246620
* COFF: Improve dllexported name mangling compatibility.Rui Ueyama2015-08-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The rules for dllexported symbols are overly complicated due to x86 name decoration, fuzzy symbol resolution, and the fact that one symbol can be resolved by so many different names. The rules are probably intended to be "intuitive", so that users don't have to understand the name mangling schemes, but it seems that it can lead to unintended symbol exports. To make it clear what I'm trying to do with this patch, let me write how the export rules are subtle and complicated. - x86 name decoration: If machine type is i386 and export name is given by a command line option, like /export:foo, the real symbol name the linker has to search for is _foo because all symbols are decorated with "_" prefixes. This doesn't happen on non-x86 machines. This automatic name decoration happens only when the name is not C++ mangled. However, the symbol name exported from DLLs are ones without "_" on all platforms. Moreover, if the option is given via .drectve section, no symbol decoration is done (the reason being that the .drectve section is created by a compiler and the compiler should always know the exact name of the symbol, I guess). - Fuzzy symbol resolution: In addition to x86 name decoration, the linker has to look for cdecl or C++ mangled symbols for a given /export. For example, it searches for not only _foo but also _foo@<number> or ??foo@... for /export:foo. Previous implementation didn't get it right. I'm trying to make it as compatible with MSVC linker as possible with this patch however the rules are. The new code looks a bit messy to me, but I don't think it can be simpler due to the ad-hoc-ness of the rules. llvm-svn: 246424
* COFF: Fix the order of the DLL import entry.Rui Ueyama2015-08-171-13/+15
| | | | | | | | | | | There are some DLLs whose initializers depends on other DLLs' initializers. The initialization order matters for them. MSVC linker uses the order of the libraries from the command line. LLD used ASCII-betical order. So they were incompatible. This patch makes LLD compatible with MSVC. llvm-svn: 245201
* COFF: In chunks, store the offset from the start of the output section. NFC.Rafael Espindola2015-08-141-21/+21
| | | | | | | | | This is more convenient than the offset from the start of the file as we don't have to worry about it changing when we move the output section. This is a port of r245008 from ELF. llvm-svn: 245018
* Move file-local classes to an anonymous namespace. NFC.Rui Ueyama2015-08-101-166/+168
| | | | llvm-svn: 244525
* COFF: Fix export symbol names for x86.Rui Ueyama2015-07-281-1/+1
| | | | | | | | | | I don't fully understand the rationale behind the name mangling scheme used for the DLL export table and the import library. Why only leading "_" is dropped for the import library while both "_" and "@" are dropped from DLL symbol table? But this seems to be what MSVC linker does. llvm-svn: 243490
* COFF: Fix 32-bit delay-import address table.Rui Ueyama2015-07-281-2/+6
| | | | | | | The address table entry is 32-bit wide on 32-bit and 64-bit on 64-bit. Previously, it was 64-bit even on 32-bit. llvm-svn: 243372
* COFF: Use short identifiers. NFC.Rui Ueyama2015-07-251-1/+1
| | | | llvm-svn: 243229
* COFF: Handle base relocation as a tuple of relocation type and RVA. NFC.Rui Ueyama2015-07-251-5/+5
| | | | | | | | | | On x64 and x86, we use only one base relocation type, so we handled base relocations just as a list of RVAs. That doesn't work well for ARM becuase we have to handle two types of base relocations on ARM. This patch changes the type of base relocation from uint32_t to {reltype, uint32_t} to make it easy to port this code to ARM. llvm-svn: 243197
* COFF: Don't assume !is64() means i386.Rui Ueyama2015-07-251-6/+12
| | | | | | | | In many places we assumed that is64() means AMD64 and i386 otherwise. This assumption is not sound because Windows also supports ARM. The linker doesn't support ARM yet, but this is a first step. llvm-svn: 243188
* COFF: Fix __ImageBase symbol relocation.Rui Ueyama2015-07-241-2/+2
| | | | | | | | | | | | | | | | | | | | | | __ImageBase is a special symbol whose value is the image base address. Previously, we handled __ImageBase symbol as an absolute symbol. Absolute symbols point to specific locations in memory and the locations never change even if an image is base-relocated. That means that we don't have base relocation entries for absolute symbols. This is not a case for __ImageBase. If an image is base-relocated, its base address changes, and __ImageBase needs to be shifted as well. So we have to have base relocations for __ImageBase. That means that __ImageBase is not really an absolute symbol but a different kind of symbol. In this patch, I introduced a new type of symbol -- DefinedRelative. DefinedRelative is similar to DefinedAbsolute, but it has not a VA but RVA and is a subject of base relocation. Currently only __ImageBase is of the new symbol type. llvm-svn: 243176
* COFF: Fix offset in x86 delay-load thunks.Rui Ueyama2015-07-151-1/+1
| | | | llvm-svn: 242353
* COFF: Implement x86 delay-load thunks.Rui Ueyama2015-07-151-8/+50
| | | | llvm-svn: 242343
* COFF: Support 32-bit x86 DLL import table.Rui Ueyama2015-07-091-8/+12
| | | | llvm-svn: 241767
* COFF: Fix ordinal-only delay-imported symbols.Rui Ueyama2015-07-031-4/+8
| | | | | | | | | | | | | | | | | | | | DLLs can export symbols only by ordinal, and DLLs are also able to be delay-loaded. The combination of the two is valid. I didn't expect that combination. This patch implements that feature. With this patch, LLD is now able to link a working executable of Chrome for 64-bit debug build. The browser seemed to be working fine. Chrome is good for testing because of its variety and size. It contains various open-source libraries written by various people. The largest file in Chrome is chrome.dll whose size is 496MB. LLD can link it in 24 seconds. MSVC linker takes 48 seconds. So it is exactly 2x faster. (I measured that with debug info and ICF being turned off.) With this achievement, I think I can say that the new COFF linker is now mostly feature complete for x86-64 Windows. I believe there are still many lingering bugs, though. llvm-svn: 241318
* COFF: Rename getReplacement -> repl.Rui Ueyama2015-07-021-1/+1
| | | | | | The previous name was too long to my taste. llvm-svn: 241215
* COFF: Simplify and rename findMangle. NFC.Rui Ueyama2015-07-021-1/+1
| | | | | | | | | | Occasionally we have to resolve an undefined symbol to its mangled symbol. Previously, we did that on calling side of findMangle by explicitly updating SymbolBody. In this patch, mangled symbols are handled as weak aliases for undefined symbols. llvm-svn: 241213
OpenPOWER on IntegriCloud