summaryrefslogtreecommitdiffstats
path: root/lld/COFF/Symbols.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* COFF: Split ImportThunkChunk into x86 and x64. NFC.Rui Ueyama2015-07-251-0/+15
| | | | | | This change should make it easy to port this code to ARM. llvm-svn: 243195
* COFF: Fix __ImageBase symbol relocation.Rui Ueyama2015-07-241-0/+3
| | | | | | | | | | | | | | | | | | | | | | __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: Inline Defined::getRVA because it's very hot.Rui Ueyama2015-07-131-24/+0
| | | | llvm-svn: 242075
* COFF: Fill in the type and storage class in the symbol tableDavid Majnemer2015-07-091-0/+8
| | | | | | | We can use the type and storage class from the symbol's original object file to fill in the linked executable's symbol table. llvm-svn: 241828
* COFF: Set parent name for bitcode files.Peter Collingbourne2015-07-081-4/+6
| | | | | | Differential Revision: http://reviews.llvm.org/D10983 llvm-svn: 241713
* COFF: Numerous fixes for interaction between LTO and weak externals.Peter Collingbourne2015-07-041-0/+8
| | | | | | | | | | | | | | | | | | | | 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: Make symbols satisfy weak ordering.Rui Ueyama2015-07-021-9/+25
| | | | | | | | | | | | | | | | | | 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: Chagne weak alias' type from SymbolBody** to SymbolBody*. NFC.Rui Ueyama2015-07-011-2/+2
| | | | llvm-svn: 241198
* COFF: Implement SymbolBody::getDebugName() for DefinedBitcode symbols.Peter Collingbourne2015-06-301-0/+3
| | | | | | Differential Revision: http://reviews.llvm.org/D10827 llvm-svn: 241029
* Move llvm_unreachable out of switch to avoid -Wswitch-covered-defualt.Rui Ueyama2015-06-291-6/+3
| | | | llvm-svn: 241008
* Silence MSVC "not all control paths return a value" warning.Rui Ueyama2015-06-291-0/+6
| | | | llvm-svn: 241004
* [opt] Devirtualize the SymbolBody type hierarchy and start compactingChandler Carruth2015-06-291-85/+143
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | its members into the base class. First, to help motivate this kind of change, understand that in a self-link, LLD creates 5.5 million defined regular symbol bodies (and 6 million symbol bodies total). A significant portion of its time is spent allocating the memory for these symbols, and befor ethis patch the defined regular symbol body objects alone consumed some 420mb of memory during the self link. As a consequence, I think it is worth expending considerable effort to make these objects as memory efficient as possible. This is the first of several components of that. This change starts with the goal of removing the virtual functins from SymbolBody so that it can avoid having a vptr embedded in it when it already contains a "kind" member, and that member can be much more compact than a vptr. The primary way of doing this is to sink as much of the logic that we would have to dispatch for into data in the base class. As part of this, I made the various flags bits that will pack into a bitfield with the kind tag. I also sank the Name down to eliminate the dispatch for that, and used LLVM's RTTI-style dispatch for everything else (most of which is cold and so doesn't matter terribly if we get minutely worse lowering than a vtable dispatch). As I was doing this, I wanted to make the RTTI-dispatch (which would become much hotter than before) as efficient as possible, so I've re-organized the tags somewhat. Notably, the common case (regular defined symbols) is now zero which we can test for faster. I also needed to rewrite the comparison routine used during resolving symbols. This proved to be quite complex as the semantics of the existing one were very subtle due to the back-and-forth virtual dispatch caused by re-dispatching with reversed operands. I've consolidated it to a single function and tried to comment it quite a bit more to help explain what is going on. However, this may need more comments or other explanations. It at least passes all the regression tests. I'm not working on Windows, so I can't fully test it. With all of these changes, the size of a DefinedRegular symbol on a 64-bit build goes from 80 bytes to 64 bytes, and we save approximately 84mb or 20% of the memory consumed by these symbol bodies during the link. The link time appears marginally faster as well, and the profile hotness of the memory allocation subsystem got a bit better, but there is still a lot of allocation traffic. Differential Revision: http://reviews.llvm.org/D10792 llvm-svn: 241001
* COFF: Better error message for duplicate symbols.Rui Ueyama2015-06-251-2/+10
| | | | | | | 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-18/+10
| | | | | | | | | 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: Separate DefinedCOMDAT from DefinedRegular symbol type. NFC.Rui Ueyama2015-06-221-14/+22
| | | | | | | | | | | | | | 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: Fix a common symbol bug.Rui Ueyama2015-06-201-11/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | 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: Simplify SymbolBody::compare(SymbolBody *Other).Rui Ueyama2015-06-151-42/+39
| | | | | | | | We are currently handling all combinations of SymbolBody types directly. This patch is to flip this and Other if Other->kind() < this->kind() to reduce number of combinations. No functionality change intended. llvm-svn: 239745
* COFF: Symbol resolution for common and comdat symbols defined in bitcode.Peter Collingbourne2015-06-111-1/+34
| | | | | | | | | | | | | | | | | | | | | | | | | In the case where either a bitcode file and a regular file or two bitcode files export a common or comdat symbol with the same name, the linker needs to pick one of them following COFF semantics. This patch implements a design for resolving such symbols that pushes most of the work onto either LLD's regular mechanism for resolving common or comdat symbols or the IR linker's mechanism for doing the same. We modify SymbolBody::compare to always prefer non-bitcode symbols, so that during the initial phase of symbol resolution, the symbol table always contains a regular symbol in any case where we need to choose between a regular and a bitcode symbol. In SymbolTable::addCombinedLTOObject, we force export any bitcode symbols that were initially pre-empted by a regular symbol, and later use SymbolBody::compare to choose between the regular symbol in the symbol table and the regular symbol from the combined LTO object file. This design seems to be sound, so long as the resolution mechanism is defined to be commutative and associative modulo arbitrary choices between symbols (which seems to be the case for COFF). Differential Revision: http://reviews.llvm.org/D10329 llvm-svn: 239563
* COFF: Update comment.Rui Ueyama2015-06-091-1/+2
| | | | llvm-svn: 239413
* COFF: Read symbol names lazily.Rui Ueyama2015-06-081-0/+13
| | | | | | | | | 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: Initial implementation of link-time optimization.Peter Collingbourne2015-06-011-0/+2
| | | | | | | | This implementation is known to work in very simple cases (see new test case). Differential Revision: http://reviews.llvm.org/D10115 llvm-svn: 238777
* COFF: Define an error category for the linker.Rui Ueyama2015-06-011-3/+5
| | | | | | | | | | | | | Instead of returning non-categorized errors, return categorized errors. All uses of make_dynamic_error_code are removed. Because we don't have error reporting mechanism, I just chose to print out error messages to stderr, and then return an error object. Not sure if that's the right thing to do, but at least it seems practical. http://reviews.llvm.org/D10129 llvm-svn: 238714
* COFF: Make the Driver own all MemoryBuffers. NFC.Rui Ueyama2015-05-311-1/+1
| | | | | | | | | | | Previously, a MemoryBuffer of a file was owned by each InputFile object. This patch makes the Driver own all of them. InputFiles now have only MemoryBufferRefs. This change simplifies ownership managment (particularly for ObjectFile -- the object owned a MemoryBuffer only when it's not created from an archive file, because in that case a parent archive file owned the entire buffer. Now it owns nothing unconditionally.) llvm-svn: 238690
* COFF: Add a new PE/COFF port.Rui Ueyama2015-05-281-0/+96
This is an initial patch for a section-based COFF linker. The patch has 2300 lines of code including comments and blank lines. Before diving into details, you want to start from reading README because it should give you an overview of the design. All important things are written in the README file, so I write summary here. - The linker is already able to self-link on Windows. - It's significantly faster than the existing implementation. The existing one takes 5 seconds to link LLD on my machine, while the new one only takes 1.2 seconds, even though the new one is not multi-threaded yet. (And a proof-of-concept multi- threaded version was able to link it in 0.5 seconds.) - It uses much less memory (250MB vs. 2GB virtual memory space to self-host). - IMHO the new code is much simpler and easier to read than the existing PE/COFF port. http://reviews.llvm.org/D10036 llvm-svn: 238458
OpenPOWER on IntegriCloud