Win32: Fix compilation with SDL.
PATCH 1/1 Win32: Fix compilation with SDL.
sdl-config --cflags defines main = SDL_main
on some platforms. One of these platforms is
Windows with mingw32.
For those platforms, the solution already developed for __APPLE__ is now applied.
A compiler warning (missing return value) is fixed, too.
Maybe __APPLE__ no longer needs a separate check.
--- vl.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
vl.c +2 -2
@@ -113,12 +113,12 @@#endif #ifdef CONFIG_SDL -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(main)#include <SDL.h> int qemu_main (int argc,char **argv,char **envp);int main (int argc,char **argv) { -qemu_main (argc, argv,NULL ); +return qemu_main (argc, argv,NULL ); }#undef main#define main qemu_main
Signature · 1 line
1.5.6.5
Quoted 4 lines · Stefan Weil
sdl-config --cflagsdefines main =SDL_main
on some platforms. One of these platforms is
Windows with mingw32.
How about adding -Umain to SDL_CFLAGS on _WIN32 and and __APPLE__?
Regards,
Anthony Liguori
Quoted 6 lines · Anthony Liguori
Quoted 4 lines · Stefan Weil
sdl-config --cflagsdefines main =SDL_main
on some platforms. One of these platforms is
Windows with mingw32.
Quoted 6 lines
How about adding -Umain to
SDL_CFLAGSon_WIN32and and__APPLE__?Regards,
Anthony Liguori
I think -Dmain=SDL_main was added to the SDL CFLAGS because the SDL implementation needs some special startup code. Redefining main (or directly using the correct name) is typical for windows gui applications.
-Umain would destroy this mechanism and create an executable which won't run in the worst case.
By the way, I just tested the cross compiled i386/qemu.exe (with my patch) using wine on debian lenny: it works :-)
Regards
Stefan Weil
Quoted 17 lines · Stefan Weil
Quoted 7 lines · Anthony Liguori
Quoted 5 lines · Stefan Weil
sdl-config --cflagsdefines main =SDL_main
on some platforms. One of these platforms is
Windows with mingw32.Quoted 7 lines
How about adding -Umain to
SDL_CFLAGSon_WIN32and and__APPLE__?Regards,
Anthony Liguori
Quoted 8 lines
I think -Dmain=SDL_main was added to the SDL CFLAGS because the SDL implementation needs some special startup code. Redefining main (or directly using the correct name) is typical for windows gui applications.
-Umain would destroy this mechanism and create an executable which won't run in the worst case.
Why do we need to do anything special then?
I don't understand what the point of the qemu_main stuff is.
Regards,
Anthony Liguori
Quoted 26 lines · Anthony Liguori
Quoted 16 lines · Stefan Weil
Quoted 6 lines · Anthony Liguori
Quoted 4 lines · Stefan Weil
sdl-config --cflagsdefines main =SDL_main
on some platforms. One of these platforms is
Windows with mingw32.Quoted 7 lines
How about adding -Umain to
SDL_CFLAGSon_WIN32and and__APPLE__?Regards,
Anthony Liguori
Quoted 8 lines
I think -Dmain=SDL_main was added to the SDL CFLAGS because the SDL implementation needs some special startup code. Redefining main (or directly using the correct name) is typical for windows gui applications.
-Umain would destroy this mechanism and create an executable which won't run in the worst case.
Quoted 8 lines
Why do we need to do anything special then?
I don't understand what the point of the
qemu_mainstuff is.Regards,
Anthony Liguori
Ah, ok: it's simply a bad prototype of SDL_config:
extern C_LINKAGE int SDL_main(int argc, char *argv[]);
QEMU's main does not match:
int main(int argc, char **argv, char **envp)
So just redefining main will result in a wrong SDL_main with 3 instead of 2 arguments.
Regards,
Stefan Weil
Quoted 10 lines · Stefan Weil
Ah, ok: it's simply a bad prototype of
SDL_config:extern
C_LINKAGEintSDL_main(int argc, char *argv[]);QEMU's main does not match:
intmain(int argc, char **argv, char **envp)So just redefining main will result in a wrong
SDL_mainwith 3 instead of 2 arguments.
Can we not use getenv() instead of envp in main()? This was introduced for cache-utils which looks to be PPC specific.
Regards,
Anthony Liguori
Quoted 4 lines
Regards,
Stefan Weil
Quoted 8 lines · Anthony Liguori
Quoted 7 lines · Stefan Weil
Ah, ok: it's simply a bad prototype of
SDL_config:extern
C_LINKAGEintSDL_main(int argc, char *argv[]);QEMU's main does not match:
intmain(int argc, char **argv, char **envp)
Quoted 6 lines
Quoted 3 lines
So just redefining main will result in a wrong
SDL_mainwith 3 instead of 2 arguments.Can we not use
getenv()instead of envp inmain()? This was introduced for cache-utils which looks to be PPC specific.
ppc_init_cacheline_sizes() doesn't actually want env; if you look closely you'll see it walks off the end of that array. What it really wants is the AUX vector defined in the PowerPC ABI, which is a way for the kernel to expose capabilities to userland. (IIRC this code should really be written "main(int argc, char *argv, char **envp, unsigned long **auxv)", but anyways...)
The only way to access the AUX vector without changing the prototype of main() is to read /proc/self/auxv. I hear the glibc maintainer has obstinately refused to add a proper interface to it.
(This issue has come up before because the AUX vector also informs userspace if Altivec is available. It's typically codec libraries that want to know, but by the time libraries are loaded, the pointer passed to main() is long gone.)
Signature · 2 lines
Hollis Blanchard IBM Linux Technology Center