summaryrefslogtreecommitdiffstats
path: root/lld/ELF
Commit message (Collapse)AuthorAgeFilesLines
...
* Keep flags from phantom synthetic sections.Rafael Espindola2018-02-264-23/+25
| | | | | | | | | | | | | | | | | | | | | This fixes pr36475. I think this code can be simplified a bit, but I would like to check in the more direct fix if we are in agreement on the direction and then refactor. This is not something that bfd does. The issue is not noticed in bfd because it keeps fewer sections from the linkerscript in the output. The reasons why it seems reasonable to do this: - As George noticed, we would still keep the flags if the output section had both an empty synthetic section and a regular section - We need an heuristic to find the flags of output sections. Using the flags of a synthetic section that would have been there seems a reasonable heuristic. llvm-svn: 326137
* [ELF] - Fix variable name and mistype in comment. NFC.George Rimar2018-02-261-4/+4
| | | | llvm-svn: 326090
* [ELF] Fix IsPreemptible comment and typo. NFCFangrui Song2018-02-232-2/+2
| | | | llvm-svn: 325963
* [ELF][MIPS] Set EI_ABIVERSION flag accordingly to MIPS ABIs requirementSimon Atanasyan2018-02-231-0/+11
| | | | | | | | MIPS ABIs require that if an executable file uses non-PIC model, the EI_ABIVERSION entry in the ELF header should be incremented from 0 to 1. That allows obsoleted / limited dynamic linkers refuse to link them. llvm-svn: 325890
* [ELF] - Do not remove empty output sections that are explicitly assigned to ↵George Rimar2018-02-233-36/+23
| | | | | | | | | | | | | phdr in script. This continues direction started in D43069. We can keep sections that are explicitly assigned to segment in script. It helps to simplify code. Differential revision: https://reviews.llvm.org/D43571 llvm-svn: 325887
* Recommit "[ELF] - Do not crash with --emit-relocs and --icf=all together."George Rimar2018-02-231-9/+6
| | | | | | | | | | | | | | | | Latest patch version now. Original commit message: [ELF] - Do not crash with --emit-relocs and --icf=all together. Previously we would crash because did not mark .rel[a] sections as dead and they tried to access parent which was not live after ICF and therefore was null. Differential revision: https://reviews.llvm.org/D43241 llvm-svn: 325879
* [ELF] - Revert r325877 "[ELF] - Do not crash with --emit-relocs and ↵George Rimar2018-02-231-2/+0
| | | | | | | | --icf=all together." Not latest version of patch was committed by mistake. llvm-svn: 325878
* [ELF] - Do not crash with --emit-relocs and --icf=all together.George Rimar2018-02-231-0/+2
| | | | | | | | | | Previously we would crash because did not mark .rel[a] sections as dead and they tried to access parent which was not live after ICF and therefore was null. Differential revision: https://reviews.llvm.org/D43241 llvm-svn: 325877
* [ELF] - Report error if removed empty output section declaration used ↵George Rimar2018-02-231-0/+7
| | | | | | | | | | | | | | undefined symbols. This is for fixing PR36297. Issue itself is that if we have SECTIONS { .bar (a+b) : { *(.stub) } }; script and no section .stub, when LLD will remove .bar, but produce output with undefined symbols a and b. Differential revision: https://reviews.llvm.org/D43069 llvm-svn: 325875
* [ELF] Add comment for preemptible and fix typo. NFCFangrui Song2018-02-234-7/+8
| | | | | | | | Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D43642 llvm-svn: 325855
* Make undefined symbol in DSO to pull out object files from archive files.Rui Ueyama2018-02-231-2/+7
| | | | | | | | | | | | | | | | | | | We have an internal program that does't link without this patch. I don't know of any open-source program that needs this, but there might be. Since this patch improves compatibility with GNU linkers with a few lines of code, I think it's worth to be committed. The problem is about undefined symbols in DSOs. Some programs depend on the GNU linkers' behavior that they pull out object files from archive files to resolve undefined symbols in DSOs. We already allow that kind of "reverse" dependency (from DSOs to the main executable) for regular symbols, in particular, for "__progname" symbol (which is usually in crt0.o), but that doesn't work if the symbol is in an archive file. This patch is to make it work. Differential Revision: https://reviews.llvm.org/D43658 llvm-svn: 325849
* [ELF] - Rewrote outdated comment. NFC.George Rimar2018-02-221-2/+2
| | | | llvm-svn: 325809
* [ELF] - Introduce getInputSections() helper.George Rimar2018-02-225-40/+27
| | | | | | | | | | | We sometimes need to iterate over input sections for a given output section. It is not very convinent because we have to iterate over section descriptions. Patch introduces getInputSections helper, it simplifies things. Differential revision: https://reviews.llvm.org/D43574 llvm-svn: 325763
* Revert r325679: [ELF] Add -nopie alias for -no-pie (PR36423)Rui Ueyama2018-02-211-1/+0
| | | | | | | | | This reverts commit r325679 that was committed without discussion. Actually, in the discussion thread, most people opposed to have this option in lld. Reverting that change doesn't mean that this is a final decision, but that needs to be discussed first. llvm-svn: 325714
* [mips][lld] Address post commit review nit.Simon Dardis2018-02-211-3/+2
| | | | | | | Address @ruiu's post commit review comment about a value which is intended to be a unsigned 32 bit integer as using uint32_t rather than unsigned. llvm-svn: 325713
* [ELF] - Simplify. NFC.George Rimar2018-02-211-3/+1
| | | | llvm-svn: 325681
* [ELF] Add -nopie alias for -no-pie (PR36423)Hans Wennborg2018-02-211-0/+1
| | | | | | | | | | | | In r324043, --nopie was renamed to --no-pie to presumably fix a typo. As it turns out, "nopie" wasn't a typo but the spelling used by OpenBSD's binutils ld. Gold on the other hand spells the flag "no-pie". (Vanilla binutils doesn't have a flag like this at all.) Since they do the same thing, let's support both spellings. llvm-svn: 325679
* [mips][lld] Spectre variant two mitigation for MIPSR2Simon Dardis2018-02-203-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch provides migitation for CVE-2017-5715, Spectre variant two, which affects the P5600 and P6600. It implements the LLD part of -z hazardplt. Like the Clang part of this patch, I have opted for that specific option name in case alternative migitation methods are required in the future. The mitigation strategy suggested by MIPS for these processors is to use hazard barrier instructions. 'jalr.hb' and 'jr.hb' are hazard barrier variants of the 'jalr' and 'jr' instructions respectively. These instructions impede the execution of instruction stream until architecturally defined hazards (changes to the instruction stream, privileged registers which may affect execution) are cleared. These instructions in MIPS' designs are not speculated past. These instructions are defined by the MIPS32R2 ISA, so this mitigation method is not compatible with processors which implement an earlier revision of the MIPS ISA. For LLD, this changes PLT stubs to use 'jalr.hb' and 'jr.hb'. Reviewers: atanasyan, ruiu Differential Revision: https://reviews.llvm.org/D43488 llvm-svn: 325647
* Consistent use of header file for ICF and MarkLiveSam Clegg2018-02-206-5/+26
| | | | | | | | | | Previously wasm used a separate header to declare markLive and ELF used to declare ICF. This change makes each backend consistently declare these in their own headers. Differential Revision: https://reviews.llvm.org/D43529 llvm-svn: 325631
* Consistent (non) use of empty lines in include blocksSam Clegg2018-02-209-10/+0
| | | | | | | | | The profailing style in lld seem to be to not include such empty lines. Clang-tidy/clang-format seem to handle this just fine. Differential Revision: https://reviews.llvm.org/D43528 llvm-svn: 325629
* [lld/LTO] Remove unused Path parameter to AddBufferFnTeresa Johnson2018-02-201-2/+3
| | | | | | | | | | | | | | | | Summary: With D43396, no clients use the Path parameter anymore. This is the lld side fix with D43400. Depends on D43396 and D43400. Reviewers: pcc Subscribers: emaste, inglorion, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D43401 llvm-svn: 325620
* Rename DynamicReloc::getAddend() to computeAddend(). NFCAlexander Richardson2018-02-192-3/+11
| | | | | | | | | | | | | Summary: Before the name of the function sounded like it was just a getter for the private class member Addend. However, it actually calculates the final value for the r_addend field in Elf_Rela that is used when writing the .rela.dyn section. I also added a comment to the UseSymVA member to explain how it interacts with computeAddend(). Differential Revision: https://reviews.llvm.org/D43161 llvm-svn: 325485
* Use toString to print out garbage-collected sections.Rui Ueyama2018-02-171-2/+1
| | | | | | | | | | Currently, archive file name is missing in this message. In general, we should avoid constructing strings in an ad-hoc manner and instead use toString() to get consistent output strings. Differential Revision: https://reviews.llvm.org/D43420 llvm-svn: 325416
* Remove "--full-shutdown" and instead use an environment variable LLD_IN_TEST.Rui Ueyama2018-02-164-11/+6
| | | | | | | | | | | | | | | | | We are running lld tests with "--full-shutdown" option because we don't want to call _exit() in lld if it is running tests. Regular shutdown is needed for leak sanitizer. This patch changes the way how we tell lld that it is running tests. Now "--full-shutdown" is removed, and LLD_IN_TEST environment variable is used instead. This patch enables full shutdown on all ports, e.g. ELF, COFF and wasm. Previously, we enabled it only for ELF. Differential Revision: https://reviews.llvm.org/D43410 llvm-svn: 325413
* ELF: Stop collecting a list of symbols in ArchiveFile.Peter Collingbourne2018-02-165-29/+19
| | | | | | | | | | | | There seems to be no reason to collect this list of symbols. Also fix a bug where --exclude-libs would apply to all symbols that appear in an archive's symbol table, even if the relevant archive member was not added to the link. Differential Revision: https://reviews.llvm.org/D43369 llvm-svn: 325380
* Simplify RelocationBaseSection::addReloc.Rafael Espindola2018-02-163-16/+12
| | | | | | | | Now that we have R_ADDEND, UseSymVA was redundant. We only want to write the symbol virtual address when using an expression other than R_ADDEND. llvm-svn: 325360
* [ELF] - Fix comment. NFC.George Rimar2018-02-161-1/+1
| | | | | | Addresses forgotten comment for D43071. llvm-svn: 325332
* [ELF] - Support COPY, INFO, OVERLAY output sections attributes.George Rimar2018-02-163-4/+14
| | | | | | | | | | | | | | This is PR36298. (COPY), (INFO), (OVERLAY) all have the same effect: section should be marked as non-allocatable. (https://www.eecs.umich.edu/courses/eecs373/readings/Linker.pdf, 3.6.8.1 Output Section Type) Differential revision: https://reviews.llvm.org/D43071 llvm-svn: 325331
* Ensure that Elf_Rel addends are always written for dynamic relocationsAlexander Richardson2018-02-166-7/+19
| | | | | | | | | | | | Summary: This follows up on r321889 where writing of Elf_Rel addends was partially moved to RelocationBaseSection. This patch ensures that the addends are always written to the output section when a input section uses RELA but the output is REL. Differential Revision: https://reviews.llvm.org/D42843 llvm-svn: 325328
* Fix an issue that weak bit is dropped when there's a lazy object symbol.Rui Ueyama2018-02-161-2/+5
| | | | | | | | Previously, we accidentally dropped STB_WEAK bit from an undefined symbol if there is a lazy object symbol with the same name. That caused a compatibility issue with GNU gold. llvm-svn: 325316
* [ELF] Fix use after free in case of using --whole-archive.Igor Kudrin2018-02-163-3/+3
| | | | | | Differential Revision: https://reviews.llvm.org/D34554 llvm-svn: 325313
* Relax relocation type checking in a non-ALLOC section.Rui Ueyama2018-02-161-9/+27
| | | | | | | | | | | | | | | | | | Even though it doesn't make sense, there seems to be multiple programs in the wild that create PC-relative relocations in non-ALLOC sections. I believe this is caused by the negligence of GNU linkers to not report any errors for such relocations. Currently, lld emits warnings against such relocations and exits. So, you cannot link any program that contains wrong relocations until you fix an issue in a program that generates wrong ELF files. It's often impractical to fix a program because it's not always easy. This patch relaxes the error checking and emit a warning instead. Differential Revision: https://reviews.llvm.org/D43351 llvm-svn: 325307
* [ELF] Simplify handling of AT section attribute.Igor Kudrin2018-02-152-9/+4
| | | | | | | | This also makes the behavior close to GNU ld's. Differential Revision: https://reviews.llvm.org/D43284 llvm-svn: 325213
* Fix an issue that lld drops symbol versions for -r.Rui Ueyama2018-02-151-1/+6
| | | | | | | | | | When we are emitting a relocatable output, we should keep the original symbol name including "@" part. Previously, we drop that part unconditionally which resulted in dropping versions from symbols. Differential Revision: https://reviews.llvm.org/D43307 llvm-svn: 325204
* Revert r325158: Convert an assert to a static_assert. NFC.Rui Ueyama2018-02-141-2/+2
| | | | | | This reverts commit r325158 because it broke GCC builds. llvm-svn: 325183
* Convert an assert to a static_assert. NFC.Sam Clegg2018-02-141-2/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D43305 llvm-svn: 325158
* Make --export-dynamic-symbol to add undefined symbols even if ↵Rui Ueyama2018-02-141-3/+8
| | | | | | | | | | | | --export-dynamic is given. This patch addresses a minor compatibility issue with GNU linkers. Previously, --export-dynamic-symbol is completely ignored if you pass --export-dynamic together. Differential Revision: https://reviews.llvm.org/D43266 llvm-svn: 325152
* [ELF] Add warnings for various symbols that cannot be orderedJames Henderson2018-02-144-8/+59
| | | | | | | | | | | | | | | | | | | | | | | | | There are a number of different situations when symbols are requested to be ordered in the --symbol-ordering-file that cannot be ordered for some reason. To assist with identifying these symbols, and either tidying up the order file, or the inputs, a number of warnings have been added. As some users may find these warnings unhelpful, due to how they use the symbol ordering file, a switch has also been added to disable these warnings. The cases where we now warn are: * Entries in the order file that don't correspond to any symbol in the input * Undefined symbols * Absolute symbols * Symbols imported from shared objects * Symbols that are discarded, due to e.g. --gc-sections or /DISCARD/ linker script sections * Multiple of the same entry in the order file Reviewed by: rafael, ruiu Differential Revision: https://reviews.llvm.org/D42475 llvm-svn: 325125
* Use a stricter return type in buildSectionOrder. NFC.Rafael Espindola2018-02-141-9/+10
| | | | | | | | | | We sort inside output sections, so all the sections we see should be InputSectionBase. I noticed the patch adding callgraph based section ordering used this type and changing this separately makes the merge easier. llvm-svn: 325094
* Use toString to stringize sections and files.Rui Ueyama2018-02-131-7/+5
| | | | | | Differential Revision: https://reviews.llvm.org/D43251 llvm-svn: 325065
* Fix coding style error.Rui Ueyama2018-02-131-3/+3
| | | | llvm-svn: 325038
* Use reinterpret_cast<> instead of C-style cast. NFC.Rui Ueyama2018-02-131-2/+2
| | | | | | | | It is currently interpreted as reinterpret_cast<>. Make it explicit. Differential Revision: https://reviews.llvm.org/D43247 llvm-svn: 325033
* Check that Symbol types are trivially destructibleSam Clegg2018-02-131-0/+2
| | | | | | | | | | | | | | This adds an extra level of static safety to our use of placement new to allocate Symbol types. It prevents the accidental addition on a non-trivially-destructible member that could allocate and leak memory. From the spec: Storage occupied by trivially destructible objects may be reused without calling the destructor. Differential Revision: https://reviews.llvm.org/D43244 llvm-svn: 325025
* Use RelType in a few more places. NFC.Rafael Espindola2018-02-132-4/+4
| | | | llvm-svn: 325017
* Add a simpler version of addReloc. NFC.Rafael Espindola2018-02-133-19/+24
| | | | | | Extracted from a patch by Alexander Richardson! llvm-svn: 325016
* Do not use Decompressor::isCompressedELFSection. NFC.Rui Ueyama2018-02-121-1/+3
| | | | | | | | | In order to identify a compressed section, we check if a section name starts with ".zdebug" or the section has SHF_COMPRESSED flag. We already use the knowledge in this function. So hiding that check in isCompressedELFSection doesn't make sense. llvm-svn: 324951
* Remove 'z' in .zdebug when decompressing a section.Rui Ueyama2018-02-122-6/+10
| | | | | | | | | | | When decompressing a compressed debug section, we drop SHF_COMPRESSED flag but we didn't drop "z" in ".zdebug" section name. This patch does that for consistency. This change also fixes the issue that .zdebug_gnu_pubnames are not dropped when we are creating a .gdb_index section. llvm-svn: 324949
* s/uncompress/decompress/g.Rui Ueyama2018-02-124-12/+12
| | | | | | | In lld, we use both "uncompress" and "decompress" which is confusing. Since LLVM uses "decompress", we should use the same term. llvm-svn: 324944
* Fixed extra ‘;’ warningGalina Kistanova2018-02-111-1/+1
| | | | llvm-svn: 324830
* Use RelType instead of uint32_t in DynamicReloc. NFCAlexander Richardson2018-02-101-2/+2
| | | | llvm-svn: 324821
OpenPOWER on IntegriCloud