[Qemu-devel] error compiling hw/sh7750.c
I'm getting this error compiling hw/sh7750.c I believe the problem comes from the include in hw/sh_intc.h with the macro #define _INTC_ARRAY(a) a, sizeof(a)/sizeof(*a) in line 587 of hw/7750.c, I see sh_intc_register_sources(s-intc, _INTC_ARRAY(vectors_irlm), _INTC_ARRAY(NULL)); So the macro turns the last _INTC_ARRAY(NULL) into NULL, sizeof(NULL)/sizeof(*NULL) Since sizeof(*NULL) doesn't make any sense, the compiler barfs on Solaris 10/x86_64. gcc -Wall -O2 -g -fno-strict-aliasing -m64 -I. -I.. -I/export-1/bent/src/qemu/07/qemu/target-sh4 -I/export-1/bent/src/qemu/07/qemu -MMD -MP -DNEED_CPU_H -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -I/export-1/bent/src/qemu/07/qemu/fpu -I/usr/gnu/include -I/export-1/bent/src/qemu/07/qemu/slirp -m64 -c -o sh7750.o /export-1/bent/src/qemu/07/qemu/hw/sh7750.c /export-1/bent/src/qemu/07/qemu/hw/sh7750.c: In function `error_access': /export-1/bent/src/qemu/07/qemu/hw/sh7750.c:184: warning: unsigned int format, different type arg (arg 5) /export-1/bent/src/qemu/07/qemu/hw/sh7750.c: In function `ignore_access': /export-1/bent/src/qemu/07/qemu/hw/sh7750.c:190: warning: unsigned int format, different type arg (arg 5) /export-1/bent/src/qemu/07/qemu/hw/sh7750.c: In function `sh7750_init': /export-1/bent/src/qemu/07/qemu/hw/sh7750.c:576: error: invalid type argument of `unary *' /export-1/bent/src/qemu/07/qemu/hw/sh7750.c:589: error: invalid type argument of `unary *' gmake[1]: *** [sh7750.o] Error 1 gmake[1]: Leaving directory `/export-1/bent/src/qemu/07/qemu/sh4-softmmu' gmake: *** [subdir-sh4-softmmu] Error 2 In this case, I've replaced _INTC_ARRAY(NULL) with NULL, NULL and it succesfully compiles, but I don't have any sh emulation to do. Ben
Re: [Qemu-devel] error compiling hw/sh7750.c
On Sun, Nov 11, 2007 at 09:30:26AM -0500, Ben Taylor wrote: So the macro turns the last _INTC_ARRAY(NULL) into NULL, sizeof(NULL)/sizeof(*NULL) in my 64bit linux using gcc-4.1.2 it becomes instead : ((void *)0), sizeof(((void *)0))/sizeof(*((void *)0)) what version of gcc (gcc -v) are you using in that Solaris 10 box? (HINT: not all available versions of gcc compile qemu correctly) : http://www.opensolaris.org/os/project/qemu/host/gcc-failures/ Carlo
Re: [Qemu-devel] error compiling hw/sh7750.c
On Sun, Nov 11, 2007 at 10:06:34AM -0600, Carlo Marcelo Arenas Belon wrote: On Sun, Nov 11, 2007 at 09:30:26AM -0500, Ben Taylor wrote: So the macro turns the last _INTC_ARRAY(NULL) into NULL, sizeof(NULL)/sizeof(*NULL) in my 64bit linux using gcc-4.1.2 it becomes instead : ((void *)0), sizeof(((void *)0))/sizeof(*((void *)0)) what version of gcc (gcc -v) are you using in that Solaris 10 box? (HINT: not all available versions of gcc compile qemu correctly) : http://www.opensolaris.org/os/project/qemu/host/gcc-failures/ That didn't sound as clear as it should, so I booted an OpenSolaris Nevada 70b using the sun provided gcc : $ uname -a SunOS dell 5.11 snv_70b i86pc i386 i86pc $ gcc -v Reading specs from /usr/sfw/lib/gcc/i386-pc-solaris2.11/3.4.3/specs Configured with: /builds2/sfwnv-gate/usr/src/cmd/gcc/gcc-3.4.3/configure --prefix=/usr/sfw --with-as=/usr/sfw/bin/gas --with-gnu-as --with-ld=/usr/ccs/bin/ld --without-gnu-ld --enable-languages=c,c++,f77,objc --enable-shared Thread model: posix gcc version 3.4.3 (csl-sol210-3_4-20050802) and run a test, the problem is in /usr/include/iso/stdio_iso.h that defined NULL as an int and not a pointer as shown by : fndef NULL #if defined(_LP64) #define NULL0L #else #define NULL0 #endif #endif contradicting (at least in spirit) the C99 (ISO/IEC 9899:TCS) standard that says : A pointer to void shall have the same representation and alignment requirements as a pointer to a character type and therefore makes sizeof(*NULL) == 1 solving the problem to compile as it is done if applying the following patch : Carlo --- --- qemu/hw/sh7750.cSun Oct 7 09:31:11 2007 +++ qemu/hw/sh7750.cSun Nov 11 16:13:13 2007 @@ -29,6 +29,9 @@ #include sh7750_regnames.h #include sh_intc.h +#undef NULL +#define NULL ((void *)0) + #define NB_DEVICES 4 typedef struct SH7750State {
Re: [Qemu-devel] error compiling hw/sh7750.c
+#undef NULL +#define NULL ((void *)0) Absolutely not. Paul
Re: [Qemu-devel] error compiling hw/sh7750.c
In message: [EMAIL PROTECTED] Carlo Marcelo Arenas Belon [EMAIL PROTECTED] writes: : On Sun, Nov 11, 2007 at 10:06:34AM -0600, Carlo Marcelo Arenas Belon wrote: : On Sun, Nov 11, 2007 at 09:30:26AM -0500, Ben Taylor wrote: : So the macro turns the last _INTC_ARRAY(NULL) into : : NULL, sizeof(NULL)/sizeof(*NULL) : : in my 64bit linux using gcc-4.1.2 it becomes instead : : :((void *)0), sizeof(((void *)0))/sizeof(*((void *)0)) : : what version of gcc (gcc -v) are you using in that Solaris 10 box? (HINT: not : all available versions of gcc compile qemu correctly) : : :http://www.opensolaris.org/os/project/qemu/host/gcc-failures/ : : That didn't sound as clear as it should, so I booted an OpenSolaris Nevada 70b : using the sun provided gcc : : : $ uname -a : SunOS dell 5.11 snv_70b i86pc i386 i86pc : $ gcc -v : Reading specs from /usr/sfw/lib/gcc/i386-pc-solaris2.11/3.4.3/specs : Configured with: /builds2/sfwnv-gate/usr/src/cmd/gcc/gcc-3.4.3/configure : --prefix=/usr/sfw --with-as=/usr/sfw/bin/gas --with-gnu-as : --with-ld=/usr/ccs/bin/ld --without-gnu-ld --enable-languages=c,c++,f77,objc : --enable-shared : Thread model: posix : gcc version 3.4.3 (csl-sol210-3_4-20050802) : : and run a test, the problem is in /usr/include/iso/stdio_iso.h that defined : NULL as an int and not a pointer as shown by : : : fndef NULL : #if defined(_LP64) : #define NULL0L : #else : #define NULL0 : #endif : #endif : : contradicting (at least in spirit) the C99 (ISO/IEC 9899:TCS) standard that : says : : : A pointer to void shall have the same representation and alignment :requirements as a pointer to a character type NULL isn't a pointer. It is a integral constant, per section 6.3.2.3.3 of C99. So *NULL is undefined. If you want a constant thats an actual pointer, you need to define one special. 6.3.2.3 Pointers ... [#3] An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant. If a null pointer constant is assigned to or compared for equality to a pointer, the constant is converted to a pointer of that type. Such a pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function. [#4] Conversion of a null pointer to another pointer type yields a null pointer of that type. Any two null pointers shall compare equal. 7.17 Common definitions stddef.h ... [#3] The macros are NULL which expands to an implementation-defined null pointer constant; and .. The root cause is of this whole problem is *NULL, an undefined, unportable construct. That's what should be fixed, not the definition of NULL if you want this code to be portable. Warner
Re: [Qemu-devel] error compiling hw/sh7750.c
Carlo Marcelo Arenas Belon [EMAIL PROTECTED] writes: and run a test, the problem is in /usr/include/iso/stdio_iso.h that defined NULL as an int and not a pointer as shown by : NULL is not a pointer, it is a null pointer constant, and 0 is a valid null pointer constant. contradicting (at least in spirit) the C99 (ISO/IEC 9899:TCS) standard that says : A pointer to void shall have the same representation and alignment requirements as a pointer to a character type A null pointer constant is not a pointer. It can be convert to a pointer, but that happens only in the right context (through explicit or implicit conversions). and therefore makes sizeof(*NULL) == 1 solving the problem to compile as it is done if applying the following patch : Carlo --- --- qemu/hw/sh7750.c Sun Oct 7 09:31:11 2007 +++ qemu/hw/sh7750.c Sun Nov 11 16:13:13 2007 @@ -29,6 +29,9 @@ #include sh7750_regnames.h #include sh_intc.h +#undef NULL +#define NULL ((void *)0) This does not make it better, since sizeof(void) is still not allowed in C. Andreas. -- Andreas Schwab, SuSE Labs, [EMAIL PROTECTED] SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 And now for something completely different.
Re: [Qemu-devel] error compiling hw/sh7750.c
On Sun, Nov 11, 2007 at 05:24:06PM +, Paul Brook wrote: +#undef NULL +#define NULL ((void *)0) Absolutely not. this was not meant to be a final solution, or even be committed in qemu, just a stop gap solution answering Ben so that he can get their build to complete and have a somehow equivalent definition of what the code is doing in linux (where I presume was tested) until it can be fixed in a portable way. Ben's solution was to replace _INTC_ARRAY(NULL) with NULL, NULL but it should had been instead NULL, 4 or NULL, 8 depending on what ISA he is compiling it for, doing the #undef/#define leads to that and, yes I agree it is awful. Carlo