summaryrefslogtreecommitdiffstats
path: root/lld/ELF/Config.h
Commit message (Collapse)AuthorAgeFilesLines
...
* ELF: Add `Rela` member variable to Config.Rui Ueyama2016-03-131-0/+1
| | | | | | | The member is true if we want to create relocatin sections with RELA instead of REL. llvm-svn: 263387
* ELF: Implement --build-id.Rui Ueyama2016-03-111-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch implements --build-id. After the linker creates an output file in the memory buffer, it computes the FNV1 hash of the resulting file and set the hash to the .note section as a build-id. GNU ld and gold have the same feature, but their default choice of the hash function is different. Their default is SHA1. We made a deliberate choice to not use a secure hash function for the sake of performance. Computing a secure hash is slow -- for example, MD5 throughput is usually 400 MB/s or so. SHA1 is slower than that. As a result, if you pass --build-id to gold, then the linker becomes about 10% slower than that without the option. We observed a similar degradation in an experimental implementation of build-id for LLD. On the other hand, we observed only 1-2% performance degradation with the FNV hash. Since build-id is not for digital certificate or anything, we think that a very small probability of collision is acceptable. We considered using other signals such as using input file timestamps as inputs to a secure hash function. But such signals would have an issue with build reproducibility (if you build a binary from the same source tree using the same toolchain, the build id should become the same.) GNU linkers accepts --build-id=<style> option where style is one of "MD5", "SHA1", or an arbitrary hex string. That option is out of scope of this patch. http://reviews.llvm.org/D18091 llvm-svn: 263292
* ELF: Add --thread option and partially parallelize writeTo().Rui Ueyama2016-03-111-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds --thread option and use parallel_for_each to write sections in regular OutputSections. This is the first patch to use more than one threads. Note that --thread is off by default because it is experimental. At this moment I still want to focus on single thread performance because multi-threading is not a magic wand to fix performance problems after all. It is generally very hard to make a slow program faster by threads. Therefore, I want to make the linker as efficient as possible first and then look for opportunity to make it even faster using more than one core. Here are some numbers to link programs with and without --threads and using GNU gold. Numbers are in seconds. Clang w/o --threads 0.697 w --threads 0.528 gold 1.643 Scylla w/o --threads 5.032 w --threads 4.935 gold 6.791 GNU gold w/o --threads 0.550 w --threads 0.551 gold 0.737 I limited the number of cores these processes can use to 4 using perf command, so although my machine has 20 physical cores, the performance gain I observed should be reproducible with a machine which is not as beefy as mine. llvm-svn: 263190
* [lto] Add beginning of -save-temps option.Sean Silva2016-03-091-0/+1
| | | | | | | | | | | | | | | | | | | | | Summary: This is useful for debugging issues with LTO. The option follows the analogous option in ld64 and the gold plugin (per Rafael's suggestion). For starters, this only dumps the combined bitcode file. In a future patch I will add dumping for the .o file. The naming of the output follows ld64's convention which is slightly more consistent IMO (consistent `.lto.<extension>` for all the files). Reviewers: rafael, ruiu Subscribers: joker.eph, Bigcheese, llvm-commits Differential Revision: http://reviews.llvm.org/D18006 llvm-svn: 263055
* Revert "ELF: Add /lib and /usr/lib as default search paths."Rafael Espindola2016-03-081-1/+0
| | | | | | | | | | | | | | | It was causing errors like /lib/libc.so.6 is incompatible with elf_x86_64 when linking on Fedora. Every system has different default paths. It seems better to just trust the driver to pass the correct -L options. This reverts commit 262910. llvm-svn: 262941
* ELF: Rename NoInhibitExec -> NoinhibitExec.Rui Ueyama2016-03-081-1/+1
| | | | | | | | The variables corresponding to command line options are named mechanically. Because the option for the variable is -noinhibit-exec and not -no-inhibit-exec, it should be name this way. llvm-svn: 262911
* ELF: Add /lib and /usr/lib as default search paths.Rui Ueyama2016-03-081-0/+1
| | | | | | | GNU ld and gold have these paths as default search paths. If you don't want these directories, pass -nostdlib. llvm-svn: 262910
* Rename elf2 to elf.Rafael Espindola2016-02-281-2/+2
| | | | llvm-svn: 262159
* ELF: Implement ICF.Rui Ueyama2016-02-251-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch implements the same algorithm as LLD/COFF's ICF. I'm not going to repeat the same description about how it works, so you want to read the comment in ICF.cpp in this patch if you want to know the details. This algorithm should be more powerful than the ICF algorithm implemented in GNU gold. It can even merge mutually-recursive functions (which is harder than one might think). ICF is a fairly effective size optimization. Here are some examples. LLD: 37.14 MB -> 35.80 MB (-3.6%) Clang: 59.41 MB -> 57.80 MB (-2.7%) The lacking feature is "safe" version of ICF. This merges all identical sections. That is not compatible with a C/C++ language requirement that two distinct functions must have distinct addresses. But as long as your program do not rely on the pointer equality (which is in many cases true), your program should work with the feature. LLD works fine for example. GNU gold implements so-called "safe ICF" that identifies functions that are safe to merge by heuristics -- for example, gold thinks that constructors are safe to merge because there is no way to take an address of a constructor in C++. We have a different idea which David Majnemer suggested that we add NOPs at beginning of merged functions so that two or more pointers can have distinct values. We can do whichever we want, but this patch does not include neither. http://reviews.llvm.org/D17529 llvm-svn: 261912
* [ELF2] - Basic implementation of -r/--relocatableGeorge Rimar2016-02-251-0/+1
| | | | | | | | | | | | | -r, -relocatable - Generate relocatable output Currently does not have support for files containing relocation sections with entries that refer to local symbols (like rel[a].eh_frame which refer to sections and not to symbols) Differential revision: http://reviews.llvm.org/D14382 llvm-svn: 261838
* ELF: Create LinkerScript class to move code out of Writer.Rui Ueyama2016-02-111-1/+0
| | | | | | | | | | | | Previously, we had code for linker scripts in Writer. This patch separates that as LinkerScript class. The class provides a few functions to query linker scripts and is also a container of some linker-script-specific information. Hopefully, Writer will only implement the default behavior and let the new class handle gotchas regarding linker scripts. llvm-svn: 260591
* [ELF][MIPS] Add handling for __gnu_local_gp symbolSimon Atanasyan2016-02-041-0/+1
| | | | | | | This symbol is a "fake" symbol like "_gp_disp" and denotes the GOT + 0x7FF0 value. llvm-svn: 259781
* [ELF] Implemented -Bsymbolic-functions command line optionGeorge Rimar2016-02-021-0/+1
| | | | | | | | | | | | | -Bsymbolic-functions: When creating a shared library, bind references to global function symbols to the definition within the shared library, if any. This patch also fixed behavior of already existent -Bsymbolic: previously PLT entries were created even if -Bsymbolic was specified. Differential revision: http://reviews.llvm.org/D16411 llvm-svn: 259481
* Reapply r257753 with fix:George Rimar2016-01-151-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Added check for terminator CIE/FDE which has zero data size. void EHOutputSection<ELFT>::addSectionAux( ... // If CIE/FDE data length is zero then Length is 4, this // shall be considered a terminator and processing shall end. if (Length == 4) break; ... After this "Bug 25923 - lld/ELF2 linked application crashes if exceptions were used." is fixed for me. Self link of clang also works. Initial commit message: [ELF] - implemented --eh-frame-hdr command line option. --eh-frame-hdr Request creation of ".eh_frame_hdr" section and ELF "PT_GNU_EH_FRAME" segment header. Both gold and the GNU linker support an option --eh-frame-hdr which tell them to construct a header for all the .eh_frame sections. This header is placed in a section named .eh_frame_hdr and also in a PT_GNU_EH_FRAME segment. At runtime the unwinder can find all the PT_GNU_EH_FRAME segments by calling dl_iterate_phdr. This section contains a lookup table for quick binary search of FDEs. Detailed info can be found here: http://www.airs.com/blog/archives/462 Differential revision: http://reviews.llvm.org/D15712 llvm-svn: 257889
* Revert r257753: "[ELF] - implemented --eh-frame-hdr command line option."Rui Ueyama2016-01-141-1/+0
| | | | | | This reverts commit r257753 because we cannot link Clang with this patch. llvm-svn: 257797
* [ELF] - implemented --eh-frame-hdr command line option.George Rimar2016-01-141-0/+1
| | | | | | | | | | | | | | --eh-frame-hdr Request creation of ".eh_frame_hdr" section and ELF "PT_GNU_EH_FRAME" segment header. Both gold and the GNU linker support an option --eh-frame-hdr which tell them to construct a header for all the .eh_frame sections. This header is placed in a section named .eh_frame_hdr and also in a PT_GNU_EH_FRAME segment. At runtime the unwinder can find all the PT_GNU_EH_FRAME segments by calling dl_iterate_phdr. This section contains a lookup table for quick binary search of FDEs. Detailed info can be found here: http://www.airs.com/blog/archives/462 Differential revision: http://reviews.llvm.org/D15712 llvm-svn: 257753
* Demangle symbols when including them in error messages.Rui Ueyama2016-01-131-0/+1
| | | | llvm-svn: 257647
* Add comments.Rui Ueyama2016-01-051-0/+5
| | | | llvm-svn: 256850
* [ELF][MIPS] Handle R_MIPS_HI16/LO16 relocations against _gp_disp symbolSimon Atanasyan2015-12-161-0/+1
| | | | | | | | | | | | The `_gp_disp` is a magic symbol designates offset between start of function and gp pointer into GOT. Only `R_MIPS_HI16` and `R_MIPS_LO16` relocations are permitted with `_gp_disp`. The patch adds the `_gp_disp` as an ignored symbol and adjusts symbol value before call the `relocateOne` for `R_MIPS_HI16/LO16` relocations. Differential Revision: http://reviews.llvm.org/D15480 llvm-svn: 255768
* [ELF] - Implemented --print-gc-sections command line argument.George Rimar2015-12-101-0/+1
| | | | | | | | List all sections removed by garbage collection. This option is only effective if garbage collection has been enabled via the `--gc-sections' option. Differential revision: http://reviews.llvm.org/D15327 llvm-svn: 255235
* Revert "ELF: Make .note.GNU-stack more compatible with traditional linkers."Rui Ueyama2015-11-241-1/+1
| | | | | | | This reverts commit r253797 because it was based on a misunderstanding that lld wouldn't work on NetBSD without this change. llvm-svn: 254003
* Reapply fixed r253967.George Rimar2015-11-241-0/+1
| | | | llvm-svn: 253971
* Revert r253967 which broke buildbot.George Rimar2015-11-241-1/+0
| | | | llvm-svn: 253970
* [ELF] Implements -z relro: create an ELF "PT_GNU_RELRO" segment header in ↵George Rimar2015-11-241-0/+1
| | | | | | | | | | | | | | | | | the object. Partial (-z relro) and full (-z relro, -z now) relro cases are implemented. Partial relro: The ELF sections are reordered so that the ELF internal data sections (.got, .dtors, etc.) precede the program's data sections (.data and .bss). .got is readonly, .got.plt is still writeable. Full relro: Supports all the features of partial RELRO, .got.plt is also readonly. Differential revision: http://reviews.llvm.org/D14218 llvm-svn: 253967
* ELF: Make .note.GNU-stack more compatible with traditional linkers.Rui Ueyama2015-11-211-1/+1
| | | | | | | | | | | | | With this patch, lld creates PT_GNU_STACK segments only when all input files have .note.GNU-stack sections. This is in line with other linkers with a minor difference (we don't care about .note.GNU-stack rwx bits as you can always remove .note.GNU-stack sections instead of setting x bit.) At least, NetBSD loader does not understand PT_GNU_STACK segments and reject any executables that have the section. This patch makes lld compatible with such operating systems. llvm-svn: 253797
* Remove default values that are always overriden in Driver.cpp.Rui Ueyama2015-11-201-3/+3
| | | | llvm-svn: 253710
* [ELF2] - Implemented PT_GNU_STACK support, -z execstack option.George Rimar2015-11-141-0/+1
| | | | | | | | | | PT_GNU_STACK is a entry in the elf file format which contains the access rights (read, write, execute) of the stack, it is always generated now. By default stack is not executable in this implementation. -z execstack can be used to make executable. Differential revision: http://reviews.llvm.org/D14571 llvm-svn: 253145
* [ELF2] SECTIONS command basic supportDenis Protivensky2015-11-121-0/+2
| | | | | | | | | | * determine output section by input section name * discard input sections * order output sections accordingly Differential Revision: http://reviews.llvm.org/D14140 llvm-svn: 252868
* Reapply r251144: fixed test.George Rimar2015-10-241-0/+1
| | | | llvm-svn: 251184
* Revert "[ELF2] --strip-all/-s command line implemented"Rui Ueyama2015-10-231-1/+0
| | | | | | This reverts commit r251144 because the new test is failing. llvm-svn: 251148
* [ELF2] --strip-all/-s command line implementedGeorge Rimar2015-10-231-0/+1
| | | | | | | | | -s, --strip-all - Strip all symbols Implementation removes .strtab and .symtab sections from output. Differential Revision: http://reviews.llvm.org/D13934 llvm-svn: 251144
* Parse and store the value of the -O option.Rafael Espindola2015-10-231-0/+1
| | | | llvm-svn: 251136
* ELF2: Implement --gc-sections.Rui Ueyama2015-10-221-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | Section garbage collection is a feature to remove unused sections from outputs. Unused sections are sections that cannot be reachable from known GC-root symbols or sections. Naturally the feature is implemented as a mark-sweep garbage collector. In this patch, I added Live bit to InputSectionBase. If and only if Live bit is on, the section will be written to the output. Starting from GC-root symbols or sections, a new function, markLive(), visits all reachable sections and sets their Live bits. Writer then ignores sections whose Live bit is off, so that such sections are excluded from the output. This change has small negative impact on performance if you use the feature because making sections means more work. The time to link Clang changes from 0.356s to 0.386s, or +8%. It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes. That is 4.3% reduction. http://reviews.llvm.org/D13950 llvm-svn: 251043
* [ELF2] Add support for GNU Hash sectionIgor Kudrin2015-10-221-0/+2
| | | | | | | | | | | | | | | | | | | This patch implements --hash-style command line switch. * By default, or with "sysv" or "both" parameters, the linker generates a standard ELF hash section. * With "gnu" or "both", it produces a GNU-style hash section. That section requires the symbols in the dynamic symbol table section, which are referenced in the GNU hash section, to be placed after not hashed ones and to be sorted to correspond the order of hash buckets in the GNU Hash section. The division function, as well as estimations for the section's parameters, are just the first rough attempt and the subjects for further adjustments. Differential Revision: http://reviews.llvm.org/D13815 llvm-svn: 251000
* [ELF2] Add support for -z origin.Davide Italiano2015-10-211-0/+1
| | | | llvm-svn: 250907
* [ELF2] Introduce support for -z nodelete. Davide Italiano2015-10-201-0/+1
| | | | llvm-svn: 250771
* [ELF2] - Linker script EXTERN command implemented.George Rimar2015-10-191-0/+1
| | | | | | | | The reason of collecting all undefines in vector is that during reading files we already need to have Symtab created. Or like was done in that patch - to put undefines from scripts somewhere to delay Symtab.addUndefinedOpt() call. Differential Revision: http://reviews.llvm.org/D13870 llvm-svn: 250711
* ELF2: Treat IsMips64EL as a global configuration.Rui Ueyama2015-10-161-0/+1
| | | | | | | | If one file is MIPS64EL, all files are MIPS64EL, and vice versa. We do not have to look up MIPS-ness for each file. Currently we do not support 64-bit MIPS, so the config value is always false. llvm-svn: 250566
* ELF2: Support --entry=<addr>.Rui Ueyama2015-10-141-0/+1
| | | | | | | | If an argument for --entry is a number, that's not a symbol name but an absolute address. If that's the case, the address is directly set to ELF header's e_entry. llvm-svn: 250334
* [ELF2] Add support for -Bsymbolic.Davide Italiano2015-10-131-0/+1
| | | | llvm-svn: 250225
* ELF2: Rename ElfKind -> EKind.Rui Ueyama2015-10-131-1/+1
| | | | | | ELFKind as a type name and ElfKind is a variable name was too subtle. llvm-svn: 250172
* Simplify the InputFile type hierarchy.Rafael Espindola2015-10-121-2/+2
| | | | | | | Now that the SymbolTable is templated, we don't need the ELFData class or multiple inheritance. llvm-svn: 250005
* ELF2: Implement --as-needed.Rui Ueyama2015-10-111-0/+1
| | | | | | | | | | | | | | This patch adds AsNeeded and IsUsed bool fields to SharedFile. AsNeeded bit is set if the DSO is enclosed with --as-needed and --no-as-needed. IsUsed bit is off by default. When we adds a symbol to the symbol table for dynamic linking, we set its SharedFile's IsUsed bit. If AsNeeded is set but IsUsed is not set, we don't want to write that file's SO name to DT_NEEDED field. http://reviews.llvm.org/D13579 llvm-svn: 249998
* Handle a crash in conflict detection with archive members.Rafael Espindola2015-10-111-0/+2
| | | | llvm-svn: 249996
* Detect incompatible files when one of them comes from an archive.Rafael Espindola2015-10-111-0/+1
| | | | llvm-svn: 249968
* ELF2: LinkerScript: Interpret -l and = file name prefixes.Rui Ueyama2015-10-111-1/+1
| | | | | | | | In the linker script, -l and = have the same meaning as in the command line. In addition to that, if a path is not absolute, the path needs to be searched from the search paths. This patch implements them. llvm-svn: 249967
* ELF2: Add --verbose.Rui Ueyama2015-10-111-0/+1
| | | | | | | It is currently not actually verbose but rather terse, but that's intentional. llvm-svn: 249964
* ELF2: Move Target and entry initialization from SymbolTable to Driver.Rui Ueyama2015-10-091-0/+3
| | | | | | | | SymbolTable was not a right place for initialization. We had to do that because Driver didn't know what type of ELF objects are being handled. We taught Driver that, so we can now move this code to Driver. llvm-svn: 249904
* ELF2: Make SymbolTable a template class.Rui Ueyama2015-10-091-1/+0
| | | | | | | | | | | | | | | | | | | | | | | SymbolTable was not a template class. Instead we had switch-case-based type dispatch to call desired functions. We had to do that because SymbolTable was created before we know what ELF type objects had been passed. Every time I tried to add a new function to the symbol table, I had to define a dispatcher which consist of a single switch statement. It also brought an restriction what the driver can do. For example, we cannot add undefined symbols before any files are added to the symbol table. That's because no symbols can be added until the symbol table knows the ELF type, but when it knows about that, it's too late. In this patch, the driver makes a decision on what ELF type objects are being handled. Then the driver creates a SymbolTable object for an appropriate ELF type. http://reviews.llvm.org/D13544 llvm-svn: 249902
* ELF2: Sort. NFC.Rui Ueyama2015-10-091-1/+1
| | | | llvm-svn: 249803
OpenPOWER on IntegriCloud