This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


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

[PATCH] ia64 fix (when building with old GCC), errno optimization


Hi!

libc-symbols.h/bcopy.S is a fix for a problem reported by David.
If a compiler supports hidden, but not HAVE_BUILTIN_REDIRECTION
(such as vanilla GCC 3.3.x), bcopy will branch to non-existant symbol.
The rest is just optimization, to kill __errno_location PLT slot
in libc.so (and libpthread.so) killed.

2004-04-23  Jakub Jelinek  <jakub@redhat.com>

	* include/libc-symbols.h (HIDDEN_BUILTIN_JUMPTARGET): Define.
	* sysdeps/ia64/bcopy.S (bcopy): Use it for jump to memmove.

	* sysdeps/unix/sysv/linux/ia64/sysdep.S (__syscall_error): Access
	gprel errno if RTLD_PRIVATE_ERRNO or __thread __libc_errno/errno
	if USE___THREAD.
nptl/
	* sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h (SYSDEP_CANCEL_ERRNO,
	SYSDEP_CANCEL_ERROR): Define.
	(PSEUDO): Use it.

--- libc/include/libc-symbols.h.jj	2004-03-11 11:10:07.000000000 +0100
+++ libc/include/libc-symbols.h	2004-04-23 06:48:31.080058057 +0200
@@ -749,11 +749,17 @@ for linking")
 # define libc_hidden_builtin_def(name) libc_hidden_def (name)
 # define libc_hidden_builtin_weak(name) libc_hidden_weak (name)
 # define libc_hidden_builtin_ver(local, name) libc_hidden_ver (local, name)
+# ifdef __ASSEMBLER__
+#  define HIDDEN_BUILTIN_JUMPTARGET(name) HIDDEN_JUMPTARGET(name)
+# endif
 #else
 # define libc_hidden_builtin_proto(name, attrs...)
 # define libc_hidden_builtin_def(name)
 # define libc_hidden_builtin_weak(name)
 # define libc_hidden_builtin_ver(local, name)
+# ifdef __ASSEMBLER__
+#  define HIDDEN_BUILTIN_JUMPTARGET(name) JUMPTARGET(name)
+# endif
 #endif
 
 /* Get some dirty hacks.  */
--- libc/sysdeps/ia64/bcopy.S.jj	2004-04-22 22:39:24.000000000 +0200
+++ libc/sysdeps/ia64/bcopy.S	2004-04-23 06:49:03.761201170 +0200
@@ -6,5 +6,5 @@ ENTRY(bcopy)
 	mov in0 = in1
 	;;
 	mov in1 = r8
-	br.cond.sptk.many HIDDEN_JUMPTARGET(memmove)
+	br.cond.sptk.many HIDDEN_BUILTIN_JUMPTARGET(memmove)
 END(bcopy)
--- libc/nptl/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h.jj	2004-04-23 06:40:20.000000000 -0400
+++ libc/nptl/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h	2004-04-23 07:47:37.000000000 -0400
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
 
@@ -27,9 +27,58 @@
 
 # undef PSEUDO
 
