summaryrefslogtreecommitdiffstats
path: root/lld/COFF/InputFiles.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* COFF: Allow forward reference for weak externalsRui Ueyama2015-08-171-1/+5
| | | | | | | | | | | Previously, weak external symbols could reference only symbols that appeared before them. Although that covers almost all use cases of weak externals, there are object files out there which contains weak externals that have forward references. This patch supports such weak externals. llvm-svn: 245258
* COFF: Fix the order of the DLL import entry.Rui Ueyama2015-08-171-1/+2
| | | | | | | | | | | 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: Simplify Writer::createImportTables.Rui Ueyama2015-08-171-5/+5
| | | | | | | A short import library has up to two symbols, so we don't have to do a for-loop and type dispatch in createImportTables. llvm-svn: 245200
* Update for llvm api change.Rafael Espindola2015-08-131-1/+1
| | | | llvm-svn: 244856
* Port the error functions from ELF to COFF.Rafael Espindola2015-08-061-56/+33
| | | | | | | | | | | | | | | 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: Fix bad #includes.Rui Ueyama2015-08-051-1/+1
| | | | | | | Writer.h is intended to be included only by Writer.cpp and Driver.cpp. Use of the header in other files are bad. llvm-svn: 244106
* Remove unused #includes.Rui Ueyama2015-07-291-1/+0
| | | | llvm-svn: 243588
* COFF: Skip non-DWARF debug info sections.Rui Ueyama2015-07-281-0/+4
| | | | | | | | Leaving them in an executable is basically harmless but wastes disk space. Because no one is using non-DWARF debug info linked by LLD, we can just remove them. llvm-svn: 243364
* COFF: Use short identifiers. NFC.Rui Ueyama2015-07-251-3/+3
| | | | llvm-svn: 243229
* COFF: Split ImportThunkChunk into x86 and x64. NFC.Rui Ueyama2015-07-251-2/+4
| | | | | | This change should make it easy to port this code to ARM. llvm-svn: 243195
* COFF: Implement Safe SEH support for x86.Rui Ueyama2015-07-241-2/+31
| | | | | | | | | | | | | 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
* Use getChildOffset instead of getBuffer for identifying a member.Rafael Espindola2015-07-141-3/+2
| | | | | | | | | I am adding support for thin archives. On those, getting the buffer involves reading another file. Since we only need an id in here, use the member offset in the archive. llvm-svn: 242205
* Revert "Make COFF linker work when it's built by clang again."Rui Ueyama2015-07-141-2/+7
| | | | | | | This reverts commit r242006. The original issue in Clang was fixed in r242009, so we can now safely use std::atomic_flag. llvm-svn: 242112
* Make COFF linker work when it's built by clang again.Nico Weber2015-07-131-7/+2
| | | | | | | | clang-cl doesn't compile std::atomic_flag correctly (PR24101). Since the COFF linker doesn't use threads yet, just revert r241420 and r241481 for now to work around this clang-cl bug. llvm-svn: 242006
* COFF: Fix import symbol name mangling.Rui Ueyama2015-07-091-2/+8
| | | | | | For IMPORT_NAME_NOPREFIX symbols, we should remove only one prefix character. llvm-svn: 241854
* COFF: Infer machine type earlier than before.Rui Ueyama2015-07-091-1/+23
| | | | | | | | | | | | | | | | 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: Implement dllimported symbol name mangling.Rui Ueyama2015-07-081-9/+18
| | | | | | | | | Symbols exported by DLLs are listed in import library files. Exported names may be mangled by "Import Name Type" field as described in PE/COFF spec 7.3. This patch implements that mangling scheme. llvm-svn: 241719
* COFF: Emit a symbol table if /debug is specifiedDavid Majnemer2015-07-081-1/+2
| | | | | | | | | | Providing a symbol table in the executable is quite useful when debugging a fully-linked executable without having to reconstruct one from DWARF. Differential Revision: http://reviews.llvm.org/D11023 llvm-svn: 241689
* COFF: Check for incompatible machine types.Rui Ueyama2015-07-071-5/+0
| | | | llvm-svn: 241647
* COFF: Make ArchiveFile::getMember lock-free.Rui Ueyama2015-07-061-5/+7
| | | | | | | | The previous code was not even safe with MSVC 2013 because the compiler doesn't guarantee that static variables (in this case, a mutex) are initialized in a thread-safe manner. llvm-svn: 241481
* COFF: Make ArchiveFile::getMember thread-safe.Rui Ueyama2015-07-051-0/+5
| | | | | | | This function is called SymbolTable::readObjects, so in order to parallelize that function, we have to make this function thread-safe. llvm-svn: 241420
* COFF: Numerous fixes for interaction between LTO and weak externals.Peter Collingbourne2015-07-041-2/+5
| | | | | | | | | | | | | | | | | | | | 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
* Revert "COFF: Do not use VirtualSize section header field for directive ↵Rui Ueyama2015-07-041-2/+1
| | | | | | | | sections." This reverts commit r241386 because the issue is addressed in LLVM (r241387). llvm-svn: 241388
* COFF: Do not use VirtualSize section header field for directive sections.Rui Ueyama2015-07-041-1/+2
| | | | | | | | | Looks like clang-cl sets a bogus value to the field, which makes getSectionContents() to truncate section contents. This patch directly uses SizeOfRawData field instead of VirtualSize to see if this can make buildbot green. llvm-svn: 241386
* COFF: Fix the case where an object defines a weak external and its alias.Peter Collingbourne2015-07-031-1/+1
| | | | | | | | | | This worked before, but only by accident, and only with assertions disabled. We ended up storing a DefinedRegular symbol in the WeakAlias field, and never using it as an Undefined. Differential Revision: http://reviews.llvm.org/D10934 llvm-svn: 241376
* COFF: Make symbols satisfy weak ordering.Rui Ueyama2015-07-021-0/+2
| | | | | | | | | | | | | | | | | | Previously, SymbolBody::compare(A, B) didn't satisfy weak ordering. There was a case that A < B and B < A could have been true. This is because we just pick LHS if A and B are consisdered equivalent. This patch is to make symbols being weakly ordered. If A and B are not tie, one of A < B && B > A or A > B && B < A is true. This is not an improtant property for a single-threaded environment because everything is deterministic anyways. However, in a multi- threaded environment, this property becomes important. If a symbol is defined or lazy, ties are resolved by its file index. For simple types that we don't really care about their identities, symbols are compared by their addresses. llvm-svn: 241294
* COFF: Resolve AlternateNames using weak aliases.Rui Ueyama2015-07-021-1/+1
| | | | | | | | Previously, we use SymbolTable::rename to resolve AlternateName symbols. This patch is to merge that mechanism with weak aliases, so that we remove that function. llvm-svn: 241230
* COFF: Chagne weak alias' type from SymbolBody** to SymbolBody*. NFC.Rui Ueyama2015-07-011-1/+3
| | | | llvm-svn: 241198
* COFF: Change the order of adding symbols to the symbol table.Rui Ueyama2015-06-301-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, the order of adding symbols to the symbol table was simple. We have a list of all input files. We read each file from beginning of the list and add all symbols in it to the symbol table. This patch changes that order. Now all archive files are added to the symbol table first, and then all the other object files are added. This shouldn't change the behavior in single-threading, and make room to parallelize in multi-threading. In the first step, only lazy symbols are added to the symbol table because archives contain only Lazy symbols. Member object files found to be necessary are queued. In the second step, defined and undefined symbols are added from object files. Adding an undefined symbol to the symbol table may cause more member files to be added to the queue. We simply continue reading all object files until the queue is empty. Finally, new archive or object files may be added to the queues by object files' directive sections (which contain new command line options). The above process is repeated until we get no new files. Symbols defined both in object files and in archives can make results undeterministic. If an archive is read before an object, a new member file gets linked, while in the other way, no new file would be added. That is the most popular cause of an undeterministic result or linking failure as I observed. Separating phases of adding lazy symbols and undefined symbols makes that deterministic. Adding symbols in each phase should be parallelizable. llvm-svn: 241107
* COFF: Implement SymbolBody::getDebugName() for DefinedBitcode symbols.Peter Collingbourne2015-06-301-1/+2
| | | | | | Differential Revision: http://reviews.llvm.org/D10827 llvm-svn: 241029
* COFF: Use LTOModule::getLinkerOpts() instead of reading the linker ↵Peter Collingbourne2015-06-291-24/+1
| | | | | | directives ourselves. llvm-svn: 241020
* COFF: Split ObjectFile::createSymbolBody into small functions. NFC.Rui Ueyama2015-06-291-13/+23
| | | | llvm-svn: 241011
* [cleanup] Clean up the flow of creating a symbol body for regular symbols.Chandler Carruth2015-06-291-17/+17
| | | | | | | | | | | | This uses a single cast and test to get the section for the symbol, and uses the cast_or_null<> pattern throughout to handle the known type but unknown non-null-ness. No functionality changed. Differential Revision: http://reviews.llvm.org/D10791 llvm-svn: 241000
* [opt] Inline a trivial lookup function into the header.Chandler Carruth2015-06-271-4/+0
| | | | | | | | | | | | | | This function is actually *very* hot. It is hard to see currently because the call graph is very recursive, but I'm working to remove that and when I do this function becomes significantly higher on the profile (up to 5%!) and so worth avoiding the call overhead. No specific perf gain I can measure yet (below the noise), but likely to have more impact as we stop cluttering the call graph. Differential Revision: http://reviews.llvm.org/D10788 llvm-svn: 240873
* COFF: Avoid vector reallocation. NFC.Rui Ueyama2015-06-261-1/+3
| | | | llvm-svn: 240859
* COFF: Fix local absolute symbols.Rui Ueyama2015-06-261-1/+1
| | | | | | | | | Absolute symbols were always handled as external symbols, so if two or more object files define the same absolute symbol, they would conflict even if the symbol is private to each file. This patch fixes that bug. llvm-svn: 240756
* COFF: Don't read non-x64 object files.Rui Ueyama2015-06-261-0/+7
| | | | | | Currently the new LLD supports only x86-64. llvm-svn: 240749
* COFF: Better error message for duplicate symbols.Rui Ueyama2015-06-251-2/+2
| | | | | | | Now the symbol table prints out not only symbol names but also file names for duplicate symbols. llvm-svn: 240719
* COFF: Merge DefinedRegular and DefinedCOMDAT.Rui Ueyama2015-06-251-4/+2
| | | | | | | | | I split them in r240319 because I thought they are different enough that we should treat them as different types. It turned out that that was not a good idea. They are so similar that we ended up having many duplicate code. llvm-svn: 240706
* COFF: Devirtualize mark(), markLive() and isCOMDAT().Rui Ueyama2015-06-251-5/+5
| | | | | | | | | | | | | | | | | | | | | | | Only SectionChunk can be dead-stripped. Previously, all types of chunks implemented these functions, but their functions were blank. Likewise, only DefinedRegular and DefinedCOMDAT symbols can be dead-stripped. markLive() function was implemented for other symbol types, but they were blank. I started thinking that the change I made in r240319 was a mistake. I separated DefinedCOMDAT from DefinedRegular because I thought that would make the code cleaner, but now we want to handle them as the same type here. Maybe we should roll it back. This change should improve readability a bit as this removes some dubious uses of reinterpret_cast. Previously, we assumed that all COMDAT chunks are actually SectionChunks, which was not very obvious. llvm-svn: 240675
* COFF: Initial implementation of Identical COMDAT Folding.Rui Ueyama2015-06-241-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Identical COMDAT Folding (ICF) is an optimization to reduce binary size by merging COMDAT sections that contain the same metadata, actual data and relocations. MSVC link.exe and many other linkers have this feature. LLD achieves on per with MSVC in terms produced binary size with this patch. This technique is pretty effective. For example, LLD's size is reduced from 64MB to 54MB by enaling this optimization. The algorithm implemented in this patch is extremely inefficient. It puts all COMDAT sections into a set to identify duplicates. Time to self-link with/without ICF are 3.3 and 320 seconds, respectively. So this option roughly makes LLD 100x slower. But it's okay as I wanted to achieve correctness first. LLD is still able to link itself with this optimization. I'm going to make it more efficient in followup patches. Note that this optimization is *not* entirely safe. C/C++ require different functions have different addresses. If your program relies on that property, your program wouldn't work with ICF. However, it's not going to be an issue on Windows because MSVC link.exe turns ICF on by default. As long as your program works with default settings (or not passing /opt:noicf), your program would work with LLD too. llvm-svn: 240519
* COFF: Remove unused field SectionChunk::SectionIndex.Peter Collingbourne2015-06-241-1/+1
| | | | llvm-svn: 240512
* COFF: Ignore debug symbols.Peter Collingbourne2015-06-241-0/+2
| | | | | | Differential Revision: http://reviews.llvm.org/D10675 llvm-svn: 240487
* COFF: Add names for logging/debugging to COMDAT chunks.Rui Ueyama2015-06-241-3/+8
| | | | | | | | | | | | Chunks are basically unnamed chunks of bytes, and we don't like to give them names. However, for logging or debugging, we want to know symbols names of functions for COMDAT chunks. (For example, we want to print out "we have removed unreferenced COMDAT section which contains a function FOOBAR.") This patch is to do that. llvm-svn: 240484
* COFF: Separate DefinedCOMDAT from DefinedRegular symbol type. NFC.Rui Ueyama2015-06-221-1/+4
| | | | | | | | | | | | | | Before this change, you got to cast a symbol to DefinedRegular and then call isCOMDAT() to determine if a given symbol is a COMDAT symbol. Now you can just use isa<DefinedCOMDAT>(). As to the class definition of DefinedCOMDAT, I could remove duplicate code from DefinedRegular and DefinedCOMDAT by introducing another base class for them, but I chose to not do that to keep the class hierarchy shallow. This amount of code duplication doesn't worth to define a new class. llvm-svn: 240319
* COFF: Combine add{Object,Archive,Bitcode,Import} functions. NFC.Rui Ueyama2015-06-201-1/+1
| | | | llvm-svn: 240229
* COFF: Fix a common symbol bug.Rui Ueyama2015-06-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | This is a case that one mistake caused a very mysterious bug. I made a mistake to calculate addresses of common symbols, so each common symbol pointed not to the beginning of its location but to the end of its location. (Ouch!) Common symbols are aligned on 16 byte boundaries. If a common symbol is small enough to fit between the end of its real location and whatever comes next, this bug didn't cause any harm. However, if a common symbol is larger than that, its memory naturally overlapped with other symbols. That means some uninitialized variables accidentally shared memory. Because totally unrelated memory writes mutated other varaibles, it was hard to debug. It's surprising that LLD was able to link itself and all LLD tests except gunit tests passed with this nasty bug. With this fix, the new COFF linker is able to pass all tests for LLVM, Clang and LLD if I use MSVC cl.exe as a compiler. Only three tests are failing when used with clang-cl. llvm-svn: 240216
* COFF: Cache Archive::Symbol::getName(). NFC.Rui Ueyama2015-06-191-3/+3
| | | | | | | | | getName() does strlen() on the symbol table, so it's not very fast. It's not as bad as r239332 because the number of symbols exported from archive files are fewer than object files, and they are usually shorter, though. llvm-svn: 240178
* COFF: Fix unsafe memory access.Rui Ueyama2015-06-181-1/+2
| | | | llvm-svn: 240046
* COFF: Handle both / and \ as path separator.Rui Ueyama2015-06-181-1/+1
| | | | llvm-svn: 240042
OpenPOWER on IntegriCloud