summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter
Commit message (Collapse)AuthorAgeFilesLines
...
* [mach-o] avoid overly clever std::find_ifTim Northover2014-10-157-16/+56
| | | | | | | The bots were complaining (possibly because of a lack of traits on the iterator I was trying to use). No functional change. llvm-svn: 219843
* [mach-o] make __unwind_info defer to __eh_frame when necessary.Tim Northover2014-10-159-47/+184
| | | | | | | | | | | | Not all situations are representable in the compressed __unwind_info format, and when this happens the entry needs to point to the more general __eh_frame description. Just x86_64 implementation for now. rdar://problem/18208653 llvm-svn: 219836
* [macho] Create references from __eh_frame FDEs to their function.Tim Northover2014-10-157-1/+135
| | | | | | | | | | | | | We'll also need references back to the CIE eventually, but for now making sure we can work out what an FDE is referring to is enough. The actual kind of reference needs to be different between architectures, probably because of MachO's chronic shortage of relocation types but I don't really want to know in case I find out something that distresses me even more. rdar://problem/18208653 llvm-svn: 219824
* Remove dead code.Rui Ueyama2014-10-141-42/+34
| | | | | | | | | | | Because we use cast<> at the beginning of this function, it will abort there if a given atom is not a DefinedAtom. In the switch statement, we checked if a given atom is a DefinedAtom again by evaluating definition() == Atom::definitionRegular. This was always true. So we can remove the outer switch statement. llvm-svn: 219724
* Use isa<> instead of checking return value of definition().Rui Ueyama2014-10-142-2/+2
| | | | | | | definition() is supposed to be used through isa, dyn_cast or cast. It's better to not call that directly. llvm-svn: 219723
* Use llvm::make_unique.Rui Ueyama2014-10-143-14/+12
| | | | llvm-svn: 219709
* [mach-o] Add Pass to create are shim Atoms for ARM interworking.Nick Kledzik2014-10-149-13/+367
| | | | | | | | | | | | | | | Arm code has two instruction encodings "thumb" and "arm". When branching from one code encoding to another, you need to use an instruction that switches the instruction mode. Usually the transition only happens at call sites, and the linker can transform a BL instruction in BLX (or vice versa). But if the compiler did a tail call optimization and a function ends with a branch (not branch and link), there is no pc-rel BX instruction. The ShimPass looks for pc-rel B instructions that will need to switch mode. For those cases it synthesizes a shim which does the transition, then modifies the original atom with the B instruction to target to the shim atom. llvm-svn: 219655
* Reapply [ELF] Only mark as DT_NEEDED libs that are strictly necessary (r219353)Rafael Auler2014-10-0911-36/+49
| | | | | | | | | | | | | | | | | | | | When committed in r219353, this patch originally caused problems because it was not tested in debug build. In such scenarios, Driver.cpp adds two additional passes. These passes serialize all atoms via YAML and reads it back. Since the patch changed ObjectAtom to hold a new reference, the serialization was removing the extra data. This commit implements r219853 in another way, similar to the original MIPS way, by using a StringSet that holds the names of all copied atoms instead of directly holding a reference to the copied atom. In this way, this commit is simpler and eliminate the necessity of changing the DefinedAtom hierarchy to hold a new data. Reviewers: shankarke http://reviews.llvm.org/D5713 llvm-svn: 219449
* [PECOFF] Refactor _imp_ symbol generator.Rui Ueyama2014-10-091-21/+28
| | | | | | | | We are going to have another type of jump table for the delay-load import table. In order to prepare for that, we want to factor out the function handling the jump table. No functionality change. llvm-svn: 219446
* [PECOFF] Remove another use of is64 to support non-Intel architectureRui Ueyama2014-10-091-19/+30
| | | | llvm-svn: 219438
* [PECOFF] Emit ModuleHandle field in delay-import table.Rui Ueyama2014-10-092-3/+22
| | | | | | | | Previously the field was not set. The field should be pointing to a placeholder where the DLL delay-loader writes the base address of a DLL. llvm-svn: 219415
* [PECOFF] Emit the delay-import tableRui Ueyama2014-10-093-3/+89
| | | | | | | | | | | This is a partial patch to emit the delay-import table. With this, LLD is now able to emit the table that llvm-readobj can read and dump. The table lacks a few fields, such as the address of HMODULE, the import address table, etc. They'll be added in subsequent patches. llvm-svn: 219384
* [ELF] Fix uninitialized variablesRafael Auler2014-10-092-4/+6
| | | | | | | Properly initialize _exportDynamic in ELFLinkingContext and an ELF_Sym object created in CRuntimeFile with default values. llvm-svn: 219380
* [mach-o] Use default for min OS version when not specified on command line.Nick Kledzik2014-10-091-0/+20
| | | | | | This matches the current darwin linker. llvm-svn: 219376
* Revert "[ELF] Only mark as DT_NEEDED libs that are strictly necessary"Rui Ueyama2014-10-0914-57/+41
| | | | | | This reverts commit r219353 because that seems to break buildbots. llvm-svn: 219369
* [ELF] Only mark as DT_NEEDED libs that are strictly necessaryRafael Auler2014-10-0814-41/+57
| | | | | | | | | | | | | | | | | | | | | Enhances the creation of an ELF dynamic executable by avoiding recording unnecessary shared libraries as NEEDED to load a program. To do this, we must keep track of not only symbols that were referenced but also of COPY relocations, which steal the symbol from a shared library but does not store from which lib this symbol came from. To fix this, this commit changes ObjectSymbol to store the original library from which this symbol came. With this information, we are able to build a list of the exact shared libraries that must be marked as DT_NEEDED, instead of blindly marking all shared libraries as needed. This logic originally came from the MIPS backend with some adaptation. Reviewers: atanasyan, shankar.easwaran http://reviews.llvm.org/D5574 llvm-svn: 219353
* [ELF] [X86_64] Update TODO.rst list wrt r218633Rafael Auler2014-10-081-6/+2
| | | | | | | | | | | Updates the remaining tasks in the X86_64 ELF lld backend after the commit that handles general dynamic TLS relocations. Reviewer: shankarke http://reviews.llvm.org/D5673 llvm-svn: 219350
* [ELF] Fix inclusion of weak symbols in the dynamic symbol tableRafael Auler2014-10-084-19/+62
| | | | | | | | | | | | | | | | | This commit implements in the X86_64 ELF lld backend yet another feature that was only available in the MIPS backend. However, this patch changes generic ELF classes to make it trivial for other ELF backends to use this logic too. When creating a dynamic executable that has dynamic relocations against weak undefined symbols, these symbols must be exported to the dynamic symbol table to seek a possible resolution at run time. A common use case is the __gmon_start__ weak glibc undefined symbol. Reviewer: shankarke http://reviews.llvm.org/D5571 llvm-svn: 219349
* [PECOFF] Simplify IdataPass. No functionality change.Rui Ueyama2014-10-082-5/+5
| | | | llvm-svn: 219348
* Use llvm::StringSwitch.Rui Ueyama2014-10-081-19/+16
| | | | llvm-svn: 219341
* [ELF] Implement --export-dynamic/-ERafael Auler2014-10-082-9/+20
| | | | | | | | | | | | | | | | | When creating a dynamic executable and receiving the -E flag, the linker should export all globally visible symbols in its dynamic symbol table. This commit also moves the logic that exports symbols in the dynamic symbol table from OutputELFWriter to the ExecutableWriter class. It is not correct to leave this at OutputELFWriter because DynamicLibraryWriter, another subclass of OutputELFWriter, already exports all symbols, meaning we can potentially end up with duplicated symbols in the dynamic symbol table when creating shared libs. Reviewers: shankarke http://reviews.llvm.org/D5585 llvm-svn: 219334
* Revert "[ELF][AllArchs] Fix includes"Shankar Easwaran2014-10-0825-53/+53
| | | | | | This reverts commit e137dd93e1291a2d2fa7f41c8f8bcdb59c8b3225. llvm-svn: 219313
* [ELF][AllArchs] Fix includesShankar Easwaran2014-10-0825-53/+53
| | | | llvm-svn: 219278
* [mach-o] Support fat archivesNick Kledzik2014-10-083-37/+57
| | | | | | | | | | | | | | mach-o supports "fat" files which are a header/table-of-contents followed by a concatenation of mach-o files (or archives of mach-o files) built for different architectures. Previously, the support for fat files was in the MachOReader, but that only supported fat .o files and dylibs (not archives). The fix is to put the fat handing into MachOFileNode. That way any input file kind (including archives) can be fat. MachOFileNode selects the sub-range of the fat file that matches the arch being linked and creates a MemoryBuffer for just that subrange. llvm-svn: 219268
* [PECOFF] Move a function out of a classRui Ueyama2014-10-082-35/+31
| | | | | | | I'm going to use this function both for the import table and the delay-import table. llvm-svn: 219267
* [PECOFF] Remove yet another use of _is64Rui Ueyama2014-10-076-54/+65
| | | | | | No functionality change intended. llvm-svn: 219246
* PE/COFF: rename applyRelocations* familySaleem Abdulrasool2014-10-071-18/+18
| | | | | | | Use x86 and x64 which is the canonical Microsoft vernacular for the targets. Addresses post-commit review comments from Rui. llvm-svn: 219179
* 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
* Do not use llvm_unreachable at reachable code.Rui Ueyama2014-10-071-3/+3
| | | | | | | These lines can be reachable if we give a broken or unsupported input object file. llvm-svn: 219176
* 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
* PE/COFF: remove another use of PECOFFLinkingContext::is64bitSaleem Abdulrasool2014-10-051-20/+37
| | | | | | | | | | | | | In order to support more than x86/x86_64, we need to change the behaviour to use the actual machine type rather than checking the bitness and assuming that we are on X86. This replaces the use of is64bit in applyAllRelocations with a check on the machine type. This will enable adding support for handling ARM relocations. Rename the existing applyRelocation methods to be similarly named and to make it clear the types of relocations they will process. llvm-svn: 219088
* [mach-o] Add support for -dependency_info command line optionNick Kledzik2014-10-041-4/+66
| | | | | | | | | | | This option is added by Xcode when it runs the linker. It produces a binary file which contains the file the linker used. Xcode uses the info to dynamically update it dependency tracking. To check the content of the binary file, the test case uses a python script to dump the binary file as text which FileCheck can check. llvm-svn: 219039
* [ELF] Fix bug in ELFFile::createAtoms() that caused lld to mislink muslRafael Auler2014-10-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When creating the graph edges of the atoms of an ELF file, special care must be taken with atoms that represent weak symbols. They cannot be the target of any Reference::kindLayoutAfter edge because they can be merged and point to other code, screwing up the final layout of the atoms. ELFFile::createAtoms() correctly handles this corner case. The problem is that createAtoms() assumed that there can be no zero-sized weak symbols, which is not true. Consider: my_weak_func1: my_weak_func2: my_weak_func3: code In this case, we have two zero-sized weak symbols, my_weak_func1 and my_weak_func2, and one non-zero weak symbol my_weak_func3. createAtoms() would correctly handle my_weak_func3, but not the first two symbols. This problem happens in the musl C library when a zero-sized weak symbol is merged and screws up the file layout. Since this musl code lives at the finalization hooks, any C program linked with LLD and musl was correctly executing, but segfaulting at the end. Reviewers: shankarke http://reviews.llvm.org/D5606 llvm-svn: 219034
* [mach-o] preserve custom section names on coalesable stringsNick Kledzik2014-10-021-5/+23
| | | | llvm-svn: 218894
* [ELF] Never mark the dynamic linker as DT_NEEDEDRafael Auler2014-10-021-0/+3
| | | | | | | | | | | | This patch adds logic to avoid putting the dynamic linker library (ld.so) as a DT_NEEDED entry in the dynamic table. It should only appear in PT_INTERP. This patch fixes SPEC programs 433, 445, 450, 453, 456, 462 when running on Ubuntu Linux x86_64 and when linking SPEC programs with LLD and glibc 2.19. http://reviews.llvm.org/D5573 llvm-svn: 218847
* [lld] [ELF] [MIPS] Remove duplicate logicRafael Auler2014-10-023-12/+0
| | | | | | | | | | | | | | Summary: With r218633, the logic that monitors which shared library symbols were used was copied from the MIPS lld backend to ELF classes, making it available to all ELF backends. However, this made the isDynSymEntryRequired() functions in MipsDynamicLibraryWriter.h/MipsELFWriters.h/MipsExecutableWriter.h to be duplicated logic, since this is already implemented in OutputELFWriter<>/DefaultLayout. This patch removes this duplicated code from MIPS. Reviewers: Bigcheese, shankarke Reviewed By: shankarke Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D5564 llvm-svn: 218846
* Add MachOLinkingContext parameter to MachOFileNode constructor.Nick Kledzik2014-10-012-5/+5
| | | | | | | | | | | 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
* [PECOFF] Fix x64 export table.Rui Ueyama2014-10-012-4/+5
| | | | | | | Export table entry is 64 bit wide in x64. If MSB is 1, it means it's imported by ordinal. The shift value was wrong. llvm-svn: 218728
* [mach-o] Implement -demangle.Nick Kledzik2014-09-301-1/+34
| | | | | | | | | | | | | | 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
* [PECOFF] Fix /entry option.Rui Ueyama2014-09-301-3/+10
| | | | | | | | This is yet another edge case of ambiguous name resolution. When a symbol is specified with /entry:SYM, SYM may be resolved to the C++ mangled function name (?SYM@@YAXXZ). llvm-svn: 218706
* [PECOFF] Move helper function out of classRui Ueyama2014-09-303-33/+55
| | | | | | No functionality change intended. llvm-svn: 218705
* [mach-o] add file comment to compact unwind passTim Northover2014-09-301-1/+3
| | | | llvm-svn: 218704
* [mach-o] create __unwind_info section on x86_64Tim Northover2014-09-3011-12/+586
| | | | | | | | | | | 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
* [PECOFF] Fix __imp_ prefix on x64.Rui Ueyama2014-09-301-8/+8
| | | | | | | | "__imp_" prefix always starts with double underscores. When I was writing the original code I misunderstood that it's "_imp_" on x64. llvm-svn: 218690
* [lld] [ELF] Support for general dynamic TLS relocations on X86_64Rafael Auler2014-09-2913-44/+74
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch adds support for the general dynamic TLS access model for X86_64 (see www.akkadia.org/drepper/tls.pdf). To properly support TLS, the patch also changes the __tls_get_addr atom to be a shared library atom instead of a regularly defined atom (the previous lld approach). This closely models the reality of a function that will be resolved at runtime by the dynamic linker and loader itself (ld.so). I was tempted to force LLD to link against ld.so itself to resolve these symbols, but since GNU ld does not need the ld.so library to resolve this symbol, I decided to mimic its behavior and keep hardwired a definition of __tls_get_addr in the lld code. This patch also moves some important logic that previously was only available to the MIPS lld backend to be used to all ELF backends. This logic, which now lives in the DefaultLayout class, will monitor which external (shared lib) symbols are really imported by the current module and will only populate the dynamic symbol table with used symbols, as opposed to the previous approach of dumping all shared lib symbols in the dynamic symbol table. This is important to this patch to avoid __tls_get_addr from getting injected into all dynamic symbol tables. By solving the previous problem of always adding __tls_get_addr, now the produced symbol tables are slightly smaller. But this impacted several tests that relied on hardwired/predefined sizes of the symbol table, requiring this patch to update such tests. Test Plan: Added a LIT test case that exercises a simple use case of TLS variable in a shared library. Reviewers: ruiu, rafael, Bigcheese, shankarke Reviewed By: Bigcheese, shankarke Subscribers: emaste, shankarke, joerg, kledzik, mcrosier, llvm-commits Projects: #lld Differential Revision: http://reviews.llvm.org/D5505 llvm-svn: 218633
* [PECOFF] Fix module definition file outputRui Ueyama2014-09-251-9/+5
| | | | | | | | Previously we emit two or more identical definitions for an exported symbol if the same /export option is given more than once. This patch fixes that bug. llvm-svn: 218433
* [AArch64] Fix an incorrect PLT entry.Chad Rosier2014-09-241-1/+2
| | | | | | | | | | This patch is difficult to test in isolation, so a subsequent patch will test further. Patch by Daniel Stewart <stewartd@codeaurora.org>! Phabricator Revision: http://reviews.llvm.org/D5377 llvm-svn: 218418
* [PECOFF] Do not print @<ordinal> if the symbol is privateRui Ueyama2014-09-241-1/+3
| | | | | | | | | | | | lib.exe prints a warning if a symbol in a module definition file has both the PRIVATE attribute and an ordinal like this. EXPORTS foo @1 PRIVATE This patch suppresses that. llvm-svn: 218395
* [PECOFF] Exported name should match C++ mangled nameRui Ueyama2014-09-241-21/+31
| | | | | | | | | | | | | | Currently you can omit the leading underscore from exported symbol name. LLD will look for mangled name for you. But it won't look for C++ mangled name. This patch is to support that. If "sym" is specified to be exported, the linker looks for not only "sym", but also "_sym" and "?sym@@<whatever>", so that you can export a C++ function without decorating it. llvm-svn: 218355
* [PECOFF] Keep renamed undefined symbol name in export descriptorRui Ueyama2014-09-242-14/+7
| | | | | | | | | | | | | | | | | Exported symbol name resolution is two-pass. In the first pass, we try to resolve that as a regular undefined symbol. If it fails, we look for mangled name for the symbol and rename the undefined symbol and try again. After all name resolution is done, we look for an atom for each exported symbol again, to construct the export table. In this process we try the regular names first, and then try mangled names. But at this moment we should have knew which name is correct. This patch is to keep the information we get in the first process to use it later. llvm-svn: 218354
OpenPOWER on IntegriCloud