http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60084
Bug ID: 60084
Summary: GCC 4.8.3 miscompiles code on ARM at -Os optimization
level
Product: gcc
Version: 4.8.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: [email protected]
Using GCC built by Linaro.
Source code (ROMCopy.c from CodeWarrior 10.5)
CW-MCU-v10.5\MCU\ARM_GCC_Support\ewl\EWL_Runtime\include\arm\ROMCopy.c
-8< ---8< ---8< ---8< ---8< ---8< ---8< ---8< --
RomInfo __S_romp[] __attribute__((weak)); /* linker defined symbol */
void __copy_rom_sections_to_ram(void)
{
int index;
if (__S_romp == 0L) return;
/*
* Go through the entire table, copying sections from ROM to RAM.
*/
for (index = 0;
__S_romp[index].Source != 0 ||
__S_romp[index].Target != 0 ||
__S_romp[index].Size != 0;
++index)
{
__copy_rom_section( __S_romp[index].Target,
__S_romp[index].Source,
__S_romp[index].Size );
__flush_cache( __S_romp[index].Target, __S_romp[index].Size);
}
}
-8< ---8< ---8< ---8< ---8< ---8< ---8< ---8< --
Compiled with 4.7_2013q1
gcc version 4.7.3 20130312 (release) [ARM/embedded-4_7-branch revision
196615] (GNU Tools for ARM Embedded Processors)
Command line
arm-none-eabi-gcc -std=c11 -g -Wall -Wextra -Os -flto -ffunction-sections
-fdata-sections -fno-builtin -fomit-frame-pointer -mthumb -mcpu=cortex-m4
-mfpu=fpv4-sp-d16 -mfloat-abi=softfp -DMK60N512VMD100 -D__thumb -I.
-IGenerated_Code -ISources -Istartup
-I..\\..\\vendors\\Freescale\\1.0.0\\Kinetis\\pdd\\inc
-DUNALIGNED_SUPPORT_DISABLE -mno-unaligned-access -c -o obj.gcc/ROMCopy.o
./startup/ROMCopy.c
Produces:
Disassembly of section .text.__copy_rom_sections_to_ram:
00000000 <__copy_rom_sections_to_ram>:
0: b510 push {r4, lr}
2: 4c0a ldr r4, [pc, #40] ; (2c
<__copy_rom_sections_to_ram+0x2c>)
4: b18c cbz r4, 2a <__copy_rom_sections_to_ram+0x2a>
6: 3408 adds r4, #8
8: f854 1c08 ldr.w r1, [r4, #-8]
c: b131 cbz r1, 1c <__copy_rom_sections_to_ram+0x1c>
e: f854 0c04 ldr.w r0, [r4, #-4]
12: f854 2b0c ldr.w r2, [r4], #12
16: f7ff fffe bl 0 <__copy_rom_sections_to_ram>
1a: e7f5 b.n 8 <__copy_rom_sections_to_ram+0x8>
1c: f854 3c04 ldr.w r3, [r4, #-4]
20: 2b00 cmp r3, #0
22: d1f4 bne.n e <__copy_rom_sections_to_ram+0xe>
24: 6820 ldr r0, [r4, #0]
26: 2800 cmp r0, #0
28: d1f1 bne.n e <__copy_rom_sections_to_ram+0xe>
2a: bd10 pop {r4, pc}
2c: 00000000 .word 0x00000000
-8< ---8< ---8< ---8< ---8< ---8< ---8< ---8< --
Compiled with 4.8_2013q4
gcc version 4.8.3 20131129 (release) [ARM/embedded-4_8-branch revision
205641] (GNU Tools for ARM Embedded Processors)
Command line
arm-none-eabi-gcc -std=c11 -g -Wall -Wextra -Os -flto -ffunction-sections
-fdata-sections -fno-builtin -fomit-frame-pointer -mthumb -mcpu=cortex-m4
-mfpu=fpv4-sp-d16 -mfloat-abi=softfp -DMK60N512VMD100 -D__thumb -I.
-IGenerated_Code -ISources -Istartup
-I..\\..\\vendors\\Freescale\\1.0.0\\Kinetis\\pdd\\inc
-DUNALIGNED_SUPPORT_DISABLE -mno-unaligned-access -c -o obj.gcc/ROMCopy.o
./startup/ROMCopy.c
Produces:
00000000 <__copy_rom_sections_to_ram>:
0: b508 push {r3, lr}
2: 4b07 ldr r3, [pc, #28] ; (20
<__copy_rom_sections_to_ram+0x20>)
4: b15b cbz r3, 1e <__copy_rom_sections_to_ram+0x1e>
6: 6819 ldr r1, [r3, #0]
8: b119 cbz r1, 12 <__copy_rom_sections_to_ram+0x12>
a: 6858 ldr r0, [r3, #4]
c: 689a ldr r2, [r3, #8]
e: f7ff fffe bl 0 <__copy_rom_sections_to_ram>
12: 685a ldr r2, [r3, #4]
14: 2a00 cmp r2, #0
16: d1f8 bne.n a <__copy_rom_sections_to_ram+0xa>
18: 689a ldr r2, [r3, #8]
1a: 2a00 cmp r2, #0
1c: d1f5 bne.n a <__copy_rom_sections_to_ram+0xa>
1e: bd08 pop {r3, pc}
20: 00000000 .word 0x00000000