From: mbizon@freebox.fr (Maxime Bizon)
To: linux-arm-kernel@lists.infradead.org
Subject: gcc miscompiles csum_tcpudp_magic() on ARMv5
Date: Thu, 12 Dec 2013 15:10:10 +0100 [thread overview]
Message-ID: <1386857410.22947.78.camel@sakura.staff.proxad.net> (raw)
In-Reply-To: <yw1xppp2ji38.fsf@unicorn.mansr.com>
On Thu, 2013-12-12 at 13:48 +0000, M?ns Rullg?rd wrote:
> In the code above, the outer (uint16_t) cast should clear the top half,
> as should passing the value to a function (inline doesn't alter the
> semantics) as a 16-bit type, so there's something fishy here.
using __attribute__((noinline)), or putting the function in another file
makes the bug disappear
But I'm not convinced inline doesn't change the semantic, since gcc is
merging the function inside another one the rules of calling convention
should not matter anymore.
I attached a second test case without a separate function that has the
same bug.
> Which gcc versions did you try?
4.3.2, 4.6.0, 4.7.2, 4.8-2013 (linaro)
Here is a simple userspace test case.
#include <stdint.h>
#include <stdio.h>
static inline uint32_t asm_add(uint16_t len, uint32_t sum)
{
__asm__(
"add %0, %1, %2 \n"
: "=&r"(sum)
: "r" (sum), "r" (len)
);
return sum;
}
#define local_swab16(x) ((uint16_t)( \
(((uint16_t)(x) & (uint16_t)0x00ffU) << 8) | \
(((uint16_t)(x) & (uint16_t)0xff00U) >> 8)))
int main(int argc, char *argv[])
{
uint16_t foo;
foo = strtoul(argv[1], NULL, 0);
printf("%08x\n", asm_add(local_swab16(foo), 0));
return 0;
}
without optimization, or with noinline:
# ./a.out 0x3412
00001234
with optimization:
# ./a.out 0x3412
00341234
And the second test case without the inline function.
int main(int argc, char *argv[])
{
uint32_t sum = 0;
uint16_t foo;
foo = strtoul(argv[1], NULL, 0);
__asm__ (
"add %0, %1, %2 \n"
: "=&r"(sum)
: "r" (sum), "r" (local_swab16(foo))
);
printf("%08x\n", sum);
return 0;
}
--
Maxime
next prev parent reply other threads:[~2013-12-12 14:10 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-12 12:14 gcc miscompiles csum_tcpudp_magic() on ARMv5 Maxime Bizon
2013-12-12 12:40 ` Russell King - ARM Linux
2013-12-12 13:36 ` Maxime Bizon
2013-12-12 13:48 ` Måns Rullgård
2013-12-12 14:10 ` Maxime Bizon [this message]
2013-12-12 14:19 ` Willy Tarreau
2013-12-12 14:28 ` Maxime Bizon
2013-12-12 14:42 ` Måns Rullgård
2013-12-12 14:52 ` Maxime Bizon
2013-12-12 14:58 ` Måns Rullgård
2013-12-12 15:00 ` Russell King - ARM Linux
2013-12-12 15:26 ` Maxime Bizon
2013-12-12 15:07 ` Willy Tarreau
2013-12-12 15:18 ` Måns Rullgård
2013-12-12 15:28 ` Willy Tarreau
2013-12-12 15:43 ` Russell King - ARM Linux
2013-12-12 15:50 ` Måns Rullgård
2013-12-12 14:37 ` Måns Rullgård
2013-12-12 14:40 ` Maxime Bizon
2013-12-12 14:47 ` Måns Rullgård
2013-12-12 14:26 ` Måns Rullgård
2013-12-12 14:48 ` Russell King - ARM Linux
2013-12-12 15:00 ` Måns Rullgård
2013-12-12 15:04 ` Maxime Bizon
2013-12-12 15:41 ` Russell King - ARM Linux
2013-12-12 16:04 ` Måns Rullgård
2013-12-12 16:04 ` Willy Tarreau
2013-12-12 16:47 ` Russell King - ARM Linux
2013-12-12 17:11 ` Willy Tarreau
2013-12-12 17:20 ` Russell King - ARM Linux
2013-12-12 17:35 ` Willy Tarreau
2013-12-12 18:07 ` Nicolas Pitre
2013-12-12 22:30 ` Maxime Bizon
2013-12-12 22:36 ` Russell King - ARM Linux
2013-12-12 22:44 ` Maxime Bizon
2013-12-12 22:48 ` Russell King - ARM Linux
2013-12-12 17:34 ` Maxime Bizon
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=1386857410.22947.78.camel@sakura.staff.proxad.net \
--to=mbizon@freebox.fr \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).