[PATCH] D75039: [MC][ELF][ARM] Add relocations for Thumb pc-relative fixups
Peter Smith via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 24 04:51:24 PST 2020
psmith created this revision.
psmith added reviewers: MaskRay, ostannard, eli.friedman.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: LLVM.
Add ELF relocations for the following Thumb fixups:
- fixup_thumb_adr_pcrel_10 -> R_ARM_THM_PC8
- fixup_thumb_cp -> R_ARM_THM_PC8
- fixup_t2_ldst_pcrel_12 -> R_ARM_THM_PC12
While these relocations are short-ranged there is support in the open source ELF linker's in binutils and soon to be in LLD. MC (D72197 <https://reviews.llvm.org/D72197>) will no longer resolve pc-relative fixups to global symbols due to interpositioning concerns, which results in an error message. I have a patch implementing these three relocations in LLD ready to submit.
TODO: Connect up the ARM state relocations for the pc-relative adr and ldr fixups. These will come in a follow-up patch when I have LLD support ready.
Part of the long term fix for pr44929 https://bugs.llvm.org/show_bug.cgi?id=44929
https://reviews.llvm.org/D75039
Files:
llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
llvm/test/MC/ARM/thumb1-relax-adr.s
llvm/test/MC/ARM/thumb1-relax-ldrlit.s
Index: llvm/test/MC/ARM/thumb1-relax-ldrlit.s
===================================================================
--- llvm/test/MC/ARM/thumb1-relax-ldrlit.s
+++ llvm/test/MC/ARM/thumb1-relax-ldrlit.s
@@ -1,9 +1,11 @@
@ RUN: not llvm-mc -triple thumbv6m-none-macho -filetype=obj -o /dev/null %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s
@ RUN: not llvm-mc -triple thumbv7m-none-macho -filetype=obj -o /dev/null %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s
-@ RUN: not llvm-mc -triple thumbv7m-none-eabi -filetype=obj -o /dev/null %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s
+@ RUN: llvm-mc -triple thumbv6m-none-eabi -filetype=obj %s -o - | llvm-readobj --relocs | FileCheck --check-prefix=CHECK-ELF-T1 %s
+@ RUN: llvm-mc -triple thumbv7m-none-eabi -filetype=obj %s -o - | llvm-readobj --relocs | FileCheck --check-prefix=CHECK-ELF-T2 %s
.global func1
_func1:
ldr r0, _func2
@ CHECK-ERROR: unsupported relocation on symbol
-
+@ CHECK-ELF-T1: 0x0 R_ARM_THM_PC8 _func2 0x0
+@ CHECK-ELF-T2: 0x0 R_ARM_THM_PC12 _func2 0x0
Index: llvm/test/MC/ARM/thumb1-relax-adr.s
===================================================================
--- llvm/test/MC/ARM/thumb1-relax-adr.s
+++ llvm/test/MC/ARM/thumb1-relax-adr.s
@@ -1,9 +1,9 @@
@ RUN: not llvm-mc -triple thumbv6m-none-macho -filetype=obj -o /dev/null %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s
@ RUN: not llvm-mc -triple thumbv7m-none-macho -filetype=obj -o /dev/null %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s
-@ RUN: not llvm-mc -triple thumbv7m-none-eabi -filetype=obj -o /dev/null %s 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s
+@ RUN: llvm-mc -triple thumbv7m-none-eabi -filetype=obj %s -o - | llvm-readobj --relocs | FileCheck --check-prefix=CHECK-ELF %s
.global func1
_func1:
adr r0, _func2
@ CHECK-ERROR: unsupported relocation on symbol
-
+@ CHECK-ELF: 0x0 R_ARM_THM_ALU_PREL_11_0 _func2 0x0
Index: llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
===================================================================
--- llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
+++ llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
@@ -137,6 +137,13 @@
default:
return ELF::R_ARM_THM_CALL;
}
+ case ARM::fixup_thumb_adr_pcrel_10:
+ case ARM::fixup_arm_thumb_cp:
+ return ELF::R_ARM_THM_PC8;
+ case ARM::fixup_t2_adr_pcrel_12:
+ return ELF::R_ARM_THM_ALU_PREL_11_0;
+ case ARM::fixup_t2_ldst_pcrel_12:
+ return ELF::R_ARM_THM_PC12;
case ARM::fixup_bf_target:
return ELF::R_ARM_THM_BF16;
case ARM::fixup_bfc_target:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75039.246178.patch
Type: text/x-patch
Size: 2630 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200224/01bef745/attachment.bin>
More information about the llvm-commits
mailing list