summaryrefslogtreecommitdiffstats
path: root/lld/COFF/DLL.cpp
Commit message (Collapse)AuthorAgeFilesLines
* 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
* COFF: Allow mangled symbols as arguments for /export.Rui Ueyama2015-06-281-2/+4
| | | | | | | | | | | | | | | | | | | | Usually dllexported symbols are defined with 'extern "C"', so identifying them is easy. We can just do hash table lookup to look up exported symbols. However, C++ non-member functions are also allowed to be exported, and they can be specified with unmangled name. So, if /export:foo is given, we need to look up not only "foo" but also its all mangled names. In MSVC mangling scheme, that means that we need to look up any symbol which starts with "?foo@@Y". In this patch, we scan the entire symbol table to search for a mangled symbol. The symbol table is a DenseMap, and that doesn't support table lookup by string prefix. This is of course very inefficient. But that should be probably OK because the user should always add 'extern "C"' to dllexported symbols. llvm-svn: 240919
* COFF: Add base relocation for delay-import table.Rui Ueyama2015-06-261-0/+4
| | | | | | | | Because the address table of the delay-import table contains absolute address, it needs to be added to the base relocation table. llvm-svn: 240844
* COFF: Fix delay-import tables.Rui Ueyama2015-06-261-20/+40
| | | | | | | | | | | | There were a few issues with the previous delay-import tables. - "Attribute" field should have been 1 instead of 0. (I don't know the meaning of this field, though.) - LEA and CALL operands had wrong addresses. - Address tables are in .didat (which is read-only). They should have been in .data. llvm-svn: 240837
* Fix typo.Rui Ueyama2015-06-221-1/+1
| | | | llvm-svn: 240298
* COFF: Support delay-load import tables.Rui Ueyama2015-06-211-10/+163
| | | | | | | | | | | | | | | | DLLs are usually resolved at process startup, but you can delay-load them by passing /delayload option to the linker. If a /delayload is specified, the linker has to create data which is similar to regular import table. One notable difference is that the pointers in a delay-load import table are originally pointing to thunks that resolves themselves. Each thunk loads a DLL, resolve its name, and then overwrites the pointer with the result so that subsequent function calls directly call a desired function. The linker has to emit thunks. llvm-svn: 240250
* COFF: Support creating DLLs.Rui Ueyama2015-06-171-7/+116
| | | | | | | | | | | | DLL files are in the same format as executables but they have export tables. The format of the export table is described in PE/COFF spec section 5.3. A new class, EdataContents, takes care of creating chunks for export tables. What we need to do is to parse command line flags for dllexports, and then instantiate the class to create chunks. For the writer, export table chunks are opaque data -- it just add chunks to .edata section. llvm-svn: 239869
* COFF: Use named constants instead of sizeof().Rui Ueyama2015-06-071-2/+2
| | | | llvm-svn: 239267
* COFF: Make local variables local.Rui Ueyama2015-06-071-2/+2
| | | | llvm-svn: 239244
* COFF: Move Windows-specific code from Chunk.{cpp,h} to DLL.{cpp,h}.Rui Ueyama2015-06-071-0/+205
llvm-svn: 239239
OpenPOWER on IntegriCloud