summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
Commit message (Collapse)AuthorAgeFilesLines
* COFF: Remove the old COFF linker and make link an alias to link2.Rui Ueyama2015-08-061-1134/+0
| | | | | | It's time to remove old COFF linker because the new one is now complete. llvm-svn: 244226
* Update for llvm api change.Rafael Espindola2015-06-131-6/+5
| | | | llvm-svn: 239671
* Use MemoryBufferRef instead of MemoryBuffer&. NFC.Rafael Espindola2015-04-241-1/+1
| | | | | | This just reduces the noise from another patch. llvm-svn: 235776
* Return an ErrorOr<std::unique_ptr<File>>. NFC.Rafael Espindola2015-04-241-4/+5
| | | | llvm-svn: 235741
* Delete unnecessary generality in loadFile.Rafael Espindola2015-04-241-5/+3
| | | | | | | | | | | | | loadFile could load mulitple files just because yaml has a feature for putting multiple documents in one file. Designing a linker around what yaml can do seems like a bad idea to me. This patch changes it to read a single file. There are further improvements to be done to the api and they will follow shortly. llvm-svn: 235724
* Remove the Native file format.Rui Ueyama2015-04-101-5/+4
| | | | | | | | | | | | | The Native file format was designed to be the fastest on-memory or on-disk file format for object files. The problem is that no one is working on that. No LLVM tools can produce object files in the Native, thus the feature of supporting the format is useless in the linker. This patch removes the Native file support. We can add it back if we really want it in future. llvm-svn: 234641
* Rename atom_collection -> AtomVector.Rui Ueyama2015-04-081-8/+8
| | | | | | Type names should start with an uppercase letter in the LLVM coding style. llvm-svn: 234452
* Separate atom_collection type into two different types. NFC.Rui Ueyama2015-04-081-6/+6
| | | | | | | | | | | | | | | | | | | | atom_collection is basically a wrapper for std::vector. The class provides begin and end member functions, so that it "hides" the other member functions provided by std::vector. However, you can still directly access _atoms member since the member is not protected. We cannot simply make the member private because we need that member when we are constructing atom vectors. This patch splits atom_collection into two types: std::vector<Atom *> and AtomRange. When we are constructing atom vectors, we use the former class. We return instances of the latter class from File objects so that callers cannot add or remove atoms from the lists. std::vector<Atom *> is automatically converted to AtomRange. llvm-svn: 234450
* Merge atom_collection_vector with atom_collection.Rui Ueyama2015-04-081-4/+4
| | | | | | | atom_collection_vector is the only derived class of atom_collection. This patch merges the two. llvm-svn: 234443
* Remove a parameter for file extension from canParse.Rui Ueyama2015-04-041-2/+1
| | | | | | | | canParse took three parameters -- file magic, filename extension and memory buffer. All but YAMLReader ignored the second parameter. This patch removes the parameter. llvm-svn: 234080
* Use alignment values everywhere instead of log2.Rui Ueyama2015-03-261-6/+4
| | | | | | | | This patch defines implicit conversion between integers and PowerOf2 instances, so uses of the classes is now implicit and look like regular integers. Now we are ready to remove the scaffolding. llvm-svn: 233245
* PECOFF: Do not copy all undefined symbols to a set. NFC.Rui Ueyama2015-03-181-12/+8
| | | | llvm-svn: 232646
* Remove unused parameter.Rui Ueyama2015-03-181-7/+3
| | | | llvm-svn: 232639
* PECOFF: Make FileCOFF:findAtomAt from O(n) to O(1).Rui Ueyama2015-03-161-19/+18
| | | | | | | | I knew I cut corners when I wrote this. Turned out that it is actually slow when a file being read has many symbols. This patch is to stop doing linear search and instead do map lookup. llvm-svn: 232436
* Add SimpleAbsoluteAtom which is analogous to other Simple* atoms.Rui Ueyama2015-03-091-3/+2
| | | | llvm-svn: 231718
* Remove COFFReference and use SimpleReference instead.Rui Ueyama2015-03-091-5/+7
| | | | | | | SimpleReference, which is defined in Core, provides the same functionality as COFFReference does, so we don't need a custom class. llvm-svn: 231715
* PECOFF: Create layout-afters instead of layout-befores.Rui Ueyama2015-03-091-3/+3
| | | | | | | | | | | | | | | | All readers except PE/COFF reader create layout-after edges to preserve the original symbol order. PE/COFF uses layout-before edges as primary edges for no reason. This patch makes PE/COFF reader to create layout-after edges. Resolver is updated to recognize reverse edges of layout-after edges in the garbage collection pass. Now we can retire layout-before edges. I don't do that in this patch because if I do, I would have updated many tests to replace all occurrrences of "layout-before" with "layout-after". So that's a TODO. llvm-svn: 231615
* Re-commit r231545: PECOFF: Do not add extraneous symbols to the dead strip rootRui Ueyama2015-03-081-5/+3
| | | | | | | That commit was reverted in r231582 as it was a culprit for buildbot breakage. Turned out it's not. llvm-svn: 231610
* Revert r231545 to unbreak buildbot.Rui Ueyama2015-03-081-3/+5
| | | | | | | | | This patch reverts r231545 "PECOFF: Do not add extraneous symbols to the dead strip root." CrWinClangLLD buildbot is currently broken. Since I can't reproduce the issue locally, I'm reverting the most relevant change. llvm-svn: 231582
* PECOFF: Do not add extraneous symbols to the dead strip root.Rui Ueyama2015-03-071-5/+3
| | | | | | | | | | Previously we added all undefined symbols found in object files to the dead strip root. This patch makes the linker to stop doing that. Undefined symbols would be resolved anyway, so this patch doesn't change the linker behavior. It should slightly improve performance but it's really marginal. This is a cleanup. llvm-svn: 231545
* Remove unused typedefs.Rui Ueyama2015-03-071-5/+0
| | | | llvm-svn: 231543
* Use multimap<T, U> instead of map<T, set<U>>. NFC.Rui Ueyama2015-03-071-11/+6
| | | | llvm-svn: 231542
* PECOFF: Update comments on .drectve section encoding.Rui Ueyama2015-03-041-6/+4
| | | | llvm-svn: 231316
* PECOFF: Do not add layout-after edges.Rui Ueyama2015-03-041-2/+8
| | | | | | | | The last use of layout-after edge for PE/COFF was removed in r231290. Now layout-after edges do nothing. We can stop adding them to the graph. No functionality change intended. llvm-svn: 231301
* Define DefinedAtom::sectionSize.Rui Ueyama2015-03-041-9/+10
| | | | | | | | | | | | | | | | | | | | | | | | Merge::mergeByLargestSection is half-baked since it's defined in terms of section size, there's no way to get the section size of an atom. Currently we work around the issue by traversing the layout edges to both directions and calculate the sum of all atoms reachable. I wrote that code but I knew it's hacky. It's even not guaranteed to work. If you add layout edges before the core linking, it miscalculates a size. Also it's of course slow. It's basically a linked list traversal. In this patch I added DefinedAtom::sectionSize so that we can use that for mergeByLargestSection. I'm not very happy to add a new field to DefinedAtom base class, but I think it's legitimate since mergeByLargestSection is defined for section size, and the section size is currently just missing. http://reviews.llvm.org/D7966 llvm-svn: 231290
* Fix -Wcast-qual warning.Rui Ueyama2015-03-031-1/+1
| | | | llvm-svn: 231139
* 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-271-1/+1
| | | | | | | | | 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-271-1/+1
| | | | | | | | 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
* PECOFF: allow more than one /alternatename for the same symbol.Rui Ueyama2015-02-261-7/+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
* 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
* 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 five of the shared library build targetsGreg Fitzgerald2015-01-211-1/+1
| | | | | | | | | | | | | | | | | | 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
* [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
* Re-commit r225674: Convert other drivers to use WrapperNode.Rui Ueyama2015-01-151-2/+2
| | | | | | | | 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-141-2/+2
| | | | | | | r225764 broke a basic functionality on Mac OS. This change reverts r225764, r225766, r225767, r225769, r225814, r225816, r225829, and r225832. llvm-svn: 225859
* Convert other drivers to use WrapperNode.Rui Ueyama2015-01-131-2/+2
| | | | llvm-svn: 225764
* ReaderWriter: teach PE/COFF backend about ARM NTSaleem Abdulrasool2014-12-311-0/+3
| | | | | | | | | This teaches lld about the ARM NT object types. Add a trivial test to ensure that it can handle ARM NT object file inputs. It is still unable to perform the necessary relocations for ARM NT, but this allows the linker to at least read the objects. llvm-svn: 225052
* Make File always take the ownership of a MemoryBuffer.Rui Ueyama2014-12-121-1/+1
| | | | | | | | | | | | | | The documentation of parseFile() said that "the resulting File object may take ownership of the MemoryBuffer." So, whether or not the ownership of a MemoryBuffer would be taken was not clear. A FileNode (a subclass of InputElement, which is being deprecated) keeps the ownership if a File doesn't take it. This patch makes File always take the ownership of a buffer. Buffers lifespan is not always the same as File instances. Files are able to deallocate buffers after parsing the contents. llvm-svn: 224113
* Separate file parsing from File's constructors.Rui Ueyama2014-12-121-172/+159
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a second patch for InputGraph cleanup. Sorry about the size of the patch, but what I did in this patch is basically moving code from constructor to a new method, parse(), so the amount of new code is small. This has no change in functionality. We've discussed the issue that we have too many classes to represent a concept of "file". We have File subclasses that represent files read from disk. In addition to that, we have bunch of InputElement subclasses (that are part of InputGraph) that represent command line arguments for input file names. InputElement is a wrapper for File. InputElement has parseFile method. The method instantiates a File. The File's constructor reads a file from disk and parses that. Because parseFile method is called from multiple worker threads, file parsing is processed in parallel. In other words, one reason why we needed the wrapper classes is because a File would start reading a file as soon as it is instantiated. So, the reason why we have too many classes here is at least partly because of the design flaw of File class. Just like threads in a good threading library, we need to separate instantiation from "start" method, so that we can instantiate File objects when we need them (which should be very fast because it involves only one mmap() and no real file IO) and use them directly instead of the wrapper classes. Later, we call parse() on each file in parallel to let them do actual file IO. In this design, we can eliminate a reason to have the wrapper classes. In order to minimize the size of the patch, I didn't go so far as to replace the wrapper classes with File classes. The wrapper classes are still there. In this patch, we call parse() immediately after instantiating a File, so this really has no change in functionality. Eventually the call of parse() should be moved to Driver::link(). That'll be done in another patch. llvm-svn: 224102
* [PECOFF] Do not skip COMDAT section symbols.Rui Ueyama2014-11-051-11/+0
| | | | | | | | | LLD skipped COMDAT section symbols when reading them because I thought we don't want to have symbols with the same name. But they are actually needed because relocations may refer to the section symbols. So we shoulnd't skip them. llvm-svn: 221329
* PE/COFF: add ARM NT reference kindsSaleem Abdulrasool2014-10-071-0/+20
| | | | | | | | Teach the reader about ARM NT relocation types. Although the writer cannot yet perform the actual application of these relocations, the reader can at least now identify the relocation types. llvm-svn: 219178
* PE/COFF: add a check to ensure that we dont mix up architecturesSaleem Abdulrasool2014-10-051-1/+27
| | | | | | | | | | | | | | | | Previously, we would not check the target machine type and the module (object) machine type. Add a check to ensure that we do not attempt to use an object file with a different target architecture. This change identified a couple of tests which were incorrectly mixing up architecture types, using x86 input for a x64 target. Adjust the tests appropriately. The renaming of the input and the architectures covers the changes to the existing tests. One significant change to the existing tests is that the newly added test input for x64 uses the correct user label prefix for X64. llvm-svn: 219093
OpenPOWER on IntegriCloud