Commit Graph

148 Commits

Author SHA1 Message Date
Sean Fertile 4d354e1199 [PPC64] Fix DQ-form instruction handling and emit error for misalignment.
Relanding r340564, original commit message:

Fixes the handling of *_DS relocations used on DQ-form instructions where we
were overwriting some of the extended opcode bits. Also adds an alignment check
so that the user will receive a diagnostic error if the value we are writing
is not properly aligned.

Differential Revision: https://reviews.llvm.org/D51124

llvm-svn: 340832
2018-08-28 15:16:01 +00:00
Sid Manning 569a56d6a0 [ELF][HEXAGON] Add R_HEX_11/10/9_X support
Differential Revision: https://reviews.llvm.org/D51225

llvm-svn: 340739
2018-08-27 12:55:28 +00:00
Sid Manning 2c3d4b37b6 [ELF][HEXAGON] Add R_HEX_B13_PCREL relocation support
Differential Revision: https://reviews.llvm.org/D51166

llvm-svn: 340693
2018-08-25 23:16:37 +00:00
Sid Manning 6d0415e098 [ELF][HEXAGON] Add R_HEX_B9_PCREL and R_HEX_B9_PCREL_X relocation support
Differential Revision: https://reviews.llvm.org/D51045

llvm-svn: 340692
2018-08-25 21:25:35 +00:00
Sean Fertile 1542b0aef5 Revert "[PPC64] Fix DQ-form instruction handling and emit error for misalign..."
This reverts commit 5125b44dbb5d06b715213e4bec75c7346bfcc7d3.
ppc64-dq.s and ppc64-error-missaligned-dq.s fail on several of the build-bots.
Reverting to investigate.

llvm-svn: 340568
2018-08-23 19:10:40 +00:00
Sean Fertile a6b2ab7a91 [PPC64] Fix DQ-form instruction handling and emit error for misalignment.
Fixes the handling of *_DS relocations used on DQ-form instructions where we
were overwriting some of the extended opcode bits. Also adds an alignment check
so that the user will receive a diagnostic error if the value we are writing
is not properly aligned.

Differential Revision: https://reviews.llvm.org/D51124

llvm-svn: 340564
2018-08-23 18:35:09 +00:00
Sid Manning 564e65a4c0 [ELF][HEXAGON] Add R_HEX_16_X relocation
This relocation has only 6-bits the remaining are in the extender.

Differential Revision: https://reviews.llvm.org/D50603

llvm-svn: 340413
2018-08-22 15:25:15 +00:00
Zaara Syeda 662d146c5b [PPC64] Add TLS initial exec to local exec relaxation
This patch adds the target call back relaxTlsIeToLe to support TLS relaxation
from initial exec to local exec model.

Differential Revision: https://reviews.llvm.org/D48091

llvm-svn: 340281
2018-08-21 15:13:53 +00:00
Peter Smith a8656c62f5 [ELF] Add support for Armv5 and Armv6 compatible Thunks
Older Arm architectures do not support the MOVT and MOVW instructions so we
must use an alternative sequence of instructions to transfer control to the
destination.

Assuming at least Armv5 this patch adds support for Thunks that load or add
to the program counter. Note that there are no Armv5 Thumb Thunks as there
is no Thumb branch instruction in Armv5 that supports Thunks. These thunks
will not work for Armv4t (arm7tdmi) as this architecture cannot change state
from using the LDR or ADD instruction.

Differential Revision: https://reviews.llvm.org/D50077

llvm-svn: 340160
2018-08-20 09:37:50 +00:00
Peter Smith d1be026ede [ELF] Add support for older Arm Architectures with smaller branch range
The Thumb BL and BLX instructions on older Arm Architectures such as v5 and
v6 have a constrained encoding J1 and J2 must equal 1, later Architectures
relaxed this restriction allowing J1 and J2 to be used to calculate a larger
immediate.

This patch adds support for the old encoding, it is used when the build
attributes for the input objects only contain older architectures.

Differential Revision: https://reviews.llvm.org/D50076

