summaryrefslogtreecommitdiffstats
path: root/lld/lib/Core
Commit message (Collapse)AuthorAgeFilesLines
...
* Remove InputGraph::getNextFile().Rui Ueyama2015-01-132-58/+28
| | | | | | | | | | | | getNextFile used to have a complex logic to determine which file should be processed by the Resolver on next iteration. Now, it is just a sequential accessor to the internal array and provides no sensible feature. This patch also removes InputGraph::getGroupSize and InputGraph:: skipGroup to simplify the code. llvm-svn: 225832
* Simplify.Rui Ueyama2015-01-131-25/+8
| | | | | | | We can remove these methods because every InputElement has only one File. llvm-svn: 225816
* Replace vector<unique_ptr<File> with unique_ptr<File>.Rui Ueyama2015-01-131-2/+2
| | | | | | | Because each InputElement has exactly one File, we no longer have to use a vector to store pointers to Files. llvm-svn: 225814
* Remove dead code.Rui Ueyama2015-01-131-18/+0
| | | | | | | Now every InputElement has exactly one File in it, so "expand" method is now no-op. llvm-svn: 225769
* Remove InputGraph::registerObserver.Rui Ueyama2015-01-131-11/+2
| | | | | | | | | | | | 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
* Remove InputGraph::dump().Rui Ueyama2015-01-131-7/+0
| | | | | | This is dead code. llvm-svn: 225766
* Convert CoreInputGraph.Rui Ueyama2015-01-061-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a part of InputGraph cleanup to represent input files as a flat list of Files (and some meta-nodes for group etc.) We cannot achieve that goal in one gigantic patch, so I split the task into small steps as shown below. (Recap the progress so far: Currently InputGraph contains a list of InputElements. Each InputElement contain one File (that used to have multiple Files, but I eliminated that use case in r223867). Files are currently instantiated in Driver::link(), but I already made a change to separate file parsing from object instantiation (r224102), so we can safely instantiate Files when we need them, instead of wrapping a file with the wrapper class (FileNode class). InputGraph used to act like a generator class by interpreting groups by itself, but it's now just a container of a list of InputElements (r223867).) 1. Instantiate Files in the driver and wrap them with WrapperNode. WrapperNode is a temporary class that allows us to instantiate Files in the driver while keep using the current InputGraph data structure. This patch demonstrates how this step 1 looks like, using Core driver as an example. 2. Do the same thing for the other drivers. When step 2 is done, an InputGraph consists of GroupEnd objects or WrapperNodes each of which contains one File. Other types of FileNode subclasses are removed. 3. Replace InputGraph with std::vector<std::unique_ptr<InputElement>>. InputGraph is already just a container of list of InputElements, so this step removes that needless class. 4. Remove WrapperNode. We need some code cleanup between each step, because many classes do a bit odd things (e.g. InputGraph::getGroupSize()). I'll straight things up as I need to. llvm-svn: 225313
* Replace ReaderError with DynamicError.Rui Ueyama2014-12-151-26/+0
| | | | | | | | | ReaderErrorCategory was used only at one place. We now have a DynamicErrorCategory for this kind of one-time error, so use it. The calling function doesn't really care the type of an error, so ReaderErrorCategory was actually dead code. llvm-svn: 224245
* Simplify InputGraph API.Rui Ueyama2014-12-143-53/+22
| | | | | | | | | These member functions returns either no_more_files error or a File object. We could simply return a nullptr instead of a no_more_files. This function will be removed soon as a part of InputGraph cleanup. I had to do that step by step. llvm-svn: 224208
* Make File always take the ownership of a MemoryBuffer.Rui Ueyama2014-12-121-11/+0
| | | | | | | | | | | | | | 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
* Re-commit r223330: Rewrite InputGraph's GroupRui Ueyama2014-12-102-54/+82
| | | | llvm-svn: 223867
* Revert "Rewrite InputGraph's Group"Rui Ueyama2014-12-042-82/+54
| | | | | | | | This reverts commit r223330 because it broke Darwin and ELF linkers in a way that we couldn't have caught with the existing test cases. llvm-svn: 223373
* Rewrite InputGraph's GroupRui Ueyama2014-12-042-54/+82
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The aim of this patch is to reduce the excessive abstraction from the InputGraph. We found that even a simple thing, such as sorting input files (Mach-O) or adding a new file to the input file list (PE/COFF), is nearly impossible with the InputGraph abstraction, because it hides too much information behind it. As a result, we invented complex interactions between components (e.g. notifyProgress() mechanism) and tricky code to work around that limitation. There were many occasions that we needed to write awkward code. This patch is a first step to make it cleaner. As a first step, this removes Group class from the InputGraph. The grouping feature is now directly handled by the Resolver. notifyProgress is removed since we no longer need that. I could have cleaned it up even more, but in order to keep the patch minimum, I focused on Group. SimpleFileNode class, a container of File objects, is now limited to have only one File. We shold have done this earlier. We used to allow putting multiple File objects to FileNode. Although SimpleFileNode usually has only one file, the Driver class actually used that capability. I modified the Driver class a bit, so that one FileNode is created for each input File. We should now probably remove SimpleFileNode and directly store File objects to the InputGraph in some way, because a container that can contain only one object is useless. This is a TODO. Mach-O input files are now sorted before they are passe to the Resolver. DarwinInputGraph class is no longer needed, so removed. PECOFF still has hacky code to add a new file to the input file list. This will be cleaned up in another patch. llvm-svn: 223330
* [Core] Remove function to not override RoundTripPasses.Shankar Easwaran2014-12-011-1/+1
| | | | | | | | | RoundTripPasses should always be called in DEBUG mode if the environment variable "LLD_RUN_ROUNDTRIP_TEST" is set. Flavors should not be able to override this behavior. llvm-svn: 223073
* [Core] Add flag to check if RoundTripPasses need to be run.Shankar Easwaran2014-12-011-0/+20
| | | | | | | | | | | | | | This would allow other flavor specific contexts to override the default value, if they want to optionally run the round trip passes. There is some information lost like the original file owner of the atom with RoundTripPasses. The Gnu flavor needs this information inorder to implement LinkerScript matching and for other diagnostic outputs such as Map files. The flag also can be used to record information in the Atom if the information to the Writer needs to be conveyed through References too. llvm-svn: 222983
* Follow-up to r221913. Fix some -Wcast-qual warning reasons.Simon Atanasyan2014-11-141-7/+9
| | | | llvm-svn: 221974
* [mach-o] Support linker synthesized mach_header symbols.Nick Kledzik2014-11-121-0/+1
| | | | | | | | | | | | | | | | | | | | | | | On darwin in final linked images, the __TEXT segment covers that start of the file. That means in memory a process can see the mach_header (and load commands) for every loaded image in a process. There are APIs that take and return the mach_header addresses as a way to specify a particular loaded image. For completeness, any code can get the address of the mach_header of the image it is in by using &__dso_handle. In addition there are mach-o type specific symbols like __mh_execute_header. The linker needs to supply a definition for any of these symbols if used. But the address the symbol it resolves to is not in any section. Instead it is the address of the start of the __TEXT segment. I needed to make a small change to SimpleFileNode to not override resetNextIndex() because the Driver creates a SimpleFileNode to hold the internal/implicit files that the context/writer can create. For some reason SimpleFileNode overrode resetNextIndex() to do nothing instead of reseting the index (which mach-o needs if the internal file is an archive). llvm-svn: 221822
* [mach-o] Add support for interposing tuples sectionNick Kledzik2014-11-061-0/+1
| | | | | | | | | | Darwin uses two-level-namespace lookup for symbols which means the static linker records where each symbol must be found at runtime. Thus defining a symbol in a dylib loaded earlier will not effect where symbols needed by later dylibs will be found. Instead overriding is done through a section of type S_INTERPOSING which contains tuples of <interposer, interposee>. llvm-svn: 221421
* [mach-o] remove __compact_unwind atoms once __unwind_info has been generatedTim Northover2014-11-041-0/+7
| | | | | | | | | | The job of the CompactUnwind pass is to turn __compact_unwind data (and __eh_frame) into the compressed final form in __unwind_info. After it's done, the original atoms are no longer relevant and should be deleted (they cause problems during actual execution, quite apart from the fact that they're not needed). llvm-svn: 221301
* Subclass InputGraph to get darwin linker library semanticsNick Kledzik2014-10-211-0/+2
| | | | | | | | | | | | | | | | | | | The darwin linker operates differently than the gnu linker with respect to libraries. The darwin linker first links in all object files from the command line, then to resolve any remaining undefines, it repeatedly iterates over libraries on the command line until either all undefines are resolved or no undefines were resolved in the last pass. When Shankar made the InputGraph model, the plan for darwin was for the darwin driver to place all libraries in a group at the end of the InputGraph. Thus making the darwin model a subset of the gnu model. But it turns out that does not work because the driver cannot tell if a file is an object or library until it has been loaded, which happens later. This solution is to subclass InputGraph for darwin and just iterate the graph the way darwin linker needs. llvm-svn: 220330
* Sort include files according to convention.Shankar Easwaran2014-10-185-12/+3
| | | | llvm-svn: 220131
* lld/lib/Core/Error.cpp: Appease g++-4.7, corresponding to LLVM r210687.NAKAMURA Takumi2014-10-171-0/+2
| | | | llvm-svn: 220039
* Use isa<> and cast<> instead of definition().Rui Ueyama2014-10-141-5/+3
| | | | | | No functionality change intended. llvm-svn: 219727
* PE/COFF: add a check to ensure that we dont mix up architecturesSaleem Abdulrasool2014-10-051-0/+2
| | | | | | | | | | | | | | | | 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
* Core: switch error mapping to switchesSaleem Abdulrasool2014-10-051-19/+32
| | | | | | | | | | Rather than a series of cascading ifs, use a switch statement to convert the error code to a string. This has the benefit of allowing the compiler to inform us if we ever add a new error code but fail to update the string representation. Add in stringified versions for a couple of missing InputGraphErrors. llvm-svn: 219089
* Preserve custom section names when coalescing.Nick Kledzik2014-10-021-0/+6
| | | | | | | | | | | | The mergeByContent attribute on DefinedAtoms triggers the symbol table to coalesce atoms with the exact same content. The problem is that atoms can also have a required custom section. The coalescing should never change the custom section of an atom. The fix is to only consider to atoms to have the same content if their sectionChoice() and customSectionName() attributes match. llvm-svn: 218893
* Add MachOLinkingContext parameter to MachOFileNode constructor.Nick Kledzik2014-10-011-1/+1
| | | | | | | | | | | No functionality change. This removes a down-cast from LinkingContext to MachOLinkingContext. Also, remove const from LinkingContext::createImplicitFiles() to remove the need for another const cast. Seems reasonable for createImplicitFiles() to need to modify the context (MachOLinkingContext does). llvm-svn: 218796
* [mach-o] Implement -demangle.Nick Kledzik2014-09-301-1/+2
| | | | | | | | | | | | | | The darwin linker has the -demangle option which directs it to demangle C++ (and soon Swift) mangled symbol names. Long term we need some Diagnostics object for formatting errors and warnings. But for now we have the Core linker just writing messages to llvm::errs(). So, to enable demangling, I changed the Resolver to call a LinkingContext method on the symbol name. To make this more interesting, the demangling code is done via __cxa_demangle() which is part of the C++ ABI, which is only supported on some platforms, so I had to conditionalize the code with the config generated HAVE_CXXABI_H. llvm-svn: 218718
* [mach-o] create __unwind_info section on x86_64Tim Northover2014-09-301-0/+1
| | | | | | | | | | | This is a minimally useful pass to construct the __unwind_info section in a final object from the various __compact_unwind inputs. Currently it doesn't produce any compressed pages, only works for x86_64 and will fail if any function ends up without __compact_unwind. rdar://problem/18208653 llvm-svn: 218703
* Use DenseMap::lookup. No functionality change.Rui Ueyama2014-09-261-4/+2
| | | | llvm-svn: 218554
* Fix crash bug on Windows.Rui Ueyama2014-09-261-2/+4
| | | | | | | Mutating the DenseMap here seems to cause the Windows executable to crash. Don't use operator[] to access possibly nonexistent key. llvm-svn: 218548
* Partially roll back r217324.Rui Ueyama2014-09-081-0/+2
| | | | llvm-svn: 217392
* [ELF] Export strong defined symbol if it coalesces away a weak symbolSimon Atanasyan2014-09-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | defined in a shared library. Now LLD does not export a strong defined symbol if it coalesces away a weak symbol defined in a shared library. This bug affects all ELF architectures and leads to segfault: % cat foo.c extern int __attribute__((weak)) flag; int foo() { return flag; } % cat main.c int flag = 1; int foo(); int main() { return foo() == 1 ? 0 : -1; } % clang -c -fPIC foo.c main.c % lld -flavor gnu -target x86_64 -shared -o libfoo.so ... foo.o % lld -flavor gnu -target x86_64 -o a.out ... main.o libfoo.so % ./a.out Segmentation fault The problem is caused by the fact that we lose all information about coalesced symbols after the `Resolver::resolve()` method is finished. The patch solves the problem by overriding the `LinkingContext::notifySymbolTableCoalesce()` method and saving names of coalesced symbols. Later in the `buildDynamicSymbolTable()` routine we use this information to export these symbols. llvm-svn: 217363
* Remove dead code.Rui Ueyama2014-09-071-6/+0
| | | | llvm-svn: 217324
* Simplify. No functionality changes.Rui Ueyama2014-08-221-6/+3
| | | | llvm-svn: 216257
* Add notifier hooks to symbol table.Nick Kledzik2014-08-201-0/+4
| | | | | | | | | | This is the one interesting aspect from: http://reviews.llvm.org/D4965 These hooks are useful for flavor specific processing, such as recording that a DefinedAtom replaced a weak SharedLibraryAtom. llvm-svn: 216122
* Change the signature of insertElementAt and rename addInputElementFrontRui Ueyama2014-07-241-11/+4
| | | | | | | | | | insertElementAt(x, END) does the identical thing as addInputElement(x), so the only reasonable use of insertElementAt is to call it with the other possible argument, BEGIN. That means the second parameter of the function is just redundant. This patch is to remove the second parameter and rename the function accordingly. llvm-svn: 213821
* Remove all uses of llvm::function_ref from LLD.Rui Ueyama2014-07-171-1/+1
| | | | llvm-svn: 213313
* Use std::function instead of llvm::function_ref.Rui Ueyama2014-07-171-1/+1
| | | | llvm-svn: 213312
* Update for llvm api change.Rafael Espindola2014-07-061-3/+4
| | | | llvm-svn: 212407
* [PECOFF] Support COMDAT associative sections.Rui Ueyama2014-06-171-1/+11
| | | | | | | | | | | | | | | | | | | COFF supports a feature similar to ELF's section groups. This patch implements it. In ELF, section groups are identified by their names, and they are treated somewhat differently from regular symbols. In COFF, the feature is realized in a more straightforward way. A section can have an annotation saying "if Nth section is linked, link this section too." I added a new reference type, kindAssociate. If a target atom is coalesced away, the referring atom is removed by Resolver, so that they are treated as a group. Differential Revision: http://reviews.llvm.org/D4028 llvm-svn: 211106
* Remove unused and odd code.Rafael Espindola2014-06-131-36/+0
| | | | | | | | This code was never being used and any use of it would look fairly strange. For example, it would try to map a NativeReaderError::file_malformed to std::errc::invalid_argument. llvm-svn: 210913
* Don't import error_code into the lld namespace.Rafael Espindola2014-06-123-5/+5
| | | | llvm-svn: 210785
* replace llvm::error_code with std::error_code.Rafael Espindola2014-06-121-5/+4
| | | | llvm-svn: 210781
* Use error_category from the std namespace.Rafael Espindola2014-06-121-11/+11
| | | | llvm-svn: 210732
* Use error_condition from the std namespace.Rafael Espindola2014-06-121-10/+10
| | | | llvm-svn: 210730
* Move Simple.h and Alias.h to include/Core.Rui Ueyama2014-06-111-2/+2
| | | | | | | | Because the files in Core actually depend on these files. Differential Revision: http://reviews.llvm.org/D4000 llvm-svn: 210710
* Use std::error_code instead of llvm::error_code.Rafael Espindola2014-06-111-5/+5
| | | | | | This is an update for a llvm api change. llvm-svn: 210689
* Missed these from the previous commit.Rafael Espindola2014-06-111-2/+2
| | | | llvm-svn: 210629
* Inherit from error_category instead of _do_message.Rafael Espindola2014-06-111-4/+4
| | | | | | There is no std::_do_message and these classes override message anyway. llvm-svn: 210626
OpenPOWER on IntegriCloud