-#ifndef USE_DL_SYSINFO
+# ifdef USE___THREAD
+#  ifndef NOT_IN_libc
+#   define SYSDEP_CANCEL_ERRNO __libc_errno
+#  else
+#   define SYSDEP_CANCEL_ERRNO errno
+#  endif
+#  define SYSDEP_CANCEL_ERROR(args)					      \
+.section .gnu.linkonce.t.__syscall_error_##args, "ax";			      \
+     .align 32;								      \
+     .proc __syscall_error_##args;					      \
+     .global __syscall_error_##args;					      \
+     .hidden __syscall_error_##args;					      \
+     .size __syscall_error_##args, 64;					      \
+__syscall_error_##args:							      \
+     .prologue;								      \
+     .regstk args, 5, args, 0;						      \
+     .save ar.pfs, loc0;						      \
+     .save rp, loc1;							      \
+     .body;								      \
+     addl loc4 = @ltoff(@tprel(SYSDEP_CANCEL_ERRNO)), gp;;		      \
+     ld8 loc4 = [loc4];							      \
+     mov rp = loc1;;							      \
+     mov r8 = -1;							      \
+     add loc4 = loc4, r13;;						      \
+     st4 [loc4] = loc3;							      \
+     mov ar.pfs = loc0
+# else
+#  define SYSDEP_CANCEL_ERROR(args)					      \
+.section .gnu.linkonce.t.__syscall_error_##args, "ax";			      \
+     .align 32;								      \
+     .proc __syscall_error_##args;					      \
+     .global __syscall_error_##args;					      \
+     .hidden __syscall_error_##args;					      \
+     .size __syscall_error_##args, 64;					      \
+__syscall_error_##args:							      \
+     .prologue;								      \
+     .regstk args, 5, args, 0;						      \
+     .save ar.pfs, loc0;						      \
+     .save rp, loc1;							      \
+     .body;								      \
+     mov loc4 = r1;;							      \
+     br.call.sptk.many b0 = __errno_location;;				      \
+     st4 [r8] = loc3;							      \
+     mov r1 = loc4;							      \
+     mov rp = loc1;							      \
+     mov r8 = -1;							      \
+     mov ar.pfs = loc0
+# endif
 
-# define PSEUDO(name, syscall_name, args)				      \
+# ifndef USE_DL_SYSINFO
+
+#  define PSEUDO(name, syscall_name, args)				      \
 .text;									      \
 ENTRY (name)								      \
      adds r14 = MULTIPLE_THREADS_OFFSET, r13;;				      \
@@ -71,29 +120,11 @@ __GC_##name:								      \
 .Lpseudo_end:								      \
      ret;								      \
      .endp __GC_##name;							      \
-.section .gnu.linkonce.t.__syscall_error_##args, "ax";			      \
-     .align 32;								      \
-     .proc __syscall_error_##args;					      \
-     .global __syscall_error_##args;					      \
-     .hidden __syscall_error_##args;					      \
-     .size __syscall_error_##args, 64;					      \
-__syscall_error_##args:							      \
-     .prologue;								      \
-     .regstk args, 5, args, 0;						      \
-     .save ar.pfs, loc0;						      \
-     .save rp, loc1;							      \
-     .body;								      \
-     mov loc4 = r1;;							      \
-     br.call.sptk.many b0 = __errno_location;;				      \
-     st4 [r8] = loc3;							      \
-     mov r1 = loc4;							      \
-     mov rp = loc1;							      \
-     mov r8 = -1;							      \
-     mov ar.pfs = loc0
+     SYSDEP_CANCEL_ERROR(args)
 
-#else /* USE_DL_SYSINFO */
+# else /* USE_DL_SYSINFO */
 
-# define PSEUDO(name, syscall_name, args)				      \
+#  define PSEUDO(name, syscall_name, args)				      \
 .text;									      \
 ENTRY (name)								      \
      .prologue;								      \
@@ -146,30 +177,12 @@ __GC_##name:								      \
 .Lpseudo_end:								      \
      ret;								      \
      .endp __GC_##name;							      \
-.section .gnu.linkonce.t.__syscall_error_##args, "ax";			      \
-     .align 32;								      \
-     .proc __syscall_error_##args;					      \
-     .global __syscall_error_##args;					      \
-     .hidden __syscall_error_##args;					      \
-     .size __syscall_error_##args, 64;					      \
-__syscall_error_##args:							      \
-     .prologue;								      \
-     .regstk args, 5, args, 0;						      \
-     .save ar.pfs, loc0;						      \
-     .save rp, loc1;							      \
-     .body;								      \
-     mov loc4 = r1;;							      \
-     br.call.sptk.many b0 = __errno_location;;				      \
-     st4 [r8] = loc3;							      \
-     mov r1 = loc4;							      \
-     mov rp = loc1;							      \
-     mov r8 = -1;							      \
-     mov ar.pfs = loc0
+     SYSDEP_CANCEL_ERROR(args)
 
