Skip to contentSkip to conversation

glibc fsyscall patch

Linux-ia64 Ian Wienand 1 participant 1 message Apr 9, 2003

lore
Share & tools
lore
#0 lore raw

Hello,

An updated version of David M's patch posted at
https://lists.linuxia64.org/archives//linux-ia64/2003-February/004656.html
is attached. The libc part should apply ontop libc cvs and the NPTL part with NPTL 0.34. To build I used

../libc/configure --with-tls --with-__thread
--with-headers=/usr/src/linux-2.5.64/include
--enable-add-ons=nptl --prefix=/usr CC=gcc-snap

where gcc-snap is the latest 3.3 snapshot [*]. You will obviously need a kernel that is sufficient to run NPTL and have fsyscall support enabled.

I can make some debian archives of this if it would help people to test it. It passes make check (except for known failures) and we here at Gelato@UNSW will be using it internally, but at the moment all I would say is "works for me".

Regards,

-i
[email protected]
http://www.gelato.unsw.edu.au

[*] I have seen problems with 3.3 snapshots locking up the system and causing a machine check. I would be interested if anyone using redhat and their gcc 3.2 with the backported __thread changes sees this problem.

? fsyscall-libc.diff
? nptl
? nptl_db
Index: sysdeps/unix/sysv/linux/dl-osinfo.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/dl-osinfo.h,v retrieving revision 1.13

unix/sysv/linux/dl-osinfo.h +5 -2
diff -u -w -r1.13 dl-osinfo.h
@@ -53,9 +53,12 @@
 	int parts;							      \
 	char *cp;							      \
 	struct utsname uts;						      \
+	int uname_err;								\
 									      \
-	/* Try the uname syscall */					      \
-	if (__uname (&uts))					      	      \
+ 	/* use an inline call incase TLS isn't setup and something 		\
+	   like fast syscalls are in use */					\
+	INTERNAL_SYSCALL(uname,uname_err,1,&uts);				\
+	if ( uname_err )							\
 	  {							      	      \
 	    /* This was not successful.  Now try reading the /proc	      \
 	       filesystem.  */						      \

Index: sysdeps/unix/sysv/linux/ia64/clone2.S
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/ia64/clone2.S,v retrieving revision 1.7

unix/sysv/linux/ia64/clone2.S +27 -14

66 lines not on this page · raw message

Index: sysdeps/unix/sysv/linux/ia64/sysdep.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/ia64/sysdep.h,v retrieving revision 1.14

unix/sysv/linux/ia64/sysdep.h +23 -0
diff -u -w -r1.14 sysdep.h
@@ -24,6 +24,8 @@
 #include <sysdeps/unix/sysdep.h>
 #include <sysdeps/ia64/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
@@ -89,9 +91,30 @@
 	cmp.eq p6,p0=-1,r10;			\
 (p6)	br.cond.spnt.few __syscall_error;
 
+#if defined HAVE_TLS_SUPPORT && (!defined NOT_IN_libc || defined IS_IN_libpthread)
+
+/* Use the lightweight stub only if (a) we have a suitably modern
+   thread-control block (HAVE_TLS_SUPPORT) and (b) we're not compiling
+   the runtime loader (which might do syscalls before being fully
+   relocated). */
+
+#define DO_CALL(num)				\
+	.prologue;				\
+        adds r2 = SYSINFO_OFFSET, r13;;		\
+        ld8 r2 = [r2];				\
+	.save ar.pfs, r11;			\
+        mov r11 = ar.pfs;;			\
+	.body;					\
+	mov r15 = num;				\
+        mov b7 = r2;				\
+        br.call.sptk.many b6 = b7;;		\
+	.restore sp;				\
+        mov ar.pfs = r11
+#else
 #define DO_CALL(num)				\
 	mov r15=num;				\
 	break __BREAK_SYSCALL;
+#endif
 
 #undef PSEUDO_END
 #define PSEUDO_END(name)	.endp C_SYMBOL_NAME(name);

Index: sysdeps/unix/sysv/linux/ia64/vfork.S
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/ia64/vfork.S,v retrieving revision 1.4

unix/sysv/linux/ia64/vfork.S +5 -1
diff -u -w -r1.4 vfork.S
@@ -34,9 +34,13 @@
 	mov out0=CLONE_VM+CLONE_VFORK+SIGCHLD
 	mov out1=0		/* Standard sp value.			*/
 	;;
+#if 0
 	DO_CALL (SYS_ify (clone))
+#else
+	mov r15=SYS_ify(clone)
+	break __BREAK_SYSCALL
+#endif
 	cmp.eq p6,p0=-1,r10
-	;;
 (p6)	br.cond.spnt.few __syscall_error
 	ret
 PSEUDO_END(__vfork)

Index: allocatestack.c
===================================================================
RCS file: /home/ianw/cvs/nptl/allocatestack.c,v
retrieving revision 1.1.1.3
retrieving revision 1.5
diff -u -r1.1.1.3 -r1.5
Index: descr.h
===================================================================
RCS file: /home/ianw/cvs/nptl/descr.h,v
retrieving revision 1.1.1.3
retrieving revision 1.7

descr.h +7 -1
diff -u -r1.1.1.3 -r1.7
@@ -62,10 +62,16 @@
 #if !TLS_DTV_AT_TP
     /* This overlaps the TCB as used for TLS without threads (see tls.h).  */
     tcbhead_t header;
-#elif TLS_MULTIPLE_THREADS_IN_TCB
+    /* For arch's who don't have room in the TCB */
+#elif (TLS_MULTIPLE_THREADS_IN_TCB || TLS_SYSINFO_IN_TCB)
     struct
     {
+      #if TLS_MULTIPLE_THREADS_IN_TCB
       int multiple_threads;
+      #endif
+      #if TLS_SYSINFO_IN_TCB
+      uintptr_t sysinfo;
+      #endif
     } header;
 #endif
 

Index: sysdeps/ia64/tcb-offsets.sym
===================================================================
RCS file: /home/ianw/cvs/nptl/sysdeps/ia64/tcb-offsets.sym,v retrieving revision 1.1.1.2
retrieving revision 1.5

ia64/tcb-offsets.sym +4 -0
diff -u -r1.1.1.2 -r1.5
@@ -2,3 +2,7 @@
 #include <tls.h>
 
 MULTIPLE_THREADS_OFFSET offsetof (struct pthread, header.multiple_threads) - sizeof (struct pthread)
+
+#ifdef TLS_SYSINFO_IN_TCB
+SYSINFO_OFFSET		offsetof (struct pthread, header.sysinfo) - sizeof (struct pthread)
+#endif

Index: sysdeps/ia64/tls.h
===================================================================
RCS file: /home/ianw/cvs/nptl/sysdeps/ia64/tls.h,v retrieving revision 1.1.1.1
retrieving revision 1.6

ia64/tls.h +32 -4
diff -u -r1.1.1.1 -r1.6
@@ -27,6 +27,22 @@
 # include <stdlib.h>
 # include <list.h>
 
+/* TLS LAYOUT
+
+ The IA64 ABI specifies that after the thread pointer there is a
+ pointer to the DTV and a private pointer.  Consequently in NPTL the
+ thread descriptor is placed directly before the thread pointer (this
+ is significantly cleaner than using indirection with the private
+ pointer).
+
+ [struct pthread][dtv][private][static tls block]
+     tp (r13)----^
+ [ in descr.h   ][ tcbhead_t  ]
+
+ Note that space is made for the descriptor during TLS setup with the
+ use of TCB_PRE_TCB_SIZE.
+
+*/
 
 /* Type for the dtv.  */
 typedef union dtv
@@ -35,14 +51,16 @@
   void *pointer;
 } dtv_t;
 
