The R_ARM_ALU_PC_G0 and R_ARM_LDR_PC_G0 relocations are used by the ADR and LDR pseudo instructions, and are the basis of the group relocations that can load an arbitrary constant via a series of add, sub and ldr instructions. The relocations need to be obtained via the .reloc directive. R_ARM_ALU_PC_G0 is much more complicated as the add/sub instruction uses a modified immediate encoding of an 8-bit immediate rotated right by an even 4-bit field. This means that the range of representable immediates is sparse. We extract the encoding and decoding functions for the modified immediate from llvm/lib/Target/ARM/MCTargetDesc/ARMAddressingModes.h as this header file is not accessible from LLD. Duplication of code isn't ideal, but as these are well-defined mathematical functions they are unlikely to change. Differential Revision: https://reviews.llvm.org/D75349
30 lines
730 B
ArmAsm
30 lines
730 B
ArmAsm
// REQUIRES: arm
|
|
// RUN: llvm-mc --triple=armv7a-none-eabi --arm-add-build-attributes -filetype=obj -o %t.o %s
|
|
// RUN: not ld.lld -n %t.o -o %t 2>&1 | FileCheck %s
|
|
.section .text.0, "ax", %progbits
|
|
.thumb_func
|
|
.balign 4
|
|
low:
|
|
bx lr
|
|
nop
|
|
nop
|
|
|
|
.section .text.1, "ax", %progbits
|
|
.global _start
|
|
.arm
|
|
_start:
|
|
// CHECK: {{.*}}.s.tmp.o:(.text.1+0x0): relocation R_ARM_LDR_PC_G0 out of range: 4096 is not in [0, 4095]
|
|
/// ldr r0, low - 4076
|
|
.inst 0xe51f0ff4
|
|
.reloc 0, R_ARM_LDR_PC_G0, low
|
|
// CHECK: {{.*}}.s.tmp.o:(.text.1+0x4): relocation R_ARM_LDR_PC_G0 out of range: 4096 is not in [0, 4095]
|
|
/// ldr r0, high + 4100
|
|
.inst 0xe59f0ffc
|
|
.reloc 4, R_ARM_LDR_PC_G0, high
|
|
|
|
.section .text.2
|
|
.thumb_func
|
|
.balign 4
|
|
high:
|
|
bx lr
|