summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter
Commit message (Collapse)AuthorAgeFilesLines
...
* [PECOFF] Keep unmangled name in the export table descriptorRui Ueyama2014-09-241-12/+1
| | | | | | | | | | | | | | | | | 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-241-10/+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
* [PECOFF] Handle PRIVATE keyword in the module definition fileRui Ueyama2014-09-221-0/+2
| | | | | | | | | | | | | | 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-191-4/+7
| | | | | | | | | 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
* 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
* 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
* [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
* 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
* [mach-o]: implement -image_base option on Darwin.Tim Northover2014-09-102-10/+12
| | | | | | | 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] Add support for -pie and -no_pieNick Kledzik2014-09-092-2/+22
| | | | | | | | | 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
* [ELF] Export strong defined symbol if it coalesces away a weak symbolSimon Atanasyan2014-09-082-1/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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] Implement --rosegmentShankar Easwaran2014-09-082-3/+4
| | | | | | | | | 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][Cleanup] Remove unused functionsShankar Easwaran2014-09-084-31/+0
| | | | | | Remove unused functions in the Target relocation handler. llvm-svn: 217354
* 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
* [mach-o] Let darwin driver infer arch from .o files if -arch not used.Nick Kledzik2014-09-043-19/+61
| | | | | | | | | | | | | | | | 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
* [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-251-0/+2
| | | | | | | This is yet another command line flag to set a bit in DLLCharacteristics. Default on Win64 is "on". llvm-svn: 216414
* Update for LLVM api changeRafael Espindola2014-08-252-9/+8
| | | | 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
* [PECOFF] Fix PE+ relocationsRui Ueyama2014-08-2211-55/+110
| | | | | | | | | | | | | The implementation of AMD64 relocations was imcomplete and wrong. On AMD64, we of course have to use AMD64 relocations instead of i386 ones. This patch fixes the issue. LLD is now able to link hello64.obj (created from hello64.asm) against user32.lib and kernel32.lib to create a Win64 binary. llvm-svn: 216253
* [mach-o] support N_NO_DEAD_STRIP nlist.desc bitNick Kledzik2014-08-214-32/+50
| | | | | | | Mach-O symbols can have an attribute on them means their content should never be dead code stripped. This translates to deadStrip() == deadStripNever. llvm-svn: 216234
* [mach-o] Fix initial live atoms with -dead_stripNick Kledzik2014-08-211-0/+16
| | | | | | | When -dead_strip is used with -exported_symbols_list the initial set of live atoms are those in the export list. llvm-svn: 216213
* Fixed typo (from r215544) that caused the lld-sphinx-docs buildbotDan Liew2014-08-211-1/+1
| | | | | | to fail. llvm-svn: 216165
* [PECOFF] Don't use default argument.Rui Ueyama2014-08-212-3/+3
| | | | | | | I'm adding new parameters to the function, and the existing parameter with a default argument is found confusing. llvm-svn: 216153
OpenPOWER on IntegriCloud