[PATCH] libm/x86: use call instead of jump for wrappers

Timo Teräs timo.teras at iki.fi
Sun Oct 31 22:07:02 UTC 2010


On 10/31/2010 05:10 PM, Denys Vlasenko wrote:
> Since by breaking long double wrappers I proved that no one actually
> runs math testsuite (does anyone runs ANY part of testsuite?),
> I decided that now it is my obligation to fix math testsuite first,
> so that in the future it will be easier to catch breakatge.
> 
> I fixed it to a certain degree already.
> 
> Then I reverted your fix, and _verified_ that it works with both
> static and shared build.

Your code crashed. Mine version did not. I did not run the test suite
nor test the call thingy. Sorry about that. Just build failed by
segfault vs. succeed was enough for me.

>> You added only the case if uclibc supports SSP. Technically that's
>> irrelevant.
> 
> You are right, I was not sure whether I am using right conditional.
> 
>> We should check:
>>  - __PIC__ for PIC build, it causes ebx reload (and ebx needs to be
>> saved/restored in prologue/epilogue on PIC).
> 
> It needs to be saved/restored *if ebx is used*. In these stubs it is
> not used, thus it is not saved by gcc, and therefore tail jump is ok
> even with __PIC__.
> 
> I do not merely think so. I tested it. Try in the directory
> where you successfully built shared uclibc using PIC:

I remember that the original crash I fixed was caused by PIC and not
SSP. The issue is that the jmp target name is outside __asm__ "" and
translated by gcc to ebx+xxx. So you use implicitly ebx in your __asm__
block. And thus gcc will save/restore and calculate the local ebx for
you automatically.

(Otherwise you'd get text relocation and PIC build fail in linking.)

Either way, you'll be hosed in PIC build.

>>  - __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".
> 
> Thanks, replaced:
> 
> -#if defined __i386__ && defined __OPTIMIZE__ && !defined __UCLIBC_HAS_SSP__
> +#if defined __i386__ && defined __OPTIMIZE__ && !defined __SSP_ALL__
> 
> and pushed to git.

Please add __PIC__ test.

>> Alternatively we could write the wrappers to cope with PIC properly and
>> use the GCC attribute naked. Or write the wrappers as .S file.
> 
> Alternatively, we may just nuke them. Maybe my idea to be "clever"
> with them wasn't such a good idea in the first place.

Tail jump is ok. Doing it in __asm__ block is not. If you want to be
"clever" you need to do it by the book and write it in .S file.

Alternatively write proper call in the wrapper function.


More information about the uClibc mailing list