rust-lang / rust-lang/rust

arm: Using `ldrd` with `static` symbol in `asm` returns "unsupported relocation type".

Open
#146,061 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-codegen A-inline-assembly A-LLVM C-bug O-Arm T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried to build this code (reduced example from trying to inline p256-cortex-m):

#![no_std]

#[unsafe(no_mangle)]
static TEST: [u32; 9] = [0; _];

#[unsafe(no_mangle)]
pub unsafe extern "C" fn test() {
    unsafe {
        core::arch::asm!(
            "
                ldrd r0, r1, {TEST}
                bx lr
            ",
        TEST = sym TEST)
    }
}

in a new library project, using cargo build --release --target thumbv7em-none-eabi.

Compiling this with rustc --target thumbv7em-none-eabi --crate-type lib lib.rs where lib.rs contains the code above also causes this error.

I expected to see this happen: this would compile & build correctly.

Instead, this happened: the compiler errors out, reporting "unsuppored relocation type".

   Compiling repro-th-none v0.1.0 (/home/jona/projects/repro-th-none)
error: unsupported relocation type
  --> src/lib.rs:11:17
   |
11 |                 ldrd r0, r1, {TEST}
   |                 ^^^^^^^^^^^^^^^^^^^
   |
note: instantiated into assembly here
  --> <inline asm>:2:17
   |
2  |                 ldrd r0, r1, TEST
   |                 ^

error: could not compile `repro-th-none` (lib) due to 1 previous error

Using ldrd r0, r1, [r2] (which is a little silly, but should be correct) instead makes building succeed.

From what I can tell, the problem is that the TEST value used in the ldrd instruction gets a relocation type of R_ARM_NONE (see disassembly below), which doesn't seem to be supported by LLVM or some other part of the linker infrastructure.

Disassembly of the generated rcgu.o file.
Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000000  00000000  00000000  00000034  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .text.test    0000000c  00000000  00000000  00000034  2**1
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
  2 .ARM.exidx.text.test 00000008  00000000  00000000  00000040  2**2
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
  3 .rodata.TEST  00000024  00000000  00000000  00000048  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  4 .comment      0000002d  00000000  00000000  0000006c  2**0
                  CONTENTS, READONLY
  5 .note.GNU-stack 00000000  00000000  00000000  00000099  2**0
                  CONTENTS, READONLY
  6 .ARM.attributes 00000032  00000000  00000000  00000099  2**0
                  CONTENTS, READONLY
SYMBOL TABLE:
00000000 l    df *ABS*  00000000 repro_th_none.94ea4bc958c41543-cgu.0
00000000 l    d  .text.test     00000000 .text.test
00000000 g     F .text.test     0000000c test
00000000 g     O .rodata.TEST   00000024 TEST



Disassembly of section .text.test:

00000000 <test>:
   0:   b580            push    {r7, lr}
   2:   466f            mov     r7, sp
   4:   e95f 0101       ldrd    r0, r1, [pc, #-4]       ; 0 <test>
                        4: R_ARM_NONE   TEST
   8:   4770            bx      lr
   a:   bd80            pop     {r7, pc}

Perhaps this is an issue for LLVM instead, or someplace else, but I'm not sure so am starting here :)

Meta

rustc --version --verbose:

rustc 1.89.0 (29483883e 2025-08-04)
binary: rustc
commit-hash: 29483883eed69d5fb4db01964cdf2af4d86e9cb2
commit-date: 2025-08-04
host: x86_64-unknown-linux-gnu
release: 1.89.0
LLVM version: 20.1.7

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example in lib.rs with rustc --target thumbv7em-none-eabi and inspect the generated rcgu.o relocation shown in the report. Compare the failing ldrd r0, r1, {TEST} form with the successful [r2] form; done means the reduced library builds without the unsupported relocation error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.