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 Fri, 1 Feb 2019, Florian Weimer wrote:
>
>> What about the patch below instead?  I tested it on i386 with and
>> without profiling.
>
> What about -fno-omit-frame-pointer?  CAN_USE_REGISTER_ASM_EBP is also for 
> that.

Well, this is getting embarrassing.  Here's the next attempt.  This time
tested on i386 (four builds, with/without -fno-omit-frame-pointer,
--enable-profile) and x86-64.

Not much can in fact be removed, but I think it's still worthwhile to
use a more descriptive macro and document the situation in comments.

Thanks,
Florian

i386: Use I386_USE_REGISTER_ASM_EBP instead of OPTIMIZE_FOR_GCC_5

Make I386_USE_REGISTER_ASM_EBP always defined, with 0 or 1 as
appropriate, relying on CAN_USE_REGISTER_ASM_EBP for the non-profiling
case.  (CAN_USE_REGISTER_ASM_EBP continues to reflect the compiler
behavior with default/user-specified flags.)

Remove the check_consistency hardening check.  %ebx is not preserved
in non-profiling, non-frame-pointer builds (the default), so the
check was already disabled in most configurations.

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

	* sysdeps/unix/sysv/linux/i386/sysdep.h
	(OPTIMIZE_FOR_GCC_5): Remove.
	(I386_USE_REGISTER_ASM_EBP): New macro. Replace references to
	OPTIMIZE_FOR_GCC_5 throughout the this file.
	(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.in (CAN_USE_REGISTER_ASM): Update comment.
	* sysdeps/unix/sysv/linux/i386/libc-do-syscall.S: Use
	I386_USE_REGISTER_ASM_EBP instead of OPTIMIZE_FOR_GCC_5.

diff --git a/config.h.in b/config.h.in
index f059ec0435..a21c31cc96 100644
--- a/config.h.in
+++ b/config.h.in
@@ -255,8 +255,13 @@
 /* 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).  */
+/* Some configurations may not allow to use of the i386 %ebp register
+   in inline assembly.  In this case, this macro is defined as 0.
+   Note that this macro only reflects the compiler behavior with the
+   default/user-specified flags.  Profiling builds can never use %ebp
+   in this way because they require a frame pointer.  See
+   I386_USE_REGISTER_EBP in sysdeps/unix/sysv/linux/i386/sysdep.h for
+   the macro that actual code should check.  */
 #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/libc-do-syscall.S b/sysdeps/unix/sysv/linux/i386/libc-do-syscall.S
index 9119cfdf01..4361c6ec3c 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_REGISTER_ASM_EBP
 
 /* %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.  */
@@ -50,4 +50,4 @@ ENTRY (__libc_do_syscall)
 	cfi_restore (ebx)
 	ret
 END (__libc_do_syscall)
-#endif
+#endif /* !I386_USE_REGISTER_ASM_EBP */
diff --git a/sysdeps/unix/sysv/linux/i386/sysdep.h b/sysdeps/unix/sysv/linux/i386/sysdep.h
index 0be10744ff..033e10a322 100644
--- a/sysdeps/unix/sysv/linux/i386/sysdep.h
+++ b/sysdeps/unix/sysv/linux/i386/sysdep.h
@@ -29,7 +29,6 @@
 #include <dl-sysdep.h>
 #include <tls.h>
 
-
 /* For Linux we can use the system call table in the header file
 	/usr/include/asm/unistd.h
    of the kernel.  But these symbols do not follow the SYS_* syntax
@@ -46,15 +45,19 @@
 # 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
+/* Indicator for whether inline assembly can use the %ebp register.
+   The configure script only detects the compiler behavior with
+   default compiler flags.  In a profiling build, a frame pointer is
+   always required, so %ebp is never usable.  Code should always check
+   I386_USE_REGISTER_ASM_EBP for this reason, and not
+   CAN_USE_REGISTER_ASM_EBP.  */
+#ifdef PROF
+# define I386_USE_REGISTER_ASM_EBP 0
+#else
+# define I386_USE_REGISTER_ASM_EBP CAN_USE_REGISTER_ASM_EBP
 #endif
 
+
 #ifdef __ASSEMBLER__
 
 /* Linux uses a negative return value to indicate syscall errors,
@@ -241,7 +244,7 @@
 extern int __syscall_error (int)
   attribute_hidden __attribute__ ((__regparm__ (1)));
 
-#ifndef OPTIMIZE_FOR_GCC_5
+#if !I386_USE_REGISTER_ASM_EBP
 /* 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 +341,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_REGISTER_ASM_EBP
 # define INTERNAL_SYSCALL_MAIN_6(name, err, args...) \
     INTERNAL_SYSCALL_MAIN_INLINE(name, err, 6, args)
-#else /* GCC 5  */
+#else /* !I386_USE_REGISTER_ASM_EBP */
 # define INTERNAL_SYSCALL_MAIN_6(name, err, arg1, arg2, arg3,		\
 				 arg4, arg5, arg6)			\
   struct libc_do_syscall_args _xv =					\
