[PATCH] libm/x86: use call instead of jump for wrappers
Timo Teräs
timo.teras at iki.fi
Sun Oct 31 06:57:26 UTC 2010
On 10/31/2010 02:41 AM, Denys Vlasenko wrote:
> Hi Timo, unfortunately your fix isn't exactly correct.
>
> 2010/5/11 Timo Teräs <timo.teras at iki.fi>:
>> GCC can emit prologue/epilogue code for the functions in various
>> different cases:
>> - frame pointers
>> - PIC build (to load ebx for indirect calls/jumps)
>> - forced stack smashing protection
>>
>> If we used jump in such cases, we'd corrupt the call stack and
>> crash.
>
> Yes, but using call will push additional word on the stack
> and the called function will use wrong offset to access
> the parameter on stack.
Oh right. Good catch.
I somehow mixed cdecl with the other calling conventions that pass first
four floating point arguments in FPU registers. Should have checked this...
> So instead of this, you need to update #if guard:
>
> #if defined __i386__ && defined __OPTIMIZE__
>
> Add more conditions so that it kicks in only when safe.
And thank you for breaking my build again with d726ada135...
You added only the case if uclibc supports SSP. Technically that's
irrelevant.
We should check:
- __PIC__ for PIC build, it causes ebx reload (and ebx needs to be
saved/restored in prologue/epilogue on PIC).
- __SSP_ALL__ (SSP build can be enabled with UCLIBC_BUILD_SSP or adding
manually the extra CFLAG) to check if even small functions get stack
smashing protection
We don't need __UCLIBC_HAS_SSP__, it means "uclibc supports applications
built with SSP", not that "uclibc itself is built with SSP enabled".
Alternatively we could write the wrappers to cope with PIC properly and
use the GCC attribute naked. Or write the wrappers as .S file.
- Timo
More information about the uClibc
mailing list