llvm-svn: 340159
2018-08-20 09:19:30 +00:00
Rui Ueyama 4c7d6beb37 Remove unnecessary applyMask() application.
applyMask(0xffffffff, x) is an identity function.

llvm-svn: 340152
2018-08-20 06:33:29 +00:00
Sid Manning 5b0141c49e [ELF][HEXAGON] Add R_HEX_32 support
Differential Revision: https://reviews.llvm.org/D50657

llvm-svn: 339677
2018-08-14 13:52:38 +00:00
Sid Manning 07e541a892 [ELF][HEXAGON] Add R_HEX_8_X relocation
Differential Revision: https://reviews.llvm.org/D50577

llvm-svn: 339477
2018-08-10 21:48:40 +00:00
Sid Manning c53078a1e3 [ELF][HEXAGON] Add R_HEX_HI16/R_HEX_LO16 relocations
Differential Revision: https://reviews.llvm.org/D50520

llvm-svn: 339371
2018-08-09 20:04:53 +00:00
Rui Ueyama 5cd9c6bcd8 Support RISC-V
Patch by PkmX.

This patch makes lld recognize RISC-V target and implements basic
relocation for RV32/RV64 (and RVC). This should be necessary for static
linking ELF applications.

The ABI documentation for RISC-V can be found at:
https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md.
Note that the documentation is far from complete so we had to figure out
some details from bfd.

The patch should be pretty straightforward. Some highlights:

 - A new relocation Expr R_RISCV_PC_INDIRECT is added. This is needed as
   the low part of a PC-relative relocation is linked to the corresponding
   high part (auipc), see:
   https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#pc-relative-symbol-addresses

 - LLVM's MC support for RISC-V is very incomplete (we are working on
   this), so tests are given in objectyaml format with the original
   assembly included in the comments. Once we have complete support for
   RISC-V in MC, we can switch to llvm-as/llvm-objdump.

 - We don't support linker relaxation for now as it requires greater
   changes to lld that is beyond the scope of this patch. Once this is
   accepted we can start to work on adding relaxation to lld.

Differential Revision: https://reviews.llvm.org/D39322

llvm-svn: 339364
2018-08-09 17:59:56 +00:00
Sid Manning 17858207a0 Add R_HEX_6_X relocation support
This is a larger patch.  This relocation has irregular immediate
masks that require a lookup to find the correct mask.

Differential Revision: https://reviews.llvm.org/D50450

llvm-svn: 339332
2018-08-09 12:00:10 +00:00
Jordan Rupprecht 0f6d31812e [LLD] Update split stack support to handle more generic prologues. Improve error handling. Add test file for better code-coverage. Update tests to be more complete.
Submitting patch on behalf of saugustine.

Differential Revision: https://reviews.llvm.org/D49926

