• Sam Lantinga's avatar
    Fixes bug 1296 - SDL_SetVideoMode crashes because of unaligned MOVAPS instruction · f5c28b24
    Sam Lantinga authored
    t.grundner@goto3d.de 2011-09-01 03:59:17 PDT
    I figured out what is going on. GCC 4.5.2 assumes the stack is 16 byte aligned
    by default. Therefore there are no AND alignment corrections necessary if we
    wish to align a stack variable to a 16 byte boundary. That is bad if your OS
    ABI is not 16 byte aligned. Windows 32 bit stacks are 4 byte aligned. This
    results in the above mentioned SIGSEGV. This is also no problem if I compile
    both SDL.dll and my app with MingW because MinGW/GCC inserts a
    
            andl    $-16, %esp
    
    instruction right in the beginning of the main function. So at least the stack
    of the thread calling the main function is 16 byte aligned. But as soon as I
    start to use the SDL.dll from an application not compiled by MinGW there is no
    ANDL safing my app.
    
    However there is a GCC option that can change the default stack alignment:
    
            -mpreferred-stack-boundary=num
    
    Setting num=2 assumes a the stack is aligned to a 4 byte boundary. This results
    in GCC inserting the necessary
    
            andl    $-16, %esp
    
    into SDL_FillRect. Rebuilding SDL with
    
           ./configure "CFLAGS=-mpreferred-stack-boundary=2 -g -O3"
    
    solved the problem.
    
    IMHO this should also be a problem on Solaris.
    
    The following links contain further information:
    
    http://gcc.gnu.org/onlinedocs/gcc-4.5.2/gcc/i386-and-x86_002d64-Options.html#i386-and-x86_002d64-Options
    
    http://www.agner.org/optimize/calling_conventions.pdf
    f5c28b24
Name
Last commit
Last update
..
SDL.h Loading commit data...
SDL_assert.h Loading commit data...
SDL_atomic.h Loading commit data...
SDL_audio.h Loading commit data...
SDL_blendmode.h Loading commit data...
SDL_clipboard.h Loading commit data...
SDL_compat.h Loading commit data...
SDL_config.h Loading commit data...
SDL_config.h.in Loading commit data...
SDL_config_android.h Loading commit data...
SDL_config_iphoneos.h Loading commit data...
SDL_config_macosx.h Loading commit data...
SDL_config_minimal.h Loading commit data...
SDL_config_nintendods.h Loading commit data...
SDL_config_pandora.h Loading commit data...
SDL_config_windows.h Loading commit data...
SDL_config_wiz.h Loading commit data...
SDL_copying.h Loading commit data...
SDL_cpuinfo.h Loading commit data...
SDL_endian.h Loading commit data...
SDL_error.h Loading commit data...
SDL_events.h Loading commit data...
SDL_gesture.h Loading commit data...
SDL_haptic.h Loading commit data...
SDL_hints.h Loading commit data...
SDL_input.h Loading commit data...
SDL_joystick.h Loading commit data...
SDL_keyboard.h Loading commit data...
SDL_keycode.h Loading commit data...
SDL_loadso.h Loading commit data...
SDL_log.h Loading commit data...
SDL_main.h Loading commit data...
SDL_mouse.h Loading commit data...
SDL_mutex.h Loading commit data...
SDL_name.h Loading commit data...
SDL_opengl.h Loading commit data...
SDL_opengles.h Loading commit data...
SDL_opengles2.h Loading commit data...
SDL_pixels.h Loading commit data...
SDL_platform.h Loading commit data...
SDL_power.h Loading commit data...
SDL_quit.h Loading commit data...
SDL_rect.h Loading commit data...
SDL_render.h Loading commit data...
SDL_revision.h Loading commit data...
SDL_rwops.h Loading commit data...
SDL_scancode.h Loading commit data...
SDL_shape.h Loading commit data...
SDL_stdinc.h Loading commit data...
SDL_surface.h Loading commit data...
SDL_syswm.h Loading commit data...
SDL_thread.h Loading commit data...
SDL_timer.h Loading commit data...
SDL_touch.h Loading commit data...
SDL_types.h Loading commit data...
SDL_version.h Loading commit data...
SDL_video.h Loading commit data...
begin_code.h Loading commit data...
close_code.h Loading commit data...
doxyfile Loading commit data...