All of lore.kernel.org
 help / color / mirror / Atom feed
From: david.jander@protonic.nl (David Jander)
To: linux-arm-kernel@lists.infradead.org
Subject: GCC 4.6.x miscompiling arm-linux?
Date: Tue, 11 Sep 2012 09:54:27 +0200	[thread overview]
Message-ID: <20120911095427.763f8619@archvile> (raw)
In-Reply-To: <20120911092753.7b8315d4@archvile>


Hi all,

On Tue, 11 Sep 2012 09:27:53 +0200
David Jander <david.jander@protonic.nl> wrote:
> Hi Matt,
> 
> On Mon, 10 Sep 2012 18:11:19 +0100
> Matthew Leach <matthew@mattleach.net> wrote:
> > David Jander <david.jander@protonic.nl> writes:
> > > ...
> > > 	.text
> > > 	.align	2
> > > 	.global	flexcan_chip_start
> > > 	.type	flexcan_chip_start, %function
> > > flexcan_chip_start:
> > > 	@ args = 0, pretend = 0, frame = 0
> > > 	@ frame_needed = 0, uses_anonymous_args = 0
> > > 	@ link register save eliminated.
> > > 	mov	r3, #0
> > > 	cmp	r0, #9
> > > 	str	r3, [r1, #0]
> > > 	ldrle	r3, [r1, #4]
> > > 	mov	r0, #0
> > > 	str	r3, [r1, #4]
> > > 	bx	lr
> > > 	.size	flexcan_chip_start, .-flexcan_chip_start
> > > 	.ident	"GCC: (OSELAS.Toolchain-2011.11.1) 4.6.2"
> > > 	.section	.note.GNU-stack,"",%progbits
> > >
> > 
> > This does indeed look wrong. I had a go at compile your code snippet the
> > following assembly was produced:
> > 
> >         .text
> >         .align  2
> >         .global flexcan_chip_start
> >         .type   flexcan_chip_start, %function
> > flexcan_chip_start:
> >         @ Function supports interworking.
> >         @ args = 0, pretend = 0, frame = 0
> >         @ frame_needed = 0, uses_anonymous_args = 0
> >         @ link register save eliminated.
> >         cmp     r0, #9
> >         mov     r3, #0
> >         str     r3, [r1, #0]
> >         mov     r0, #0
> >         strgt   r3, [r1, #4]
> >         bx      lr
> >         .size   flexcan_chip_start, .-flexcan_chip_start
> >         .ident  "GCC: (GNU) 4.3.3"
> >         .section        .note.GNU-stack,"",%progbits
> > 
> > I think this looks correct. Perhaps you could try the angstrom arm5te
> > toolchain and see if it's a toolchain issue?
> 
> Yes, this looks a lot better, and is exactly what I get when I compile this
> code with CodeSourcery GCC-4.4.1
> 
> I have tries building gcc-4.6.3 also with OSELAS/PTXdist, and it gives the
> same (wrong) result as with gcc-4.6.2
> 
> > I think this looks correct. Perhaps you could try the angstrom arm5te
> > toolchain and see if it's a toolchain issue?
> >
> > http://www.angstrom-distribution.org/toolchains/angstrom-2011.03-i686-linux-armv5te-linux-gnueabi-toolchain-qte-4.6.3.tar.bz2
> 
> This toolchain is a lot older:
> 
> $ ./usr/local/angstrom/arm/bin/arm-angstrom-linux-gnueabi-gcc --version
> arm-angstrom-linux-gnueabi-gcc (GCC) 4.3.3
> Copyright (C) 2008 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> 
> The tar-ball says 4.6.3, but that is probably the version number of the qte
> library, not that of gcc, which is 4.3.3, It does indeed produce
> the same (correct) output as in your case.
> 
> The newest angstrom (next) toolchain has gcc version 4.5.3, and it produces
> this (correct) output:
> 
> flexcan_chip_start:
>         @ Function supports interworking.
>         @ args = 0, pretend = 0, frame = 0
>         @ frame_needed = 0, uses_anonymous_args = 0
>         @ link register save eliminated.
>         mov     r3, #0
>         cmp     r0, #9
>         str     r3, [r1, #0]
>         mov     r0, #0
>         strgt   r3, [r1, #4]
>         bx      lr
>         .size   flexcan_chip_start, .-flexcan_chip_start
>         .ident  "GCC: (GNU) 4.5.3 20110311 (prerelease)"
>         .section        .note.GNU-stack,"",%progbits
> 
> Anyone knows where I can download a pre-built toolchain for 32-bit linux that
> is based on gcc-4.6 and/or gcc-4.7 to try out?
> 
> I have quite a hard time believing this issue is a yet unknown bug in GCC...
> I'd rather believe that I lack sufficient GCC knowledge to know how to
> correctly tell the compiler that this is a memory-IO operation. Anyone knows
> how to do this correctly? Or to explain why the output of gcc-4.6 looks less
> optimal than the output of older versions of GCC?

I finally found two linaro toolchains that I could download and try. The
results are rather interesting though:

1.- Ubuntu package gcc-4.6-arm-linux-gnueabi 4.6.3-1ubuntu5cross1.62:

flexcan_chip_start:
        .fnstart
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        mov     r3, #0
        cmp     r0, #9
        str     r3, [r1, #0]
        ldrle   r3, [r1, #4]
        mov     r0, #0
        str     r3, [r1, #4]
        bx      lr
        .fnend
        .size   flexcan_chip_start, .-flexcan_chip_start
        .ident  "GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3"
        .section        .note.GNU-stack,"",%progbits

Wrong code.

2. Linaro gcc-linaro-arm-linux-gnueabihf-2012.08-20120827_linux gcc 4.7.2:

flexcan_chip_start:
        .fnstart
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        cmp     r0, #9
        mov     r3, #0
        str     r3, [r1, #0]
        mov     r0, #0
        strgt   r3, [r1, #4]
        bx      lr
        .fnend
        .size   flexcan_chip_start, .-flexcan_chip_start
        .ident  "GCC: (crosstool-NG linaro-1.13.1-2012.08-20120827 - Linaro GCC 2012.08) 4.7.2 20120731 (prerelease)"
        .section        .note.GNU-stack,"",%progbits

This looks correct again! Could it be that all versions 4.6.x of gcc are
broken for ARM??

Best regards,

-- 
David Jander
Protonic Holland.

  reply	other threads:[~2012-09-11  7:54 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-10 15:16 GCC 4.6.x miscompiling arm-linux? David Jander
2012-09-10 17:11 ` Matthew Leach
2012-09-11  7:27   ` David Jander
2012-09-11  7:54     ` David Jander [this message]
2012-09-11  8:11     ` Mikael Pettersson
2012-09-11  8:49       ` David Jander
2012-09-11  9:41         ` Mikael Pettersson
2012-09-11 10:37           ` David Jander
2012-09-11 11:35             ` Mikael Pettersson
2012-09-11 11:52               ` David Jander
2012-09-11 12:53                 ` Mikael Pettersson
2012-09-11 13:43                   ` David Jander
2012-09-11 14:10                     ` Mikael Pettersson
2012-09-13  8:38                       ` David Jander
2012-09-11  8:48     ` Sascha Hauer
2012-09-11  9:31       ` David Jander
2012-09-11 10:29         ` Michael Olbrich
2012-09-11 10:33           ` Matthew Leach
2012-09-11 10:42           ` David Jander
2012-09-11 13:07             ` Michael Olbrich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120911095427.763f8619@archvile \
    --to=david.jander@protonic.nl \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.