summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [ELF] Add Readers for all the ELF subtargets.Shankar Easwaran2014-10-181-4/+1
| | | | | | | | | 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
* [ELF] Fix uninitialized variablesRafael Auler2014-10-091-4/+5
| | | | | | | Properly initialize _exportDynamic in ELFLinkingContext and an ELF_Sym object created in CRuntimeFile with default values. llvm-svn: 219380
* [lld] [ELF] Support for general dynamic TLS relocations on X86_64Rafael Auler2014-09-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* Re-commit r218259.Rui Ueyama2014-09-221-9/+5
| | | | llvm-svn: 218272
* Revert "[ELF] Fix linking when a regular object defines a symbol that is ↵Rui Ueyama2014-09-221-5/+9
| | | | | | | | | 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-221-9/+5
| | | | | | | | | | | | | | | | | | 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-081-0/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-081-2/+2
| | | | | | | | | 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
* [AArch64] Initial ELF/AArch64 SupportChad Rosier2014-08-131-0/+5
| | | | | | | | | | 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
* [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 llvm api change.Rafael Espindola2014-06-131-3/+4
| | | | llvm-svn: 210919
* Don't use make_error_code from the llvm namespace.Rafael Espindola2014-06-121-3/+3
| | | | llvm-svn: 210741
* Use std::error_code instead of llvm::error_code.Rafael Espindola2014-06-111-3/+3
| | | | | | This is an update for a llvm api change. llvm-svn: 210689
* Move alias symbols from ELFLinkingContext to LinkingContext.Rui Ueyama2014-05-221-75/+0
| | | | | | | | | | Alias symbols are SimpleDefinedAtoms and are platform neutral. They don't have to belong ELF. This patch is to make it available to all platforms. No functionality change intended. Differential Revision: http://reviews.llvm.org/D3862 llvm-svn: 209475
* Fix typosAlp Toker2014-05-201-1/+1
| | | | llvm-svn: 209213
* [ELF] Fix the file look up algorithm used in the linker script GROUP command.Simon Atanasyan2014-05-011-0/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | In general the linker scripts's GROUP command works like a pair of command line options --start-group/--end-group. But there is a difference in the files look up algorithm. The --start-group/--end-group commands use a trivial approach: a) If the path has '-l' prefix, add 'lib' prefix and '.a'/'.so' suffix and search the path through library search directories. b) Otherwise, use the path 'as-is'. The GROUP command implements more compicated approach: a) If the path has '-l' prefix, add 'lib' prefix and '.a'/'.so' suffix and search the path through library search directories. b) If the path does not have '-l' prefix, and sysroot is configured, and the path starts with the / character, and the script being processed is located inside the sysroot, search the path under the sysroot. Otherwise, try to open the path in the current directory. If it is not found, search through library search directories. https://www.sourceware.org/binutils/docs-2.24/ld/File-Commands.html The patch reviewed by Shankar Easwaran, Rui Ueyama. llvm-svn: 207769
* [ELF] Return result from the function ASAP.Simon Atanasyan2014-04-301-16/+6
| | | | | | No functional changes. llvm-svn: 207690
* [ELF] Factor out the code builds a library search directory pathSimon Atanasyan2014-04-301-14/+12
| | | | | | | | into the separate function. No functional changes. llvm-svn: 207689
* [ELF] Support --defsym=<symbol>=<symbol>.Rui Ueyama2014-04-161-0/+75
| | | | | | | | | | | | | | | | | | | | | Currently LLD supports --defsym only in the form of --defsym=<symbol>=<integer>, where the integer is interpreted as the absolute address of the symbol. This patch extends it to allow other symbol name to be given as an RHS value. If a RHS value is a symbol name, the LHS symbol will be defined as an alias for the RHS symbol. Internally, a LHS symbol is represented as a zero-size defined atom who has an LayoutAfter reference to an undefined atom, whose name is the RHS value. Everything else is already implemented -- Resolver will resolve the undefined symbol, and the layout pass will layout the two atoms at the same location. Looks like it's working fine. Note that GNU LD supports --defsym=<symbol>=<symbol>+<addend>. That feature is out of scope of this patch. Differential Revision: http://reviews.llvm.org/D3332 llvm-svn: 206417
* Attempt to unbreak buildbots.Rui Ueyama2014-03-281-1/+1
| | | | llvm-svn: 205034
* [ELF] Support --defsym option to define an absolute symbol.Rui Ueyama2014-03-281-1/+30
| | | | | | | | | | | | | | | | | This patch is to support --defsym option for ELF file format/GNU-compatible driver. Currently it takes a symbol name followed by '=' and a number. If such option is given, the driver sets up an absolute symbol with the specified address. You can specify multiple --defsym options to define multiple symbols. GNU LD's --defsym provides many more features. For example, it allows users to specify another symbol name instead of a number to define a symbol alias, or it even allows a symbol plus an offset (e.g. --defsym=foo+3) to define symbol- relative alias. This patch does not support that, but will be supported in subsequent patches. Differential Revision: http://llvm-reviews.chandlerc.com/D3208 llvm-svn: 205029
* Add "override" and remove "virtual" where appropriate.Rui Ueyama2014-03-061-1/+1
| | | | | | | For the record, I used clang-modernize to add "override" and perl to remove "virtual". llvm-svn: 203164
* [lld] Include reference kind in cycle detector debug outputNico Rieck2014-02-241-1/+1
| | | | | | | | This restores the debug output to how it was before r197727 broke it. This went undetected because the corresponding test was never run due to broken feature detection. llvm-svn: 202079
* [ELF] Create Target specific Writers.Shankar Easwaran2014-01-271-1/+1
| | | | llvm-svn: 200176
* [ELF] Rename File.h to ELFFile.h to avoid confusion.Shankar Easwaran2014-01-261-1/+1
| | | | | | No change in functionality. llvm-svn: 200166
* Run clang-format on r197727.Rui Ueyama2013-12-201-2/+2
| | | | llvm-svn: 197788
* [lld] Introduce registry and Reference kind tupleNick Kledzik2013-12-191-5/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The main changes are in: include/lld/Core/Reference.h include/lld/ReaderWriter/Reader.h Everything else is details to support the main change. 1) Registration based Readers Previously, lld had a tangled interdependency with all the Readers. It would have been impossible to make a streamlined linker (say for a JIT) which just supported one file format and one architecture (no yaml, no archives, etc). The old model also required a LinkingContext to read an object file, which would have made .o inspection tools awkward. The new model is that there is a global Registry object. You programmatically register the Readers you want with the registry object. Whenever you need to read/parse a file, you ask the registry to do it, and the registry tries each registered reader. For ease of use with the existing lld code base, there is one Registry object inside the LinkingContext object. 2) Changing kind value to be a tuple Beside Readers, the registry also keeps track of the mapping for Reference Kind values to and from strings. Along with that, this patch also fixes an ambiguity with the previous Reference::Kind values. The problem was that we wanted to reuse existing relocation type values as Reference::Kind values. But then how can the YAML write know how to convert a value to a string? The fix is to change the 32-bit Reference::Kind into a tuple with an 8-bit namespace (e.g. ELF, COFFF, etc), an 8-bit architecture (e.g. x86_64, PowerPC, etc), and a 16-bit value. This tuple system allows conversion to and from strings with no ambiguities. llvm-svn: 197727
* Linking of shared libraries for MIPS little-endian 32-bit target.Simon Atanasyan2013-12-151-0/+5
| | | | | | | | | | | | | | | | | | | | | The following are the most significant peculiarities of MIPS target: - MIPS ABI requires some special tags in the dynamic table. - GOT consists of two parts local and global. The local part contains entries refer locally visible symbols. The global part contains entries refer global symbols. - Entries in the .dynsym section which have corresponded entries in the GOT should be: * Emitted at the end of .dynsym section * Sorted accordingly to theirs GOT counterparts - There are "paired" relocations. One or more R_MIPS_HI16 and R_MIPS_GOT16 relocations should be followed by R_MIPS_LO16 relocation. To calculate result of R_MIPS_HI16 and R_MIPS_GOT16 relocations we need to combine addends from these relocations and paired R_MIPS_LO16 relocation. The patch reviewed by Michael Spencer, Shankar Easwaran, Rui Ueyama. http://llvm-reviews.chandlerc.com/D2156 llvm-svn: 197342
* [Gnu] Set the defaults in the ELFLinkingContext.Shankar Easwaran2013-11-251-1/+1
| | | | | | Comment from Rui Ueyema. llvm-svn: 195598
* [Gnu] -L paths is not positional.Shankar Easwaran2013-11-251-3/+2
| | | | | | | Looks like -L paths are not positional. They need to be added to a list of search paths and those needs to be searched when lld looks for a library. llvm-svn: 195594
* [InputGraph][Gnu] Add LinkerScript support.Shankar Easwaran2013-11-241-2/+0
| | | | | | | | | | | | | | | | This adds LinkerScript support by creating a type Script which is of type FileNode in the InputGraph. Once the LinkerScript Parser converts the LinkerScript into a sequence of command, the commands are handled by the equivalent LinkerScript node for the current Flavor/Target. For ELF, a ELFGNULdScript gets created which converts the commands to ELF nodes and ELF control nodes(ELFGroup for handling Group nodes). Since the Inputfile type has to be determined in the Driver, the Driver needs to determine the complete path of the file that needs to be processed by the Linker. Due to this, few tests have been removed since the Driver uses paths that doesnot exist. llvm-svn: 195583
* Remove unnecessary namespace qualifier.Rui Ueyama2013-11-051-1/+1
| | | | llvm-svn: 194037
* Remove duplicate calls of pm.add() for RoundTrip tests.Rui Ueyama2013-11-011-4/+0
| | | | llvm-svn: 193885
* [PassManager] add ReaderWriter{Native,YAML} to the Driver.Shankar Easwaran2013-10-291-1/+7
| | | | | | | | | | | | | Enable this for the following flavors a) core b) gnu c) darwin Its disabled for the flavor PECOFF. Convenient markers are added with FIXME comments in the Driver that would be removed and code removed from each flavor. llvm-svn: 193585
* [ELF] Implement .{init,fini}_array ordering.Michael J. Spencer2013-10-251-0/+2
| | | | llvm-svn: 193451
* [LinkingContext] make LinkingContext non-constShankar Easwaran2013-10-081-1/+1
| | | | llvm-svn: 192183
* [lld][InputGraph] Change the Resolver to use inputGraphShankar Easwaran2013-10-071-20/+1
| | | | | | | | | | | | Changes :- a) Functionality in InputGraph to insert Input elements at any position b) Functionality in the Resolver to use nextFile c) Move the functionality of assigning file ordinals to InputGraph d) Changes all inputs to MemoryBuffers e) Remove LinkerInput, InputFiles, ReaderArchive llvm-svn: 192081
* [ELF] Fix use after free.Michael J. Spencer2013-09-251-15/+16
| | | | llvm-svn: 191403
* Make Driver::link and LinkingContext::validate return true on success.Rui Ueyama2013-09-241-1/+1
| | | | | | | | | | | | | This patch inverts the return value of these functions, so that they return "true" on success and "false" on failure. The meaning of boolean return value was mixed in LLD; for example, InputGraph::validate() returns true on success. With this patch they'll become consistent. CC: llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1748 llvm-svn: 191341
* [lld][LinkingContext][ELF] Allow different output file types.Shankar Easwaran2013-09-231-5/+15
| | | | | | | | | | This adds an option --output-filetype that can be set to either YAML/Native(case insensitive). The linker would create the outputs associated with the type specified by the user. Changes all the tests to use the new option. llvm-svn: 191183
* Change the parseFile argument from MemoryBuffer pointer to LinkerInputJoerg Sonnenberger2013-09-071-6/+5
| | | | | | reference. Move readFile logic into FileNode::createLinkerInput. llvm-svn: 190253
* [lld] handle the case of errors from createLinkerInputShankar Easwaran2013-09-031-2/+5
| | | | | | | | | | This changes the interface of createLinkerInput to use ErrorOr, so that errors from the linker can be captured. Also adds a convenience function for error strings to be returned from file nodes. llvm-svn: 189871
* Add support for --sysroot.Joerg Sonnenberger2013-09-031-3/+14
| | | | llvm-svn: 189826
* [lld][LinkingContext] Atoms created from command line options should be ↵Shankar Easwaran2013-08-311-6/+30
| | | | | | | | | | | | available in YAML This adds an API to the LinkingContext for flavors to add Internal files containing atoms that need to appear in the YAML output as well, when -emit-yaml switch is used. Flavors can add more internal files for other options that are needed. llvm-svn: 189718
* add InputGraph functionalityShankar Easwaran2013-08-211-15/+6
| | | | llvm-svn: 188958
* Update to llvm changes.Michael J. Spencer2013-08-081-0/+1
| | | | llvm-svn: 188021
* Rename TargetInfo -> LinkingContext.Rui Ueyama2013-08-061-0/+168
Also change some local variable names: "ti" -> "context" and "_targetInfo" -> "_context". Differential Revision: http://llvm-reviews.chandlerc.com/D1301 llvm-svn: 187823
OpenPOWER on IntegriCloud