summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2010-10-22 13:58:13 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-10-22 13:58:13 +0200
commitf53db356f53686cb0e4ddb25946b8cff9e82453d (patch)
treee9e9038e90ad491b3631c8aee4637b4306e3df7f
parent5e8d3975e2cb45df16038e2a99c74abfb252d44a (diff)
libm/x86: use call instead of jump for wrappers
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. Signed-off-by: Timo Teräs <timo.teras@iki.fi> Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r--libm/ldouble_wrappers.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/libm/ldouble_wrappers.c b/libm/ldouble_wrappers.c
index bf7ae15f0..f78a97a05 100644
--- a/libm/ldouble_wrappers.c
+++ b/libm/ldouble_wrappers.c
@@ -61,6 +61,10 @@ long long func##l(long double x) \
* a long double or returning a double). So we can simply jump to func.
* Using __GI_func in jump to make optimized intra-library jump.
* gcc will still generate a useless "ret" after asm. Oh well...
+ *
+ * Update: we do need to use call (instead of tail jump) as gcc can create
+ * stack frame, and push/modify/pop ebx during PIC build.
+ * TODO: add conditionals to use tail jump if possible?
*/
# define WRAPPER1(func) \
long double func##l(long double x) \
@@ -69,7 +73,7 @@ long double func##l(long double x) \
__asm__ ( \
" fldt %1\n" \
" fstpl %1\n" \
- " jmp " __stringify(__GI_##func) "\n" \
+ " call " __stringify(__GI_##func) "\n" \
: "=t" (st_top) \
: "m" (x) \
); \
@@ -82,7 +86,7 @@ int func##l(long double x) \
__asm__ ( \
" fldt %1\n" \
" fstpl %1\n" \
- " jmp " __stringify(__GI_##func) "\n" \
+ " call " __stringify(__GI_##func) "\n" \
: "=a" (ret) \
: "m" (x) \
); \
@@ -95,7 +99,7 @@ long func##l(long double x) \
__asm__ ( \
" fldt %1\n" \
" fstpl %1\n" \
- " jmp " __stringify(__GI_##func) "\n" \
+ " call " __stringify(__GI_##func) "\n" \
: "=a" (ret) \
: "m" (x) \
); \
@@ -108,7 +112,7 @@ long long func##l(long double x) \
__asm__ ( \
" fldt %1\n" \
" fstpl %1\n" \
- " jmp " __stringify(__GI_##func) "\n" \
+ " call " __stringify(__GI_##func) "\n" \
: "=A" (ret) \
: "m" (x) \
); \