https://sourceware.org/bugzilla/show_bug.cgi?id=33386

            Bug ID: 33386
           Summary: ARM/Thumb PIE link corrupts first instruction in
                    `.text`
           Product: binutils
           Version: 2.43.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: petr at cerninovi dot cz
  Target Milestone: ---

Created attachment 16315
  --> https://sourceware.org/bugzilla/attachment.cgi?id=16315&action=edit
source code, linker script, build script

When linking a minimal Thumb function as PIE for Cortex-M33, the first
instruction of the first function in `.text` is corrupted in the linked ELF:
the low byte becomes `0x00`. 

Object code is correct; corruption appears at link stage with `-pie`. Removing
`-pie` avoids the corruption.

Toolchain: Arm GNU Toolchain 14.2.Rel1 (Build arm-14.52) 2.43.1.20241119
Target: `arm-none-eabi` (Cortex-M33, Thumb)
Host OS: Linux

-------------------------------------------------------------------
Source code (main.c):

int answer_for_everything(void) {
    return 42;
}

-------------------------------------------------------------------
Build commands:

arm-none-eabi-gcc -mcpu=cortex-m33 -mthumb -Os -fpie main.c -o main.o
arm-none-eabi-ld -T linker.ld -pie main.o -o main.elf

-------------------------------------------------------------------
Object file (correct):

00000000 <answer_for_everything>:
   0: 202a       movs r0, #42
   2: 4770       bx   lr

-------------------------------------------------------------------
Linked ELF with `-pie` (corrupted):

00000000 <answer_for_everything>:
   0: 2000       movs r0, #0   <-- low byte became 0x00
   2: 4770       bx   lr

The problem consistently affects the first instruction at `.text + 0` (the very
first byte in the first PT_LOAD RX segment).

I've attached a complete example showing how to reproduce the bug.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Reply via email to