summaryrefslogtreecommitdiffstats
path: root/lld/COFF/Driver.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* COFF: Implement DLL symbol forwarding.Rui Ueyama2016-01-091-0/+2
| | | | | | | | | | | | | | | | 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: Create a PDB file with the correct file signature.Rui Ueyama2015-12-041-1/+1
| | | | | | | | | | | | | | | | | Before this patch, we created an empty PDB file if /debug option is specified. For MSVC linker, such PDB file is completely broken, and linker exits without doing anything as soon as it finds an empty PDB file. A PDB file created in this patch has the correct file signature. MSVC linker still thinks that the file is broken, but it then removes and replaces with its output. This is an initial patch to support PDB in LLD. We aim to support PDB in order to make it 100% compatible with MSVC linker. PDB support is the last missing piece. llvm-svn: 254796
* COFF: /OPT should accept comma-separated multiple arguments.Rui Ueyama2015-10-191-28/+32
| | | | | | | | /OPT:foo,bar is equivalent to /OPT:foo /OPT:bar. Reported by alexchandel. https://llvm.org/bugs/show_bug.cgi?id=25228 llvm-svn: 250728
* COFF: Add /nosymtab command line option.Rui Ueyama2015-09-211-0/+2
| | | | | | | | | | | | | This is an LLD extension to MSVC link.exe command line. MSVC linker does not write symbol tables for executables. We do unless no /debug option is given. There's a situation that we want to enable debug info but don't want to emit the symbol table. One example is when we are comparing output file size. With this patch, you can tell the linker to not create a symbol table by just specifying /nosymtab. llvm-svn: 248225
* COFF: Move markLive() from Writer.cpp to its own file.Rui Ueyama2015-09-191-0/+8
| | | | | | | Conceptually, garbage collection is not part of Writer, so move the function out of the file. llvm-svn: 248099
* Remove unused #includes.Rui Ueyama2015-09-191-3/+0
| | | | llvm-svn: 248081
* COFF: Fix bug that /opt:noicf was ignored.Rui Ueyama2015-09-161-1/+5
| | | | llvm-svn: 247854
* COFF: Enable ICF by default.Rui Ueyama2015-09-161-0/+1
| | | | | | MSVC linker enables ICF as long as /opt:ref is eanbled, so do we. llvm-svn: 247817
* COFF: Rename /opt:lldicf -> /opt:icf.Rui Ueyama2015-09-161-6/+3
| | | | | | | Now that ICF is complete, we can rename this option so that the driver accepts the MSVC-compatible command line option. llvm-svn: 247816
* Fix style.Rui Ueyama2015-09-151-8/+4
| | | | llvm-svn: 247644
* COFF: Ignore /GUARDSYM option.Rui Ueyama2015-09-031-0/+1
| | | | | | | | The option is added in MSVC 2015, and there's no documentation about what the option is. This patch is to ignore the option for now, so that at least LLD is usable with MSVC 2015. llvm-svn: 246780
* COFF: .exe files should be able to export functions.Rui Ueyama2015-09-011-1/+1
| | | | | | | | | In r246424, I made a change that disables non-DLL to export symbols. It turned out that the change was not correct. Both DLLs and executables are able to export symbols (although the latter is relatively rare). This change restores the feature. llvm-svn: 246537
* COFF: Improve dllexported name mangling compatibility.Rui Ueyama2015-08-311-6/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: Implement parallel LTO code generation.Peter Collingbourne2015-08-281-5/+10
| | | | | | | | | This is exposed via a new flag /opt:lldltojobs=N, where N is the number of code generation threads. Differential Revision: http://reviews.llvm.org/D12309 llvm-svn: 246342
* Do not use unique pointers. NFC.Rui Ueyama2015-08-181-4/+4
| | | | | | | These unique pointers have the exact same lifetime as automatic variables, so use automatic variables instead. llvm-svn: 245281
* COFF: Introduce flag /opt:lldlto=N for controlling LTO optimization level.Peter Collingbourne2015-08-141-0/+8
| | | | | | Differential Revision: http://reviews.llvm.org/D12024 llvm-svn: 245027
* COFF: Ignore /editandcontinue option.Rui Ueyama2015-08-111-0/+1
| | | | llvm-svn: 244626
* COFF: Define symbols for MSVC 2015 Control Flow Protection.Rui Ueyama2015-08-091-0/+6
| | | | | | | | | | | | | | | MSVC 2015's load configuration object (__load_config_used) contains references to these symbols. I don't fully understand how it works, but looks like these symbols are linker-defined ones. So I define them here in the Driver. With this patch, LLD can self-host with MSVC 2015. This patch is to link MSVC 2015-produced object files. It does not implement Control Flow Protection. If I understand correctly, the linker has to create a bitmap of function entry point addresses for the CFG runtime. We don't do that yet. Produced executables will not be protected by CFG. llvm-svn: 244425
* COFF: Do not fall through if /lib is processed.Rui Ueyama2015-08-091-6/+8
| | | | llvm-svn: 244424
* COFF: Simplify.Rui Ueyama2015-08-081-2/+2
| | | | | | | | SymbolTable::find(mangle(X)) is equivalent to SymbolTable::findUnderscore(X) except that the latter is slightly efficient as that doesn't allocate a new string. llvm-svn: 244377
* COFF: Handle _load_config_used in the same way as other special symbols.Rui Ueyama2015-08-071-3/+2
| | | | | | | Handling the symbol this way is consistent with other symbols, such as _tls_used. NFC. llvm-svn: 244367
* Port the error functions from ELF to COFF.Rafael Espindola2015-08-061-190/+78
| | | | | | | | | | | | | | | This has a few advantages * Less C++ code (about 300 lines less). * Less machine code (about 14 KB of text on a linux x86_64 build). * It is more debugger friendly. Just set a breakpoint on the exit function and you get the complete lld stack trace of when the error was found. * It is a more robust API. The errors are handled early and we don't get a std::error_code hot potato being passed around. * In most cases the error function in a better position to print diagnostics (it has more context). llvm-svn: 244215
* COFF, ELF2: Pass output file path implicitly using Config global variable.Rui Ueyama2015-08-051-1/+1
| | | | | | | | | | | Various parameters are passed implicitly using Config global variable already. Output file path is no different from others, so there was no special reason to handle that differnetly. This patch changes the signature of writeResult(SymbolTable *, StringRef) to writeResult(SymbolTable *). llvm-svn: 244180
* COFF: Simplify Writer interface by hiding Writer class.Rui Ueyama2015-08-051-2/+2
| | | | llvm-svn: 244175
* Handle writeImportLibrary failing.Rafael Espindola2015-08-051-1/+2
| | | | | | | | | We were printing an error but exiting with 0. Not sure how to test this. We could add a no-winlib feature, but that is probably not worth it. llvm-svn: 244109
* COFF: When resolving _load_config_used, add it as a GC root.Peter Collingbourne2015-07-311-3/+2
| | | | | | | | This fixes the cases where the symbol is defined in a comdat or by bitcode. Differential Revision: http://reviews.llvm.org/D11673 llvm-svn: 243735
* COFF: Fix command line option spelling.Rui Ueyama2015-07-291-1/+1
| | | | llvm-svn: 243573
* COFF: Ignore /ThrowNew command line option.Rui Ueyama2015-07-291-0/+2
| | | | | | | This command line option is added since MSVC 2015. Our wild guess is that the flag is for LTCG and we can safely ignore that. llvm-svn: 243568
* COFF: Add /safeseh command line option.Rui Ueyama2015-07-291-0/+11
| | | | | | If /safeseh is specified, all input files must be compatible with Safe SEH. llvm-svn: 243565
* COFF: Set load config table entry on non-x86.Rui Ueyama2015-07-291-4/+4
| | | | llvm-svn: 243532
* COFF: /HighEntropyVA is on by default only on 64-bit.Rui Ueyama2015-07-281-2/+4
| | | | llvm-svn: 243374
* COFF: Add /LargeAddressAware command line option.Rui Ueyama2015-07-281-0/+4
| | | | llvm-svn: 243373
* COFF: Use short identifiers. NFC.Rui Ueyama2015-07-251-17/+17
| | | | llvm-svn: 243229
* COFF: Fix image base address for 32-bit.Rui Ueyama2015-07-251-1/+10
| | | | | | | 0x140000000 or 0x180000000 are not correct image base addresses for 32-bit. They are actually much smaller. llvm-svn: 243228
* COFF: Don't assume !is64() means i386.Rui Ueyama2015-07-251-7/+7
| | | | | | | | 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: Implement Safe SEH support for x86.Rui Ueyama2015-07-241-0/+10
| | | | | | | | | | | | | An object file compatible with Safe SEH contains a .sxdata section. The section contains a list of symbol table indices, each of which is an exception handler function. A safe SEH-enabled executable contains a list of exception handler RVAs. So, what the linker has to do to support Safe SEH is basically to read the .sxdata section, interpret the contents as a list of symbol indices, unique-fy and sort their RVAs, and then emit that list to .rdata. This patch implements that feature. llvm-svn: 243182
* COFF: Fix __ImageBase symbol relocation.Rui Ueyama2015-07-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | __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 mangled dllexported names.Rui Ueyama2015-07-151-5/+4
| | | | | | | | | If a symbol is exported as /export:foo, and foo is resolved as a mangled name (_foo@<number> or ?foo@@Y...), that mangled name should be written to the export table. Previously, we wrote the original name to the export table. llvm-svn: 242342
* COFF: Fix entry name inference for x86.Rui Ueyama2015-07-141-2/+2
| | | | | | | | | | | Entry name selection rule is already complicated on x64, but it's more complicated on x86 because of the underscore name mangling scheme. If one of _main, _main@<number> (a C function) or ?main@@... (a C++ function) is defined, entry name is _mainCRTStartup. If _wmain, _wmain@<number or ?wmain@@... is defined, entry name is _wmainCRTStartup. And so on. llvm-svn: 242110
* COFF: Fix x86 delay-load helper function name.Rui Ueyama2015-07-131-6/+10
| | | | | | | | If /delayload option is given, we have to resolve __delayLoadHelper2 since the function is the dynamic loader to delay-load DLLs. The function name is mangled in x86 as ___delayLoadHelper2@8. llvm-svn: 242078
* COFF: Fix dllexported symbol names on x86.Rui Ueyama2015-07-091-34/+36
| | | | | | | | Symbol names are usually mangled by appending "_" prefix on x86. But the mangled name is not used in DLL export table. The export table contains unmangled names. llvm-svn: 241872
* COFF: Infer machine type earlier than before.Rui Ueyama2015-07-091-47/+57
| | | | | | | | | | | | | | | | Previously, we infer machine type at the very end of linking after all symbols are resolved. That's actually too late because machine type affects how we mangle symbols (whether or not we need to add "_"). For example, /entry:foo adds "_foo" to the symbol table if x86 but "foo" if x64. This patch moves the code to infer machine type, so that machine type is inferred based on input files given via the command line (but not based on .directives files). llvm-svn: 241843
* COFF: Fix import thunks and name mangling for x86.Rui Ueyama2015-07-091-6/+13
| | | | | | | With this patch, LLD is now able to correctly link a "hello world" program written in assembly for 32-bit x86. llvm-svn: 241771
* COFF: Handle /machine option in a similar manner for other options. NFC.Rui Ueyama2015-07-081-5/+5
| | | | llvm-svn: 241701
* COFF: Check for incompatible machine types.Rui Ueyama2015-07-071-3/+23
| | | | llvm-svn: 241647
* COFF: Support isa<> for Symbol::Body, whose type is std::atomic<SymbolBody *>.Rui Ueyama2015-07-061-2/+2
| | | | llvm-svn: 241477
* COFF: Use atomic pointers in preparation for parallelizing.Rui Ueyama2015-07-051-2/+2
| | | | | | | | | | | | | In the new design, mutation of Symbol pointers is the name resolution operation. This patch makes them atomic pointers so that they can be mutated by multiple threads safely. I'm going to use atomic compare-exchange on these pointers. dyn_cast<> doesn't recognize atomic pointers as pointers, so we need to call load(). This is unfortunate, but in other places automatic type conversion works fine. llvm-svn: 241416
* COFF: Implement /merge option.Rui Ueyama2015-07-041-1/+11
| | | | | | /merge:.foo=.bar makes the linker to merge section .foo with section .bar. llvm-svn: 241396
* COFF: Numerous fixes for interaction between LTO and weak externals.Peter Collingbourne2015-07-041-4/+4
| | | | | | | | | | | | | | | | | | | | We were previously hitting assertion failures in the writer in cases where a regular object file defined a weak external symbol that was defined by a bitcode file. Because /export and /entry name mangling were implemented using weak externals, the same problem affected mangled symbol names in bitcode files. The underlying cause of the problem was that weak external symbols were being resolved before doing LTO, so the symbol table may have contained stale references to bitcode symbols. The fix here is to defer weak external symbol resolution until after LTO. Also implement support for weak external symbols in bitcode files by modelling them as replaceable DefinedBitcode symbols. Differential Revision: http://reviews.llvm.org/D10940 llvm-svn: 241391
* COFF: Call exit(0) on success to not call destructors.Rui Ueyama2015-07-031-1/+2
| | | | | | | | | This change cut the link time of chrome.dll from 24 seconds to 22 seconds (5% gain). When the control reaches end of link(), all output files have already been written. All in-memory objects can just vanish. There is no use to call their dtors. llvm-svn: 241320
OpenPOWER on IntegriCloud