summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/ELF
Commit message (Collapse)AuthorAgeFilesLines
...
* [ELF] Implement demangle.Shankar Easwaran2014-10-201-6/+35
| | | | | | | This adds functionality in the GNU flavor to demangle symbols when undefined symbols are displayed to the user. llvm-svn: 220184
* [ELF] Check for target architecture.Shankar Easwaran2014-10-2012-25/+157
| | | | | | | | | | The canParse function for all the ELF subtargets check if the input files match the subtarget. There were few mismatches in the input files that didnt match the subtarget for which the link was being invoked, which also acts as a test for this change. llvm-svn: 220182
* [ELF] Make updateReferenceForMergeStringAccess virtual.Shankar Easwaran2014-10-201-3/+3
| | | | | | | The ELF subtargets would usually want to override the function updateReferenceForMergeStringAccess. Allow this by making it virtual. llvm-svn: 220180
* [ELF] Fix functionality of merging similar strings.Shankar Easwaran2014-10-201-29/+44
| | | | | | | | For PC relative accesses, negative addends were to be ignored. The linker was not ignoring it and would fail with an assert. This fixes the issue and is able to get Helloworld working. llvm-svn: 220179
* [ELF][Cleanup] Remove unused code.Shankar Easwaran2014-10-191-9/+1
| | | | | | | | The old code was used as a workaround to fix how relocations are calculated for sections with SHF_MERGE|SHF_STRINGS attribute. This patch removes the erroneous code. llvm-svn: 220159
* Sort include files according to convention.Shankar Easwaran2014-10-181-1/+0
| | | | llvm-svn: 220131
* [ELF] Add Readers for all the ELF subtargets.Shankar Easwaran2014-10-1863-169/+756
| | | | | | | | | This would permit the ELF reader to check the architecture that is being selected by the linking process. This patch also sorts the include files according to LLVM conventions. llvm-svn: 220129
* Hardcode the list of ELF targets here rather than using a glob.Richard Smith2014-10-181-8/+6
| | | | | | | | The code was making non-portable assumptions about the exact string returned by the glob (possibly by the shell?); this is more robust and matches what is done everywhere else. llvm-svn: 220117
* [CMake] lld: Introduce ${cmake_2_8_12_INTERFACE} onto each ↵NAKAMURA Takumi2014-10-177-7/+7
| | | | | | | target_link_libraries. [PR20254] FIXME: Dependencies should be reorganized. llvm-svn: 220000
* 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
* 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
* [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
* 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
* [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
* [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
* [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
* [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
* [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
* 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
* 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
* [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
* Fixed typo (from r215544) that caused the lld-sphinx-docs buildbotDan Liew2014-08-211-1/+1
| | | | | | to fail. llvm-svn: 216165
* AArch64: replace __func__ with LLVM_FUNCTION_NAMEHans Wennborg2014-08-132-123/+123
| | | | | | MSVC doesn't define __func__. llvm-svn: 215578
* Remove unused private fields from r215544 to appease buildbots.Chad Rosier2014-08-132-8/+2
| | | | llvm-svn: 215547
* [AArch64] Initial ELF/AArch64 SupportChad Rosier2014-08-1320-2/+1698
| | | | | | | | | | This patch adds the initial ELF/AArch64 support to lld. Only a basic "Hello World" app has been successfully tested for both dynamic and static compiling. Differential Revision: http://reviews.llvm.org/D4778 Patch by Daniel Stewart <stewartd@codeaurora.org>! llvm-svn: 215544
* [Mips] Fix typo in the comment.Simon Atanasyan2014-07-211-1/+1
| | | | llvm-svn: 213520
* [Mips] s/context/ctx/ for consistency and reduce lines lengths.Simon Atanasyan2014-07-178-48/+42
| | | | | | No functional changes. llvm-svn: 213310
* [ELF] Implement parsing `-l` prefixed items in the `GROUP` linker script ↵Simon Atanasyan2014-07-151-2/+7
| | | | | | | | | | | | | | | | | | command. There are two forms of `-l` prefixed expression: * -l<libname> * -l:<filename> In the first case a linker should construct a full library name `lib + libname + .[so|a]` and search this library as usual. In the second case a linker should use the `<filename>` as is and search this file through library search directories. The patch reviewed by Shankar Easwaran. llvm-svn: 213077
* Update for llm api change.Rafael Espindola2014-07-057-14/+18
| | | | llvm-svn: 212372
* [ELF] Add two new virtual functions to the `OutputELFWriter` class to controlSimon Atanasyan2014-06-255-2/+70
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | dynamic symbol table populating and DT_NEEDED tag creation. The `isDynSymEntryRequired` function returns true if the specified shared library atom requires a dynamic symbol table entry. The `isNeededTagRequired` function returns true if we need to create DT_NEEDED tag for the shared library defined specified shared atom. By default the both functions return true. So there is no functional changes for all targets except MIPS. Probably we need to spread the same modifications on other ELF targets but I want to implement and fully tested complete set of changes for MIPS target first. For MIPS we create a dynamic symbol table entry for a shared library atom iif this atom is referenced by a regular defined atom. For example, if library L1 defines symbol T1, library L2 defines symbol T2 and uses symbol T1 and executable file E1 uses symbol T2 but does not use symbol T1 we create an entry in the E1 dynamic symbol table for symbol T2 and do not create an entry for T1. The patch creates DT_NEEDED tags for shared libraries contain shared library atoms which a) referenced by regular defined atoms; b) have corresponding copy dynamic relocations (R_MIPS_COPY). Now the patch does not take in account --as-needed / --no-as-needed command line options. So it is too restrictive and create DT_NEEDED tags for really needed shared libraries only. I plan to fix that by subsequent patches. llvm-svn: 211674
* [Mips] Remove redundant checking from the RelocationPass::isDynamic() function.Simon Atanasyan2014-06-211-8/+1
| | | | | | No functional changes. llvm-svn: 211431
* Update for llvm api change.Rafael Espindola2014-06-132-5/+6
| | | | llvm-svn: 210919
* More prefixing of error_code.Rafael Espindola2014-06-1220-82/+83
| | | | llvm-svn: 210831
* include system_error directly.Rafael Espindola2014-06-121-1/+1
| | | | llvm-svn: 210801
* Run llvm/utils/sort_includes.py in a few files.Rafael Espindola2014-06-121-4/+0
| | | | | | This will reduce the noise in a followup patch. llvm-svn: 210800
* Don't import error_code into the lld namespace.Rafael Espindola2014-06-126-37/+38
| | | | llvm-svn: 210785
* Don't use make_error_code from the llvm namespace.Rafael Espindola2014-06-121-3/+3
| | | | llvm-svn: 210741
* Move Simple.h and Alias.h to include/Core.Rui Ueyama2014-06-114-4/+4
| | | | | | | | Because the files in Core actually depend on these files. Differential Revision: http://reviews.llvm.org/D4000 llvm-svn: 210710
* Quick fix for the windows build.Rafael Espindola2014-06-111-0/+1
| | | | | | We have to look for both std::make_error_code as well as our overloads. llvm-svn: 210704
* Use std::error_code instead of llvm::error_code.Rafael Espindola2014-06-112-4/+4
| | | | | | This is an update for a llvm api change. llvm-svn: 210689
OpenPOWER on IntegriCloud