We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 17 - Various ASM PIC issues...
Summary: Various ASM PIC issues...
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: don't know
Hardware: x86 Other
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-03 12:03 UTC by Ryan C. Gordon
Modified: 2007-03-19 15:19 UTC (History)
2 users (show)

See Also:


Attachments
no-exec-stack (1.12 KB, patch)
2006-01-03 12:03 UTC, Ryan C. Gordon
Details | Diff
hermes-call-dont-jump (4.75 KB, patch)
2006-01-03 12:04 UTC, Ryan C. Gordon
Details | Diff
hermes-cpuid (405 bytes, patch)
2006-01-03 12:04 UTC, Ryan C. Gordon
Details | Diff
load-mmx-masks-from-stack (1.76 KB, patch)
2006-01-03 12:05 UTC, Ryan C. Gordon
Details | Diff
SDL_stretch-PIC (639 bytes, patch)
2006-01-03 12:07 UTC, Ryan C. Gordon
Details | Diff
libsdl-1.2.9-PIC-load-mmx-masks-from-stack.patch (3.81 KB, patch)
2006-01-05 09:35 UTC, Mike Frysinger
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryan C. Gordon 2006-01-03 12:03:28 UTC
From: Mike Frysinger <vapier@gentoo.org>
To: sdl@libsdl.org
Date: Thu, 29 Sep 2005 05:57:04 -0400
Subject: [SDL] 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 :)

- 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
Comment 1 Ryan C. Gordon 2006-01-03 12:03:57 UTC
Created attachment 10 [details]
no-exec-stack
Comment 2 Ryan C. Gordon 2006-01-03 12:04:18 UTC
Created attachment 11 [details]
hermes-call-dont-jump
Comment 3 Ryan C. Gordon 2006-01-03 12:04:33 UTC
Created attachment 12 [details]
hermes-cpuid
Comment 4 Ryan C. Gordon 2006-01-03 12:05:00 UTC
Created attachment 13 [details]
load-mmx-masks-from-stack
Comment 5 Ryan C. Gordon 2006-01-03 12:05:57 UTC
Please note that some (or all?) of these might have been applied to CVS, and some (or all?) might have been declared broken by Mike later on. Please follow up with Mike before committing!

--ryan.

Comment 6 Ryan C. Gordon 2006-01-03 12:07:14 UTC
Created attachment 14 [details]
SDL_stretch-PIC
Comment 7 Mike Frysinger 2006-01-04 22:17:43 UTC
Comment on attachment 10 [details]
no-exec-stack

this has been committed
Comment 8 Mike Frysinger 2006-01-04 22:19:02 UTC
Comment on attachment 12 [details]
hermes-cpuid

this hermes-cpuid patch is still applicable
Comment 9 Mike Frysinger 2006-01-04 22:19:23 UTC
Comment on attachment 14 [details]
SDL_stretch-PIC

this SDL_stretch change is safe and still applicable
Comment 10 Mike Frysinger 2006-01-04 22:19:46 UTC
Comment on attachment 13 [details]
load-mmx-masks-from-stack

this load mmx masks is safe and still applicable
Comment 11 Mike Frysinger 2006-01-04 22:20:24 UTC
Comment on attachment 11 [details]
hermes-call-dont-jump

i would put this on hold as it can be solved with just a few lines of code once ELF visibility is added to nasm, so i wouldnt bother changing it now
Comment 12 Ryan C. Gordon 2006-01-05 02:09:36 UTC
hermes-cpuid is in CVS.

--ryan.

Comment 13 Ryan C. Gordon 2006-01-05 02:13:17 UTC
Comment on attachment 12 [details]
hermes-cpuid


(Tagging cpuid patch as obsolete so I know it's done with.)

--ryan.
Comment 14 Ryan C. Gordon 2006-01-05 02:20:37 UTC
Comment on attachment 14 [details]
SDL_stretch-PIC


SDL_stretch patch is in CVS now.

--ryan.
Comment 15 Ryan C. Gordon 2006-01-05 02:26:09 UTC
Mike,

In the mmx-masks-from-stack patch:

Why was this a problem:
        movq mm6, qword [mmx32_rgb888_mask]

But this one in _ConvertMMXpII32_16RGB555 wasn't:
        movq mm7,qword [mmx32_rgb555_mul]

(and a few others)

--ryan.

Comment 16 Mike Frysinger 2006-01-05 09:35:35 UTC
Created attachment 17 [details]
libsdl-1.2.9-PIC-load-mmx-masks-from-stack.patch

hrm, it looks like in my original e-mail i attached two patches named the samething ... the first one was incomplete and is the one you see here

here is the "full" version :)
Comment 17 Ryan C. Gordon 2006-01-05 10:25:48 UTC
Comment on attachment 17 [details]
libsdl-1.2.9-PIC-load-mmx-masks-from-stack.patch


MMX patch is in CVS now.

--ryan.
Comment 18 Ryan C. Gordon 2006-01-05 10:26:17 UTC
Look at that, we're out of patches!   :)

I'm resolving this bug now.

Thanks, Mike!

--ryan.

Comment 19 Mike Frysinger 2006-01-05 10:54:34 UTC
awesome ... i'll file a new bug for the other issue once i can get the nasm guys to wake up
Comment 20 Ryan C. Gordon 2006-01-27 11:23:03 UTC
Setting Sam as "QA Contact" on all bugs (even resolved ones) so he'll definitely be in the loop to any further discussion here about SDL.

--ryan.

Comment 21 Ryan C. Gordon 2007-03-19 15:19:55 UTC
*** Bug 418 has been marked as a duplicate of this bug. ***