summaryrefslogtreecommitdiffstats
path: root/lld/ELF/Relocations.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Ensure that Elf_Rel addends are always written for dynamic relocationsAlexander Richardson2018-02-161-2/+2
| | | | | | | | | | | | 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
* Add a simpler version of addReloc. NFC.Rafael Espindola2018-02-131-19/+17
| | | | | | Extracted from a patch by Alexander Richardson! llvm-svn: 325016
* [ELF] Make overlapping output sections an errorAlexander Richardson2018-01-311-7/+0
| | | | | | | | | | | | | | | | | | | | | | | Summary: While trying to make a linker script behave the same way with lld as it did with bfd, I discovered that lld currently doesn't diagnose overlapping output sections. I was getting very strange runtime failures which I tracked down to overlapping sections in the resulting binary. When linking with ld.bfd overlapping output sections are an error unless --noinhibit-exec is passed and I believe lld should behave the same way here to avoid surprising crashes at runtime. The patch also uncovered an errors in the tests: arm-thumb-interwork-thunk was creating a binary where .got.plt was placed at an address overlapping with .got. Reviewers: ruiu, grimar, rafael Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D41046 llvm-svn: 323856
* Inline foot gun into only valid use.Rafael Espindola2018-01-161-1/+4
| | | | | | | | | | | | | | Symbol had both Visibility and getVisibility() and they had different meanings. That is just too easy to get wrong. getVisibility() would compute the visibility of a particular symbol (foo in bar.o), and Visibility stores the computed value we will put in the output. There is only one case when we want what getVisibility() provides, so inline it. llvm-svn: 322590
* Fix another case we were using the wrong visibility.Rafael Espindola2018-01-161-1/+1
| | | | llvm-svn: 322580
* Rename --icf-data and add a corresponding flag for functions.Rafael Espindola2018-01-101-1/+18
| | | | | | | | | | When we have --icf=safe we should be able to define --icf=all as a shorthand for --icf=safe --ignore-function-address-equality. For now --ignore-function-address-equality is used only to control access to non preemptable symbols in shared libraries. llvm-svn: 322152
* Rewrite our relocation processing.Rafael Espindola2018-01-091-186/+146
| | | | | | | | | | | | | | | | | | | | | | | | | | This splits relocation processing in two steps. First, analyze what needs to be done at the relocation spot. This can be a constant (non preemptible symbol, relative got reference, etc) or require a dynamic relocation. At this step we also consider creating copy relocations. Once that is done we decide if we need a got or a plt entry. The code is simpler IMHO. For example: - There is a single call to isPicRel since the logic is not split among adjustExpr and the caller. - R_MIPS_GOTREL is simple to handle now. - The tracking of what is preemptible or not is much simpler now. This also fixes a regression with symbols being both in a got and copy relocated. They had regressed in r268668 and r268149. The other test changes are because of error messages changes or the order of two relocations in the output. llvm-svn: 322047
* Move scanReloc to an auxiliary function.Rafael Espindola2018-01-081-146/+155
| | | | | | | | | | The body of the in scanRelocs is fairly big. This moves it to its own function. It is not a big readability win by itself, but should help further refactoring. llvm-svn: 322035
* Simplify handling of size relocations.Rafael Espindola2018-01-051-4/+0
| | | | | | This is possible now that getSize is not a template. llvm-svn: 321900
* Centralize Config->IsRela handling.Rafael Espindola2018-01-051-19/+4
| | | | | | | This merges the two places were we check Config->IsRela to decide how to write a relocation addend. llvm-svn: 321889
* Inline a function that is only called once. NFC.Rafael Espindola2018-01-041-31/+26
| | | | llvm-svn: 321780
* Use references for a few arguments that are never null.Rafael Espindola2018-01-031-13/+13
| | | | llvm-svn: 321772
* Mention symbol name in error message.Rafael Espindola2018-01-031-4/+3
| | | | llvm-svn: 321769
* Use getLocation to improve error message.Rafael Espindola2018-01-031-2/+2
| | | | llvm-svn: 321768
* Update code as this also handles GOT relocations.Rafael Espindola2018-01-031-1/+1
| | | | llvm-svn: 321738
* Use a switch. NFC.Rafael Espindola2018-01-031-5/+8
| | | | llvm-svn: 321737
* Refactor duplicated expression.Rafael Espindola2018-01-031-4/+3
| | | | llvm-svn: 321736
* Use a swtich. NFC.Rafael Espindola2018-01-031-4/+7
| | | | llvm-svn: 321734
* Simplify mips gprel handling.Rafael Espindola2018-01-031-23/+7
| | | | | | | We normally add checks on the architecture independent Expr instead of on the architecture dependent relocation type. llvm-svn: 321733
* Don't assume that size relocations are always constant.Rafael Espindola2018-01-031-1/+5
| | | | llvm-svn: 321688
* Produce relocations with weak undef if the section is RW.Rafael Espindola2018-01-031-6/+6
| | | | | | | If a section is RW there is no reason to drop a relocation with a weak undefined symbol. llvm-svn: 321684
* Allow copy relocation with -z notext.Rafael Espindola2017-12-281-5/+8
| | | | | | | | | | This makes adjustExpr a bit simpler too IMHO. It seems that some of the complication around relocation processing is that we are trying to create copy relocations too early. It seems we could handle a few simple cases first and continue. llvm-svn: 321507
* Don't try to preempt protected symbols with -z notext.Rafael Espindola2017-12-271-10/+10
| | | | | | I will send a followup patch removing the FIXME this patch adds. llvm-svn: 321499
* [ELF] - Allow relocation to a weak undefined symbol when -z notext is given.George Rimar2017-12-271-13/+13
| | | | | | | | | | | | | | Previously we failed to resolve them when produced executables: "relocation R_X86_64_32 cannot be used against shared object; recompile with -fPIC" Patch fixes it so that we resolve them to 0 for executables. And for -shared case we still should produce the relocation. This finishes fixing PR35720. DIfferential revision: https://reviews.llvm.org/D41551 llvm-svn: 321473
* Allow relocations in rw sections to create plt entries.Rafael Espindola2017-12-241-8/+4
| | | | | | | | | | | If a relocation cannot be implemented by the dynamic linker and the section is rw, allow creating a plt entry to use as the function address as if the section was ro. This matches bfd and gold. It also matches our behavior with -z notext. llvm-svn: 321430
* Detemplate reportDuplicate.Rafael Espindola2017-12-231-12/+9
| | | | | | | | | | We normally avoid "switch (Config->EKind)", but in this case I think it is worth it. It is only executed when there is an error and it allows detemplating a lot of code. llvm-svn: 321404
* [ELF] - Allow using PLT relocations when "-z notext" is given.George Rimar2017-12-231-28/+38
| | | | | | | | | | | | | | | This is part of PR35720. Currently LLD allows dynamic relocations against text when -z notext is given. Though for non-PIC relocations like R_X86_64_PC32 that does not work, we produce "relocation R_X86_64_PC32 cannot be used against shared object;" error because they may overflow in runtime. Solution implemented is to use PLT for them. Differential revision: https://reviews.llvm.org/D41541 llvm-svn: 321400
* Call isStaticLinkTimeConstant only once per relocation.Rafael Espindola2017-12-211-7/+10
| | | | | | | | | It is a pretty expensive function. Some of the speedups: clang: 1.92% chrome: 1.15% linux-kernel: 1.40% llvm-svn: 321311
* Use a reference for the shared symbol file.Rafael Espindola2017-12-201-5/+5
| | | | | | Every shared symbol has a file, so we can use a reference. llvm-svn: 321187
* Don't write preemptible symbol values to the .got.Rafael Espindola2017-12-181-1/+1
| | | | | | | | It is not necessary and matches what bfd and gold do. This was a regression from r315658. llvm-svn: 321023
* Move RelaPlt and RelaIplt to InX. NFC.Rafael Espindola2017-12-101-5/+5
| | | | llvm-svn: 320327
* Move RelaDyn to InX. NFC.Rafael Espindola2017-12-101-21/+20
| | | | llvm-svn: 320324
* Remove some includes from InputFiles.h.Rafael Espindola2017-12-091-0/+1
| | | | | | | They were not used in InputFiles.h and it was getting too easy to add circular includes. llvm-svn: 320256
* Add a call to std::vector::reserve.Rafael Espindola2017-12-061-0/+3
| | | | | | | | | | This reduces total allocations when linking clang fsds from 263.21MB to 174.62MB. This also has some very nice speed improvements on some benchmarks. Chromium and clang fsds link 6% faster. llvm-svn: 319976
* Fix a crash.Rafael Espindola2017-12-061-2/+2
| | | | | | | This is a constructed testcase I noticed while working on another patch. llvm-svn: 319874
* Use Symbol::File directly.Rafael Espindola2017-11-291-2/+2
| | | | | | | We are already paying the cost of storing a InputFile in every Symbol, so use it uniformly. llvm-svn: 319378
* 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/+1
| | | | | | | | | | | | | | 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
* [ELF][MIPS] Fix crash in LLD when linking code that needs PIC thunksAlexander Richardson2017-11-201-0/+2
| | | | | | | | | | | | | | | | | | | | | | | Summary: The bug triggers when the following conditions are met: - A thunk is created in a given input section S - A linker script is specified - There is at least one matcher in the linker script .text section output that does not match any of the sections in the input files, before the matcher that matches section S. The issue was found when linking the FreeBSD kernel for MIPS when built with -fPIC. Patch by Alfredo Mazzinghi. Reviewers: ruiu, psmith, atanasyan Reviewed By: ruiu Subscribers: peter.smith, emaste, sdardis, krytarowski, llvm-commits Differential Revision: https://reviews.llvm.org/D40174 llvm-svn: 318653
* [ELF] Fix typo in comment for getISDThunkSec [NFC]Peter Smith2017-11-061-1/+1
| | | | | | | | The ISR in the comment should read ISD for InputSectionDescription. The use of ISR (InputSectionRange) was from the original implementation that did not use the sections from InputSectionDescription directly. llvm-svn: 317469
* ELF: Merge DefinedRegular and Defined.Peter Collingbourne2017-11-061-1/+1
| | | | | | | | | 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 Body -> Sym.Rui Ueyama2017-11-041-113/+110
| | | | | | | | | | This patch is mechanically created by sed -i -e s/Body/Sym/g lld/ELF/*.{cpp,h} and clang-format-diff. llvm-svn: 317392
* Rename SymbolBody -> SymbolRui Ueyama2017-11-031-19/+17
| | | | | | | | | | | | | 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
* [ELF] - Teach LLD to report line numbers for data symbols.George Rimar2017-11-011-2/+2
| | | | | | | | | | | | | | | | | | | This is PR34826. Currently LLD is unable to report line number when reporting duplicate declaration of some variable. That happens because for extracting line information we always use .debug_line section content which describes mapping from machine instructions to source file locations, what does not help for variables as does not describe them. In this patch I am taking the approproate information about variables locations from the .debug_info section. Differential revision: https://reviews.llvm.org/D38721 llvm-svn: 317080
* Merge SymbolBody and Symbol into one class, SymbolBody.Rui Ueyama2017-10-311-4/+4
| | | | | | | | | | | | | | | | | | | 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
* Skip abs symbols when handling copy reloc aliases.Rafael Espindola2017-10-301-1/+2
| | | | | | | Since we now only check st_value, we have to consider the case where the section index is special. llvm-svn: 316928
* Reduce sizeof(Symbol) from 104 bytes to 88 bytes.Rui Ueyama2017-10-281-1/+1
| | | | | | | Finding aliases for shared symbols doesn't need st_shndx because we can just compare st_value. llvm-svn: 316848
* Pass symbol attributes instead of ElfSym to Shared symbol ctor.Rui Ueyama2017-10-281-9/+6
| | | | | | | This change allows us to use less templates for Shared symbol and the functions that deals with shared symbols. llvm-svn: 316841
* [ELF] Add support for multiple passes to createThunks()Peter Smith2017-10-271-22/+160
| | | | | | | | | | | | | This change allows Thunks to be added on multiple passes. To do this we must merge only the thunks added in each pass, and deal with thunks that have drifted out of range of their callers. A thunk may end out of range of its caller if enough thunks are added in between the caller and the thunk. To handle this we create another thunk. Differential Revision: https://reviews.llvm.org/D34692 llvm-svn: 316754
* [ELF] Introduce range extension thunks for ARMPeter Smith2017-10-271-23/+45
| | | | | | | | | | | | | | This change adds initial support for range extension thunks. All thunks must be created within the first pass so some corner cases are not supported. A follow up patch will add support for multiple passes. With this change the existing tests arm-branch-error.s and arm-thumb-branch-error.s now no longer fail with an out of range branch. These have been renamed and tests added for the range extension thunk. Differential Revision: https://reviews.llvm.org/D34691 llvm-svn: 316752
OpenPOWER on IntegriCloud