summaryrefslogtreecommitdiffstats
path: root/lld/COFF/InputFiles.h
Commit message (Collapse)AuthorAgeFilesLines
...
* Add {Obj,Import,Bitcode}File::Instances to COFF input files.Rui Ueyama2017-07-271-0/+5
| | | | | | | We did the same thing for ELF in r309152, and I want to maintain COFF and ELF as close as possible. llvm-svn: 309239
* Rename ObjectFile ObjFile for COFF as well.Rui Ueyama2017-07-261-2/+2
| | | | llvm-svn: 309228
* [PDB] Add a module descriptor for every object fileReid Kleckner2017-06-131-0/+12
| | | | | | | | | | | | | | Summary: Expose the module descriptor index and fill it in for section contributions. Reviewers: zturner Subscribers: llvm-commits, ruiu, hiraditya Differential Revision: https://reviews.llvm.org/D34126 llvm-svn: 305296
* Garbage collect dllimported symbols.Rui Ueyama2017-05-241-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | This is a different implementation than r303225 (which was reverted in r303270, re-submitted in r303304 and then re-reverted in r303527). In the previous patch, I tried to add Live bit to each dllimported symbol. It turned out that it didn't work with "oldnames.lib" which contains a lot of weak aliases to dllimported symbols. The way we handle weak aliases is to check if undefined symbols can be resolved using weak aliases, and if so, memcpy the Defined symbols to weak Undefined symbols, so that any references to weak aliases automatically see defined symbols instead of undefined ones. This memcpy happens before MarkLive kicks in. That means we may have multiple copies of dllimported symbols. So turning on one instance's Live bit is not enough. This patch moves the Live bit to dllimport file. Since multiple copies of dllsymbols still point to the same file, we can use it as the central repository to keep track of liveness. Differential Revision: https://reviews.llvm.org/D33520 llvm-svn: 303814
* Use make<> everywhere in COFF to make it consistent with ELF.Rui Ueyama2017-05-181-6/+1
| | | | | | | | | 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: actually synthesize CONST imports properlySaleem Abdulrasool2017-04-281-0/+1
| | | | | | | | | | CONSTANT imports expect both the `_imp_` prefixed and non-prefixed symbols should be added to the symbol table. This allows for linking symbols like _NSConcreteGlobalBlock in WinObjC. The previous change would generate the import library properly by handling the option but would not consume the generated entry properly. llvm-svn: 301657
* [coff] for /msvclto, pass archive members with prevailing symbols firstBob Haarman2017-04-211-1/+2
| | | | | | | | | | | | | | Summary: When using /msvclto, lld and MSVC's linker both do their own symbol resolution. This can cause them to select different archive members, which can result in undefined references. This change avoids that situation by extracting archive members that are selected by lld and passing those to link.exe before any archives, so that MSVC's uses those objects for symbol resolution instead of different archive members. Reviewers: pcc, rnk, ruiu Reviewed By: pcc Subscribers: llvm-commits, mehdi_amini Differential Revision: https://reviews.llvm.org/D32317 llvm-svn: 301045
* COFF: Remove some unused fields.Peter Collingbourne2017-04-141-2/+0
| | | | llvm-svn: 300298
* refactor COFF linker to use new LTO APIBob Haarman2017-02-021-7/+2
| | | | | | | | | | | | | | Summary: The COFF linker previously implemented link-time optimization using an API which has now been marked as legacy. This change refactors the COFF linker to use the new LTO API, which is also used by the ELF linker. Reviewers: pcc, ruiu Reviewed By: pcc Subscribers: mgorny, mehdi_amini Differential Revision: https://reviews.llvm.org/D29059 llvm-svn: 293967
* Merge elf::toString and coff::toString.Rui Ueyama2017-01-061-3/+2
| | | | | | The two overloaded functions hid each other. This patch merges them. llvm-svn: 291222
* COFF: Open and map input files asynchronously on Windows.Peter Collingbourne2016-12-151-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Profiling revealed that the majority of lld's execution time on Windows was spent opening and mapping input files. We can reduce this cost significantly by performing these operations asynchronously. This change introduces a queue for all operations on input file data. When we discover that we need to load a file (for example, when we find a lazy archive for an undefined symbol, or when we read a linker directive to load a file from disk), the file operation is launched using a future and the symbol resolution operation is enqueued. This implies another change to symbol resolution semantics, but it seems to be harmless ("ninja All" in Chromium still succeeds). To measure the perf impact of this change I linked Chromium's chrome_child.dll with both thin and fat archives. Thin archives: Before (median of 5 runs): 19.50s After: 10.93s Fat archives: Before: 12.00s After: 9.90s On Linux I found that doing this asynchronously had a negative effect on performance, probably because the cost of mapping a file is small enough that it becomes outweighed by the cost of managing the futures. So on non-Windows platforms I use the deferred execution strategy. Differential Revision: https://reviews.llvm.org/D27768 llvm-svn: 289760
* COFF: Remove an unused mutex declaration.Peter Collingbourne2016-12-121-2/+0
| | | | llvm-svn: 289415
* COFF: Use a DenseSet instead of a map to atomic_flag to track which archive ↵Peter Collingbourne2016-12-121-1/+2
| | | | | | | | members have been read. Differential Revision: https://reviews.llvm.org/D27667 llvm-svn: 289414
* COFF: New symbol table design.Peter Collingbourne2016-12-091-28/+16
| | | | | | | | | 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
* Revert r289084: Start using make() in COFF.Rui Ueyama2016-12-081-2/+2
| | | | | | This reverts commit r289084 to appease buildbots. llvm-svn: 289086
* Start using make() in COFF.Rui Ueyama2016-12-081-2/+2
| | | | | | We don't want ELF and COFF to diverge too much. llvm-svn: 289085
* COFF: Define overloaded toString functions.Rui Ueyama2016-12-071-8/+4
| | | | | | | | | | | | | Previously, we had different way to stringize SymbolBody and InputFile to construct error messages. This patch defines overloaded function toString() so that we don't need to memorize all these different function names. With that change, it is now easy to include demangled names in error messages. Now, if there is a symbol name conflict, we'll print out both mangled and demangled names. llvm-svn: 288992
* Do plumbing work for CodeView debug info.Rui Ueyama2016-11-211-0/+5
| | | | | | | | | | Previously, we discarded .debug$ sections. This patch adds them to files so that PDB.cpp can access them. This patch also adds a debug option, /dumppdb, to dump debug info fed to createPDB so that we can verify that valid data has been passed. llvm-svn: 287555
* Create PDB.h and move code to remove unnecessary #includes.Rui Ueyama2016-09-151-2/+2
| | | | llvm-svn: 281670
* COFF: Rename noreturn error -> fatal.Rui Ueyama2016-07-141-1/+1
| | | | | | This new name is also consistent with ELF. llvm-svn: 275500
* COFF: Update remaining #include paths.Peter Collingbourne2016-07-141-1/+1
| | | | llvm-svn: 275480
* Do not use llvm::getGlobalContext().Rui Ueyama2016-04-141-1/+3
| | | | llvm-svn: 266375
* [COFF] Remove undefined behavior from ObjectFile::createWeakExternalDavid Majnemer2016-03-201-1/+0
| | | | | | | | | | | | | | | LLD type-punned an integral type and a pointer type using a pointer field. This is problematic because the pointer type has alignment greater than some of the integral values. This would be less problematic if a union was used but it turns out the integral values are only present for a short, transient, amount of time. Let's remove this undefined behavior by skipping the punning altogether by storing the state in a separate memory location: a vector which informs us which symbols to process for weak externs. llvm-svn: 263918
* COFF: Destroy LTOModules as they are linked.Peter Collingbourne2015-11-171-1/+0
| | | | | | | | This should help reduce memory consumption during LTO. Differential Revision: http://reviews.llvm.org/D14672 llvm-svn: 253397
* COFF: Fix thread-safety bug.Rui Ueyama2015-09-191-0/+2
| | | | | | LTOModule doesn't seem to be thread-safe, so guard that with mutex. llvm-svn: 248102
* Remove an allocator which was used for just one allocation.Rafael Espindola2015-09-021-3/+2
| | | | llvm-svn: 246662
* COFF: Update for LTO API change.Peter Collingbourne2015-08-241-1/+1
| | | | llvm-svn: 245892
* COFF: Fix the order of the DLL import entry.Rui Ueyama2015-08-171-0/+1
| | | | | | | | | | | 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-0/+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
* Make these headers as being c++.Rafael Espindola2015-08-141-1/+1
| | | | llvm-svn: 245050
* Update for llvm api change.Rafael Espindola2015-08-131-1/+1
| | | | llvm-svn: 244856
* COFF: Update a comment.Rui Ueyama2015-08-061-2/+1
| | | | llvm-svn: 244258
* Port the error functions from ELF to COFF.Rafael Espindola2015-08-061-9/+9
| | | | | | | | | | | | | | | 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: Implement Safe SEH support for x86.Rui Ueyama2015-07-241-0/+11
| | | | | | | | | | | | | 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-1/+1
| | | | | | | | | 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-1/+1
| | | | | | | 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-1/+1
| | | | | | | | 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: Infer machine type earlier than before.Rui Ueyama2015-07-091-0/+7
| | | | | | | | | | | | | | | | 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: Make ArchiveFile::getMember lock-free.Rui Ueyama2015-07-061-1/+1
| | | | | | | | 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 symbols satisfy weak ordering.Rui Ueyama2015-07-021-1/+8
| | | | | | | | | | | | | | | | | | 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: Change the order of adding symbols to the symbol table.Rui Ueyama2015-06-301-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: Split ObjectFile::createSymbolBody into small functions. NFC.Rui Ueyama2015-06-291-2/+5
| | | | llvm-svn: 241011
* [opt] Hoist the call throuh SymbolBody::getReplacement out of the inlineChandler Carruth2015-06-291-3/+5
| | | | | | | | | | | | | | | | | | | method to get a SymbolBody and into the callers, and kill now dead includes. This removes the need to have the SymbolBody definition when we're defining the inline method and makes it a better inline method. That was the only reason for a lot of header includes here. Removing these and using forward declarations actually uncovers a bunch of cross-header dependencies that I've fixed while I'm here, and will allow me to introduce some *important* inline code into Chunks.h that requires the definition of ObjectFile. No functionality changed at this point. Differential Revision: http://reviews.llvm.org/D10789 llvm-svn: 240982
* COFF: Remove useless "explicit".Rui Ueyama2015-06-281-1/+1
| | | | llvm-svn: 240899
* [opt] Inline a trivial lookup function into the header.Chandler Carruth2015-06-271-1/+3
| | | | | | | | | | | | | | 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: Combine add{Object,Archive,Bitcode,Import} functions. NFC.Rui Ueyama2015-06-201-8/+2
| | | | llvm-svn: 240229
* Update for llvm api change.Rafael Espindola2015-06-131-3/+5
| | | | llvm-svn: 239671
* COFF: Read symbol names lazily.Rui Ueyama2015-06-081-2/+2
| | | | | | | | | This change seems to make the linker about 10% faster. Reading symbol name is not very cheap because it needs strlen() on the string table. We were wasting time on reading non-external symbol names that would never be used by the linker. llvm-svn: 239332
* COFF: Add more log messages.Rui Ueyama2015-06-081-4/+6
| | | | llvm-svn: 239289
* COFF: Simplify InputFile class.Rui Ueyama2015-06-081-14/+7
| | | | | | | Now that all InputFile subclasses have MemoryBufferRefs and provides the same set of functions. Implement that in the base class. llvm-svn: 239281
OpenPOWER on IntegriCloud