From patchwork Thu Jan 13 10:49:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 49959 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9A44A38B3429 for ; Thu, 13 Jan 2022 10:50:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A44A38B3429 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1642071041; bh=qdtx9/3ASttVFnX0nJlDiJBdEiccm5yVxGFOQsN6l1A=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=fCNgJJjDYbW8VbQfLpVRE9UAI5Iagb19YX1qaM8joCezXLm6JX5DSnstJRFEnBxGa N78E27+1xtGqsHvrbv/HhqBVzWcU32C3kfzsF1bxLVjPS2OGEBGWLj6GV4vRRYEvGm tdY0YTbZJtwM+Rqyoc49R+mQVpWwsrSIsAEzilzQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id BEA0738A9414 for ; Thu, 13 Jan 2022 10:49:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BEA0738A9414 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-475-7g2Mw-lvPcyTdQNY0Cflhg-1; Thu, 13 Jan 2022 05:49:49 -0500 X-MC-Unique: 7g2Mw-lvPcyTdQNY0Cflhg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3A31883DEA6; Thu, 13 Jan 2022 10:49:48 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.102]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EE68E6F9C6; Thu, 13 Jan 2022 10:49:46 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH v2] i386: Remove broken CAN_USE_REGISTER_ASM_EBP (bug 28771) Date: Thu, 13 Jan 2022 11:49:45 +0100 Message-ID: <87o84fkj06.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The configure check for CAN_USE_REGISTER_ASM_EBP tried to compile a simple function that uses %ebp as an inline assembly operand. If compilation failed, CAN_USE_REGISTER_ASM_EBP was set 0, which eventually had these consequences: (1) %ebx was avoided as an inline assembly operand, with an assembler macro hack to avoid unnecessary register moves. (2) %ebp was avoided as an inline assembly operand, using an out-of-line syscall function for 6-argument system calls. (1) is no longer needed for any GCC version that is supported for building glibc. %ebx can be used directly as a register operand. Therefore, this commit removes the %ebx avoidance completely. This avoids the assembler macro hack, which turns out to be incompatible with the current Systemtap probe macros (which switch to .altmacro unconditionally). (2) is still needed in many build configurations. The existing configure check cannot really capture that because the simple function succeeds to compile, while the full glibc build still fails. Therefore, this commit removes the check, the CAN_USE_REGISTER_ASM_EBP macro, and uses the out-of-line syscall function for 6-argument system calls unconditionally. Reviewed-by: H.J. Lu --- v2: Merged the two patches. Reference the new bug. config.h.in | 4 - sysdeps/unix/sysv/linux/i386/configure | 39 ------ sysdeps/unix/sysv/linux/i386/configure.ac | 17 --- sysdeps/unix/sysv/linux/i386/sysdep.h | 222 ++++-------------------------- 4 files changed, 27 insertions(+), 255 deletions(-) diff --git a/config.h.in b/config.h.in index 82ade1cec4..ff8597413d 100644 --- a/config.h.in +++ b/config.h.in @@ -277,10 +277,6 @@ /* Define if static PIE is enabled. */ #define ENABLE_STATIC_PIE 0 -/* Some compiler options may now allow to use ebp in __asm__ (used mainly - in i386 6 argument syscall issue). */ -#define CAN_USE_REGISTER_ASM_EBP 0 - /* The default value of x86 CET control. */ #define DEFAULT_DL_X86_CET_CONTROL cet_elf_property diff --git a/sysdeps/unix/sysv/linux/i386/configure b/sysdeps/unix/sysv/linux/i386/configure index 0327590486..f119e62fc3 100644 --- a/sysdeps/unix/sysv/linux/i386/configure +++ b/sysdeps/unix/sysv/linux/i386/configure @@ -1,44 +1,5 @@ # This file is generated from configure.ac by Autoconf. DO NOT EDIT! # Local configure fragment for sysdeps/unix/sysv/linux/i386. -# Check if CFLAGS allows compiler to use ebp register in inline assembly. - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if compiler flags allows ebp in inline assembly" >&5 -$as_echo_n "checking if compiler flags allows ebp in inline assembly... " >&6; } -if ${libc_cv_can_use_register_asm_ebp+:} false; then : - $as_echo_n "(cached) " >&6 -else - -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - - void foo (int i) - { - register int reg asm ("ebp") = i; - asm ("# %0" : : "r" (reg)); - } -int -main () -{ - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - libc_cv_can_use_register_asm_ebp=yes -else - libc_cv_can_use_register_asm_ebp=no -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_can_use_register_asm_ebp" >&5 -$as_echo "$libc_cv_can_use_register_asm_ebp" >&6; } -if test $libc_cv_can_use_register_asm_ebp = yes; then - $as_echo "#define CAN_USE_REGISTER_ASM_EBP 1" >>confdefs.h - -fi - libc_cv_gcc_unwind_find_fde=yes ldd_rewrite_script=sysdeps/unix/sysv/linux/ldd-rewrite.sed diff --git a/sysdeps/unix/sysv/linux/i386/configure.ac b/sysdeps/unix/sysv/linux/i386/configure.ac index 9e980784bb..64ab2cc2c8 100644 --- a/sysdeps/unix/sysv/linux/i386/configure.ac +++ b/sysdeps/unix/sysv/linux/i386/configure.ac @@ -1,22 +1,5 @@ GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory. # Local configure fragment for sysdeps/unix/sysv/linux/i386. -# Check if CFLAGS allows compiler to use ebp register in inline assembly. -AC_CACHE_CHECK([if compiler flags allows ebp in inline assembly], - libc_cv_can_use_register_asm_ebp, [ -AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM([ - void foo (int i) - { - register int reg asm ("ebp") = i; - asm ("# %0" : : "r" (reg)); - }])], - [libc_cv_can_use_register_asm_ebp=yes], - [libc_cv_can_use_register_asm_ebp=no]) -]) -if test $libc_cv_can_use_register_asm_ebp = yes; then - AC_DEFINE(CAN_USE_REGISTER_ASM_EBP) -fi - libc_cv_gcc_unwind_find_fde=yes ldd_rewrite_script=sysdeps/unix/sysv/linux/ldd-rewrite.sed diff --git a/sysdeps/unix/sysv/linux/i386/sysdep.h b/sysdeps/unix/sysv/linux/i386/sysdep.h index 66c2833a49..4558ab66cb 100644 --- a/sysdeps/unix/sysv/linux/i386/sysdep.h +++ b/sysdeps/unix/sysv/linux/i386/sysdep.h @@ -42,15 +42,6 @@ # endif #endif -/* Since GCC 5 and above can properly spill %ebx with PIC when needed, - we can inline syscalls with 6 arguments if GCC 5 or above is used - to compile glibc. Disable GCC 5 optimization when compiling for - profiling or when -fno-omit-frame-pointer is used since asm ("ebp") - can't be used to put the 6th argument in %ebp for syscall. */ -#if !defined PROF && CAN_USE_REGISTER_ASM_EBP -# define OPTIMIZE_FOR_GCC_5 -#endif - #ifdef __ASSEMBLER__ /* Linux uses a negative return value to indicate syscall errors, @@ -238,36 +229,6 @@ extern int __syscall_error (int) attribute_hidden __attribute__ ((__regparm__ (1))); -#ifndef OPTIMIZE_FOR_GCC_5 -/* We need some help from the assembler to generate optimal code. We - define some macros here which later will be used. */ -asm (".L__X'%ebx = 1\n\t" - ".L__X'%ecx = 2\n\t" - ".L__X'%edx = 2\n\t" - ".L__X'%eax = 3\n\t" - ".L__X'%esi = 3\n\t" - ".L__X'%edi = 3\n\t" - ".L__X'%ebp = 3\n\t" - ".L__X'%esp = 3\n\t" - ".macro bpushl name reg\n\t" - ".if 1 - \\name\n\t" - ".if 2 - \\name\n\t" - "error\n\t" - ".else\n\t" - "xchgl \\reg, %ebx\n\t" - ".endif\n\t" - ".endif\n\t" - ".endm\n\t" - ".macro bpopl name reg\n\t" - ".if 1 - \\name\n\t" - ".if 2 - \\name\n\t" - "error\n\t" - ".else\n\t" - "xchgl \\reg, %ebx\n\t" - ".endif\n\t" - ".endif\n\t" - ".endm\n\t"); - /* Six-argument syscalls use an out-of-line helper, because an inline asm using all registers apart from %esp cannot work reliably and the assembler does not support describing an asm that saves and @@ -278,7 +239,6 @@ struct libc_do_syscall_args { int ebx, edi, ebp; }; -#endif # define VDSO_NAME "LINUX_2.6" # define VDSO_HASH 61765110 @@ -331,14 +291,8 @@ struct libc_do_syscall_args /* Each object using 6-argument inline syscalls must include a definition of __libc_do_syscall. */ -#ifdef OPTIMIZE_FOR_GCC_5 -# define INTERNAL_SYSCALL_MAIN_6(name, args...) \ - INTERNAL_SYSCALL_MAIN_INLINE(name, 6, args) -# define INTERNAL_SYSCALL_MAIN_NCS_6(name, args...) \ - INTERNAL_SYSCALL_MAIN_NCS(name, 6, args) -#else /* GCC 5 */ -# define INTERNAL_SYSCALL_MAIN_6(name, arg1, arg2, arg3, \ - arg4, arg5, arg6) \ +#define INTERNAL_SYSCALL_MAIN_6(name, arg1, arg2, arg3, \ + arg4, arg5, arg6) \ struct libc_do_syscall_args _xv = \ { \ (int) (arg1), \ @@ -351,8 +305,8 @@ struct libc_do_syscall_args : "=a" (resultvar) \ : "i" (__NR_##name), "c" (arg2), "d" (arg3), "S" (arg4), "D" (&_xv) \ : "memory", "cc") -# define INTERNAL_SYSCALL_MAIN_NCS_6(name, arg1, arg2, arg3, \ - arg4, arg5, arg6) \ +#define INTERNAL_SYSCALL_MAIN_NCS_6(name, arg1, arg2, arg3, \ + arg4, arg5, arg6) \ struct libc_do_syscall_args _xv = \ { \ (int) (arg1), \ @@ -365,7 +319,6 @@ struct libc_do_syscall_args : "=a" (resultvar) \ : "a" (name), "c" (arg2), "d" (arg3), "S" (arg4), "D" (&_xv) \ : "memory", "cc") -#endif /* GCC 5 */ #define INTERNAL_SYSCALL(name, nr, args...) \ ({ \ @@ -379,193 +332,72 @@ struct libc_do_syscall_args (int) resultvar; }) #if I386_USE_SYSENTER -# ifdef OPTIMIZE_FOR_GCC_5 -# ifdef PIC -# define INTERNAL_SYSCALL_MAIN_INLINE(name, nr, args...) \ +# ifdef PIC +# define INTERNAL_SYSCALL_MAIN_INLINE(name, nr, args...) \ LOADREGS_##nr(args) \ asm volatile ( \ "call *%%gs:%P2" \ : "=a" (resultvar) \ : "a" (__NR_##name), "i" (offsetof (tcbhead_t, sysinfo)) \ ASMARGS_##nr(args) : "memory", "cc") -# define INTERNAL_SYSCALL_MAIN_NCS(name, nr, args...) \ +# define INTERNAL_SYSCALL_MAIN_NCS(name, nr, args...) \ LOADREGS_##nr(args) \ asm volatile ( \ "call *%%gs:%P2" \ : "=a" (resultvar) \ : "a" (name), "i" (offsetof (tcbhead_t, sysinfo)) \ ASMARGS_##nr(args) : "memory", "cc") -# else -# define INTERNAL_SYSCALL_MAIN_INLINE(name, nr, args...) \ +# else /* I386_USE_SYSENTER && !PIC */ +# define INTERNAL_SYSCALL_MAIN_INLINE(name, nr, args...) \ LOADREGS_##nr(args) \ asm volatile ( \ "call *_dl_sysinfo" \ : "=a" (resultvar) \ : "a" (__NR_##name) ASMARGS_##nr(args) : "memory", "cc") -# define INTERNAL_SYSCALL_MAIN_NCS(name, nr, args...) \ +# define INTERNAL_SYSCALL_MAIN_NCS(name, nr, args...) \ LOADREGS_##nr(args) \ asm volatile ( \ "call *_dl_sysinfo" \ : "=a" (resultvar) \ : "a" (name) ASMARGS_##nr(args) : "memory", "cc") -# endif -# else /* GCC 5 */ -# ifdef PIC -# define INTERNAL_SYSCALL_MAIN_INLINE(name, nr, args...) \ - EXTRAVAR_##nr \ - asm volatile ( \ - LOADARGS_##nr \ - "movl %1, %%eax\n\t" \ - "call *%%gs:%P2\n\t" \ - RESTOREARGS_##nr \ - : "=a" (resultvar) \ - : "i" (__NR_##name), "i" (offsetof (tcbhead_t, sysinfo)) \ - ASMFMT_##nr(args) : "memory", "cc") -# define INTERNAL_SYSCALL_MAIN_NCS(name, nr, args...) \ - EXTRAVAR_##nr \ - asm volatile ( \ - LOADARGS_##nr \ - "call *%%gs:%P2\n\t" \ - RESTOREARGS_##nr \ - : "=a" (resultvar) \ - : "0" (name), "i" (offsetof (tcbhead_t, sysinfo)) \ - ASMFMT_##nr(args) : "memory", "cc") -# else -# define INTERNAL_SYSCALL_MAIN_INLINE(name, nr, args...) \ - EXTRAVAR_##nr \ - asm volatile ( \ - LOADARGS_##nr \ - "movl %1, %%eax\n\t" \ - "call *_dl_sysinfo\n\t" \ - RESTOREARGS_##nr \ - : "=a" (resultvar) \ - : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc") -# define INTERNAL_SYSCALL_MAIN_NCS(name, nr, args...) \ - EXTRAVAR_##nr \ - asm volatile ( \ - LOADARGS_##nr \ - "call *_dl_sysinfo\n\t" \ - RESTOREARGS_##nr \ - : "=a" (resultvar) \ - : "0" (name) ASMFMT_##nr(args) : "memory", "cc") -# endif -# endif /* GCC 5 */ -#else -# ifdef OPTIMIZE_FOR_GCC_5 -# define INTERNAL_SYSCALL_MAIN_INLINE(name, nr, args...) \ +# endif /* I386_USE_SYSENTER && !PIC */ +#else /* !I386_USE_SYSENTER */ +# define INTERNAL_SYSCALL_MAIN_INLINE(name, nr, args...) \ LOADREGS_##nr(args) \ asm volatile ( \ "int $0x80" \ : "=a" (resultvar) \ : "a" (__NR_##name) ASMARGS_##nr(args) : "memory", "cc") -# define INTERNAL_SYSCALL_MAIN_NCS(name, nr, args...) \ +# define INTERNAL_SYSCALL_MAIN_NCS(name, nr, args...) \ LOADREGS_##nr(args) \ asm volatile ( \ "int $0x80" \ : "=a" (resultvar) \ : "a" (name) ASMARGS_##nr(args) : "memory", "cc") -# else /* GCC 5 */ -# define INTERNAL_SYSCALL_MAIN_INLINE(name, nr, args...) \ - EXTRAVAR_##nr \ - asm volatile ( \ - LOADARGS_##nr \ - "movl %1, %%eax\n\t" \ - "int $0x80\n\t" \ - RESTOREARGS_##nr \ - : "=a" (resultvar) \ - : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc") -# define INTERNAL_SYSCALL_MAIN_NCS(name, nr, args...) \ - EXTRAVAR_##nr \ - asm volatile ( \ - LOADARGS_##nr \ - "int $0x80\n\t" \ - RESTOREARGS_##nr \ - : "=a" (resultvar) \ - : "0" (name) ASMFMT_##nr(args) : "memory", "cc") -# endif /* GCC 5 */ -#endif - -#define LOADARGS_0 -#ifdef __PIC__ -# if I386_USE_SYSENTER && defined PIC -# define LOADARGS_1 \ - "bpushl .L__X'%k3, %k3\n\t" -# define LOADARGS_5 \ - "movl %%ebx, %4\n\t" \ - "movl %3, %%ebx\n\t" -# else -# define LOADARGS_1 \ - "bpushl .L__X'%k2, %k2\n\t" -# define LOADARGS_5 \ - "movl %%ebx, %3\n\t" \ - "movl %2, %%ebx\n\t" -# endif -# define LOADARGS_2 LOADARGS_1 -# define LOADARGS_3 \ - "xchgl %%ebx, %%edi\n\t" -# define LOADARGS_4 LOADARGS_3 -#else -# define LOADARGS_1 -# define LOADARGS_2 -# define LOADARGS_3 -# define LOADARGS_4 -# define LOADARGS_5 -#endif - -#define RESTOREARGS_0 -#ifdef __PIC__ -# if I386_USE_SYSENTER && defined PIC -# define RESTOREARGS_1 \ - "bpopl .L__X'%k3, %k3\n\t" -# define RESTOREARGS_5 \ - "movl %4, %%ebx" -# else -# define RESTOREARGS_1 \ - "bpopl .L__X'%k2, %k2\n\t" -# define RESTOREARGS_5 \ - "movl %3, %%ebx" -# endif -# define RESTOREARGS_2 RESTOREARGS_1 -# define RESTOREARGS_3 \ - "xchgl %%edi, %%ebx\n\t" -# define RESTOREARGS_4 RESTOREARGS_3 -#else -# define RESTOREARGS_1 -# define RESTOREARGS_2 -# define RESTOREARGS_3 -# define RESTOREARGS_4 -# define RESTOREARGS_5 -#endif +#endif /* !I386_USE_SYSENTER */ -#ifdef OPTIMIZE_FOR_GCC_5 -# define LOADREGS_0() -# define ASMARGS_0() -# define LOADREGS_1(arg1) \ +#define LOADREGS_0() +#define ASMARGS_0() +#define LOADREGS_1(arg1) \ LOADREGS_0 () -# define ASMARGS_1(arg1) \ +#define ASMARGS_1(arg1) \ ASMARGS_0 (), "b" ((unsigned int) (arg1)) -# define LOADREGS_2(arg1, arg2) \ +#define LOADREGS_2(arg1, arg2) \ LOADREGS_1 (arg1) -# define ASMARGS_2(arg1, arg2) \ +#define ASMARGS_2(arg1, arg2) \ ASMARGS_1 (arg1), "c" ((unsigned int) (arg2)) -# define LOADREGS_3(arg1, arg2, arg3) \ +#define LOADREGS_3(arg1, arg2, arg3) \ LOADREGS_2 (arg1, arg2) -# define ASMARGS_3(arg1, arg2, arg3) \ +#define ASMARGS_3(arg1, arg2, arg3) \ ASMARGS_2 (arg1, arg2), "d" ((unsigned int) (arg3)) -# define LOADREGS_4(arg1, arg2, arg3, arg4) \ +#define LOADREGS_4(arg1, arg2, arg3, arg4) \ LOADREGS_3 (arg1, arg2, arg3) -# define ASMARGS_4(arg1, arg2, arg3, arg4) \ +#define ASMARGS_4(arg1, arg2, arg3, arg4) \ ASMARGS_3 (arg1, arg2, arg3), "S" ((unsigned int) (arg4)) -# define LOADREGS_5(arg1, arg2, arg3, arg4, arg5) \ +#define LOADREGS_5(arg1, arg2, arg3, arg4, arg5) \ LOADREGS_4 (arg1, arg2, arg3, arg4) -# define ASMARGS_5(arg1, arg2, arg3, arg4, arg5) \ +#define ASMARGS_5(arg1, arg2, arg3, arg4, arg5) \ ASMARGS_4 (arg1, arg2, arg3, arg4), "D" ((unsigned int) (arg5)) -# define LOADREGS_6(arg1, arg2, arg3, arg4, arg5, arg6) \ - register unsigned int _a6 asm ("ebp") = (unsigned int) (arg6); \ - LOADREGS_5 (arg1, arg2, arg3, arg4, arg5) -# define ASMARGS_6(arg1, arg2, arg3, arg4, arg5, arg6) \ - ASMARGS_5 (arg1, arg2, arg3, arg4, arg5), "r" (_a6) -#endif /* GCC 5 */ #define ASMFMT_0() #ifdef __PIC__