Clean up some of the PIC issues in libSDL asm

the assembly used in some parts of libSDL arent very PIC friendly thus causing
some ugly TEXTREL’s in the final library … the PaX team has put together a
bunch of fixes which i’m forwarding (along with some test cases to show that
the code is sane) … there may be a little conflict between these patches,
but hopefully not

  • libsdl-SDL_stretch-PIC.patch
    ignoring the general fact of how SDL_stretch relies on executing dynamic code,
    the inline asm should let gcc handle the a details for getting the actual
    address for _copy_row as it will do the right thing
    test case: http://dev.gentoo.org/~vapier/libsdl/sdl-stretch.tar.bz2

  • libsdl-no-exec-stack.patch
    this makes sure that the nasm code declares itself as not needing executable
    stacks. if GNU stack is not found in assembly files, binutils assumes that
    it requires a read/write/executable stack. before the patch, running readelf -l libSDL.so would show a GNU_STACK program header marked as RWE … after
    the patch, the GNU_STACK should be marked as just RW.

  • libsdl-PIC-hermes-cpuid.patch
    rewrites the code in _Hermes_X86_CPU so that it doesnt require the local
    cpu_flags memory variable, it just uses registers.
    test case: http://dev.gentoo.org/~vapier/libsdl/hermes-cpuid-test.tar.bz2

  • libsdl-PIC-hermes-call-dont-jump.patch
    call, dont jmp, with _mmxreturn and _x86return labels. if you try to jmp to
    them, nasm will generate relocations which ld is unable to resolve while
    linking, so the resulting library will contain a ton of TEXTREL’s (one per
    jmp pretty much). simply calling and returning in a normal function fashion
    resolves this. no test case as i’m not well versed enough in SDL to put
    together a comprehensive one … but it does compile and my games dont
    segfault :slight_smile:

  • libsdl-PIC-load-mmx-masks-from-stack.patch
    this one may be a little controversial … the fix here is again that you cant
    reference the memory addresses like this to load into a mmx register, so the
    way to do it is to push two 32bit words onto the stack, load the 64bit value
    off of the stack into the mmx register, and then adjust the stack so that
    it’s back to normal.
    -mike
    -------------- next part --------------
    A non-text attachment was scrubbed…
    Name: libsdl-PIC-hermes-cpuid.patch
    Type: text/x-diff
    Size: 405 bytes
    Desc: not available
    URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050929/9098f15e/attachment.patch
    -------------- next part --------------
    A non-text attachment was scrubbed…
    Name: libsdl-SDL_stretch-PIC.patch
    Type: text/x-diff
    Size: 639 bytes
    Desc: not available
    URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050929/9098f15e/attachment-0001.patch
    -------------- next part --------------
    A non-text attachment was scrubbed…
    Name: libsdl-PIC-hermes-call-dont-jump.patch
    Type: text/x-diff
    Size: 4868 bytes
    Desc: not available
    URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050929/9098f15e/attachment-0002.patch
    -------------- next part --------------
    A non-text attachment was scrubbed…
    Name: libsdl-PIC-load-mmx-masks-from-stack.patch
    Type: text/x-diff
    Size: 1803 bytes
    Desc: not available
    URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050929/9098f15e/attachment-0003.patch
    -------------- next part --------------
    A non-text attachment was scrubbed…
    Name: libsdl-PIC-load-mmx-masks-from-stack.patch
    Type: text/x-diff
    Size: 4184 bytes
    Desc: not available
    URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050929/9098f15e/attachment-0004.patch

the assembly used in some parts of libSDL arent very PIC friendly thus causing
some ugly TEXTREL’s in the final library … the PaX team has put together a
bunch of fixes which i’m forwarding (along with some test cases to show that
the code is sane) … there may be a little conflict between these patches,
but hopefully not

libsdl-PIC-load-mmx-masks-from-stack.patch was attached twice, and
libsdl-no-exec-stack.patch wasn’t attached at all. Can you resend the
missing patch?

Thanks,
–ryan.