-
 typedef struct
 {
   dtv_t *dtv;
   void *private;
 } tcbhead_t;
 
+/* As TCB_DTV_AT_TP doesn't allow us more room in the tcbhead defined
+   above, we have extra pointers in our thread descriptor.  */
 # define TLS_MULTIPLE_THREADS_IN_TCB 1
+# define TLS_SYSINFO_IN_TCB 1
 
 #else /* __ASSEMBLER__ */
 # include <tcb-offsets.h>
@@ -100,11 +118,21 @@
 #  define GET_DTV(descr) \
   (((tcbhead_t *) (descr))->dtv)
 
+/* The room for the thread descriptor is allocated thanks to setting
+   TLS_PRE_TCB_SIZE so we are safe set this here */
+#if NEED_DL_SYSINFO
+# define INIT_SYSINFO \
+  THREAD_SELF->header.sysinfo = GL(dl_sysinfo)
+#else
+# define INIT_SYSINFO
+#endif
+
 /* Code to initially initialize the thread pointer.  This might need
    special attention since 'errno' is not yet available and if the
-   operation can cause a failure 'errno' must not be touched.  */
-# define TLS_INIT_TP(thrdescr, secondcall) \
-  (__thread_self = (thrdescr), NULL)
+   operation can cause a failure 'errno' must not be touched.  This
+   should return a string error, but we really can't fail */
+#define TLS_INIT_TP(thrdescr, secondcall) \
+ ( __thread_self = (thrdescr) , INIT_SYSINFO , NULL )
 
 /* Return the address of the dtv for the current thread.  */
 #  define THREAD_DTV() \

Index: sysdeps/pthread/createthread.c
===================================================================
RCS file: /home/ianw/cvs/nptl/sysdeps/pthread/createthread.c,v retrieving revision 1.1.1.3
retrieving revision 1.4

pthread/createthread.c +1 -1
diff -u -r1.1.1.3 -r1.4
@@ -113,7 +113,7 @@
 	}
     }
 
-#ifdef NEED_DL_SYSINFO
+#ifdef NEED_DL_SYSINFO 
   assert (THREAD_GETMEM (THREAD_SELF, header.sysinfo) == pd->header.sysinfo);
 #endif
 

Index: sysdeps/unix/sysv/linux/ia64/dl-sysdep.h
===================================================================
RCS file: sysdeps/unix/sysv/linux/ia64/dl-sysdep.h

unix/sysv/linux/ia64/dl-sysdep.h new file +44 -0

44 lines not on this page · raw message

Index: sysdeps/unix/sysv/linux/ia64/lowlevellock.h
===================================================================
RCS file: /home/ianw/cvs/nptl/sysdeps/unix/sysv/linux/ia64/lowlevellock.h,v retrieving revision 1.1.1.4
retrieving revision 1.2
diff -u -r1.1.1.4 -r1.2