summaryrefslogtreecommitdiffstats
path: root/lld/lib
Commit message (Collapse)AuthorAgeFilesLines
...
* [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
* [PECOFF] Infer machine type from input object fileRui Ueyama2014-10-071-3/+39
| | | | | | | If /machine option is omitted, the linker needs to infer that from input object files. This patch implements that. llvm-svn: 219180
* 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-052-1/+29
| | | | | | | | | | | | | | | | 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
* 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 -iphoneos_version_min as alias for -ios_version_minNick Kledzik2014-10-041-0/+2
| | | | llvm-svn: 219041
* [mach-o] Add support for -dependency_info command line optionNick Kledzik2014-10-044-4/+82
| | | | | | | | | | | 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
* [PECOFF] Resolve __delayLoadHelper2 if /delayload is givenRui Ueyama2014-10-032-1/+6
| | | | | | | | | | | | | | | | | | DLL delay importing is a feature to load a DLL lazily, instead of at program start-up time. If the feature is turned on with the /delayload flag, the linker resolves the delay-load helper function. All function pointer table entries for the DLL are initially pointing to the helper function. When called, the function loads and resolves the DLL symbols using dlopen-ish Windows system calls and then write the reuslts to the function pointer table. The helper function is in "delayimp.lib". Note that this feature is not completely implemented yet. LLD also needs to emit the table that's consumed by the delay-load helper function. That'll be done in another patch. llvm-svn: 218943
* [mach-o] preserve custom section names on coalesable stringsNick Kledzik2014-10-021-5/+23
| | | | llvm-svn: 218894
* 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
* [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-015-14/+13
| | | | | | | | | | | 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-304-2/+42
| | | | | | | | | | | | | | 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-3012-12/+587
| | | | | | | | | | | 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] Allow /export:<symbol>,PRTVATE.Rui Ueyama2014-09-301-3/+7
| | | | | | PRIVATE option is also an undocumented feature. llvm-svn: 218696
* [PECOFF] Fix /export option.Rui Ueyama2014-09-301-3/+12
| | | | | | | | | | | MSDN doesn't say about /export:foo=bar style option, but it turned out MSVC link.exe actually accepts that. So we need that too. It also means that the export directive in the module definition file and /export command line option are functionally equivalent. llvm-svn: 218695
* [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
* [mach-o] Move implementation of MachOFileNode::parseNick Kledzik2014-09-292-0/+70
| | | | | | | Move method implementation from header file to .cpp file. No functionality change. llvm-svn: 218639
* [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
* 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
* [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
* [PECOFF] Keep unmangled name in the export table descriptorRui Ueyama2014-09-243-13/+3
| | | | | | | | | | | | | | | | | The export table descriptor is a data structure to keep information about the export table. It contains a symbol name, and the name may or may not be mangled. We need unmangled names for the export table, so we demangle them before writing them to the export table. Obviously this is not a correct round-trip conversion. That could drop a leading underscore from a symbol because that's indistinguishable from a mangled name. What we need to do is to keep unmangled names. This patch does that. llvm-svn: 218345
* [PECOFF] Simplify /machine option handlingRui Ueyama2014-09-242-11/+0
| | | | | | | | /machine:ebc was previously recognized but rejected. Unknown architecture names were handled differently but eventually rejected too. We don't need to distinguish them. llvm-svn: 218344
* [PECOFF] Change export table type.Rui Ueyama2014-09-242-14/+27
| | | | | | | | | This patch changes the type of export table set from std::set to std::vector. The new code is slightly inefficient, but because export table elements are actually mutable, std::vector is better here. No functionality change. llvm-svn: 218343
* [PECOFF] Fix duplicate /export optionsRui Ueyama2014-09-231-12/+6
| | | | | | | | | If two or more /export options are given for the same symbol, we should always print a warning message and use the first one regardless of other parameters. Previously there was a case that the first parameter is not used. llvm-svn: 218342
* Make -core/-flavor options have higher priority than linker nameRui Ueyama2014-09-231-16/+26
| | | | | | | | | Also allows -core/flavor to appear at any position in the command line. Patch from Oleg Ranevskyy! http://reviews.llvm.org/D5384 llvm-svn: 218321
* [PECOFF] Handle PRIVATE keyword in the module definition fileRui Ueyama2014-09-222-10/+17
| | | | | | | | | | | | | | A symbol in a module definition file may be annotated with the PRIVATE keyword like this. EXPORTS func PRIVATE The PRIVATE keyword does not affect the resulting .dll file. But it prevents the symbol to be listed in the .lib (import library) file. llvm-svn: 218273
* Re-commit r218259.Rui Ueyama2014-09-222-10/+6
| | | | llvm-svn: 218272
* Revert "[ELF] Fix linking when a regular object defines a symbol that is ↵Rui Ueyama2014-09-222-6/+10
| | | | | | | | | used in a DSO" This commit reverts r218259 because it needed to be checked in with a few binary files for the test. llvm-svn: 218262
* [ELF] Fix linking when a regular object defines a symbol that is used in a DSORui Ueyama2014-09-222-10/+6
| | | | | | | | | | | | | | | | | | Patch from Rafael Auler! When a shared lib has an undefined symbol that is defined in a regular object (the program), the final executable must export this symbol in the dynamic symbol table. However, in the current logic, lld only puts the symbol in the dynamic symbol table if the symbol is weak. This patch fixes lld to put the symbol in the dynamic symbol table regardless if it is weak or not. This caused a problem in FreeBSD10, whose programs link against a crt1.o that defines the symbol __progname, which is, in turn, undefined in libc.so.7 and will only be resolved in runtime. http://reviews.llvm.org/D5424 llvm-svn: 218259
* Modified per David Blakie suggestion.Yaron Keren2014-09-212-5/+2
| | | | llvm-svn: 218198
* Silence these C4715 warnings from Visual C++ (NFC)Yaron Keren2014-09-212-0/+5
| | | | | | | | | | | | | | | llvm\tools\lld\lib\readerwriter\macho\macholinkingcontext.cpp(647): warning C4715: 'lld::MachOLinkingContext::exportSymbolNamed' : not all control paths return a value llvm\tools\lld\lib\readerwriter\macho\machonormalizedfilefromatoms.cpp(723): warning C4715: '`anonymous namespace'::Util::getSymbolTableRegion' : not all control paths return a value While all enum values do appear in the switch, an uninitialized or corrupted enum variable would not be caught without the default: case in the switch. llvm-svn: 218197
* [PECOFF] Set ordinal to alias atomsRui Ueyama2014-09-191-3/+4
| | | | | | | | | | | | | | | | Atoms are ordered in the output file by ordinal. File has file ordinal, and atom has atom ordinal which is unique within the file. No two atoms should have the same combination of ordinals. However that contract was not satisifed for alias atoms. Alias atom is defined by /alternatename:sym1=sym2. In this case sym1 is defined as an alias for sym2. sym1 always got ordinal 0. As a result LLD failed with an assertion failure. This patch assigns ordinal to alias atoms. llvm-svn: 218158
* PECOFF: loosen another assumption of x86 onlySaleem Abdulrasool2014-09-191-4/+14
| | | | | | | | | | | | Cache the machine type value of the linking context. We need this in order to calculate the virtual address of the atom when resolving function symbols. Windows on ARM must check if the atom is a function and if so, set the Thumb bit for the returned virtual address. Failure to do so will result in an abnormal exit due to a trap caused by invalid instruction decoding. The same information can be used to determine the relocation type that was previously being done via is64 to select between x86 and x86_64. llvm-svn: 218106
* Driver: accept /machine:arm for Windows linkerSaleem Abdulrasool2014-09-192-5/+10
| | | | | | | | | Accept /machine:arm as an argument. This is changed to support ARM NT. Although there is no way to differentiate between ARM (Windows CE) and ARM NT (Windows on ARM), since LLVM currently only supports Windows on ARM, simply take /machine:arm to mean Windows on ARM. llvm-svn: 218105
OpenPOWER on IntegriCloud