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 157

Summary: [patch] PIC support in Hermes
Product: SDL Reporter: Sam Lantinga <slouken>
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: codepro, vapier
Version: don't know   
Hardware: x86   
OS: All   
URL: http://dev.gentoo.org/~vapier/patches/nasm-elf-visibility.patch
Attachments: libsdl-PIC-hermes-call-dont-jump.patch
libsdl-hidden-nasm.patch

Description Sam Lantinga 2006-03-08 01:10:32 UTC
Date: Tue, 7 Mar 2006 02:05:09 -0500
From: Mike Frysinger <vapier@gentoo.org>
Subject: Re: [SDL] [patch] PIC support in Hermes

On Wednesday 01 March 2006 19:32, Mike Frysinger wrote:
> rather than doing all the funky stuff with PIC, just mark all the symbols
> hidden ... then you dont have to change anything else ...

you can find my patch to add elf visibility support to nasm here:
http://dev.gentoo.org/~vapier/patches/nasm-elf-visibility.patch

then simply add 'hidden' to the decl:
GLOBAL _mmxreturn:function hidden

and many of the TEXTRELs should magically vanish :)
-mike
Comment 1 Alex Volkov 2006-03-15 18:31:24 UTC
Created attachment 82 [details]
libsdl-PIC-hermes-call-dont-jump.patch

I think the proper way to resolve these TEXTREL problems is to apply the libsdl-PIC-hermes-call-dont-jump.patch mentioned on the list. This will get rid of the _mmxreturn and and _x86return labels, period. Using jumps in those cases serves no real purpose from the optimizations' point of view -- saving and reloading the return address from the stack is so cheap compared to other operations inside the loop.
Comment 2 Mike Frysinger 2006-03-15 18:56:37 UTC
maybe, but it's even cheaper to not even touch the stack
Comment 3 Sam Lantinga 2006-03-20 01:45:39 UTC
(In reply to comment #0)
> Date: Tue, 7 Mar 2006 02:05:09 -0500
> From: Mike Frysinger <vapier@gentoo.org>
> Subject: Re: [SDL] [patch] PIC support in Hermes
> 
> On Wednesday 01 March 2006 19:32, Mike Frysinger wrote:
> > rather than doing all the funky stuff with PIC, just mark all the symbols
> > hidden ... then you dont have to change anything else ...
> 
> you can find my patch to add elf visibility support to nasm here:
> http://dev.gentoo.org/~vapier/patches/nasm-elf-visibility.patch
> 
> then simply add 'hidden' to the decl:
> GLOBAL _mmxreturn:function hidden

Can you explain to me how this fixes the problem?  Doesn't the address still have to be relocated at object load?
Comment 4 Mike Frysinger 2006-03-20 19:18:50 UTC
> Doesn't the address still have to be relocated at object load?

it doesnt ... that's the magic part :)

default visibility means the symbol is exported and usuable by any external program ... so currently, people could declare an extern '_mmxreturn' function in their code and then call that location (even though it'd prob crash horribly)

but since the symbol is exported, the actual address wont really be known until load time so all of the absolute references need to be fixed up at runtime

if the symbol is marked as hidden, the linker will know that the symbol is not supposed to be exported and can rewrite all references to it at link time so that it no longer exists ... so all of the 'jmp _mmxreturn' lines get rewritten with relative jump's ... thus there's nothing left to fixup at runtime

the other nice benefit is you shrink the exported symbol table a little bit so there's less symbols to process at runtime ... all such private non-static SDL functions could benefit from being marked hidden
Comment 5 Mike Frysinger 2006-05-22 01:24:07 UTC
Created attachment 132 [details]
libsdl-hidden-nasm.patch

here's the patch i posted here:
http://www.libsdl.org/pipermail/sdl/2006-March/073618.html

this will hide the symbols dynamically if the build nasm/yasm supports the hidden stuff ... in other words, this patch should be safe with both older and new versions of nasm/yasm
Comment 6 Sam Lantinga 2006-06-21 03:58:16 UTC
This is in subversion, thanks!
I tweaked the patch slightly to handle older versions of nasm, which don't support :function syntax on Win32.
Comment 7 Mike Frysinger 2006-06-21 04:14:28 UTC
erm, sorry, but i forgot to update the patch here ...

the file "common.asm" needs to be renamed to "common.inc" otherwise the build system will try and compile it into the library:

SOURCES="$SOURCES $srcdir/src/hermes/*.asm"
Comment 8 Sam Lantinga 2006-06-21 04:27:42 UTC
Got it, thanks!