Bug 40803 - [4.4 Regression] Optimization generates bad assembly causing compile to fail
Summary: [4.4 Regression] Optimization generates bad assembly causing compile to fail
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.4.0
: P3 blocker
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-19 08:18 UTC by Jonathan Liu
Modified: 2009-07-19 22:08 UTC (History)
1 user (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target: x86_64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu
Known to work: 4.3.3
Known to fail: 4.4.0
Last reconfirmed:


Attachments
Preprocessed output (106.68 KB, text/plain)
2009-07-19 08:21 UTC, Jonathan Liu
Details
Assembly output (12.18 KB, text/plain)
2009-07-19 08:22 UTC, Jonathan Liu
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Liu 2009-07-19 08:18:21 UTC
Can't compile Linux 2.6.29.6 kernel with grsecurity-2.1.14-2.6.29.6-200907122214 patch using GCC 4.4.0.

$ gcc -Wp,-MD,drivers/staging/meilhaus/.memain.o.d  -nostdinc -isystem /usr/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/include -Iinclude  -I/home/net147/gccbug/linux-2.6.29/arch/x86/include -include include/linux/autoconf.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -O2 -m64 -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -maccumulate-outgoing-args -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -Iarch/x86/include/asm/mach-default -Wframe-larger-than=2048 -fno-stack-protector -fomit-frame-pointer -Wdeclaration-after-statement -Wno-pointer-sign -fwrapv -fno-dwarf2-cfi-asm -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(memain)"  -D"KBUILD_MODNAME=KBUILD_STR(memain)"  -c -o drivers/staging/meilhaus/memain.o drivers/staging/meilhaus/memain.c
/home/net147/gccbug/linux-2.6.29/arch/x86/include/asm/uaccess_64.h: Assembler messages:
/home/net147/gccbug/linux-2.6.29/arch/x86/include/asm/uaccess_64.h:92: Error: suffix or operands invalid for `movq'

The compiler outputs the assembly instruction "movq $4294967295,(%rbp)" which causes the compile to fail. Compiling with -O0 or with GCC 4.3.3 works.

$ gcc -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --prefix=/usr --enable-shared --enable-languages=c,c++,fortran,objc,obj-c++ --enable-threads=posix --mandir=/usr/share/man --infodir=/usr/share/info --enable-__cxa_atexit --disable-multilib --libdir=/usr/lib --libexecdir=/usr/lib --enable-clocale=gnu --disable-libstdcxx-pch --with-tune=generic
Thread model: posix
gcc version 4.4.0 20090630 (prerelease) (GCC)

Related bug: http://bugs.archlinux.org/task/15498.
Comment 1 Jonathan Liu 2009-07-19 08:21:25 UTC
Created attachment 18225 [details]
Preprocessed output

$ gcc -Wp,-MD,drivers/staging/meilhaus/.memain.o.d  -nostdinc -isystem /usr/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/include -Iinclude  -I/home/net147/gccbug/linux-2.6.29/arch/x86/include -include include/linux/autoconf.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -O2 -m64 -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -maccumulate-outgoing-args -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -Iarch/x86/include/asm/mach-default -Wframe-larger-than=2048 -fno-stack-protector -fomit-frame-pointer -Wdeclaration-after-statement -Wno-pointer-sign -fwrapv -fno-dwarf2-cfi-asm -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(memain)"  -D"KBUILD_MODNAME=KBUILD_STR(memain)"  -c drivers/staging/meilhaus/memain.c -E > memain.i
Comment 2 Jonathan Liu 2009-07-19 08:22:19 UTC
Created attachment 18226 [details]
Assembly output

$ gcc -Wp,-MD,drivers/staging/meilhaus/.memain.o.d  -nostdinc -isystem /usr/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/include -Iinclude  -I/home/net147/gccbug/linux-2.6.29/arch/x86/include -include include/linux/autoconf.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -O2 -m64 -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -maccumulate-outgoing-args -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -Iarch/x86/include/asm/mach-default -Wframe-larger-than=2048 -fno-stack-protector -fomit-frame-pointer -Wdeclaration-after-statement -Wno-pointer-sign -fwrapv -fno-dwarf2-cfi-asm -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(memain)"  -D"KBUILD_MODNAME=KBUILD_STR(memain)"  -c drivers/staging/meilhaus/memain.c -S -o memain.s
Comment 3 Uroš Bizjak 2009-07-19 15:14:26 UTC
"i" is not correct constraint to immediate operand for sign-extending movq.  Use "e".
Comment 4 Uroš Bizjak 2009-07-19 15:47:56 UTC
BTW: Constraints in arch/x86/include/asm/uaccess_64.h from linux-2.6.31 are wrong for all cases where mov is suffixed with "q", i.e.:

int __copy_to_user(void __user *dst, const void *src, unsigned size)
{
	...
	case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
			      ret, "q", "", "ir", 8);
		return ret;
	...
Comment 5 Uroš Bizjak 2009-07-19 20:30:26 UTC
FYI, patch for linux kernel is at [1].

[1] http://marc.info/?l=linux-kernel&m=124801961215396&w=2
Comment 6 Steven Bosscher 2009-07-19 22:08:03 UTC
*sigh* another kernel bug where kernel developers just immediately look to blame gcc instead of trying to see their own mistake...