summaryrefslogtreecommitdiffstats
path: root/lld
Commit message (Collapse)AuthorAgeFilesLines
...
* [WebAssembly][NFC] Remove unnecessary bracesThomas Lively2019-09-191-2/+1
| | | | llvm-svn: 372358
* Don't false-positive match against binary path.Mitch Phillips2019-09-191-1/+4
| | | | | | | | | | | copy-rel-abs.s uses llvm-objdump to generate output that's then run through FileCheck. llvm-objdump prints the file path at the top of the file, which means that any build path that contains 'zed' will get false-matched. Ensure that 'zed' is only matched after the 'SYMBOL TABLE:' output, preventing this from failing if your build directory is ~/build/sanitized-xxx/, or similar. llvm-svn: 372351
* [WebAssembly] Sort output data sections to place .bss lastThomas Lively2019-09-1910-109/+184
| | | | | | | | | | | | | | | | | | | | Summary: This was always the intended behavior, but had not been implemented. This ordering is important for Emscripten when generating .mem files while compiling to JS, since only zeros at the end of initialized memory can be dropped. Fixes https://github.com/emscripten-core/emscripten/issues/8999 Reviewers: sbc100 Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67736 llvm-svn: 372284
* [lld][WebAssembly] Fix use after free of archive pathSam Clegg2019-09-181-1/+1
| | | | | | | | This was fixed in the ELF backend in https://reviews.llvm.org/D34554. Differential Revision: https://reviews.llvm.org/D67676 llvm-svn: 372266
* [ELF][AARCH64] Refactor AArchErrataFix to match changes in ARMErrataFix NFC.Peter Smith2019-09-171-22/+19
| | | | | | | | | | | | | | | | | | D67284 introduced ARMErrataFix.cpp which was derived from AArch64ErrataFix.cpp. There were some useful refactoring changes made to ARMErrataFix.cpp made as part of the review. This change applies the relevant changes back to AArch64ErrataFix.cpp. Main changes are: - Old style variable names in comments like IS, are now new style isec. - Simplify init() collection of mappingSymbols to always start with a code mapping symbol. - Simplify logic in mergeCmp(). - Fix one 80 column overflow caused by IS -> isec transformation. Differential Revision: https://reviews.llvm.org/D67622 llvm-svn: 372094
* [ELF][Hexagon] Allow PT_LOAD to have overlapping p_offset ranges on EM_HEXAGONFangrui Song2019-09-174-81/+76
| | | | | | | | Port the D64906 technique to EM_HEXAGON. This concludes the patch series. Differential Revision: https://reviews.llvm.org/D67605 llvm-svn: 372059
* [lld] Update lld driver to use new LTO APIs to handle libcall symbolsSteven Wu2019-09-162-14/+4
| | | | | | | NFC. Remove duplicated code in ELF/COFF driver and libLTO legacy interfaces. llvm-svn: 372022
* [ELF][ARM] Fix -Werror buildbots NFC.Peter Smith2019-09-161-1/+1
| | | | | | | | | | Provide a missing initializer to get rid of warning provoking buildbot failures. error: missing field 'rel' initializer [-Werror,-Wmissing-field-initializers] llvm-svn: 371970
* [ELF][ARM] Implement --fix-cortex-a8 to fix erratum 657417Peter Smith2019-09-1614-7/+1109
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The --fix-cortex-a8 option implements a linker workaround for the coretex-a8 erratum 657417. A summary of the erratum conditions is: - A 32-bit Thumb-2 branch instruction B.w, Bcc.w, BL, BLX spans two 4KiB regions. - The destination of the branch is to the first 4KiB region. - The instruction before the branch is a 32-bit Thumb-2 non-branch instruction. The linker fix is to redirect the branch to a patch not in the first 4KiB region. The patch forwards the branch on to its target. The cortex-a8, is an old CPU, with the first implementation of this workaround in ld.bfd appearing in 2009. The cortex-a8 has been used in early Android Phones and there are some critical applications that still need to run on a cortex-a8 that have the erratum. The patch is applied roughly 10 times on LLD and 20 on Clang when they are built with --fix-cortex-a8 on an Arm system. The formal erratum description is avaliable in the ARM Core Cortex-A8 (AT400/AT401) Errata Notice document. This is available from Arm on request but it seems to be findable via a web search. Differential Revision: https://reviews.llvm.org/D67284 llvm-svn: 371965
* [ELF][X86] Allow PT_LOAD to have overlapping p_offset ranges on EM_X86_64Fangrui Song2019-09-16119-787/+792
| | | | | | | | Port the D64906 technique to EM_X86_64. Differential Revision: https://reviews.llvm.org/D67482 llvm-svn: 371958
* [ELF] Map the ELF header at imageBaseFangrui Song2019-09-167-48/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If there is no readonly section, we map: * The ELF header at imageBase+maxPageSize * Program headers at imageBase+maxPageSize+sizeof(Ehdr) * The first section .text at imageBase+maxPageSize+sizeof(Ehdr)+sizeof(program headers) Due to the interaction between Writer<ELFT>::fixSectionAlignments and LinkerScript::allocateHeaders, `alignDown(p_vaddr(R PT_LOAD)) = alignDown(p_vaddr(RX PT_LOAD))`. The RX PT_LOAD will override the R PT_LOAD at runtime, which is not ideal: ``` // PHDR at 0x401034, should be 0x400034 PHDR 0x000034 0x00401034 0x00401034 0x000a0 0x000a0 R 0x4 // R PT_LOAD contains just Ehdr and program headers. // At 0x401000, should be 0x400000 LOAD 0x000000 0x00401000 0x00401000 0x000d4 0x000d4 R 0x1000 LOAD 0x0000d4 0x004010d4 0x004010d4 0x00001 0x00001 R E 0x1000 ``` * createPhdrs allocates the headers to the R PT_LOAD. * fixSectionAlignments assigns `imageBase+maxPageSize+sizeof(Ehdr)+sizeof(program headers)` (formula: `alignTo(dot, maxPageSize) + dot % config->maxPageSize`) to addrExpr of .text * allocateHeaders computes the minimum address among SHF_ALLOC sections, i.e. addr(.text) * allocateHeaders sets address of ELF header to `addr(.text)-sizeof(Ehdr)-sizeof(program headers) = imageBase+maxPageSize` The main observation is that when the SECTIONS command is not used, we don't have to call allocateHeaders. This requires an assumption that the presence of PT_PHDR and addresses of headers can be decided regardless of address information. This may seem natural because dot is not manipulated by a linker script. The other thing is that we have to drop the special rule for -T<section> in `getInitialDot`. If -Ttext is smaller than the image base, the headers will not be allocated with the old behavior (allocateHeaders is called) but always allocated with the new behavior. The behavior change is not a problem. Whether and where headers are allocated can vary among linkers, or ld.bfd across different versions (--enable-separate-code or not). It is thus advised to use a linker script with the PHDRS command to have a consistent behavior across linkers. If PT_PHDR is needed, an explicit --image-base can be a simpler alternative. Differential Revision: https://reviews.llvm.org/D67325 llvm-svn: 371957
* lld-link: Make Options.td formatting more self-consistent.Nico Weber2019-09-141-13/+19
| | | | | | | | Also tighten up help strings for /force, --start-lib, and --end-lib. Differential Revision: https://reviews.llvm.org/D67457 llvm-svn: 371927
* lld-link: Add a flag /lldignoreenv that makes lld-link ignore env vars.Nico Weber2019-09-137-11/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | This is useful for enforcing that builds are independent of the environment; it can be used when all system library paths are added via /libpath: already. It's similar ot cl.exe's /X flag. Since it should also affect %LINK% (the other caller of `Process::GetEnv` in lld/COFF), the early-option-parsing needs to move around a bit. The options are: - Add a manual loop over the argv ArrayRef and look for "/lldignoreenv". This repeats the name of the flag in both Options.td and in DriverUtils.cpp. - Add yet another table.ParseArgs() call just for /lldignoreenv before adding %LINK%. - Use the existing early ParseArgs() that's there for --rsp-quoting and use it for /lldignoreenv for %LINK% as well. This means --rsp-quoting and /lldignoreenv can't be passed via %LINK%. I went with the third approach. Differential Revision: https://reviews.llvm.org/D67456 llvm-svn: 371852
* [ELF] Delete a redundant assignment to SectionBase::assigned. NFCFangrui Song2019-09-131-1/+0
| | | | | | | LinkerScript::discard marks a section dead. It is unnecessary to set the `assigned` bit. llvm-svn: 371804
* [COFF] Fix to not add archive name to buffer identifiers when they comeAmy Huang2019-09-122-2/+14
| | | | | | | | | | | | from thin archives. Currently lld adds the archive name to MemoryBufferRef identifiers in order to ensure they are unique. For thin archives, since the file name is already unique and we want to keep the original path to the file, don't add the archive name. Differential Revision: https://reviews.llvm.org/D67295 llvm-svn: 371778
* [ELF] ICF: change a dyn_cast<InputSection> to castFangrui Song2019-09-121-4/+5
| | | | | | | | ICF is performed after EhInputSections and MergeInputSections were eliminated from inputSections. Every element of inputSections is an InputSection. llvm-svn: 371744
* lld-link: Fix tests that do not run on macOS after r371729.Nico Weber2019-09-122-3/+3
| | | | llvm-svn: 371732
* lld-link: Make /linkrepro: take a filename, not a directory.Nico Weber2019-09-124-11/+12
| | | | | | | | | | | | This makes lld-link behave like ld.lld. I don't see a reason for the two drivers to have different behavior here. While here, also make lld-link add a version.txt to the tar, like ld.lld does. Differential Revision: https://reviews.llvm.org/D67461 llvm-svn: 371729
* [ELF] Fix a common-page-size typoFangrui Song2019-09-121-1/+1
| | | | llvm-svn: 371716
* [ELF] Support -z undefsFangrui Song2019-09-122-1/+9
| | | | | | | | | | | -z undefs is the inverse of -z defs. It allows unresolved references from object files. This can be used to cancel --no-undefined or -z defs. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D67479 llvm-svn: 371715
* [ELF][test] Make tests more tolerant to exact symbol addressesFangrui Song2019-09-119-109/+101
| | | | llvm-svn: 371588
* Reland "Change the X86 datalayout to add three address spacesAmy Huang2019-09-10191-191/+191
| | | | | | | | | | for 32 bit signed, 32 bit unsigned, and 64 bit pointers." This reverts 57076d3199fc2b0af4a3736b7749dd5462cacda5. Original review at https://reviews.llvm.org/D64931. Review for added fix at https://reviews.llvm.org/D66843. llvm-svn: 371568
* [mips] Allow PT_LOAD to have overlapping p_offset ranges on EM_MIPSSimon Atanasyan2019-09-102-23/+22
| | | | | | | | Port the D64906 <https://reviews.llvm.org/D64906> technique to MIPS. Fix PR33131 llvm-svn: 371554
* [ELF][test] Make tests more tolerant to exact symbol addressesFangrui Song2019-09-1022-234/+166
| | | | | | Delete relocation-local.s and relocation-shared.s - covered by various tests llvm-svn: 371514
* [LLD][COFF] Add index to disambiguate archive members when using -wholearchiveRui Ueyama2019-09-102-1/+32
| | | | | | | | | | | | | Patch by Markus Böck. PR42951: When linking an archive with members that have the same name linking fails when using the -wholearchive option. This patch passes the index of the member in the archive to the offset parameter to disambiguate the member. Differential Revision: https://reviews.llvm.org/D66239 llvm-svn: 371509
* [mips] Make another set of test cases more tolerant to exact symbol ↵Simon Atanasyan2019-09-0923-664/+463
| | | | | | addresses. NFC llvm-svn: 371458
* [mips] Fix decoding of microMIPS JALX instructionSimon Atanasyan2019-09-091-2/+2
| | | | | | | | | | | | | microMIPS jump and link exchange instruction stores a target in a 26-bits field. Despite other microMIPS JAL instructions these bits are target address shifted right 2 bits [1]. The patch fixes the JALX instruction decoding and uses 2-bit shift. [1] MIPS Architecture for Programmers Volume II-B: The microMIPS32 Instruction Set Differential Revision: https://reviews.llvm.org/D67320 llvm-svn: 371428
* [ELF] nmagic or omagic: don't allocate PT_PHDR or PF_R PT_LOAD for the ↵Fangrui Song2019-09-095-47/+52
| | | | | | | | | | | | | | | | | | | !hasPhdrsCommands case ``` part.phdrs = script->hasPhdrsCommands() ? script->createPhdrs() : createPhdrs(part); ``` createPhdrs() allocates a PT_PHDR and a PF_R PT_LOAD, which will be deleted later in LinkerScript::allocateHeaders, but leave a gap between the program headers and the first section. Don't allocate the segments to avoid the gap. PT_INTERP is likely not needed as well. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D67324 llvm-svn: 371398
* [ELF][AArch64] Apply some NFC cleanups to AArch64ErrataFix.cppFangrui Song2019-09-091-10/+10
| | | | | | | | Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D67310 llvm-svn: 371389
* [ELF][test] Improve and reorganize another set of testsFangrui Song2019-09-0939-253/+268
| | | | | | | | | | | | | | | | | | | | | | Add file-level comments Replace trivial Input/*.s with echo ... | llvm-mc Delete insignificant addresses to make them more tolerant to layout changes Simplify test output Merge merge-section-types.s into compatible-section-types.s and add a missed case Merge gnu-ifunc-gotpcrel.s (added in D19517) into gnu-ifunc-dso.s (added in D35119) and add missed cases Delete typed-undef.s - covered by executable-undefined-ignoreall.s Delete emit-relocs-shared.s - covered by emit-relocs-merge.s Replace copy-rel-pie.s and copy-rel-pie2.s with canonical-plt-pcrel.s, canonical-plt-symbolic.s and copy-rel.s: add -no-pie cases. add a case that a canonical PLT can be created for STT_GNU_IFUNC. The logic in Symbols.h was untested: // ctor of SharedSymbol if (this->type == llvm::ELF::STT_GNU_IFUNC) this->type = llvm::ELF::STT_FUNC; llvm-svn: 371361
* [mips] Follow-up to r371313 - fix failed test case. NFCSimon Atanasyan2019-09-071-1/+1
| | | | llvm-svn: 371316
* [mips] Make another set of test cases more tolerant to exact symbol ↵Simon Atanasyan2019-09-0716-356/+251
| | | | | | addresses. NFC llvm-svn: 371313
* [ELF][test] Improve testsFangrui Song2019-09-0733-360/+205
| | | | | | | | | | | | | | Add file-level comments Delete insignificant addresses to make them more tolerant to layout changes Simplify test output Delete weak-undef-val.s - covered by relocation-undefined-weak.s Delete weak-undef-export.s - covered by additional test added to weak-undef.s Delete version-undef-sym.s - covered by undefined-versioned-symbol.s => version-symbol-undef.s Delete symbol-ordering-file2.s - covered by symbol-ordering-file.s Delete gotpcrelx.s - covered by gotpc-relax-und-dso.s => x86-64-gotpc-relax-und-dso.s llvm-svn: 371299
* [ELF][test] Improve LTO testsFangrui Song2019-09-0715-78/+85
| | | | | | | | Add file-level comments Delete insignificant addresses to make them more tolerant to layout changes Simplify test output llvm-svn: 371292
* Update lld tests dynamic-list.s and symbol-override.s to use llvm-nmMatthew Voss2019-09-062-4/+4
| | | | | | | | | | The following tests failed on Windows bots due to nm not being available: lld/test/ELF/dynamic-list.s lld/test/ELF/symbol-override.s llvm-svn: 371267
* [ELF] Replace error() with errorOrWarn() for the ASSERT commandFangrui Song2019-09-062-3/+3
| | | | | | | | | | | | | | | Summary: ld.bfd produces an output with --noinhibit-exec when an ASSERT fails. Use errorOrWarn() so that we can produce an output as well. An interesting case is that symbol assignments may execute multiple times, so we probably want to suppress errors for non-final runs. Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D67285 llvm-svn: 371225
* Reland D66717 [ELF] Do not ICF two sections with different output sections ↵Fangrui Song2019-09-064-10/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (by SECTIONS commands) Recommit r370635 (reverted by r371202), with one change: move addOrphanSections() before ICF. Before, orphan sections in two different partitions may be folded and moved to the main partition. Now, InputSection->OutputSection assignment for orphans happens before ICF. ICF does not fold input sections with different output sections. With the PR43241 reproduce, `llvm-objcopy --extract-partition libvr.so libchrome__combined.so libvr.so` => no error Updated description: Fixes PR39418. Complements D47241 (the non-linker-script case). processSectionCommands() assigns input sections to output sections. ICF is called before it, so .text.foo and .text.bar may be folded even if their output sections are made different by SECTIONS commands. ``` markLive<ELFT>() doIcf<ELFT>() // During ICF, we don't know the output sections writeResult() combineEhSections<ELFT>() script->processSectionCommands() // InputSection -> OutputSection assignment ``` This patch splits processSectionCommands() into processSectionCommands() and processSymbolAssignments(), and moves processSectionCommands()/addOrphanSections() before ICF: ``` markLive<ELFT>() combineEhSections<ELFT>() script->processSectionCommands() script->addOrphanSections(); doIcf<ELFT>() // should remove folded input sections writeResult() script->processSymbolAssignments() ``` An alternative approach is to unfold a section `sec` in processSectionCommands() when we find `sec` and `sec->repl` belong to different output sections. I feel this patch is superior because this can fold more sections and the decouple of SectionCommand/SymbolAssignment gives flexibility: * An ExprValue can't be evaluated before its section is assigned to an output section -> we can delete getOutputSectionVA and simplify another place where we had to check if the output section is null. Moreover, a case in linkerscript/early-assign-symbol.s can be handled now. * processSectionCommands/processSymbolAssignments can be freely moved around. llvm-svn: 371216
* Revert "Revert r370635, it caused PR43241."Fangrui Song2019-09-069-81/+146
| | | | | | This reverts commit 50d2dca22b3b05d0ee4883b0cbf93d7d15f241fc. llvm-svn: 371215
* [ELF][test] Simplify and reorganize testsFangrui Song2019-09-0641-1129/+367
| | | | | | | | | | | | Add file-level comments Delete insignificant addresses to make them more tolerant to layout changes Simplify test output Delete simple Inputs/*.s files Delete version-script-copy-rel.s - covered by verdef-defaultver.s Delete version-wildcard.test - covered by version-script-glob.s llvm-svn: 371213
* Revert r370635, it caused PR43241.Nico Weber2019-09-069-146/+81
| | | | llvm-svn: 371202
* [ELF][test] Update test after r371185Fangrui Song2019-09-061-1/+1
| | | | llvm-svn: 371189
* [mips] Make another set of test cases more tolerant to exact symbol ↵Simon Atanasyan2019-09-0611-263/+178
| | | | | | addresses. NFC llvm-svn: 371174
* Update SHT_LLVM_PART_EHDR test after r371157Fangrui Song2019-09-061-2/+2
| | | | llvm-svn: 371160
* [ELF] Initialize PhdrEntry::p_align to maxPageSize for PT_LOADFangrui Song2019-09-052-10/+8
| | | | | | | | | | | | | | | | | | | | | ``` Writer<ELFT>::run assignFileOffsets setFileOffset computeFileOffset os->ptLoad->p_align may be smaller than config->maxPageSize setPhdrs p_align = max(p_align, config->maxPageSize) ``` If we move the config->maxPageSize logic to the constructor of PhdrEntry, computeFileOffset can be simplified. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D67211 llvm-svn: 371085
* [mips] Make a few test cases more tolerant to exact symbol addresses. NFCSimon Atanasyan2019-09-055-89/+75
| | | | llvm-svn: 371065
* Align output segments correctlyRui Ueyama2019-09-052-1/+25
| | | | | | | | | | | | | | | | Previously, segments were aligned according to their first section's alignment requirements. That was not correct, but segments are also aligned to a page boundary, and a page boundary is usually much larger than a section alignment requirement, so no one noticed this bug before. Now, lld has --nmagic option which sets maxPageSize to 1 to effectively disable page alignment, which reveals the issue. Fixes https://bugs.llvm.org/show_bug.cgi?id=43212 Differential Revision: https://reviews.llvm.org/D67152 llvm-svn: 371013
* [LLD] [COFF] Implement MinGW default manifest handlingMartin Storsjo2019-09-048-1/+127
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In mingw environments, resources are normally compiled to resource object files directly, instead of letting the linker convert them to COFF format. Since some time, GCC supports the notion of a default manifest object. When invoking the linker, GCC looks for the default manifest object file, and if found in the expected path, it is added to linker commands. The default manifest is one that indicates support for the latest known versions of windows, to implicitly unlock the modern behaviours of certain APIs. Not all mingw/gcc distributions include this file, but e.g. in msys2, the default manifest object is distributed in a separate package (which can be but might not always be installed). This means that even if user projects only use one single resource object file, the linker can end up with two resource object files, and thus needs to support merging them. The default manifest has a language id of zero, and GNU ld has got logic for dropping a manifest with a zero language id, if there's another manifest present with a nonzero language id. If there are multiple manifests with a nonzero language id, the merging process errors out. Differential Revision: https://reviews.llvm.org/D66825 llvm-svn: 370974
* [WebAssembly] Initialize memory in start functionThomas Lively2019-09-0420-147/+252
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: - `__wasm_init_memory` is now the WebAssembly start function instead of being called from `__wasm_call_ctors` or called directly by the runtime. - Adds a new synthetic data symbol `__wasm_init_memory_flag` that is atomically incremented from zero to one by the thread responsible for initializing memory. - All threads now unconditionally perform data.drop on all passive segments. - Removes --passive-segments and --active-segments flags and controls segment type based on --shared-memory instead. The deleted flags were only present to ameliorate the upgrade path in Emscripten. Reviewers: sbc100, aheejin Subscribers: dschuff, jgravelle-google, sunfish, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65783 llvm-svn: 370965
* [ELF] Don't shrink RelrSectionFangrui Song2019-09-042-0/+44
| | | | | | | | | | | | | | | | | | | | Fixes PR43214. The size of SHT_RELR may oscillate between 2 numbers (see D53003 for a similar --pack-dyn-relocs=android issue). This can happen if the shrink of SHT_RELR causes it to take more words to encode relocation offsets (this can happen with thunks or segments with overlapping p_offset ranges), and the expansion of SHT_RELR causes it to take fewer words to encode relocation offsets. To avoid the issue, add padding 1s to the end of the relocation section if its size would decrease. Trailing 1s do not decode to more relocations. Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D67164 llvm-svn: 370923
* [ELF] Fix spell corrector: don't call elf::InputFile::getSymbols() on shared ↵Fangrui Song2019-09-041-1/+1
| | | | | | | | objects Exposed by pr34872.s llvm-svn: 370875
OpenPOWER on IntegriCloud