darkrom38 / mupen64plus

Automatically exported from code.google.com/p/mupen64plus
0 stars 0 forks source link

-core fails to build with PIE, i386, GCC < 4.7 #591

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
OpenBSD recently switched to PIE on i386. The combination of PIE, i386, and GCC 
4.2.1 is probably rare enough that this hasn’t been seen before:

https://github.com/mupen64plus/mupen64plus-core/blob/master/src/r4300/x86/rjump.
c#L104

cc -O2 -pipe -g -DIOAPI_NO_64  -Wall -ffast-math -fno-strict-aliasing 
-fvisibility=hidden -I../../src -DM64P_PARALLEL -fno-PIC -I/usr/include 
-I/usr/local/include/libpng16 -I/usr/local/include -I/usr/local/include/SDL 
-D_GNU_SOURCE=1 -D_REENTRANT -I/usr/X11R6/include -DXTHREADS -DM64P_OSD 
-I/usr/X11R6/include/freetype2 -I/usr/X11R6/include -I/usr/X11R6/include 
-I/usr/include/dev/pci/drm -I/usr/X11R6/include -I/usr/include/dev/pci/drm 
-DDYNAREC -DNOCRYPT -DNOUNCRYPT -MD   -c -o _obj/r4300/x86/rjump.o 
../../src/r4300/x86/rjump.c
../../src/r4300/x86/rjump.c:104:23: error: missing binary operator before token 
"("
Makefile:581: recipe for target '_obj/r4300/x86/rjump.o' failed

Original issue reported on code.google.com by anth...@cathet.us on 9 Jan 2014 at 4:39

GoogleCodeExporter commented 8 years ago
Please try to change this lines (the __GNUC_PREREQ "#if, #else, #endif" block) 
to following and report back

#if defined(__GNUC_PREREQ)
 /* the original block */
 #if __GNUC_PREREQ (4, 7)
    #  define GET_PC_THUNK_STR(reg) "__x86.get_pc_thunk." #reg
 #else
    #  define GET_PC_THUNK_STR(reg) "__i686.get_pc_thunk." #reg
 #endif
 /* end of the original block */
#else 
  #  define GET_PC_THUNK_STR(reg) "__i686.get_pc_thunk." #reg
#endif

Also test if it works (please remove the previously mentioned change) when you 
add following line before the statement

#include <features.h>

I don't have a OpenBSD installed at the moment to check these things. Getting 
feedback would help a lot to find an acceptable fix for OpenBSD

Original comment by s...@narfation.org on 9 Jan 2014 at 7:36

GoogleCodeExporter commented 8 years ago
OpenBSD doesn’t have features.h.

The change that you described fixes the build here, thanks. Now that core 
works, though, it reveals that glide64 runs out of registers:

c++ -fvisibility-inlines-hidden -O2 -pipe -g  -Wall -ffast-math 
-fno-strict-aliasing -fvisibility=hidden -I../../src -I../../src/wrapper -DGCC 
-msse -fno-PIC -I/usr/X11R6/include -I/usr/include/dev/pci/drm 
-I/usr/local/include -I/usr/local/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT 
-I/usr/X11R6/include -DXTHREADS "-I/usrlocal/include/mupen64plus" -MD   -c -o 
_obj/TexCache.o ../../src/TexCache.cpp
../../src/TexLoad4b.h: In function 'DWORD Load4bCI(unsigned char*, unsigned 
char*, int, int, int, int, int)':
../../src/TexLoad4b.h:748: error: can't find a register in class 'GENERAL_REGS' 
while reloading 'asm'
../../src/TexLoad4b.h:1451: error: can't find a register in class 
'GENERAL_REGS' while reloading 'asm'
../../src/TexLoad4b.h:748: error: 'asm' operand has impossible constraints
../../src/TexLoad4b.h:1451: error: 'asm' operand has impossible constraints
Makefile:395: recipe for target '_obj/TexCache.o' failed

I can think of a few places to go from here…

* Use -fomit-frame-pointer on i386/PIE
* On i386/PIE, skip asm altogether and fall back to C code
* Investigate why this doesn’t happen on glide64mk2

Thoughts? I’m leaning toward the second option, since i386 is so 
register-starved it is going to be a pain with PIE no matter what.

Original comment by anth...@cathet.us on 9 Jan 2014 at 8:27

GoogleCodeExporter commented 8 years ago
It doesn't happen with glide64mk2 because I've removed the asm stuff and 
replaced it with C versions. And just disabling ASM for glide64 is not an 
option because no one added pure C versions of these functions.

It really seems to be a big hassle to use GCC 4.2 (I can build a i386 PIC/PIE 
version of m64p with GCC 4.8). Is OpenBSD now also trying to switch to LLVM? 
Because it is probably a better idea to just use/port the stuff to clang/clang++

Just tried to use it with 

make -C projects/unix CC=clang CXX=clang++ OPTFLAGS="-O2" V=1 all

(-O2 was used because I don't have the working goldplugin for link-time 
optimization installed). Many components seem to build quite fine with it. You 
may have to replace   things like __builtin_ia32_loadups(...) with

#include <xmmintrin.h>
_mm_loadu_ps(...)

Here is an example 
https://github.com/ecsv/mupen64plus-video-glide64/commit/96f51afcf4fa02405fa860e
03031f8ce97abc5d9

Original comment by s...@narfation.org on 9 Jan 2014 at 9:40

GoogleCodeExporter commented 8 years ago
It is not that difficult for me to switch the package to LLVM or GCC 4.6. But 
really, this kind of thing should not be compiler dependent; there should at 
least be a C fallback for the asm. I would be willing to look into porting the 
C over from glide64mk2...

Original comment by anth...@cathet.us on 9 Jan 2014 at 3:57

GoogleCodeExporter commented 8 years ago
I have started with it in 
https://github.com/ecsv/mupen64plus-video-glide64/tree/noasm

Please pick it up, continue + test it

Original comment by s...@narfation.org on 11 Jan 2014 at 1:42