This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] i386: Remove support for GCC versions before 5 from <sysdep.h>


* Joseph Myers:

> On Thu, 31 Jan 2019, Florian Weimer wrote:
>
>> Tested on i386.
>
> Has profiling libc and building with -fno-omit-frame-pointer been tested 
> (since the comment on OPTIMIZE_FOR_GCC_5 suggests it's also relevant for 
> those cases)?

Ouch, thanks for catching that.  Somehow I managed not look at the
actual macro definition.  It is still needed for profiling builds.

What about the patch below instead?  I tested it on i386 with and
without profiling.

Thanks,
Florian
---

i386: Use more descriptive name for OPTIMIZE_FOR_GCC_5 macro

It is now called I386_USE_EBP_IN_ASM_CONSTRAINTS.

Remove GCC version checks for GCC 5.  CAN_USE_REGISTER_ASM_EBP is
always defined, so remove it (along with the configure check).

2019-02-01  Florian Weimer  <fweimer@redhat.com>

	i386: Update macro selection for the use of %ebp in asm constraints.
	* sysdeps/unix/sysv/linux/i386/sysdep.h
	(OPTIMIZE_FOR_GCC_5): Remove.
	(I386_USE_EBP_IN_ASM_CONSTRAINTS): Define based on PROF.  Use
	throughout the file instead of OPTIMIZE_FOR_GCC_5.
	(check_consistency): Remove.
	* elf/dl-load.c (_dl_map_object_from_fd): Remove call to
	check_consistency.
	* sysdeps/unix/sysv/linux/dl-execstack.c
	(_dl_make_stack_executable): Likewise.
	* config.h (CAN_USE_REGISTER_ASM_EBP): Remove.
	* sysdeps/unix/sysv/linux/i386/configure.ac: Remove check for
	CAN_USE_REGISTER_ASM_EBP.
	* sysdeps/unix/sysv/linux/i386/configure: Regenerate.
	* sysdeps/unix/sysv/linux/i386/libc-do-syscall.S: Use
	I386_USE_EBP_IN_ASM_CONSTRAINTS instead of OPTIMIZE_FOR_GCC_5.

diff --git a/config.h.in b/config.h.in
index f059ec0435..761e8a0942 100644
--- a/config.h.in
+++ b/config.h.in
@@ -255,8 +255,4 @@
 /* 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
-
 #endif
diff --git a/elf/dl-load.c b/elf/dl-load.c
index f972524421..80c23446ba 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1281,10 +1281,6 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
 #endif
 	__stack_prot |= PROT_READ|PROT_WRITE|PROT_EXEC;
 
-#ifdef check_consistency
-      check_consistency ();
-#endif
-
       errval = (*GL(dl_make_stack_executable_hook)) (stack_endp);
       if (errval)
 	{
diff --git a/sysdeps/unix/sysv/linux/dl-execstack.c b/sysdeps/unix/sysv/linux/dl-execstack.c
index ac1aa72f3b..28f3bd90e0 100644
--- a/sysdeps/unix/sysv/linux/dl-execstack.c
+++ b/sysdeps/unix/sysv/linux/dl-execstack.c
@@ -50,10 +50,6 @@ _dl_make_stack_executable (void **stack_endp)
   GL(dl_stack_flags) |= PF_X;
 
  out:
-#ifdef check_consistency
-  check_consistency ();
-#endif
-
   return result;
 }
 rtld_hidden_def (_dl_make_stack_executable)
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/libc-do-syscall.S b/sysdeps/unix/sysv/linux/i386/libc-do-syscall.S
index 9119cfdf01..20841fb265 100644
--- a/sysdeps/unix/sysv/linux/i386/libc-do-syscall.S
+++ b/sysdeps/unix/sysv/linux/i386/libc-do-syscall.S
@@ -18,7 +18,7 @@
 
 #include <sysdep.h>
 
-#ifndef OPTIMIZE_FOR_GCC_5
+#if !I386_USE_EBP_IN_ASM_CONSTRAINTS
 
 /* %eax, %ecx, %edx and %esi contain the values expected by the kernel.
    %edi points to a structure with the values of %ebx, %edi and %ebp.  */
diff --git a/sysdeps/unix/sysv/linux/i386/sysdep.h b/sysdeps/unix/sysv/linux/i386/sysdep.h
index 0be10744ff..e2f3fcf1ca 100644
--- a/sysdeps/unix/sysv/linux/i386/sysdep.h
+++ b/sysdeps/unix/sysv/linux/i386/sysdep.h
@@ -46,13 +46,12 @@
 # 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 __GNUC_PREREQ (5,0) && !defined PROF && CAN_USE_REGISTER_ASM_EBP
-# define OPTIMIZE_FOR_GCC_5
+/* When profiling is enabled, GCC cannot spill the %ebp register, so
+   it cannot be used directly in constraints in inline assembly.  */
+#ifdef PROF
+# define I386_USE_EBP_IN_ASM_CONSTRAINTS 0
+#else
+# define I386_USE_EBP_IN_ASM_CONSTRAINTS 1
 #endif
 
 #ifdef __ASSEMBLER__
@@ -241,7 +240,7 @@
 extern int __syscall_error (int)
   attribute_hidden __attribute__ ((__regparm__ (1)));
 
