GCC 3.4.1 bugs
by James Urquhart · in Torque Game Engine · 09/18/2004 (4:31 am) · 70 replies
Hi there,
I've recently reinstalled my gentoo linux system.
Unfortunatly, it seems that i have been updated to a newer GCC release. I am getting rather odd compiler errors in torque (relatively recent HEAD copy).
Firstly, it seems "-mcpu" is deprecated, so i'm getting the nice warning when compiling each source file :
Secondly, in core/resManager.h :
Seems it does not like using the forward declaration (class ResManager;) and the subsequent "extern ResManager *ResourceManager;" object, though i don't see why this should be a problem. It even thinks ResManager is a struct, which it clearly is not.
Perhaps could be a new GCC bug?
And in platform/event.h :
It seems to be having a problem with the Offset() macro.
My GCC version is as follows :
I'll see if i can fix these errors. If anyone has any bright ideas, please tell me
I've recently reinstalled my gentoo linux system.
Unfortunatly, it seems that i have been updated to a newer GCC release. I am getting rather odd compiler errors in torque (relatively recent HEAD copy).
Firstly, it seems "-mcpu" is deprecated, so i'm getting the nice warning when compiling each source file :
Quote:
--> Compiling lpng/png.c
'-mcpu=' is deprecated. Use '-mtune=' or '-march=' instead.
--> Compiling lpng/pngerror.c
'-mcpu=' is deprecated. Use '-mtune=' or '-march=' instead.
...
Secondly, in core/resManager.h :
Quote:(errors also exist in the subsequent inline's that use ResourceManager)
--> Compiling audio/audio.cc
'-mcpu=' is deprecated. Use '-mtune=' or '-march=' instead.
In file included from ./audio/audioBuffer.h:16,
from ./audio/audioDataBlock.h:13,
from ./audio/audio.h:13,
from audio/audio.cc:6:
./core/resManager.h: In member function 'void Resource<T>::unlock()':
./core/resManager.h:255: error: invalid use of undefined type 'struct ResManager'
./core/resManager.h:38: error: forward declaration of 'struct ResManager'
...
Seems it does not like using the forward declaration (class ResManager;) and the subsequent "extern ResManager *ResourceManager;" object, though i don't see why this should be a problem. It even thinks ResManager is a struct, which it clearly is not.
Perhaps could be a new GCC bug?
And in platform/event.h :
Quote:
In file included from ./sim/netConnection.h:19,
from ./game/gameConnection.h:16,
from audio/audio.cc:11:
./platform/event.h: At global scope:
./platform/event.h:137: error: a casts to a type other than an integral or enumeration type cannot appear in a constant-expression
./platform/event.h:137: error: '->' cannot appear in a constant-expression
./platform/event.h:137: error: '&' cannot appear in a constant-expression
./platform/event.h:137: error: enumerator value for 'PacketReceiveEventHeaderSize' not integer constant
./platform/event.h:140: error: a casts to a type other than an integral or enumeration type cannot appear in a constant-expression
./platform/event.h:140: error: '->' cannot appear in a constant-expression
./platform/event.h:140: error: '&' cannot appear in a constant-expression
./platform/event.h:140: error: enumerator value for 'ConnectedReceiveEventHeaderSize' not integer constant
...
It seems to be having a problem with the Offset() macro.
My GCC version is as follows :
Quote:
Reading specs from /usr/lib/gcc/i686-pc-linux-gnu/3.4.1/specs
Configured with: /var/tmp/portage/gcc-3.4.1-r2/work/gcc-3.4.1/configure --prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/3.4 --includedir=/usr/lib/gcc/i686-pc-linux-gnu/3.4.1/include --datadir=/usr/share/gcc-data/i686-pc-linux-gnu/3.4 --mandir=/usr/share/gcc-data/i686-pc-linux-gnu/3.4/man --infodir=/usr/share/gcc-data/i686-pc-linux-gnu/3.4/info --enable-shared --host=i686-pc-linux-gnu --target=i686-pc-linux-gnu --with-system-zlib --enable-languages=c,c++ --enable-threads=posix --enable-long-long --disable-checking --disable-libunwind-exceptions --enable-cstdio=stdio --enable-version-specific-runtime-libs --with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/3.4.1/include/g++-v3 --with-local-prefix=/usr/local --disable-werror --enable-shared --enable-nls --without-included-gettext --disable-multilib --enable-__cxa_atexit --enable-clocale=gnu
Thread model: posix
gcc version 3.4.1 20040803 (Gentoo Linux 3.4.1-r2, ssp-3.4-2, pie-8.7.6.5)
I'll see if i can fix these errors. If anyone has any bright ideas, please tell me
About the author
#2
The problem in platform/event.h is all to do with the fact that the Offset macro is incorrectly used to determine sizes of the header enum's, which are constants.
The "&" symbol is used to get a pointer to the class, and of course, "->" is also used .
As far as i can tell, this is not compliant according to c++ standards, since these define's are determined at compile time.
Of course, you could argue that the compiler compiles it fine, so why should we care? But remember, compiler's are very renound for their standards "compliance" ;)
An alternative would be to do something like this :
Though of course, i've not been able to test it, so i cannot guarantee its 100% correct.
As for the resource manager bug, i am still looking into it.
09/18/2004 (11:09 am)
*Updates*The problem in platform/event.h is all to do with the fact that the Offset macro is incorrectly used to determine sizes of the header enum's, which are constants.
The "&" symbol is used to get a pointer to the class, and of course, "->" is also used .
As far as i can tell, this is not compliant according to c++ standards, since these define's are determined at compile time.
Of course, you could argue that the compiler compiles it fine, so why should we care? But remember, compiler's are very renound for their standards "compliance" ;)
An alternative would be to do something like this :
enum HeaderSizes
{
/// Byte offset to payload of a PacketReceiveEvent
PacketReceiveEventHeaderSize = sizeof(Event) + sizeof(NetAddress),
/// Byte offset to payload of a ConnectedReceiveEvent
ConnectedReceiveEventHeaderSize = sizeof(Event) + sizeof(U32),
/// Byte offset to payload of a ConsoleEvent
ConsoleEventHeaderSize = sizeof(Event)
};(alternative would be sizeof(Event Type) -MaxPacketDataSize , size varying respectively for each)Though of course, i've not been able to test it, so i cannot guarantee its 100% correct.
As for the resource manager bug, i am still looking into it.
#3
It can simply be fixed by moving the inline Resource template functions to the end of the file, or rather, after the decleration of the ResManager class.
After all, it doesn't make sense to use a class in a function before that class is defined fully.
09/18/2004 (11:16 am)
Now for the bug in core/resManager.h...It can simply be fixed by moving the inline Resource
After all, it doesn't make sense to use a class in a function before that class is defined fully.
#4
09/18/2004 (1:06 pm)
Can you mail me the changed files?
#5
09/18/2004 (1:24 pm)
Will do once i can confirm they are ok.
#6
10/21/2004 (3:31 am)
Any updates on this, i tried gcc 3.4.1 and 3.4.2 with the same errors (using head updated as of this morning)?
#7
As far as i can tell, ben hasn't merged in the changes.
However, it should be quite simple to fix yourself, following my instructions.
If you want, i could email you the changes...
10/21/2004 (3:52 am)
Benoit,As far as i can tell, ben hasn't merged in the changes.
However, it should be quite simple to fix yourself, following my instructions.
If you want, i could email you the changes...
#8
10/21/2004 (4:41 am)
Sure i haven't had a lot of time these last couple of weeks to look at ths, any help would be appreciated thanks.
#9
#define Offset(s_member, s_name) \
(__offsetof__ (reinterpret_cast \
(&reinterpret_cast \
(static_cast (0)->s_member))))
or after a bit more research since this should of been fixed in gcc 3.4.2 by using the following (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16618) :
#include
#define Offset(t_member, t_name) offsetof(t_name , t_member)
both give me a bunch of similar errors anywhere Offset is used:
audio/audioDataBlock.cc:102: warning: invalid access to non-static data member 'AudioEnvironment::mUseRoom' of NULL object
audio/audioDataBlock.cc:102: warning: (perhaps the 'offsetof' macro was used incorrectly)
Not sure what else to try.
10/21/2004 (4:37 pm)
Did some research and replacing Offset with#define Offset(s_member, s_name) \
(__offsetof__ (reinterpret_cast
(&reinterpret_cast
(static_cast
or after a bit more research since this should of been fixed in gcc 3.4.2 by using the following (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16618) :
#include
#define Offset(t_member, t_name) offsetof(t_name , t_member)
both give me a bunch of similar errors anywhere Offset is used:
audio/audioDataBlock.cc:102: warning: invalid access to non-static data member 'AudioEnvironment::mUseRoom' of NULL object
audio/audioDataBlock.cc:102: warning: (perhaps the 'offsetof' macro was used incorrectly)
Not sure what else to try.
#10
I tried this construct in engine/platform/event.h
#if defined(TORQUE_COMPILER_GCC) && __GNUC__ >= 3 && __GNUC_MINOR__ >= 4
#include
#endif
#ifndef __Offset__
#define __Offset__
#if defined(TORQUE_COMPILER_GCC) && __GNUC__ >= 3 && __GNUC_MINOR__ >= 4
#define Offset(t_member, t_name) offsetof(t_name , t_member)
#elif defined(TORQUE_COMPILER_GCC) && (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
#define Offset(m,T) ((int)(&((T *)1)->m) - 1)
#else
#define Offset(x, cls) ((dsize_t)((const char *)&(((cls *)0)->x)-(const char *)0))
#endif
#endif
It compiles and generates a binary, but it segfaults so i guess tomorrow i will try to debug it and see whats going on.
10/21/2004 (5:32 pm)
Seems adding -Wno-invalid-offsetof helps and the compiling interruption message i forgot to mention in the last message seems to have been caused by needing to make clean first. I tried this construct in engine/platform/event.h
#if defined(TORQUE_COMPILER_GCC) && __GNUC__ >= 3 && __GNUC_MINOR__ >= 4
#include
#endif
#ifndef __Offset__
#define __Offset__
#if defined(TORQUE_COMPILER_GCC) && __GNUC__ >= 3 && __GNUC_MINOR__ >= 4
#define Offset(t_member, t_name) offsetof(t_name , t_member)
#elif defined(TORQUE_COMPILER_GCC) && (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
#define Offset(m,T) ((int)(&((T *)1)->m) - 1)
#else
#define Offset(x, cls) ((dsize_t)((const char *)&(((cls *)0)->x)-(const char *)0))
#endif
#endif
It compiles and generates a binary, but it segfaults so i guess tomorrow i will try to debug it and see whats going on.
#11
10/21/2004 (8:53 pm)
Try using the the last Offset definition:Offset(x, cls) ((dsize_t)((const char *)&(((cls *)0)->x)-(const char *)0))instead of the offsetof macro. With previous versions of gcc, it would work, but it spewed tons of those friggin invalid offsetof warnings. Then somebody tipped me off to the "((T*)1)->m)-1" format, which tricked GCC into not displaying the warnings. But now that they've added a flag to disable the warnings, maybe we can revert to the original Offset definition for all platforms.
#12
10/22/2004 (2:18 am)
Tried that one but it causes errors in gcc (3.4.2) same as the orignal one did. Tracked my segfault to duplicate definitions being generated for Offset which gcc seemed to not include at that point. As quick test i did an #undef and then redefine it which seems to work but now i have no textures in some places and garbage in others. Will try some more stuff when i get back from work today. I may try that 1, -1 trick though just to see.
#13
The Offset() macro appears to work fine in all other cases (which mainly seem to be in initPersistFields() functions).
10/22/2004 (2:20 am)
As far as i can recall, GCC only bugs about the Offset macro when it is incorrectly used to determine *static* packet header sizes in one of the net headers.The Offset() macro appears to work fine in all other cases (which mainly seem to be in initPersistFields() functions).
#14
10/22/2004 (5:05 am)
James like i mentioned in my email, i will try all of this with a clean tree, freshly checked out later today :)
#15
10/23/2004 (9:33 am)
James which compiler are you using? I tried what came with mandrake 10.1, then the -4mdk version from cooker and the gcc 3.4.2 from sources from gcc.gnu.org and i always end up with one of two results, segfault or corrupted/missing textures.
#16
Could you perhaps do a diff of your sources and email me a copy?
10/23/2004 (9:55 am)
Benoit,gcc version 3.4.2 (Gentoo Linux 3.4.2-r2, ssp-3.4.1-1, pie-8.7.6.5)
Could you perhaps do a diff of your sources and email me a copy?
#17
10/23/2004 (10:13 am)
Which sources ? torque or gcc?
#18
10/23/2004 (11:21 am)
Torque.
#19
11/02/2004 (3:18 pm)
Has anyone found a solution to this problem? Here's what i'm doing:[ 16:47:09 ] [~/projects/torque ]--- -- - -
( brian@brian-linux ) $ uname -a
Linux brian-linux 2.6.8-gentoo-r1 #3 Mon Sep 20 16:06:55 PDT 2004 i686 Intel(R) Pentium(R) 4 CPU 2.80GHz GenuineIntel GNU/Linux
[ 16:47:13 ] [~/projects/torque ]--- -- - -
( brian@brian-linux ) $ gcc --version
gcc (GCC) 3.4.2 (Gentoo Linux 3.4.2-r2, ssp-3.4.1-1, pie-8.7.6.5)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[ 16:47:17 ] [~/projects/torque ]--- -- - -
( brian@brian-linux ) $ make
--> Compiling audio/audio.cc
In file included from ./sim/netConnection.h:19,
from ./game/gameConnection.h:16,
from audio/audio.cc:11:
./platform/event.h:137: error: a casts to a type other than an integral or enumeration type cannot appear in a constant-expression
./platform/event.h:137: error: '->' cannot appear in a constant-expression
./platform/event.h:137: error: '&' cannot appear in a constant-expression
./platform/event.h:137: error: enumerator value for 'PacketReceiveEventHeaderSize' not integer constant
./platform/event.h:140: error: a casts to a type other than an integral or enumeration type cannot appear in a constant-expression
./platform/event.h:140: error: '->' cannot appear in a constant-expression
./platform/event.h:140: error: '&' cannot appear in a constant-expression
./platform/event.h:140: error: enumerator value for 'ConnectedReceiveEventHeaderSize' not integer constant
./platform/event.h:143: error: a casts to a type other than an integral or enumeration type cannot appear in a constant-expression
./platform/event.h:143: error: '->' cannot appear in a constant-expression
./platform/event.h:143: error: '&' cannot appear in a constant-expression
./platform/event.h:145: error: enumerator value for 'ConsoleEventHeaderSize' not integer constant
audio/audio.cc: In function 'int loopingImageSort(const void*, const void*)':
audio/audio.cc:161: warning: converting to 'int' from 'float'
audio/audio.cc: In function 'int streamingSourceSort(const void*, const void*)':
audio/audio.cc:193: warning: converting to 'int' from 'float'
audio/audio.cc: In function 'AUDIOHANDLE alxCreateSource(const Audio::Description*, const char*, const MatrixF*, AudioSampleEnvironment*)':
audio/audio.cc:707: warning: converting to non-pointer type 'ALuint' from NULL
audio/audio.cc: In function 'ALuint alxGetWaveLen(ALuint)':
audio/audio.cc:2092: warning: converting to 'ALuint' from 'F64'
make[1]: *** [out.GCC3.DEBUG/audio/audio.obj] Error 1
make: *** [default] Error 2
#20
#include
#define Offset(m,T) offsetof(T,m)
This will generate a lot of warnings but should work. To make the warnings disappear try adding this to conf.Unix.mk
-Wno-invalid-offsetof
11/03/2004 (2:55 am)
Try changing the Offset define in event.h to use this#include
#define Offset(m,T) offsetof(T,m)
This will generate a lot of warnings but should work. To make the warnings disappear try adding this to conf.Unix.mk
-Wno-invalid-offsetof
Torque 3D Owner Tom Bampton
The resource manager issue could just be an include file ordering problem, though if it was I'd of thought it would show up by now.
The Offset() macro ... there are two versions of it, one for gcc and one for other compilers. Try the non-GCC one, that may do it.
If its none of that, well, your guess is as good as mine :)
T.