Unsupported SBREL32 relocation

Bug #1693289 reported by Amit Levy
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
Confirmed
Undecided
Unassigned

Bug Description

I'm compiling bare-metal relocatable binaries for Thumb using
the RWPI relocation model from LLVM (which is used by Rust in my case).

However, I'm unable to link this code since arm-none-eabi-ld is missing support for the ARM relocation type R_ARM_SBREL32 (relocation
type 9 in
http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044f/IHI0044F_aaelf.pdf)
which is emitted by LLVM for the RWPI relocation model.

Below is a simple assembly regressions, which tries to dereference a global called `foo` in the `_start` procedure, using the SBREL_32 relocation:

 .text
 .syntax unified
 .eabi_attribute 67, "2.09" @ Tag_conformance
 .cpu arm7tdmi
 .eabi_attribute 6, 2 @ Tag_CPU_arch
 .eabi_attribute 8, 1 @ Tag_ARM_ISA_use
 .eabi_attribute 15, 2 @ Tag_ABI_PCS_RW_data
 .eabi_attribute 16, 1 @ Tag_ABI_PCS_RO_data
 .eabi_attribute 17, 1 @ Tag_ABI_PCS_GOT_use
 .eabi_attribute 20, 1 @ Tag_ABI_FP_denormal
 .eabi_attribute 21, 1 @ Tag_ABI_FP_exceptions
 .eabi_attribute 23, 3 @ Tag_ABI_FP_number_model
 .eabi_attribute 34, 0 @ Tag_CPU_unaligned_access
 .eabi_attribute 24, 1 @ Tag_ABI_align_needed
 .eabi_attribute 25, 1 @ Tag_ABI_align_preserved
 .eabi_attribute 38, 1 @ Tag_ABI_FP_16bit_format
 .eabi_attribute 18, 4 @ Tag_ABI_PCS_wchar_t
 .eabi_attribute 26, 2 @ Tag_ABI_enum_size
 .eabi_attribute 14, 1 @ Tag_ABI_PCS_R9_use
 .file "test.c"
 .globl _start
 .p2align 2
 .type _start,%function
 .code 32 @ @_start
_start:
 .fnstart
@ BB#0:
 ldr r0, .LCPI0_0
 mov r1, r9
 ldr r0, [r1, r0]
 bx lr
 .p2align 2
@ BB#4:
.LCPI0_0:
 .long foo(sbrel)

Assembling this file works fine:

$ arm-none-eabi-as -o foo.o foo.s

But linking fails due to an "unsupported relocation":

$ arm-none-eabi-ld -o foo foo.o
foo.o: In function `_start':
test.c:(.text+0x10): undefined reference to `foo'
test.c:(.text+0x10): dangerous relocation: unsupported relocation

There _is_ support for this relocation in ARM's proprietary toolchain (which I believe is based on LLVM's LLD) and LLD now has support for it in tip: https://reviews.llvm.org/D33280

Changed in gcc-arm-embedded:
status: New → Confirmed
Revision history for this message
Amit Levy (aalevy) wrote :

For a complete example, compile with clang >= 4.0:

```
static volatile int foo = 0;

void _start() {
  while (foo != 1) {
    asm volatile ("nop");
  }
}
```

$ clang -fropi -frwpi --target=thumbv7-eabi -c -o test.o test.c
$ arm-none-eabi-ld test.o -o test
test.o: In function `_start':
test.c:(.text+0x28): dangerous relocation: unsupported relocation

I believe the fix would be somewhere in

static bfd_reloc_status_type elf32_arm_final_link_relocate

starting on line 9872 in `bfd/elf32-arm.c`

Amit Levy (aalevy)
information type: Public → Public Security
information type: Public Security → Public
Revision history for this message
Amit Levy (aalevy) wrote :

I would love to help get this fixed, but would appreciate any pointers in where to look. In principle the implementation should be reasonably straight forward, but I'm unfamiliar with the LD code-base...

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) wrote :

Hi Amit,

All the changes should be in bfd/elf32-arm.c, and in particular in elf32_arm_final_link_relocate (see the switch (r_type) blocks. I believe you'll also need to add an entry to elf32_arm_howto_table_1.

Best regards.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.