llvm-svn: 338750
2018-08-02 18:13:40 +00:00
Peter Smith 70997f9a4e [ELF][ARM] Implement support for Tag_ABI_VFP_args
The Tag_ABI_VFP_args build attribute controls the procedure call standard
used for floating point parameters on ARM. The values are:
0 - Base AAPCS (FP Parameters passed in Core (Integer) registers
1 - VFP AAPCS (FP Parameters passed in FP registers)
2 - Toolchain specific (Neither Base or VFP)
3 - Compatible with all (No use of floating point parameters)

If the Tag_ABI_VFP_args build attribute is missing it has an implicit value
of 0.
    
We use the attribute in two ways:
- Detect a clash in calling convention between Base, VFP and Toolchain.
we follow ld.bfd's lead and do not error if there is a clash between an
implicit Base AAPCS caused by a missing attribute. Many projects
including the hard-float (VFP AAPCS) version of glibc contain assembler
files that do not use floating point but do not have Tag_ABI_VFP_args.
- Set the EF_ARM_ABI_FLOAT_SOFT or EF_ARM_ABI_FLOAT_HARD ELF header flag
for Base or VFP AAPCS respectively. This flag is used by some ELF
loaders.
    
References:
- Addenda to, and Errata in, the ABI for the ARM Architecture for
Tag_ABI_VFP_args
- Elf for the ARM Architecture for ELF header flags
    
Fixes PR36009
    
Differential Revision: https://reviews.llvm.org/D49993

llvm-svn: 338377
2018-07-31 13:41:59 +00:00
Sid Manning bff6719450 [ELF][HEXAGON] Add R_HEX_32_6_X and R_HEX_12_X
And add a test.

llvm-svn: 338213
2018-07-29 11:59:38 +00:00
Sid Manning 3241724536 [ELF][HEXAGON] Add R_HEX_B15_PCREL_X relocation
Update testcase

Differential Revision: https://reviews.llvm.org/D49567

llvm-svn: 337829
2018-07-24 15:08:13 +00:00
Sid Manning 690b544f41 [ELF][HEXAGON] Add support for R_HEX_B15_PCREL
Add support and update the testcase.

Differential Revision: https://reviews.llvm.org/D49394

llvm-svn: 337494
2018-07-19 20:27:43 +00:00
Sid Manning bdd71f358d Add support for R_HEX_B32_PCREL_X, R_HEX_B22_PCREL_X relocations
A couple more basic relocations plus testcase.

Differential Revision: https://reviews.llvm.org/D47791

llvm-svn: 337484
2018-07-19 19:10:56 +00:00
Sterling Augustine 2526104ee4 Workaround warning bug in old versions of gcc.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480

llvm-svn: 337340
2018-07-18 00:33:25 +00:00
Sterling Augustine 4fd84c18df Implement framework for linking split-stack object files, and x86_64 support.
llvm-svn: 337332
2018-07-17 23:16:02 +00:00
Simon Atanasyan 64fb2901e5 [ELF][MIPS] Add mote tests on MipsArchTree routines, fix typos in error messages
This fix add more test cases for routines check MIPS ELF header flags and
flags from .MIPS.abiflags sections. The tests use yaml2obj for object
files generation because not all combinations of flags can be produced
by LLVM tools.

llvm-svn: 336704
2018-07-10 16:51:17 +00:00
Zaara Syeda 75c348a097 [PPC64] Add TLS local dynamic to local exec relaxation
This patch adds the target call back relaxTlsLdToLe to support TLS relaxation
from local dynamic to local exec model.

Differential Revision: https://reviews.llvm.org/D48293

llvm-svn: 336559
2018-07-09 16:35:51 +00:00
Simon Atanasyan 78c46bdf52 [ELF][MIPS] Simplify `checkFlags` routine and inline `rejectMicroMips64`. NFC
llvm-svn: 336414
2018-07-06 05:50:46 +00:00
Simon Atanasyan 0905b953da [ELF][MIPS] Remove support for linking microMIPS 64-bit code
Remove support for linking microMIPS 64-bit code because this kind of
ISA is rarely used and unsupported by LLVM.

Differential revision: https://reviews.llvm.org/D48949

llvm-svn: 336413
2018-07-06 05:50:41 +00:00
Rui Ueyama a8db71f06f Remove redundnat call of makeArrayRef(). NFC.
llvm-svn: 336378
2018-07-05 17:14:33 +00:00
Rui Ueyama 5ba7266761 Simplify PPC64::calcEFlags().
In this file we only have to handle the v2 ABI, so what we need to do
is to just make sure that all object files have v2 or unspecified version
number.

Differential Revision: https://reviews.llvm.org/D48112

llvm-svn: 336372
2018-07-05 16:58:42 +00:00
Zaara Syeda de54f584cc [PPC64] Add support for R_PPC64_GOT_DTPREL16* relocations
The local dynamic TLS access on PPC64 ELF v2 ABI uses R_PPC64_GOT_DTPREL16*
relocations when a TLS variables falls outside 2 GB of the thread storage
block. This patch adds support for these relocations by adding a new RelExpr
called R_TLSLD_GOT_OFF which emits a got entry for the TLS variable relative
to the dynamic thread pointer using the relocation R_PPC64_DTPREL64. It then
evaluates the R_PPC64_GOT_DTPREL16* relocations as the got offset for the
R_PPC64_DTPREL64 got entries.

Differential Revision: https://reviews.llvm.org/D48484

llvm-svn: 335732
2018-06-27 13:55:41 +00:00
Zaara Syeda 1cdd816c12 [PPC64] Add TLS global dynamic to local exec relaxation
This patch adds the target call back relaxTlsGdToLe to support TLS relaxation
from global dynamic to local exec model.

The relaxation performs the following transformation:
addis r3, r2, x@got@tlsgd@ha --> nop
addi r3, r3, x@got@tlsgd@l   --> addis r3, r13, x@tprel@ha
bl __tls_get_addr(x@tlsgd)   --> nop
nop                          --> addi r3, r3, x@tprel@l

Differential Revision: https://reviews.llvm.org/D48082

llvm-svn: 335730
2018-06-27 13:27:29 +00:00
Sean Fertile f60cb34c91 [PPC64] Thread-local storage general-dynamic to initial-exec relaxation.
Patch adds support for relaxing the general-dynamic tls sequence to
initial-exec.

the relaxation performs the following transformation:
addis r3, r2, x@got@tlsgd@ha --> addis r3, r2, x@got@tprel@ha
addi r3, r3, x@got@tlsgd@l   --> ld r3, x@got@tprel@l(r3)
bl __tls_get_addr(x@tlsgd)   --> nop
nop                          --> add r3, r3, r13

and instead of emitting a DTPMOD64/DTPREL64 pair for x, we emit a single
R_PPC64_TPREL64.

Differential Revision: https://reviews.llvm.org/D48090

llvm-svn: 335651
2018-06-26 19:38:18 +00:00
Fangrui Song 4ff63648ad [ELF][X86_64] Use R_GOTREL_FROM_END instead of R_GOTREL for R_X86_64_GOTOFF64
Summary:
R_X86_64_GOTOFF64: S + A - GOT
R_X86_64_GOTPC{32,64}: GOT + A - P (R_GOTONLY_PC_FROM_END)

R_X86_64_GOTOFF64 should use R_GOTREL_FROM_END so that in conjunction with
R_X86_64_GOTPC{32,64}, the `GOT` term is neutralized. This also matches
the handling of R_386_GOTOFF (S + A - GOT).

Reviewers: ruiu, espindola

Subscribers: emaste, arichardson, llvm-commits

Differential Revision: https://reviews.llvm.org/D48095

llvm-svn: 334672
2018-06-13 23:29:28 +00:00
Rui Ueyama 1ebde333e8 Remove needless bitwise-AND.
Because applyMask ignores upper bits, we don't need to mask them.

llvm-svn: 334647
2018-06-13 19:58:33 +00:00
Rui Ueyama 3cc4a0825b Make a function non-member because it doesn't depend on any class.
llvm-svn: 334646
2018-06-13 19:50:10 +00:00
Rui Ueyama 803ffdbc7b Apply clang-format.
llvm-svn: 334645
2018-06-13 19:49:58 +00:00
Sid Manning 95b0c2e1e3 Add Hexagon Support
Differential Revision: https://reviews.llvm.org/D47791

llvm-svn: 334637
2018-06-13 18:45:25 +00:00
Rui Ueyama 92b931d519 Use shorter names for #lo, #hi, #ha, etc. NFC.
Since these functions are file-local, the new names shouldn't be ambiguous.

Differential Revision: https://reviews.llvm.org/D48093

llvm-svn: 334564
2018-06-13 00:50:17 +00:00
Rui Ueyama 864289990a Handle R_X86_64_GOTOFF64.
R_X86_64_GOTOFF64 is a relocation type to set to a distance betwween
a symbol and the beginning of the .got section. Previously, we always
created a dynamic relocation for the relocation type even though it
can be resolved at link-time.

Creating a dynamic relocation for R_X86_64_GOTOFF64 caused link failure
for some programs that do have a relocation of the type in a .text
section, as text relocations are prohibited in most configurations.

Differential Revision: https://reviews.llvm.org/D48058

llvm-svn: 334534
2018-06-12 20:27:16 +00:00
Fangrui Song 3773c196fc [ELF][PPC64] Support R_PPC64_DTPREL64 which may be emitted in .rela.debug_addr
llvm-svn: 334533
2018-06-12 20:26:49 +00:00
Fangrui Song aa473c5387 [ELF] Support R_X86_64_GOTPC{32,64}
Reviewers: ruiu, grimar, espindola

Subscribers: emaste, arichardson, llvm-commits

Differential Revision: https://reviews.llvm.org/D47098

llvm-svn: 334532
2018-06-12 20:18:41 +00:00
Sean Fertile e6b2e06f28 [PPC64] Support R_PPC64_DTPREL relocations.
Patch adds support for most of the dynamic thread pointer based relocations
for local-dynamic tls. The HIGH and HIGHA versions are missing becuase they
are not supported by the llvm integrated assembler yet.

llvm-svn: 334465
2018-06-12 01:47:02 +00:00
Konstantin Zhuravlyov d70c367267 AMDGPU/LLD: Handle R_AMDGPU_REL64 relocation
Requires r334443 from llvm

Differential Revision: https://reviews.llvm.org/D47734

llvm-svn: 334444
2018-06-11 21:42:53 +00:00
Zaara Syeda 4455b37666 [PPC64] Add support for local-exec TLS model
This patch adds the relocations needed support the local-exec TLS model:

R_PPC64_TPREL16
R_PPC64_TPREL16_HA
R_PPC64_TPREL16_LO
R_PPC64_TPREL16_HI
R_PPC64_TPREL16_DS
R_PPC64_TPREL16_LO_DS
R_PPC64_TPREL16_HIGHER
R_PPC64_TPREL16_HIGHERA
R_PPC64_TPREL16_HIGHEST
R_PPC64_TPREL16_HIGHESTA

Differential Revision: https://reviews.llvm.org/D47598

llvm-svn: 334304
2018-06-08 17:04:09 +00:00
Zaara Syeda e4da09f920 [PPC64] Add support for initial-exec TLS model
This patch adds the relocations needed support the initial-exec TLS model:
R_PPC64_GOT_TPREL16_HA
R_PPC64_GOT_TPREL16_LO_DS
R_PPC64_GOT_TPREL16_DS
R_PPC64_GOT_TPREL16_HI
R_PPC64_TLS

Differential Revision: https://reviews.llvm.org/D47455

llvm-svn: 333769
2018-06-01 15:20:56 +00:00
Sean Fertile 1a8343fce3 [PPC64] Support R_PPC64_GOT_TLSLD16 relocations.
Add support for the R_PPC64_GOT_TLSLD16 relocations used to build the address of
the tls_index struct used in local-dynamic tls.

Differential Revision: https://reviews.llvm.org/D47538

llvm-svn: 333681
2018-05-31 18:44:12 +00:00
Sean Fertile fb613e552a Rename R_TLSGD/R_TLSLD to add _GOT_FROM_END. NFC.
getRelocTargetVA for R_TLSGD and R_TLSLD RelExprs calculate an offset from the
end of the got, so adjust the names to reflect this.

Differential Revision: https://reviews.llvm.org/D47379

llvm-svn: 333674
2018-05-31 18:07:06 +00:00
Sean Fertile ef0f7496d1 [PPC64] Support General-Dynamic tls.
Adds handling of all the relocation types for general-dynamic thread local
storage.

Differential Revision: https://reviews.llvm.org/D47325

llvm-svn: 333420
2018-05-29 14:34:38 +00:00
Rui Ueyama 1fa3c728b9 Fix retpoline PLT for x86-64 when used for >4GB address.
Previously, we wrote only the least significant 32 bits.

llvm-svn: 333313
2018-05-25 21:14:45 +00:00