summaryrefslogtreecommitdiffstats
path: root/lld
Commit message (Collapse)AuthorAgeFilesLines
...
* [ELF] Support R_X86_64_GOTPC{32,64}Fangrui Song2018-06-122-0/+25
| | | | | | | | | | Reviewers: ruiu, grimar, espindola Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D47098 llvm-svn: 334532
* Refactor ExecuteAndWait to take StringRefs.Zachary Turner2018-06-121-6/+1
| | | | | | | | | | | | | | | | | | | This simplifies some code which had StringRefs to begin with, and makes other code more complicated which had const char* to begin with. In the end, I think this makes for a more idiomatic and platform agnostic API. Not all platforms launch process with null terminated c-string arrays for the environment pointer and argv, but the api was designed that way because it allowed easy pass-through for posix-based platforms. There's a little additional overhead now since on posix based platforms we'll be takign StringRefs which were constructed from null terminated strings and then copying them to null terminate them again, but from a readability and usability standpoint of the API user, I think this API signature is strictly better. llvm-svn: 334518
* Fix -DBUILD_SHARED_LIBS=1 buildSam Clegg2018-06-121-0/+1
| | | | | | This was broken in rL334466 llvm-svn: 334507
* [ELF][MIPS] Fix TLS GOT entries for local symbols in shared librariesAlexander Richardson2018-06-122-2/+63
| | | | | | | | | | | | | Summary: Previously LLD would not add any dynamic relocations and write a module index of 1 which is not correct for the shared library case. This can happen when a thread-local global variable is marked as local with a version script. With this change I am now able to link all of the FreeBSD base system for MIPS64 with LLD. Differential Revision: https://reviews.llvm.org/D48002 llvm-svn: 334483
* [Darwin] Use errorHandler from liblldCommonBrian Gesiak2018-06-1211-186/+170
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Error handling in liblldCore and the Darwin toolchain prints to an output stream. A TODO in the project explained that a diagnostics interface resembling Clang's should be added. For now, the simple diagnostics interface defined in liblldCommon seems like an improvement. It prints colors when they're available, uses locks for thread-safety, and abstracts away the `"error: "` and newline literal strings that litter the Darwin toolchain code. To use the liblldCommon error handler, a link dependency is added to the liblldDriver library. Test Plan: 1. check-lld 2. Invoke `ld64.lld -r` in a terminal that supports color output. Confirm that "ld64.lld: error: -arch not specified and could not be inferred" is output, and that the "error:" is colored red! Reviewers: ruiu, smeenai Reviewed By: ruiu Subscribers: mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D47998 llvm-svn: 334466
* [PPC64] Support R_PPC64_DTPREL relocations.Sean Fertile2018-06-123-13/+227
| | | | | | | | Patch adds support for most of the dynamic thread pointer based relocations for local-dynamic tls. The HIGH and HIGHA versions are missing becuase they are not supported by the llvm integrated assembler yet. llvm-svn: 334465
* AMDGPU/LLD: Handle R_AMDGPU_REL64 relocationKonstantin Zhuravlyov2018-06-112-0/+14
| | | | | | | | Requires r334443 from llvm Differential Revision: https://reviews.llvm.org/D47734 llvm-svn: 334444
* [ELF] Fix copy relocation when two symbols share the same Symbol instance.Fangrui Song2018-06-113-4/+31
| | | | | | | | | | In glibc libc.so.6, the multiple versions of sys_errlist share the same Symbol instance. When sys_errlist is copy relocated, we would replace SharedSymbol with Defined in the first iteration of the following loop: for (SharedSymbol *Sym : getSymbolsAt<ELFT>(SS)) Then in the second iteration, we think the symbol (which has been changed to Defined) is still SharedSymbol and screw up (the address ends up in the `Size` field). llvm-svn: 334432
* [ELF] Pass a pointer to InputFile to the getRelocTargetVA to escape ↵Simon Atanasyan2018-06-113-23/+22
| | | | | | dereferencing of nullptr. NFC llvm-svn: 334392
* [ELF][MIPS] Multi-GOT implementationSimon Atanasyan2018-06-1122-459/+851
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Almost all entries inside MIPS GOT are referenced by signed 16-bit index. Zero entry lies approximately in the middle of the GOT. So the total number of GOT entries cannot exceed ~16384 for 32-bit architecture and ~8192 for 64-bit architecture. This limitation makes impossible to link rather large application like for example LLVM+Clang. There are two workaround for this problem. The first one is using the -mxgot compiler's flag. It enables using a 32-bit index to access GOT entries. But each access requires two assembly instructions two load GOT entry index to a register. Another workaround is multi-GOT. This patch implements it. Here is a brief description of multi-GOT for detailed one see the following link https://dmz-portal.mips.com/wiki/MIPS_Multi_GOT. If the sum of local, global and tls entries is less than 64K only single got is enough. Otherwise, multi-got is created. Series of primary and multiple secondary GOTs have the following layout: ``` - Primary GOT Header Local entries Global entries Relocation only entries TLS entries - Secondary GOT Local entries Global entries TLS entries ... ``` All GOT entries required by relocations from a single input file entirely belong to either primary or one of secondary GOTs. To reference GOT entries each GOT has its own _gp value points to the "middle" of the GOT. In the code this value loaded to the register which is used for GOT access. MIPS 32 function's prologue: ``` lui v0,0x0 0: R_MIPS_HI16 _gp_disp addiu v0,v0,0 4: R_MIPS_LO16 _gp_disp ``` MIPS 64 function's prologue: ``` lui at,0x0 14: R_MIPS_GPREL16 main ``` Dynamic linker does not know anything about secondary GOTs and cannot use a regular MIPS mechanism for GOT entries initialization. So we have to use an approach accepted by other architectures and create dynamic relocations R_MIPS_REL32 to initialize global entries (and local in case of PIC code) in secondary GOTs. But ironically MIPS dynamic linker requires GOT entries and correspondingly ordered dynamic symbol table entries to deal with dynamic relocations. To handle this problem relocation-only section in the primary GOT contains entries for all symbols referenced in global parts of secondary GOTs. Although the sum of local and normal global entries of the primary got should be less than 64K, the size of the primary got (including relocation-only entries can be greater than 64K, because parts of the primary got that overflow the 64K limit are used only by the dynamic linker at dynamic link-time and not by 16-bit gp-relative addressing at run-time. The patch affects common LLD code in the following places: - Added new hidden -mips-got-size flag. This flag required to set low maximum size of a single GOT to be able to test the implementation using small test cases. - Added InputFile argument to the getRelocTargetVA function. The same symbol referenced by GOT relocation from different input file might be allocated in different GOT. So result of relocation depends on the file. - Added new ctor to the DynamicReloc class. This constructor records settings of dynamic relocation which used to adjust address of 64kb page lies inside a specific output section. With the patch LLD is able to link all LLVM+Clang+LLD applications and libraries for MIPS 32/64 targets. Differential revision: https://reviews.llvm.org/D31528 llvm-svn: 334390
* Fix build broken by r334341.Rui Ueyama2018-06-091-1/+1
| | | | llvm-svn: 334342
* Remove a dead variable.Rui Ueyama2018-06-092-2/+0
| | | | llvm-svn: 334341
* [PPC64] Add support for local-exec TLS modelZaara Syeda2018-06-084-2/+209
| | | | | | | | | | | | | | | | | | | This patch adds the relocations needed support the local-exec TLS model: R_PPC64_TPREL16 R_PPC64_TPREL16_HA R_PPC64_TPREL16_LO R_PPC64_TPREL16_HI R_PPC64_TPREL16_DS R_PPC64_TPREL16_LO_DS R_PPC64_TPREL16_HIGHER R_PPC64_TPREL16_HIGHERA R_PPC64_TPREL16_HIGHEST R_PPC64_TPREL16_HIGHESTA Differential Revision: https://reviews.llvm.org/D47598 llvm-svn: 334304
* Expand comments.Rui Ueyama2018-06-082-11/+42
| | | | llvm-svn: 334250
* [WebAssembly] Add --export-all flagSam Clegg2018-06-075-5/+64
| | | | | | | | | | | | | This causes all symbols to be exported in the final wasm binary even if they were not compiled with default visibility. This feature is useful for the emscripten toolchain that has a corresponding EXPORT_ALL feature which allows the JS code to interact with all C function. Differential Revision: https://reviews.llvm.org/D47806 llvm-svn: 334157
* [COFF] report file containing unsupported relocationBob Haarman2018-06-071-4/+8
| | | | | | | | | | | | | | | | Summary: When reporting an unsupported relocation type, let's also report the file we encountered it in to aid diagnosis. Reviewers: ruiu, rnk Reviewed By: rnk Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D45911 llvm-svn: 334154
* Expand the file comment for the error handlers.Rui Ueyama2018-06-071-11/+52
| | | | | | Differential Revision: https://reviews.llvm.org/D47790 llvm-svn: 334148
* [ThinLTO/lld] Document constant bool ModuleSummaryIndex parameter (NFC)Teresa Johnson2018-06-061-1/+1
| | | | | | Makes this consistent with other ModuleSummaryIndex constructor calls. llvm-svn: 334141
* Correct aligment computation for shared object symbols.Han Shen2018-06-067-7/+93
| | | | | | | | | | The original computation for shared object symbol alignment is wrong when st_value equals 0. It is very unusual for dso symbols to have st_value equal 0. But when it happens, it causes obscure run time bugs. Differential Revision: https://reviews.llvm.org/D47602 llvm-svn: 334135
* Remove an unrelated file accidentally submitted as part of r334095.Rui Ueyama2018-06-061-5797/+0
| | | | llvm-svn: 334129
* [lld] Add REQUIRES: x86 where needed to testsJoel Jones2018-06-06118-3/+5914
| | | | | | | | | | | | | | | | | | | | | | | | If building lld without x86 support, tests that require that support should be treated as unsupported, not errors. Tested using: 1. cmake '-DLLVM_TARGETS_TO_BUILD=AArch64;X86' make check-lld => Expected Passes : 1406 Unsupported Tests : 287 2. cmake '-DLLVM_TARGETS_TO_BUILD=AArch64' make check-lld => Expected Passes : 410 Unsupported Tests : 1283 Patch by Joel Jones Differential Revision: https://reviews.llvm.org/D47748 llvm-svn: 334095
* Do not show unrelated "-m is missing" error message.Rui Ueyama2018-06-051-0/+3
| | | | | | | | | | | | | | Previously, "-m is missing" error message is shown if you pass a nonexistent file or don't pass any file at all to lld, as shown below: $ ld.lld nonexistent.o ld.lld: error: cannot open nonexistent.o: No such file or directory ld.lld: error: target emulation unknown: -m or at least one .o file required This patch eliminates the second error message because it's not related and even inaccurate (you passed a .o file though it didn't exist). llvm-svn: 334024
* [ELF] - Fix BB.George Rimar2018-06-041-2/+2
| | | | llvm-svn: 333883
* [ELF] - Also use DW_AT_linkage_name when gathering information about ↵George Rimar2018-06-042-3/+201
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | variables for error messages. Currently, when LLD do a lookup for variables location, it uses DW_AT_name attribute. That is not always enough. Imagine code: namespace A { int bar = 0; } namespace Z { int bar = 1; } int hoho; In this case there are 3 variables and their debug attributes are following: A::bar has: DW_AT_name [DW_FORM_string] ("bar") DW_AT_linkage_name [DW_FORM_strp] ( .debug_str[0x00000006] = "_ZN1A3barE") Z::bar has: DW_AT_name [DW_FORM_string] ("bar") DW_AT_linkage_name [DW_FORM_strp] ( .debug_str[0x0000003f] = "_ZN1Z3barE") hoho has: DW_AT_name [DW_FORM_strp] ( .debug_str[0x0000004a] = "hoho") and has NO DW_AT_linkage_name attribute. Because it would be the same as DW_AT_name and DWARF producers avoids emiting excessive data. Hence LLD should also use DW_AT_linkage_name when it is available. (currently, LLD fails to report location correctly because thinks that A::bar and Z::bar are the same things) Differential revision: https://reviews.llvm.org/D47373 llvm-svn: 333880
* ELF: Ignore argument after --plugin.Peter Collingbourne2018-06-012-1/+3
| | | | | | | | | | | | | | Clang passes --plugin /path/to/LLVMgold.so to the linker when -flto is passed. After r333607 we only ignore --plugin as a joined argument, which means that the following argument (/path/to/LLVMgold.so) is interpreted as an input file. This means that either every LTO'd program ends up being linked with the gold plugin or we error out if the plugin does not exist. The fix is to use Eq to ignore both --plugin=foo and --plugin foo as before. Differential Revision: https://reviews.llvm.org/D47657 llvm-svn: 333793
* Show choices of multiple-choice options in `ld.lld --help` message.Rui Ueyama2018-06-011-13/+17
| | | | | | Differential Revision: https://reviews.llvm.org/D47656 llvm-svn: 333792
* [PPC64] Add support for initial-exec TLS modelZaara Syeda2018-06-013-0/+134
| | | | | | | | | | | | | This patch adds the relocations needed support the initial-exec TLS model: R_PPC64_GOT_TPREL16_HA R_PPC64_GOT_TPREL16_LO_DS R_PPC64_GOT_TPREL16_DS R_PPC64_GOT_TPREL16_HI R_PPC64_TLS Differential Revision: https://reviews.llvm.org/D47455 llvm-svn: 333769
* Print out "Alias for -foo" instead of repeating the same help message for -foo.Rui Ueyama2018-05-312-49/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since aliases don't actually need name, I removed it from Options.td to keep the definitions concise. Before: -( Ignored for compatibility with GNU unless you pass --warn-backrefs -) Ignored for compatibility with GNU unless you pass --warn-backrefs --allow-multiple-definition Allow multiple definitions --apply-dynamic-relocs Apply dynamic relocations to place --as-needed Only set DT_NEEDED for shared libraries if used --auxiliary=<value> Set DT_AUXILIARY field to the specified name --Bdynamic Link against shared libraries --Bshareable Build a shared object ... After: -( Alias for --start-group -) Alias for --end-group --allow-multiple-definition Allow multiple definitions --apply-dynamic-relocs Apply dynamic relocations to place --as-needed Only set DT_NEEDED for shared libraries if used --auxiliary=<value> Set DT_AUXILIARY field to the specified name --Bdynamic Link against shared libraries (default) --Bshareable Alias for --shared ... Differential Revision: https://reviews.llvm.org/D47588 llvm-svn: 333694
* Fix rpath-link handlingTaiju Tsuiki2018-05-311-1/+1
| | | | | | | | | | | | | | | | Summary: After r333596, rpath-link no longer consumes the following argument, and the path argument left by it confuses LLD. Reviewers: espindola, ruiu Reviewed By: ruiu Subscribers: ruiu, emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D47591 llvm-svn: 333686
* [PPC64] Support R_PPC64_GOT_TLSLD16 relocations.Sean Fertile2018-05-315-1/+126
| | | | | | | | | Add support for the R_PPC64_GOT_TLSLD16 relocations used to build the address of the tls_index struct used in local-dynamic tls. Differential Revision: https://reviews.llvm.org/D47538 llvm-svn: 333681
* Rename R_TLSGD/R_TLSLD to add _GOT_FROM_END. NFC.Sean Fertile2018-05-314-13/+14
| | | | | | | | | getRelocTargetVA for R_TLSGD and R_TLSLD RelExprs calculate an offset from the end of the got, so adjust the names to reflect this. Differential Revision: https://reviews.llvm.org/D47379 llvm-svn: 333674
* Remove name from unused options. NFC.Rui Ueyama2018-05-311-22/+22
| | | | | | This change makes it impossible to use these options in code. llvm-svn: 333655
* Fix formatting. NFC.Rui Ueyama2018-05-311-5/+5
| | | | llvm-svn: 333654
* lld-link: Implement /INTEGRITYCHECK flagNico Weber2018-05-315-1/+19
| | | | | | | | /INTEGRITYCHECK has the effect of setting IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY. Fixes PR31066. https://reviews.llvm.org/D47472 llvm-svn: 333652
* Attempt to fix a buildbot.Rui Ueyama2018-05-311-1/+1
| | | | | | | Broken buildbot log: http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/30855/steps/build/logs/stdio llvm-svn: 333648
* Fix a wrong `ld.lld --help` message.Rui Ueyama2018-05-311-1/+1
| | | | llvm-svn: 333647
* Implement --{push,pop}-state.Rui Ueyama2018-05-314-0/+66
| | | | | | | | | | | | | | | | | | | | --push-state implemented in this patch saves the states of --as-needed, --whole-archive and --static. It saves less number of flags than GNU linkers. Since even GNU linkers save different flags, no one seems to care about the details. In this patch, I tried to save the minimal number of flags to not complicate the implementation and the siutation. I'm not personally happy about adding the --{push,pop}-state flags though. That options seem too hacky to me. However, gcc started using the options since GCC 8 when GNU ld is available at the build time. Therefore, lld is no longer a drop-in replacmenet for GNU linker for that machine without supporting the flags. Fixes https://bugs.llvm.org/show_bug.cgi?id=34567 Differential Revision: https://reviews.llvm.org/D47542 llvm-svn: 333646
* Add "(default)" to default optionsRui Ueyama2018-05-301-24/+24
| | | | | | | | This improves the help message shown for `ld.lld --help`. Differential Revision: https://reviews.llvm.org/D47562 llvm-svn: 333607
* Simplify `ld.lld --help` message.Rui Ueyama2018-05-301-79/+67
| | | | | | | | | | | | | | | | | | | | Previously, we printed out two lines of help messages for `--foo bar` and `--foo=bar` like this: --soname=<value> Set DT_SONAME --soname <value> Set DT_SONAME --sort-section=<value> Specifies sections sorting rule when linkerscript is used --sort-section <value> Specifies sections sorting rule when linkerscript is used This change eliminates duplicate lines that doesn't contain `=` for such options like this. --soname=<value> Set DT_SONAME --sort-section=<value> Specifies sections sorting rule when linkerscript is used Differential Revision: https://reviews.llvm.org/D47558 llvm-svn: 333596
* [WebAssembly] Initial support for LTOSam Clegg2018-05-3026-21/+674
| | | | | | Differential Revision: https://reviews.llvm.org/D47162 llvm-svn: 333570
* [ELF] Remove -m argument to lld in test files. NFC.Sam Clegg2018-05-3065-98/+99
| | | | | | | | | | | This should be correctly implied by the linker. This also makes the tests slightly easier to maintain and compare with the equivalent tests under for other platforms. Differential Revision: https://reviews.llvm.org/D47513 llvm-svn: 333567
* [ELF][MIPS] Update comments in test cases. NFCSimon Atanasyan2018-05-302-4/+6
| | | | | | This is a follow-up to the r332374. llvm-svn: 333516
* [ELF] Group LTO options together. NFC.Sam Clegg2018-05-301-3/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D47512 llvm-svn: 333505
* [WebAssembly] Add support for response file parsingSam Clegg2018-05-302-0/+14
| | | | | | Differential Revision: https://reviews.llvm.org/D47500 llvm-svn: 333499
* ELF: Run the same test without --thinlto-jobs as we do with --thinlto-jobs.Peter Collingbourne2018-05-291-3/+3
| | | | | | | | The comment only made sense a long time ago, when --thinlto-jobs was tied with --lto-partitions. That was changed in r283817, but the test wasn't updated at the same time. This patch does so. llvm-svn: 333480
* [COFF] Unify output section code. NFCShoaib Meenai2018-05-291-22/+17
| | | | | | | | | | Peter Collingbourne suggested moving the switch to the top of the function, so that all the code that cares about the output section for a symbol is in the same place. Differential Revision: https://reviews.llvm.org/D47497 llvm-svn: 333472
* [COFF] Simplify symbol table output section computationShoaib Meenai2018-05-293-15/+14
| | | | | | | | | | | | | | | | | | | | | Rather than using a loop to compare symbol RVAs to the starting RVAs of sections to determine which section a symbol belongs to, just get the output section of a symbol directly via its chunk, and bail if the symbol doesn't have an output section, which avoids having to hardcode logic for handling dead symbols, CodeView symbols, etc. This was suggested by Reid Kleckner; thank you. This also fixes writing out symbol tables in the presence of RVA table input sections (e.g. .sxdata and .gfids). Such sections aren't written to the output file directly, so their RVA is 0, and the loop would thus fail to find an output section for them, resulting in a segfault. Extend some existing tests to cover this case. Fixes PR37584. Differential Revision: https://reviews.llvm.org/D47391 llvm-svn: 333450
* [COFF] Update CV register names.Jonas Devlieghere2018-05-299-21/+21
| | | | | | | Update tests to use the new prefix for CodeView registers added in r333421. llvm-svn: 333425
* [PPC64] Support General-Dynamic tls.Sean Fertile2018-05-295-4/+133
| | | | | | | | | Adds handling of all the relocation types for general-dynamic thread local storage. Differential Revision: https://reviews.llvm.org/D47325 llvm-svn: 333420
* [ELF][MIPS] Add test case to cover handling of microMIPS relocations in ↵Simon Atanasyan2018-05-291-0/+22
| | | | | | 64-bit mode llvm-svn: 333418
OpenPOWER on IntegriCloud