-#endif /* USE_DL_SYSINFO */
+# endif /* USE_DL_SYSINFO */
 
-#undef PSEUDO_END
-#define PSEUDO_END(name) .endp
+# undef PSEUDO_END
+# define PSEUDO_END(name) .endp
 
 # ifdef IS_IN_libpthread
 #  define CENABLE	br.call.sptk.many b0 = __pthread_enable_asynccancel
@@ -184,14 +197,14 @@ __syscall_error_##args:							      \
 #  error Unsupported library
 # endif
 
-#define COPY_ARGS_0	/* Nothing */
-#define COPY_ARGS_1	COPY_ARGS_0 mov out0 = in0;
-#define COPY_ARGS_2	COPY_ARGS_1 mov out1 = in1;
-#define COPY_ARGS_3	COPY_ARGS_2 mov out2 = in2;
-#define COPY_ARGS_4	COPY_ARGS_3 mov out3 = in3;
-#define COPY_ARGS_5	COPY_ARGS_4 mov out4 = in4;
-#define COPY_ARGS_6	COPY_ARGS_5 mov out5 = in5;
-#define COPY_ARGS_7	COPY_ARGS_6 mov out6 = in6;
+# define COPY_ARGS_0	/* Nothing */
+# define COPY_ARGS_1	COPY_ARGS_0 mov out0 = in0;
+# define COPY_ARGS_2	COPY_ARGS_1 mov out1 = in1;
+# define COPY_ARGS_3	COPY_ARGS_2 mov out2 = in2;
+# define COPY_ARGS_4	COPY_ARGS_3 mov out3 = in3;
+# define COPY_ARGS_5	COPY_ARGS_4 mov out4 = in4;
+# define COPY_ARGS_6	COPY_ARGS_5 mov out5 = in5;
+# define COPY_ARGS_7	COPY_ARGS_6 mov out6 = in6;
 
 # ifndef __ASSEMBLER__
 #  define SINGLE_THREAD_P \
--- libc/sysdeps/unix/sysv/linux/ia64/sysdep.S.jj	2003-02-27 04:32:40.000000000 -0500
+++ libc/sysdeps/unix/sysv/linux/ia64/sysdep.S	2004-04-23 07:59:53.000000000 -0400
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1999, 2000, 2001, 2003, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by David Mosberger-Tang <davidm@hpl.hp.com>.
 
@@ -19,9 +19,34 @@
 
 #include <sysdep.h>
 #include <features.h>
+#include <tls.h>
 
 ENTRY(__syscall_error)
-#ifdef _LIBC_REENTRANT
+#if RTLD_PRIVATE_ERRNO
+	/*
+	 * Note that the gp has to be set properly for this to work.
+	 * As long as all syscalls are in the same load unit
+	 * (executable or shared library) as this routine, we should
+	 * be fine.  Otherwise, we would have to first load the global
+	 * pointer register from __gp.
+	 */
+	addl	r2=@gprel(errno),gp
+	;;
+	st4	[r2]=r8
+	mov	r8=-1
+#elif defined USE___THREAD
+# ifndef NOT_IN_libc
+#  define SYSCALL_ERROR_ERRNO __libc_errno
+# else
+#  define SYSCALL_ERROR_ERRNO errno
+# endif
+	addl	r2=@ltoff(@tprel(SYSCALL_ERROR_ERRNO)), gp;;
+	ld8	r2=[r2]
+	mov	r3=r8;;
+	mov	r8=-1
+	add	r2=r2,r13;;
+	st4	[r2]=r3
+#elif defined _LIBC_REENTRANT
 	.prologue ASM_UNW_PRLG_RP|ASM_UNW_PRLG_PFS, ASM_UNW_PRLG_GRSAVE(0)
 	alloc	r33=ar.pfs, 0, 4, 0, 0
 	mov	r32=rp

	Jakub


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