Actions

icon Post
text/html Subscribe
text/html Unsubscribe

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[arm-gcc] arm-2008q1-126 gcc creates broken code with -Os


  • To: arm-gcc@xxxxxxxxxxxxxxxx
  • Subject: [arm-gcc] arm-2008q1-126 gcc creates broken code with -Os
  • From: "Matthias Welwarsky" <mwelwarsky@xxxxxxxxxxxxxx>
  • Date: Mon, 23 Jun 2008 10:27:20 +0200

Hello,

the arm-2008q1-126 gcc apparently has an optimizer bug when -Os is used. For
example, take a look at the following objdump output of some portion of gdb
(sources also from the arm-2008q1-126 release):

gdb-2008q1-126-target/bfd/elf.c:

compiled with -Os

00009c80 <bfd_section_from_shdr>:

/* Create a new bfd section from an ELF section header.  */

bfd_boolean
bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
{
    9c80:    e92d47f3     push    {r0, r1, r4, r5, r6, r7, r8, r9, sl, lr}
[removed some code here]
        /* Otherwise it should be processed.  */
        return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex);
    a66c:    e1a00007     mov    r0, r7
    a670:    e1a01006     mov    r1, r6
    a674:    e1a02005     mov    r2, r5
    a678:    e1a03008     mov    r3, r8

      return FALSE;
    }

  return TRUE;
}
    a67c:    e8bd47fc     pop    {r2, r3, r4, r5, r6, r7, r8, r9, sl, lr}
          (_("%B: don't know how to handle OS specific section "
         "`%s' [0x%8x]"),
           abfd, name, hdr->sh_type);
      else
        /* Otherwise it should be processed.  */
        return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex);
    a680:    eafffffe     b    9510 <_bfd_elf_make_section_from_shdr>
    }


If you look at the asm starting at 0xa66c, you see it preparing the function
arguments for calling _bfd_elf_make_section_from_shdr() at 0xa680. But
immediately afterwards at 0xa67c it clobbers r2 and r3 again by restoring
the registers saved on entry of bfd_section_from_shdr() (0x9c80).
Effectively, the original r0 (*abfd) and r1 (shindex) are now in r2,r3. This
is correct for r3 (shindex), but r2 now contains *abfd instead of name,
which is not correct.

The same code section compiled with -O2 is correct:

bfd_boolean
bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
{
    a9b4:    e92d4ff0     push    {r4, r5, r6, r7, r8, r9, sl, fp, lr}
    a9b8:    e59040b8     ldr    r4, [r0, #184]
    a9bc:    e24dd00c     sub    sp, sp, #12    ; 0xc
...
        return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex);
    acb4:    e1a00007     mov    r0, r7
    acb8:    e1a01006     mov    r1, r6
    acbc:    e1a02009     mov    r2, r9
    acc0:    e1a03008     mov    r3, r8

      return FALSE;
    }

  return TRUE;
}
    acc4:    e28dd00c     add    sp, sp, #12    ; 0xc
    acc8:    e8bd4ff0     pop    {r4, r5, r6, r7, r8, r9, sl, fp, lr}
          (_("%B: don't know how to handle OS specific section "
         "`%s' [0x%8x]"),
           abfd, name, hdr->sh_type);
      else
        /* Otherwise it should be processed.  */
        return _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex);
    accc:    eafffffe     b    a210 <_bfd_elf_make_section_from_shdr>
      {

Is there any patch available to fix this problem?

kind regards,
matthias