Skip to contentSkip to conversation

2.6.19-rc5-mm1 fails to compile with gcc 4.2

DISCUSSION Bernhard Rosenkraenzer 3 participants 13 messages Nov 11, 2006 – Nov 12, 2006

lore
Share & tools
lore
#0 lore raw

drivers/kvm/kvm_main.c: In function 'kvm_dev_ioctl_run':
drivers/kvm/kvm_main.c:153: error: 'asm' operand has impossible constraints drivers/kvm/kvm_main.c:158: error: 'asm' operand has impossible constraints

#1 lore raw
Quoted 4 lines · Bernhard Rosenkraenzer

drivers/kvm/kvm_main.c: In function 'kvm_dev_ioctl_run':
drivers/kvm/kvm_main.c:153: error: 'asm' operand has impossible constraints drivers/kvm/kvm_main.c:158: error: 'asm' operand has impossible constraints

Smells like a gcc regression. Can you send .config?

Or better yet, preprocessed source and full gcc command line (as seen on 'make V=1').

Signature · 1 line
error compiling committee.c: too many arguments to function
#2 lore raw
Quoted 10 lines · Avi Kivity
Quoted 4 lines · Bernhard Rosenkraenzer

drivers/kvm/kvm_main.c: In function 'kvm_dev_ioctl_run':
drivers/kvm/kvm_main.c:153: error: 'asm' operand has impossible constraints drivers/kvm/kvm_main.c:158: error: 'asm' operand has impossible constraints

Smells like a gcc regression. Can you send .config?

Or better yet, preprocessed source and full gcc command line (as seen on 'make V=1').

It does look like a gcc bug -- -O0 makes it go away. Details at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29808

#3 lore raw
Quoted 9 lines · Bernhard Rosenkraenzer
Quoted 7 lines · Avi Kivity
Quoted 5 lines · Bernhard Rosenkraenzer

drivers/kvm/kvm_main.c: In function 'kvm_dev_ioctl_run':
drivers/kvm/kvm_main.c:153: error: 'asm' operand has impossible constraints drivers/kvm/kvm_main.c:158: error: 'asm' operand has impossible constraints

Quoted 9 lines
Quoted 5 lines

Smells like a gcc regression. Can you send .config?

Or better yet, preprocessed source and full gcc command line (as seen on 'make V=1').

It does look like a gcc bug -- -O0 makes it go away. Details at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29808

That's a different bug, gcc generates code that the assembler can't handle. Might be an assembler bug.

Can you compile it with -S and post the generated assembly?

Signature · 1 line
error compiling committee.c: too many arguments to function
#10 lore raw
In reply to Bernhard Rosenkraenzer
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines

drivers/kvm/kvm_main.c: In function 'kvm_dev_ioctl_run':
drivers/kvm/kvm_main.c:153: error: 'asm' operand has impossible constraints drivers/kvm/kvm_main.c:158: error: 'asm' operand has impossible constraints

Smells like a gcc regression. Can you send .config?

Or better yet, preprocessed source and full gcc command line (as seen on 'make V=1').

Just the function containing those lines (please mark which lines they are) would do probably.

Quoted 2 lines

It does look like a gcc bug -- -O0 makes it go away. Details at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29808

PR29808 is not a GCC bug, but invalid code.

Segher

#4 lore raw
In reply to Avi Kivity
Quoted 2 lines · Avi Kivity
Quoted 2 lines
Quoted 2 lines

Or better yet, preprocessed source and full gcc command line (as seen on 'make V=1').

gcc -m32 -Wp,-MD,drivers/kvm/.kvm_main.o.d -nostdinc -isystem /usr/lib/gcc/i586-ark-linux/4.2.0/include -D__KERNEL__ -Iinclude -include
include/linux/autoconf.h -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -O2 -pipe -msoft-float -mpreferred-stack-boundary=2 -march=i686 -mtune=pentium3 -maccumulate-outgoing-args -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -Iinclude/asm-i386/mach-default -fomit-frame-pointer -fno-stack-protector -Wdeclaration-after-statement -Wno-pointer-sign -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(kvm_main)" -D"KBUILD_MODNAME=KBUILD_STR(kvm)" -c -o
drivers/kvm/.tmp_kvm_main.o drivers/kvm/kvm_main.c
drivers/kvm/kvm_main.c: In function 'kvm_dev_ioctl_run':
drivers/kvm/kvm_main.c:153: error: 'asm' operand has impossible constraints
drivers/kvm/kvm_main.c:158: error: 'asm' operand has impossible constraints

