Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lld/COFF
AgeCommit message (Collapse)Author
2015-07-03COFF: Fix /base option.Rui Ueyama
Previously, __ImageBase symbol got a different value than the one specified by /base:<number> because the symbol was created in the SymbolTable's constructor. When the constructor is called, no command line options are processed yet, so the symbol was created always with the initial value. This caused wrong relocations and thus caused mysterious crashes of some executables linked by LLD. llvm-svn: 241313
2015-07-03COFF: Define SymbolTable::insert to simplify. NFC.Rui Ueyama
llvm-svn: 241311
2015-07-02COFF: Fix locally-imported symbols.Rui Ueyama
Previously, pointers pointed by locally-imported symbols were broken. It has only 4 bytes although the correct size is 8 byte. This patch fixes that bug. llvm-svn: 241295
2015-07-02COFF: Make symbols satisfy weak ordering.Rui Ueyama
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
2015-07-02COFF: Merge SymbolTable::find{,Symbol}. NFCRui Ueyama
llvm-svn: 241238
2015-07-02COFF: Infer entry point as early as possible, but not too early.Rui Ueyama
On Windows, we have four different main functions, {w,}{main,WinMain}. The linker has to choose a corresponding entry point function among {w,}{main,WinMain}CRTStartup. These entry point functions are defined in the standard library. The linker resolves one of them by looking at which main function is defined and adding a corresponding undefined symbol to the symbol table. Object files containing entry point functions conflicts each other. For example, we cannot resolve both mainCRTStartup and WinMainCRTStartup because other symbols defined in the files conflict. Previously, we inferred CRT function name at the very end of name resolution. I found that that is sometimes too late. If the linker already linked one of these four archive member objects, it's too late to change the decision. The right thing to do here is to infer entry point name after adding all symbols from command line files and before adding any other files (which are specified by directive sections). This patch does that. llvm-svn: 241236
2015-07-02COFF: Resolve AlternateNames using weak aliases.Rui Ueyama
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
2015-07-02COFF: Rename getReplacement -> repl.Rui Ueyama
The previous name was too long to my taste. llvm-svn: 241215
2015-07-02COFF: Change GCRoot member type from StringRef to Undefined. NFC.Rui Ueyama
I think Undefined symbols are a bit more convenient than StringRefs since SymbolBodies are handles for symbols. You can get resolved symbols for undefined symbols just by calling getReplacmenet without looking up the symbol table. llvm-svn: 241214
2015-07-02COFF: Simplify and rename findMangle. NFC.Rui Ueyama
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
2015-07-02COFF: Chagne weak alias' type from SymbolBody** to SymbolBody*. NFC.Rui Ueyama
llvm-svn: 241198
2015-07-01COFF: Simplify SymbolTable::findLazy. NFC.Rui Ueyama
llvm-svn: 241128
2015-06-30COFF: Change the order of adding symbols to the symbol table.Rui Ueyama
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
2015-06-30COFF: Implement SymbolBody::getDebugName() for DefinedBitcode symbols.Peter Collingbourne
Differential Revision: http://reviews.llvm.org/D10827 llvm-svn: 241029
2015-06-30COFF: Make DefinedCOFF one pointer smaller.Rui Ueyama
The size of this class actually matters because this is the most popular class among all classes. We create a Defined symbol for each defined symbol in a symbol table. That can be millions for a large program. For example, linking LLD instantiates this class millions times. llvm-svn: 241025
2015-06-30COFF: Use LTOModule::getLinkerOpts() instead of reading the linker ↵Peter Collingbourne
directives ourselves. llvm-svn: 241020
2015-06-30COFF: Split ObjectFile::createSymbolBody into small functions. NFC.Rui Ueyama
llvm-svn: 241011
2015-06-30Move llvm_unreachable out of switch to avoid -Wswitch-covered-defualt.Rui Ueyama
llvm-svn: 241008
2015-06-30Silence MSVC "not all control paths return a value" warning.Rui Ueyama
llvm-svn: 241004
2015-06-30[opt] Devirtualize the SymbolBody type hierarchy and start compactingChandler Carruth
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
2015-06-30[cleanup] Clean up the flow of creating a symbol body for regular symbols.Chandler Carruth
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
2015-06-30[opt] Replace the recursive walk for GC with a worklist algorithm.Chandler Carruth
This flattens the entire liveness walk from a recursive mark approach to a worklist approach. It also sinks the worklist management completely out of the SectionChunk and into the Writer by exposing the ability to iterato over children of a chunk and over the symbol bodies of relocated symbols. I'm not 100% happy with the API names, so suggestions welcome there. This allows us to use a single worklist for the entire recursive walk and would also be a natural place to take advantage of parallelism at some future point. With this, we completely inline away the GC walk into the Writer::markLive function and it makes it very easy to profile what is slow. Currently, time is being wasted checking whether a Chunk isa SectionChunk (it essentially always is), finding (or skipping) a replacement for a symbol, and chasing pointers between symbols and their chunks. There are a bunch of things we can do to fix this, and its easier to do them after this change IMO. This change alone saves 1-2% of the time for my self-link of lld.exe (which I'm running and benchmarking on Linux ironically). Perhaps more notably, we'll no longer blow out the stack for large links. =] Just as an FYI, at this point, I/O is starting to really dominate the profile. Well over 10% of the time appears to be inside the kernel doing page table silliness. I think a decent chunk of this can be nuked as well, but it's a little odd as cross-linking in this way isn't really the primary goal here. Differential Revision: http://reviews.llvm.org/D10790 llvm-svn: 240995
2015-06-29[opt] Hoist the call throuh SymbolBody::getReplacement out of the inlineChandler Carruth
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
2015-06-29COFF: Handle mangled entry symbol name.Rui Ueyama
Compilers recognize "main" function and don't mangle its name. But if you use a different function as a user-defined entry name, and if you didn't define that function with extern C, your entry point function name is mangled. And the linker has to be able to find that. This is relatively rare but can happen. llvm-svn: 240953
2015-06-29COFF: Create an empty file for /pdb.Rui Ueyama
Most build system depends on existence or time stamp of a file. This patch is to create an empty file for /pdb:<filename> option just to satisfy some build rules. llvm-svn: 240948
2015-06-29COFF: Fix /export.Rui Ueyama
Mangled dllexported symbols may be defined in a library. If that's the case, we have to read a member file from the library. llvm-svn: 240947
2015-06-29COFF: Fix logic to find default entry name or subsystem.Rui Ueyama
The previous logic to find default entry name or subsystem does not seem correct (i.e. was not compatible with MSVC linker). Previously, default entry name was inferred from CRT functions and user-defined entry functions. Subsystem was inferred from CRT functions. Default entry name and subsystem are now inferred based on the following table. Note that we no longer use CRT functions to infer them. Entry name Subsystem main mainCRTStartup console wmain wmainCRTStartup console WinMain WinMainCRTStartup windows wWinMain wWinMainCRTStartup windows llvm-svn: 240922
2015-06-29COFF: Allow mangled symbols as arguments for /export.Rui Ueyama
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
2015-06-28COFF: Undefined weak aliases are not fatal if /force is given.Rui Ueyama
llvm-svn: 240917
2015-06-28COFF: Add a comment.Rui Ueyama
llvm-svn: 240916
2015-06-28COFF: Add /noentry flag.Rui Ueyama
This option is sometimes used to create a resource-only DLL that doesn't need any initialization. llvm-svn: 240915
2015-06-28COFF: Support /force flag.Rui Ueyama
This option is to ignore remaining undefined symbols and force the linker to create an output file anyways. The existing code assumes that there's no undefined symbol after reportRemainingUndefines(). That assumption is legitimate. I also don't want to mess up the existing code for this minor feature. In order to keep it as is, remaining undefined symbols are replaced with dummy defined symbols. llvm-svn: 240913
2015-06-28COFF: Remove a function that doesn't do much itself. NFC.Rui Ueyama
llvm-svn: 240901
2015-06-28COFF: Handle LINK environment variable.Rui Ueyama
If LINK is defined and not empty, it's supposed to contain command line options. llvm-svn: 240900
2015-06-28COFF: Remove useless "explicit".Rui Ueyama
llvm-svn: 240899
2015-06-28COFF: Make doICF non-recursive. NFC.Rui Ueyama
llvm-svn: 240898
2015-06-28COFF: Fix ICF correctness bug.Rui Ueyama
When comparing two COMDAT sections, we need to take section values and associative sections into account. This patch fixes that bug. It fixes a crash bug of llvm-tblgen when linked with /opt:lldicf. One thing I don't understand yet is that this logic seems to be too strict. MSVC linker is able to create more compact executables (which of course work correctly). With this ICF algorithm, LLD is able to make executable smaller, but the outputs are larger than MSVC's. There must be something I'm missing here. llvm-svn: 240897
2015-06-27[opt] Inline a trivial lookup function into the header.Chandler Carruth
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
2015-06-27Switch the new COFF linker's symbol table to use a DenseMap ofChandler Carruth
StringRefs. This uses the LLVM hashing rather than the standard library and a closed addressed hash table rather than chaining. This improves the Windows self-link of LLD by 4.4% (averaged over 10 runs, with well under 1% of variance on each). There is still some room to improve here. Two things I clearly see in the profile: 1) This is one of the biggest stress tests for the LLVM hashing code. It actually consumes something like 3-4% of the link time after the change. 2) The way that StringRef keys are handled in the DenseMap interface is pretty suboptimal. We pay the price of checking for empty and tombstone keys when we could only possibly be looking for a normal key. But fixing this requires invasive API changes. So there is still some headroom here. Differential Revision: http://reviews.llvm.org/D10684 llvm-svn: 240871
2015-06-27COFF: Use vector::erase instead of reallocating entire vector. NFC.Rui Ueyama
llvm-svn: 240862
2015-06-27COFF: Avoid vector reallocation. NFC.Rui Ueyama
llvm-svn: 240859
2015-06-27COFF: Remove dead code.Rui Ueyama
llvm-svn: 240846
2015-06-27COFF: Add base relocation for delay-import table.Rui Ueyama
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
2015-06-27COFF: Fix delay-import tables.Rui Ueyama
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
2015-06-26Fix MSVC build.Peter Collingbourne
llvm-svn: 240818
2015-06-26COFF: Implement /lldmap flag.Peter Collingbourne
This flag can be used to produce a map file, which is essentially a list of objects linked into the final output file together with the RVAs of their symbols. Because our format differs from MSVC's we expose it as a separate flag. Differential Revision: http://reviews.llvm.org/D10773 llvm-svn: 240812
2015-06-26COFF: Align DLL import thunks on 16-byte boundaries.Rui Ueyama
llvm-svn: 240806
2015-06-26COFF: Fix README.Rui Ueyama
llvm-svn: 240802
2015-06-26COFF: Update README with the latest performance numbers.Rui Ueyama
llvm-svn: 240759
2015-06-26COFF: Change symbol resolution order for entry and /include.Rui Ueyama
We were resolving entry symbols and /include'd symbols after all other symbols are resolved. But looks like it's too late. I found that it causes some program to fail to link. Let's say we have an object file A which defines symbols X and Y in an archive. We also have another file B after A which defines X, Y and _DLLMainCRTStartup in another archive. They conflict each other, so either A or B can be linked. If we have _DLLMainCRTStartup as an undefined symbol, file B is always chosen. If not, there's a chance that A is chosen. If the linker find it needs _DllMainCRTStartup after that, it's too late. This patch adds undefined symbols to the symbol table as soon as possible to fix the issue. llvm-svn: 240757