-#ifndef OPTIMIZE_FOR_GCC_5
+#if !I386_USE_EBP_IN_ASM_CONSTRAINTS
 /* 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"
@@ -338,10 +337,10 @@ struct libc_do_syscall_args
     INTERNAL_SYSCALL_MAIN_INLINE(name, err, 5, args)
 /* Each object using 6-argument inline syscalls must include a
    definition of __libc_do_syscall.  */
-#ifdef OPTIMIZE_FOR_GCC_5
+#if I386_USE_EBP_IN_ASM_CONSTRAINTS
 # define INTERNAL_SYSCALL_MAIN_6(name, err, args...) \
     INTERNAL_SYSCALL_MAIN_INLINE(name, err, 6, args)
-#else /* GCC 5  */
+#else /* !I386_USE_EBP_IN_ASM_CONSTRAINTS  */
 # define INTERNAL_SYSCALL_MAIN_6(name, err, arg1, arg2, arg3,		\
 				 arg4, arg5, arg6)			\
   struct libc_do_syscall_args _xv =					\
@@ -356,14 +355,14 @@ struct libc_do_syscall_args
     : "=a" (resultvar)							\
     : "i" (__NR_##name), "c" (arg2), "d" (arg3), "S" (arg4), "D" (&_xv) \
     : "memory", "cc")
-#endif /* GCC 5  */
+#endif /* !I386_USE_EBP_IN_ASM_CONSTRAINTS  */
 #define INTERNAL_SYSCALL(name, err, nr, args...) \
   ({									      \
     register unsigned int resultvar;					      \
     INTERNAL_SYSCALL_MAIN_##nr (name, err, args);			      \
     (int) resultvar; })
 #if I386_USE_SYSENTER
-# ifdef OPTIMIZE_FOR_GCC_5
+# if I386_USE_EBP_IN_ASM_CONSTRAINTS
 #  ifdef PIC
 #   define INTERNAL_SYSCALL_MAIN_INLINE(name, err, nr, args...) \
     LOADREGS_##nr(args)							\
@@ -399,7 +398,7 @@ struct libc_do_syscall_args
     : "a" (name) ASMARGS_##nr(args) : "memory", "cc");			\
     (int) resultvar; })
 #  endif
-# else /* GCC 5  */
+# else /* !I386_USE_EBP_IN_ASM_CONSTRAINTS  */
 #  ifdef PIC
 #   define INTERNAL_SYSCALL_MAIN_INLINE(name, err, nr, args...) \
     EXTRAVAR_##nr							      \
@@ -445,9 +444,9 @@ struct libc_do_syscall_args
     : "0" (name) ASMFMT_##nr(args) : "memory", "cc");			      \
     (int) resultvar; })
 #  endif
-# endif /* GCC 5  */
+# endif /* !I386_USE_EBP_IN_ASM_CONSTRAINTS  */
 #else
-# ifdef OPTIMIZE_FOR_GCC_5
+# if I386_USE_EBP_IN_ASM_CONSTRAINTS
 #  define INTERNAL_SYSCALL_MAIN_INLINE(name, err, nr, args...) \
     LOADREGS_##nr(args)							\
     asm volatile (							\
@@ -463,7 +462,7 @@ struct libc_do_syscall_args
     : "=a" (resultvar)							\
     : "a" (name) ASMARGS_##nr(args) : "memory", "cc");			\
     (int) resultvar; })
-# else /* GCC 5  */
+# else /* !I386_USE_EBP_IN_ASM_CONSTRAINTS  */
 #  define INTERNAL_SYSCALL_MAIN_INLINE(name, err, nr, args...) \
     EXTRAVAR_##nr							      \
     asm volatile (							      \
@@ -484,7 +483,7 @@ struct libc_do_syscall_args
     : "=a" (resultvar)							      \
     : "0" (name) ASMFMT_##nr(args) : "memory", "cc");			      \
     (int) resultvar; })
-# endif /* GCC 5  */
+# endif /* !I386_USE_EBP_IN_ASM_CONSTRAINTS  */
 #endif
 
 #undef INTERNAL_SYSCALL_DECL
@@ -549,7 +548,7 @@ struct libc_do_syscall_args
 # define RESTOREARGS_5
 #endif
 
-#ifdef OPTIMIZE_FOR_GCC_5
+#if I386_USE_EBP_IN_ASM_CONSTRAINTS
 # define LOADREGS_0()
 # define ASMARGS_0()
 # define LOADREGS_1(arg1) \
@@ -577,7 +576,7 @@ struct libc_do_syscall_args
 	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  */
+#endif /* !I386_USE_EBP_IN_ASM_CONSTRAINTS  */
 
 #define ASMFMT_0()
 #ifdef __PIC__
@@ -615,20 +614,6 @@ struct libc_do_syscall_args
 # define EXTRAVAR_5
 #endif
 
-/* Consistency check for position-independent code.  */
-#if defined __PIC__ && !defined OPTIMIZE_FOR_GCC_5
-# define check_consistency()						      \
-  ({ int __res;								      \
-     __asm__ __volatile__						      \
-       (LOAD_PIC_REG_STR (cx) ";"					      \
-	"subl %%ebx, %%ecx;"						      \
-	"je 1f;"							      \
-	"ud2;"								      \
-	"1:\n"								      \
-	: "=c" (__res));						      \
-     __res; })
-#endif
-
 #endif	/* __ASSEMBLER__ */
 
 
--
Work around Zimbra bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]