summaryrefslogtreecommitdiffstats
path: root/lld/ELF/MarkLive.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Revert an accidental commit af5ca40b47b3e85c3add81ccdc0b787c4bc355aeRui Ueyama2019-12-131-2/+0
|
* temporaryRui Ueyama2019-12-131-0/+2
|
* [ELF] Replace SymbolTable::forEachSymbol with iterator_range symbols()Fangrui Song2019-11-261-4/+2
| | | | | | | | | | | | | | D62381 introduced forEachSymbol(). It seems that many call sites cannot be parallelized because the body shared some states. Replace forEachSymbol with iterator_range<filter_iterator<...>> symbols() to simplify code and improve debuggability (std::function calls take some frames). It also allows us to use early return to simplify code added in D69650. Reviewed By: grimar Differential Revision: https://reviews.llvm.org/D70505
* [ELF] Improve --gc-sections compatibility with GNU ld regarding section groupsFangrui Song2019-11-191-2/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Based on D70020 by serge-sans-paille. The ELF spec says: > Furthermore, there may be internal references among these sections that would not make sense if one of the sections were removed or replaced by a duplicate from another object. Therefore, such groups must be included or omitted from the linked object as a unit. A section cannot be a member of more than one group. GNU ld has 2 behaviors that we don't have: - Group members (nextInSectionGroup != nullptr) are subject to garbage collection. This includes non-SHF_ALLOC SHT_NOTE sections. In particular, discarding non-SHF_ALLOC SHT_NOTE sections is an expected behavior by the Annobin project. See https://developers.redhat.com/blog/2018/02/20/annobin-storing-information-binaries/ for more information. - Groups members are retained or discarded as a unit. Members may have internal references that are not expressed as SHF_LINK_ORDER, relocations, etc. It seems that we should be more conservative here: if a section is marked live, mark all the other member within the group. Both behaviors are reasonable. This patch implements them. A new field InputSectionBase::nextInSectionGroup tracks the next member within a group. on ELF64, this increases sizeof(InputSectionBase) froms 144 to 152. InputSectionBase::dependentSections tracks section dependencies, which is used by both --gc-sections and /DISCARD/. We can't overload it for the "next member" semantic, because we should allow /DISCARD/ to discard sections independent of --gc-sections (GNU ld behavior). This behavior may be reasonably used by `/DISCARD/ : { *(.ARM.exidx*) }` or `/DISCARD/ : { *(.note*) }` (new test `linkerscript/discard-group.s`). Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D70146
* Fix a few typos in lld/ELF to cycle botsNico Weber2019-10-281-1/+1
|
* [ELF] Wrap things in `namespace lld { namespace elf {`, NFCFangrui Song2019-10-071-9/+12
| | | | | | | | | | | This makes it clear `ELF/**/*.cpp` files define things in the `lld::elf` namespace and simplifies `elf::foo` to `foo`. Reviewed By: atanasyan, grimar, ruiu Differential Revision: https://reviews.llvm.org/D68323 llvm-svn: 373885
* ELF: Move sections referred to by __start_/__stop_ symbols into the main ↵Peter Collingbourne2019-08-091-0/+12
| | | | | | | | | | | | | | | | | | | | | partition. In the case where C identifier sections have SHF_LINK_ORDER they will most likely be placed in the same partition as the section that they are associated with. But unless this happens to be the main partition, this will cause them to be excluded from the range covered by the __start_ and __stop_ symbols, which may lead to incorrect program behaviour. So we need to move them all into the main partition so that they will be covered by the __start_ and __stop_ symbols. We may want to refine this approach later and allow different __start_/__stop_ symbol values for different partitions. This would only make sense for relocations from SHT_NOTE sections since they are duplicated into each partition. Differential Revision: https://reviews.llvm.org/D65909 llvm-svn: 368375
* [Coding style change][lld] Rename variables for non-ELF portsRui Ueyama2019-07-111-2/+2
| | | | | | | | | | | This patch does the same thing as r365595 to other subdirectories, which completes the naming style change for the entire lld directory. With this, the naming style conversion is complete for lld. Differential Revision: https://reviews.llvm.org/D64473 llvm-svn: 365730
* [Coding style change] Rename variables so that they start with a lowercase ↵Rui Ueyama2019-07-101-121/+121
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | letter This patch is mechanically generated by clang-llvm-rename tool that I wrote using Clang Refactoring Engine just for creating this patch. You can see the source code of the tool at https://reviews.llvm.org/D64123. There's no manual post-processing; you can generate the same patch by re-running the tool against lld's code base. Here is the main discussion thread to change the LLVM coding style: https://lists.llvm.org/pipermail/llvm-dev/2019-February/130083.html In the discussion thread, I proposed we use lld as a testbed for variable naming scheme change, and this patch does that. I chose to rename variables so that they are in camelCase, just because that is a minimal change to make variables to start with a lowercase letter. Note to downstream patch maintainers: if you are maintaining a downstream lld repo, just rebasing ahead of this commit would cause massive merge conflicts because this patch essentially changes every line in the lld subdirectory. But there's a remedy. clang-llvm-rename tool is a batch tool, so you can rename variables in your downstream repo with the tool. Given that, here is how to rebase your repo to a commit after the mass renaming: 1. rebase to the commit just before the mass variable renaming, 2. apply the tool to your downstream repo to mass-rename variables locally, and 3. rebase again to the head. Most changes made by the tool should be identical for a downstream repo and for the head, so at the step 3, almost all changes should be merged and disappear. I'd expect that there would be some lines that you need to merge by hand, but that shouldn't be too many. Differential Revision: https://reviews.llvm.org/D64121 llvm-svn: 365595
* ELF: Add basic partition data structures and behaviours.Peter Collingbourne2019-05-291-14/+59
| | | | | | | | | | | | | | This change causes us to read partition specifications from partition specification sections and split output sections into partitions according to their reachability from partition entry points. This is only the first step towards a full implementation of partitions. Later changes will add additional synthetic sections to each partition so that they can be loaded independently. Differential Revision: https://reviews.llvm.org/D60353 llvm-svn: 361925
* Use SymbolTable::insert() to implement --trace.Rui Ueyama2019-05-281-4/+6
| | | | | | Differential Revision: https://reviews.llvm.org/D62381 llvm-svn: 361791
* [ELF] Fix a doc typo. NFCFangrui Song2019-05-241-1/+1
| | | | llvm-svn: 361617
* Revert r358069 "Discard debuginfo for object files empty after GC"Bob Haarman2019-05-161-25/+11
| | | | | | | | The change broke some scenarios where debug information is still needed, although MarkLive cannot see it, including the Chromium/Android build. Reverting to unbreak that build. llvm-svn: 360955
* Discard debuginfo for object files empty after GCRui Ueyama2019-04-101-11/+25
| | | | | | | | | | | | | | | | | | | | | | Patch by Robert O'Callahan. Rust projects tend to link in all object files from all dependent libraries and rely on --gc-sections to strip unused code and data. Unfortunately --gc-sections doesn't currently strip any debuginfo associated with GC'ed sections, so lld links in the full debuginfo from all dependencies even if almost all that code has been discarded. See https://github.com/rust-lang/rust/issues/56068 for some details. Properly stripping debuginfo for discarded sections would be difficult, but a simple approach that helps significantly is to mark debuginfo sections as live only if their associated object file has at least one live code/data section. This patch does that. In a (contrived but not totally artificial) Rust testcase linked above, it reduces the final binary size from 46MB to 5.1MB. Differential Revision: https://reviews.llvm.org/D54747 llvm-svn: 358069
* ELF: De-template SharedFile. NFCI.Peter Collingbourne2019-04-081-2/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D60305 llvm-svn: 357925
* Use a class instead of lambda-based callbacks to organize garbage collector.Rui Ueyama2019-03-251-117/+120
| | | | | | | | | | | | | | | | | | | | | | lld's mark-sweep garbage collector was written in the visitor pattern. There are functions that traverses a given graph, and the functions calls callback functions to dispatch according to node type. The code was originaly pretty simple, and lambdas worked pretty well. However, as we add more features to the garbage collector, that became more like a callback hell. We now have a callback function that wraps another callback function, for example. It is not easy to follow the flow of the control. This patch rewrites it as a regular class. What was once a lambda is now a regular class member function. I think this change fixes the readability issue. No functionality change intended. Differential Revision: https://reviews.llvm.org/D59800 llvm-svn: 356966
* [ELF] De-template wrapSymbols, isReserved and addGotEntry. NFCFangrui Song2019-03-151-2/+2
| | | | llvm-svn: 356237
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* Fix formatting. NFC.Rui Ueyama2019-01-091-2/+3
| | | | llvm-svn: 350767
* [ELF] Move IsNeeded logic from SymbolTable::addShared to MarkLive, and check ↵Fangrui Song2018-12-201-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | IsUsedInRegularObj Summary: In glibc, libc.so is a linker script with an as-needed dependency on ld-linux-x86-64.so.2 GROUP ( /lib/x86_64-linux-gnu/libc.so.6 /usr/lib/x86_64-linux-gnu/libc_nonshared.a AS_NEEDED ( /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 ) ) ld-linux-x86-64.so.2 (as-needed) defines some symbols which resolve undefined references in libc.so.6, it will therefore be added as a DT_NEEDED entry, which isn't necessary. The test case as-needed-not-in-regular.s emulates the libc.so scenario, where ld.bfd and gold don't add DT_NEEDED for a.so The relevant code in gold/resolve.cc: // If we have a non-WEAK reference from a regular object to a // dynamic object, mark the dynamic object as needed. if (to->is_from_dynobj() && to->in_reg() && !to->is_undef_binding_weak()) to->object()->set_is_needed(); in_reg() appears to do something similar to IsUsedInRegularObj. This patch makes lld do the similar thing, but moves the check from addShared to a later stage MarkLive where all symbols are scanned. Reviewers: ruiu, pcc, espindola Reviewed By: ruiu Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D55902 llvm-svn: 349849
* Avoid unnecessary buffer allocation and memcpy for compressed sections.Rui Ueyama2018-10-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, we uncompress all compressed sections before doing anything. That works, and that is conceptually simple, but that could results in a waste of CPU time and memory if uncompressed sections are then discarded or just copied to the output buffer. In particular, if .debug_gnu_pub{names,types} are compressed and if no -gdb-index option is given, we wasted CPU and memory because we uncompress them into newly allocated bufers and then memcpy the buffers to the output buffer. That temporary buffer was redundant. This patch changes how to uncompress sections. Now, compressed sections are uncompressed lazily. To do that, `Data` member of `InputSectionBase` is now hidden from outside, and `data()` accessor automatically expands an compressed buffer if necessary. If no one calls `data()`, then `writeTo()` directly uncompresses compressed data into the output buffer. That eliminates the redundant memory allocation and redundant memcpy. This patch significantly reduces memory consumption (20 GiB max RSS to 15 Gib) for an executable whose .debug_gnu_pub{names,types} are in total 5 GiB in an uncompressed form. Differential Revision: https://reviews.llvm.org/D52917 llvm-svn: 343979
* [ELF] Pass callables by function_refBenjamin Kramer2018-06-161-5/+6
| | | | | | | No need to create a heavyweight std::function if it's not stored. No functionality change intended. llvm-svn: 334885
* [ELF] - Do not crash when do --gc-sections for non-allocatable metadata ↵George Rimar2018-05-171-4/+10
| | | | | | | | | | | | | | | | sections. Currently, LLD marks all non-allocatable sections except SHF_REL[A] as Live when doing GC. This can be a reason of the crash when SHF_LINK_ORDER sections are involved, because their parents can be dead. We should do GC for them correctly. The patch implements it. Differential revision: https://reviews.llvm.org/D46880 llvm-svn: 332589
* Split .eh_frame sections in parellel.Rafael Espindola2018-04-271-4/+0
| | | | | | We can now split them in the same spot we split merge sections. llvm-svn: 331064
* Split merge sections early.Rafael Espindola2018-04-271-1/+1
| | | | | | | | | | | | | | | Now that getSectionPiece is fast (uses a hash) it is probably OK to split merge sections early. The reason I want to do this is to split eh_frame sections in the same place. This does mean that we have to decompress early. Given that the only compressed sections are debug info, I don't think we are missing much. It is a small improvement: 0.5% on the geometric mean. llvm-svn: 331058
* 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
* Consistent use of header file for ICF and MarkLiveSam Clegg2018-02-201-1/+1
| | | | | | | | | | 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
* 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
* Use dyn_cast instead of dyn_cast_or_null.Rafael Espindola2017-12-201-1/+1
| | | | | | There should be no null sections in InputSections. llvm-svn: 321219
* Use a reference for the shared symbol file.Rafael Espindola2017-12-201-1/+1
| | | | | | Every shared symbol has a file, so we can use a reference. llvm-svn: 321187
* ELF: Do not follow relocation edges to output sections during GC.Peter Collingbourne2017-12-111-2/+3
| | | | | | | | This fixes an assertion error introduced by r320390. Differential Revision: https://reviews.llvm.org/D41095 llvm-svn: 320431
* Handle symbols pointing to output sections.Rafael Espindola2017-12-111-1/+1
| | | | | | | | | Now that gc sections runs after linker defined symbols are added it can see symbols that point to an OutputSection. Should fix a bot failure. llvm-svn: 320412
* [ELF] - Handle EhInputSection Live bit in MarkLive.cppGeorge Rimar2017-11-301-4/+8
| | | | | | | | | | Since MarkLive.cpp is the place where we set Live flags for other sections, it looks correct to do that there. Benefit is that we stop spreading GC logic outsize of MarkLive.cpp. Differential revision: https://reviews.llvm.org/D40454 llvm-svn: 319435
* Move Memory.{h,cpp} to Common.Rui Ueyama2017-11-281-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D40571 llvm-svn: 319221
* Bring back r319008.Rafael Espindola2017-11-281-0/+6
| | | | | | | | | | | | | | This includes a fix to mark copy reloc aliases as used. Original message: [ELF] Do not keep symbols if they referenced only from discarded sections. This patch also ensures that in case of "--as-needed" is used, DT_NEEDED entries are not created if they are required only by these eliminated symbols. llvm-svn: 319215
* Revert r319008, "[ELF] Do not keep symbols if they referenced only from ↵Igor Kudrin2017-11-281-6/+0
| | | | | | | | | | | discarded sections." and r319051, "Add a missing test." r319008 broke the LTO bots; r319051 depends on changes in r319008. llvm-svn: 319154
* [ELF] Do not keep symbols if they referenced only from discarded sections.Igor Kudrin2017-11-271-0/+6
| | | | | | | | | | This patch also ensures that in case of "--as-needed" is used, DT_NEEDED entries are not created if they are required only by these eliminated symbols. Differential Revision: https://reviews.llvm.org/D38790 llvm-svn: 319008
* ELF: Remove function Symbol::isInCurrentOutput().Peter Collingbourne2017-11-061-1/+1
| | | | | | This function is now equivalent to isDefined(). llvm-svn: 317449
* ELF: Merge DefinedRegular and Defined.Peter Collingbourne2017-11-061-2/+2
| | | | | | | | | Now that DefinedRegular is the only remaining derived class of Defined, we can merge the two classes. Differential Revision: https://reviews.llvm.org/D39667 llvm-svn: 317448
* Rename SymbolBody -> SymbolRui Ueyama2017-11-031-3/+3
| | | | | | | | | | | | | Now that we have only SymbolBody as the symbol class. So, "SymbolBody" is a bit strange name now. This is a mechanical change generated by perl -i -pe s/SymbolBody/Symbol/g $(git grep -l SymbolBody lld/ELF lld/COFF) nd clang-format-diff. Differential Revision: https://reviews.llvm.org/D39459 llvm-svn: 317370
* Merge SymbolBody and Symbol into one class, SymbolBody.Rui Ueyama2017-10-311-2/+2
| | | | | | | | | | | | | | | | | | | SymbolBody and Symbol were separated classes due to a historical reason. Symbol used to be a pointer to a SymbolBody, and the relationship between Symbol and SymbolBody was n:1. r2681780 changed that. Since that patch, SymbolBody and Symbol are allocated next to each other to improve memory locality, and they have 1:1 relationship now. So, the separation of Symbol and SymbolBody no longer makes sense. This patch merges them into one class. In order to avoid updating too many places, I chose SymbolBody as a unified name. I'll rename it Symbol in a follow-up patch. Differential Revision: https://reviews.llvm.org/D39406 llvm-svn: 317006
* Rename isInCurrentDSO -> isInCurrentOutput.Rui Ueyama2017-10-271-1/+1
| | | | | | | | | | | | DSO is short for dynamic shared object, so the function name was a little confusing because it sounded like it didn't work when we were a creating statically-linked executable or something. What we mean by "DSO" here is the current output file that we are creating. Thus the new name. Alternatively, we could call it the current ELF module, but "module" is a overloaded word, so I avoided that. llvm-svn: 316809
* [ELF] - Simplify reporting of garbage collected sections.George Rimar2017-10-271-0/+7
| | | | | | | | | This moves reporting of garbage collected sections right after we do GC. That simplifies things. Differential revision: https://reviews.llvm.org/D39058 llvm-svn: 316759
* [ELF] - Do not collect SHT_REL[A] sections unconditionally when ↵George Rimar2017-10-241-9/+3
| | | | | | | | | | | | | --gc-sections and --emit-relocs used together. This is "Bug 34836 - --gc-sections remove relocations from --emit-relocs", When --emit-relocs is used, LLD currently always drops SHT_REL[A] sections from output if --gc-sections is present. Patch fixes the issue. Differential revision: https://reviews.llvm.org/D38724 llvm-svn: 316418
* Handle shared symbols in --gc-sections.Rafael Espindola2017-10-131-1/+1
| | | | | | | We don't want to gc a section if it is used via __start_*, but we were doing that if the same symbol was visible in a shared library. llvm-svn: 315727
* Simplify. NFC.Rafael Espindola2017-10-131-2/+2
| | | | llvm-svn: 315724
* Remove ScriptConfiguration class and move the members to LinkerScript class.Rui Ueyama2017-10-111-1/+1
| | | | | | | | | | | | | | | | ScriptConfiguration was a class to contain parsed results of linker scripts. LinkerScript is a class to interpret it. That ditinction was needed because we haven't instantiated LinkerScript early (because, IIRC, LinkerScript class was a ELFT template function). So, when we parse linker scripts, we couldn't directly store the result to a LinkerScript instance. Now, that limitation is gone. We instantiate LinkerScript at the very beginning of our main function. We can directly store parse results to a LinkerScript instance. llvm-svn: 315403
* Handle input section liveness only in MarkLive.cpp.Rui Ueyama2017-10-101-1/+37
| | | | | | | | | | | | The condition whether a section is alive or not by default is becoming increasingly complex, so the decision of garbage collection is spreading over InputSection.h and MarkLive.cpp, which is not a good state. This moves the code to MarkLive.cpp, to keep the file the central place to make decisions about garbage collection. llvm-svn: 315384
* [ELF] Simpler scheme for handling common symbolsBen Dunbobbin2017-09-291-10/+1
| | | | | | | | | Convert all common symbols to regular symbols after scan. This means that the downstream code does not to handle common symbols as a special case. Differential Revision: https://reviews.llvm.org/D38137 llvm-svn: 314495
* Revert rL313697, "Compact EhSectionPiece from 32 bytes to 16 bytes."NAKAMURA Takumi2017-09-201-1/+1
| | | | | | | It broke selfhosting. http://lab.llvm.org:8011/builders/clang-with-lto-ubuntu/builds/4896 llvm-svn: 313731
OpenPOWER on IntegriCloud