Quoted 5 lines
Quoted 2 lines

It does look like a gcc bug -- -O0 makes it go away. Details at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29808

That's a different bug, gcc generates code that the assembler can't handle. Might be an assembler bug.

It's the same thing, the code is taken from kvm_main.c:

static void load_fs(u16 sel)

{
        asm ("mov %0, %%fs" : : "g"(sel));	<--- line 153
}

static void load_gs(u16 sel)

{
        asm ("mov %0, %%gs" : : "g"(sel));	<--- line 158
}
Quoted 1 line

Can you compile it with -S and post the generated assembly?

It can't generate assembly with asm() constructs it perceives as invalid -- -S produces the same error.

#5 lore raw
Quoted 22 lines · Bernhard Rosenkraenzer
Quoted 3 lines · Avi Kivity
Quoted 3 lines
Quoted 3 lines

Or better yet, preprocessed source and full gcc command line (as seen on 'make V=1').

gcc -m32 -Wp,-MD,drivers/kvm/.kvm_main.o.d -nostdinc -isystem /usr/lib/gcc/i586-ark-linux/4.2.0/include -D__KERNEL__ -Iinclude -include include/linux/autoconf.h -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -O2 -pipe -msoft-float -mpreferred-stack-boundary=2 -march=i686 -mtune=pentium3 -maccumulate-outgoing-args -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -Iinclude/asm-i386/mach-default -fomit-frame-pointer -fno-stack-protector -Wdeclaration-after-statement -Wno-pointer-sign -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(kvm_main)" -D"KBUILD_MODNAME=KBUILD_STR(kvm)" -c -o drivers/kvm/.tmp_kvm_main.o drivers/kvm/kvm_main.c
drivers/kvm/kvm_main.c: In function 'kvm_dev_ioctl_run':
drivers/kvm/kvm_main.c:153: error: 'asm' operand has impossible constraints drivers/kvm/kvm_main.c:158: error: 'asm' operand has impossible constraints

Quoted 6 lines
Quoted 3 lines

It does look like a gcc bug -- -O0 makes it go away. Details at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29808

That's a different bug, gcc generates code that the assembler can't handle. Might be an assembler bug.

It's the same thing, the code is taken from kvm_main.c:

static void load_fs(u16 sel)

Quoted 10 lines
{
        asm ("mov %0, %%fs" : : "g"(sel));	<--- line 153
}

static void load_gs(u16 sel)

{
        asm ("mov %0, %%gs" : : "g"(sel));	<--- line 158
}

'sel' is a variable, so gcc can't provide it as an immediate operand. Specifying it as "rm" instead of "g" would have been better, but can't have any real influence.

Quoted 6 lines
Quoted 3 lines

Can you compile it with -S and post the generated assembly?

It can't generate assembly with asm() constructs it perceives as invalid -- -S produces the same error.

Well, for the code you posted in in the gcc bug, it probaby generated something like

mov $0, %fs

which is indeed invalid assembly. But the kvm miscompile is something else (running out of registers or something like that).

Signature · 1 line
error compiling committee.c: too many arguments to function
#11 lore raw
In reply to Avi Kivity
Quoted 5 lines · Avi Kivity
Quoted 4 lines · Bernhard Rosenkraenzer

drivers/kvm/kvm_main.c: In function 'kvm_dev_ioctl_run':
drivers/kvm/kvm_main.c:153: error: 'asm' operand has impossible constraints drivers/kvm/kvm_main.c:158: error: 'asm' operand has impossible constraints

