summaryrefslogtreecommitdiffstats
path: root/lld/ELF/Target.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [ELF] - Ignore R_386_NONE.George Rimar2017-01-111-0/+2
| | | | | | | | | | | | | | We had an error when met this relocation after latest changes aboult listing x86 relocations explicitly. Since we support R_X86_64_NONE, and GNU ld supports R_386_NONE, it seems reasonable to have. Differential revision: https://reviews.llvm.org/D28552 llvm-svn: 291672
* [ELF] - Explicitly list supported relocations for x86 target.George Rimar2017-01-111-1/+7
| | | | | | | | | | | | | | | | Previously some value was returned by default for relocations by getRelExpr(), even if relocation actually was not supported. This is orthogonal alternative to D28094. Instead of implementing probably useless R_386_PC8/R_386_8 relocations, this patch uses them in a testcase to demonstrate what happens when LLD mets unsupported relocations. Patch passes all testcases and changes logic only for x86. Differential revision: https://reviews.llvm.org/D28516 llvm-svn: 291658
* Merge elf::toString and coff::toString.Rui Ueyama2017-01-061-4/+4
| | | | | | The two overloaded functions hid each other. This patch merges them. llvm-svn: 291222
* [ELF] Add support for thunks to undefined non-weak symbolsPeter Smith2017-01-041-2/+5
| | | | | | | | | | | | In a shared library an undefined symbol is implicitly imported. If the symbol is called as a function a PLT entry is generated for it. When the caller is a Thumb b.w a thunk to the PLT entry is needed as all PLT entries are in ARM state. This change allows undefined symbols to have thunks in the same way that shared symbols may have thunks. llvm-svn: 290951
* [ELF] - Use error() instead of fatal() during relaxation of R_X86_64_GOTTPOFFGeorge Rimar2016-12-221-1/+1
| | | | | | | | | | | | This is last known noticable fatal() in target.cpp. We also have other ones for unknown relocations or creating unknown targets, but that one can be just error I think. Used yaml2obj to generate test. Differential revision: https://reviews.llvm.org/D28049 llvm-svn: 290335
* [ELF] - Do not call fatal() in Target.cpp, call error() instead.George Rimar2016-12-211-7/+7
| | | | | | | | | | | | | | | | | | | | | We probably would want to avoid fatal() if we can in context of librarification, but for me reason of that patch is to help D27900 go. D27900 changes errors reporting to something like error: text1 note: text2 note: text3 where hint used to provide additional information about location. In that case I can't just call fatal() because user will not see notes after that what adds additional complication to handle. So It is good to switch fatal() to error() where it is possible. Also it adds testcase with broken relocation number. Previously we did not have any, It checks that error() instead of fatal() works fine. Differential revision: https://reviews.llvm.org/D27973 llvm-svn: 290239
* Move a function defintion to make it static.Rui Ueyama2016-12-211-0/+29
| | | | llvm-svn: 290215
* Remove lld/Support/Memory.h.Rui Ueyama2016-12-181-1/+1
| | | | | | | | | | | | I thought for a while about how to remove it, but it looks like we can just copy the file for now. Of course I'm not happy about that, but it's just less than 50 lines of code, and we already have duplicate code in Error.h and some other places. I want to solve them all at once later. Differential Revision: https://reviews.llvm.org/D27819 llvm-svn: 290062
* Rename functions as per post commit review for r289072.Rui Ueyama2016-12-151-12/+12
| | | | llvm-svn: 289758
* [ELF] Add R_ARM_RELATIVE to relocations that can be applied to GotSectionPeter Smith2016-12-131-0/+1
| | | | | | | | | | | | | | When compiling -fpie and linking with the --pie option the R_ARM_GOTBREL relocation to D is resolved by writing the value of D into the .got slot and emitting an R_ARM_RELATIVE relocation for it. This changes adds the R_ARM_RELATIVE relocation to the switch in relocateOne() so we can process the GotSection relocation to write the value of the variable as well as emitting the dynamic relocation. Differential revision: https://reviews.llvm.org/D27678 llvm-svn: 289527
* Add support for R_X86_64_GOT64.Rafael Espindola2016-12-091-0/+2
| | | | llvm-svn: 289277
* [ELF][I386] .got.plt entries for i386 should use VA of ifunc resolverPeter Smith2016-12-091-0/+16
| | | | | | | | | | | | | | | | | | The i386 glibc ld.so expects the .got.slot entry that is relocated by a R_386_IRELATIVE relocation to point directly at the ifunc resolver and not the address of the PLT entry + 6 (thus entering the lazy resolver). This is also the case for ARM and I suspect it is because these use REL relocations and can't use the addend field to store the address of the ifunc resolver. If the lazy resolver is used we get an error message stating that only R_386_JUMP_SLOT is supported. As ARM and i386 share the same code, I've removed the ARM specific test and added a writeIgotPlt() function that by default calls writeGotPlt(). ARM and i386 override this to write the address of the ifunc resolver. Differential Revision: https://reviews.llvm.org/D27581 llvm-svn: 289198
* Move Memory.{h,cpp} to lld/Support so that we can use them from COFF.Rui Ueyama2016-12-081-3/+2
| | | | llvm-svn: 289084
* Use make to instantiate Target and LinkerScript. NFC.Rui Ueyama2016-12-081-12/+13
| | | | llvm-svn: 289079
* Make function names shorter. NFC.Rui Ueyama2016-12-081-13/+13
| | | | llvm-svn: 289072
* Do not use template where template is not needed.Rui Ueyama2016-12-081-8/+8
| | | | | | Compilers can inline and optimize this code in the same way as template. llvm-svn: 289071
* [ELF] - Read 16 bits for R_386_16/R_386_PC16 relocations instead of 32.George Rimar2016-12-081-1/+2
| | | | | | | Looks it was theoretically incorrect if the section is at the very end of the file as reading 32 bits would pass the end of file llvm-svn: 289046
* [ELF][MIPS] Make _gp, _gp_disp, __gnu_local_gp global symbolsSimon Atanasyan2016-12-081-4/+4
| | | | | | | | | | | | | | These MIPS specific symbols should be global because in general they can have an arbitrary value. By default this value is a fixed offset from .got section. This patch adds more checks to the mips-gp-local.s test case but marks it as XFAIL because LLD does not allow redefinition of absolute symbols value by a linker script. This should be fixed by D27276. Differential revision: https://reviews.llvm.org/D27524 llvm-svn: 289025
* Rename MaxPageSize to DefaultMaxPageSize to avoid confusion.Rafael Espindola2016-12-071-3/+3
| | | | | | Thanks to Rui for the suggestion. llvm-svn: 288982
* ELF/AArch64: Refactor R_AARCH64_LDST{8,15,32,64,128}_ABS_LO12_NC RelocationsAdhemerval Zanella2016-12-071-12/+20
| | | | | | | | | | | | | | This patch refactor how to apply the R_AARCH64_LDST{8,16,32,64,128}_ABS_NC relocations by adding a new function to correct extract the bits expected by each relocation. This make is explicit which are the bits range expected and simplify the code to mask and shift the deriable values. It also fixes the R_AARCH64_LDST128_ABS_LO12_NC mask, although in pratice the mask/shift always returns a 16 bytes aligned value. Checked on AArch64 and with test-suite. llvm-svn: 288921
* ELF/AArch64: Fix R_AARCH64_LDST16_ABS_LO12_NC maskAdhemerval Zanella2016-12-051-1/+1
| | | | | | | | | | | The relocation R_AARCH64_LDST16_ABS_LO12_NC should set a ld/st immediate value to bits [11:1] not [11:2]. This patches fixes it and adds a testcase for regression. With this fix all the faulty tests on test-suite (clavm, lencod, and trimaran) pass. llvm-svn: 288670
* ELF/AArch64: Simplify R_AARCH64_ADD_ABS_LO12_NC relocationAdhemerval Zanella2016-12-051-5/+1
| | | | | | | This patch uses the updateAArch64Add on relocation apply and remove the comment. llvm-svn: 288669
* ELF/AArch64: consolidate getAArch64Page implementationAdhemerval Zanella2016-12-051-1/+4
| | | | | | | This patch avoid getAArch64Page code duplication by removing the implementation at InputSection. llvm-svn: 288668
* [ELF] - Implemented R_386_16 and R_386PC16 relocationsGeorge Rimar2016-12-031-0/+10
| | | | | | | | | | | | | | | | | A program or object file using R_386_8, R_386_16, R_386_PC16 or R_386_PC8 relocations is not conformant to latest ABI. The R_386_16, and R_386_8 relocations truncate the computed value to 16 - bits and 8 - bits respectively. R_386_PC16 and R_386_16 are used by some applications, for example by FreeBSD loaders. Previously we did not take addend in account for these relocation, counting it as 0, what is wrong and was a reason of hangs. This patch needed for example for FreeBSD pmbr (protective mbr). Differential revision: https://reviews.llvm.org/D27303 llvm-svn: 288581
* Ignore R_X86_64_NONE.Rafael Espindola2016-12-021-0/+2
| | | | | | | | | | It looks like the way dtrace works is * The user creates .o files that reference magical symbol names. * dtrace reads those files, collecs the info it needs and changes the relocation to R_X86_64_NONE expecting the linker to ignore them. llvm-svn: 288485
* [ELF] Add support for static TLS to ARMPeter Smith2016-11-291-0/+3
| | | | | | | | | | | | | | | | | | | | The module index dynamic relocation R_ARM_DTPMOD32 is always 1 for an executable. When static linking and when we know that we are not a shared object we can resolve the module index relocation statically. The logic in handleNoRelaxTlsRelocation remains the same for Mips as it has its own custom GOT writing code. For ARM we add the module index relocation to the GOT when it can be resolved statically. In addition the type of the RelExpr for the static resolution of TlsGotRel should be R_TLS and not R_ABS as we need to include the size of the thread control block in the calculation. Addresses the TLS part of PR30218. Differential revision: https://reviews.llvm.org/D27213 llvm-svn: 288153
* [ELF] Refactor target error messagesEugene Leviant2016-11-291-50/+60
| | | | | | Differential revision: https://reviews.llvm.org/D27097 llvm-svn: 288114
* Use relocations to fill statically known got entries.Rafael Espindola2016-11-291-0/+4
| | | | | | | | | | | | | Right now we just remember a SymbolBody for each got entry and duplicate a bit of logic to decide what value, if any, should be written for that SymbolBody. With ARM there will be more complicated values, and it seems better to just use the relocation code to fill the got entries. This makes it clear that each entry is filled by the dynamic linker or by the static linker. llvm-svn: 288107
* Sort. NFC.Rafael Espindola2016-11-291-1/+1
| | | | llvm-svn: 288102
* [ELF] Refactor getDynRel to print error locationEugene Leviant2016-11-251-23/+18
| | | | | | Differential revision: https://reviews.llvm.org/D27055 llvm-svn: 287915
* Remove trailing whitespace.Rui Ueyama2016-11-231-1/+1
| | | | llvm-svn: 287830
* Define toString() as a generic function to get a string for error message.Rui Ueyama2016-11-231-6/+6
| | | | | | | | | | | | | | | We have different functions to stringize objects to construct error messages. For InputFile, we have getFilename, and for InputSection, we have getName. You had to memorize them. I think this is the case where the function overloading comes in handy. This patch defines toString() functions that are overloaded for all these types, so that you just call it in error(). Differential Revision: https://reviews.llvm.org/D27030 llvm-svn: 287787
* lld: Default image base address to 0x200000 on x86-64Ed Maste2016-11-231-0/+3
| | | | | | | | | Align to the large page size (known as a superpage or huge page). FreeBSD automatically promotes large, superpage-aligned allocations. Differential Revision: https://reviews.llvm.org/D27042 llvm-svn: 287782
* [ELF] Convert PltSection to input sectionEugene Leviant2016-11-181-6/+6
| | | | | | Differential revision: https://reviews.llvm.org/D26842 llvm-svn: 287346
* [ELF][MIPS] Add MipsGotSection to handle MIPS GOTSimon Atanasyan2016-11-161-1/+1
| | | | | | | | | | | | | MIPS GOT handling is very different from other targets so it is better to keep the code in the separatre section class MipsGotSection. This patch introduces the new section and moves all MIPS specific code from GotSection to the new class. I did not rename fields and methods in the MipsGotSection class to reduce the diff and plan to do that by the separate commit. Differential revision: https://reviews.llvm.org/D26733 llvm-svn: 287150
* [ELF] Convert DynamicSection to input section.Eugene Leviant2016-11-151-2/+2
| | | | | | | | | | | | | | | | This patch introduces the following changes: - DynamicSection now inherits InputSection<ELFT> and was moved to SyntheticSections.h/.cpp. - Link and Entsize fields of DynamicSection are propagated to its output section - In<ELFT>::SyntheticSections was removed. - Finalization of synthetic sections was removed from OutputSection<ELFT>::finalize. Now finalizeSyntheticSections is used instead. Differential revision: https://reviews.llvm.org/D26603 llvm-svn: 286950
* [ELF] Convert .got section to input sectionEugene Leviant2016-11-111-1/+1
| | | | | | Differential revision: https://reviews.llvm.org/D26498 llvm-svn: 286580
* [ELF] Convert .got.plt section to input sectionEugene Leviant2016-11-101-6/+7
| | | | | | Differential revision: https://reviews.llvm.org/D26349 llvm-svn: 286443
* Split Header into individual fields.Rafael Espindola2016-11-091-15/+15
| | | | | | | | | This is similar to what was done for InputSection. With this the various fields are stored in host order and only converted to target order when writing. llvm-svn: 286327
* [ELF][MIPS] N32 ABI supportSimon Atanasyan2016-11-051-10/+18
| | | | | | | | | | | | | | | | | | | | | | | | In short the patch introduces support for linking object file conform MIPS N32 ABI [1]. This ABI is similar to N64 ABI but uses 32-bit pointer size. The most non-trivial requirement of this ABI is one more relocation packing format. N64 ABI puts multiple relocation type into the single relocation record. The N32 ABI uses series of successive relocations with the same offset for this purpose. In this patch, new function `mergeMipsN32RelTypes` handle this case and "convert" N32 relocation to the N64 relocation so the rest of the code keep unchanged. For now, linker does not support series of relocations applied to sections without SHF_ALLOC bit. Probably later I will add the support or insert some sort of assert into the `relocateNonAlloc` routine to catch this case. [1] ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/MIPS-N32-ABI-Handbook.pdf Differential revision: https://reviews.llvm.org/D26298 llvm-svn: 286052
* [ELF] Do not create interworking thunks for undefined weak references.Peter Smith2016-11-031-0/+3
| | | | | | | | | | | | | | An undefined weak reference is given an address of 0 this will incorrectly trigger the creation of a Thumb to ARM interworking Thunk if there is a Thumb branch instruction to the symbol. This results in an error as Thunks only make sense to defined or shared symbols. We prevent this by detecting an undefined symbol and not creating a thunk for it. Differential Revision: https://reviews.llvm.org/D26239 llvm-svn: 285896
* Implement R_PPC_ADDR32.Rui Ueyama2016-11-011-3/+4
| | | | | | Patch from Jack Andersen. llvm-svn: 285720
* Implement R_PPC_REL24 and R_PPC_REL32 relocations.Rui Ueyama2016-11-011-1/+14
| | | | | | | | | This enables LLD to relocate PC-relative R_PPC_REL32 and R_PPC_REL24 types (as used in bl instructions). Patch from Jack Andersen! llvm-svn: 285719
* [ELF][MIPS] Put local GOT entries accessed via a 16-bit index firstSimon Atanasyan2016-10-211-3/+4
| | | | | | | | | | | | | | | | | | | | | | Some MIPS relocations used to access GOT entries are able to manipulate 16-bit index. The other ones like R_MIPS_CALL_HI16/LO16 can handle 32-bit indexes. 16-bit relocations are generated by default. The 32-bit relocations are generated by -mxgot flag passed to compiler. Usually these relocation are not mixed in the same code but files like crt*.o contain 16-bit relocations so even if all "user's" code compiled with -mxgot flag a few 16-bit relocations might come to the linking phase. Now LLD does not differentiate local GOT entries accessed via a 16-bit and 32-bit indexes. That might lead to relocation's overflow if 16-bit entries are allocated to far from the beginning of the GOT. The patch introduces new "part" of MIPS GOT dedicated to the local GOT entries accessed by 32-bit relocations. That allows to put local GOT entries accessed via a 16-bit index first and escape relocation's overflow. Differential revision: https://reviews.llvm.org/D25833 llvm-svn: 284809
* [AMDGPU] Handle R_AMDGPU_ABS64 relocationKonstantin Zhuravlyov2016-10-201-0/+4
| | | | | | | | | | | This is needed for the following case (OpenCL example): __global int Var = 0; __global int* Ptr[] = {&Var}; ... Differential Revision: https://reviews.llvm.org/D25815 llvm-svn: 284764
* [ELF] Allow relative exceptions relocations in shared librariesPeter Smith2016-10-201-4/+4
| | | | | | | | | | | | | The R_ARM_PREL31 and R_ARM_NONE relocations should not be faulted in shared libraries. In the case of R_ARM_NONE, we have moved the TLS relaxation hint instruction to R_TLSDESC_CALL so that R_HINT can be used without side-effects. In the case of R_ARM_PREL31 we permit it to be used against PLT entries as the personality routines are imported when used in shared libraries. Differential Revision: https://reviews.llvm.org/D25721 llvm-svn: 284710
* [ELF] - Applied clang format. NFC.George Rimar2016-10-201-35/+34
| | | | llvm-svn: 284705
* [ELF] Support for R_ARM_TARGET2 relocationPeter Smith2016-10-171-0/+8
| | | | | | | | | | | | | | | | | The R_ARM_TARGET2 relocation is used in ARM exception tables to encode a data dependency that will only be dereferenced by code in the run-time support library. In a similar way to R_ARM_TARGET1 the handling of the relocation is target specific, it maps to one of R_ARM_ABS32, R_ARM_REL32 or R_ARM_GOT_PREL. The choice depends on the run-time library. R_ARM_GOT_PREL is used for linux and BSD, R_ARM_ABS32 and R_ARM_REL32 are used for bare-metal. The command line option --target2=<target> can be used to select the relocation used for R_ARM_TARGET2. The default is R_ARM_GOT_PREL. Differential revision: https://reviews.llvm.org/D25684 llvm-svn: 284404
* [ELF/AMDGPU]: Add support for new relocationsKonstantin Zhuravlyov2016-10-141-0/+10
| | | | | | Differential Revision: https://reviews.llvm.org/D25563 llvm-svn: 284197
* [ELF] Set max page size to 64K for AArch64Eugene Leviant2016-10-041-0/+1
| | | | | | Differential revision: https://reviews.llvm.org/D25079 llvm-svn: 283200
OpenPOWER on IntegriCloud