[Bug c/60084] New: GCC 4.8.3 miscompiles code on ARM at -Os optimization level

2014-02-05 Thread florin.iu...@hill-rom.com
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: florin.iu...@hill-rom.com

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)
{

intindex;

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:

 <__copy_rom_sections_to_ram>:
   0:b510  push{r4, lr}
   2:4c0a  ldrr4, [pc, #40]; (2c
<__copy_rom_sections_to_ram+0x2c>)
   4:b18c  cbzr4, 2a <__copy_rom_sections_to_ram+0x2a>
   6:3408  addsr4, #8
   8:f854 1c08 ldr.wr1, [r4, #-8]
   c:b131  cbzr1, 1c <__copy_rom_sections_to_ram+0x1c>
   e:f854 0c04 ldr.wr0, [r4, #-4]
  12:f854 2b0c ldr.wr2, [r4], #12
  16:f7ff fffe bl0 <__copy_rom_sections_to_ram>
  1a:e7f5  b.n8 <__copy_rom_sections_to_ram+0x8>
  1c:f854 3c04 ldr.wr3, [r4, #-4]
  20:2b00  cmpr3, #0
  22:d1f4  bne.ne <__copy_rom_sections_to_ram+0xe>
  24:6820  ldrr0, [r4, #0]
  26:2800  cmpr0, #0
  28:d1f1  bne.ne <__copy_rom_sections_to_ram+0xe>
  2a:bd10  pop{r4, pc}
  2c: .word0x

-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:

 <__copy_rom_sections_to_ram>:
   0:b508  push{r3, lr}
   2:4b07  ldrr3, [pc, #28]; (20
<__copy_rom_sections_to_ram+0x20>)
   4:b15b  cbzr3, 1e <__copy_rom_sections_to_ram+0x1e>
   6:6819  ldrr1, [r3, #0]
   8:b119  cbzr1, 12 <__copy_rom_sections_to_ram+0x12>
   a:6858  ldrr0, [r3, #4]
   c:689a  ldrr2, [r3, #8]
   e:f7ff fffe bl0 <__copy_rom_sections_to_ram>
  12:685a  ldrr2, [r3, #4]
  14:2a00  cmpr2, #0
  16:d1f8  bne.na <__copy_rom_sections_to_ram+0xa>
  18:689a  ldrr2, [r3, #8]
  1a:2a00  cmpr2, #0
  1c:d1f5  bne.na <__copy_rom_sections_to_ram+0xa>
  1e:bd08  pop{r3, pc}
  20: .word0x


[Bug c/60084] GCC 4.8.3 miscompiles code on ARM at -Os optimization level

2014-02-05 Thread florin.iu...@hill-rom.com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60084

--- Comment #1 from Florin Iucha  ---
Created attachment 32057
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32057&action=edit
objdump of binary built with gcc-4.7.3


[Bug c/60084] GCC 4.8.3 miscompiles code on ARM at -Os optimization level

2014-02-05 Thread florin.iu...@hill-rom.com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60084

--- Comment #2 from Florin Iucha  ---
Created attachment 32058
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32058&action=edit
objdump of binary built with gcc-4.8.3


[Bug target/60084] GCC 4.8.3 miscompiles code on ARM at -Os optimization level

2014-02-05 Thread florin.iu...@hill-rom.com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60084

--- Comment #3 from Florin Iucha  ---
gcc version 4.7.4 20130913 (release) [ARM/embedded-4_7-branch revision 202601]
(GNU Tools for ARM Embedded Processors) generates the same code as 4.7.3


[Bug target/60084] GCC 4.8.3 miscompiles code on ARM at -Os optimization level

2014-02-05 Thread florin.iu...@hill-rom.com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60084

--- Comment #5 from Florin Iucha  ---
Created attachment 32059
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32059&action=edit
Preprocessed source file (both 4.7.4 and 4.8.3 produce the same .i file)


[Bug target/60084] GCC 4.8.3 miscompiles code on ARM at -Os optimization level

2014-02-05 Thread florin.iu...@hill-rom.com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60084

--- Comment #6 from Florin Iucha  ---
Andrew,

Is that a general comment regarding Linaro GCC build, or do you have more
specific information about some of their changes that might have an impact on
compiling the source code I am referencing in this bug report?

Thanks,
florin


[Bug target/60084] GCC 4.8.3 miscompiles code on ARM at -Os optimization level

2014-02-05 Thread florin.iu...@hill-rom.com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60084

--- Comment #8 from Florin Iucha  ---
Andrew,

You are correct! Sorry, I have missed the lack of 'extern'. I noticed the
warning, but did not heed it ;(

florin