The attached patch makes it compile (but I'm not 100% sure it's the right thing to do, I'm not very experienced with gcc-style asm).

drivers/kvm/kvm_main.c renamed from drivers/kvm/kvm_main.c.ark +2 -2
@@ -150,12 +150,12 @@
 
 static void load_fs(u16 sel)
 {
-	asm ("mov %0, %%fs" : : "g"(sel));
+	asm ("mov %0, %%fs" : : "m"(sel));
 }
 
 static void load_gs(u16 sel)
 {
-	asm ("mov %0, %%gs" : : "g"(sel));
+	asm ("mov %0, %%gs" : : "m"(sel));
 }
 
 #ifndef load_ldt
#12 lore raw
Quoted 12 lines · Bernhard Rosenkraenzer

The attached patch makes it compile (but I'm not 100% sure it's the right thing to do, I'm not very experienced with gcc-style asm).

------------------------------------------------------------------------

drivers/kvm/kvm_main.c renamed from drivers/kvm/kvm_main.c.ark +0 -1
@@ -150,12 +150,12 @@
 
 static void load_fs(u16 sel)
 {
-	asm ("mov %0, %%fs" : : "g"(sel));

drivers/kvm/kvm_main.c line 161

Quoted 10 lines
drivers/kvm/kvm_main.c renamed from drivers/kvm/kvm_main.c.ark +2 -1
+	asm ("mov %0, %%fs" : : "m"(sel));
 }
 
 static void load_gs(u16 sel)
 {
-	asm ("mov %0, %%gs" : : "g"(sel));
+	asm ("mov %0, %%gs" : : "m"(sel));
 }
 
 #ifndef load_ldt

Does "rm" instead of "m" work as well?

Signature · 1 line
error compiling committee.c: too many arguments to function
#6 lore raw
In reply to Avi Kivity
Quoted 3 lines · Avi Kivity

'sel' is a variable, so gcc can't provide it as an immediate operand. Specifying it as "rm" instead of "g" would have been better, but can't have any real influence.

Specifying it as "rm" instead of "g" does fix it -- patch attached.

Quoted 7 lines

Well, for the code you posted in in the gcc bug, it probaby generated something like

    mov $0, %fs

which is indeed invalid assembly. But the kvm miscompile is something else (running out of registers or something like that).

What am I overlooking? The code is the exact same (except I replaced "u16" with "unsigned short" to avoid the #include), and produces the exact same error message, and the fix is the same ("g" -> "rm").

drivers/kvm/kvm_main.c renamed from drivers/kvm/kvm_main.c.ark +2 -2
@@ -150,12 +150,12 @@
 
 static void load_fs(u16 sel)
 {
-	asm ("mov %0, %%fs" : : "g"(sel));
+	asm ("mov %0, %%fs" : : "rm"(sel));
 }
 
 static void load_gs(u16 sel)
 {
-	asm ("mov %0, %%gs" : : "g"(sel));
+	asm ("mov %0, %%gs" : : "rm"(sel));
 }
 
 #ifndef load_ldt
#7 lore raw
Quoted 13 lines · Bernhard Rosenkraenzer
Quoted 4 lines · Avi Kivity

'sel' is a variable, so gcc can't provide it as an immediate operand. Specifying it as "rm" instead of "g" would have been better, but can't have any real influence.

Specifying it as "rm" instead of "g" does fix it -- patch attached.

Quoted 3 lines

Well, for the code you posted in in the gcc bug, it probaby generated something like

Quoted 8 lines
Quoted 5 lines
    mov $0, %fs

which is indeed invalid assembly. But the kvm miscompile is something else (running out of registers or something like that).

What am I overlooking? The code is the exact same (except I replaced "u16" with "unsigned short" to avoid the #include), and produces the exact same error message, and the fix is the same ("g" -> "rm").

Well, since it works, I guess I'm overlooking something. Maybe it's just a bad error message from gcc.

I'll apply this. Thanks!

Quoted 20 lines

------------------------------------------------------------------------

drivers/kvm/kvm_main.c renamed from drivers/kvm/kvm_main.c.ark +2 -2
@@ -150,12 +150,12 @@
 
 static void load_fs(u16 sel)
 {
-	asm ("mov %0, %%fs" : : "g"(sel));
+	asm ("mov %0, %%fs" : : "rm"(sel));
 }
 
 static void load_gs(u16 sel)
 {
-	asm ("mov %0, %%gs" : : "g"(sel));
+	asm ("mov %0, %%gs" : : "rm"(sel));
 }
 
 #ifndef load_ldt
Signature · 1 line
error compiling committee.c: too many arguments to function
#9 lore raw
In reply to Bernhard Rosenkraenzer
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

It does look like a gcc bug -- -O0 makes it go away. Details at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29808

That's a different bug, gcc generates code that the assembler can't handle. Might be an assembler bug.

Quoted 6 lines

It's the same thing, the code is taken from kvm_main.c:

static void load_fs(u16 sel)

{
        asm ("mov %0, %%fs" : : "g"(sel));	<--- line 153
}

Like I said in GCC PR29808, it's invalid -- use "r" instead.

Segher

#8 lore raw
In reply to Avi Kivity
Quoted 1 line

'sel' is a variable, so gcc can't provide it as an immediate operand. Specifying it as "rm" instead of "g" would have been better, but can't have any real influence.

It can become an immediate operand if the function gets inlined into a caller.

Segher