Inline asm build issue
by Jonathan Polley · in Torque Game Engine · 11/03/2008 (6:52 pm) · 7 replies
Trying to build TGE 1.5.2 on my Debian x86_64 machine using gcc 4.3.2. I made the changes to include -m32 in the compiler flags and I changed a couple of ALvoids to void in lib/openal/LINUX/al/al_func.h and lib/openal/LINUX/al/alc_func.h.
I'm stuck on another issue that came up, though, and am unable to find any leads searching around.
In file included from platformX86UNIX/x86UNIXWindow.cc:28:
./platformX86UNIX/x86UNIXInputManager.h:33: warning: 'typedef' was ignored in this declaration
platformX86UNIX/x86UNIXWindow.cc: In static member function 'static bool Platform::openWebBrowser(const char*)':
platformX86UNIX/x86UNIXWindow.cc:793: warning: deprecated conversion from string constant to 'char*'
--> Compiling platformX86UNIX/x86UNIXUtils.cc
--> Linking out.GCC4.DEBUG/torqueDemo_DEBUG.bin
out.GCC4.DEBUG/platformX86UNIX/x86UNIXCPUInfo.obj: In function 'Processor::init()':
/home/jonathan/src/Torque1.5.2-Linux/engine/platformX86UNIX/x86UNIXCPUInfo.cc:88: undefined reference to 'timeHi'
/home/jonathan/src/Torque1.5.2-Linux/engine/platformX86UNIX/x86UNIXCPUInfo.cc:88: undefined reference to 'timeLo'
/home/jonathan/src/Torque1.5.2-Linux/engine/platformX86UNIX/x86UNIXCPUInfo.cc:88: undefined reference to 'clockticks'
collect2: ld returned 1 exit status
make[1]: *** [out.GCC4.DEBUG/torqueDemo_DEBUG.bin] Error 1
make: *** [default] Error 2
There were some old posts I found dealing with this code but the solution there generally seemed to be making sure that there were declarations for timeHi and timeLo. I don't really know my way around gcc's inline assembly very well so I'm not sure what's going on.
If I change the declarations of those three variables to NOT be static it does compile, but that doesn't seem right for several reasons.
I'm stuck on another issue that came up, though, and am unable to find any leads searching around.
In file included from platformX86UNIX/x86UNIXWindow.cc:28:
./platformX86UNIX/x86UNIXInputManager.h:33: warning: 'typedef' was ignored in this declaration
platformX86UNIX/x86UNIXWindow.cc: In static member function 'static bool Platform::openWebBrowser(const char*)':
platformX86UNIX/x86UNIXWindow.cc:793: warning: deprecated conversion from string constant to 'char*'
--> Compiling platformX86UNIX/x86UNIXUtils.cc
--> Linking out.GCC4.DEBUG/torqueDemo_DEBUG.bin
out.GCC4.DEBUG/platformX86UNIX/x86UNIXCPUInfo.obj: In function 'Processor::init()':
/home/jonathan/src/Torque1.5.2-Linux/engine/platformX86UNIX/x86UNIXCPUInfo.cc:88: undefined reference to 'timeHi'
/home/jonathan/src/Torque1.5.2-Linux/engine/platformX86UNIX/x86UNIXCPUInfo.cc:88: undefined reference to 'timeLo'
/home/jonathan/src/Torque1.5.2-Linux/engine/platformX86UNIX/x86UNIXCPUInfo.cc:88: undefined reference to 'clockticks'
collect2: ld returned 1 exit status
make[1]: *** [out.GCC4.DEBUG/torqueDemo_DEBUG.bin] Error 1
make: *** [default] Error 2
There were some old posts I found dealing with this code but the solution there generally seemed to be making sure that there were declarations for timeHi and timeLo. I don't really know my way around gcc's inline assembly very well so I'm not sure what's going on.
If I change the declarations of those three variables to NOT be static it does compile, but that doesn't seem right for several reasons.
#2
11/20/2008 (10:54 pm)
I am having the exact same problem on 1.5.0 in 32bit land with Kubuntu 8.10 and GCC 4.3.2. I'll give your fix a shot and see if that does it.
#3
On a somewhat related note, I've been having to make changes here and there (forward declarations, ALvoid, etc), but I never saw anything about the -m32 flag. I get the old "-mcpu is deprecated" message on every file; is that the proper fix? Can you post up a link?
11/20/2008 (11:12 pm)
The patch makes it link, start up, and run. My X86 ASM is so rusty that can't tell you why it works or if it works correctly, but it does start up and run and I definitely couldn't have done it myself. Thanks!On a somewhat related note, I've been having to make changes here and there (forward declarations, ALvoid, etc), but I never saw anything about the -m32 flag. I get the old "-mcpu is deprecated" message on every file; is that the proper fix? Can you post up a link?
#4
11/22/2008 (6:04 pm)
I just changed torque/mk/conf.UNIX.mk to have -march instead of -mcpu. -m32 is only relevant if you're running in a 64 bit OS but want to make a 32 bit executable.
#5
I had to do several other little code changes to get past certain compiling issues, but couldn't get past this one. After I applied your patch, I was able to get it to compile, but sadly, it doesn't run (well, it does start). It just sits there consuming about 1% of the processor time, but nothing ever happens. No window or anything.
I started attempting to build the source on a 64-bit version of Ubuntu, but decided to reinstall the 32-bit one as I wasn't sure why I was getting the errors I was (I believe I was getting the same error as listed above -- although I did know about the -m32 switch, which seemed to do what it was supposed to do on 64-bit arch).
Anyway, I'll keep trying, but must get some sleep now.
Just for the record, here's some info on my machine:
Ubuntu Intrepid (32-bit)
AMD Opteron (64-bit)
TGE 1.5.2
GCC4.3
I may just start over with a fresh Ubuntu 64-bit install since I may have messed something up whilst installing packages like a drunken mad man, trying to meet all the dependencies. At least now I can recreate all the steps necessary for the code to compile.
01/08/2009 (12:42 am)
Thanks. I've been struggling for quite a while just getting this bloody code to compile.I had to do several other little code changes to get past certain compiling issues, but couldn't get past this one. After I applied your patch, I was able to get it to compile, but sadly, it doesn't run (well, it does start). It just sits there consuming about 1% of the processor time, but nothing ever happens. No window or anything.
I started attempting to build the source on a 64-bit version of Ubuntu, but decided to reinstall the 32-bit one as I wasn't sure why I was getting the errors I was (I believe I was getting the same error as listed above -- although I did know about the -m32 switch, which seemed to do what it was supposed to do on 64-bit arch).
Anyway, I'll keep trying, but must get some sleep now.
Just for the record, here's some info on my machine:
Ubuntu Intrepid (32-bit)
AMD Opteron (64-bit)
TGE 1.5.2
GCC4.3
I may just start over with a fresh Ubuntu 64-bit install since I may have messed something up whilst installing packages like a drunken mad man, trying to meet all the dependencies. At least now I can recreate all the steps necessary for the code to compile.
#6
01/08/2009 (2:01 am)
Interesting... Jonathan and I created the exact same asm fix for that issue at two different times, so it must be right :). Take a look here, I noticed that the compiler is optimizing a lot of code out for some reason. As mentioned in that thread installing an older version of GCC will solve the issues.
#7
01/08/2009 (7:24 pm)
Wonderful! Thanks for the tip, Wes. I installed GCC-4.2/G++-4.2, make clean, make, and now it's running.
Torque Owner Jonathan Polley
Index: engine/platformX86UNIX/x86UNIXCPUInfo.cc =================================================================== --- engine/platformX86UNIX/x86UNIXCPUInfo.cc (revision 6) +++ engine/platformX86UNIX/x86UNIXCPUInfo.cc (working copy) @@ -77,14 +77,16 @@ ms = Platform::getRealMilliseconds()-ms; #if defined(TORQUE_COMPILER_GCC) && ((__GNUC__ >= 3) && (__GNUC_MINOR__ >= 4)) || ((__GNUC__ >= 4) && (__GNUC_MINOR__ >=0)) asm( - "pushl %eax\n" - "pushl %edx\n" + "pushl %%eax\n" + "pushl %%edx\n" "rdtsc\n" - "sub (timeHi), %edx\n" - "sbb (timeLo), %eax\n" - "mov %eax, (clockticks)\n" - "popl %edx\n" - "popl %eax\n" + "sub %1, %%edx\n" + "sbb %2, %%eax\n" + "mov %%eax, %0\n" + "popl %%edx\n" + "popl %%eax\n" + : "=m"(clockticks) + : "m"(timeHi), "m"(timeLo) ); #else asm(