summaryrefslogtreecommitdiffstats
path: root/lld/COFF/Writer.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* COFF: Move code for ICF from Writer.cpp to ICF.cpp.Rui Ueyama2015-06-241-25/+3
| | | | llvm-svn: 240590
* COFF: Initial implementation of Identical COMDAT Folding.Rui Ueyama2015-06-241-0/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: Make link order compatible with MSVC link.exe.Rui Ueyama2015-06-231-4/+4
| | | | | | | | | | | | | Previously, we added files in directive sections to the symbol table as we read the sections, so the link order was depth-first. That's not compatible with MSVC link.exe nor the old LLD. This patch is to queue files so that new files are added to the end of the queue and processed last. Now addFile() doesn't parse files nor resolve symbols. You need to call run() to process queued files. llvm-svn: 240483
* COFF: Support delay-load import tables.Rui Ueyama2015-06-211-17/+38
| | | | | | | | | | | | | | | | DLLs are usually resolved at process startup, but you can delay-load them by passing /delayload option to the linker. If a /delayload is specified, the linker has to create data which is similar to regular import table. One notable difference is that the pointers in a delay-load import table are originally pointing to thunks that resolves themselves. Each thunk loads a DLL, resolve its name, and then overwrites the pointer with the result so that subsequent function calls directly call a desired function. The linker has to emit thunks. llvm-svn: 240250
* COFF: Use short varaible name. NFC.Rui Ueyama2015-06-211-14/+14
| | | | llvm-svn: 240232
* COFF: Support exception table.Rui Ueyama2015-06-211-0/+17
| | | | | | | | | | | | | | .pdata section contains a list of triplets of function start address, function end address and its unwind information. Linkers have to sort section contents by function start address and set the section address to the file header (so that runtime is able to find it and do binary search.) This change seems to resolve all but one remaining test failures in check{,-clang,-lld} when building the entire stuff with clang-cl and lld-link. llvm-svn: 240231
* COFF: Support creating DLLs.Rui Ueyama2015-06-171-0/+17
| | | | | | | | | | | | DLL files are in the same format as executables but they have export tables. The format of the export table is described in PE/COFF spec section 5.3. A new class, EdataContents, takes care of creating chunks for export tables. What we need to do is to parse command line flags for dllexports, and then instantiate the class to create chunks. For the writer, export table chunks are opaque data -- it just add chunks to .edata section. llvm-svn: 239869
* COFF: Add miscellaneous boolean flags.Rui Ueyama2015-06-161-2/+12
| | | | llvm-svn: 239864
* COFF: Use ulittle32_t::operator|=. NFC.Rui Ueyama2015-06-151-4/+4
| | | | llvm-svn: 239717
* COFF: Fix resource table size.Rui Ueyama2015-06-151-1/+1
| | | | | | The size field shouldn't include trailing padding. llvm-svn: 239712
* COFF: Support base relocations.Rui Ueyama2015-06-151-2/+52
| | | | | | | | | | | | | | | | | | | PE/COFF executables/DLLs usually contain data which is called base relocations. Base relocations are a list of addresses that need to be fixed by the loader if load-time relocation is needed. Base relocations are in .reloc section. We emit one base relocation entry for each IMAGE_REL_AMD64_ADDR64 relocation. In order to save disk space, base relocations are grouped by page. Each group is called a block. A block starts with a 32-bit page address followed by 16-bit offsets in the page. That is more efficient representation of addresses than just an array of 32-bit addresses. llvm-svn: 239710
* COFF: Change const name. NFC.Rui Ueyama2015-06-141-2/+2
| | | | llvm-svn: 239707
* COFF: Set Chunk to OutputSection backreference in addChunk().Rui Ueyama2015-06-141-1/+1
| | | | | | | | When we add a chunk to an OutputSection, we always want to create a backreference from an OutputSection to a Chunk. To make sure we always do, do that in addChunk(). NFC. llvm-svn: 239706
* COFF: Support Windows resource files.Rui Ueyama2015-06-141-0/+4
| | | | | | | | | | | Resource files are data files containing i18n messages, icon images, etc. MSVC has a tool to convert a resource file to a regular COFF file so that you can just link that file to embed resources to an executable. However, you can directly pass resource files to the linker. If you do that, the linker invokes the tool automatically. This patch implements that feature. llvm-svn: 239704
* COFF: Avoid callign stable_sort.Rui Ueyama2015-06-081-13/+13
| | | | | | | | | MSVC profiler reported that this stable_sort takes 7% time when self-linking. As a result, createSection was taking 10% time. Now createSection takes 3%. This small change actually makes the linker a bit but perceptibly faster. llvm-svn: 239292
* COFF: Add /opt:noref option.Rui Ueyama2015-06-071-1/+3
| | | | | | This option disables dead-stripping. llvm-svn: 239243
* COFF: Add comments and move main function to the top. NFC.Rui Ueyama2015-06-061-19/+26
| | | | llvm-svn: 239237
* COFF: Rename writeHeader -> writeHeaderTo.Rui Ueyama2015-06-061-2/+2
| | | | | | | | Chunk has writeTo function which takes uint8_t *Buf. writeHeaderTo feels more consistent with that because this member function also takes uint8_t *Buf. llvm-svn: 239236
* COFF: Inline a constant that is used only once.Rui Ueyama2015-06-061-4/+4
| | | | llvm-svn: 239235
* COFF: Add .didat section.Rui Ueyama2015-06-061-9/+13
| | | | llvm-svn: 239233
* COFF: Update comments.Rui Ueyama2015-06-061-1/+4
| | | | llvm-svn: 239232
* COFF: Move .idata constructor from Writer to Chunk.Rui Ueyama2015-06-061-76/+18
| | | | | | | | Previously, half of the constructor for .idata contents was in Chunks.cpp and the rest was in Writer.cpp. This patch moves the latter to Chunks.cpp. Now IdataContents class manages everything for .idata section. llvm-svn: 239230
* COFF: Merge Chunk::applyRelocations with Chunk::writeTo.Rui Ueyama2015-06-061-8/+0
| | | | | | | | In this design, Chunk is the only thing that knows how to write its contents to output file as well as how to apply relocations there. The writer shouldn't know about the details. llvm-svn: 239216
* COFF: /include'd symbols must be preserved.Rui Ueyama2015-06-041-2/+3
| | | | | | | | | Not only entry point symbol but also symbols specified by /include option must be preserved, as they will never be dead-stripped. http://reviews.llvm.org/D10220 llvm-svn: 239005
* COFF: Change OutputSections' type from vector<unique_ptr<T>> to vector<T*>.Rui Ueyama2015-06-031-17/+16
| | | | | | | This is mainly for readability. OutputSection objects are still owned by the writer using SpecificBumpPtrAllocator. llvm-svn: 238936
* COFF: Use Chunk instead of its derived classes.Rui Ueyama2015-06-011-3/+3
| | | | | | | | | I'm adding ordinal-only (nameless) imports to the import table. The chunk for that type is going to be different from LookupChunk. Without this change, we cannot add objects of the new type to the vectors. llvm-svn: 238779
* Fix comments.Rui Ueyama2015-06-011-1/+1
| | | | llvm-svn: 238718
* COFF: Define an error category for the linker.Rui Ueyama2015-06-011-4/+4
| | | | | | | | | | | | | 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
* Use initializer instead of memset to zero out.Rui Ueyama2015-05-301-5/+0
| | | | llvm-svn: 238662
* COFF: Support long section name.Rui Ueyama2015-05-301-6/+51
| | | | | | | | Section names were truncated to 8 bytes because the section table's name field is 8 byte long. This patch creates the string table to store long names. llvm-svn: 238661
* COFF: Move machine type auto-detection to SymbolTable.Peter Collingbourne2015-05-291-1/+17
| | | | | | | | | The new mechanism is less code, and fixes the case where all inputs are archives. Differential Revision: http://reviews.llvm.org/D10136 llvm-svn: 238618
* COFF: Add /subsystem option.Rui Ueyama2015-05-291-3/+5
| | | | llvm-svn: 238571
* COFF: Add /version option.Rui Ueyama2015-05-291-0/+2
| | | | llvm-svn: 238570
* COFF: Add /heap option.Rui Ueyama2015-05-291-2/+2
| | | | llvm-svn: 238569
* Add /stack option.Rui Ueyama2015-05-291-2/+2
| | | | llvm-svn: 238568
* COFF: Add /machine option.Rui Ueyama2015-05-291-1/+1
| | | | llvm-svn: 238564
* COFF: Return an error_code directly.Rui Ueyama2015-05-281-3/+1
| | | | llvm-svn: 238486
* COFF: Teach Chunk to write to a mmap'ed output file.Rui Ueyama2015-05-281-2/+1
| | | | | | | | | | | | | | Previously Writer directly handles writes to a file. Chunks needed to give Writer a continuous chunk of memory. That was inefficent if you construct data in chunks because it would require two memory copies (one to construct a chunk and the other is to write that to a file). This patch teaches chunk to write directly to a file. From readability point of view, this is also good because you no longer have to call hasData() before calling getData(). llvm-svn: 238464
* COFF: Add a new PE/COFF port.Rui Ueyama2015-05-281-0/+381
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