summaryrefslogtreecommitdiffstats
path: root/lld/ELF/Relocations.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Convert an use of OutputSections to OutputSectionCommands.Rafael Espindola2017-06-071-5/+8
| | | | | | This allows moving clearOutputSections a bit earlier. llvm-svn: 304947
* [ELF] Convert Thunks to use InputSectionDescriptionsPeter Smith2017-06-071-12/+32
| | | | | | | | | | | | | | | | Thunks are now generated per InputSectionDescription instead of per OutputSection. This allows created ThunkSections to be inserted directly into InputSectionDescription. Changes in this patch: - Loop over InputSectionDescriptions to find relocations to Thunks - Generate a ThunkSection per InputSectionDescription - Remove synchronize() as we no longer need it - Move fabricateDefaultCommands() before createThunks Differential Revision: https://reviews.llvm.org/D33835 llvm-svn: 304887
* [ELF] Refactor CreateThunks to extract the iteration through InputSections.Peter Smith2017-06-061-30/+41
| | | | | | | | | | | In preparation for inserting Thunks into InputSectionDescription::Sections extract the loop that finds InputSections that may have calls that need Thunks. This isn't much benefit now but this will be useful when we have to extract the InputSectionDescriptions::Sections from the script. Differential Revision: https://reviews.llvm.org/D33834 llvm-svn: 304783
* [ELF] Refactor ThunkCreator to not key on OutputSection for ThunksPeter Smith2017-06-061-31/+35
| | | | | | | | | | In preparation for inserting Thunks into InputSectionDescriptions this simple change associates added Thunks with a vector of InputSections instead of an OutputSection. As of now we are just using OutputSection::Sections. Differential Revision: https://reviews.llvm.org/D33832 llvm-svn: 304782
* [ELF] - Properly handle R_386_GOTPC relocation.George Rimar2017-06-011-3/+3
| | | | | | | | | | | | | | | | This is PR33243. R_GOTONLY_PC_FROM_END was not in a list of link time constant expressions and that was a result of confusiing messages like PR shows: /usr/bin/ld.lld: error: /usr/lib/go/src/runtime/alg.go:47: can't create dynamic relocation R_386_GOTPC against local symbol in readonly segment defined in /tmp/nice/go-link-597453838/go.o Though in reality we just should not have try to create a dynamic relocation for this case at all. Patch fixes the issue. Differential revision: https://reviews.llvm.org/D33717 llvm-svn: 304393
* Store a single Parent pointer for InputSectionBase.Rafael Espindola2017-05-311-1/+1
| | | | | | | | | | | | | | | Before InputSectionBase had an OutputSection pointer, but that was not always valid. For example, if it was a merge section one actually had to look at MergeSec->OutSec. This was brittle and caused bugs like the one fixed by r304260. We now have a single Parent pointer that points to an OutputSection for InputSection, but to a SyntheticSection for merge sections and .eh_frame. This makes it impossible to accidentally access an invalid OutSec. llvm-svn: 304338
* Alternative way to detemplate GotSection.Rafael Espindola2017-05-181-0/+4
| | | | | | | | | | | | | | | | | | | | GetSection is a template because write calls relocate. relocate has two parts. The non alloc code really has to be a template, as it is looking a raw input file data. The alloc part is only a template because of getSize. This patch folds the value of getSize early, detemplates getRelocTargetVA and splits relocate into a templated non alloc case and a regular function for the alloc case. This has the nice advantage of making sure we collect all the information we need for relocations before getting to InputSection::relocateNonAlloc. Since we know got is alloc, it can just call the function directly and avoid the template. llvm-svn: 303355
* [ELF] - Detemplate Thunk creation.George Rimar2017-05-171-21/+9
| | | | | | | | | Nothing special here, just detemplates code that became possible to detemplate after recent commits in a straghtforward way. Differential revision: https://reviews.llvm.org/D33234 llvm-svn: 303237
* Detemplate the got.Rafael Espindola2017-05-111-26/+26
| | | | | | This is a bit hackish, but allows for a lot of followup cleanups. llvm-svn: 302845
* Reduce template usage. NFC.Rafael Espindola2017-05-111-2/+2
| | | | llvm-svn: 302832
* Reduce template usage. NFC.Rafael Espindola2017-05-111-10/+10
| | | | llvm-svn: 302828
* Reduce template usage. NFC.Rafael Espindola2017-05-111-2/+2
| | | | llvm-svn: 302826
* Remove isTlsLocalDynamicRel and isTlsInitialExecRel.Rafael Espindola2017-05-051-2/+3
| | | | | | | | | | | | | | This feels a bit hackish, but I think it is still an improvement. The way a tls address is computed in the various architectures is not that different. For example, for local dynamic we need the base of the tls (R_TLSLD or R_TLSLD_PC), and the offset of that particular symbol (R_ABS). Given the similarity, we can just use the expressions instead of having two additional target hooks. llvm-svn: 302279
* Accept archive files with no symbol table instad of warning on them.Rui Ueyama2017-05-031-11/+0
| | | | | | | | | | | | | It seems virtually everyone who tries to do LTO build with Clang and LLD was hit by a mistake to forget using llvm-ar command to create archive files. I wasn't an exception. Since this is an annoying common issue, it is probably better to handle that gracefully rather than reporting an error and tell the user to redo build with different configuration. Differential Revision: https://reviews.llvm.org/D32721 llvm-svn: 302083
* [ELF] Tidy up handleARMTlsRelocation [NFC]Peter Smith2017-04-131-19/+17
| | | | | | | | | Replace addModuleReloc with AddTlsReloc so that we can use it for both the module relocation and the offset relocation. Differential Revision: https://reviews.llvm.org/D31751 llvm-svn: 300192
* [ELF] - Stop producing broken output for R_386_GOT32[X] relocations.George Rimar2017-04-081-1/+2
| | | | | | | | | | | | | | | | | | Previously we silently produced broken output for R_386_GOT32X/R_386_GOT32 relocations if they were used to compute the address of the symbol’s global offset table entry without base register when position-independent code is disabled. Situation happened because of recent ABI changes. Released ABI mentions that R_386_GOT32X can be calculated in a two different ways (so we did not follow ABI here before this patch), but draft ABI also mentions R_386_GOT32 relocation here. We should use the same calculations for both relocations. Problem is that we always calculated them as G + A - GOT (offset from end of GOT), but for case when PIC is disabled, according to i386 ABI calculation should be G + A, what should produce just an address in GOT finally. ABI: https://github.com/hjl-tools/x86-psABI/wiki/intel386-psABI-draft.pdf (p36, p60). llvm-svn: 299812
* [ELF] Do not pass GOT section as an argument to handleARMTlsRelocation and ↵Simon Atanasyan2017-04-071-27/+24
| | | | | | | | | | handleMipsTlsRelocation functions. NFC Both functions always use the same GOT sections In<ELFT>::Got and In<ELFT>::MipsGot respectively, so we do not need to pass them as an argument. llvm-svn: 299773
* [ELF] Fix ARM TLS global dynamic TlsOffsetRel for non-preemtible symbolsPeter Smith2017-04-071-0/+3
| | | | | | | | | | | | | | | When the target of the TlsOffsetRel is non-preemptible we can write the offset directly into the GOT without needing a dynamic relocation. This is optional for dynamically linked executables but is required for static linking. This change adds the relocation to the GOT entry and a test case for non-0 offsets so that if we miss out the offset the test won't spuriously pass by virtue of the default value being 0. Differential Revision: https://reviews.llvm.org/D31749 llvm-svn: 299751
* [ELF] Split handleNoRelaxTlsRelocation into ARM and Mips specific implsPeter Smith2017-04-071-23/+69
| | | | | | | | | | | | | | | | The handleNoRelaxTlsRelocation handled both ARM and Mips as at a high-level the actions of what to do when encountering a local dynamic or global dynamic TLS relocation are the same. However due to Mips using a custom GOT the differences of the implementation are enough that the function became difficult to understand. This change replaces handleNotRelaxTlsRelocation into handleARMTlsRelocation() and handleMipsTlsRelocation() so that the ARM and Mips specific code is isolated. Differential Revision: https://reviews.llvm.org/D31748 llvm-svn: 299750
* Rename refersToGotEntry needsGot and add comments.Rui Ueyama2017-04-061-9/+12
| | | | | | | | This patch addresses a post-commit review comment for r299615. Differential Revision: https://reviews.llvm.org/D31792 llvm-svn: 299722
* Create GOT and PLT entries early in scanRelocs().Rui Ueyama2017-04-061-46/+39
| | | | | | | | | | | | | | scanRelocs() does a lot of things. It fills InputSection's Relocations vector, making a decision whether a TLS relocation should be relaxed or not, and making a decision whether a GOT/PLT slot needs to be created or not. They don't actually have to be done in a single loop. I want to separate them so that some of them can be run concurently. As a first step, this patch moves PLT/GOT slot assignment to beginning of the loop, so that they just fall through to the next statements. This should make it clear that that code doesn't affect other parts of the loop. llvm-svn: 299615
* Remove Target::isTlsGlobalDynamicRel()Rui Ueyama2017-04-061-3/+3
| | | | | | | | Relocations are abstracted as platform-independent R_TLS_* relocations, so we don't need to check platform-specific ones to see if a relocation is TLS GD. llvm-svn: 299614
* [ELF] Make createThunks a class [NFC]Peter Smith2017-04-051-64/+63
| | | | | | | | | | | For range extension thunks we will need to repeatedly call createThunks() until no more thunks are created. We will need to retain the state of Thunks that we have created so far to avoid recreating them on later passes. This change does not change the functionality of createThunks(). Differential Revision: https://reviews.llvm.org/D31654 llvm-svn: 299530
* Change the error message format for an incompatible relocation.Rui Ueyama2017-04-031-15/+32
| | | | | | | | | | | | | | | Previous error message style: error: /home/alice/src/bar.c:12: relocation R_X86_64_PLT32 cannot refer to absolute symbol 'answer' defined in /home/alice/src/foo.o New error message style: error: relocation R_X86_64_PLT32 cannot refer to absolute symbol: foo >>> defined in /home/alice/src/foo.o >>> referenced by bar.c:12 (/home/alice/src/bar.c:12) >>> /home/alice/src/bar.o:(.text+0x1) llvm-svn: 299390
* Remove unnecessary cast and branch. NFC.James Henderson2017-03-311-5/+1
| | | | llvm-svn: 299208
* Do not enclose an entire file with namespaces.Rui Ueyama2017-03-301-14/+12
| | | | | | This change is to improve consistency with other files. llvm-svn: 299110
* Change the error message format for undefined symbols.Rui Ueyama2017-03-301-2/+8
| | | | | | | | | | | | | | | | | | | | Previously, undefined symbol errors are one line like this and wasn't easy to read. /ssd/clang/bin/ld.lld: error: /ssd/llvm-project/lld/ELF/Writer.cpp:207: undefined symbol 'lld::elf::EhFrameSection<llvm::object::ELFType<(llvm::support::endianness)0, true> >::addSection(lld::elf::InputSectionBase*)' This patch make it more structured like this. bin/ld.lld: error: undefined symbol: lld::elf::EhFrameSection<llvm::object::ELFType<(llvm::support::endianness)0, true> >>> Referenced by Writer.cpp:207 (/ssd/llvm-project/lld/ELF/Writer.cpp:207) >>> Writer.cpp.o in archive lib/liblldELF.a Discussion thread: http://lists.llvm.org/pipermail/llvm-dev/2017-March/111459.html Differential Revision: https://reviews.llvm.org/D31481 llvm-svn: 299097
* Revert r298815: Do not use assert to report broken input files.Rui Ueyama2017-03-291-4/+2
| | | | | | | This reverts commit because this really shouldn't happen unless there's a bug in LLD. llvm-svn: 299021
* Use uint64_t instead of uintX_t and size_t.Rui Ueyama2017-03-291-4/+2
| | | | | | uint64_t is simpler and less error-prone than target or host-dependent types. llvm-svn: 298969
* Change the order of parameters. NFC.Rui Ueyama2017-03-291-1/+1
| | | | | | | If a function takes a size and an alignment, we usually pass them in that order instead of the reverse order. llvm-svn: 298968
* Simplify. NFC.Rui Ueyama2017-03-271-3/+3
| | | | | | | | This patch calls getAddend on a relocation only when the relocation is RELA. That doesn't really improve runtime performance but should improve readability as the code now matches the function description. llvm-svn: 298828
* Factor out code to add a GOT entry.Rui Ueyama2017-03-261-22/+28
| | | | llvm-svn: 298821
* Factor out common code.Rui Ueyama2017-03-261-13/+15
| | | | llvm-svn: 298818
* Remove MIPS-specific code from computeAddend.Rui Ueyama2017-03-261-51/+56
| | | | | | | | | Previously, computeAddend had many parameters but most of them were used only for MIPS. The MIPS ABI is too odd that I don't want to mix it into the regular code path. Splitting the function into non-MIPS and MIPS parts makes the regular code path easy to follow. llvm-svn: 298817
* Do not use assert to report broken input files.Rui Ueyama2017-03-261-1/+5
| | | | llvm-svn: 298815
* Update comments.Rui Ueyama2017-03-261-1/+4
| | | | llvm-svn: 298814
* Remove a redundant local variable.Rui Ueyama2017-03-261-3/+5
| | | | llvm-svn: 298796
* Add a comment.Rui Ueyama2017-03-261-0/+1
| | | | llvm-svn: 298795
* Inline a function that is used only once.Rui Ueyama2017-03-261-6/+5
| | | | llvm-svn: 298794
* De-template a few functions in which ELFT is not needed.Rui Ueyama2017-03-261-32/+31
| | | | llvm-svn: 298793
* Add comments and return early.Rui Ueyama2017-03-261-9/+19
| | | | llvm-svn: 298792
* Remove unused parameter.Rui Ueyama2017-03-261-8/+8
| | | | llvm-svn: 298790
* Remove redundant local variables.Rui Ueyama2017-03-261-5/+3
| | | | llvm-svn: 298789
* Remove a parameter from adjustExpr. NFC.Rui Ueyama2017-03-261-8/+4
| | | | llvm-svn: 298788
* Inline a small lambda.Rui Ueyama2017-03-261-9/+8
| | | | llvm-svn: 298787
* Rename C -> Sec and RI -> Rel.Rui Ueyama2017-03-261-26/+26
| | | | | | | C is short for Chunk, but we are no longer using that term. RI is probably short for relocation iterator, but this is not an interator. llvm-svn: 298786
* Simplify relocation offset adjustment.Rui Ueyama2017-03-261-25/+50
| | | | | | | | Previously, relocation offsets are recalculated for .eh_frame sections inside the main loop, and that messed up the main loop. This patch separates that logic into a dedicated class. llvm-svn: 298785
* Update comment.Rui Ueyama2017-03-241-2/+4
| | | | llvm-svn: 298748
* Return early.Rui Ueyama2017-03-241-2/+4
| | | | llvm-svn: 298675
* Early continue. NFC.Rui Ueyama2017-03-241-20/+20
| | | | | | | | | | | | | | | | | | | | | | | The original code is a big `if` and `else` which ends with `continue` like this: if (cond) { ... // fall through } else { ... continue; } This patch rewrites it with the following. if (!cond) { ... continue; } ... llvm-svn: 298672
OpenPOWER on IntegriCloud