summaryrefslogtreecommitdiffstats
path: root/lld/ELF/Writer.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [ELF] - Stop setting OutSecOff too early.George Rimar2018-04-091-4/+14
| | | | | | | | | | | | | | | | | | | | | | | Currently LLD sets OutSecOff in addSection for input sections. That is a fake offset (just a rude approximation to remember the order), used for sorting SHF_LINK_ORDER sections (see resolveShfLinkOrder, compareByFilePosition). There are 2 problems with such approach: 1. We currently change and reuse Size field as a value assigned. Changing size is not good because leads to bugs. Currently, SIZEOF(.bss) for empty .bss returns 2 because we add two empty synthetic sections and increase size twice by 1. (See PR37011: https://bugs.llvm.org/show_bug.cgi?id=37011) 2. Such approach simply does not work when --symbol-ordering-file is involved, because processing of the ordering file might break the initial section order. This fixes PR37011. Differential revision: https://reviews.llvm.org/D45368 llvm-svn: 329560
* [ELF] - Allow LLD to produce file symbols.George Rimar2018-04-091-1/+1
| | | | | | | | | | | | | This is for PR36716 and this enables emitting STT_FILE symbols. Output size affect is minor: lld binary size changes from 52,883,408 to 52,949,400 clang binary size changes from 83,136,456 to 83,219,600 Differential revision: https://reviews.llvm.org/D45261 llvm-svn: 329557
* Change which file we print when a symbol cannot be ordered.Rafael Espindola2018-04-061-26/+34
| | | | | | | | | | | | Currently there are a few odd things about the warning about symbols that cannot be ordered. This patch fixes: * When there is an undefined symbol that resolves to a shared file, we were printing the location of the undefined reference. * If there are multiple comdats, we were reporting them all. llvm-svn: 329371
* [ELF] Don't add NOLOAD sections to segmentEugene Leviant2018-04-051-1/+1
| | | | | | Differential revision: https://reviews.llvm.org/D45264 llvm-svn: 329281
* [ELF] - Rename checkSectionOverlap() to checkSections(). NFC.George Rimar2018-04-041-3/+3
| | | | | | Renaming was requested in post commit review for D43820. llvm-svn: 329159
* Instead of using std::copy, clear the vector first and add new elements. NFC.Rui Ueyama2018-04-031-10/+9
| | | | | | Differential Revision: https://reviews.llvm.org/D45227 llvm-svn: 329107
* ELF: Use a vector of pairs to sort sections ordered using ↵Peter Collingbourne2018-04-031-10/+14
| | | | | | | | | | --symbol-ordering-file. This improved performance by 0.5-1% linking Chromium for Android. Differential Revision: https://reviews.llvm.org/D45222 llvm-svn: 329106
* [ELF] - Check that output sections fit in address space.George Rimar2018-04-031-6/+14
| | | | | | | | | | Added checks to test that we do not produce output where VA of sections overruns the address space available. Differential revision: https://reviews.llvm.org/D43820 llvm-svn: 329063
* [ELF] - Fix the comment. NFC.George Rimar2018-04-031-3/+2
| | | | llvm-svn: 329062
* ELF: Place ordered sections in the middle of the unordered section list on ↵Peter Collingbourne2018-03-301-1/+69
| | | | | | | | | | | | | | | | | | | | | targets with limited-range branches. It generally does not matter much where we place sections ordered by --symbol-ordering-file relative to other sections. But if the ordered sections are hot (which is the case already for some users of --symbol-ordering-file, and is increasingly more likely to be the case once profile-guided section layout lands) and the target has limited-range branches, it is beneficial to place the ordered sections in the middle of the output section in order to decrease the likelihood that a range extension thunk will be required to call a hot function from a cold function or vice versa. That is what this patch does. After D44966 it reduces the size of Chromium for Android's .text section by 60KB. Differential Revision: https://reviews.llvm.org/D44969 llvm-svn: 328905
* Initialize Elf Header to zero to ensure that bytes not assigned any value ↵Rumeet Dhindsa2018-03-301-0/+4
| | | | | | | | later on are initialized properly. Differential Revision: https://reviews.llvm.org/D44986 llvm-svn: 328902
* Simplify. NFC.Rui Ueyama2018-03-291-28/+11
| | | | llvm-svn: 328817
* Exit early from a loop. NFC.Rui Ueyama2018-03-291-1/+1
| | | | | | | | This patch fixes an issue introduced in r328810 which made the algorithm to always run the loop O(n^2) times, though we can break early. The output remains the same. llvm-svn: 328811
* Refactor Writer::checkNoOverlappingSections. NFC.Rui Ueyama2018-03-291-47/+48
| | | | | | | This patch rewrites the function to remove lambda callbacks and use of template. The algorithm is the same as before. llvm-svn: 328810
* Unloop a for-loop so that we can comment on each symbol. NFC.Rui Ueyama2018-03-281-4/+6
| | | | llvm-svn: 328736
* Merge nested "if"s. NFC.Rui Ueyama2018-03-281-6/+4
| | | | llvm-svn: 328733
* Reduce code duplication a bit. NFCRafael Espindola2018-03-261-7/+7
| | | | llvm-svn: 328569
* [ELF] - Simplify. NFC.George Rimar2018-03-231-4/+2
| | | | llvm-svn: 328319
* [ELF] - Apply clang-format. NFC.George Rimar2018-03-221-10/+10
| | | | llvm-svn: 328195
* [ELF] - Make __start_/__stop_<section_name> symbols STV_PROTECTEDGeorge Rimar2018-03-201-2/+2
| | | | | | | | | There are no reasons for them to be STV_DEFAULT, recently bfd did the same change. Differential revision: https://reviews.llvm.org/D44566 llvm-svn: 327983
* [ELF] Add basic support for PPC LEZaara Syeda2018-03-191-1/+7
| | | | | | | | | | | | This patch adds changes to start supporting the Power 64-Bit ELF V2 ABI. This includes: - Changing the ElfSym::GlobalOffsetTable to be named .TOC. - Creating a GotHeader so the first entry in the .got is .TOC. - Setting the e_flags to be 1 for ELF V1 and 2 for ELF V2 Differential Revision: https://reviews.llvm.org/D44483 llvm-svn: 327871
* [ELF] Recommit 327248 with Arm using the .got for _GLOBAL_OFFSET_TABLE_Peter Smith2018-03-191-5/+6
| | | | | | | | | | | | | | | | | | | | | | This is the same as 327248 except Arm defining _GLOBAL_OFFSET_TABLE_ to be the base of the .got section as some existing code is relying upon it. For most Targets the _GLOBAL_OFFSET_TABLE_ symbol is expected to be at the start of the .got.plt section so that _GLOBAL_OFFSET_TABLE_[0] = reserved value that is by convention the address of the dynamic section. Previously we had defined _GLOBAL_OFFSET_TABLE_ as either the start or end of the .got section with the intention that the .got.plt section would follow the .got. However this does not always hold with the current default section ordering so _GLOBAL_OFFSET_TABLE_[0] may not be consistent with the reserved first entry of the .got.plt. X86, X86_64 and AArch64 will use the .got.plt. Arm, Mips and Power use .got Fixes PR36555 Differential Revision: https://reviews.llvm.org/D44259 llvm-svn: 327823
* Revert r327248, "For most Targets the _GLOBAL_OFFSET_TABLE_ symbol is ↵Peter Collingbourne2018-03-161-6/+5
| | | | | | | | | | | expected to be at" This change broke ARM code that expects to be able to add _GLOBAL_OFFSET_TABLE_ to the result of an R_ARM_REL32. I will provide a reproducer on llvm-commits. llvm-svn: 327688
* Implement --cref.Rui Ueyama2018-03-141-1/+2
| | | | | | | | | | | | | | This is an option to print out a table of symbols and filenames. The output format of this option is the same as GNU, so that it can be processed by the same scripts as before after migrating from GNU to lld. This option is mildly useful; we can live without it. But it is pretty convenient sometimes, and it can be implemented in 50 lines of code, so I think lld should support this option. Differential Revision: https://reviews.llvm.org/D44336 llvm-svn: 327565
* [ELF] - Restrict section offsets that exceeds file size.George Rimar2018-03-131-6/+25
| | | | | | | | | | | | | | | | | This is part of PR36515. With some linkerscripts it is possible to get file offset overlaps and overflows. Currently LLD checks overlaps in checkNoOverlappingSections(). And also we allow broken output with --no-inhibit-exec. Problem is that sometimes final offset of sections is completely broken and we calculate output file size wrong and might crash. Patch implements check to verify that there is no output section which offset exceeds file size. Differential revision: https://reviews.llvm.org/D43819 llvm-svn: 327376
* For most Targets the _GLOBAL_OFFSET_TABLE_ symbol is expected to be atPeter Smith2018-03-111-5/+6
| | | | | | | | | | | | | | | | | | the start of the .got.plt section so that _GLOBAL_OFFSET_TABLE_[0] = reserved value that is by convention the address of the dynamic section. Previously we had defined _GLOBAL_OFFSET_TABLE_ as either the start or end of the .got section with the intention that the .got.plt section would follow the .got. However this does not always hold with the current default section ordering so _GLOBAL_OFFSET_TABLE_[0] may not be consistent with the reserved first entry of the .got.plt. X86, X86_64, Arm and AArch64 will use the .got.plt. Mips and Power use .got Fixes PR36555 Differential Revision: https://reviews.llvm.org/D44259 llvm-svn: 327248
* Use exact uint32_t for uint32_t ELF field. NFC.Rui Ueyama2018-03-071-1/+1
| | | | llvm-svn: 326934
* [ELF] - Adjust rangeToString to report ranges in a different format.George Rimar2018-03-071-1/+1
| | | | | | | | | | | | | It was raised during the review of D43819. LLD usually use [X, Y] for reporting ranges, like below: "relocation R_386_16 out of range: 65536 is not in [0, 65535]" Patch changes rangeToString() to do the same. Differential revision: https://reviews.llvm.org/D44207 llvm-svn: 326918
* Revert r326911: Improve --warn-symbol-ordering.Rui Ueyama2018-03-071-25/+18
| | | | | | This reverts commit r326911 because it was committed by accident. llvm-svn: 326914
* Improve --warn-symbol-ordering.Rui Ueyama2018-03-071-18/+25
| | | | | | | | | | | | | | | | Summary: I originally tried to simplify code and then noticed that lld doesn't do what it tells to the user by warn(). It says "unable to order discarded symbol" but it actually can for sections eliminated by ICF. With this patch, lld doesn't sort such sections. Reviewers: jhenderson, rafael Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D44180 llvm-svn: 326911
* Do not create multiple NOTE segments.Rui Ueyama2018-03-011-10/+18
| | | | | | | | | | | Previously, we didn't try to make effort to put .note sections next to each other in the output file, so two .note sections were likely to be stored to two separate NOTE segments. That's undesirable because we should create as few segments as possible in general. Differential Revision: https://reviews.llvm.org/D43858 llvm-svn: 326410
* Simplify removing empty output sections.Rafael Espindola2018-03-011-5/+0
| | | | | | | With this the meaning of the Live bit in output sections is clear: we have at some point added a input section into it. llvm-svn: 326401
* Merge {COFF,ELF}/Strings.cpp to Common/Strings.cpp.Rui Ueyama2018-02-281-1/+1
| | | | | | | | | This should resolve the issue that lld build fails in some hosts that uses case-insensitive file system. Differential Revision: https://reviews.llvm.org/D43788 llvm-svn: 326339
* [ELF] - Format, fix mistype. NFC.George Rimar2018-02-271-3/+2
| | | | llvm-svn: 326198
* [ELF] - Fix case of using both --icf and --symbol-ordering-file together.George Rimar2018-02-271-1/+1
| | | | | | | | | | | | | Imagine that we have sections A, B, C, where A == C and symbol ordering file containing symbols: symC, symB, symA Previously because of ICF it was possible that final order would be B, A or B, C. That violates order specified in ordering file. Patch changes that. Differential revision: https://reviews.llvm.org/D43234 llvm-svn: 326179
* Keep flags from phantom synthetic sections.Rafael Espindola2018-02-261-3/+3
| | | | | | | | | | | | | | | | | | | | | 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][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-231-14/+6
| | | | | | | | | | | | | 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
* [ELF] Add comment for preemptible and fix typo. NFCFangrui Song2018-02-231-3/+3
| | | | | | | | Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D43642 llvm-svn: 325855
* [ELF] - Rewrote outdated comment. NFC.George Rimar2018-02-221-2/+2
| | | | llvm-svn: 325809
* [ELF] - Introduce getInputSections() helper.George Rimar2018-02-221-6/+1
| | | | | | | | | | | 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
* [ELF] - Simplify. NFC.George Rimar2018-02-211-3/+1
| | | | llvm-svn: 325681
* [ELF] Simplify handling of AT section attribute.Igor Kudrin2018-02-151-4/+4
| | | | | | | | This also makes the behavior close to GNU ld's. Differential Revision: https://reviews.llvm.org/D43284 llvm-svn: 325213
* [ELF] Add warnings for various symbols that cannot be orderedJames Henderson2018-02-141-7/+40
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* Remove 'z' in .zdebug when decompressing a section.Rui Ueyama2018-02-121-5/+0
| | | | | | | | | | | 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
* Refactor how we decide which sections to sort.Rafael Espindola2018-02-091-28/+33
| | | | | | | | | | | | | This is a bit more verbose, but it has a few advantages. The logic on what to do with special sections like .init_array is not duplicated. Before we would need keep isKnownNonreorderableSection in sync. I think with this the call graph based sorting can be implemented by "just" returning a new order from buildSectionOrder. llvm-svn: 324744
* [ELF] Don't sort non reorderable sections with --symbol-ordering-fileMichael J. Spencer2018-02-081-1/+8
| | | | | | Differential Revision: https://reviews.llvm.org/D43038 llvm-svn: 324656
* [ELF] - Remove unused synthetic sections correctly.George Rimar2018-02-071-14/+12
| | | | | | | | | | | | | | | | This is PR35740 which now crashes because we remove unused synthetic sections incorrectly. We can keep input section description and corresponding output section live even if it must be empty and dead. This results in a crash because SHF_LINK_ORDER handling code tries to access first section which is nullptr in this case. Patch fixes the issue. Differential revision: https://reviews.llvm.org/D42681 llvm-svn: 324463
OpenPOWER on IntegriCloud