summaryrefslogtreecommitdiffstats
path: root/lld/lib
Commit message (Collapse)AuthorAgeFilesLines
...
* PECOFF: loosen assumptions about x86-only targetsSaleem Abdulrasool2014-09-191-12/+14
| | | | | | | | | | | | Rather than saving whether we are targeting 64-bit x86 (x86_64), simply convert the single use of that information to the actual relocation type. This will permit the selection of non-x86 relocation types (e.g. for WoA support). Inline the access of the machine type field as it is relatively cheap (a couple of pointer dereferences) rather than storing the relocation type as a member variable. llvm-svn: 218104
* ReaderWriter: print magic in hexSaleem Abdulrasool2014-09-191-1/+3
| | | | | | | | When we encounter an unknown machine type, we print out the machine type magic. However, we would print out the magic in decimal rather than hex. Perform this conversion to make it easier to identify what machine is unsupported. llvm-svn: 218103
* [PECOFF] __tls_used is _tls_used on x64.Rui Ueyama2014-09-191-5/+7
| | | | llvm-svn: 218090
* Fixes wrong Twine uses in FileNode::errStr() and in LayoutPass.cppRui Ueyama2014-09-181-9/+10
| | | | | | Patch from Rafael Auler! llvm-svn: 218088
* Fix buggy Twine storage in ELFLinkingContext::searchLibrary()Rui Ueyama2014-09-181-6/+6
| | | | | | | | | | | | This patch fixes a forbidden use of Twine. It should only be used as an intermediary value, but never stored. This caused a bug in lld when running on Linux and compiled with optimizations - it couldn't properly search libs. Patch from Rafael Auler! llvm-svn: 218083
* [PECOFF] /safeseh:no on x64 is not an errorRui Ueyama2014-09-181-6/+0
| | | | | | | | I made LLD to report an error if /safeseh:no option is given on x64, but it turned out MSVC link.exe doesn't report error on it. Removing the check. llvm-svn: 218077
* [PECOFF] Support TLS callbacks.Rui Ueyama2014-09-181-14/+28
| | | | | | | | | | | | | | | | | | | | | | The contents from section .CRT$XLA to .CRT$XLZ is an array of function pointers. They are called by the runtime when a new thread is created or (gracefully) terminated. You can make your own initialization function to be called by that mechanism. All you have to do is: - Define a pointer to a function in a .CRT$XL* section using pragma - Make an external reference to "__tls_used" symbol That technique is used in many projects. This patch is to support that. What this patch does is to set the relative virtual address of "__tls_used" to the PECOFF directory table. __tls_used is actually a struct containing pointers to a symbol in .CRT$XLA and another symbol in .CRT$XLZ. The runtime looks at the directory table, gets the address of the struct, and call the function pointers between XLA and XLZ. llvm-svn: 218007
* [mach-o] Fix two-level namespace ordinalsNick Kledzik2014-09-161-11/+14
| | | | | | | | | On darwin, the linker tools records which dylib (DSO) each undefined was found in, and then at runtime, the loader (dyld) only looks in that one specific dylib for each undefined symbol. Now that llvm-objdump can display that info I can write test cases. llvm-svn: 217898
* Adjust lld to handle LLVM r217812David Majnemer2014-09-151-1/+2
| | | | llvm-svn: 217815
* Make anonymous namespace as small as possible.Rui Ueyama2014-09-121-13/+13
| | | | | | | | | LLVM coding style says that "static" is preferred for file-scope functions. Differential Revision: http://reviews.llvm.org/D5323 llvm-svn: 217692
* [mach-o] support "0x" or "0X" as prefix on hex numbers on command lineNick Kledzik2014-09-121-5/+9
| | | | | | This matches the strtoull() behavior in ld64. llvm-svn: 217650
* [PECOFF] Do r217639 leftover.Rui Ueyama2014-09-111-9/+9
| | | | llvm-svn: 217645
* [PECOFF] Use ulittle32_t::operator+=.Rui Ueyama2014-09-111-15/+9
| | | | llvm-svn: 217639
* Always check that instantiateMember returns only one file.Rui Ueyama2014-09-111-9/+12
| | | | | | Also make it private as it doesn't have to be protected function. llvm-svn: 217626
* [mach-o]: support optional "0x" prefix for -image_baseTim Northover2014-09-111-1/+5
| | | | llvm-svn: 217578
* [mach-o]: tighten up diagnostics for -image_base optionTim Northover2014-09-111-0/+4
| | | | | | | | | The provided base must also be a multiple of the system's page size, which is a reasonable enough demand. Also check the other diagnostics more thoroughly. llvm-svn: 217577
* [mach-o]: Support deprecated -seg1addr alias for -image_baseTim Northover2014-09-111-0/+2
| | | | | | | Because NO LINKER MAY CHANGE. EVER. Even if it's a complete rewrite from scratch. llvm-svn: 217572
* Make getFlavor function.Rui Ueyama2014-09-111-24/+28
| | | | | | | The dangling "else" at the end of #if looked a bit error-prone. Make it a separate function. No functionality change. llvm-svn: 217568
* If lld is renamed (or symlinked) to "ld" automatically pick the right flavor.Nick Kledzik2014-09-111-6/+11
| | | | | | | | | | | | | The existing system linkers on Darwin and Linux are called "ld". We'd like to eventually drop in lld as "ld" and have it just work. But lld is a universal linker that requires the first option to be -flavor to know which command line mode to emulate (gnu or darwin). This change tests if argv[0] is "ld" and if so, if the tool was built on MacOSX then assume the darwin flavor otherwise the gnu flavor. There are two test cases which copy lld to "ld" and then run it. One for darwin and one for linux. llvm-svn: 217566
* Remove unused local typedef.Eric Christopher2014-09-101-1/+0
| | | | llvm-svn: 217532
* [PECOFF] Add support for bigobjDavid Majnemer2014-09-101-79/+73
| | | | | | | | | | | | | | lld shouldn't directly use the COFF header nor should it use raw coff_symbols. Instead, query the header properties from the COFFObjectFile and use COFFSymbolRef to abstractly reference COFF symbols. This is just enough to get lld compiling with the changes to llvm::object. Bigobj specific testing will come later. Differential Revision: http://reviews.llvm.org/D5280 llvm-svn: 217497
* [MSVC]: use StringRef::getAsInteger instead of strtoullTim Northover2014-09-101-5/+3
| | | | | | This keeps non-conformant MSVC implementations happy. llvm-svn: 217491
* [mach-o]: implement -image_base option on Darwin.Tim Northover2014-09-104-10/+28
| | | | | | | As suggested by Nick, this will make __unwind_info implementation more natural, and it'd have to be done at some point anyway. llvm-svn: 217486
* [mach-o] Add support for arm64 (AAarch64)Nick Kledzik2014-09-0914-26/+858
| | | | | | | | | | Most of the changes are in the new file ArchHandler_arm64.cpp. But a few things had to be fixed to support 16KB pages (instead of 4KB) which iOS arm64 requires. In addition the StubInfo struct had to be expanded because arm64 uses two instruction (ADRP/LDR) to load a global which requires two relocations. The other mach-o arches just needed one relocation. llvm-svn: 217469
* [mach-o] Fix missing { }Nick Kledzik2014-09-091-1/+2
| | | | llvm-svn: 217411
* [mach-o] Fix so no options causes usage message to be printedNick Kledzik2014-09-091-5/+5
| | | | llvm-svn: 217409
* [mach-o] Add support for -pie and -no_pieNick Kledzik2014-09-094-2/+74
| | | | | | | | | There is a bit (MH_PIE) in the flags field of the mach_header which tells the kernel is a program was built position independent (for ASLR). The linker automatically attempts to build programs PIE if they are built for a recent OS version. But the -pie and -no_pie options override that default behavior. llvm-svn: 217408
* 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-083-2/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [ELF][Driver] Produce a proper error when file is not foundShankar Easwaran2014-09-081-0/+4
| | | | | | | | | | When a file is not found, produce a proper error message. The previous error message produced a file format error, which made me wonder for a while why there is a file format error, but essentially the file was not found. This fixes the problem by producing a proper error message. llvm-svn: 217359
* [ELF] Implement --rosegmentShankar Easwaran2014-09-084-3/+11
| | | | | | | | | By default linker would not create a separate segment to hold read only data. This option overrides that behavior by creating the a separate read only segment for read only data. llvm-svn: 217358
* [ELF] Undefined symbols should be allowed when building dynamic librariesShankar Easwaran2014-09-081-0/+2
| | | | | | | When dynamic libraries are built, undefined symbols should always be allowed and the linker should not exit with an error. llvm-svn: 217356
* [ELF][Cleanup] Remove unused functionsShankar Easwaran2014-09-084-31/+0
| | | | | | Remove unused functions in the Target relocation handler. llvm-svn: 217354
* Remove dead code.Rui Ueyama2014-09-071-6/+0
| | | | llvm-svn: 217324
* FileArchive cleanupRui Ueyama2014-09-051-25/+19
| | | | | | | | | Moved code used only by isDataSymbol from find to isDataSymbol member function. Also changed the return type of isDataSymbol because previously "if (isDataSymbol(...))" meant "if it is *not* a data symbol" which is opposite from what you'd expect. llvm-svn: 217285
* [PECOFF] Run lib.exe with /machine:x64.Rui Ueyama2014-09-051-1/+1
| | | | llvm-svn: 217219
* [PECOFF] Run cvtres.exe with /machine:x64.Rui Ueyama2014-09-051-3/+4
| | | | | | | | If we are creating a PE+ executable, we need to run cvtres with /machine:x64 instead of /machine:x86. Otherwise the resulting executable would be invalid. llvm-svn: 217214
* [mach-o] Let darwin driver infer arch from .o files if -arch not used.Nick Kledzik2014-09-044-19/+75
| | | | | | | | | | | | | | | | Mach-O has a "fat" (or "universal") variant where the same contents built for different architectures are concatenated into one file with a table-of-contents header at the start. But this leaves a dilemma for the linker - which architecture to use. Normally, the linker command line -arch is used to force which slice of any fat files are used. The clang compiler always passes -arch to the linker when invoking it. But some Makefiles invoke the linker directly and don’t specify the -arch option. For those cases, the linker scans all input files in command line order and finds the first non-fat object file. Whatever architecture it is becomes the architecture for the link. llvm-svn: 217189
* Move function. No functionality change.Rui Ueyama2014-09-041-5/+4
| | | | llvm-svn: 217121
* If lld binary is named 'ld' on darwin, use darwin driver modeNick Kledzik2014-09-041-1/+7
| | | | llvm-svn: 217112
* [mach-o] Improve x86_64 reference kind switch statements.Nick Kledzik2014-09-031-46/+57
| | | | | | | | The use of default: was disabling the warning about unused enumerators. Fix that, then fix the one enumerator that was not handled. Add coverage for it in test suite. llvm-svn: 217078
* [mach-o] Add support for using export triesNick Kledzik2014-09-035-14/+317
| | | | | | | | | | | On Darwin at runtime, dyld will prefer to use the export trie of a dylib instead of the traditional symbol table (which is large and requires a binary search). This change enables the linker to generate an export trie and to prefer it if found in a dylib being linked against. This also simples the yaml for dylibs because the yaml form of the trie can be reduced to just a sequence of names. llvm-svn: 217066
* [PECOFF] Fix AMD64_REL_[1-5] and AMD64_SECTION relocationsRui Ueyama2014-08-291-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | I hope this is the last fix for x64 relocations as I've wasted a few days on this. This caused a mysterious issue that some C++ programs crash on startup. It was because a null pointer is passed as argv to main. __tmainCRTStartup calls main, but before that it calls all initialization routines between .text$xc_a and .text$xc_z. pre_cpp_init is one of such routines, and it is the one who initializes a heap pointer for argv for later use. That routine was not called for some reason. It turned out that __tmainCRTStartup was skipping a block of code because of the relocation bug. A condition in the function depends on a memory load, and that memory load was referring a wrong location. As a result a jump instruction took the wrong branch, skipping pre_cpp_init and so on. This patch fixes the issue. Also added more tests to fix them once and for all. llvm-svn: 216772
* [PECOFF] Another Win64 relocation bug fixRui Ueyama2014-08-281-11/+18
| | | | | | | | | When a relocation is applied to a location, the new value needs to be added to the existing value at the location. Existing value is in most cases zero, but if not, the current code does not work. llvm-svn: 216680
* [PECOFF] Implement Win64 base relocationsRui Ueyama2014-08-281-4/+8
| | | | | | | | | | | | | | Image Base field in the PE/COFF header is used as hint for the loader. If the loader can load the executable at the specified address, that's fine, but if not, it has to load it at a different address. If that happens, the loader has to fix up the addresses in the executable by adding the offset. The list of addresses that need to be fixed is in .reloc section. This patch is to emit x64 .reloc section contents. llvm-svn: 216636
* [PECOFF] Fix AMD64_ADDR64 relocation.Rui Ueyama2014-08-271-1/+1
| | | | | | | | IMAGE_REL_AMD64_ADDR64 relocation should set 64-bit *VA* (virtual address) instead of *RVA* (relative virtual address), so we have to add the iamge base to the target's RVA. llvm-svn: 216512
* [PECOFF] Add /HighEntropyVA.Rui Ueyama2014-08-253-0/+4
| | | | | | | This is yet another command line flag to set a bit in DLLCharacteristics. Default on Win64 is "on". llvm-svn: 216414
* Use LLD naming style.Rui Ueyama2014-08-251-8/+8
| | | | llvm-svn: 216402
* Update for LLVM api changeRafael Espindola2014-08-253-18/+16
| | | | llvm-svn: 216395
* [PECOFF] Explicitly pass machine typeRui Ueyama2014-08-225-15/+13
| | | | | | | x86 and x64 are created equal -- taking x86 as the default argument made it hard to find bugs. llvm-svn: 216295
OpenPOWER on IntegriCloud