@@ -356,14 +359,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_REGISTER_ASM_EBP */
 #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_REGISTER_ASM_EBP
 #  ifdef PIC
 #   define INTERNAL_SYSCALL_MAIN_INLINE(name, err, nr, args...) \
     LOADREGS_##nr(args)							\
@@ -399,7 +402,7 @@ struct libc_do_syscall_args
     : "a" (name) ASMARGS_##nr(args) : "memory", "cc");			\
     (int) resultvar; })
 #  endif
-# else /* GCC 5  */
+# else /* !I386_USE_REGISTER_ASM_EBP */
 #  ifdef PIC
 #   define INTERNAL_SYSCALL_MAIN_INLINE(name, err, nr, args...) \
     EXTRAVAR_##nr							      \
@@ -445,9 +448,9 @@ struct libc_do_syscall_args
     : "0" (name) ASMFMT_##nr(args) : "memory", "cc");			      \
     (int) resultvar; })
 #  endif
-# endif /* GCC 5  */
+# endif /* !I386_USE_REGISTER_ASM_EBP */
 #else
-# ifdef OPTIMIZE_FOR_GCC_5
+# if I386_USE_REGISTER_ASM_EBP
 #  define INTERNAL_SYSCALL_MAIN_INLINE(name, err, nr, args...) \
     LOADREGS_##nr(args)							\
     asm volatile (							\
@@ -463,7 +466,7 @@ struct libc_do_syscall_args
     : "=a" (resultvar)							\
     : "a" (name) ASMARGS_##nr(args) : "memory", "cc");			\
     (int) resultvar; })
-# else /* GCC 5  */
+# else /* !I386_USE_REGISTER_ASM_EBP */
 #  define INTERNAL_SYSCALL_MAIN_INLINE(name, err, nr, args...) \
     EXTRAVAR_##nr							      \
     asm volatile (							      \
@@ -484,7 +487,7 @@ struct libc_do_syscall_args
     : "=a" (resultvar)							      \
     : "0" (name) ASMFMT_##nr(args) : "memory", "cc");			      \
     (int) resultvar; })
-# endif /* GCC 5  */
+# endif /* !I386_USE_REGISTER_ASM_EBP */
 #endif
 
 #undef INTERNAL_SYSCALL_DECL
@@ -549,7 +552,7 @@ struct libc_do_syscall_args
 # define RESTOREARGS_5
 #endif
 
-#ifdef OPTIMIZE_FOR_GCC_5
+#if I386_USE_REGISTER_ASM_EBP
 # define LOADREGS_0()
 # define ASMARGS_0()
 # define LOADREGS_1(arg1) \
@@ -577,7 +580,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_REGISTER_ASM_EBP */
 
 #define ASMFMT_0()
 #ifdef __PIC__
@@ -615,20 +618,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__ */
 
 


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