indeed … lets see if i can figure out how to use my e-mail client this
time :wink:
-mike
-------------- next part --------------
A non-text attachment was scrubbed…
Name: libsdl-no-exec-stack.patch
Type: text/x-diff
Size: 1146 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050930/6e6a6178/attachment.patchOn Friday 30 September 2005 04:57 am, Ryan C. Gordon wrote:

the assembly used in some parts of libSDL arent very PIC friendly thus
causing some ugly TEXTREL’s in the final library … the PaX team has put
together a bunch of fixes which i’m forwarding (along with some test
cases to show that the code is sane) … there may be a little conflict
between these patches, but hopefully not

libsdl-PIC-load-mmx-masks-from-stack.patch was attached twice, and
libsdl-no-exec-stack.patch wasn’t attached at all. Can you resend the
missing patch?

  • libsdl-PIC-yuv-mmx.patch
    rework how the masks are declared and used in src/video/SDL_yuv_mmx.c so that
    gcc handles the addressing details. no test case for this code either, so i
    hope someone can help test it :slight_smile:
    -mike
    -------------- next part --------------
    A non-text attachment was scrubbed…
    Name: libsdl-1.2.9-PIC-yuv-mmx.patch
    Type: text/x-diff
    Size: 13260 bytes
    Desc: not available
    URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20051004/de6a26c5/attachment.patchOn Thursday 29 September 2005 05:57 am, Mike Frysinger wrote:

the assembly used in some parts of libSDL arent very PIC friendly thus
causing some ugly TEXTREL’s in the final library … the PaX team has put
together a bunch of fixes which i’m forwarding (along with some test cases
to show that the code is sane) … there may be a little conflict between
these patches, but hopefully not

hrm, seems this breaks on gcc-2, so i guess ignore this for now until i can
get a version that complies cleanly on gcc-2/gcc-3.3/gcc-3.4/gcc-4 and doesnt
have ugly TEXTRELs :wink:
-mikeOn Tuesday 04 October 2005 07:29 pm, Mike Frysinger wrote:

On Thursday 29 September 2005 05:57 am, Mike Frysinger wrote:

the assembly used in some parts of libSDL arent very PIC friendly thus
causing some ugly TEXTREL’s in the final library … the PaX team has put
together a bunch of fixes which i’m forwarding (along with some test
cases to show that the code is sane) … there may be a little conflict
between these patches, but hopefully not

  • libsdl-PIC-yuv-mmx.patch
    rework how the masks are declared and used in src/video/SDL_yuv_mmx.c so
    that gcc handles the addressing details. no test case for this code
    either, so i hope someone can help test it :slight_smile:

hrm, seems this breaks on gcc-2, so i guess ignore this for now until i can
get a version that complies cleanly on gcc-2/gcc-3.3/gcc-3.4/gcc-4 and doesnt
have ugly TEXTRELs :wink:

Are the other PIC/TEXTREL patches still okay to apply?

–ryan.

yes … ive built libsdl using these patches with gcc 3.3.6/3.4.4/4.0.2

the yuv mmx PIC patch fails to build with 2.x due to the limit of 10 input asm
constraints … the other patches are gcc 2 friendly though

in terms of stability, ive deployed these patches in Gentoo about three weeks
ago and i havent received any related bug reports yet
-mikeOn Monday 17 October 2005 06:31 pm, Ryan C. Gordon wrote:

hrm, seems this breaks on gcc-2, so i guess ignore this for now until i
can get a version that complies cleanly on gcc-2/gcc-3.3/gcc-3.4/gcc-4
and doesnt have ugly TEXTRELs :wink:

Are the other PIC/TEXTREL patches still okay to apply?

actually, this patch can be put on hold … if i can work with the nasm peeps
to get ELF visibility integrated into the nasm language, then the issues here
can be solved much nicer by only changing the function def lines to declare
these internal functions as hidden
-mikeOn Thursday 29 September 2005 05:57, Mike Frysinger wrote:

  • libsdl-PIC-hermes-call-dont-jump.patch