[llvm] [llvm][MC][ARM][Assembly] Emit relocs for LDRs (PR #72873)

Eleanor Bonnnici via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 21 09:57:35 PST 2023


================
@@ -0,0 +1,41 @@
+@ RUN: llvm-mc -filetype=obj -triple=armv7 %s -o %t
+@ RUN: llvm-readelf -r %t | FileCheck %s --check-prefix=ARM
+@ RUN: llvm-objdump -d --triple=armv7 %t | FileCheck %s --check-prefix=ARM_ADDEND
+
+@ ARM: R_ARM_LDRS_PC_G0
+@ ARM: foo1
+@ ARM: R_ARM_LDRS_PC_G0
+@ ARM: foo2
+@ ARM: R_ARM_LDRS_PC_G0
+@ ARM: foo3
+
+// The value format is decimal in these specific cases, but it's hex for other
+// ldr instructions. These checks are valid for both formats.
+
+@ ARM_ADDEND: r0, [pc, #-
----------------
eleanor-arm wrote:

The -8 is the addend for arm pcrel instructions because of the PC offset. Technically the default offset (=the immediate value in the instruction before the relocation is applied) should be 0 to indicate the current PC, but the PC is 2 instructions behind for historical reasons. So for Thumb the added is -4. It's mentioned it in the ABI -[ ](https://github.com/ARM-software/abi-aa/blob/main/aaelf32/aaelf32.rst#addends-and-pc-bias-compensation)

We can't see the final value here because the relocation resolution is a linker's job and the linker is not run. 

https://github.com/llvm/llvm-project/pull/72873


More information about the llvm-commits mailing list