LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* gcc-4.3 considers unaligned accesses on X86 as undefined
@ 2008-03-25 20:51 Török Edwin
2008-03-25 20:56 ` H. Peter Anvin
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Török Edwin @ 2008-03-25 20:51 UTC (permalink / raw)
To: Thomas Gleixner mingo@redhat.com, H. Peter Anvin, Ingo Molnar
Cc: Linux Kernel
Hello x86 architecture maintainers,
GCC-4.3 now considers that it is undefined behaviour to access memory
through an int* that is not aligned to sizeof(int).
At -O3 it generates vectorized code that _relies_ on the fact that
pointers are always aligned (unless you use packed attributes, etc.),
and the resulting code crashes if the pointer is unaligned. (-O3 -msse
on 32-bit, and simply -O3 on 64-bit since -msse is default)
See this gcc bugreport: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35653
[I do not really agree with this sudden change, because unaligned
accesses have always been possible on x86, but the C99 standard does say
it is undefined behaviour ...]
I thought to inform you of this change in gcc's behaviour, because
include/asm-x86/unaligned.h is no longer safe in the above context,
especially that it is being used in a loop:
http://lxr.linux.no/linux/net/bluetooth/bnep/core.c#L153
P.S.: I only compile my kernels with -O2, so I don't know if it actually
crashes or not at -O3.
Best regards,
--Edwin
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: gcc-4.3 considers unaligned accesses on X86 as undefined
2008-03-25 20:51 gcc-4.3 considers unaligned accesses on X86 as undefined Török Edwin
@ 2008-03-25 20:56 ` H. Peter Anvin
2008-03-25 21:11 ` Alan Cox
2008-03-26 5:30 ` Andi Kleen
2 siblings, 0 replies; 4+ messages in thread
From: H. Peter Anvin @ 2008-03-25 20:56 UTC (permalink / raw)
To: Török Edwin
Cc: Thomas Gleixner mingo@redhat.com, Ingo Molnar, Linux Kernel
Török Edwin wrote:
> Hello x86 architecture maintainers,
>
> GCC-4.3 now considers that it is undefined behaviour to access memory
> through an int* that is not aligned to sizeof(int).
> At -O3 it generates vectorized code that _relies_ on the fact that
> pointers are always aligned (unless you use packed attributes, etc.),
> and the resulting code crashes if the pointer is unaligned. (-O3 -msse
> on 32-bit, and simply -O3 on 64-bit since -msse is default)
> See this gcc bugreport: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35653
> [I do not really agree with this sudden change, because unaligned
> accesses have always been possible on x86, but the C99 standard does say
> it is undefined behaviour ...]
>
> I thought to inform you of this change in gcc's behaviour, because
> include/asm-x86/unaligned.h is no longer safe in the above context,
> especially that it is being used in a loop:
> http://lxr.linux.no/linux/net/bluetooth/bnep/core.c#L153
>
> P.S.: I only compile my kernels with -O2, so I don't know if it actually
> crashes or not at -O3.
>
Generating vectorized code in the kernel is death anyway, so I don't
think the change in alignment is an issue. We CANNOT ALLOW vectorized
code in the kernel under any circumstances (well, except when surrounded
by the appropriate protection constructs.)
-hpa
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: gcc-4.3 considers unaligned accesses on X86 as undefined
2008-03-25 20:51 gcc-4.3 considers unaligned accesses on X86 as undefined Török Edwin
2008-03-25 20:56 ` H. Peter Anvin
@ 2008-03-25 21:11 ` Alan Cox
2008-03-26 5:30 ` Andi Kleen
2 siblings, 0 replies; 4+ messages in thread
From: Alan Cox @ 2008-03-25 21:11 UTC (permalink / raw)
To: Török Edwin
Cc: Thomas Gleixner mingo@redhat.com, H. Peter Anvin, Ingo Molnar,
Linux Kernel
On Tue, 25 Mar 2008 22:51:09 +0200
Török Edwin <edwintorok@gmail.com> wrote:
> Hello x86 architecture maintainers,
>
> GCC-4.3 now considers that it is undefined behaviour to access memory
> through an int* that is not aligned to sizeof(int).
> At -O3 it generates vectorized code
FPU/MMX/SSE are not available or usable for the kernel anyway fortunately
in this case.
Alan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: gcc-4.3 considers unaligned accesses on X86 as undefined
2008-03-25 20:51 gcc-4.3 considers unaligned accesses on X86 as undefined Török Edwin
2008-03-25 20:56 ` H. Peter Anvin
2008-03-25 21:11 ` Alan Cox
@ 2008-03-26 5:30 ` Andi Kleen
2 siblings, 0 replies; 4+ messages in thread
From: Andi Kleen @ 2008-03-26 5:30 UTC (permalink / raw)
To: Török Edwin
Cc: Thomas Gleixner mingo@redhat.com, H. Peter Anvin, Ingo Molnar,
Linux Kernel
Török Edwin <edwintorok@gmail.com> writes:
> At -O3 it generates vectorized code that _relies_ on the fact that
> pointers are always aligned (unless you use packed attributes, etc.),
> and the resulting code crashes if the pointer is unaligned. (-O3 -msse
> on 32-bit, and simply -O3 on 64-bit since -msse is default)
The 2.6 kernel disables SSE and MMX code generation explicitely.
2.4 should be also safe unless someone misguided recompiles it with -O3.
-Andi
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-03-26 5:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-25 20:51 gcc-4.3 considers unaligned accesses on X86 as undefined Török Edwin
2008-03-25 20:56 ` H. Peter Anvin
2008-03-25 21:11 ` Alan Cox
2008-03-26 5:30 ` Andi Kleen
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).