From: Richard Henderson <rth@twiddle.net>
To: libffi-discuss@sourceware.org
Subject: [PATCH 13/13] x86: Work around two clang assembler bugs
Date: Fri, 07 Nov 2014 15:31:00 -0000 [thread overview]
Message-ID: <1415374240-1792-14-git-send-email-rth@twiddle.net> (raw)
In-Reply-To: <1415374240-1792-1-git-send-email-rth@twiddle.net>
http://llvm.org/bugs/show_bug.cgi?id=21500
http://llvm.org/bugs/show_bug.cgi?id=21501
Basically, we can't trust .macro at all, and .org doesn't work.
We have to omit the checking that .org gave, and hope that errors
are noticed when building with gcc+gas.
---
src/x86/sysv.S | 125 +++++++++++++++++++++++++++++++--------------------------
1 file changed, 67 insertions(+), 58 deletions(-)
diff --git a/src/x86/sysv.S b/src/x86/sysv.S
index e6a8c1e..b3ed87e 100644
--- a/src/x86/sysv.S
+++ b/src/x86/sysv.S
@@ -59,7 +59,12 @@
/* This macro allows the safe creation of jump tables without an
actual table. The entry points into the table are all 8 bytes.
The use of ORG asserts that we're at the correct location. */
-#define E(X) .align 8; .org 0b + X * 8
+/* ??? The clang assembler doesn't handle .org with symbolic expressions. */
+#ifdef __clang__
+# define E(X) .align 8
+#else
+# define E(X) .align 8; .org 0b + X * 8
+#endif
.text
.align 16
@@ -194,70 +199,74 @@ ENDF(ffi_call_i386)
#define closure_FS (16 + 3*4 + 3*4 + 4)
-.macro FFI_CLOSURE_SAVE_REGS
- movl %eax, 16+R_EAX*4(%esp)
- movl %edx, 16+R_EDX*4(%esp)
+#define FFI_CLOSURE_SAVE_REGS \
+ movl %eax, 16+R_EAX*4(%esp); \
+ movl %edx, 16+R_EDX*4(%esp); \
movl %ecx, 16+R_ECX*4(%esp)
-.endm
-
-.macro FFI_CLOSURE_COPY_TRAMP_DATA chain
- movl FFI_TRAMPOLINE_SIZE(%eax), %edx /* copy cif */
- movl FFI_TRAMPOLINE_SIZE+4(%eax), %ecx /* copy fun */
- movl FFI_TRAMPOLINE_SIZE+8(%eax), %eax /* copy user_data */
- movl %edx, 28(%esp)
- movl %ecx, 32(%esp)
+
+#define FFI_CLOSURE_COPY_TRAMP_DATA \
+ movl FFI_TRAMPOLINE_SIZE(%eax), %edx; /* copy cif */ \
+ movl FFI_TRAMPOLINE_SIZE+4(%eax), %ecx; /* copy fun */ \
+ movl FFI_TRAMPOLINE_SIZE+8(%eax), %eax; /* copy user_data */ \
+ movl %edx, 28(%esp); \
+ movl %ecx, 32(%esp); \
movl %eax, 36(%esp)
-.endm
-.macro FFI_CLOSURE_CALL_INNER
- movl %esp, %ecx /* load closure_data */
- leal closure_FS+4(%esp), %edx /* load incoming stack */
-#ifdef __PIC__
- movl %ebx, 40(%esp) /* save ebx */
- cfi_rel_offset(%ebx, 40)
- call __x86.get_pc_thunk.bx /* load got register */
- addl $C(_GLOBAL_OFFSET_TABLE_), %ebx
-#endif
-#if defined HAVE_HIDDEN_VISIBILITY_ATTRIBUTE || !defined __PIC__
- call ffi_closure_inner
-#else
- call ffi_closure_inner@PLT
-#endif
-.endm
-.macro FFI_CLOSURE_MASK_AND_JUMP
- andl $X86_RET_TYPE_MASK, %eax
#ifdef __PIC__
- leal 0f@GOTOFF(%ebx, %eax, 8), %eax
- movl 40(%esp), %ebx /* restore ebx */
- cfi_restore(%ebx)
+/* We're going to always load the got register here, even if .hidden says
+ we're going to avoid the PLT call. We'll use the got register in
+ FFI_CLOSURE_MASK_AND_JUMP. */
+# if defined HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
+# define PLT(X) X
+# else
+# define PLT(X) X@PLT
+# endif
+# define FFI_CLOSURE_CALL_INNER \
+ movl %esp, %ecx; /* load closure_data */ \
+ leal closure_FS+4(%esp), %edx; /* load incoming stack */ \
+ movl %ebx, 40(%esp); /* save ebx */ \
+ cfi_rel_offset(%ebx, 40); \
+ call __x86.get_pc_thunk.bx; /* load got register */ \
+ addl $C(_GLOBAL_OFFSET_TABLE_), %ebx; \
+ call PLT(ffi_closure_inner)
+#define FFI_CLOSURE_MASK_AND_JUMP \
+ andl $X86_RET_TYPE_MASK, %eax; \
+ leal 0f@GOTOFF(%ebx, %eax, 8), %eax; \
+ movl 40(%esp), %ebx; /* restore ebx */ \
+ cfi_restore(%ebx); \
+ jmp *%eax
#else
- leal 0f(, %eax, 8), %eax
-#endif
+# define FFI_CLOSURE_CALL_INNER \
+ movl %esp, %ecx; /* load closure_data */ \
+ leal closure_FS+4(%esp), %edx; /* load incoming stack */ \
+ call ffi_closure_inner
+#define FFI_CLOSURE_MASK_AND_JUMP \
+ andl $X86_RET_TYPE_MASK, %eax; \
+ leal 0f(, %eax, 8), %eax; \
jmp *%eax
-.endm
-
-.macro FFI_GO_CLOSURE suffix, chain, t1, t2
- .align 16
- .globl C(ffi_go_closure_\suffix)
- FFI_HIDDEN(C(ffi_go_closure_\suffix))
-C(ffi_go_closure_\suffix):
- cfi_startproc
- subl $closure_FS, %esp
- cfi_adjust_cfa_offset(closure_FS)
- FFI_CLOSURE_SAVE_REGS
- movl 4(\chain), \t1 /* copy cif */
- movl 8(\chain), \t2 /* copy fun */
- movl \t1, 28(%esp)
- movl \t2, 32(%esp)
- movl \chain, 36(%esp) /* closure is user_data */
- jmp 88f
- cfi_endproc
-ENDF(C(ffi_go_closure_\suffix))
-.endm
+#endif /* __PIC__ */
-FFI_GO_CLOSURE EAX, %eax, %edx, %ecx
-FFI_GO_CLOSURE ECX, %ecx, %edx, %eax
+#define FFI_GO_CLOSURE(suffix, chain, t1, t2) \
+ .align 16; \
+ .globl C(C1(ffi_go_closure_,suffix)); \
+ FFI_HIDDEN(C(C1(ffi_go_closure_,suffix))); \
+C(C1(ffi_go_closure_,suffix)): \
+ cfi_startproc; \
+ subl $closure_FS, %esp; \
+ cfi_adjust_cfa_offset(closure_FS); \
+ FFI_CLOSURE_SAVE_REGS; \
+ movl 4(chain), t1; /* copy cif */ \
+ movl 8(chain), t2; /* copy fun */ \
+ movl t1, 28(%esp); \
+ movl t2, 32(%esp); \
+ movl chain, 36(%esp); /* closure is user_data */ \
+ jmp 88f; \
+ cfi_endproc; \
+ENDF(C(C1(ffi_go_closure_,suffix)))
+
+FFI_GO_CLOSURE(EAX, %eax, %edx, %ecx)
+FFI_GO_CLOSURE(ECX, %ecx, %edx, %eax)
/* The closure entry points are reached from the ffi_closure trampoline.
On entry, %eax contains the address of the ffi_closure. */
@@ -337,7 +346,7 @@ E(X86_RET_UNUSED15)
cfi_endproc
ENDF(C(ffi_closure_i386))
-FFI_GO_CLOSURE STDCALL, %ecx, %edx, %eax
+FFI_GO_CLOSURE(STDCALL, %ecx, %edx, %eax)
/* For REGISTER, we have no available parameter registers, and so we
enter here having pushed the closure onto the stack. */
--
1.9.3
next prev parent reply other threads:[~2014-11-07 15:31 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-07 15:30 [PATCH 00/13] Go closures for i686 Richard Henderson
2014-11-07 15:30 ` [PATCH 02/13] x86: Remove some conditional compilation Richard Henderson
2014-11-07 15:31 ` Richard Henderson [this message]
2014-11-07 15:31 ` [PATCH 03/13] x86: Force FFI_TYPE_LONGDOUBLE different from FFI_TYPE_DOUBLE Richard Henderson
2014-11-07 15:31 ` [PATCH 08/13] testsuite: Fix return_complex2 vs excessive precision Richard Henderson
2014-11-07 15:31 ` [PATCH 01/13] x86: Tidy ffi_abi Richard Henderson
2014-11-07 15:31 ` [PATCH 06/13] x86: Rewrite ffi_call Richard Henderson
2014-11-07 15:31 ` [PATCH 04/13] x86: Convert to gas generated unwind info Richard Henderson
2014-11-07 15:31 ` [PATCH 09/13] x86: Add support for Complex Richard Henderson
2014-11-07 15:31 ` [PATCH 11/13] x86: Use win32 name mangling for fastcall functions Richard Henderson
2014-11-07 15:31 ` [PATCH 12/13] testsuite: Add two dg-do run markers Richard Henderson
2014-11-07 15:31 ` [PATCH 10/13] x86: Add support for Go closures Richard Henderson
2014-11-07 15:31 ` [PATCH 05/13] ffi_cif: Add cfa_escape Richard Henderson
2014-11-07 15:31 ` [PATCH 07/13] x86: Rewrite closures Richard Henderson
2014-11-07 16:09 ` [PATCH 00/13] Go closures for i686 Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1415374240-1792-14-git-send-email-rth@twiddle.net \
--to=rth@twiddle.net \
--cc=libffi-discuss@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).