Change of PIC addressing when using -flto with -fPIC

Bug #1777775 reported by Gregor Bader
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
New
Undecided
Unassigned

Bug Description

When using "-fPIC -msingle-pic-base" the data is addressed relative to R9 as expected. But when adding "-flto" compile switch, the addressing changes to PC-relative which leads to runtime problems!

Toolchain: 7-2017-q4-major

Source:

int i;

int main(void)
{
  i = 321;
  return(0);
}

Result compiled with "arm-none-eabi-gcc -mthumb -mcpu=cortex-m3 --specs=nosys.specs --specs=nano.specs -g -std=c99 -fPIC -msingle-pic-base -ffunction-sections -fdata-sections test_flto_fPIC.c -o test_flto_fPIC.elf"

000080e8 <main>:
    80e8: b480 push {r7}
    80ea: af00 add r7, sp, #0
    80ec: 4b05 ldr r3, [pc, #20] ; (8104 <main+0x1c>)
    80ee: f859 3003 ldr.w r3, [r9, r3]
    80f2: 461a mov r2, r3
    80f4: f240 1341 movw r3, #321 ; 0x141
    80f8: 6013 str r3, [r2, #0]
    80fa: 2300 movs r3, #0
    80fc: 4618 mov r0, r3
    80fe: 46bd mov sp, r7
    8100: bc80 pop {r7}
    8102: 4770 bx lr
    8104: 0000000c .word 0x0000000c

Result compiled with "arm-none-eabi-gcc -mthumb -mcpu=cortex-m3 --specs=nosys.specs --specs=nano.specs -g -std=c99 -fPIC -msingle-pic-base -flto -ffunction-sections -fdata-sections test_flto_fPIC.c -o test_flto_fPIC.elf"

000080e8 <main>:
    80e8: b480 push {r7}
    80ea: af00 add r7, sp, #0
    80ec: 4b05 ldr r3, [pc, #20] ; (8104 <main+0x1c>)
    80ee: 447b add r3, pc
    80f0: 461a mov r2, r3
    80f2: f240 1341 movw r3, #321 ; 0x141
    80f6: 6013 str r3, [r2, #0]
    80f8: 2300 movs r3, #0
    80fa: 4618 mov r0, r3
    80fc: 46bd mov sp, r7
    80fe: bc80 pop {r7}
    8100: 4770 bx lr
    8102: bf00 nop
    8104: 0001011a .word 0x0001011a

Tags: lto pic
Revision history for this message
Gregor Bader (gregorbader) wrote :
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.