summaryrefslogtreecommitdiffstats
path: root/lld/ELF/Target.h
Commit message (Collapse)AuthorAgeFilesLines
...
* Revert r327248, "For most Targets the _GLOBAL_OFFSET_TABLE_ symbol is ↵Peter Collingbourne2018-03-161-3/+2
| | | | | | | | | | | 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
* Reduce code duplication a bit.Rafael Espindola2018-03-141-0/+4
| | | | | | | The code for computing the offset of an entry in the plt is simple, but it was duplicated in quite a few places. llvm-svn: 327536
* For most Targets the _GLOBAL_OFFSET_TABLE_ symbol is expected to be atPeter Smith2018-03-111-2/+3
| | | | | | | | | | | | | | | | | | 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
* [ELF] Convert {read,write}*be to endianness-aware read/write.Fangrui Song2018-03-091-0/+25
| | | | | | | | Subscribers: emaste, nemanjai, arichardson, kbarton, llvm-commits Differential Revision: https://reviews.llvm.org/D44227 llvm-svn: 327156
* Use references instead of pointers. NFC.Rafael Espindola2017-12-191-2/+2
| | | | | | | These values are trivially never null. While at it, also use InputSection instead of InputSectionBase when possible. llvm-svn: 321126
* [ELF] When a relocation is out of range print the value and the rangeAlexander Richardson2017-12-111-6/+13
| | | | | | | | | | | | Reviewers: ruiu, grimar Reviewed By: ruiu Subscribers: emaste, nemanjai, javed.absar, kbarton, llvm-commits Differential Revision: https://reviews.llvm.org/D40962 llvm-svn: 320416
* Print the bad value and required alignment for unaligned relocationsAlexander Richardson2017-12-081-1/+2
| | | | | | | | | | | | Reviewers: ruiu, grimar Reviewed By: ruiu Subscribers: emaste, javed.absar, llvm-commits Differential Revision: https://reviews.llvm.org/D40963 llvm-svn: 320147
* Move MIPS-specific code from Symbols.cpp to MIPS.cpp.Rui Ueyama2017-11-071-0/+3
| | | | | | | | | We have a lot of "if (MIPS)" conditions in lld because the MIPS' ABI is different at various places than other arch's ABIs at where it don't have to be different, but we at least want to reduce MIPS-ness from the regular classes. llvm-svn: 317525
* Rename SymbolBody -> SymbolRui Ueyama2017-11-031-5/+5
| | | | | | | | | | | | | 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] Introduce range extension thunks for ARMPeter Smith2017-10-271-5/+5
| | | | | | | | | | | | | | 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
* [ELF] Pre-create ThunkSections at Target specific intervalsPeter Smith2017-10-271-0/+4
| | | | | | | | | | | | | | When an OutputSection is larger than the branch range for a Target we need to place thunks such that they are always in range of their caller, and sufficiently spaced to maximise the number of callers that can use the thunk. We use the simple heuristic of placing the ThunkSection at intervals corresponding to a target specific branch range. If the OutputSection is small we put the thunks at the end of the executable sections. Differential Revision: https://reviews.llvm.org/D34689 llvm-svn: 316751
* [lld] unified COFF and ELF error handling on new Common/ErrorHandlerBob Haarman2017-10-251-1/+1
| | | | | | | | | | | | | | | | | | | Summary: The COFF linker and the ELF linker have long had similar but separate Error.h and Error.cpp files to implement error handling. This change introduces new error handling code in Common/ErrorHandler.h, changes the COFF and ELF linkers to use it, and removes the old, separate implementations. Reviewers: ruiu Reviewed By: ruiu Subscribers: smeenai, jyknight, emaste, sdardis, nemanjai, nhaehnle, mgorny, javed.absar, kbarton, fedor.sergeev, llvm-commits Differential Revision: https://reviews.llvm.org/D39259 llvm-svn: 316624
* LLD/ELF: Allow targets to set e_flagsKonstantin Zhuravlyov2017-10-241-0/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D39139 llvm-svn: 316460
* Remove one parameter from Target::getRelExpr.Rui Ueyama2017-10-121-1/+0
| | | | | | | | A section was passed to getRelExpr just to create an error message. But if there's an invalid relocation, we would eventually report it in relocateOne. So we don't have to pass a section to getRelExpr. llvm-svn: 315552
* Define RelType to represent relocation types.Rui Ueyama2017-10-111-30/+34
| | | | | | | | | | | | | | | | | | We were using uint32_t as the type of relocation kind. It has a readability issue because what Type really means in `uint32_t Type` is not obvious. It could be a section type, a symbol type or a relocation type. Since we do not do any arithemetic operations on relocation types (e.g. adding one to R_X86_64_PC32 doesn't make sense), it would be more natural if they are represented as enums. Unfortunately, that is not doable because relocation type definitions are spread into multiple header files. So I decided to use typedef. This still should be better than the plain uint32_t because the intended type is now obvious. llvm-svn: 315525
* [ELF] Set Dot initially to --image-base value when using linker scriptsJames Henderson2017-10-101-5/+8
| | | | | | | | | | | | | | | | | | | | | When parsing linker scripts, LLD previously started with a '.' value of 0, regardless of the internal default image base for the target, and regardless of switches such as --image-base. It seems reasonable to use a different image base value when using linker scripts and --image-base is specified, since otherwise the switch has no effect. This change does this, as well as removing unnecessary initialisation of Dot where it is not used. The default image base should not be used when processing linker scripts, because this will change the behaviour for existing linker script users, and potentially result in invalid output being produced, as a subsequent assignment to Dot could move the location counter backwards. Instead, we maintain the existing behaviour of starting from 0 if --image-base is not specified. Reviewers: ruiu Differential Revision: https://reviews.llvm.org/D38360 llvm-svn: 315293
* Fix which file is in an error message.Rafael Espindola2017-08-041-0/+1
| | | | | | | When reporting an invalid relocation we were blaming the destination file instead of the file with the relocation. llvm-svn: 310084
* [ELF] - Apply clang-format. NFC.George Rimar2017-07-181-1/+1
| | | | llvm-svn: 308297
* [ELF] Introduce target specific inBranchRange() functionPeter Smith2017-07-171-0/+3
| | | | | | | | | | | | | | In preparation for range extension thunks introduce a function that will check whether a branch identified by a relocation type at a source address can reach a destination. For targets where range extension thunks are not supported the function will return true as it is not expected that branches are out of range. An implementation has been provided for ARM. Differential Revision: https://reviews.llvm.org/D34690 llvm-svn: 308188
* Add basic 64-bit SPARC supportRui Ueyama2017-06-281-0/+1
| | | | | | | | | | | | | | | Add support for the most common SPARC relocations. Make DT_PLTGOT point to the PLT on SPARC. Mark the PLT as executable on SPARC. This adds a basic test that creates a SPARV9 executable that invokes the exit system call on OpenBSD. Patch by Mark Kettenis. Differential Revision: https://reviews.llvm.org/D34618 llvm-svn: 306565
* [ELF] Define _GLOBAL_OFFSET_TABLE_ symbol relative to .gotPeter Smith2017-06-261-0/+4
| | | | | | | | | | | | | | | | | | On many architectures gcc and clang will recognize _GLOBAL_OFFSET_TABLE_ - . and produce a relocation that can be processed without needing to know the value of _GLOBAL_OFFSET_TABLE_. This is not always the case; for example ARM gcc produces R_ARM_BASE_PREL but clang produces the more general R_ARM_REL32 to _GLOBAL_OFFSET_TABLE_. To evaluate this relocation correctly _GLOBAL_OFFSET_TABLE_ must be defined to be the either the base of the GOT or end of the GOT dependent on architecture.. If/when llvm-mc is changed to recognize _GLOBAL_OFFSET_TABLE_ - . this change will not be necessary for new objects. However there may still be old objects and versions of clang. Differential Revision: https://reviews.llvm.org/D34355 llvm-svn: 306282
* Do not use make<> to allocate TargetInfo. NFC.Rui Ueyama2017-06-161-11/+11
| | | | llvm-svn: 305577
* Split Target.cpp into small files.Rui Ueyama2017-06-161-4/+43
| | | | | | | | | | | | Target.cpp contains code for all the targets that LLD supports. It was simple and easy, but as the number of supported targets increased, it got messy. This patch splits the file into per-target files under ELF/arch directory. Differential Revision: https://reviews.llvm.org/D34222 llvm-svn: 305565
* Remove isTlsLocalDynamicRel and isTlsInitialExecRel.Rafael Espindola2017-05-051-2/+0
| | | | | | | | | | | | | | 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
* [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] Recommit r299635 to pad x86 executable sections with 0xccJames Henderson2017-04-071-0/+4
| | | | | | This follows r299748 which fixed a latent bug the original commit exposed. llvm-svn: 299755
* Revert r299635 because it exposed a latent bug.James Henderson2017-04-061-4/+0
| | | | llvm-svn: 299655
* [ELF] Pad x86 executable sections with 0xcc int3 instructionsJames Henderson2017-04-061-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Executable sections should not be padded with zero by default. On some architectures, 0x00 is the start of a valid instruction sequence, so can confuse disassembly between InputSections (and indeed the start of the next InputSection in some situations). Further, in the case of misjumps into padding, padding may start to be executed silently. On x86, the "0xcc" byte represents the int3 trap instruction. It is a single byte long so can serve well as padding. This change switches x86 (and x86_64) to use this value for padding in executable sections, if no linker script directive overrides it. It also puts the behaviour into place making it easy to change the behaviour of other targets when desired. I do not know the relevant instruction sequences for trap instructions on other targets however, so somebody should add this separately. Because the old behaviour simply wrote padding in the whole section before overwriting most of it, this change also modifies the padding algorithm to write padding only where needed. This in turn has caused a small behaviour change with regards to what values are written via Fill commands in linker scripts, bringing it into line with ld.bfd. The fill value is now written starting from the end of the previous block, which means that it always starts from the first byte of the fill, whereas the old behaviour meant that the padding sometimes started mid-way through the fill value. See the test changes for more details. Reviewed by: ruiu Differential Revision: https://reviews.llvm.org/D30886 Bugzilla: http://bugs.llvm.org/show_bug.cgi?id=32227 llvm-svn: 299635
* Remove Target::isTlsGlobalDynamicRel()Rui Ueyama2017-04-061-1/+0
| | | | | | | | 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
* Merge InputSectionData and InputSectionBase.Rafael Espindola2017-02-231-2/+2
| | | | | | | Now that InputSectionBase is not a template there is no reason to have the two. llvm-svn: 295924
* Change the return type of getImplicitAddend to signed integer.Rui Ueyama2017-02-061-1/+1
| | | | | | | | | If relocations don't have addends, addends are embedded in operands. getImplicitAddend is a function to read addends. Addends can be negative numbers, so the return type of the function should be a signed integer type. llvm-svn: 294253
* [ELF] Use SyntheticSections for ThunksPeter Smith2017-02-011-10/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | Thunks are now implemented by redirecting the relocation to the symbol S, to a symbol TS in a Thunk. The Thunk will transfer control to S. This has the following implications: - All the side-effects of Thunks happen within createThunks() - Thunks are no longer stored in InputSections and Symbols no longer need to hold a pointer to a Thunk - The synthetic Thunk sections need to be merged into OutputSections This implementation is almost a direct conversion of the existing Thunks with the following exceptions: - Mips LA25 Thunks are placed before the InputSection that defines the symbol that needs a Thunk. - All ARM Thunks are placed at the end of the OutputSection of the first caller to the Thunk. Range extension Thunks are not supported yet so it is optimistically assumed that all Thunks can be reused. This is a recommit of r293283 with a fixed comparison predicate as std::merge requires a strict weak ordering. Differential revision: https://reviews.llvm.org/D29327 llvm-svn: 293757
* Revert "[ELF][ARM] Use SyntheticSections for Thunks"Rui Ueyama2017-01-281-5/+10
| | | | | | This reverts commit r293283 because it broke MSVC build. llvm-svn: 293352
* [ELF][ARM] Use SyntheticSections for ThunksPeter Smith2017-01-271-10/+5
| | | | | | | | | | | | | | | | | | | | | | | | Thunks are now implemented by redirecting the relocation to the symbol S, to a symbol TS in a Thunk. The Thunk will transfer control to S. This has the following implications: - All the side-effects of Thunks happen within createThunks() - Thunks are no longer stored in InputSections and Symbols no longer need to hold a pointer to a Thunk - The synthetic Thunk sections need to be merged into OutputSections This implementation is almost a direct conversion of the existing Thunks with the following exceptions: - Mips LA25 Thunks are placed before the InputSection that defines the symbol that needs a Thunk. - All ARM Thunks are placed at the end of the OutputSection of the first caller to the Thunk. Range extension Thunks are not supported yet so it is optimistically assumed that all Thunks can be reused. Differential Revision: https://reviews.llvm.org/D29129 llvm-svn: 293283
* [ELF] Add local mapping symbols to ARM PLT entriesPeter Smith2017-01-251-1/+2
| | | | | | | | | | | | | Mapping symbols allow a mapping symbol aware disassembler to correctly disassemble the PLT when the code immediately prior to the PLT is Thumb. To implement this we add a function to add symbols with local binding to be defined in SyntheticSymbols. Differential Revision: https://reviews.llvm.org/D28956 llvm-svn: 293044
* [ELF] Move createThunks() after scanRelocations()Peter Smith2017-01-181-1/+1
| | | | | | | | | | | | | | | | | | | | A necessary first step towards range extension thunks is to delay the creation of thunks until the layout of InputSections within OutputSections has been done. The change scans the relocations directly from InputSections rather than looking in the ELF File the InputSection came from. This will allow a future change to redirect the relocations to symbols defined by Thunks rather than indirect when resolving relocations. A side-effect of moving ThunkCreation is that the OutSecOff of InputSections may change in an OutputSection that contains Thunks. In well behaved programs thunks are not in OutputSections with dynamic relocations. Differential Revision: https://reviews.llvm.org/D28811 llvm-svn: 292359
* Merge elf::toString and coff::toString.Rui Ueyama2017-01-061-1/+2
| | | | | | The two overloaded functions hid each other. This patch merges them. llvm-svn: 291222
* [ELF][I386] .got.plt entries for i386 should use VA of ifunc resolverPeter Smith2016-12-091-0/+1
| | | | | | | | | | | | | | | | | | 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
* Rename MaxPageSize to DefaultMaxPageSize to avoid confusion.Rafael Espindola2016-12-071-1/+1
| | | | | | Thanks to Rui for the suggestion. llvm-svn: 288982
* ELF/AArch64: consolidate getAArch64Page implementationAdhemerval Zanella2016-12-051-0/+1
| | | | | | | This patch avoid getAArch64Page code duplication by removing the implementation at InputSection. llvm-svn: 288668
* [ELF] Refactor getDynRel to print error locationEugene Leviant2016-11-251-0/+1
| | | | | | Differential revision: https://reviews.llvm.org/D27055 llvm-svn: 287915
* [ELF][MIPS] Fix handling of _gp/_gp_disp/__gnu_local_gp symbolsSimon Atanasyan2016-11-231-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | Offset between beginning of a .got section and _gp symbols used in MIPS GOT relocations calculations. Usually the expression looks like VA + Offset - GP, where VA is the .got section address, Offset - offset of the GOT entry, GP - offset between .got and _gp. Also there two "magic" symbols _gp_disp and __gnu_local_gp which hold the offset mentioned above. These symbols might be referenced by MIPS relocations. Now the linker always defines _gp symbol and uses hardcoded value for its initialization. So offset between .got and _gp is 0x7ff0. The _gp_disp and __gnu_local_gp defined if required and initialized by 0x7ff0. In fact that is not correct because _gp symbol might be defined by a linker script and holds arbitrary value. In that case we need to use this value in relocation calculation and initialize _gp_disp and __gnu_local_gp properly. The patch fixes the problem and completes fixing the bug #30311. https://llvm.org/bugs/show_bug.cgi?id=30311 Differential revision: https://reviews.llvm.org/D27036 llvm-svn: 287832
* Define toString() as a generic function to get a string for error message.Rui Ueyama2016-11-231-1/+1
| | | | | | | | | | | | | | | 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-4/+2
| | | | | | | | | 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] Attempt to fix PPC buildbotEugene Leviant2016-11-111-1/+1
| | | | llvm-svn: 286590
* [ELF] Convert .got.plt section to input sectionEugene Leviant2016-11-101-1/+1
| | | | | | Differential revision: https://reviews.llvm.org/D26349 llvm-svn: 286443
* [ELF] Set MAXPAGESIZE to 2MiB on x86-64 to match bfd and gold.Michael J. Spencer2016-08-171-0/+1
| | | | | | The FreeBSD kernel relies on this behavior to not overwrite the boot loader. llvm-svn: 278889
* Create thunks before regular relocation scan.Rafael Espindola2016-07-201-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We will need to do something like this to support range extension thunks since that process is iterative. Doing this also has the advantage that when doing the regular relocation scan the offset in the output section is known and we can just store that. This reduces the number of times we have to run getOffset and I think will allow a more specialized .eh_frame representation. By itself this is already a performance win. firefox master 7.295045737 patch 7.209466989 0.98826892235 chromium master 4.531254468 patch 4.509221804 0.995137623774 chromium fast master 1.836928973 patch 1.823805241 0.992855612714 the gold plugin master 0.379768791 patch 0.380043405 1.00072310839 clang master 0.642698284 patch 0.642215663 0.999249070657 llvm-as master 0.036665467 patch 0.036456225 0.994293213284 the gold plugin fsds master 0.40395817 patch 0.404384555 1.0010555177 clang fsds master 0.722045545 patch 0.720946135 0.998477367518 llvm-as fsds master 0.03292646 patch 0.032759965 0.994943428477 scylla master 3.427376378 patch 3.368316181 0.98276810292 llvm-svn: 276146
* Remove TargetInfo::getImageBase. NFC.Rui Ueyama2016-07-141-2/+1
| | | | llvm-svn: 275447
* Add GotEntrySize/GotPltEntrySize to ELF target.Rui Ueyama2016-07-131-0/+2
| | | | | | | | | | | | | Patch by H.J Lu. For x86-64 psABI, the entry size of .got and .got.plt sections is 8 bytes for both LP64 and ILP32. Add GotEntrySize and GotPltEntrySize to ELF target instead of using size of ELFT::uint. Now we can generate a simple working x32 executable. Differential Revision: http://reviews.llvm.org/D22288 llvm-svn: 275301
OpenPOWER on IntegriCloud