From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10611 invoked by alias); 7 Nov 2014 15:31:20 -0000 Mailing-List: contact libffi-discuss-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libffi-discuss-owner@sourceware.org Received: (qmail 10572 invoked by uid 89); 7 Nov 2014 15:31:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wg0-f48.google.com Received: from mail-wg0-f48.google.com (HELO mail-wg0-f48.google.com) (74.125.82.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 07 Nov 2014 15:31:15 +0000 Received: by mail-wg0-f48.google.com with SMTP id m15so3993130wgh.21 for ; Fri, 07 Nov 2014 07:31:12 -0800 (PST) X-Received: by 10.180.19.164 with SMTP id g4mr6013134wie.51.1415374271982; Fri, 07 Nov 2014 07:31:11 -0800 (PST) Received: from pike.twiddle.home.com ([87.111.149.167]) by mx.google.com with ESMTPSA id p1sm12186731wjy.22.2014.11.07.07.31.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Nov 2014 07:31:11 -0800 (PST) From: Richard Henderson 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 Message-Id: <1415374240-1792-14-git-send-email-rth@twiddle.net> In-Reply-To: <1415374240-1792-1-git-send-email-rth@twiddle.net> References: <1415374240-1792-1-git-send-email-rth@twiddle.net> X-SW-Source: 2014/txt/msg00200.txt.bz2 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