summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/PECOFF
Commit message (Collapse)AuthorAgeFilesLines
...
* Revert "PECOFF: Temporarily add a lock to un-break buildbot."Rui Ueyama2015-03-011-4/+0
| | | | | | | | | This reverts commit r230086. I added a lock to guard FileCOFF::doParse(), which killed parallel file parsing. Now the buildbots got back to green, I believe the threading issue was resolved, so it's time to remove the guard to see if it works with the buildbots. llvm-svn: 230886
* PECOFF: Move a call of WinLinkDriver::parse from FileCOFF::doParse to ↵Rui Ueyama2015-02-271-27/+26
| | | | | | | | | | | | | | | FileCOFF::beforeLink In doParse, we shouldn't do anything that has side effects. That function may be called speculatively and possibly in parallel. We called WinLinkDriver::parse from doParse to parse a command line in a .drectve section. The parse function updates a linking context object, so it has many side effects. It was not safe to call that function from doParse. beforeLink is a function for a File object to do something that has side effects. Moving a call of WinLinkDriver::parse to there. llvm-svn: 230791
* PECOFF: Use StringRef::find_first_of instead of a hand-written loop.Rui Ueyama2015-02-271-11/+3
| | | | llvm-svn: 230770
* Partially revert "PECOFF: Do not add layout-after edges."Rui Ueyama2015-02-272-7/+12
| | | | | | | | | This reverts commit r230732. sectionSize() in lib/Core/SymbolTable.cpp still depends on the layout- after edges, so we couldn't remove them yet. llvm-svn: 230734
* PECOFF: Do not add layout-after edges.Rui Ueyama2015-02-272-18/+7
| | | | | | | | Previously we needed to create atoms as a doubly-linked link, but it's no longer needed. Also we don't use layout-after edges in PE/COFF. Creating such edges is just waste. llvm-svn: 230732
* Twine should be used within a statement.Rui Ueyama2015-02-271-3/+3
| | | | llvm-svn: 230730
* Update comments, fix typos.Rui Ueyama2015-02-271-1/+4
| | | | llvm-svn: 230729
* Remove unused #includes.Rui Ueyama2015-02-272-2/+0
| | | | llvm-svn: 230726
* Add {read,write}{16,32,64}{le,be} functions.Rui Ueyama2015-02-273-14/+15
| | | | | | | | | | | | | | Nothing wrong with reinterpret_cast<llvm::support::ulittle32_t *>(loc), but that's redundant and not great from readability point of view. The new functions are wrappers for that kind of reinterpet_casts. Surprisingly or unsurprisingly, there was no use of big endian read and write. {read,write}{16,32,64}be have no user. But I think they still worth to be there in the header for completeness. http://reviews.llvm.org/D7927 llvm-svn: 230725
* PECOFF: allow more than one /alternatename for the same symbol.Rui Ueyama2015-02-262-18/+7
| | | | | | | | | | | Previously we have a string -> string map to keep the weak alias symbol mapping. Naturally we can't define more than one weak alias with that data structure. This patch is to allow multiple aliases for the same symbol by changing the map type to string -> set of string map. llvm-svn: 230702
* PECOFF: Temporarily add a lock to un-break buildbot.Rui Ueyama2015-02-201-0/+4
| | | | | | | | | | | | Looks like there's a threading issue in the COFF reader which makes buildbot unstable. Probability of crash varies depending on the number of input. If we are linking a big executalbe, LLD almost always crash. This patch temporarily adds a lock to guard the reader so that LLD doesn't crash. I'll investigate and fix the issue as soon as possible because this patch has negative performance impact. llvm-svn: 230086
* Remove YAML/Native round-trip passes.Rui Ueyama2015-02-201-1/+0
| | | | | | | | | | | | | | | | | | | | The round-trip passes were introduced in r193300. The intention of the change was to make sure that LLD is capable of reading end writing such file formats. But that turned out to be yet another over-designed stuff that had been slowing down everyday development. The passes ran after the core linker and before the writer. If you had an additional piece of information that needs to be passed from front-end to the writer, you had to invent a way to save the data to YAML/Native. These passes forced us to do that even if that data was not needed to be represented neither in an object file nor in an executable/DSO. It doesn't make sense. We don't need these passes. http://reviews.llvm.org/D7480 llvm-svn: 230069
* PECOFF: Fix base relocation for ImageBase.Rui Ueyama2015-02-201-1/+7
| | | | | | | | | | | | | | This is yet another edge case of base relocation for symbols. Absolute symbols are in general not target of base relocation because absolute atom is a way to point to a specific memory location. In r229816, I removed entries for absolute atoms from the base relocation table (so that they won't be fixed by the loader). However, there was one exception -- ImageBase. ImageBase points to the start address of the current image in memory. That needs to be fixed up at load time. This patch is to treat the symbol in a special manner. llvm-svn: 229961
* PECOFF: Fix base relocation for an absolute symbol.Rui Ueyama2015-02-191-0/+2
| | | | | | | | | | | | Previously we wrongly emitted a base relocation entry for an absolute symbol. That made the loader to rewrite some instruction operands with wrong values only when a DLL is not loaded at the default address. That caused a misterious crash of some executable. Absolute symbols will of course never change value wherever the binary is loaded to memory. We shouldn't emit base relocations for absolute symbols. llvm-svn: 229816
* PECOFF: Fix symbol aliasesRui Ueyama2015-02-181-13/+17
| | | | | | | | | | | | | | | | | | | | Weak aliases defined using /alternatename command line option were getting wrong RVAs in the final output because of wrong atom ordinal. Alias atoms were assigned large ordinals than any other regular atoms because they were instantiated after other atoms and just got new (larger) ordinals. Atoms are sorted by its file and atom ordinals in the order pass. Alias atoms were located after all other atoms in the same file. An alias atom's ordinal needs to be smaller than its alias target but larger than the atom appeared before the target -- so that the alias is located between the two. Since an alias has no size, the alias target will be located at the same location as the alias. In this patch, I made a gap between two regular atoms so that we can put aliases after instantiating them (without re-numbering existing atoms). llvm-svn: 229762
* Fix use-after-free bug identified by the Address SanitizerGreg Fitzgerald2015-02-181-3/+1
| | | | | | | | | atomContent's memory is freed at the end of the stack frame, but it is referenced by the atom pushed into _definedAtoms. Differential Revision: http://reviews.llvm.org/D7732 llvm-svn: 229749
* MSVC no longer requires the explicit cast operation to obtain a function ↵Aaron Ballman2015-02-161-7/+2
| | | | | | pointer from this capture-less lambda. NFC. llvm-svn: 229426
* PECOFF: Fix dummy symbol table in executable.Rui Ueyama2015-02-121-0/+4
| | | | | | | | | | | If the name field of a symbol table entry is all zero, it's interpreted as it's pointing to the beginning of the string table. The first four bytes of the string table is the size field, so dumpbin dumps that number as an ASCIZ string. This patch fills a dummy value to name field. llvm-svn: 228971
* PECOFF: make dumpbin tool happy.Rui Ueyama2015-02-121-8/+17
| | | | | | | | | | | | | | | | | | | | | The dumpbin tool in the MSVC toolchain cannot handle an executable created by LLD if the executable contains a long section name. In PE/COFF, a section name is stored to a section table entry. Because the section name field in the table is only 8 byte long, a name longer than that is stored to the string table and the offset in the string table is stored to the section table entry instead. In order to look up a string from the string table, tools need to handle the symbol table, because the string table is defined as it immediately follows the symbol table. And seems the dumpbin doesn't like zero-length symbol table. This patch teaches LLD how to emit a dummy symbol table. The dummy table has one dummy entry in it. llvm-svn: 228900
* PECOFF: Move error check for invalid command line combination to validateImpl.Rui Ueyama2015-02-061-0/+6
| | | | llvm-svn: 228461
* Use make_unique.Rui Ueyama2015-02-061-6/+6
| | | | llvm-svn: 228453
* PECOFF: Fix I386_DIR32 relocation to an absolute symbolRui Ueyama2015-02-051-2/+6
| | | | | | | | | | | | | Previously, we incorrectly added the image base address to an absolute symbol address (that calculation doesn't make any sense) if an IMAGE_REL_I386_DIR32 relocation is applied to an absolute symbol. This patch fixes the issue. With this fix, we can link Bochs using LLD. (Choosing Bochs has no special meaining -- I just picked it up as a test program and found it didn't work.) This also fixes one of the issues we currently have to link Chromium using LLD. llvm-svn: 228279
* ELF: Don't use LayoutPass.Rui Ueyama2015-01-311-11/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously we applied the LayoutPass to order atoms and then apply elf::ArrayOrderPass to sort them again. The first pass is basically supposed to sort atoms in the normal fashion (which is to sort symbols in the same order as the input files). The second pass sorts atoms in {init,fini}_array.<priority> by priority. The problem is that the LayoutPass is overkill. It analyzes references between atoms to make a decision how to sort them. It's slow, hard to understand, and above all, it doesn't seem that we need its feature for ELF in the first place. This patch remove the LayoutPass from ELF pass list. Now all reordering is done in elf::OrderPass. That pass sorts atoms by {init,fini}_array, and if they are not in the special section, they are ordered as the same order as they appear in the command line. The new code is far easier to understand, faster, and still able to create valid executables. Unlike the previous layout pass, elf::OrderPass doesn't count any attributes of an atom (e.g. permissions) except its position. It's OK because the writer takes care of them if we have to. This patch changes the order of final output, although that's benign. Tests are updated. http://reviews.llvm.org/D7278 llvm-svn: 227666
* Remove unused #includes.Rui Ueyama2015-01-301-3/+0
| | | | llvm-svn: 227526
* Add an assert to check atom ordinal.Rui Ueyama2015-01-291-0/+1
| | | | | | | No two atoms are allowed to have the same file and atom ordinals. If there's such atoms, there's a bug in the reader. llvm-svn: 227504
* PECOFF: Do not use LayoutPass and instead use simpler one.Rui Ueyama2015-01-292-15/+30
| | | | | | | | | | | | | | | | | | | | | | | | The LayoutPass is one of the slowest pass. This change is to skip that pass. This change not only improve performance but also improve maintainability of the code because the LayoutPass is pretty complex. Previously we used the LayoutPass to sort all atoms in a specific way, and reorder them again for PE/COFF in GroupedSectionPass. I spent time on improving and fixing bugs in the LayoutPass (e.g. r193029), but the pass is still hard to understand and hard to use. It's better not to depend on that if we don't need. For PE/COFF, we just wanted to sort atoms in the same order as the file order in the command line. The feature we used in the LayoutPass is now simplified to compareByPosition function in OrderPass.cpp. The function is just 5 lines. This patch changes the order of final output because it changes the sort order a bit. The output is still correct, though. llvm-svn: 227500
* Fix shared library buildGreg Fitzgerald2015-01-261-3/+4
| | | | | | | | | * Removed cyclic dependency between lldPECOFF and lldDriver * Added missing dependencies in unit tests Differential Revision: http://reviews.llvm.org/D7185 llvm-svn: 227134
* Fix the ELF shared library build targets - take 2Greg Fitzgerald2015-01-242-2/+3
| | | | | | | | | | lldELF is used by each ELF backend. lldELF's ELFLinkingContext also held a reference to each backend, creating a link-time cycle. This patch moves the backend references to lldDriver. Differential Revision: http://reviews.llvm.org/D7119 llvm-svn: 226976
* Revert " Fix the ELF shared library build targets"Greg Fitzgerald2015-01-232-3/+2
| | | | | | This reverts commit 6a3f545b44cea46321e025d9ab773786af86cb51. llvm-svn: 226928
* Fix the ELF shared library build targetsGreg Fitzgerald2015-01-232-2/+3
| | | | | | | | | | lldELF is used by each ELF backend. lldELF's ELFLinkingContext also held a reference to each backend, creating a link-time cycle. This patch moves the backend references to lldDriver. Differential Revision: http://reviews.llvm.org/D7119 llvm-svn: 226922
* Fix five of the shared library build targetsGreg Fitzgerald2015-01-213-4/+4
| | | | | | | | | | | | | | | | | | Before this patch there was a cyclic dependency between lldCore and lldReaderWriter. Only lldConfig could be built as a shared library. * Moved Reader and Writer base classes into lldCore. * The following shared libraries can now be built: lldCore lldYAML lldNative lldPasses lldReaderWriter Differential Revision: http://reviews.llvm.org/D7105 From: Greg Fitzgerald <garious@gmail.com> llvm-svn: 226732
* add_lld_library -> add_llvm_libraryGreg Fitzgerald2015-01-211-8/+5
| | | | | | | | | | | * Works better for shared libraries (sets PRIVATE instead of INTERFACE) * Fixes http://llvm.org/bugs/show_bug.cgi?id=22269 * Also, use build-target names instead of component names Differential Revision: http://reviews.llvm.org/D7074 From: Greg Fitzgerald <garious@gmail.com> llvm-svn: 226702
* Add LLVM_LINK_COMPONENTS for the shared object buildGreg Fitzgerald2015-01-161-0/+2
| | | | | | | Differential Revision: http://reviews.llvm.org/D7023 From: Greg Fitzgerald <garious@gmail.com> llvm-svn: 226346
* [PATCH] Speculatively instantiate archive membersRui Ueyama2015-01-161-4/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | LLD parses archive file index table only at first. When it finds a symbol it is looking for is defined in a member file in an archive file, it actually reads the member from the archive file. That's done in the core linker. That's a single-thread process since the core linker is single threaded. If your command line contains a few object files and a lot of archive files (which is quite often the case), LLD hardly utilizes hardware parallelism. This patch improves parallelism by speculatively instantiating archive file members. At the beginning of the core linking, we first create a map containing all symbols defined in all members, and each time we find a new undefined symbol, we instantiate a member file containing the symbol (if such file exists). File instantiation is side effect free, so this should not affect correctness. This is a quick benchmark result. Time to link self-link LLD executable: Linux 9.78s -> 8.50s (0.86x) Windows 6.18s -> 4.51s (0.73x) http://reviews.llvm.org/D7015 llvm-svn: 226336
* PE/COFF: rework how we handle base relocationsSaleem Abdulrasool2015-01-161-51/+59
| | | | | | | | | | | | | Generalise the base relocation handling slightly to support multiple base relocation types in PE/COFF. This is necessary to generate proper executables for WoA. Track the base relocation type from the decision that we need a base relocation to the point where we emit the base relocation into base relocation directory. Remove an outdated TODO item while in the area. llvm-svn: 226335
* [PECOFF] Remove ResolvableSymbols to simplify.Rui Ueyama2015-01-163-44/+36
| | | | | | | | | | | We had such class there because of InputGraph abstraction. Previously, no one except InputGraph itself has complete picture of input file list. In order to create a set of all defined symbols, we had to use some indirections there to workaround InputGraph. It can now be rewritten as simple code. No change in functionality. llvm-svn: 226319
* Run the resolver in parallel with the reader.Rui Ueyama2015-01-161-1/+10
| | | | | | | | | | | | | | | | | | | | This patch makes File::parse() multi-thread safe. If one thread is running File::parse(), other threads will block if they try to call the same method. File::parse() is idempotent, so you can safely call multiple times. With this change, we don't have to wait for all worker threads to finish in Driver::link(). Previously, Driver::link() calls TaskGroup::sync() to wait for all threads running File::parse(). This was not ideal because we couldn't start the resolver until we parse all files. This patch increase parallelism by making Driver::link() to not wait for worker threads. The resolver calls parse() to make sure that the file being read has been parsed, and then uses the file. In this approach, the resolver can run with the parser threads in parallel. http://reviews.llvm.org/D6994 llvm-svn: 226281
* PE/COFF: use dyn_cast for the check of the targetSaleem Abdulrasool2015-01-161-1/+1
| | | | | | | | | | The target may be a synthetic symbol like __ImageBase. cast_or_null will ensure that the atom is a DefinedAtom, which is not guaranteed, which was the original reason for the cast_or_null. Switch this to dyn_cast, which should enable building of executables for WoA. Unfortunately, the issue of missing base relocations still needs to be investigated. llvm-svn: 226246
* Remove InputGraph and use std::vector<Node> instead.Rui Ueyama2015-01-151-4/+2
| | | | | | In total we have removed more than 1000 lines! llvm-svn: 226149
* Rename InputElement Node.Rui Ueyama2015-01-151-2/+2
| | | | | | | | | InputElement was named that because it's an element of an InputGraph. It's losing the origin because the InputGraph is now being removed. InputElement's subclass is FileNode, that naming inconsistency needed to be fixed. llvm-svn: 226147
* Remove InputGraph::addInputElement{,Front}.Rui Ueyama2015-01-151-3/+5
| | | | | | | | They were the last member functions of InputGraph (besides members()). Now InputGraph is just a container of a vector. We are ready to replace InputGraph with plain File vector. llvm-svn: 226146
* Remove WrapperNode.Rui Ueyama2015-01-151-5/+4
| | | | | | | WrapperNode was a useless subclass of FileNode. We should just use FileNode instead. llvm-svn: 226145
* Remove InputGraph::size().Rui Ueyama2015-01-151-1/+1
| | | | llvm-svn: 226140
* Merge SimpleFileNode with WrapperNode.Rui Ueyama2015-01-151-12/+9
| | | | llvm-svn: 226137
* [PECOFF] Remove an InputElement placeholder for the entry name.Rui Ueyama2015-01-151-5/+8
| | | | llvm-svn: 226133
* Re-commit r225766, r225767, r225769, r225814, r225816, r225829, and r225832.Rui Ueyama2015-01-152-49/+31
| | | | | | | These changes depended on r225674 and had been rolled back in r225859. Because r225674 has been re-submitted, it's safe to re-submit them. llvm-svn: 226132
* Re-commit r225674: Convert other drivers to use WrapperNode.Rui Ueyama2015-01-153-10/+9
| | | | | | | | The original commit had an issue with Mac OS dylib files. It didn't handle fat binary dylib files correctly. This patch includes a fix. A test for that case has already been committed in r225764. llvm-svn: 226123
* Revert "Convert other drivers to use WrapperNode" and subsequent commits.Rui Ueyama2015-01-144-36/+54
| | | | | | | r225764 broke a basic functionality on Mac OS. This change reverts r225764, r225766, r225767, r225769, r225814, r225816, r225829, and r225832. llvm-svn: 225859
* Remove InputGraph::registerObserver.Rui Ueyama2015-01-132-49/+31
| | | | | | | | | | | | PECOFF was the only user of the API, and the reason why we created the API is because, although the driver creates a list of input files, it has no knowledge on what files are being created. It was because everything was hidden behind the InputGraph abstraction. Now the driver knows what that's doing. We no longer need this indirection to get the file list being processed. llvm-svn: 225767
* Convert other drivers to use WrapperNode.Rui Ueyama2015-01-133-5/+5
| | | | llvm-svn: 225764
OpenPOWER on IntegriCloud