aboutsummaryrefslogtreecommitdiff
path: root/lld
AgeCommit message (Collapse)AuthorFilesLines
2020-09-26Internalize functions from various tools. NFCFangrui Song1-1/+1
And internalize some classes if I noticed them:)
2020-09-25[lld-macho] Ignore a few more undocumented flagsJez Ng2-6/+14
Reviewed By: #lld-macho, compnerd Differential Revision: https://reviews.llvm.org/D88268
2020-09-25[lld-macho] Always include custom syslibroot when running testsJez Ng89-273/+280
This greatly reduces the amount of boilerplate in our tests. Reviewed By: #lld-macho, compnerd Differential Revision: https://reviews.llvm.org/D87960
2020-09-25[lld-macho] Support absolute symbolsJez Ng10-39/+148
They operate like Defined symbols but with no associated InputSection. Note that `ld64` seems to treat the weak definition flag like a no-op for absolute symbols, so I have replicated that behavior. Reviewed By: #lld-macho, smeenai Differential Revision: https://reviews.llvm.org/D87909
2020-09-25[lld-macho] Allow the entry symbol to be dynamically boundJez Ng6-31/+84
Apparently this is used in real programs. I've handled this by reusing the logic we already have for branch (function call) relocations. Reviewed By: #lld-macho, smeenai Differential Revision: https://reviews.llvm.org/D87852
2020-09-25[lld-macho] Support -bundleJez Ng3-12/+63
Not 100% sure but it appears that bundles are almost identical to dylibs, aside from the fact that they do not contain `LC_ID_DYLIB`. ld64's code seems to treat bundles and dylibs identically in most places. Supporting bundles allows us to run e.g. XCTests, as all test suites are compiled into bundles which get dynamically loaded by the `xctest` test runner. Reviewed By: #lld-macho, smeenai Differential Revision: https://reviews.llvm.org/D87856
2020-09-25[lld-macho] Implement support for PICJez Ng10-43/+252
* Implement rebase opcodes. Rebase opcodes tell dyld where absolute addresses have been encoded in the binary. If the binary is not loaded at its preferred address, dyld has to rebase these addresses by adding an offset to them. * Support `-pie` and use it to test rebase opcodes. This is necessary for absolute address references in dylibs, bundles etc to work. Reviewed By: #lld-macho, gkm Differential Revision: https://reviews.llvm.org/D87199
2020-09-25[PowerPC][NFC] Merged two switch entries.Stefan Pintilie1-11/+1
Two switch entries did exactly the same thing. This patch merges them.
2020-09-25[PowerPC][LLD] Extend R2 save stub to support offsets of more than 26 bitsStefan Pintilie2-27/+138
The R2 save stub will now support offsets up to 64 bits. There are three cases that will be used. 1) The offset fits in 26 bits. ``` b <26 bit offset> ``` 2) The offset does not fit in 26 bits but fits in 34 bits. ``` paddi r12, 0, <34 bit offset>, 1 mtctr r12 bctr ``` 3) The offset does not fit in 34 bits. Since this is an R2 save stub we can use the TOC in R2. We are not loading the offset but the actual address we want to branch to. ``` addis r12, r2, <address in TOC lo> ld r12 <address in TOC hi>(r12) mtctr r12 bctr ``` In case 1) the stub is only 8 bytes while in cases 2) and 3) the stub will be 20 bytes. Reviewed By: MaskRay, sfertile, NeHuang Differential Revision: https://reviews.llvm.org/D87916
2020-09-24[lld][WebAssembly] Allow `atomics` feature with unshared memoryThomas Lively2-13/+0
https://github.com/WebAssembly/threads/issues/144 updated the WebAssembly threads proposal to make atomic operations on unshared memories valid. This change updates the feature checking in the linker accordingly. Production WebAssembly engines have recently been updated to allow this behvaior, but after this change users who accidentally use atomics with unshared memories on older versions of the engines will get validation errors at runtime rather than link errors. Differential Revision: https://reviews.llvm.org/D79530
2020-09-24[lld] Clean up in lld::{coff,elf}::link after D70378Fangrui Song2-2/+8
Library users should not need to call errorHandler().reset() explicitly. google/iree calls lld::elf::link and without the patch some global variables are not cleaned up in the next invocation.
2020-09-24[lld] Make -z keep-text-section-prefix recognize .text.split. as a prefix.Snehasish Kumar2-4/+14
".text.split." holds symbols which are split out from functions in other input sections. For example, with -fsplit-machine-functions, placing the cold parts in .text.split instead of .text.unlikely mitigates against poor profile inaccuracy. Techniques such as hugepage remapping can make conservative decisions at the section granularity. Differential Revision: https://reviews.llvm.org/D87840
2020-09-24[lld-macho][re-land] Implement and test resolution of common symbolsJez Ng3-2/+134
Earlier build break fixed in c32e69b2ce7abfb151a87ba363ac9e25abf7d417. This reverts commit c367f93e8539c4d0bcdc86ad7ea7923e06231a93.
2020-09-24[lld-macho][re-land] Initial support for common symbolsJez Ng7-5/+177
Fix earlier build break via a static_cast. This reverts commit 8112d494d344dc0935d5c078f066a43d7c984e0c. Differential Revision: https://reviews.llvm.org/D86909
2020-09-24[LLD][COFF] Cover usage of LLD-as-a-library in testsAlexandre Ganea12-55/+178
In lit tests, we run each LLD invocation twice (LLD_IN_TEST=2), without shutting down the process in-between. This ensures a full cleanup is properly done between runs. Only active for the COFF driver for now. Other drivers still use LLD_IN_TEST=1 which executes just one iteration with full cleanup, like before. When the environment variable LLD_IN_TEST is unset, a shortcut is taken, only one iteration is executed, no cleanup for faster exit, like before. A public API, lld::safeLldMain(), is also available when using LLD as a library. Differential Revision: https://reviews.llvm.org/D70378
2020-09-24[LLD][COFF] Avoid overwriting inputs in testsAlexandre Ganea2-6/+6
Before this patch, these two tests were emitting both a .DLL and .LIB. The output .LIB file name also happens to be an input .LIB file name. This prevented the test from executing a second time when LLD is re-entrant (LLD_IN_TEST=2). This is a support patch for https://reviews.llvm.org/D70378.
2020-09-24lld: Try to fix check-lld on incremental builds after 8f2c31f22b974daNico Weber1-0/+1
2020-09-24[lld][ELF][test] Add a couple of test cases for LTO behaviourJames Henderson2-15/+48
This patch expands two LTO test cases to check other aspects. 1) weak.ll has been expanded to show that it doesn't matter whether the first appearance of a weak symbol appears in a bitcode file or native object - that one is picked. 2) reproduce-lto.ll has been expanded to show that the bitcode files are stored in the reproduce package and that intermediate files (such as the LTO-compiled object) are not. Differential Revision: https://reviews.llvm.org/D88094 Reviewed by: grimar, MaskRay
2020-09-24Revert "[lld-macho] Initial support for common symbols"Muhammad Omair Javaid7-174/+5
This reverts commit 63ace77962543f961f1d566dd1243b1fb37129ef. Breaks LLDB Arm build: http://lab.llvm.org:8011/builders/lldb-arm-ubuntu/builds/4409
2020-09-24Revert "[lld-macho] Implement and test resolution of common symbols"Muhammad Omair Javaid3-134/+2
This reverts commit cd7cb0c30305501982ba37b4905bb264b3539ad0. Break lldb Arm build: http://lab.llvm.org:8011/builders/lldb-arm-ubuntu/builds/4409
2020-09-23[lld-macho][NFC] Make `!= nullptr` implicitJez Ng3-5/+5
2020-09-23[lld-macho][NFC] Refactor syslibroot / library path lookupJez Ng1-28/+36
* Move computation of systemLibraryRoots into a separate function, so we can add more functionality to it without things becoming unwieldy * Have `getSearchPaths` and related functions return by value instead of by output parameter. NRVO should ensure that performance is unaffected. Reviewed By: #lld-macho, smeenai Differential Revision: https://reviews.llvm.org/D87959
2020-09-23[lld-macho] Support -weak_lx, -weak_library, -weak_frameworkJez Ng5-17/+64
They cause their corresponding libraries / frameworks to be loaded via `LC_LOAD_WEAK_DYLIB` instead of `LC_LOAD_DYLIB`. Reviewed By: #lld-macho, gkm Differential Revision: https://reviews.llvm.org/D87929
2020-09-23[lld-macho] Ignore `-mllvm` and its argumentJez Ng2-5/+5
Test Plan: Reviewed By: #lld-macho, compnerd, MaskRay Differential Revision: https://reviews.llvm.org/D87803
2020-09-23[lld-macho] Emit indirect symbol tableJez Ng6-9/+156
Makes it a little easier to read objdump's disassembly. Reviewed By: #lld-macho, gkm Differential Revision: https://reviews.llvm.org/D87178
2020-09-23[lld-macho] Implement and test resolution of common symbolsJez Ng3-2/+134
Handle the case where there are both common and non-common definitions of the same symbol. Add a bunch of tests to ensure compatibility with ld64. Reviewed By: #lld-macho, gkm Differential Revision: https://reviews.llvm.org/D86910
2020-09-23[lld-macho] Initial support for common symbolsJez Ng7-5/+174
On Unix, it is traditionally allowed to write variable definitions without initialization expressions (such as "int foo;") to header files. These are called tentative definitions. The compiler creates common symbols when it sees tentative definitions. When linking the final binary, if there are remaining common symbols after name resolution is complete, the linker converts them to regular defined symbols in a `__common` section. This diff implements most of that functionality, though we do not yet handle the case where there are both common and non-common definitions of the same symbol. Reviewed By: #lld-macho, gkm Differential Revision: https://reviews.llvm.org/D86909
2020-09-23[lld-macho] handle options -search_paths_first, -search_dylibs_firstGreg McGary4-25/+66
Differential Revision: https://reviews.llvm.org/D88054
2020-09-23[lld-macho] cleanup unimplemented-option warningsGreg McGary2-32/+3
Remove all spurious `HelpHidden` flags from `lld/MachO/Options.td`. Add test for `HelpHidden` to `warnIfUnimplementedOption()` so that the empty `// handled elsewhere` case is unnecessary. Reviewed By: #lld-macho, int3, smeenai Differential Revision: https://reviews.llvm.org/D88160
2020-09-22[lld-maco] fix build breakageGreg McGary1-1/+1
2020-09-22[lld-macho] In the context of relocs, s/target/referent/ for sections & symbolsGreg McGary3-38/+39
The word "target" is overloaded, so lighten its load by using another word to denote the symbol or section to which a reloc points. While more stilted than "target", "referent" is rather less pompous than "designatum" or "denotatum". :P Along the way, make a few neighboring variable names more descriptive. Reviewed By: #lld-macho, int3 Differential Revision: https://reviews.llvm.org/D87584
2020-09-22[lld-macho] handle option -headerpad_max_install_namesGreg McGary5-9/+80
Differential Revision: https://reviews.llvm.org/D88064
2020-09-22[lld-macho] Make lld::getInteger() tolerate leading "0x"/"0X" when base is 16Greg McGary2-3/+11
ld64 is cool with leading `0x` for hex command-line args, and we should be also. Reviewed By: #lld-macho, int3 Differential Revision: https://reviews.llvm.org/D88065
2020-09-22[lld-macho] minimally handle option -dynamicGreg McGary3-1/+5
Stifle the warning for unimplemented option `-dyamic`, since it is already the default. Add `Config::staticLink` and skeletal support for altering the flag, but otherwise leave the option `-static` as hidden and its warning in place. Differential Revision: https://reviews.llvm.org/D88045
2020-09-22[LLD][PowerPC][test] Update thunk range error report for ↵Victor Huang3-21/+77
PPC64PCRelLongBranchThunk Update the thunk range error report for PPC64PCRelLongBranchThunk and add a range error test case for PPC64R12SetupStub. Differential Revision: https://reviews.llvm.org/D87381
2020-09-22[PowerPC] Add support for R_PPC64_GOT_TPREL_PCREL34 used in TLS Initial ExecStefan Pintilie2-9/+170
Add Thread Local Storage Initial Exec support to LLD. This patch adds the computation for the relocations as well as the relaxation from Initial Exec to Local Exec. Initial Exec: ``` pld r9, x@got@tprel@pcrel add r9, r9, x@tls@pcrel ``` or ``` pld r9, x@got@tprel@pcrel lbzx r10, r9, x@tls@pcrel ``` Note that @tls@pcrel is actually encoded as R_PPC64_TLS with a one byte displacement. For the above examples relaxing Intitial Exec to Local Exec: ``` paddi r9, r9, x@tprel nop ``` or ``` paddi r9, r13, x@tprel lbz r10, 0(r9) ``` Reviewed By: nemanjai, MaskRay, #powerpc Differential Revision: https://reviews.llvm.org/D86893
2020-09-21[ELF][test] Delete large temporary files and make some temporary files ↵Fangrui Song7-19/+52
smaller with two text segments Large files are cumbersome on some filesystems and can more easily trigger ENOSPC. Some tests use two text sections with output section addresses to test branch ranges. Use two text segments to prevent LLD from filling the gap and unnecessarily increasing the output size. With this change, there is no test/ELF temporary file larger than 100MiB. Reviewed By: psmith Differential Revision: https://reviews.llvm.org/D88037
2020-09-21[LLD][ELF][test] Fix CHECKs in map-file testEdd Dawson1-16/+16
A repeated typo in lld/test/ELF/map-file.s prevented a number of checks from being executed. CHECk-NEXT -> CHECK-NEXT ^ ^ After correcting the typo, a small adjustment was needed to match the size of the synthetic .comment section (which always contains "LLD 1.0" in the test environment). Differential revision: https://reviews.llvm.org/D88023
2020-09-21[lld][ELF][test] Add additional LTO testingJames Henderson4-20/+150
The additional testing is testing we previously had in a downstream test suite. Reviewed by: grimar, MaskRay Differential Revision: https://reviews.llvm.org/D87824
2020-09-20[lld-macho] Export trie addresses should be relative to the image baseJez Ng4-9/+25
We didn't notice this earlier this we were only testing the export trie encoded in a dylib, whose image base starts at zero. But a regular executable contains `__PAGEZERO`, which means it has a non-zero image base. This bug was discovered after attempting to run some programs that performed `dlopen` on an executable. Reviewed By: #lld-macho, smeenai Differential Revision: https://reviews.llvm.org/D87780
2020-09-20[lld-macho] Mark weak symbols in symbol tableJez Ng2-2/+5
Reviewed By: #lld-macho, smeenai Differential Revision: https://reviews.llvm.org/D86908
2020-09-19align __TEXT,__unwind_info to 8 byte boundaryGreg McGary1-1/+3
2020-09-19lld/mach-o: Make tool scripts from 2124ca1d5cb py2.7-compatibleNico Weber2-43/+47
2020-09-18[lld-macho] create __TEXT,__unwind_info from __LD,__compact_unwindGreg McGary9-3/+641
Digest the input `__LD,__compact_unwind` and produce the output `__TEXT,__unwind_info`. This is the initial commit with the major functionality. Successor commits will add handling for ... * `__TEXT,__eh_frame` * personalities & LSDA * `-r` pass-through Differential Revision: https://reviews.llvm.org/D86805
2020-09-18[lld][WebAssembly] Fix -Wunused-variable after D87663Fangrui Song1-1/+1
2020-09-17[PDB] Split TypeServerSource and extend type index map lifetimeReid Kleckner5-128/+130
Extending the lifetime of these type index mappings does increase memory usage (+2% in my case), but it decouples type merging from symbol merging. This is a pre-requisite for two changes that I have in mind: - parallel type merging: speeds up slow type merging - defered symbol merging: avoid heap allocating (relocating) all symbols This eliminates CVIndexMap and moves its data into TpiSource. The maps are also split into a SmallVector and ArrayRef component, so that the ipiMap can alias the tpiMap for /Z7 object files, and so that both maps can simply alias the PDB type server maps for /Zi files. Splitting TypeServerSource establishes that all input types to be merged can be identified with two 32-bit indices: - The index of the TpiSource object - The type index of the record This is useful, because this information can be stored in a single 64-bit atomic word to enable concurrent hashtable insertion. One last change is that now all object files with debugChunks get a TpiSource, even if they have no type info. This avoids some null checks and special cases. Differential Revision: https://reviews.llvm.org/D87736
2020-09-17Flush bitcode incrementally for LTO outputJianzhou Zhao1-1/+15
Bitcode writer does not flush buffer until the end by default. This is fine to small bitcode files. When -flto,--plugin-opt=emit-llvm,-gmlt are used, the final bitcode file is large, for example, >8G. Keeping all data in memory consumes a lot of memory. This change allows bitcode writer flush data to disk early when buffered data size is above some threshold. This is only enabled when lld emits LLVM bitcode. One issue to address is backpatching bitcode: subblock length, function body indexes, meta data indexes need to backfill. If buffer can be flushed partially, we introduced raw_fd_stream that supports read/seek/write, and enables backpatching bitcode flushed in disk. Reviewed-by: tejohnson, MaskRay Differential Revision: https://reviews.llvm.org/D86905
2020-09-16[ELF] Bump the limit of thunk creation passes from 10 to 15Fangrui Song1-2/+2
I have noticed that a 374MiB powerpc64le 'ld.lld' requires 11 passes to link. There is a ThunkSection (whose parent OutputSection is ".text" of 169MiB) with 12867 thunks.
2020-09-16[LLD][ELF] Optimize linker script filename glob pattern matching NFCAndrew Ng8-21/+67
Optimize the filename glob pattern matching in LinkerScript::computeInputSections() and LinkerScript::shouldKeep(). Add InputFile::getNameForScript() which gets and if required caches the Inputfile's name used for linker script matching. This avoids the overhead of name creation that was in getFilename() in LinkerScript.cpp. Add InputSectionDescription::matchesFile() and SectionPattern::excludesFile() which perform the glob pattern matching for an InputFile and make use of a cache of the previous result. As both computeInputSections() and shouldKeep() process sections in order and the sections of the same InputFile are contiguous, these single entry caches can significantly speed up performance for more complex glob patterns. These changes have been seen to reduce link time with --gc-sections by up to ~40% with linker scripts that contain KEEP filename glob patterns such as "*crtbegin*.o". Differential Revision: https://reviews.llvm.org/D87469
2020-09-15[PDB] Drop LF_PRECOMP from debugTypes earlierReid Kleckner2-10/+2
This is a minor simplification to avoid firing up a BinaryStreamReader and CVType parser.