Re: [PATCH] Fix immediate asm constraint for gcc 3 x86_64

Previous thread: BUG: unable to handle kernel paging request - scsi_bus_uevent by Zdenek Kabelac on Wednesday, May 14, 2008 - 2:23 am. (2 messages)

Next thread: [PATCH ?] usb/gadget/pxa27x_udc: test ep0state == IN_DATA_STAGE rather than non-bool USB_DIR_IN by Roel Kluin on Wednesday, May 14, 2008 - 3:29 am. (2 messages)
From: Jeremy Fitzhardinge
Date: Wednesday, May 14, 2008 - 2:54 am

I'm getting this when I build for x86-64 with

jeremy@cosworth:~/hg/xen/paravirt/linux-x86_64$ gcc -v
Reading specs from /usr/lib/gcc/x86_64-linux/3.4.4/specs
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr --libexecdir=/usr/lib --with-gxx-include-dir=/usr/include/c++/3.4 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --program-suffix=-3.4 --enable-__cxa_atexit --enable-libstdcxx-allocator=mt --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk --disable-werror x86_64-linux
Thread model: posix
gcc version 3.4.4 20050314 (prerelease) (Debian 3.4.3-13)


  CC      kernel/sched.o
/home/jeremy/hg/xen/paravirt/linux/kernel/sched_trace.h: In function `wait_task_inactive':
/home/jeremy/hg/xen/paravirt/linux/kernel/sched_trace.h:5: warning: asm operand 1 probably doesn't match constraints
/home/jeremy/hg/xen/paravirt/linux/kernel/sched_trace.h:5: error: impossible constraint in `asm'
/home/jeremy/hg/xen/paravirt/linux/kernel/sched_trace.h:5: warning: 'value' might be used uninitialized in this function
/home/jeremy/hg/xen/paravirt/linux/kernel/sched.c: At top level:
/home/jeremy/hg/xen/paravirt/linux/kernel/sched_fair.c:1167: warning: 'wakeup_preempt_entity' defined but not used
make[3]: *** [kernel/sched.o] Error 1


Turning CONFIG_MARKER off avoids the problem.

    J
--

From: Mathieu Desnoyers
Date: Friday, May 16, 2008 - 5:48 am

It seems that include/asm-x86/immediate.h in sched-devel.git causes
this. gcc-3.4 does not seem to like the "i" (&name##__imv) constraint. I
have seen no such problem with gcc-4.1. This is weird. It seems that
relaxing the constraint helps fixing this, but it's not clear whether
fixing the code or gcc-3.4 is the correct solution... here is the fix :

Fix immediate asm constraint for gcc 3 x86_64

make CC=gcc-3.4 HOSTCC=gcc-3.4 causes this problem with immediate values on
x86_64 :

kernel/sched_trace.h: In function `wait_task_inactive':
kernel/sched_trace.h:5: warning: asm operand 1 probably doesn't match constraints
kernel/sched_trace.h:5: error: impossible constraint in `asm'
kernel/sched_trace.h:5: warning: 'value' might be used uninitialized in this function
make[1]: *** [kernel/sched.o] Error 1
make: *** [kernel/] Error 2

gcc-4.1 does not have this problem.

Fix this by changing the "i" (&name##__imv) for a "g" (&name##__imv) constraint.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
CC: Jeremy Fitzhardinge <jeremy@goop.org>
CC: Ingo Molnar <mingo@elte.hu>
CC: "H. Peter Anvin" <hpa@zytor.com>
---
 include/asm-x86/immediate.h |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Index: linux-2.6-sched-devel/include/asm-x86/immediate.h
===================================================================
--- linux-2.6-sched-devel.orig/include/asm-x86/immediate.h	2008-05-16 05:07:55.000000000 -0400
+++ linux-2.6-sched-devel/include/asm-x86/immediate.h	2008-05-16 05:08:29.000000000 -0400
@@ -63,7 +63,7 @@
 				"mov $0,%0\n\t"				\
 				"3:\n\t"				\
 				: "=q" (value)				\
-				: "i" (&name##__imv),			\
+				: "g" (&name##__imv),			\
 				  "i" (sizeof(value)));			\
 			break;						\
 		case 2:							\
@@ -81,7 +81,7 @@
 				"mov $0,%0\n\t"				\
 				"3:\n\t"				\
 				: "=r" (value)				\
-				: "i" (&name##__imv),			\
+				: "g" (&name##__imv),			\
 				  "i" (sizeof(value)));			\
 			break;						\
 		case 8:							\
@@ ...
From: H. Peter Anvin
Date: Friday, May 16, 2008 - 2:32 pm

It might make it compile, but it's completely *wrong* for the purpose 
intended.

It permits gcc to present the address in a register, for example, so 
there is no guarantee that you end up with an immediate.

	-hpa
--

From: Mathieu Desnoyers
Date: Wednesday, May 21, 2008 - 6:31 am

Hrm, you are right. Let's see a simple toy case which generates the
problem :

struct test_struct {
  int a;
  int b;
  int c;
};

static struct test_struct testa;

int main()
{
        asm (
             ".quad %c0\n\t"
                :
                : "i" (&testa.c));
        return 0;
}

gcc 4.1 generates :  .quad testa+8

and doesn't complain. However, gcc-3.4 stops with :
compudj@amd64:~/test$ gcc-3.4 -S -o oldgcc.S oldgcc.c
oldgcc.c: In function `main':
oldgcc.c:11: warning: asm operand 0 probably doesn't match constraints
oldgcc.c:11: error: impossible constraint in `asm'

It's understandable given that changing the "i" for a "g" constraint
changes the assembly result for :

        movl    $testa, %eax
        addq    $8, %rax
#APP
        .quad %rax

#NO_APP

Is there any way we could get a symbol assigned to &testa.c to make gcc
3 happy ?

Mathieu

-- 
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
--

Previous thread: BUG: unable to handle kernel paging request - scsi_bus_uevent by Zdenek Kabelac on Wednesday, May 14, 2008 - 2:23 am. (2 messages)

Next thread: [PATCH ?] usb/gadget/pxa27x_udc: test ep0state == IN_DATA_STAGE rather than non-bool USB_DIR_IN by Roel Kluin on Wednesday, May 14, 2008 - 3:29 am. (2 messages)