This is the mail archive of the glibc-cvs@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]

GNU C Library master sources branch azanella/bz12683 created. glibc-2.24-719-g9deb03e


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, azanella/bz12683 has been created
        at  9deb03eea85c5b047e8ca0d8ddb1c9e5349107e0 (commit)

- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=9deb03eea85c5b047e8ca0d8ddb1c9e5349107e0

commit 9deb03eea85c5b047e8ca0d8ddb1c9e5349107e0
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Wed Jan 25 17:08:51 2017 -0200

    nptl: Consolidate pthread_{timed,try}join{_np}
    
    This patch consolidates the pthread_join and gnu extensions to avoid
    simplify implementation and avoid code duplication.  Both pthread_join
    and pthread_tryjoin are now based on pthread_timedjoin_np.
    
    It also fixes some inconsistencies on ESRCH, EINVAL, EDEADLK handling
    (where each implementation differs from each other) and also on
    clenup handler (which now always use a CAS).  It also replace the
    atomics operation with the C11 ones.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* nptl/pthreadP.h (__pthread_timedjoin_np): Define.
    	* nptl/pthread_join.c (pthread_join): Use __pthread_timedjoin_np.
    	* nptl/pthread_tryjoin.c (pthread_tryjoin): Likewise.
    	* nptl/pthread_timedjoin.c (cleanup): Use CAS on argument setting.
    	(pthread_timedjoin_np): Define internal symbol and common code from
    	pthread_join.
    	* sysdeps/unix/sysv/linux/i386/lowlevellock.h (__lll_timedwait_tid):
    	Remove superflous checks.
    	* sysdeps/unix/sysv/linux/x86_64/lowlevellock.h (__lll_timedwait_tid):
    	Likewise.

diff --git a/ChangeLog b/ChangeLog
index a2241d4..7edab8e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* nptl/pthreadP.h (__pthread_timedjoin_np): Define.
+	* nptl/pthread_join.c (pthread_join): Use __pthread_timedjoin_np.
+	* nptl/pthread_timedjoin.c (cleanup): Use CAS on argument setting.
+	(pthread_timedjoin_np): Define internal symbol and common code from
+	pthread_join.
+	* sysdeps/unix/sysv/linux/i386/lowlevellock.h (__lll_timedwait_tid):
+	Remove superflous checks.
+	* sysdeps/unix/sysv/linux/x86_64/lowlevellock.h (__lll_timedwait_tid):
+	Likewise.
+
 	* manual/pattern.texi (THREAD_ATOMIC_BIT_SET): Remove.
 	(THREAD_ATOMIC_CMPXCHG_VAL): Likewise.
 	* nptl/pthreadP.h (THREAD_ATOMIC_CMPXCHG_VAL): Likewise.
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index c10b7c2..168a441 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -452,6 +452,8 @@ extern int __pthread_kill (pthread_t threadid, int signo);
 extern void __pthread_exit (void *value) __attribute__ ((__noreturn__));
 extern int __pthread_setcanceltype (int type, int *oldtype);
 extern void __pthread_testcancel (void);
+extern int __pthread_timedjoin_np (pthread_t threadid, void **thread_return,
+				   const struct timespec *abstime);
 
 #if IS_IN (libpthread)
 hidden_proto (__pthread_mutex_init)
@@ -467,6 +469,7 @@ hidden_proto (__pthread_setspecific)
 hidden_proto (__pthread_once)
 hidden_proto (__pthread_setcancelstate)
 hidden_proto (__pthread_testcancel)
+hidden_proto (__pthread_timedjoin_np)
 #endif
 
 extern int __pthread_cond_broadcast_2_0 (pthread_cond_2_0_t *cond);
diff --git a/nptl/pthread_join.c b/nptl/pthread_join.c
index 8d92647..8a98de7 100644
--- a/nptl/pthread_join.c
+++ b/nptl/pthread_join.c
@@ -16,98 +16,10 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <stdlib.h>
-
-#include <atomic.h>
 #include "pthreadP.h"
 
-#include <stap-probe.h>
-
-
-static void
-cleanup (void *arg)
-{
-  /* If we already changed the waiter ID, reset it.  The call cannot
-     fail for any reason but the thread not having done that yet so
-     there is no reason for a loop.  */
-  (void) atomic_compare_and_exchange_bool_acq ((struct pthread **) arg, NULL,
-					       THREAD_SELF);
-}
-
-
 int
 pthread_join (pthread_t threadid, void **thread_return)
 {
-  struct pthread *pd = (struct pthread *) threadid;
-
-  /* Make sure the descriptor is valid.  */
-  if (INVALID_NOT_TERMINATED_TD_P (pd))
-    /* Not a valid thread handle.  */
-    return ESRCH;
-
-  /* Is the thread joinable?.  */
-  if (IS_DETACHED (pd))
-    /* We cannot wait for the thread.  */
-    return EINVAL;
-
-  struct pthread *self = THREAD_SELF;
-  int result = 0, ct;
-
-  LIBC_PROBE (pthread_join, 1, threadid);
-
-  /* During the wait we change to asynchronous cancellation.  If we
-     are canceled the thread we are waiting for must be marked as
-     un-wait-ed for again.  */
-  pthread_cleanup_push (cleanup, &pd->joinid);
-
-  /* Switch to asynchronous cancellation.  */
-  __pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &ct);
-
-  unsigned int ch = atomic_load_relaxed (&pd->cancelhandling);
-  if ((pd == self || (self->joinid == pd && ch == 0))
-      && !(self->cancelstate == PTHREAD_CANCEL_ENABLE
-           && ch & THREAD_CANCELED))
-    /* This is a deadlock situation.  The threads are waiting for each
-       other to finish.  Note that this is a "may" error.  To be 100%
-       sure we catch this error we would have to lock the data
-       structures but it is not necessary.  In the unlikely case that
-       two threads are really caught in this situation they will
-       deadlock.  It is the programmer's problem to figure this
-       out.  */
-    result = EDEADLK;
-  /* Wait for the thread to finish.  If it is already locked something
-     is wrong.  There can only be one waiter.  */
-  else if (__builtin_expect (atomic_compare_and_exchange_bool_acq (&pd->joinid,
-								   self,
-								   NULL), 0))
-    /* There is already somebody waiting for the thread.  */
-    result = EINVAL;
-  else
-    /* Wait for the child.  */
-    lll_wait_tid (pd->tid);
-
-  __pthread_setcanceltype (ct, NULL);
-
-  /* Remove the handler.  */
-  pthread_cleanup_pop (0);
-
-
-  if (__glibc_likely (result == 0))
-    {
-      /* We mark the thread as terminated and as joined.  */
-      pd->tid = -1;
-
-      /* Store the return value if the caller is interested.  */
-      if (thread_return != NULL)
-	*thread_return = pd->result;
-
-
-      /* Free the TCB.  */
-      __free_tcb (pd);
-    }
-
-  LIBC_PROBE (pthread_join_ret, 3, threadid, result, pd->result);
-
-  return result;
+  return __pthread_timedjoin_np (threadid, thread_return, NULL);
 }
diff --git a/nptl/pthread_timedjoin.c b/nptl/pthread_timedjoin.c
index 75a9cfe..a685972 100644
--- a/nptl/pthread_timedjoin.c
+++ b/nptl/pthread_timedjoin.c
@@ -21,21 +21,26 @@
 #include <atomic.h>
 #include "pthreadP.h"
 
+#include <stap-probe.h>
+
 
 static void
 cleanup (void *arg)
 {
-  *(void **) arg = NULL;
+  /* If we already changed the waiter ID, reset it.  The call cannot
+     fail for any reason but the thread not having done that yet so
+     there is no reason for a loop.  */
+  struct pthread *self = THREAD_SELF;
+  atomic_compare_exchange_weak_acquire (&arg, &self, NULL);
 }
 
 
 int
-pthread_timedjoin_np (pthread_t threadid, void **thread_return,
-		      const struct timespec *abstime)
+__pthread_timedjoin_np (pthread_t threadid, void **thread_return,
+			const struct timespec *abstime)
 {
-  struct pthread *self;
   struct pthread *pd = (struct pthread *) threadid;
-  int result, ct;
+  int result = 0, ct;
 
   /* Make sure the descriptor is valid.  */
   if (INVALID_NOT_TERMINATED_TD_P (pd))
@@ -47,8 +52,13 @@ pthread_timedjoin_np (pthread_t threadid, void **thread_return,
     /* We cannot wait for the thread.  */
     return EINVAL;
 
-  self = THREAD_SELF;
-  if (pd == self || self->joinid == pd)
+  LIBC_PROBE (pthread_join, 1, threadid);
+
+  struct pthread *self = THREAD_SELF;
+  unsigned int ch = atomic_load_relaxed (&pd->cancelhandling);
+  if ((pd == self || (self->joinid == pd && ch == 0))
+      && !(self->cancelstate == PTHREAD_CANCEL_ENABLE
+           && ch & THREAD_CANCELED))
     /* This is a deadlock situation.  The threads are waiting for each
        other to finish.  Note that this is a "may" error.  To be 100%
        sure we catch this error we would have to lock the data
@@ -60,9 +70,8 @@ pthread_timedjoin_np (pthread_t threadid, void **thread_return,
 
   /* Wait for the thread to finish.  If it is already locked something
      is wrong.  There can only be one waiter.  */
-  if (__builtin_expect (atomic_compare_and_exchange_bool_acq (&pd->joinid,
-							      self, NULL), 0))
-    /* There is already somebody waiting for the thread.  */
+  if (__glibc_unlikely (atomic_compare_exchange_weak_acquire (&pd->joinid,
+							      &self, NULL)))
     return EINVAL;
 
 
@@ -75,7 +84,10 @@ pthread_timedjoin_np (pthread_t threadid, void **thread_return,
   __pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &ct);
 
   /* Wait for the child.  */
-  result = lll_timedwait_tid (pd->tid, abstime);
+  if (abstime != NULL)
+    result = lll_timedwait_tid (pd->tid, abstime);
+  else
+    lll_wait_tid (pd->tid);
 
   __pthread_setcanceltype (ct, NULL);
 
@@ -84,18 +96,24 @@ pthread_timedjoin_np (pthread_t threadid, void **thread_return,
 
 
   /* We might have timed out.  */
-  if (result == 0)
+  if (__glibc_likely (result == 0))
     {
+      /* We mark the thread as terminated and as joined.  */
+      pd->tid = -1;
+
       /* Store the return value if the caller is interested.  */
       if (thread_return != NULL)
 	*thread_return = pd->result;
 
-
       /* Free the TCB.  */
       __free_tcb (pd);
     }
   else
     pd->joinid = NULL;
 
+  LIBC_PROBE (pthread_join_ret, 3, threadid, result, pd->result);
+
   return result;
 }
+weak_alias (__pthread_timedjoin_np, pthread_timedjoin_np)
+hidden_def (__pthread_timedjoin_np)
diff --git a/nptl/pthread_tryjoin.c b/nptl/pthread_tryjoin.c
index 6a3b62e..14c5d38 100644
--- a/nptl/pthread_tryjoin.c
+++ b/nptl/pthread_tryjoin.c
@@ -26,47 +26,12 @@
 int
 pthread_tryjoin_np (pthread_t threadid, void **thread_return)
 {
-  struct pthread *self;
-  struct pthread *pd = (struct pthread *) threadid;
-
-  /* Make sure the descriptor is valid.  */
-  if (DEBUGGING_P && __find_in_stack_list (pd) == NULL)
-    /* Not a valid thread handle.  */
-    return ESRCH;
-
-  /* Is the thread joinable?.  */
-  if (IS_DETACHED (pd))
-    /* We cannot wait for the thread.  */
-    return EINVAL;
-
-  self = THREAD_SELF;
-  if (pd == self || self->joinid == pd)
-    /* This is a deadlock situation.  The threads are waiting for each
-       other to finish.  Note that this is a "may" error.  To be 100%
-       sure we catch this error we would have to lock the data
-       structures but it is not necessary.  In the unlikely case that
-       two threads are really caught in this situation they will
-       deadlock.  It is the programmer's problem to figure this
-       out.  */
-    return EDEADLK;
-
   /* Return right away if the thread hasn't terminated yet.  */
+  struct pthread *pd = (struct pthread *) threadid;
   if (pd->tid != 0)
     return EBUSY;
 
-  /* Wait for the thread to finish.  If it is already locked something
-     is wrong.  There can only be one waiter.  */
-  if (atomic_compare_and_exchange_bool_acq (&pd->joinid, self, NULL))
-    /* There is already somebody waiting for the thread.  */
-    return EINVAL;
-
-  /* Store the return value if the caller is interested.  */
-  if (thread_return != NULL)
-    *thread_return = pd->result;
-
-
-  /* Free the TCB.  */
-  __free_tcb (pd);
-
-  return 0;
+  /* If pd->tid != 0 then lll_wait_tid will not block on futex
+     operation.  */
+  return __pthread_timedjoin_np (threadid, thread_return, NULL);
 }
diff --git a/sysdeps/unix/sysv/linux/i386/lowlevellock.h b/sysdeps/unix/sysv/linux/i386/lowlevellock.h
index e54d1ea..0368c9d 100644
--- a/sysdeps/unix/sysv/linux/i386/lowlevellock.h
+++ b/sysdeps/unix/sysv/linux/i386/lowlevellock.h
@@ -237,12 +237,7 @@ extern int __lll_timedwait_tid (int *tid, const struct timespec *abstime)
   ({									      \
     int __result = 0;							      \
     if ((tid) != 0)							      \
-      {									      \
-	if ((abstime)->tv_nsec < 0 || (abstime)->tv_nsec >= 1000000000)	      \
-	  __result = EINVAL;						      \
-	else								      \
-	  __result = __lll_timedwait_tid (&(tid), (abstime));		      \
-      }									      \
+      __result = __lll_timedwait_tid (&(tid), (abstime));		      \
     __result; })
 
 
diff --git a/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h b/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
index bb6d9ee..74e2c80 100644
--- a/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
+++ b/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
@@ -249,12 +249,7 @@ extern int __lll_timedwait_tid (int *, const struct timespec *)
   ({									      \
     int __result = 0;							      \
     if ((tid) != 0)							      \
-      {									      \
-	if ((abstime)->tv_nsec < 0 || (abstime)->tv_nsec >= 1000000000)	      \
-	  __result = EINVAL;						      \
-	else								      \
-	  __result = __lll_timedwait_tid (&(tid), (abstime));		      \
-      }									      \
+      __result = __lll_timedwait_tid (&(tid), (abstime));		      \
     __result; })
 
 extern int __lll_lock_elision (int *futex, short *adapt_count, int private)

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=beb3b97507e1b183d4ee364c1969629f4ced028c

commit beb3b97507e1b183d4ee364c1969629f4ced028c
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Jan 24 21:05:56 2017 -0200

    nptl: Remove THREAD_ATOMIC_* macros
    
    This patch removes the ununsed THREAD_ATOMIC_* macros now that nptl
    code is using C11 atomics.
    
    Checked on x86_64-linux-gnu and i686-linux-gnu.
    
    	* manual/pattern.texi (THREAD_ATOMIC_BIT_SET): Remove.
    	(THREAD_ATOMIC_CMPXCHG_VAL): Likewise.
    	* nptl/pthreadP.h (THREAD_ATOMIC_CMPXCHG_VAL): Likewise.
    	(THREAD_ATOMIC_BIT_SET): Likewise.
    	* sysdeps/i386/nptl/tls.h (THREAD_ATOMIC_CMPXCHG_VAL): Likewise.
    	(THREAD_ATOMIC_AND): Likewise.
    	* sysdeps/x86_64/nptl/tls.h (THREAD_ATOMIC_CMPXCHG_VAL): Likewise.
    	(THREAD_ATOMIC_AND): Likewise.

diff --git a/ChangeLog b/ChangeLog
index 57916c2..a2241d4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* manual/pattern.texi (THREAD_ATOMIC_BIT_SET): Remove.
+	(THREAD_ATOMIC_CMPXCHG_VAL): Likewise.
+	* nptl/pthreadP.h (THREAD_ATOMIC_CMPXCHG_VAL): Likewise.
+	(THREAD_ATOMIC_BIT_SET): Likewise.
+	* sysdeps/i386/nptl/tls.h (THREAD_ATOMIC_CMPXCHG_VAL): Likewise.
+	(THREAD_ATOMIC_AND): Likewise.
+	* sysdeps/x86_64/nptl/tls.h (THREAD_ATOMIC_CMPXCHG_VAL): Likewise.
+	(THREAD_ATOMIC_AND): Likewise.
+
 	* nptl/descr.h (CANCELED_BITMASK): Rename to THREAD_CANCELED.
 	(EXITING_BITMASK): Rename to THREAD_EXITING.
 	(TERMINATED_BITMARK): Rename to THREAD_TERMINATED.
diff --git a/manual/pattern.texi b/manual/pattern.texi
index 6f1ed22..644ac9e 100644
--- a/manual/pattern.texi
+++ b/manual/pattern.texi
@@ -1881,7 +1881,6 @@ the beginning of the vector.
 @c      (disable cancellation around exec_comm; it may do_cancel the
 @c       second time, if async cancel is enabled)
 @c     do_cancel @ascuplugin @ascuheap @acsmem
-@c      THREAD_ATOMIC_BIT_SET dup ok
 @c      pthread_unwind @ascuplugin @ascuheap @acsmem
 @c       Unwind_ForcedUnwind if available @ascuplugin @ascuheap @acsmem
 @c       libc_unwind_longjmp otherwise
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index 37799b7..c10b7c2 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -35,18 +35,6 @@
 #include <nptl-signals.h>
 
 
-/* Atomic operations on TLS memory.  */
-#ifndef THREAD_ATOMIC_CMPXCHG_VAL
-# define THREAD_ATOMIC_CMPXCHG_VAL(descr, member, new, old) \
-  atomic_compare_and_exchange_val_acq (&(descr)->member, new, old)
-#endif
-
-#ifndef THREAD_ATOMIC_BIT_SET
-# define THREAD_ATOMIC_BIT_SET(descr, member, bit) \
-  atomic_bit_set (&(descr)->member, bit)
-#endif
-
-
 /* Adaptive mutex definitions.  */
 #ifndef MAX_ADAPTIVE_COUNT
 # define MAX_ADAPTIVE_COUNT 100
diff --git a/sysdeps/i386/nptl/tls.h b/sysdeps/i386/nptl/tls.h
index 0fa8377..252bffb 100644
--- a/sysdeps/i386/nptl/tls.h
+++ b/sysdeps/i386/nptl/tls.h
@@ -357,32 +357,6 @@ tls_fill_user_desc (union user_desc_init *desc,
        }})
 
 
-/* Atomic compare and exchange on TLS, returning old value.  */
-#define THREAD_ATOMIC_CMPXCHG_VAL(descr, member, newval, oldval) \
-  ({ __typeof (descr->member) __ret;					      \
-     __typeof (oldval) __old = (oldval);				      \
-     if (sizeof (descr->member) == 4)					      \
-       asm volatile (LOCK_PREFIX "cmpxchgl %2, %%gs:%P3"		      \
-		     : "=a" (__ret)					      \
-		     : "0" (__old), "r" (newval),			      \
-		       "i" (offsetof (struct pthread, member)));	      \
-     else								      \
-       /* Not necessary for other sizes in the moment.  */		      \
-       abort ();							      \
-     __ret; })
-
-
-/* Atomic logical and.  */
-#define THREAD_ATOMIC_AND(descr, member, val) \
-  (void) ({ if (sizeof ((descr)->member) == 4)				      \
-	      asm volatile (LOCK_PREFIX "andl %1, %%gs:%P0"		      \
-			    :: "i" (offsetof (struct pthread, member)),	      \
-			       "ir" (val));				      \
-	    else							      \
-	      /* Not necessary for other sizes in the moment.  */	      \
-	      abort (); })
-
-
 /* Call the user-provided thread function.  */
 #define CALL_THREAD_FCT(descr) \
   ({ void *__res;							      \
diff --git a/sysdeps/x86_64/nptl/tls.h b/sysdeps/x86_64/nptl/tls.h
index 45f5f4a..f55724f 100644
--- a/sysdeps/x86_64/nptl/tls.h
+++ b/sysdeps/x86_64/nptl/tls.h
@@ -289,32 +289,6 @@ typedef struct
        }})
 
 
-/* Atomic compare and exchange on TLS, returning old value.  */
-# define THREAD_ATOMIC_CMPXCHG_VAL(descr, member, newval, oldval) \
-  ({ __typeof (descr->member) __ret;					      \
-     __typeof (oldval) __old = (oldval);				      \
-     if (sizeof (descr->member) == 4)					      \
-       asm volatile (LOCK_PREFIX "cmpxchgl %2, %%fs:%P3"		      \
-		     : "=a" (__ret)					      \
-		     : "0" (__old), "r" (newval),			      \
-		       "i" (offsetof (struct pthread, member)));	      \
-     else								      \
-       /* Not necessary for other sizes in the moment.  */		      \
-       abort ();							      \
-     __ret; })
-
-
-/* Atomic logical and.  */
-# define THREAD_ATOMIC_AND(descr, member, val) \
-  (void) ({ if (sizeof ((descr)->member) == 4)				      \
-	      asm volatile (LOCK_PREFIX "andl %1, %%fs:%P0"		      \
-			    :: "i" (offsetof (struct pthread, member)),	      \
-			       "ir" (val));				      \
-	    else							      \
-	      /* Not necessary for other sizes in the moment.  */	      \
-	      abort (); })
-
-
 # define CALL_THREAD_FCT(descr) \
   ({ void *__res;							      \
      asm volatile ("movq %%fs:%P2, %%rdi\n\t"				      \

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=790729367957a36b7bdc2f7a2f0b0ae1c59e6eac

commit 790729367957a36b7bdc2f7a2f0b0ae1c59e6eac
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Jan 24 09:17:37 2017 -0200

    nptl: cancelhandling refactor
    
    This patch basically uses glibc C11 atomic function to access and
    modify struct pthread cancelhandling variable.  All plain access
    are handled using the atomic_load_* functions and THREAD_ATOMIC_BIT_SET
    is replaced by atomic_fetch_or_acquire.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* nptl/descr.h (CANCELED_BITMASK): Rename to THREAD_CANCELED.
    	(EXITING_BITMASK): Rename to THREAD_EXITING.
    	(TERMINATED_BITMARK): Rename to THREAD_TERMINATED.
    	* nptl/allocatestack.c (setxid_mark_thread): Use THREAD_* instead of
    	*_BITMASK and use glibc C11 atomic function to access pthread
    	cancelhandling.
    	* nptl/libc-cancellation.c (__syscall_cancel): Likewise.
    	* nptl/nptl-init.c (sigcancel_handler): Likewise.
    	* nptl/pthread_cancel.c (pthread_cancel): Likewise.
    	* nptl/pthread_create.c (__free_tcb): Likewise.
    	(START_THREAD_DEFN): Likewise.
    	(__pthread_create_2_1): Likewise.
    	* nptl/pthread_detach.c (pthread_detach): Likewise.
    	* nptl/pthread_exit.c (__pthread_exit): Likewise.
    	* nptl/pthread_join.c (pthread_join): Likewise.
    	* nptl_db/td_thr_get_info.c (td_thr_get_info): Likewise.
    	* nptl_db/td_thr_getfpregs.c (td_thr_getfpregs): Likewise.
    	* nptl_db/td_thr_getgregs.c (td_thr_getregs): Likewise.
    	* nptl_db/td_thr_setfpregs.c (td_thr_setfpregs): Likewise.
    	* nptl_db/td_thr_setgregs.c (td_thr_setgregs): Likewise.
    	* sysdeps/unix/sysv/linux/arm/syscall_cancel.S
    	(__syscall_cancel_arch): Change CANCELED_BITMASK to
    	THREAD_CANCELED in comment.
    	* sysdeps/unix/sysv/linux/syscall_cancel.c
    	(__syscall_cancel_arch): Likewise.
    	* sysdeps/x86_64/nptl/tcb-offsets.sym (TCB_CANCELED_BITMASK):
    	Remove.
    	(TCB_EXITING_BITMASK): Likewise.
    	(TCB_TERMINATED_BITMASK): Likewise.
    	* sysdeps/unix/sysv/linux/i386/syscall_cancel.S
    	(__syscall_cancel_arch): Likewise.
    	* sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S
    	(__syscall_cancel_arch): Likewise.
    	* sysdeps/unix/sysv/linux/sh/syscall_cancel.S
    	(__syscall_cancel_arch): Likewise.
    	* sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S
    	(__syscall_cancel_arch): Likewise.
    	* sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S
    	(__syscall_cancel_arch): Likewise.

diff --git a/ChangeLog b/ChangeLog
index b074988..57916c2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,45 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* nptl/descr.h (CANCELED_BITMASK): Rename to THREAD_CANCELED.
+	(EXITING_BITMASK): Rename to THREAD_EXITING.
+	(TERMINATED_BITMARK): Rename to THREAD_TERMINATED.
+	* nptl/allocatestack.c (setxid_mark_thread): Use THREAD_* instead of
+	*_BITMASK and use glibc C11 atomic function to access pthread
+	cancelhandling.
+	* nptl/libc-cancellation.c (__syscall_cancel): Likewise.
+	* nptl/nptl-init.c (sigcancel_handler): Likewise.
+	* nptl/pthread_cancel.c (pthread_cancel): Likewise.
+	* nptl/pthread_create.c (__free_tcb): Likewise.
+	(START_THREAD_DEFN): Likewise.
+	(__pthread_create_2_1): Likewise.
+	* nptl/pthread_detach.c (pthread_detach): Likewise.
+	* nptl/pthread_exit.c (__pthread_exit): Likewise.
+	* nptl/pthread_join.c (pthread_join): Likewise.
+	* nptl_db/td_thr_get_info.c (td_thr_get_info): Likewise.
+	* nptl_db/td_thr_getfpregs.c (td_thr_getfpregs): Likewise.
+	* nptl_db/td_thr_getgregs.c (td_thr_getregs): Likewise.
+	* nptl_db/td_thr_setfpregs.c (td_thr_setfpregs): Likewise.
+	* nptl_db/td_thr_setgregs.c (td_thr_setgregs): Likewise.
+	* sysdeps/unix/sysv/linux/arm/syscall_cancel.S
+	(__syscall_cancel_arch): Change CANCELED_BITMASK to
+	THREAD_CANCELED in comment.
+	* sysdeps/unix/sysv/linux/syscall_cancel.c
+	(__syscall_cancel_arch): Likewise.
+	* sysdeps/x86_64/nptl/tcb-offsets.sym (TCB_CANCELED_BITMASK):
+	Remove.
+	(TCB_EXITING_BITMASK): Likewise.
+	(TCB_TERMINATED_BITMASK): Likewise.
+	* sysdeps/unix/sysv/linux/i386/syscall_cancel.S
+	(__syscall_cancel_arch): Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S
+	(__syscall_cancel_arch): Likewise.
+	* sysdeps/unix/sysv/linux/sh/syscall_cancel.S
+	(__syscall_cancel_arch): Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S
+	(__syscall_cancel_arch): Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S
+	(__syscall_cancel_arch): Likewise.
+
 	* nptl/allocatestack.c (get_cached_stack): Set sexid_op on new
 	allocated stack.
 	(setxid_mark_thread): Use setxid_op to mark thread as executing
diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
index 3e70e0b..b1cfd97 100644
--- a/nptl/allocatestack.c
+++ b/nptl/allocatestack.c
@@ -991,7 +991,7 @@ setxid_mark_thread (struct xid_command *cmdp, struct pthread *t)
   do
     {
       /* If the thread is exiting right now, ignore it.  */
-      if ((atomic_load_relaxed (&t->cancelhandling) & EXITING_BITMASK) != 0)
+      if ((atomic_load_relaxed (&t->cancelhandling) & THREAD_EXITING) != 0)
 	{
 	  /* Release the futex if there is no other setxid in
 	     progress.  */
diff --git a/nptl/descr.h b/nptl/descr.h
index 50853bf..3885f02 100644
--- a/nptl/descr.h
+++ b/nptl/descr.h
@@ -272,18 +272,27 @@ struct pthread
   struct pthread_unwind_buf *cleanup_jmp_buf;
 #define HAVE_CLEANUP_JMP_BUF
 
-  /* Flags determining processing of cancellation.  */
+  /* Flags determining process of thread cancellation, termination, and
+     finalization.  Initial state is 0 set at allocate_stack
+     (pthread_create.c).
+
+     THREAD_CANCELED bit is used to mark the thread as cancelled and it
+     is set atomically by pthread_cancel.
+
+     THREAD_EXITING bit is used to mark the thread as exiting and it
+     is set atomically either by 1. pthread_exit, 2. thread cancellation
+     signal handler at nptl-init.c, or 3. after thread execution at
+     pthread_create.c.
+
+     THREAD_TERMINATED bit used to mark the thread resources are being
+     freed and set by __free_tcb (called by pthread_detach and
+     pthread_{timed,try}join.
+   */
+#define THREAD_CANCELED		0x04
+#define THREAD_EXITING		0x08
+#define THREAD_TERMINATED	0x10
   int cancelhandling;
 
-#define CANCELED_BIT		2
-#define CANCELED_BITMASK	(0x01 << CANCELED_BIT)
-  /* Bit set if thread is exiting.  */
-#define EXITING_BIT		3
-#define EXITING_BITMASK		(0x01 << EXITING_BIT)
-  /* Bit set if thread terminated and TCB is freed.  */
-#define TERMINATED_BIT		4
-#define TERMINATED_BITMASK	(0x01 << TERMINATED_BIT)
-
   /* Flag to indicate thread cancel disable state (PTHREAD_CANCEL_ENABLE or
      PTHREAD_CANCEL_DISABLE).  */
   int cancelstate;
diff --git a/nptl/libc-cancellation.c b/nptl/libc-cancellation.c
index 335acab..65caf6e 100644
--- a/nptl/libc-cancellation.c
+++ b/nptl/libc-cancellation.c
@@ -48,7 +48,7 @@ __syscall_cancel (__syscall_arg_t nr, __syscall_arg_t a1,
 			          a6 __SYSCALL_CANCEL7_ARG7);
 
   if ((result == -EINTR)
-      && (pd->cancelhandling & CANCELED_BITMASK)
+      && (atomic_load_relaxed (&pd->cancelhandling) & THREAD_CANCELED)
       && (pd->cancelstate != PTHREAD_CANCEL_DISABLE))
     __syscall_do_cancel ();
 
diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c
index ecef5d2..9f558fd 100644
--- a/nptl/nptl-init.c
+++ b/nptl/nptl-init.c
@@ -205,7 +205,7 @@ sigcancel_handler (int sig, siginfo_t *si, void *ctx)
   ucontext_t *uc = ctx;
 
   if ((pd->cancelstate == PTHREAD_CANCEL_DISABLE)
-      || ((pd->cancelhandling & CANCELED_BITMASK) == 0))
+      || (atomic_load_relaxed (&pd->cancelhandling) & THREAD_CANCELED) == 0)
     return;
 
   sigaddset_cancel (&uc->uc_sigmask);
@@ -223,7 +223,7 @@ sigcancel_handler (int sig, siginfo_t *si, void *ctx)
       || (pc >= (uintptr_t) __syscall_cancel_arch_start
           && pc < (uintptr_t) __syscall_cancel_arch_end))
     {
-      THREAD_ATOMIC_BIT_SET (self, cancelhandling, EXITING_BIT);
+      atomic_fetch_or_acquire (&self->cancelhandling, THREAD_EXITING);
       THREAD_SETMEM (self, result, PTHREAD_CANCELED);
 
       /* Add SIGCANCEL on ignored sigmask to avoid the handler to be called
diff --git a/nptl/pthread_cancel.c b/nptl/pthread_cancel.c
index 7e80b1d..8d2b425 100644
--- a/nptl/pthread_cancel.c
+++ b/nptl/pthread_cancel.c
@@ -38,7 +38,7 @@ pthread_cancel (pthread_t th)
   pthread_cancel_init ();
 #endif
 
-  THREAD_ATOMIC_BIT_SET (pd, cancelhandling, CANCELED_BIT);
+  atomic_fetch_or_acquire (&pd->cancelhandling, THREAD_CANCELED);
 
   /* A single-threaded process should be able to kill itself, since there is
      nothing in the POSIX specification that says that it cannot.  So we set
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index 15cd9d5..9f329f8 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -335,8 +335,9 @@ internal_function
 __free_tcb (struct pthread *pd)
 {
   /* The thread is exiting now.  */
-  if (__builtin_expect (atomic_bit_test_set (&pd->cancelhandling,
-					     TERMINATED_BIT) == 0, 1))
+  unsigned int ch = atomic_fetch_or_acquire (&pd->cancelhandling,
+					     THREAD_TERMINATED);
+  if (__glibc_likely ((ch & THREAD_TERMINATED) == 0))
     {
       /* Remove the descriptor from the list.  */
       if (DEBUGGING_P && __find_in_stack_list (pd) == NULL)
@@ -404,13 +405,14 @@ START_THREAD_DEFN
   /* If the parent was running cancellation handlers while creating
      the thread the new thread inherited the signal mask.  Reset the
      cancellation signal mask.  */
-  if (__glibc_unlikely (pd->parent_cancelhandling & CANCELED_BITMASK))
+  unsigned int ch = atomic_load_relaxed (&pd->parent_cancelhandling);
+  if (__glibc_unlikely (ch & THREAD_CANCELED))
     {
       INTERNAL_SYSCALL_DECL (err);
       sigset_t mask;
       __sigemptyset (&mask);
       __sigaddset (&mask, SIGCANCEL);
-      (void) INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_UNBLOCK, &mask,
+      INTERNAL_SYSCALL_CALL (rt_sigprocmask, err, SIG_UNBLOCK, &mask,
 			       NULL, _NSIG / 8);
     }
 #endif
@@ -511,7 +513,7 @@ START_THREAD_DEFN
   /* The thread is exiting now.  Don't set this bit until after we've hit
      the event-reporting breakpoint, so that td_thr_get_info on us while at
      the breakpoint reports TD_THR_RUN state rather than TD_THR_ZOMBIE.  */
-  atomic_bit_set (&pd->cancelhandling, EXITING_BIT);
+  atomic_fetch_or_acquire (&pd->cancelhandling, THREAD_EXITING);
 
 #ifndef __ASSUME_SET_ROBUST_LIST
   /* If this thread has any robust mutexes locked, handle them now.  */
@@ -573,14 +575,14 @@ START_THREAD_DEFN
 #endif
 
   /* If the thread is detached free the TCB.  */
+  unsigned int s;
   if (IS_DETACHED (pd))
     /* Free the TCB.  */
     __free_tcb (pd);
-  else
+  else if ((s = atomic_load_relaxed (&pd->setxid_op)) == 1)
     {
       /* Some other thread might call any of the setXid functions and expect
 	 us to reply.  In this case wait until we did that.  */
-      unsigned int s = atomic_load_relaxed (&pd->setxid_op);
       do
 	/* XXX This differs from the typical futex_wait_simple pattern in that
 	   the futex_wait condition (setxid_futex) is different from the
@@ -729,7 +731,7 @@ __pthread_create_2_1 (pthread_t *newthread, const pthread_attr_t *attr,
 
   /* Inform start_thread (above) about cancellation state that might
      translate into inherited signal state.  */
-  pd->parent_cancelhandling = THREAD_GETMEM (THREAD_SELF, cancelhandling);
+  pd->parent_cancelhandling = atomic_load_relaxed (&self->cancelhandling);
 
   /* Determine scheduling parameters for the thread.  */
   if (__builtin_expect ((iattr->flags & ATTR_FLAG_NOTINHERITSCHED) != 0, 0)
diff --git a/nptl/pthread_detach.c b/nptl/pthread_detach.c
index 8a2e943..21572c9 100644
--- a/nptl/pthread_detach.c
+++ b/nptl/pthread_detach.c
@@ -46,7 +46,7 @@ pthread_detach (pthread_t th)
   else
     /* Check whether the thread terminated meanwhile.  In this case we
        will just free the TCB.  */
-    if ((pd->cancelhandling & EXITING_BITMASK) != 0)
+    if ((atomic_load_relaxed(&pd->cancelhandling) & THREAD_EXITING) != 0)
       /* Note that the code in __free_tcb makes sure each thread
 	 control block is freed only once.  */
       __free_tcb (pd);
diff --git a/nptl/pthread_exit.c b/nptl/pthread_exit.c
index 0f29609..1e1a13b 100644
--- a/nptl/pthread_exit.c
+++ b/nptl/pthread_exit.c
@@ -27,7 +27,7 @@ __pthread_exit (void *value)
 
   THREAD_SETMEM (self, result, value);
 
-  THREAD_ATOMIC_BIT_SET (self, cancelhandling, EXITING_BIT);
+  atomic_fetch_or_acquire (&self->cancelhandling, THREAD_EXITING);
 
   __pthread_unwind ((__pthread_unwind_buf_t *)
 		    THREAD_GETMEM (self, cleanup_jmp_buf));
diff --git a/nptl/pthread_join.c b/nptl/pthread_join.c
index 6f15fa7..8d92647 100644
--- a/nptl/pthread_join.c
+++ b/nptl/pthread_join.c
@@ -64,13 +64,10 @@ pthread_join (pthread_t threadid, void **thread_return)
   /* Switch to asynchronous cancellation.  */
   __pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &ct);
 
-  if ((pd == self
-       || (self->joinid == pd
-	   && (pd->cancelhandling
-	       & (CANCELED_BITMASK | EXITING_BITMASK
-		  | TERMINATED_BITMASK)) == 0))
+  unsigned int ch = atomic_load_relaxed (&pd->cancelhandling);
+  if ((pd == self || (self->joinid == pd && ch == 0))
       && !(self->cancelstate == PTHREAD_CANCEL_ENABLE
-           && self->cancelhandling & CANCELED_BITMASK))
+           && ch & THREAD_CANCELED))
     /* This is a deadlock situation.  The threads are waiting for each
        other to finish.  Note that this is a "may" error.  To be 100%
        sure we catch this error we would have to lock the data
diff --git a/nptl_db/td_thr_get_info.c b/nptl_db/td_thr_get_info.c
index 48979b8..d549bc8 100644
--- a/nptl_db/td_thr_get_info.c
+++ b/nptl_db/td_thr_get_info.c
@@ -89,10 +89,10 @@ td_thr_get_info (const td_thrhandle_t *th, td_thrinfo_t *infop)
 		   ? 0 : (uintptr_t) schedprio);
   infop->ti_type = TD_THR_USER;
 
-  if ((((int) (uintptr_t) cancelhandling) & EXITING_BITMASK) == 0)
+  if ((((int) (uintptr_t) cancelhandling) & THREAD_EXITING) == 0)
     /* XXX For now there is no way to get more information.  */
     infop->ti_state = TD_THR_ACTIVE;
-  else if ((((int) (uintptr_t) cancelhandling) & TERMINATED_BITMASK) == 0)
+  else if ((((int) (uintptr_t) cancelhandling) & THREAD_TERMINATED) == 0)
     infop->ti_state = TD_THR_ZOMBIE;
   else
     infop->ti_state = TD_THR_UNKNOWN;
diff --git a/nptl_db/td_thr_getfpregs.c b/nptl_db/td_thr_getfpregs.c
index 3c5462c..aaba61a 100644
--- a/nptl_db/td_thr_getfpregs.c
+++ b/nptl_db/td_thr_getfpregs.c
@@ -40,7 +40,7 @@ td_thr_getfpregs (const td_thrhandle_t *th, prfpregset_t *regset)
     return err;
 
   /* If the thread already terminated we return all zeroes.  */
-  if (((int) (uintptr_t) cancelhandling) & TERMINATED_BITMASK)
+  if (((int) (uintptr_t) cancelhandling) & THREAD_TERMINATED)
     memset (regset, '\0', sizeof (*regset));
   /* Otherwise get the register content through the callback.  */
   else
diff --git a/nptl_db/td_thr_getgregs.c b/nptl_db/td_thr_getgregs.c
index 61ffa12..1be9072 100644
--- a/nptl_db/td_thr_getgregs.c
+++ b/nptl_db/td_thr_getgregs.c
@@ -40,7 +40,7 @@ td_thr_getgregs (const td_thrhandle_t *th, prgregset_t regset)
     return err;
 
   /* If the thread already terminated we return all zeroes.  */
-  if (((int) (uintptr_t) cancelhandling) & TERMINATED_BITMASK)
+  if (((int) (uintptr_t) cancelhandling) & THREAD_TERMINATED)
     memset (regset, '\0', sizeof (*regset));
   /* Otherwise get the register content through the callback.  */
   else
diff --git a/nptl_db/td_thr_setfpregs.c b/nptl_db/td_thr_setfpregs.c
index 092fc1a..e5cb76d 100644
--- a/nptl_db/td_thr_setfpregs.c
+++ b/nptl_db/td_thr_setfpregs.c
@@ -40,7 +40,7 @@ td_thr_setfpregs (const td_thrhandle_t *th, const prfpregset_t *fpregs)
     return err;
 
   /* Only set the registers if the thread hasn't yet terminated.  */
-  if ((((int) (uintptr_t) cancelhandling) & TERMINATED_BITMASK) == 0)
+  if ((((int) (uintptr_t) cancelhandling) & THREAD_TERMINATED) == 0)
     {
       err = DB_GET_FIELD (tid, th->th_ta_p, th->th_unique, pthread, tid, 0);
       if (err != TD_OK)
diff --git a/nptl_db/td_thr_setgregs.c b/nptl_db/td_thr_setgregs.c
index a927119..2eb03c1 100644
--- a/nptl_db/td_thr_setgregs.c
+++ b/nptl_db/td_thr_setgregs.c
@@ -40,7 +40,7 @@ td_thr_setgregs (const td_thrhandle_t *th, prgregset_t gregs)
     return err;
 
   /* Only set the registers if the thread hasn't yet terminated.  */
-  if ((((int) (uintptr_t) cancelhandling) & TERMINATED_BITMASK) == 0)
+  if ((((int) (uintptr_t) cancelhandling) & THREAD_TERMINATED) == 0)
     {
       err = DB_GET_FIELD (tid, th->th_ta_p, th->th_unique, pthread, tid, 0);
       if (err != TD_OK)
diff --git a/sysdeps/unix/sysv/linux/arm/syscall_cancel.S b/sysdeps/unix/sysv/linux/arm/syscall_cancel.S
index 431cae2..f3d6699 100644
--- a/sysdeps/unix/sysv/linux/arm/syscall_cancel.S
+++ b/sysdeps/unix/sysv/linux/arm/syscall_cancel.S
@@ -44,7 +44,7 @@ ENTRY (__syscall_cancel_arch)
 	.globl __syscall_cancel_arch_start
 __syscall_cancel_arch_start:
 
-	/* if (*cancelhandling & CANCELED_BITMASK)
+	/* if (*cancelhandling & THREAD_CANCELED)
 	     __syscall_do_cancel()  */
 	ldr	r0,[r0]
 	tst	r0, #4
diff --git a/sysdeps/unix/sysv/linux/i386/syscall_cancel.S b/sysdeps/unix/sysv/linux/i386/syscall_cancel.S
index 64ce1f7..442adc2 100644
--- a/sysdeps/unix/sysv/linux/i386/syscall_cancel.S
+++ b/sysdeps/unix/sysv/linux/i386/syscall_cancel.S
@@ -44,7 +44,7 @@ ENTRY (__syscall_cancel_arch)
 	.global __syscall_cancel_arch_start
 __syscall_cancel_arch_start:
 
-	/* if (*cancelhandling & CANCELED_BITMASK)
+	/* if (*cancelhandling & THREAD_CANCELED)
 	     __syscall_do_cancel()  */
 	testb	$4, (%eax)
 	jne     1f
diff --git a/sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S b/sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S
index 4e6dc58..26027db 100644
--- a/sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S
+++ b/sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S
@@ -33,7 +33,7 @@ ENTRY (__syscall_cancel_arch)
 	.type  __syscall_cancel_arch_start,@function
 __syscall_cancel_arch_start:
 
-	/* if (*cancelhandling & CANCELED_BITMASK)
+	/* if (*cancelhandling & THREAD_CANCELED)
 	     __syscall_do_cancel()  */
 	lwz     r0,0(r3)
 	rldicl. r0,r0,62,63
diff --git a/sysdeps/unix/sysv/linux/sh/syscall_cancel.S b/sysdeps/unix/sysv/linux/sh/syscall_cancel.S
index 2b2e62a..f2aba75 100644
--- a/sysdeps/unix/sysv/linux/sh/syscall_cancel.S
+++ b/sysdeps/unix/sysv/linux/sh/syscall_cancel.S
@@ -36,7 +36,7 @@ ENTRY (__syscall_cancel_arch)
 	.globl __syscall_cancel_arch_start
 __syscall_cancel_arch_start:
 
-	/* if (*cancelhandling & CANCELED_BITMASK)
+	/* if (*cancelhandling & THREAD_CANCELED)
 	     __syscall_do_cancel()  */
 	mov.l	@r4,r0
 	tst	#4,r0
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S b/sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S
index 111a40b..95d2cf6 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S
@@ -37,7 +37,7 @@ ENTRY (__syscall_cancel_arch)
 	.globl __syscall_cancel_arch_start
 __syscall_cancel_arch_start:
 
-	/* if (*cancelhandling & CANCELED_BITMASK)
+	/* if (*cancelhandling & THREAD_CANCELED)
 	     __syscall_do_cancel()  */
 	ld	[%i0], %g2
 	andcc	%g2, 4, %g0
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S b/sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S
index 905530a..dd65ba4 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S
@@ -37,7 +37,7 @@ ENTRY (__syscall_cancel_arch)
 	.globl __syscall_cancel_arch_start
 __syscall_cancel_arch_start:
 
-	/* if (*cancelhandling & CANCELED_BITMASK)
+	/* if (*cancelhandling & THREAD_CANCELED)
 	     __syscall_do_cancel()  */
 	lduw	[%i0], %g1
 	andcc	%g1, 4, %g0
diff --git a/sysdeps/unix/sysv/linux/syscall_cancel.c b/sysdeps/unix/sysv/linux/syscall_cancel.c
index c9d4126..a79a360 100644
--- a/sysdeps/unix/sysv/linux/syscall_cancel.c
+++ b/sysdeps/unix/sysv/linux/syscall_cancel.c
@@ -47,7 +47,7 @@ __syscall_cancel_arch (volatile int *ch, __syscall_arg_t nr,
 		       __SYSCALL_CANCEL7_ARG_DEF)
 {
   ADD_LABEL ("__syscall_cancel_arch_start");
-  if (__glibc_unlikely (*ch & CANCELED_BITMASK))
+  if (__glibc_unlikely (atomic_load_relaxed (ch) & THREAD_CANCELED))
     __syscall_do_cancel();
 
   INTERNAL_SYSCALL_DECL(err);
diff --git a/sysdeps/x86_64/nptl/tcb-offsets.sym b/sysdeps/x86_64/nptl/tcb-offsets.sym
index 37069dd..8710fd9 100644
--- a/sysdeps/x86_64/nptl/tcb-offsets.sym
+++ b/sysdeps/x86_64/nptl/tcb-offsets.sym
@@ -17,7 +17,4 @@ PRIVATE_FUTEX		offsetof (tcbhead_t, private_futex)
 #endif
 
 -- Not strictly offsets, but these values are also used in the TCB.
-TCB_CANCELED_BITMASK	 CANCELED_BITMASK
-TCB_EXITING_BITMASK	 EXITING_BITMASK
-TCB_TERMINATED_BITMASK	 TERMINATED_BITMASK
 TCB_PTHREAD_CANCELED	 PTHREAD_CANCELED

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=0561dc9dff5923035144da3cdbd10b90ed14e127

commit 0561dc9dff5923035144da3cdbd10b90ed14e127
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Jan 23 10:44:40 2017 -0200

    nptl: Remove setxid bit from cancelhandling
    
    This patch removes the setxid signaling out of cancelhandling flag
    and use its own member of pthread instead.  The idea is 1 simplify
    setxid handling to now mix atomic operation with thread cancellation
    since both are orthogonal, 2. isolate cancelhandling variable to only
    track thread cancel state.
    
    It also uses glibc C11 atomic operation while accessing new setxid_op
    field.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* nptl/allocatestack.c (get_cached_stack): Set sexid_op on new
    	allocated stack.
    	(setxid_mark_thread): Use setxid_op to mark thread as executing
    	a sexid operation insteaf of using cancelhandling.  Also adapt
    	algorithm to use C11 atomic analogous functions.
    	(setxid_unmark_thread): Likewise.
    	(setxid_signal_thread): Likewise.
    	* nptl/nptl-init.c (sighandler_setxid): Likewise.
    	* nptl/pthread_create.c (sighandler_setxid): Likewise.
    	* nptl/descr.h (SETXID_BIT): Remove define.
    	(SETXID_BITMASK): Likewise.
    	(setxid_op): New member.

diff --git a/ChangeLog b/ChangeLog
index ddd1fe0..b074988 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* nptl/allocatestack.c (get_cached_stack): Set sexid_op on new
+	allocated stack.
+	(setxid_mark_thread): Use setxid_op to mark thread as executing
+	a sexid operation insteaf of using cancelhandling.  Also adapt
+	algorithm to use C11 atomic analogous functions.
+	(setxid_unmark_thread): Likewise.
+	(setxid_signal_thread): Likewise.
+	* nptl/nptl-init.c (sighandler_setxid): Likewise.
+	* nptl/pthread_create.c (sighandler_setxid): Likewise.
+	* nptl/descr.h (SETXID_BIT): Remove define.
+	(SETXID_BITMASK): Likewise.
+	(setxid_op): New member.
+
 	* nptl/allocatestack.c (get_cached_stack): Set both cancelstate
 	and canceltype on new stack allocation.
 	* nptl/cleanup_defer.c (__pthread_register_cancel_defer): Set
diff --git a/manual/users.texi b/manual/users.texi
index 433eead..2315171 100644
--- a/manual/users.texi
+++ b/manual/users.texi
@@ -305,7 +305,7 @@ include the header files @file{sys/types.h} and @file{unistd.h}.
 @c    nptl to propagate the syscall to all cloned processes used to
 @c    implement threads.
 @c   nptl_setxid @asulock @aculock
-@c     while holding the stack_alloc_lock, mark with SETXID_BITMASK all
+@c     while holding the stack_alloc_lock, mark with setxid_op all
 @c     threads that are not exiting, signal them until no thread remains
 @c     marked, clear the marks and run the syscall, then release the lock.
 @c    lll_lock @asulock @aculock
@@ -313,18 +313,18 @@ include the header files @file{sys/types.h} and @file{unistd.h}.
 @c    list_entry ok
 @c    setxid_mark_thread ok
 @c      if a thread is initializing, wait for it to be cloned.
-@c      mark it with SETXID_BITMASK if it's not exiting
+@c      mark it with setxid_op if it's not exiting
 @c    setxid_signal_thread ok
-@c      if a thread is marked with SETXID_BITMASK,
+@c      if a thread is marked with setxid_op,
 @c        send it the SIGSETXID signal
 @c    setxid_unmark_thread ok
-@c      clear SETXID_BITMASK and release the futex if SETXID_BITMASK is
+@c      clear setxid_op and release the futex if setxid_op is
 @c      set.
 @c    <syscall> ok
 @c    lll_unlock @aculock
 @c
 @c  sighandler_setxid ok
-@c    issue the syscall, clear SETXID_BITMASK, release the futex, and
+@c    issue the syscall, clear setxid_op, release the futex, and
 @c    wake up the signaller loop if the counter reached zero.
 This function sets the effective user ID of a process to @var{neweuid},
 provided that the process is allowed to change its effective user ID.  A
diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
index d57c769..3e70e0b 100644
--- a/nptl/allocatestack.c
+++ b/nptl/allocatestack.c
@@ -244,6 +244,8 @@ get_cached_stack (size_t *sizep, void **memp)
   /* No pending event.  */
   result->nextevent = NULL;
 
+  result->setxid_op = 0;
+
   /* Clear the DTV.  */
   dtv_t *dtv = GET_DTV (TLS_TPADJ (result));
   for (size_t cnt = 0; cnt < dtv[-1].counter; ++cnt)
@@ -975,8 +977,6 @@ static void
 internal_function
 setxid_mark_thread (struct xid_command *cmdp, struct pthread *t)
 {
-  int ch;
-
   /* Wait until this thread is cloned.  */
   if (t->setxid_futex == -1
       && ! atomic_compare_and_exchange_bool_acq (&t->setxid_futex, -2, -1))
@@ -987,16 +987,15 @@ setxid_mark_thread (struct xid_command *cmdp, struct pthread *t)
   /* Don't let the thread exit before the setxid handler runs.  */
   t->setxid_futex = 0;
 
+  unsigned int s = atomic_load_relaxed (&t->setxid_op);
   do
     {
-      ch = t->cancelhandling;
-
       /* If the thread is exiting right now, ignore it.  */
-      if ((ch & EXITING_BITMASK) != 0)
+      if ((atomic_load_relaxed (&t->cancelhandling) & EXITING_BITMASK) != 0)
 	{
 	  /* Release the futex if there is no other setxid in
 	     progress.  */
-	  if ((ch & SETXID_BITMASK) == 0)
+	  if (s == 0)
 	    {
 	      t->setxid_futex = 1;
 	      futex_wake (&t->setxid_futex, 1, FUTEX_PRIVATE);
@@ -1004,8 +1003,7 @@ setxid_mark_thread (struct xid_command *cmdp, struct pthread *t)
 	  return;
 	}
     }
-  while (atomic_compare_and_exchange_bool_acq (&t->cancelhandling,
-					       ch | SETXID_BITMASK, ch));
+  while (atomic_compare_exchange_weak_acquire(&t->setxid_op, &s, 1));
 }
 
 
@@ -1013,16 +1011,13 @@ static void
 internal_function
 setxid_unmark_thread (struct xid_command *cmdp, struct pthread *t)
 {
-  int ch;
-
+  unsigned int s = atomic_load_relaxed (&t->setxid_op);
   do
     {
-      ch = t->cancelhandling;
-      if ((ch & SETXID_BITMASK) == 0)
+      if (s == 0)
 	return;
     }
-  while (atomic_compare_and_exchange_bool_acq (&t->cancelhandling,
-					       ch & ~SETXID_BITMASK, ch));
+  while (atomic_compare_exchange_weak_acquire (&t->setxid_op, &s, 0));
 
   /* Release the futex just in case.  */
   t->setxid_futex = 1;
@@ -1034,7 +1029,7 @@ static int
 internal_function
 setxid_signal_thread (struct xid_command *cmdp, struct pthread *t)
 {
-  if ((t->cancelhandling & SETXID_BITMASK) == 0)
+  if (atomic_load_relaxed (&t->setxid_op) == 0)
     return 0;
 
   int val;
diff --git a/nptl/descr.h b/nptl/descr.h
index 5cc6f52..50853bf 100644
--- a/nptl/descr.h
+++ b/nptl/descr.h
@@ -283,9 +283,6 @@ struct pthread
   /* Bit set if thread terminated and TCB is freed.  */
 #define TERMINATED_BIT		4
 #define TERMINATED_BITMASK	(0x01 << TERMINATED_BIT)
-  /* Bit set if thread is supposed to change XID.  */
-#define SETXID_BIT		5
-#define SETXID_BITMASK		(0x01 << SETXID_BIT)
 
   /* Flag to indicate thread cancel disable state (PTHREAD_CANCEL_ENABLE or
      PTHREAD_CANCEL_DISABLE).  */
@@ -332,6 +329,9 @@ struct pthread
   /* Lock to synchronize access to the descriptor.  */
   int lock;
 
+  /* Set if thread is supposed to change XID.  */
+  int setxid_op;
+
   /* Lock for synchronizing setxid calls.  */
   unsigned int setxid_futex;
 
diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c
index 0a1b610..ecef5d2 100644
--- a/nptl/nptl-init.c
+++ b/nptl/nptl-init.c
@@ -269,14 +269,11 @@ sighandler_setxid (int sig, siginfo_t *si, void *ctx)
 
   /* Reset the SETXID flag.  */
   struct pthread *self = THREAD_SELF;
-  int flags, newval;
+  unsigned int s = atomic_load_relaxed (&self->setxid_op);
   do
-    {
-      flags = THREAD_GETMEM (self, cancelhandling);
-      newval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling,
-					  flags & ~SETXID_BITMASK, flags);
-    }
-  while (flags != newval);
+    if (s == 0)
+      return;
+  while (atomic_compare_exchange_weak_acquire (&self->setxid_op, &s, 0));
 
   /* And release the futex.  */
   self->setxid_futex = 1;
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index 40dc557..15cd9d5 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -576,17 +576,18 @@ START_THREAD_DEFN
   if (IS_DETACHED (pd))
     /* Free the TCB.  */
     __free_tcb (pd);
-  else if (__glibc_unlikely (pd->cancelhandling & SETXID_BITMASK))
+  else
     {
       /* Some other thread might call any of the setXid functions and expect
 	 us to reply.  In this case wait until we did that.  */
+      unsigned int s = atomic_load_relaxed (&pd->setxid_op);
       do
 	/* XXX This differs from the typical futex_wait_simple pattern in that
 	   the futex_wait condition (setxid_futex) is different from the
 	   condition used in the surrounding loop (cancelhandling).  We need
 	   to check and document why this is correct.  */
 	futex_wait_simple (&pd->setxid_futex, 0, FUTEX_PRIVATE);
-      while (pd->cancelhandling & SETXID_BITMASK);
+      while (atomic_compare_exchange_weak_acquire (&pd->setxid_op, &s, 1));
 
       /* Reset the value so that the stack can be reused.  */
       pd->setxid_futex = 0;

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=b6c7058acee871a6b79c407d876a470b5d1236d2

commit b6c7058acee871a6b79c407d876a470b5d1236d2
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Fri Jan 20 17:24:35 2017 -0200

    nptl: Move cancel state and type out cancelhandling
    
    This patch move both the cancel state (PTHREAD_CANCEL_ENABLE and
    PTHREAD_CANCEL_DISABLE) and cancel type (PTHREAD_CANCEL_DEFERRED and
    PTHREAD_CANCEL_ASYNCHRONOUS) out of cancelhandling member.  The idea
    is to avoid atomic handling of cancelhandling where these states
    are concerned since with exclusive member they are not concurrent
    accessed:
    
      * pthread_setcancel{type,state} and internal functions
        __pthread_{un}register_cancel_defer (and its analogous compat
        versions) only change the type/state of the calling thread.
      * __syscall_cancel also only requires to check the state of
        calling thread.
      * sigcancel_handler is executed only for the thread about to be
        potentially canceled.
      * pthread_join deadlock checks only requires access the state for
        the calling thread.
      * Same behavior for pthread_testcancel.
    
    With this change the cancelhandling member from pthread struct is
    used solely for cancelation handling and setxid signaling.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* nptl/allocatestack.c (get_cached_stack): Set both cancelstate
    	and canceltype on new stack allocation.
    	* nptl/cleanup_defer.c (__pthread_register_cancel_defer): Set
    	canceltype directly instead of using cancelhandling member.
    	(__pthread_unregister_cancel_restore): Likewise.
    	* nptl/cleanup_defer_compat.c (_pthread_cleanup_push_defer):
    	Likewise.
    	(_pthread_cleanup_pop_restore): Likewise.
    	* nptl/descr.h (CANCELSTATE_BIT): Remove flag.
    	(CANCELSTATE_BITMASK): Likewise.
    	(CANCELTYPE_BIT): Likewise.
    	(CANCELTYPE_BITMSK): Likewise.
    	(CANCEL_RESTMASK): Likewise.
    	(CANCEL_ENABLED_AND_CANCELED): Likewise.
    	(CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS): Likewise.
    	(cancelstate): New member.
    	(canceltype): Likewise.
    	* nptl/libc-cancellation.c (__syscall_cancel): Use cancelstate
    	instead of cancelhandling member.
    	* nptl/nptl-init.c (sigcancel_handler): Likewise.
    	* nptl/pthreadP.h (__do_cancel): Likewise.
    	(CANCELLATION_P): Likewise.
    	* nptl/pthread_join.c (pthread_join): Remove CANCELLATION_P
    	usage.
    	* nptl/pthread_testcancel.c (__pthread_testcancel): Likewise.
    	* nptl/pthread_setcancelstate.c (__pthread_setcancelstate):
    	Use cancelstate member instead of cancelhandling.
    	* nptl/pthread_setcanceltype.c (__pthread_setcanceltype): Use
    	canceltype member instead of canceltype.
    	* sysdeps/x86_64/nptl/tcb-offsets.sym (TCB_CANCELSTATE_BITMASK):
    	Remove.
    	(TCB_CANCELTYPE_BITMASK): Likewise.
    	(TCB_CANCEL_RETMASK): Likewise.

diff --git a/ChangeLog b/ChangeLog
index 4571572..ddd1fe0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,39 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* nptl/allocatestack.c (get_cached_stack): Set both cancelstate
+	and canceltype on new stack allocation.
+	* nptl/cleanup_defer.c (__pthread_register_cancel_defer): Set
+	canceltype directly instead of using cancelhandling member.
+	(__pthread_unregister_cancel_restore): Likewise.
+	* nptl/cleanup_defer_compat.c (_pthread_cleanup_push_defer):
+	Likewise.
+	(_pthread_cleanup_pop_restore): Likewise.
+	* nptl/descr.h (CANCELSTATE_BIT): Remove flag.
+	(CANCELSTATE_BITMASK): Likewise.
+	(CANCELTYPE_BIT): Likewise.
+	(CANCELTYPE_BITMSK): Likewise.
+	(CANCEL_RESTMASK): Likewise.
+	(CANCEL_ENABLED_AND_CANCELED): Likewise.
+	(CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS): Likewise.
+	(cancelstate): New member.
+	(canceltype): Likewise.
+	* nptl/libc-cancellation.c (__syscall_cancel): Use cancelstate
+	instead of cancelhandling member.
+	* nptl/nptl-init.c (sigcancel_handler): Likewise.
+	* nptl/pthreadP.h (__do_cancel): Likewise.
+	(CANCELLATION_P): Likewise.
+	* nptl/pthread_join.c (pthread_join): Remove CANCELLATION_P
+	usage.
+	* nptl/pthread_testcancel.c (__pthread_testcancel): Likewise.
+	* nptl/pthread_setcancelstate.c (__pthread_setcancelstate):
+	Use cancelstate member instead of cancelhandling.
+	* nptl/pthread_setcanceltype.c (__pthread_setcanceltype): Use
+	canceltype member instead of canceltype.
+	* sysdeps/x86_64/nptl/tcb-offsets.sym (TCB_CANCELSTATE_BITMASK):
+	Remove.
+	(TCB_CANCELTYPE_BITMASK): Likewise.
+	(TCB_CANCEL_RETMASK): Likewise.
+
 	* sysdeps/unix/sysv/linux/hppa/syscall_cancel.S: New file.
 	* sysdeps/unix/sysv/linux/hppa/sysdep-cancel.h (__pthread_get_pc):
 	New function.
diff --git a/manual/pattern.texi b/manual/pattern.texi
index 30a76c8..6f1ed22 100644
--- a/manual/pattern.texi
+++ b/manual/pattern.texi
@@ -1880,8 +1880,6 @@ the beginning of the vector.
 @c    pthread_setcancelstate @ascuplugin @ascuheap @acsmem
 @c      (disable cancellation around exec_comm; it may do_cancel the
 @c       second time, if async cancel is enabled)
-@c     THREAD_ATOMIC_CMPXCHG_VAL dup ok
-@c     CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS dup ok
 @c     do_cancel @ascuplugin @ascuheap @acsmem
 @c      THREAD_ATOMIC_BIT_SET dup ok
 @c      pthread_unwind @ascuplugin @ascuheap @acsmem
diff --git a/manual/process.texi b/manual/process.texi
index 085fdec..a8a5225 100644
--- a/manual/process.texi
+++ b/manual/process.texi
@@ -85,12 +85,7 @@ until the subprogram terminates before you can do anything else.
 @c    libc_cleanup_region_end ok
 @c     pthread_cleanup_pop_restore ok
 @c  SINGLE_THREAD_P ok
-@c  LIBC_CANCEL_ASYNC @ascuplugin @ascuheap @acsmem
-@c   libc_enable_asynccancel @ascuplugin @ascuheap @acsmem
-@c    CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS dup ok
 @c    do_cancel dup @ascuplugin @ascuheap @acsmem
-@c  LIBC_CANCEL_RESET ok
-@c   libc_disable_asynccancel ok
 @c    lll_futex_wait dup ok
 This function executes @var{command} as a shell command.  In @theglibc{},
 it always uses the default shell @code{sh} to run the command.
diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
index 6402ea4..d57c769 100644
--- a/nptl/allocatestack.c
+++ b/nptl/allocatestack.c
@@ -237,6 +237,8 @@ get_cached_stack (size_t *sizep, void **memp)
 
   /* Cancellation handling is back to the default.  */
   result->cancelhandling = 0;
+  result->cancelstate = PTHREAD_CANCEL_ENABLE; 
+  result->canceltype = PTHREAD_CANCEL_DEFERRED;
   result->cleanup = NULL;
 
   /* No pending event.  */
diff --git a/nptl/cleanup_defer.c b/nptl/cleanup_defer.c
index 7e1942d..0eb6332 100644
--- a/nptl/cleanup_defer.c
+++ b/nptl/cleanup_defer.c
@@ -31,27 +31,9 @@ __pthread_register_cancel_defer (__pthread_unwind_buf_t *buf)
   ibuf->priv.data.prev = THREAD_GETMEM (self, cleanup_jmp_buf);
   ibuf->priv.data.cleanup = THREAD_GETMEM (self, cleanup);
 
-  int cancelhandling = THREAD_GETMEM (self, cancelhandling);
-
-  /* Disable asynchronous cancellation for now.  */
-  if (__glibc_unlikely (cancelhandling & CANCELTYPE_BITMASK))
-    while (1)
-      {
-	int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling,
-						cancelhandling
-						& ~CANCELTYPE_BITMASK,
-						cancelhandling);
-	if (__glibc_likely (curval == cancelhandling))
-	  /* Successfully replaced the value.  */
-	  break;
-
-	/* Prepare for the next round.  */
-	cancelhandling = curval;
-      }
-
-  ibuf->priv.data.canceltype = (cancelhandling & CANCELTYPE_BITMASK
-				? PTHREAD_CANCEL_ASYNCHRONOUS
-				: PTHREAD_CANCEL_DEFERRED);
+  volatile struct pthread *pd = (volatile struct pthread *) self;
+  pd->canceltype = PTHREAD_CANCEL_DEFERRED;
+  ibuf->priv.data.canceltype = pd->canceltype;
 
   /* Store the new cleanup handler info.  */
   THREAD_SETMEM (self, cleanup_jmp_buf, (struct pthread_unwind_buf *) buf);
@@ -67,25 +49,11 @@ __pthread_unregister_cancel_restore (__pthread_unwind_buf_t *buf)
 
   THREAD_SETMEM (self, cleanup_jmp_buf, ibuf->priv.data.prev);
 
-  int cancelhandling;
+  volatile struct pthread *pd = (volatile struct pthread *) self;
   if (ibuf->priv.data.canceltype != PTHREAD_CANCEL_DEFERRED
-      && ((cancelhandling = THREAD_GETMEM (self, cancelhandling))
-	  & CANCELTYPE_BITMASK) == 0)
+      && pd->canceltype == PTHREAD_CANCEL_DEFERRED)
     {
-      while (1)
-	{
-	  int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling,
-						  cancelhandling
-						  | CANCELTYPE_BITMASK,
-						  cancelhandling);
-	  if (__glibc_likely (curval == cancelhandling))
-	    /* Successfully replaced the value.  */
-	    break;
-
-	  /* Prepare for the next round.  */
-	  cancelhandling = curval;
-	}
-
-      CANCELLATION_P (self);
+      pd->canceltype = PTHREAD_CANCEL_ASYNCHRONOUS;
+      __pthread_testcancel ();
     }
 }
diff --git a/nptl/cleanup_defer_compat.c b/nptl/cleanup_defer_compat.c
index 2705b46..7644977 100644
--- a/nptl/cleanup_defer_compat.c
+++ b/nptl/cleanup_defer_compat.c
@@ -29,27 +29,9 @@ _pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer,
   buffer->__arg = arg;
   buffer->__prev = THREAD_GETMEM (self, cleanup);
 
-  int cancelhandling = THREAD_GETMEM (self, cancelhandling);
-
-  /* Disable asynchronous cancellation for now.  */
-  if (__glibc_unlikely (cancelhandling & CANCELTYPE_BITMASK))
-    while (1)
-      {
-	int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling,
-						cancelhandling
-						& ~CANCELTYPE_BITMASK,
-						cancelhandling);
-	if (__glibc_likely (curval == cancelhandling))
-	  /* Successfully replaced the value.  */
-	  break;
-
-	/* Prepare for the next round.  */
-	cancelhandling = curval;
-      }
-
-  buffer->__canceltype = (cancelhandling & CANCELTYPE_BITMASK
-			  ? PTHREAD_CANCEL_ASYNCHRONOUS
-			  : PTHREAD_CANCEL_DEFERRED);
+  volatile struct pthread *pd = (volatile struct pthread *) self;
+  pd->canceltype = PTHREAD_CANCEL_DEFERRED;
+  buffer->__canceltype = pd->canceltype;
 
   THREAD_SETMEM (self, cleanup, buffer);
 }
@@ -64,26 +46,12 @@ _pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer,
 
   THREAD_SETMEM (self, cleanup, buffer->__prev);
 
-  int cancelhandling;
-  if (__builtin_expect (buffer->__canceltype != PTHREAD_CANCEL_DEFERRED, 0)
-      && ((cancelhandling = THREAD_GETMEM (self, cancelhandling))
-	  & CANCELTYPE_BITMASK) == 0)
+  volatile struct pthread *pd = (volatile struct pthread *) self;
+  if (buffer->__canceltype != PTHREAD_CANCEL_DEFERRED
+      && pd->canceltype == PTHREAD_CANCEL_DEFERRED)
     {
-      while (1)
-	{
-	  int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling,
-						  cancelhandling
-						  | CANCELTYPE_BITMASK,
-						  cancelhandling);
-	  if (__glibc_likely (curval == cancelhandling))
-	    /* Successfully replaced the value.  */
-	    break;
-
-	  /* Prepare for the next round.  */
-	  cancelhandling = curval;
-	}
-
-      CANCELLATION_P (self);
+      pd->canceltype = PTHREAD_CANCEL_ASYNCHRONOUS;
+      __pthread_testcancel ();
     }
 
   /* If necessary call the cleanup routine after we removed the
diff --git a/nptl/descr.h b/nptl/descr.h
index a7349fa..5cc6f52 100644
--- a/nptl/descr.h
+++ b/nptl/descr.h
@@ -274,13 +274,7 @@ struct pthread
 
   /* Flags determining processing of cancellation.  */
   int cancelhandling;
-  /* Bit set if cancellation is disabled.  */
-#define CANCELSTATE_BIT		0
-#define CANCELSTATE_BITMASK	(0x01 << CANCELSTATE_BIT)
-  /* Bit set if asynchronous cancellation mode is selected.  */
-#define CANCELTYPE_BIT		1
-#define CANCELTYPE_BITMASK	(0x01 << CANCELTYPE_BIT)
-  /* Bit set if threads is canceled.  */
+
 #define CANCELED_BIT		2
 #define CANCELED_BITMASK	(0x01 << CANCELED_BIT)
   /* Bit set if thread is exiting.  */
@@ -292,16 +286,13 @@ struct pthread
   /* Bit set if thread is supposed to change XID.  */
 #define SETXID_BIT		5
 #define SETXID_BITMASK		(0x01 << SETXID_BIT)
-  /* Mask for the rest.  Helps the compiler to optimize.  */
-#define CANCEL_RESTMASK		0xffffffc0
-
-#define CANCEL_ENABLED_AND_CANCELED(value) \
-  (((value) & (CANCELSTATE_BITMASK | CANCELED_BITMASK | EXITING_BITMASK	      \
-	       | CANCEL_RESTMASK | TERMINATED_BITMASK)) == CANCELED_BITMASK)
-#define CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS(value) \
-  (((value) & (CANCELSTATE_BITMASK | CANCELTYPE_BITMASK | CANCELED_BITMASK    \
-	       | EXITING_BITMASK | CANCEL_RESTMASK | TERMINATED_BITMASK))     \
-   == (CANCELTYPE_BITMASK | CANCELED_BITMASK))
+
+  /* Flag to indicate thread cancel disable state (PTHREAD_CANCEL_ENABLE or
+     PTHREAD_CANCEL_DISABLE).  */
+  int cancelstate;
+  /* Flag to indicate thread cancel type (PTHREAD_CANCEL_DEFERRED or
+     PTHREAD_CANCEL_ASYNCHRONOUS).  */
+  int canceltype;
 
   /* Flags.  Including those copied from the thread attribute.  */
   int flags;
diff --git a/nptl/libc-cancellation.c b/nptl/libc-cancellation.c
index a7bbd7f..335acab 100644
--- a/nptl/libc-cancellation.c
+++ b/nptl/libc-cancellation.c
@@ -32,7 +32,7 @@ __syscall_cancel (__syscall_arg_t nr, __syscall_arg_t a1,
   long int result;
 
   /* If cancellation is not enabled, call the syscall directly.  */
-  if (pd->cancelhandling & CANCELSTATE_BITMASK)
+  if (pd->cancelstate == PTHREAD_CANCEL_DISABLE)
     {
       INTERNAL_SYSCALL_DECL (err);
       result = INTERNAL_SYSCALL_NCS_CALL (nr, err, a1, a2, a3, a4, a5, a6
@@ -49,7 +49,7 @@ __syscall_cancel (__syscall_arg_t nr, __syscall_arg_t a1,
 
   if ((result == -EINTR)
       && (pd->cancelhandling & CANCELED_BITMASK)
-      && !(pd->cancelhandling & CANCELSTATE_BITMASK))
+      && (pd->cancelstate != PTHREAD_CANCEL_DISABLE))
     __syscall_do_cancel ();
 
   return result;
diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c
index af7e8af..0a1b610 100644
--- a/nptl/nptl-init.c
+++ b/nptl/nptl-init.c
@@ -204,7 +204,7 @@ sigcancel_handler (int sig, siginfo_t *si, void *ctx)
   volatile struct pthread *pd = (volatile struct pthread *) self;
   ucontext_t *uc = ctx;
 
-  if (((pd->cancelhandling & (CANCELSTATE_BITMASK)) != 0)
+  if ((pd->cancelstate == PTHREAD_CANCEL_DISABLE)
       || ((pd->cancelhandling & CANCELED_BITMASK) == 0))
     return;
 
@@ -219,7 +219,7 @@ sigcancel_handler (int sig, siginfo_t *si, void *ctx)
   extern const char __syscall_cancel_arch_start[1];
   extern const char __syscall_cancel_arch_end[1];
   uintptr_t pc = __pthread_get_pc (ctx);
-  if (pd->cancelhandling & CANCELTYPE_BITMASK
+  if (pd->canceltype == PTHREAD_CANCEL_ASYNCHRONOUS
       || (pc >= (uintptr_t) __syscall_cancel_arch_start
           && pc < (uintptr_t) __syscall_cancel_arch_end))
     {
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index aec0e08..37799b7 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -244,18 +244,6 @@ extern int __pthread_debug attribute_hidden;
 #endif
 
 
-/* Cancellation test.  */
-#define CANCELLATION_P(self) \
-  do {									      \
-    int cancelhandling = THREAD_GETMEM (self, cancelhandling);		      \
-    if (CANCEL_ENABLED_AND_CANCELED (cancelhandling))			      \
-      {									      \
-	THREAD_SETMEM (self, result, PTHREAD_CANCELED);			      \
-	__do_cancel ();							      \
-      }									      \
-  } while (0)
-
-
 extern void __pthread_unwind (__pthread_unwind_buf_t *__buf)
      __cleanup_fct_attribute __attribute ((__noreturn__))
 #if !defined SHARED && !IS_IN (libpthread)
@@ -291,22 +279,8 @@ __do_cancel (void)
 {
   struct pthread *self = THREAD_SELF;
 
-  /* Make sure we get no more cancellations by clearing the cancel
-     state.  */
-  int oldval = THREAD_GETMEM (self, cancelhandling);
-  while (1)
-    {
-      int newval = (oldval | CANCELSTATE_BITMASK);
-      newval &= ~(CANCELTYPE_BITMASK);
-      if (oldval == newval)
-	break;
-
-      int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
-					  oldval);
-      if (__glibc_likely (curval == oldval))
-	break;
-      oldval = curval;
-    }
+  /* Make sure we get no more cancellations.  */
+  self->cancelstate = PTHREAD_CANCEL_DISABLE;
 
   THREAD_SETMEM (self, result, PTHREAD_CANCELED);
 
diff --git a/nptl/pthread_cancel.c b/nptl/pthread_cancel.c
index d2e7737..7e80b1d 100644
--- a/nptl/pthread_cancel.c
+++ b/nptl/pthread_cancel.c
@@ -50,7 +50,7 @@ pthread_cancel (pthread_t th)
 
   /* Avoid signaling when thread attempts cancel itself (pthread_kill
      is expensive).  */
-  if (pd == THREAD_SELF && !(pd->canceltype & CANCELTYPE_BITMASK))
+  if (pd == THREAD_SELF && pd->canceltype == PTHREAD_CANCEL_DEFERRED)
     return 0;
 
   return __pthread_kill (th, SIGCANCEL);
diff --git a/nptl/pthread_join.c b/nptl/pthread_join.c
index bcdfea8..6f15fa7 100644
--- a/nptl/pthread_join.c
+++ b/nptl/pthread_join.c
@@ -69,7 +69,8 @@ pthread_join (pthread_t threadid, void **thread_return)
 	   && (pd->cancelhandling
 	       & (CANCELED_BITMASK | EXITING_BITMASK
 		  | TERMINATED_BITMASK)) == 0))
-      && !CANCEL_ENABLED_AND_CANCELED (self->cancelhandling))
+      && !(self->cancelstate == PTHREAD_CANCEL_ENABLE
+           && self->cancelhandling & CANCELED_BITMASK))
     /* This is a deadlock situation.  The threads are waiting for each
        other to finish.  Note that this is a "may" error.  To be 100%
        sure we catch this error we would have to lock the data
diff --git a/nptl/pthread_setcancelstate.c b/nptl/pthread_setcancelstate.c
index 8a1cb9a..40cfe54 100644
--- a/nptl/pthread_setcancelstate.c
+++ b/nptl/pthread_setcancelstate.c
@@ -24,46 +24,13 @@
 int
 __pthread_setcancelstate (int state, int *oldstate)
 {
-  volatile struct pthread *self;
-
   if (state < PTHREAD_CANCEL_ENABLE || state > PTHREAD_CANCEL_DISABLE)
     return EINVAL;
 
-  self = THREAD_SELF;
-
-  int oldval = THREAD_GETMEM (self, cancelhandling);
-  while (1)
-    {
-      int newval = (state == PTHREAD_CANCEL_DISABLE
-		    ? oldval | CANCELSTATE_BITMASK
-		    : oldval & ~CANCELSTATE_BITMASK);
-
-      /* Store the old value.  */
-      if (oldstate != NULL)
-	*oldstate = ((oldval & CANCELSTATE_BITMASK)
-		     ? PTHREAD_CANCEL_DISABLE : PTHREAD_CANCEL_ENABLE);
-
-      /* Avoid doing unnecessary work.  The atomic operation can
-	 potentially be expensive if the memory has to be locked and
-	 remote cache lines have to be invalidated.  */
-      if (oldval == newval)
-	break;
-
-      /* Update the cancel handling word.  This has to be done
-	 atomically since other bits could be modified as well.  */
-      int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
-					      oldval);
-      if (__glibc_likely (curval == oldval))
-	{
-	  if (CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS (newval))
-	    __do_cancel ();
-
-	  break;
-	}
-
-      /* Prepare for the next round.  */
-      oldval = curval;
-    }
+  volatile struct pthread *self = THREAD_SELF;
+  if (oldstate)
+    *oldstate = self->cancelstate;
+  self->cancelstate = state;
 
   return 0;
 }
diff --git a/nptl/pthread_setcanceltype.c b/nptl/pthread_setcanceltype.c
index dd1f374..4273359 100644
--- a/nptl/pthread_setcanceltype.c
+++ b/nptl/pthread_setcanceltype.c
@@ -33,43 +33,18 @@ __pthread_setcanceltype (int type, int *oldtype)
 #endif
 
   volatile struct pthread *self = THREAD_SELF;
-
-  int oldval = THREAD_GETMEM (self, cancelhandling);
-  while (1)
-    {
-      int newval = (type == PTHREAD_CANCEL_ASYNCHRONOUS
-		    ? oldval | CANCELTYPE_BITMASK
-		    : oldval & ~CANCELTYPE_BITMASK);
-
-      /* Store the old value.  */
-      if (oldtype != NULL)
-	*oldtype = ((oldval & CANCELTYPE_BITMASK)
-		    ? PTHREAD_CANCEL_ASYNCHRONOUS : PTHREAD_CANCEL_DEFERRED);
-
-      /* Avoid doing unnecessary work.  The atomic operation can
-	 potentially be expensive if the memory has to be locked and
-	 remote cache lines have to be invalidated.  */
-      if (oldval == newval)
-	break;
-
-      /* Update the cancel handling word.  This has to be done
-	 atomically since other bits could be modified as well.  */
-      int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
-					      oldval);
-      if (__glibc_likely (curval == oldval))
-	{
-	  if (CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS (newval))
-	    {
-	      THREAD_SETMEM (self, result, PTHREAD_CANCELED);
-	      __do_cancel ();
-	    }
-
-	  break;
-	}
-
-      /* Prepare for the next round.  */
-      oldval = curval;
-    }
+  if (oldtype)
+    *oldtype = self->canceltype;
+  self->canceltype = type;
+
+  /* Although pthread_setcanceltype is not a cancellation point,
+     there is a small race window where cancellation arrives just
+     before async cancellation is enabled and without a explicit
+     test the cancellation might not act upon.  Also, an application
+     can not work around by checking with pthread_testcase because
+     only pthread_setcanceltype is async-safe.  */
+  if (type == PTHREAD_CANCEL_ASYNCHRONOUS)
+    __pthread_testcancel ();
 
   return 0;
 }
diff --git a/nptl/pthread_testcancel.c b/nptl/pthread_testcancel.c
index 38b343f..8a65b94 100644
--- a/nptl/pthread_testcancel.c
+++ b/nptl/pthread_testcancel.c
@@ -23,7 +23,11 @@
 void
 __pthread_testcancel (void)
 {
-  CANCELLATION_P (THREAD_SELF);
+  pthread_t self = (pthread_t) THREAD_SELF;
+  volatile struct pthread *pd = (volatile struct pthread *) self;
+
+  if (pd->cancelhandling && pd->cancelstate == PTHREAD_CANCEL_ENABLE)
+    __do_cancel ();
 }
 strong_alias (__pthread_testcancel, pthread_testcancel)
 hidden_def (__pthread_testcancel)
diff --git a/sysdeps/x86_64/nptl/tcb-offsets.sym b/sysdeps/x86_64/nptl/tcb-offsets.sym
index b225e5b..37069dd 100644
--- a/sysdeps/x86_64/nptl/tcb-offsets.sym
+++ b/sysdeps/x86_64/nptl/tcb-offsets.sym
@@ -17,10 +17,7 @@ PRIVATE_FUTEX		offsetof (tcbhead_t, private_futex)
 #endif
 
 -- Not strictly offsets, but these values are also used in the TCB.
-TCB_CANCELSTATE_BITMASK	 CANCELSTATE_BITMASK
-TCB_CANCELTYPE_BITMASK	 CANCELTYPE_BITMASK
 TCB_CANCELED_BITMASK	 CANCELED_BITMASK
 TCB_EXITING_BITMASK	 EXITING_BITMASK
-TCB_CANCEL_RESTMASK	 CANCEL_RESTMASK
 TCB_TERMINATED_BITMASK	 TERMINATED_BITMASK
 TCB_PTHREAD_CANCELED	 PTHREAD_CANCELED

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=f5a9826425ec16fbc8ca820f09afd1bdb66f4341

commit f5a9826425ec16fbc8ca820f09afd1bdb66f4341
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Fri Feb 3 21:07:07 2017 -0200

    nptl: hppa: Fix Race conditions in pthread cancellation (BZ#12683)a
    
    This patch adds the hppa modifications required for the BZ#12683.
    It basically adds the required __pthread_get_pc function.
    
    HPPA requires an arch-specific syscall_cancel because the
    INTERNAL_SYSCALL_NCS adds some instruction to fetch the returned
    syscalls value.  The implementation were based on on default C
    version built with GCC 6.1
    
    Checked on hppa-linux-gnu with a simple fix to BZ#21016 to remove
    the hppa pthread cond implementations.
    
    	* sysdeps/unix/sysv/linux/hppa/syscall_cancel.S: New file.
    	* sysdeps/unix/sysv/linux/hppa/sysdep-cancel.h (__pthread_get_pc):
    	New function.

diff --git a/ChangeLog b/ChangeLog
index e92296a..4571572 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/hppa/syscall_cancel.S: New file.
+	* sysdeps/unix/sysv/linux/hppa/sysdep-cancel.h (__pthread_get_pc):
+	New function.
+
 	* nptl/libc-cancellation.c (__syscall_cancel): Define and use 7
 	argument syscall if architecture requires it.
 	* nptl/pthreadP.h (__syscall_cancel_arch): Likewise.
diff --git a/sysdeps/unix/sysv/linux/hppa/syscall_cancel.S b/sysdeps/unix/sysv/linux/hppa/syscall_cancel.S
new file mode 100644
index 0000000..2990278
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/hppa/syscall_cancel.S
@@ -0,0 +1,82 @@
+/* Cancellable syscall wrapper.  Linux/hppa version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+
+/* long int __syscall_cancel_arch (int *cancelhandling,
+				   long int nr,
+				   long int arg1,
+				   long int arg2,
+				   long int arg3,
+				   long int arg4,
+				   long int arg5,
+				   long int arg6)  */
+
+	.text
+ENTRY(__syscall_cancel_arch)
+	stw	%r2,-20(%r30)
+	ldo	128(%r30),%r30
+	cfi_def_cfa_offset (-128)
+	cfi_offset (2, -20)
+	ldw	-180(%r30),%r28
+	copy	%r24,%r31
+	stw	%r28,-104(%r30)
+	ldw	-184(%r30),%r28
+	stw	%r28,-108(%r30)
+	ldw	-188(%r30),%r28
+	stw	%r28,-112(%r30)
+	ldw	-192(%r30),%r28
+	stw	%r4,-100(%r30)
+	stw	%r28,-116(%r30)
+	copy	%r25,%r28
+	copy	%r23,%r25
+	stw	%r19,-32(%r30)
+	cfi_offset (4, 28)
+
+	.global __syscall_cancel_arch_start	
+.type __syscall_cancel_arch_start,@function	
+__syscall_cancel_arch_start:
+
+	ldw	0(%r26),%r20
+	stw	%r20,-120(%r30)
+	ldw	-120(%r30),%r20
+	bb,<	%r20,29,1f
+	ldw	-116(%r30),%r21
+	ldw	-112(%r30),%r22
+	copy	%r31,%r26
+	ldw	-108(%r30),%r23
+	ldw	-104(%r30),%r24
+	copy	%r19, %r4
+	ble	0x100(%sr2, %r0)
+
+	.global __syscall_cancel_arch_end	
+.type __syscall_cancel_arch_end,@function	
+__syscall_cancel_arch_end:
+
+	copy	%r28, %r20
+	copy	%r4, %r19
+	ldw	-148(%r30),%r2
+	ldw	-100(%r30),%r4
+	bv	%r0(%r2)
+	ldo	-128(%r30),%r30
+1:
+	bl __syscall_do_cancel,%r2
+	nop
+	nop
+END(__syscall_cancel_arch)
+libc_hidden_def (__syscall_cancel_arch)
diff --git a/sysdeps/unix/sysv/linux/hppa/sysdep-cancel.h b/sysdeps/unix/sysv/linux/hppa/sysdep-cancel.h
index a6189a7..60efb2f 100644
--- a/sysdeps/unix/sysv/linux/hppa/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/hppa/sysdep-cancel.h
@@ -49,3 +49,9 @@
 #define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
+
+static inline
+uintptr_t __pthread_get_pc (const struct ucontext *uc)
+{
+  return (uintptr_t) uc->uc_mcontext.sc_gr[31] & ~0x4;
+}

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=09cb407519ed5351aba49e508134bb46103457bf

commit 09cb407519ed5351aba49e508134bb46103457bf
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Jan 16 17:03:07 2017 -0200

    nptl: mips: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patch adds the mips modifications required for the BZ#12683.
    It adds the required __pthread_get_pc function and adds 7 argument
    cancellable syscall support.
    
    To avoid code pessimization and add a requirement on all architectures
    to support {INLINE,INTERNAL)_SYSCALL, the 7 argument support is added
    through a flag, HAVE_CANCELABLE_SYSCALL_WITH_7_ARGS, which changes
    the signature and prototype of the requires macros and functions
    (SYSCALL_CANCEL, __syscall_cancel and __syscall_cancel_arch). As
    default 6 arguments cancellable syscalls are use.
    
    MIPS o32 requires an arch-specific implementation because
    INTERNAL_SYSCALL_NCS adds an 'addiu' just after the syscall
    instruction which invalidates the checks on sigcancel_handler.
    
    Checked against a build and make check run-built-tests=no for
    mips-gnu-linux, mips64-linux-gnu, mips64-linux-gnun32.  I also
    ran some basic o32 and n64 cancellation tests on a simulates
    mips64 qemu system.
    
    	* nptl/libc-cancellation.c (__syscall_cancel): Define and use 7
    	argument syscall if architecture requires it.
    	* nptl/pthreadP.h (__syscall_cancel_arch): Likewise.
    	(__SYSCALL_CANCEL0): Likewise.
    	(__SYSCALL_CANCEL1): Likewise.
    	(__SYSCALL_CANCEL2): Likewise.
    	(__SYSCALL_CANCEL3): Likewise.
    	(__SYSCALL_CANCEL4): Likewise.
    	(__SYSCALL_CANCEL5): Likewise.
    	(__SYSCALL_CANCEL6): Likewise.
    	(__SYSCALL_CANCEL6): New macro.
    	* sysdeps/unix/sysdep.h (__syscall_cancel): Define with 7 argument
    	if architecture requires it.
    	(__SYSCALL_CANCEL7_ARG_DEF): New macro.
    	(__SYSCALL_CANCEL7_ARG): Likewise.
    	(__SYSCALL_CANCEL7_ARG7): Likewise.
    	* sysdeps/unix/sysv/linux/lowlevellock-futex.h
    	(lll_futex_timed_wait_cancel): Use 7 arguments if architecture requires
    	it.
    	(lll_futex_timed_wait_bitset_cancel): Likewise.
    	* sysdeps/unix/sysv/linux/syscall_cancel.c (__syscall_cancel_arch):
    	Likewise.
    	* sysdeps/mips/nptl/tls.h (READ_THREAD_POINTER): Check __mips_isa_rev
    	existance for macro definition.
    	* sysdeps/unix/sysv/linux/mips/sysdep-cancel.h (__pthread_get_pc):
    	New function.
    	* sysdeps/unix/sysv/linux/mips/mips32/syscall_cancel.S: New file.
    	* sysdeps/unix/sysv/linux/mips/mips32/sysdep.h
    	(HAVE_CANCELABLE_SYSCALL_WITH_7_ARGS): Define.

diff --git a/ChangeLog b/ChangeLog
index f993ce2..e92296a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,35 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* nptl/libc-cancellation.c (__syscall_cancel): Define and use 7
+	argument syscall if architecture requires it.
+	* nptl/pthreadP.h (__syscall_cancel_arch): Likewise.
+	(__SYSCALL_CANCEL0): Likewise.
+	(__SYSCALL_CANCEL1): Likewise.
+	(__SYSCALL_CANCEL2): Likewise.
+	(__SYSCALL_CANCEL3): Likewise.
+	(__SYSCALL_CANCEL4): Likewise.
+	(__SYSCALL_CANCEL5): Likewise.
+	(__SYSCALL_CANCEL6): Likewise.
+	(__SYSCALL_CANCEL6): New macro.
+	* sysdeps/unix/sysdep.h (__syscall_cancel): Define with 7 argument
+	if architecture requires it.
+	(__SYSCALL_CANCEL7_ARG_DEF): New macro.
+	(__SYSCALL_CANCEL7_ARG): Likewise.
+	(__SYSCALL_CANCEL7_ARG7): Likewise.
+	* sysdeps/unix/sysv/linux/lowlevellock-futex.h
+	(lll_futex_timed_wait_cancel): Use 7 arguments if architecture requires
+	it.
+	(lll_futex_timed_wait_bitset_cancel): Likewise.
+	* sysdeps/unix/sysv/linux/syscall_cancel.c (__syscall_cancel_arch):
+	Likewise.
+	* sysdeps/mips/nptl/tls.h (READ_THREAD_POINTER): Check __mips_isa_rev
+	existance for macro definition.
+	* sysdeps/unix/sysv/linux/mips/sysdep-cancel.h (__pthread_get_pc):
+	New function.
+	* sysdeps/unix/sysv/linux/mips/mips32/syscall_cancel.S: New file.
+	* sysdeps/unix/sysv/linux/mips/mips32/sysdep.h
+	(HAVE_CANCELABLE_SYSCALL_WITH_7_ARGS): Define.
+
 	* sysdeps/unix/sysv/linux/sh/sysdep-cancel.h (__pthread_get_pc):
 	New function.
 
diff --git a/nptl/libc-cancellation.c b/nptl/libc-cancellation.c
index b013435..a7bbd7f 100644
--- a/nptl/libc-cancellation.c
+++ b/nptl/libc-cancellation.c
@@ -25,7 +25,7 @@ long int
 __syscall_cancel (__syscall_arg_t nr, __syscall_arg_t a1,
 		  __syscall_arg_t a2, __syscall_arg_t a3,
 		  __syscall_arg_t a4, __syscall_arg_t a5,
-		  __syscall_arg_t a6)
+		  __syscall_arg_t a6 __SYSCALL_CANCEL7_ARG_DEF)
 {
   pthread_t self = (pthread_t) THREAD_SELF;
   volatile struct pthread *pd = (volatile struct pthread *) self;
@@ -35,7 +35,8 @@ __syscall_cancel (__syscall_arg_t nr, __syscall_arg_t a1,
   if (pd->cancelhandling & CANCELSTATE_BITMASK)
     {
       INTERNAL_SYSCALL_DECL (err);
-      result = INTERNAL_SYSCALL_NCS_CALL (nr, err, a1, a2, a3, a4, a5, a6);
+      result = INTERNAL_SYSCALL_NCS_CALL (nr, err, a1, a2, a3, a4, a5, a6
+					  __SYSCALL_CANCEL7_ARG7);
       if (INTERNAL_SYSCALL_ERROR_P (result, err))
 	return -INTERNAL_SYSCALL_ERRNO (result, err);
       return result;
@@ -44,7 +45,7 @@ __syscall_cancel (__syscall_arg_t nr, __syscall_arg_t a1,
   /* Call the arch-specific entry points that contains the globals markers
      to be checked by SIGCANCEL handler.  */
   result = __syscall_cancel_arch (&pd->cancelhandling, nr, a1, a2, a3, a4, a5,
-			          a6);
+			          a6 __SYSCALL_CANCEL7_ARG7);
 
   if ((result == -EINTR)
       && (pd->cancelhandling & CANCELED_BITMASK)
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index 7b2cf71..aec0e08 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -317,7 +317,8 @@ __do_cancel (void)
 
 extern long int __syscall_cancel_arch (volatile int *, __syscall_arg_t nr,
      __syscall_arg_t arg1, __syscall_arg_t arg2, __syscall_arg_t arg3,
-     __syscall_arg_t arg4, __syscall_arg_t arg5, __syscall_arg_t arg6);
+     __syscall_arg_t arg4, __syscall_arg_t arg5, __syscall_arg_t arg6
+     __SYSCALL_CANCEL7_ARG_DEF);
 libc_hidden_proto (__syscall_cancel_arch);
 
 extern void __syscall_do_cancel (void)
diff --git a/sysdeps/mips/nptl/tls.h b/sysdeps/mips/nptl/tls.h
index 913f7d3..0d32424 100644
--- a/sysdeps/mips/nptl/tls.h
+++ b/sysdeps/mips/nptl/tls.h
@@ -35,7 +35,7 @@
 # define READ_THREAD_POINTER() (__builtin_thread_pointer ())
 #else
 /* Note: rd must be $v1 to be ABI-conformant.  */
-# if __mips_isa_rev >= 2
+# if defined __mips_isa_rev && __mips_isa_rev >= 2
 #  define READ_THREAD_POINTER() \
      ({ void *__result;							      \
         asm volatile ("rdhwr\t%0, $29" : "=v" (__result));	      	      \
diff --git a/sysdeps/unix/sysdep.h b/sysdeps/unix/sysdep.h
index 10669ae..c90898d 100644
--- a/sysdeps/unix/sysdep.h
+++ b/sysdeps/unix/sysdep.h
@@ -121,29 +121,51 @@ typedef long int __syscall_arg_t;
 # define __SSC(__x) ((__syscall_arg_t) (__x))
 #endif
 
+/* Adjust both the __syscall_cancel and the SYSCALL_CANCEL macro to support
+   7 arguments instead of default 6 (for some architectures like mip32).
+   We need it because using 7 arguments for all architecture would require
+   then to implement both {INTERNAL,INLINE}_SYSCALL and __syscall_cancel_arch
+   to accept 7 arguments.  */
+#ifdef HAVE_CANCELABLE_SYSCALL_WITH_7_ARGS
+# define __SYSCALL_CANCEL7_ARG_DEF 	, __syscall_arg_t arg7
+# define __SYSCALL_CANCEL7_ARG		, 0
+# define __SYSCALL_CANCEL7_ARG7		, arg7
+#else
+# define __SYSCALL_CANCEL7_ARG_DEF
+# define __SYSCALL_CANCEL7_ARG
+# define __SYSCALL_CANCEL7_ARG7
+#endif
+
 long int __syscall_cancel (__syscall_arg_t nr, __syscall_arg_t arg1,
 			   __syscall_arg_t arg2, __syscall_arg_t arg3,
 			   __syscall_arg_t arg4, __syscall_arg_t arg5,
-			   __syscall_arg_t arg6);
+			   __syscall_arg_t arg6 __SYSCALL_CANCEL7_ARG_DEF);
 libc_hidden_proto (__syscall_cancel);
 
 #define __SYSCALL_CANCEL0(name) \
-  (__syscall_cancel)(__NR_##name, 0, 0, 0, 0, 0, 0)
+  (__syscall_cancel)(__NR_##name, 0, 0, 0, 0, 0, 0 \
+		     __SYSCALL_CANCEL7_ARG)
 #define __SYSCALL_CANCEL1(name, a1) \
-  (__syscall_cancel)(__NR_##name, __SSC(a1), 0, 0, 0, 0, 0)
+  (__syscall_cancel)(__NR_##name, __SSC(a1), 0, 0, 0, 0, 0 \
+		     __SYSCALL_CANCEL7_ARG)
 #define __SYSCALL_CANCEL2(name, a1, a2) \
-  (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), 0, 0, 0, 0)
+  (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), 0, 0, 0, 0 \
+		     __SYSCALL_CANCEL7_ARG)
 #define __SYSCALL_CANCEL3(name, a1, a2, a3) \
-  (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), __SSC(a3), 0, 0, 0)
+  (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), __SSC(a3), 0, 0, 0 \
+		     __SYSCALL_CANCEL7_ARG)
 #define __SYSCALL_CANCEL4(name, a1, a2, a3, a4) \
   (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), __SSC(a3), \
-		     __SSC(a4), 0, 0)
+		     __SSC(a4), 0, 0 __SYSCALL_CANCEL7_ARG)
 #define __SYSCALL_CANCEL5(name, a1, a2, a3, a4, a5) \
   (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), __SSC(a3), \
-		     __SSC(a4), __SSC(a5), 0)
+		     __SSC(a4), __SSC(a5), 0 __SYSCALL_CANCEL7_ARG)
 #define __SYSCALL_CANCEL6(name, a1, a2, a3, a4, a5, a6) \
   (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), __SSC(a3), \
-		     __SSC(a4), __SSC(a5), __SSC(a6))
+		     __SSC(a4), __SSC(a5), __SSC(a6) __SYSCALL_CANCEL7_ARG)
+#define __SYSCALL_CANCEL7(name, a1, a2, a3, a4, a5, a6, a7) \
+  (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), __SSC(a3), \
+		     __SSC(a4), __SSC(a5), __SSC(a6), __SSC(a7))
 
 #define __SYSCALL_CANCEL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n
 #define __SYSCALL_CANCEL_NARGS(...) \
diff --git a/sysdeps/unix/sysv/linux/lowlevellock-futex.h b/sysdeps/unix/sysv/linux/lowlevellock-futex.h
index 04085a5..7902300 100644
--- a/sysdeps/unix/sysv/linux/lowlevellock-futex.h
+++ b/sysdeps/unix/sysv/linux/lowlevellock-futex.h
@@ -151,7 +151,8 @@
                                                                               \
     __ret = __syscall_cancel (__NR_futex, __SSC (futexp),		      \
 			      __SSC (__lll_private_flag (__op, private)),     \
-			      __SSC (val), __SSC (timespec), 0, 0);           \
+			      __SSC (val), __SSC (timespec), 0, 0	      \
+			      __SYSCALL_CANCEL7_ARG);                         \
     __ret;								      \
   })
 
@@ -164,7 +165,8 @@
     __ret = __syscall_cancel (__NR_futex, __SSC (futexp),		      \
 			      __SSC (__lll_private_flag (__op, private)),     \
 			      __SSC (val), __SSC (timespec), 0,	              \
-                              FUTEX_BITSET_MATCH_ANY);                        \
+                              FUTEX_BITSET_MATCH_ANY                          \
+			      __SYSCALL_CANCEL7_ARG);                         \
     __ret;								      \
   })
 
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/syscall_cancel.S b/sysdeps/unix/sysv/linux/mips/mips32/syscall_cancel.S
new file mode 100644
index 0000000..75c4390
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/mips/mips32/syscall_cancel.S
@@ -0,0 +1,128 @@
+/* Cancellable syscall wrapper.  Linux/mips32 version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+#include <sys/asm.h>
+
+/* long int __syscall_cancel_arch (int *cancelhandling,
+				   __syscall_arg_t nr,
+				   __syscall_arg_t arg1,
+				   __syscall_arg_t arg2,
+				   __syscall_arg_t arg3,
+				   __syscall_arg_t arg4,
+				   __syscall_arg_t arg5,
+				   __syscall_arg_t arg6,
+				   __syscall_arg_t arg7)  */
+
+#define FRAME_SIZE 56
+
+NESTED (__syscall_cancel_arch, FRAME_SIZE, fp)
+	.mask	0xc0070000,-SZREG
+	.fmask	0x00000000,0
+
+	PTR_ADDIU sp, -FRAME_SIZE
+	cfi_def_cfa_offset (FRAME_SIZE)
+
+	sw	fp,48(sp)
+	sw	ra,52(sp)
+	sw	s2,44(sp)
+	sw	s1,40(sp)
+	sw	s0,36(sp)
+#ifdef __PIC__
+	.cprestore	16
+#endif
+	cfi_offset (31, -4)
+	cfi_offset (30, -8)
+	cfi_offset (18, -12)
+	cfi_offset (17, -16)
+	cfi_offset (16, -20)
+	move	fp,sp
+	cfi_def_cfa_register (30)
+
+	.globl __syscall_cancel_arch_start
+	.type __syscall_cancel_arch_start, @function
+__syscall_cancel_arch_start:
+
+	lw	v0,0(a0)
+	andi	v0,v0,0x4
+	bne	v0,zero,2f
+
+	addiu	sp,sp,-16
+	addiu	v0,sp,16
+	sw	v0,24(fp)
+
+	move	s0,a1
+	move	a0,a2
+	move	a1,a3
+	lw	a2,72(fp)
+	lw	a3,76(fp)
+	lw	v0,84(fp)
+	lw	s1,80(fp)
+	lw	s2,88(fp)
+
+	.set	noreorder
+	subu	sp, 32
+	sw	s1, 16(sp)
+	sw	v0, 20(sp)
+	sw	s2, 24(sp)
+	move	v0, $16
+	syscall
+
+	.globl __syscall_cancel_arch_end
+	.type __syscall_cancel_arch_end, @function
+__syscall_cancel_arch_end:
+	addiu	sp, 32
+	.set	reorder
+
+	beq	a3,zero,1f
+	subu	v0,zero,v0
+1:
+	move	sp,fp
+	cfi_remember_state
+	cfi_def_cfa_register (29)
+	lw	ra,52(fp)
+	lw	fp,48(sp)
+	lw	s2,44(sp)
+	lw	s1,40(sp)
+	lw	s0,36(sp)
+	.set	noreorder
+	.set	nomacro
+	jr	ra
+	addiu	sp,sp,FRAME_SIZE
+
+	.set	macro
+	.set	reorder
+
+	cfi_def_cfa_offset (0)
+	cfi_restore (16)
+	cfi_restore (17)
+	cfi_restore (18)
+	cfi_restore (30)
+	cfi_restore (31)
+
+2:
+	cfi_restore_state
+#ifdef __PIC__
+	PTR_LA	t9, __syscall_do_cancel
+	jalr	t9
+#else
+	jal	__syscall_do_cancel
+#endif
+
+END (__syscall_cancel_arch)
+libc_hidden_def (__syscall_cancel_arch)
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h b/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h
index e9e3ee7..1855c76 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h
+++ b/sysdeps/unix/sysv/linux/mips/mips32/sysdep.h
@@ -18,6 +18,10 @@
 #ifndef _LINUX_MIPS_MIPS32_SYSDEP_H
 #define _LINUX_MIPS_MIPS32_SYSDEP_H 1
 
+/* mips32 have cancelable syscalls with 7 arguments (currently only
+   sync_file_range).  */
+#define HAVE_CANCELABLE_SYSCALL_WITH_7_ARGS	1
+
 /* There is some commonality.  */
 #include <sysdeps/unix/sysv/linux/sysdep.h>
 #include <sysdeps/unix/mips/mips32/sysdep.h>
diff --git a/sysdeps/unix/sysv/linux/mips/sysdep-cancel.h b/sysdeps/unix/sysv/linux/mips/sysdep-cancel.h
index fe9a3fc..230889e 100644
--- a/sysdeps/unix/sysv/linux/mips/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/mips/sysdep-cancel.h
@@ -15,6 +15,9 @@
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef __SYSDEP_CANCEL_H
+# define __SYSDEP_CANCEL_H
+
 #include <sysdep.h>
 #include <sysdeps/generic/sysdep.h>
 #include <tls.h>
@@ -37,3 +40,11 @@
 #define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
+
+static inline
+uintptr_t __pthread_get_pc (const struct ucontext *uc)
+{
+  return uc->uc_mcontext.pc;
+}
+
+#endif /* __SYSDEP_CANCEL_H  */
diff --git a/sysdeps/unix/sysv/linux/syscall_cancel.c b/sysdeps/unix/sysv/linux/syscall_cancel.c
index cb8f6ae..c9d4126 100644
--- a/sysdeps/unix/sysv/linux/syscall_cancel.c
+++ b/sysdeps/unix/sysv/linux/syscall_cancel.c
@@ -43,14 +43,16 @@ long int
 __syscall_cancel_arch (volatile int *ch, __syscall_arg_t nr,
 		       __syscall_arg_t a1, __syscall_arg_t a2,
 		       __syscall_arg_t a3, __syscall_arg_t a4,
-		       __syscall_arg_t a5, __syscall_arg_t a6)
+		       __syscall_arg_t a5, __syscall_arg_t a6
+		       __SYSCALL_CANCEL7_ARG_DEF)
 {
   ADD_LABEL ("__syscall_cancel_arch_start");
   if (__glibc_unlikely (*ch & CANCELED_BITMASK))
     __syscall_do_cancel();
 
   INTERNAL_SYSCALL_DECL(err);
-  long int result = INTERNAL_SYSCALL_NCS (nr, err, 6, a1, a2, a3, a4, a5, a6);
+  long int result = INTERNAL_SYSCALL_NCS_CALL (nr, err, a1, a2, a3, a4, a5,
+					       a6 __SYSCALL_CANCEL7_ARG7);
   ADD_LABEL ("__syscall_cancel_arch_end");
   if (INTERNAL_SYSCALL_ERROR_P (result, err))
     return -INTERNAL_SYSCALL_ERRNO (result, err);

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=7807aceaed8603822bcf0970e4cb2878ef21c559

commit 7807aceaed8603822bcf0970e4cb2878ef21c559
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Jan 16 17:03:03 2017 -0200

    nptl: sh: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patch adds the sh modifications required for the BZ#12683.
    It basically adds the required __pthread_get_pc function.
    
    SH requires an arch-specific syscall_cancel because the
    INTERNAL_SYSCALL_NCS adds the required or instruction to workaround
    a hardware bug.  The implementation were based on on default C
    version built with GCC 6.1
    
    Checked against a build and make check run-built-tests=no for
    sh4-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/sh/sysdep-cancel.h (__pthread_get_pc):
    	New function.
    	* sysdeps/unix/sysv/linux/sh/syscall_cancel.S: New file.

diff --git a/ChangeLog b/ChangeLog
index d8c4cb8..f993ce2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/sh/sysdep-cancel.h (__pthread_get_pc):
+	New function.
+
 	* sysdeps/unix/sysv/linux/nios2/sysdep-cancel.h (__pthread_get_pc):
 	New function.
 
diff --git a/sysdeps/unix/sysv/linux/sh/syscall_cancel.S b/sysdeps/unix/sysv/linux/sh/syscall_cancel.S
new file mode 100644
index 0000000..2b2e62a
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sh/syscall_cancel.S
@@ -0,0 +1,85 @@
+/* Cancellable syscall wrapper.  Linux/sh version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+
+/* long int __syscall_cancel_arch (int *cancelhandling,
+				   long int nr,
+				   long int arg1,
+				   long int arg2,
+				   long int arg3,
+				   long int arg4,
+				   long int arg5,
+				   long int arg6)  */
+
+ENTRY (__syscall_cancel_arch)
+
+	sts.l	pr,@-r15
+	cfi_def_cfa_offset (4)
+	cfi_offset (17, -4)
+
+	.globl __syscall_cancel_arch_start
+__syscall_cancel_arch_start:
+
+	/* if (*cancelhandling & CANCELED_BITMASK)
+	     __syscall_do_cancel()  */
+	mov.l	@r4,r0
+	tst	#4,r0
+	bf/s	1f
+
+	/* Issue a 6 argument syscall.  */
+	mov	r5,r3
+	mov	r6,r4
+	mov	r7,r5
+	mov.l	@(4,r15),r6
+	mov.l	@(8,r15),r7
+	mov.l	@(12,r15),r0
+	mov.l	@(16,r15),r1
+	trapa	#0x16
+/* The additional or is a workaround for a hardware issue:
+   http://documentation.renesas.com/eng/products/mpumcu/tu/tnsh7456ae.pdf
+ */
+	.globl __syscall_cancel_arch_end
+__syscall_cancel_arch_end:
+
+	or	r0,r0;
+	or	r0,r0;
+	or	r0,r0;
+	or	r0,r0;
+	or	r0,r0
+
+	lds.l	@r15+,pr
+	cfi_remember_state
+	cfi_restore (17)
+	cfi_def_cfa_offset (0)
+	rts	
+	nop
+
+	.align 1
+	cfi_restore_state
+1:
+	mov.l	2f,r1
+	jsr	@r1
+	nop
+
+	.align 2
+2:
+	.long	__syscall_do_cancel
+
+END (__syscall_cancel_arch)
+libc_hidden_def (__syscall_cancel_arch)
diff --git a/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h b/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h
index 1ea501b..8848c62 100644
--- a/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h
@@ -37,3 +37,9 @@
 #define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
+
+static inline
+uintptr_t __pthread_get_pc (const struct ucontext *uc)
+{
+  return uc->uc_mcontext.pc;
+}

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=542b2b6e82573472a0bf5bc167bfd01fe48332fd

commit 542b2b6e82573472a0bf5bc167bfd01fe48332fd
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Jan 16 17:02:53 2017 -0200

    nptl: nios2: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patch adds the nios2 modifications required for the BZ#12683.
    It basically adds the required __pthread_get_pc function
    
    The default syscall_cancel.c should be fine for nios2 and GCC 6.1
    generates the following assembly for syscall_cancel.c:
    
    [...]
    .LVL4:
            trap
    .LVL5:
    .LBE3:
    .LBE2:
            .loc 1 53 0
            .global __syscall_cancel_arch_end
    __syscall_cancel_arch_end:
    [...]
    
    Checked against a build and make check run-built-tests=no for
    nios2-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/nios2/sysdep-cancel.h (__pthread_get_pc):
    	New function.

diff --git a/ChangeLog b/ChangeLog
index eeaa86d..d8c4cb8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/nios2/sysdep-cancel.h (__pthread_get_pc):
+	New function.
+
 	* sysdeps/unix/sysv/linux/sparc/sysdep-cancel.h (__pthread_get_pc):
 	New function.
 	* sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S: New file.
diff --git a/sysdeps/unix/sysv/linux/nios2/sysdep-cancel.h b/sysdeps/unix/sysv/linux/nios2/sysdep-cancel.h
index 7647363..52a4640 100644
--- a/sysdeps/unix/sysv/linux/nios2/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/nios2/sysdep-cancel.h
@@ -37,3 +37,12 @@
 #define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
+
+static inline
+uintptr_t __pthread_get_pc (const struct ucontext *uc)
+{
+  /* rt_restore_ucontext (arch/nios/kernel/signal.c) sets this position
+     to 'ea' register which is stated as exception return address (pc)
+     at arch/nios2/include/asm/ptrace.h.  */
+  return uc->uc_mcontext.regs[27];
+}

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=973a2675a3b99f4f34e1b709f20fe203784c4d3f

commit 973a2675a3b99f4f34e1b709f20fe203784c4d3f
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Jan 16 17:02:36 2017 -0200

    nptl: sparc: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patch adds the sparc modifications required for the BZ#12683.
    It basically adds the required __pthread_get_pc function.
    
    Sparc requires arch-specific syscall_cancel implementation because
    INLINE_SYSCALL_NCS uses the __SYSCALL_STRING (defined different
    for sparc32 and sparc64) and it issues additional instructions
    after the syscall one to check the resulting errpr code. Both
    32 and 64 bits version were based on default C version built
    with GCC 6.1.
    
    Checked on a SPARC T5 for sparc64-linux-gnu and sparcv9-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/sparc/sysdep-cancel.h (__pthread_get_pc):
    	New function.
    	* sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S: New file.
    	* sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S: Likwise.
    	* sysdeps/unix/sysv/linux/sparc/sparc64/pause.c: New file.

diff --git a/ChangeLog b/ChangeLog
index 964025d..eeaa86d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/sparc/sysdep-cancel.h (__pthread_get_pc):
+	New function.
+	* sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S: New file.
+	* sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S: Likwise.
+	* sysdeps/unix/sysv/linux/sparc/sparc64/pause.c: Likewise.
+
 	* sysdeps/unix/sysv/linux/tile/sysdep-cancel.h (__pthread_get_pc):
 	New function.
 
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S b/sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S
new file mode 100644
index 0000000..111a40b
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/syscall_cancel.S
@@ -0,0 +1,74 @@
+/* Cancellable syscall wrapper.  Linux/sparc32 version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+
+/* long int __syscall_cancel_arch (int *cancelhandling,
+				   long int nr,
+				   long int arg1,
+				   long int arg2,
+				   long int arg3,
+				   long int arg4,
+				   long int arg5,
+				   long int arg6)  */
+
+ENTRY (__syscall_cancel_arch)
+	save	%sp, -104, %sp
+
+	cfi_window_save
+	cfi_register (15, 31)
+	cfi_def_cfa_register (30)
+
+	.globl __syscall_cancel_arch_start
+__syscall_cancel_arch_start:
+
+	/* if (*cancelhandling & CANCELED_BITMASK)
+	     __syscall_do_cancel()  */
+	ld	[%i0], %g2
+	andcc	%g2, 4, %g0
+	bne,pn	%icc, 2f
+
+	/* Issue a 6 argument syscall.  */
+	mov	%i1, %g1
+	mov	%i2, %o0
+	mov	%i3, %o1
+	mov	%i4, %o2
+	mov	%i5, %o3
+	ld	[%fp+92], %o4
+	ld	[%fp+96], %o5
+	ta	0x10
+
+	.globl __syscall_cancel_arch_end
+__syscall_cancel_arch_end:
+	bcc	1f
+	mov	0,%g1
+	sub	%g0, %o0, %o0
+	mov	1, %g1
+	
+1:
+	mov	%o0, %i0
+	return	%i7+8
+	 nop
+
+2:
+	call	__syscall_do_cancel, 0
+	 nop
+	nop
+
+END (__syscall_cancel_arch)
+libc_hidden_def (__syscall_cancel_arch)
diff --git a/sysdeps/unix/sysv/linux/sparc/sysdep-cancel.h b/sysdeps/unix/sysv/linux/sparc/sparc64/pause.c
similarity index 56%
copy from sysdeps/unix/sysv/linux/sparc/sysdep-cancel.h
copy to sysdeps/unix/sysv/linux/sparc/sparc64/pause.c
index 61bfa33..a9a5cc4 100644
--- a/sysdeps/unix/sysv/linux/sparc/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/pause.c
@@ -1,6 +1,6 @@
-/* Copyright (C) 2002-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1999-2017 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
+   Contributed by Richard Henderson (rth@tamu.edu).
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -16,23 +16,11 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <sysdep.h>
-#include <tls.h>
-#include <nptl/pthreadP.h>
+#include <sys/syscall.h>
 
-#if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
+/* On sparc interrupted pause syscall returns with a PC indicating a
+   side-effect and this deviates from other architectures.  Fall back to
+   ppool implementation.  */
+#undef __NR_pause
 
-# define SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF,				      \
-				   header.multiple_threads) == 0, 1)
-
-#else
-
-# define SINGLE_THREAD_P (1)
-# define NO_CANCELLATION 1
-
-#endif
-
-#define RTLD_SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
-				   header.multiple_threads) == 0, 1)
+#include <sysdeps/unix/sysv/linux/pause.c>
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S b/sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S
new file mode 100644
index 0000000..905530a
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/syscall_cancel.S
@@ -0,0 +1,74 @@
+/* Cancellable syscall wrapper.  Linux/sparc64 version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+
+/* long int __syscall_cancel_arch (int *cancelhandling,
+					long int nr,
+					long int arg1,
+					long int arg2,
+					long int arg3,
+					long int arg4,
+					long int arg5,
+					long int arg6)  */
+
+ENTRY (__syscall_cancel_arch)
+	save	%sp, -176, %sp
+
+	cfi_window_save
+	cfi_register (15, 31)
+	cfi_def_cfa_register (30)
+
+	.globl __syscall_cancel_arch_start
+__syscall_cancel_arch_start:
+
+	/* if (*cancelhandling & CANCELED_BITMASK)
+	     __syscall_do_cancel()  */
+	lduw	[%i0], %g1
+	andcc	%g1, 4, %g0
+	bne,pn	%xcc, 2f
+
+	/* Issue a 6 argument syscall.  */
+	mov	%i1, %g1
+	mov	%i2, %o0
+	mov	%i3, %o1
+	mov	%i4, %o2
+	mov	%i5, %o3
+	ldx	[%fp + STACK_BIAS + 176], %o4
+	ldx	[%fp + STACK_BIAS + 184], %o5
+	ta	0x6d
+
+	.global __syscall_cancel_arch_end	
+__syscall_cancel_arch_end:
+
+	bcc,pt	%xcc, 1f
+	mov	0, %g1
+	sub	%g0, %o0, %o0
+	mov	1, %g1
+1:
+	mov	%o0, %i0
+	return	%i7+8
+	nop
+
+2:
+	call	__syscall_do_cancel, 0
+	nop
+	nop
+
+END (__syscall_cancel_arch)
+libc_hidden_def (__syscall_cancel_arch)
diff --git a/sysdeps/unix/sysv/linux/sparc/sysdep-cancel.h b/sysdeps/unix/sysv/linux/sparc/sysdep-cancel.h
index 61bfa33..e99b559 100644
--- a/sysdeps/unix/sysv/linux/sparc/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/sparc/sysdep-cancel.h
@@ -36,3 +36,15 @@
 #define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
+
+/* Different that other architectures, SPARC pass a sigcontext_t struct
+   in third argument for signal handler with SA_SIGINFO.  */
+static inline
+uintptr_t __pthread_get_pc (const struct sigcontext *sigctx)
+{
+#if __WORDSIZE == 64
+  return sigctx->sigc_regs.tpc;
+#else
+  return sigctx->si_regs.pc;
+#endif
+}

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=2852b4c3ac5e2a96ea8522a153a60b33b1afd851

commit 2852b4c3ac5e2a96ea8522a153a60b33b1afd851
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Jan 16 17:02:28 2017 -0200

    nptl: tile: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patch adds the tile modifications required for the BZ#12683.
    It basically adds the required __pthread_get_pc function
    
    The default syscall_cancel.c should be fine for tile and GCC 6.1
    generates the following assembly for syscall_cancel.c:
    
    [...]
            swint1
    .LVL5:
    .LBE2:
            .loc 1 53 0
            .global __syscall_cancel_arch_end
    __syscall_cancel_arch_end:
    [...]
    
    Checked against a build and make check run-built-tests=no for
    tile-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/tile/sysdep-cancel.h (__pthread_get_pc):
    	New function.

diff --git a/ChangeLog b/ChangeLog
index d9921f0..964025d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/tile/sysdep-cancel.h (__pthread_get_pc):
+	New function.
+
 	* sysdeps/unix/sysv/linux/microblaze/sysdep-cancel.h
 	(__pthread_get_pc): New function.
 
diff --git a/sysdeps/unix/sysv/linux/tile/sysdep-cancel.h b/sysdeps/unix/sysv/linux/tile/sysdep-cancel.h
index c8994db..4c8a76e 100644
--- a/sysdeps/unix/sysv/linux/tile/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/tile/sysdep-cancel.h
@@ -37,3 +37,9 @@
 #define RTLD_SINGLE_THREAD_P                                           \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF,                         \
                                    header.multiple_threads) == 0, 1)
+
+static inline
+uintptr_t __pthread_get_pc (const struct ucontext *uc)
+{
+  return uc->uc_mcontext.pc;
+}

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=a6285f025042fd254643c862f05812e846da034c

commit a6285f025042fd254643c862f05812e846da034c
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Jan 16 17:02:17 2017 -0200

    nptl: microblaze: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patch adds the microblaze modifications required for the BZ#12683.
    It basically adds the required __pthread_get_pc function.
    
    Microblaze requires an arch specific assembly implementation because
    arch INTERNAL_SYSCALL_NCS implementation adds a nop after the brki
    instruction.  I based this implementation on generated assembly
    using GCC 6.1.
    
    Checked against a build and make check run-built-tests=no for
    microblaze-linux-gnu.
    
            * sysdeps/unix/sysv/linux/microblaze/sysdep-cancel.h
    	(__pthread_get_pc): New function.
    	* sysdeps/unix/sysv/linux/microblaze/syscall_cancel.S: New file.

diff --git a/ChangeLog b/ChangeLog
index 562bc86..d9921f0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/microblaze/sysdep-cancel.h
+	(__pthread_get_pc): New function.
+
 	* sysdeps/unix/sysv/linux/m68k/sysdep-cancel.h (__pthread_get_pc):
 	New function.
 
diff --git a/sysdeps/unix/sysv/linux/microblaze/syscall_cancel.S b/sysdeps/unix/sysv/linux/microblaze/syscall_cancel.S
new file mode 100644
index 0000000..784c91f
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/microblaze/syscall_cancel.S
@@ -0,0 +1,62 @@
+/* Cancellable syscall wrapper.  Linux/microblaze version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+
+/* long int __syscall_cancel_arch (int *cancelhandling,
+				   long int nr,
+				   long int arg1,
+				   long int arg2,
+				   long int arg3,
+				   long int arg4,
+				   long int arg5,
+				   long int arg6)  */
+
+ENTRY (__syscall_cancel_arch)
+
+	.globl __syscall_cancel_arch_start
+__syscall_cancel_arch_start:
+
+	lwi	r3,r5,0
+	andi	r3,r3,4 #and1
+	bneid	r3,1f
+	addk	r12,r6,r0
+
+	addk	r5,r7,r0
+	addk	r6,r8,r0
+	addk	r7,r9,r0
+	addk	r8,r10,r0
+	lwi	r9,r1,56
+	lwi	r10,r1,60
+	brki	r14,8;
+
+	.globl __syscall_cancel_arch_end
+__syscall_cancel_arch_end:
+
+	nop
+	lwi	r15,r1,0
+	rtsd	r15,8 
+	addik	r1,r1,28
+
+1:
+	brlid	r15, __syscall_do_cancel
+	nop
+
+END (__syscall_cancel_arch)
+libc_hidden_def (__syscall_cancel_arch)
+
diff --git a/sysdeps/unix/sysv/linux/microblaze/sysdep-cancel.h b/sysdeps/unix/sysv/linux/microblaze/sysdep-cancel.h
index 7fe030b..d7668f3 100644
--- a/sysdeps/unix/sysv/linux/microblaze/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/microblaze/sysdep-cancel.h
@@ -15,6 +15,9 @@
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef __SYSDEP_CANCEL_H
+# define __SYSDEP_CANCEL_H
+
 #include <sysdep.h>
 #include <tls.h>
 #ifndef __ASSEMBLER__
@@ -48,3 +51,11 @@ extern int __local_multiple_threads attribute_hidden;
 #define RTLD_SINGLE_THREAD_P                                        \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF,                      \
                                    header.multiple_threads) == 0, 1)
+
+static inline
+uintptr_t __pthread_get_pc (const struct ucontext *uc)
+{
+  return uc->uc_mcontext.regs.pc;
+}
+
+#endif /* __SYSDEP_CANCEL_H  */

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=7e58beaa3fc09821fc4f336b42bb0e3c8f1f7b16

commit 7e58beaa3fc09821fc4f336b42bb0e3c8f1f7b16
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Jan 16 17:02:08 2017 -0200

    nptl: m68k: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patch adds the m68k modifications required for the BZ#12683.
    It basically adds the required __pthread_get_pc function
    
    The default syscall_cancel.c should be fine for m68k and GCC 6.1
    generates the following assembly for syscall_cancel.c:
    
    | 52 "../sysdeps/unix/sysv/linux/syscall_cancel.c" 1
            trap #0
    | 0 "" 2
    .LVL2:
    .LBE3:
    .LBE2:
            .loc 1 53 0
    | 53 "../sysdeps/unix/sysv/linux/syscall_cancel.c" 1
            .global __syscall_cancel_arch_end
    __syscall_cancel_arch_end:
    
    Checked against a build and make check run-built-tests=no for
    m68k-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/m68k/sysdep-cancel.h (__pthread_get_pc):
    	New function.

diff --git a/ChangeLog b/ChangeLog
index 2201294..562bc86 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/m68k/sysdep-cancel.h (__pthread_get_pc):
+	New function.
+
 	* sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h (__pthread_get_pc):
 	New function.
 
diff --git a/sysdeps/unix/sysv/linux/m68k/sysdep-cancel.h b/sysdeps/unix/sysv/linux/m68k/sysdep-cancel.h
index 1603c5f..1d83a31 100644
--- a/sysdeps/unix/sysv/linux/m68k/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/m68k/sysdep-cancel.h
@@ -36,3 +36,9 @@
   __builtin_expect (THREAD_GETMEM (THREAD_SELF,			  \
 				   header.multiple_threads) == 0, \
 		    1)
+
+static inline
+uintptr_t __pthread_get_pc (const struct ucontext *uc)
+{
+  return uc->uc_mcontext.gregs[R_PC];
+}

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=9bd32d23c2fad4aeee4ac8676eaff5eb21903efa

commit 9bd32d23c2fad4aeee4ac8676eaff5eb21903efa
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Jan 16 17:01:58 2017 -0200

    nptl: alpha: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patch adds the alpha modifications required for the BZ#12683.
    It basically adds the required __pthread_get_pc function
    
    The default syscall_cancel.c should be fine for alpha and GCC 6.1
    generates the following assembly for syscall_cancel.c:
    
     # 52 "../sysdeps/unix/sysv/linux/syscall_cancel.c" 1
            callsys # $0 $19 <= $16 $17 $18 $20 $21 $0 $19
     # 0 "" 2
    $LVL8:
            .set    nomacro
    $LBE3:
    $LBE2:
            .loc 1 53 0
            .set    macro
     # 53 "../sysdeps/unix/sysv/linux/syscall_cancel.c" 1
            .global __syscall_cancel_arch_end
    __syscall_cancel_arch_end:
    
    Checked against a build and make check run-built-tests=no for
    alpha-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h (__pthread_get_pc):
    	New function.

diff --git a/ChangeLog b/ChangeLog
index 16f3022..2201294 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h (__pthread_get_pc):
+	New function.
+
 	* nptl/nptl-init.c (sigaddset_cancel): New macro.
 	(sigcancel_handler): Use sigaddset_cancel instead of __sigaddset.
 	* sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h (__pthread_get_pc):
diff --git a/sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h b/sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h
index 366cf31..5663128 100644
--- a/sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h
@@ -47,3 +47,9 @@ extern int __local_multiple_threads attribute_hidden;
 # define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
+
+static inline
+uintptr_t __pthread_get_pc (const struct ucontext *uc)
+{
+  return uc->uc_mcontext.sc_pc;
+}

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=2b54b596cd1cc9323ff2138f32994eab7a33fa0d

commit 2b54b596cd1cc9323ff2138f32994eab7a33fa0d
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Jan 16 17:01:44 2017 -0200

    nptl: ia64: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patch adds the s390 modifications required for the BZ#12683.
    It basically adds the required __pthread_get_pc function and a
    workaround for nptl/nptl-init.c build due IA64 uc_sigmask being an
    unsigned long rather than the larger expected userspace sigset_t.
    
    The default syscall_cancel.c should be fine for IA64 (and since
    syscall_cancel is built only for libc IA64_USE_NEW_STUB will be
    always defined).  GCC 6.1 generates the following assembly for
    syscall_cancel.c:
    
    [...]
    // 52 "../sysdeps/unix/sysv/linux/syscall_cancel.c" 1
            br.call.sptk.many b6=b7;;
    
    // 0 "" 2
    [.LVL3:]
    [.LBE2:]
            .loc 1 53 0
            ;;
    // 53 "../sysdeps/unix/sysv/linux/syscall_cancel.c" 1
            .global __syscall_cancel_arch_end
    __syscall_cancel_arch_end:
    [...]
    
    Checked against a build and make check run-built-tests=no for
    ia64-linux-gnu.
    
    	* nptl/nptl-init.c (sigaddset_cancel): New macro.
    	(sigcancel_handler): Use sigaddset_cancel instead of __sigaddset.
    	* sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h (__pthread_get_pc):
    	New function.
    	(sigaddset_cancel): New macro.

diff --git a/ChangeLog b/ChangeLog
index b529478..16f3022 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* nptl/nptl-init.c (sigaddset_cancel): New macro.
+	(sigcancel_handler): Use sigaddset_cancel instead of __sigaddset.
+	* sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h (__pthread_get_pc):
+	New function.
+	(sigaddset_cancel): New macro.
+
 	* sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h
 	(__pthread_get_pc): New function.
 	* sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h
diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c
index 5febd77..af7e8af 100644
--- a/nptl/nptl-init.c
+++ b/nptl/nptl-init.c
@@ -178,6 +178,12 @@ __nptl_set_robust (struct pthread *self)
 
 #ifdef SIGCANCEL
 
+/* Workaround for ia64 where uc_sigmask is an unsigned long rather than the
+   larger userspace sigset_t.  */
+#ifndef sigaddset_cancel
+# define sigaddset_cancel(set) __sigaddset ((set), SIGCANCEL)
+#endif
+
 /* For asynchronous cancellation we use a signal.  This is the handler.  */
 static void
 sigcancel_handler (int sig, siginfo_t *si, void *ctx)
@@ -202,7 +208,7 @@ sigcancel_handler (int sig, siginfo_t *si, void *ctx)
       || ((pd->cancelhandling & CANCELED_BITMASK) == 0))
     return;
 
-  __sigaddset (&uc->uc_sigmask, SIGCANCEL);
+  sigaddset_cancel (&uc->uc_sigmask);
 
   /* Check if asynchronous cancellation mode is set and if interrupted
      instruction pointer falls within the cancellable syscall bridge.  For
diff --git a/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h b/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h
index 96d04de..6f86072 100644
--- a/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h
@@ -33,3 +33,11 @@
 #define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
+
+static inline
+uintptr_t __pthread_get_pc (const struct ucontext *uc)
+{
+  return uc->uc_mcontext.sc_ip;
+}
+
+#define sigaddset_cancel(set) __sigaddset ((sigset_t *) (set), SIGCANCEL)

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=eb801698e07dbfeafc32d196f0870c89897f4108

commit eb801698e07dbfeafc32d196f0870c89897f4108
Author: Adhemerval Zanella <adhemerval.zanella@linaro.com>
Date:   Wed Aug 12 10:51:38 2015 -0300

    nptl: s390: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patch adds the s390 modifications required for the BZ#12683 fix.
    It basically adds the required __pthread_get_pc function.
    
    Checked with a s390-linux-gnu and s390x-linux-gnu build with
    run-tests-built=no.
    
    	* sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h
    	(__pthread_get_pc): New function.
    	* sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h
    	(__pthread_get_pc): Likewise.

diff --git a/ChangeLog b/ChangeLog
index d86e300..b529478 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h
+	(__pthread_get_pc): New function.
+	* sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h
+	(__pthread_get_pc): Likewise.
+
 	* sysdeps/unix/sysv/linux/arm/syscall_cancel.S: New file.
 	* sysdeps/unix/sysv/linux/arm/sysdep-cancel.h (__pthread_get_pc):
 	New function.
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h b/sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h
index 82763b7..961db9c 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h
@@ -38,3 +38,10 @@
 #define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
+
+static inline
+uintptr_t __pthread_get_pc (const struct ucontext *uc)
+{
+  /* We have 31bit addresses, remove bit 0.  */
+  return uc->uc_mcontext.psw.addr & 0x7FFFFFFF;
+}
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h b/sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h
index 952d2af..fd54c28 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h
@@ -26,6 +26,8 @@
 #  define __local_multiple_threads	__pthread_multiple_threads
 # elif IS_IN (libc)
 #  define __local_multiple_threads	__libc_multiple_threads
+# elif !IS_IN (librt)
+#  error Unsupported library
 # endif
 
 # if IS_IN (libpthread) || IS_IN (libc)
@@ -51,3 +53,9 @@ extern int __local_multiple_threads attribute_hidden;
 #define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
+
+static inline
+uintptr_t __pthread_get_pc (const struct ucontext *uc)
+{
+  return uc->uc_mcontext.psw.addr;
+}

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=dae029c208a90f16b10661b316c68ea735fb8f3c

commit dae029c208a90f16b10661b316c68ea735fb8f3c
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Fri May 8 17:12:31 2015 -0300

    nptl: arm: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patch adds the ARM modifications required for the BZ#12683.
    It basically adds the required __pthread_get_pc function and a arch
    specific syscall_cancel implementation.
    
    ARM requires an arch-specific syscall_cancel implemetantion because
    INTERNAL_SYSCALL_NCS may call an auxiliary symbol (__libc_do_syscall)
    for thumb which invalides the check on sigcancel_handler.
    
    The localptr.data is update since now syscalls are make through libc
    syscall_cancel bridge and this functio is the one suppose to update
    errno in case of an error (instead of the previous syscall wrappers
    in libpthread.so case).
    
    Checked on arm-linux-gnueabihf.
    
    	* sysdeps/unix/sysv/linux/arm/syscall_cancel.S: New file.
    	* sysdeps/unix/sysv/linux/arm/sysdep-cancel.h (__pthread_get_pc):
    	New function.
    	* sysdeps/unix/sysv/linux/arm/localplt.data (__errno_location):
    	Remove.

diff --git a/ChangeLog b/ChangeLog
index 532c73d..d86e300 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/arm/syscall_cancel.S: New file.
+	* sysdeps/unix/sysv/linux/arm/sysdep-cancel.h (__pthread_get_pc):
+	New function.
+
 	* sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h
 	(__pthread_get_pc): New function.
 
diff --git a/sysdeps/unix/sysv/linux/arm/localplt.data b/sysdeps/unix/sysv/linux/arm/localplt.data
index 8bc876d..19d3299 100644
--- a/sysdeps/unix/sysv/linux/arm/localplt.data
+++ b/sysdeps/unix/sysv/linux/arm/localplt.data
@@ -5,7 +5,6 @@ libc.so: memalign
 libc.so: raise
 libc.so: realloc
 libm.so: matherr
-libpthread.so: __errno_location
 libpthread.so: raise
 # The dynamic loader needs __tls_get_addr for TLS.
 ld.so: __tls_get_addr
diff --git a/sysdeps/unix/sysv/linux/arm/syscall_cancel.S b/sysdeps/unix/sysv/linux/arm/syscall_cancel.S
new file mode 100644
index 0000000..431cae2
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/arm/syscall_cancel.S
@@ -0,0 +1,72 @@
+/* Cancellable syscall wrapper.  Linux/arm version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+
+/* long int [r0] __syscall_cancel_arch (int *cancelhandling [r0],
+					long int nr   [r1],
+					long int arg1 [r2],
+					long int arg2 [r3],
+					long int arg3 [SP],
+					long int arg4 [SP+4],
+					long int arg5 [SP+8],
+					long int arg6 [SP+12])  */
+
+#ifdef __thumb2__
+	.thumb
+#endif
+	.syntax unified
+
+ENTRY (__syscall_cancel_arch)
+	.fnstart
+	mov	ip,sp
+	stmfd	sp!,{r4,r5,r6,lr}
+	.save	{r4,r5,r6,lr}
+
+	cfi_adjust_cfa_offset (20)
+	cfi_rel_offset (lr, 16)
+
+	.globl __syscall_cancel_arch_start
+__syscall_cancel_arch_start:
+
+	/* if (*cancelhandling & CANCELED_BITMASK)
+	     __syscall_do_cancel()  */
+	ldr	r0,[r0]
+	tst	r0, #4
+	bne	1f
+
+	/* Issue a 6 argument syscall, the nr [r1] being the syscall
+	   number.  */
+	mov	r7,r1
+	mov	r0,r2
+	mov	r1,r3
+	ldmfd	ip,{r2,r3,r4,r5,r6}
+	svc	0x0
+
+	.globl __syscall_cancel_arch_end
+__syscall_cancel_arch_end:
+	ldmfd	sp!,{r4,r5,r6,lr}
+	cfi_adjust_cfa_offset (-16);
+	bx	lr
+
+1:
+	mov	lr, pc
+	b	__syscall_do_cancel
+	.fnend
+END (__syscall_cancel_arch)
+libc_hidden_def (__syscall_cancel_arch)
diff --git a/sysdeps/unix/sysv/linux/arm/sysdep-cancel.h b/sysdeps/unix/sysv/linux/arm/sysdep-cancel.h
index 738e749..f216f47 100644
--- a/sysdeps/unix/sysv/linux/arm/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/arm/sysdep-cancel.h
@@ -19,6 +19,7 @@
 #include <tls.h>
 #ifndef __ASSEMBLER__
 # include <nptl/pthreadP.h>
+# include <sys/ucontext.h>
 #endif
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
@@ -50,3 +51,9 @@ extern int __local_multiple_threads attribute_hidden;
 #define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
+
+static inline
+uintptr_t __pthread_get_pc (const struct ucontext *uc)
+{
+  return uc->uc_mcontext.arm_pc;
+}

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=f9c76e76a3c51b5110c0be86804e5e447868ad73

commit f9c76e76a3c51b5110c0be86804e5e447868ad73
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Wed May 6 17:51:29 2015 -0300

    nptl: aarch64: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patch adds the aarch64 modifications required for the BZ#12683.
    It basically adds the required __pthread_get_pc function.
    
    Checked on aarch64-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h (PSEUDO): Redefine
    	to call __syscall_cancel function for cancellable syscalls.
    	(__pthread_get_ip): Add implementation.
    	* sysdeps/unix/sysv/linux/aarch64/sysdep.h (SYSCALL_CANCEL_ERROR): Add
    	definition.
    	(SYSCALL_CANCEL_ERRNO): Likewise.

diff --git a/ChangeLog b/ChangeLog
index e3152e7..532c73d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h
+	(__pthread_get_pc): New function.
+
 	* sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S: New file.
 	* sysdeps/unix/sysv/linux/powerpc/sysdep-cancel.h
 	(__pthread_get_pc): New function.
diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h b/sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h
index d39b6a2..3adfa15 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h
@@ -20,6 +20,7 @@
 #include <tls.h>
 #ifndef __ASSEMBLER__
 # include <nptl/pthreadP.h>
+# include <sys/ucontext.h>
 #endif
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
@@ -51,3 +52,9 @@ extern int __local_multiple_threads attribute_hidden;
 # define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
+
+static inline
+uintptr_t __pthread_get_pc (const struct ucontext *uc)
+{
+  return uc->uc_mcontext.pc;
+}

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=0815702a91446c8a6cc70bfc20497948bc76fdbd

commit 0815702a91446c8a6cc70bfc20497948bc76fdbd
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Fri Sep 18 18:14:19 2015 -0300

    nptl: powerpc: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patches adds the powerpc64 modification required for the BZ#12683.
    It basically adds the required __pthread_get_pc function and a arch
    specific syscall_cancel implementation.
    
    The powerpc requires an arch-specific syscall_cancel because
    INTERNAL_SYSCALL_NCS adds a mfcr just after the sc instruction to get
    the CR0.SO bit information from kernel (which signals the error
    return status).  So for cancelled syscalls with side effects,
    __pthread_get_pc will point to mcfr and thus invalidating the checks
    on sigcancel_handler.
    
    Checked on powerpc64le-linux-gnu and powerpc-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S: New file.
    	* sysdeps/unix/sysv/linux/powerpc/sysdep-cancel.h
    	(__pthread_get_pc): New function.

diff --git a/ChangeLog b/ChangeLog
index e23fa70..e3152e7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S: New file.
+	* sysdeps/unix/sysv/linux/powerpc/sysdep-cancel.h
+	(__pthread_get_pc): New function.
+
 	* sysdeps/i386/nptl/tls.h (THREAD_ATOMIC_BIT_SET): Remove macro.
 	* sysdeps/unix/sysv/linux/i386/Makefile
 	[$(subdir) = elf] (sysdep-rtld_routines): Add libc-do-syscall object.
diff --git a/sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S b/sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S
new file mode 100644
index 0000000..4e6dc58
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S
@@ -0,0 +1,63 @@
+/* Cancellable syscall wrapper.  Linux/powerpc version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+
+/* long int [r3] __syscall_cancel_arch (int *cancelhandling [r3],
+					long int nr   [r4],
+					long int arg1 [r5],
+					long int arg2 [r6],
+					long int arg3 [r7],
+					long int arg4 [r8],
+					long int arg5 [r9],
+					long int arg6 [r10])  */
+
+ENTRY (__syscall_cancel_arch)
+
+	.globl __syscall_cancel_arch_start
+	.type  __syscall_cancel_arch_start,@function
+__syscall_cancel_arch_start:
+
+	/* if (*cancelhandling & CANCELED_BITMASK)
+	     __syscall_do_cancel()  */
+	lwz     r0,0(r3)
+	rldicl. r0,r0,62,63
+	beq     1f
+	b       __syscall_do_cancel
+	nop
+1:
+	/* Issue a 6 argument syscall, the nr [r4] being the syscall
+	   number.  */
+	mr      r0,r4
+	mr      r3,r5
+	mr      r4,r6
+	mr      r5,r7
+	mr      r6,r8
+	mr      r7,r9
+	mr      r8,r10
+	sc
+
+	.globl __syscall_cancel_arch_end
+	.type  __syscall_cancel_arch_end,@function
+__syscall_cancel_arch_end:
+
+	bnslr+
+	neg	r3,r3
+	blr
+END (__syscall_cancel_arch)
+libc_hidden_def (__syscall_cancel_arch)
diff --git a/sysdeps/unix/sysv/linux/powerpc/sysdep-cancel.h b/sysdeps/unix/sysv/linux/powerpc/sysdep-cancel.h
index 85af880..645e3cf 100644
--- a/sysdeps/unix/sysv/linux/powerpc/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/powerpc/sysdep-cancel.h
@@ -36,3 +36,13 @@
 #define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
+
+static inline
+uintptr_t __pthread_get_pc (const ucontext_t *uc)
+{
+#ifdef __powerpc64__
+  return uc->uc_mcontext.gp_regs[PT_NIP];
+#else
+  return uc->uc_mcontext.uc_regs->gregs[PT_NIP];
+#endif
+}

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=1aff4ca6f4941beb7f6069fb67ff5e0d2b1e2e77

commit 1aff4ca6f4941beb7f6069fb67ff5e0d2b1e2e77
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon May 4 16:30:13 2015 -0300

    nptl: i386: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patch adds the i386 modifications required for the BZ#12683.
    It basically provide an arch-specific symbol that contains global
    markers to be used in SIGCANCEL handler, adds a arch-specific
    syscall_cancel implementation and adapt arch-specific cancellable
    syscall implementation.
    
    On i386 an arch-specific cancellation implementation is required
    because depending of the glibc configuration and underlying kernel
    the syscall may be done using a vDSO symbol (__kernel_vsyscall).
    And using the vDSO symbol the resulting PC value for an interrupted
    syscall points to value outside the expected markers in
    __syscall_cancel_arch.  It has been discussed in LKML [1] on how
    kernel could help userland to accomplish it, but afaik discussion
    was stalled.
    
    Also, since glibc supports i486, the old 'int 0x80' should be used
    in the syscall wrapper.  One option could make minimum default chip
    to pentium II (which implements sysenter) or add a runtime check
    on syscall_cancel.S to use 'int 0x80' or sysenter.
    
    Checked on i686-linux-gnu.
    
    	* sysdeps/i386/nptl/tls.h (THREAD_ATOMIC_BIT_SET): Remove macro.
    	* sysdeps/unix/sysv/linux/i386/Makefile
    	[$(subdir) = elf] (sysdep-rtld_routines): Add libc-do-syscall object.
    	* sysdeps/unix/sysv/linux/i386/fcntl.c (NO_CANCELLATION): Replace
    	by IS_IN (rtld).
    	* sysdeps/unix/sysv/linux/i386/lowlevellock.h (lll_wait_tid): Use
    	cancellable futex syscall macro.
    	* sysdeps/unix/sysv/linux/i386/syscall_cancel.S: New file.
    	* sysdeps/unix/sysv/linux/i386/sysdep-cancel.h (__pthread_get_pc):
    	New function.
    
    [1] https://lkml.org/lkml/2016/3/8/1105

diff --git a/ChangeLog b/ChangeLog
index cd3c3e9..e23fa70 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/i386/nptl/tls.h (THREAD_ATOMIC_BIT_SET): Remove macro.
+	* sysdeps/unix/sysv/linux/i386/Makefile
+	[$(subdir) = elf] (sysdep-rtld_routines): Add libc-do-syscall object.
+	* sysdeps/unix/sysv/linux/i386/fcntl.c (NO_CANCELLATION): Replace
+	by IS_IN (rtld).
+	* sysdeps/unix/sysv/linux/i386/lowlevellock.h (lll_wait_tid): Use
+	cancellable futex syscall macro.
+	* sysdeps/unix/sysv/linux/i386/syscall_cancel.S: New file.
+	* sysdeps/unix/sysv/linux/i386/sysdep-cancel.h (__pthread_get_pc):
+	New function.
+
 	* sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h (__syscall_arg_t):
 	Define type for x32.
 	(__SSC): Add platform specific macro.
diff --git a/sysdeps/i386/nptl/tls.h b/sysdeps/i386/nptl/tls.h
index 2500c82..0fa8377 100644
--- a/sysdeps/i386/nptl/tls.h
+++ b/sysdeps/i386/nptl/tls.h
@@ -383,17 +383,6 @@ tls_fill_user_desc (union user_desc_init *desc,
 	      abort (); })
 
 
-/* Atomic set bit.  */
-#define THREAD_ATOMIC_BIT_SET(descr, member, bit) \
-  (void) ({ if (sizeof ((descr)->member) == 4)				      \
-	      asm volatile (LOCK_PREFIX "orl %1, %%gs:%P0"		      \
-			    :: "i" (offsetof (struct pthread, member)),	      \
-			       "ir" (1 << (bit)));			      \
-	    else							      \
-	      /* Not necessary for other sizes in the moment.  */	      \
-	      abort (); })
-
-
 /* Call the user-provided thread function.  */
 #define CALL_THREAD_FCT(descr) \
   ({ void *__res;							      \
diff --git a/sysdeps/unix/sysv/linux/i386/Makefile b/sysdeps/unix/sysv/linux/i386/Makefile
index 9609752..c804369 100644
--- a/sysdeps/unix/sysv/linux/i386/Makefile
+++ b/sysdeps/unix/sysv/linux/i386/Makefile
@@ -24,6 +24,7 @@ CFLAGS-semtimedop.os += $(uses-6-syscall-arguments)
 endif
 
 ifeq ($(subdir),elf)
+sysdep-rtld_routines += libc-do-syscall
 sysdep-others += lddlibc4
 install-bin += lddlibc4
 endif
diff --git a/sysdeps/unix/sysv/linux/i386/lowlevellock.h b/sysdeps/unix/sysv/linux/i386/lowlevellock.h
index 197bb1f..e54d1ea 100644
--- a/sysdeps/unix/sysv/linux/i386/lowlevellock.h
+++ b/sysdeps/unix/sysv/linux/i386/lowlevellock.h
@@ -223,7 +223,7 @@ extern int __lll_timedlock_elision (int *futex, short *adapt_count,
   do {					\
     __typeof (tid) __tid;		\
     while ((__tid = (tid)) != 0)	\
-      lll_futex_wait (&(tid), __tid, LLL_SHARED);\
+      lll_futex_wait_cancel (&(tid), __tid, LLL_SHARED);\
   } while (0)
 
 extern int __lll_timedwait_tid (int *tid, const struct timespec *abstime)
diff --git a/sysdeps/unix/sysv/linux/i386/syscall_cancel.S b/sysdeps/unix/sysv/linux/i386/syscall_cancel.S
new file mode 100644
index 0000000..64ce1f7
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/i386/syscall_cancel.S
@@ -0,0 +1,103 @@
+/* Cancellable syscall wrapper.  Linux/i686 version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+
+/* long int [eax] __syscall_cancel_arch (int *cancelhandling [SP],
+					 long int nr   [SP+4],
+					 long int arg1 [SP+8],
+					 long int arg2 [SP+12],
+					 long int arg3 [SP+16],
+					 long int arg4 [SP+20],
+					 long int arg5 [SP+24],
+					 long int arg6 [SP+28])  */
+
+ENTRY (__syscall_cancel_arch)
+	pushl %ebp
+	cfi_def_cfa_offset (8)
+	cfi_offset (ebp, -8)
+	pushl %edi
+	cfi_def_cfa_offset (12)
+	cfi_offset (edi, -12)
+	pushl %esi
+	cfi_def_cfa_offset (16)
+	cfi_offset (esi, -16)
+	pushl %ebx
+	cfi_def_cfa_offset (20)
+	cfi_offset (ebx, -20)
+
+	.global __syscall_cancel_arch_start
+__syscall_cancel_arch_start:
+
+	/* if (*cancelhandling & CANCELED_BITMASK)
+	     __syscall_do_cancel()  */
+	testb	$4, (%eax)
+	jne     1f
+
+	/* Issue a 6 argument syscall, the nr [%eax] being the syscall
+	   number.  */
+	movl    24(%esp), %eax
+	movl    28(%esp), %ebx
+	movl    32(%esp), %ecx
+	movl    36(%esp), %edx
+	movl    40(%esp), %esi
+	movl    44(%esp), %edi
+	movl    48(%esp), %ebp
+
+        /* It can not use the vDSO __kernel_vsyscall because the cancelable
+	   checks in libc-cancelation.c requires to know if the cancellation
+	   IP value that was trigger between the two
+	   __syscall_cancel_arch_{start,end} marks.  */
+	int	$128
+
+	.global __syscall_cancel_arch_end
+__syscall_cancel_arch_end:
+
+	popl %ebx
+	cfi_restore (ebx)
+	cfi_def_cfa_offset (16)
+	popl %esi
+	cfi_restore (esi)
+	cfi_def_cfa_offset (12)
+	popl %edi
+	cfi_restore (edi)
+	cfi_def_cfa_offset (8)
+	popl %ebp
+	cfi_restore (ebp)
+	cfi_def_cfa_offset (4)
+        ret
+
+1:
+	/* Although the __syscall_do_cancel do not return, we need to stack
+	   being set correctly so exceptions work correctly.  */
+	popl %ebx
+	cfi_restore (ebx)
+	cfi_def_cfa_offset (16)
+	popl %esi
+	cfi_restore (esi)
+	cfi_def_cfa_offset (12)
+	popl %edi
+	cfi_restore (edi)
+	cfi_def_cfa_offset (8)
+	popl %ebp
+	cfi_restore (ebp)
+	cfi_def_cfa_offset (4)
+	jmp __syscall_do_cancel
+
+END (__syscall_cancel_arch)
+libc_hidden_def (__syscall_cancel_arch)
diff --git a/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h b/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h
index 34e2b6f..0acd087 100644
--- a/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h
@@ -38,3 +38,9 @@
 #define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
+
+static inline
+uintptr_t __pthread_get_pc (const ucontext_t *uc)
+{
+  return (long int)uc->uc_mcontext.gregs[REG_EIP];
+}

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=cf40fe28f863fc27a6a7962535e2ccea58e99b86

commit cf40fe28f863fc27a6a7962535e2ccea58e99b86
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Sat May 9 14:20:26 2015 -0300

    nptl: x32: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patches adds the x32 modification required for the BZ#12683.
    It basically adjust the syscall size used to pass the arguments to
    the syscall cancel wrappers.
    
    Checked on x32.
    
    	* sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h (__syscall_arg_t):
    	Define type for x32.
    	(__SSC): Add platform specific macro.

diff --git a/ChangeLog b/ChangeLog
index 73ef953..cd3c3e9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h (__syscall_arg_t):
+	Define type for x32.
+	(__SSC): Add platform specific macro.
+
 	* sysdeps/unix/sysv/linux/x86_64/cancellation.S: Remove file.
 	* sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S: Remove file.
 	* sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S: Remove file.
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h
index f90fcfa..d1c0a0c 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h
@@ -18,6 +18,27 @@
 #ifndef _LINUX_X32_SYSDEP_H
 #define _LINUX_X32_SYSDEP_H 1
 
+#ifndef __ASSEMBLER__
+#include <libc-internal.h>
+
+typedef long long int __syscall_arg_t;
+
+/* Syscall arguments for x32 follows x86_64 size, however pointers are 32
+   bits in size.  This suppress the GCC warning "cast from pointer to 
+   integer of different size" when calling __syscall_cancel with
+   pointer as arguments.  */
+# define __SSC(__x)						\
+  ({								\
+    __syscall_arg_t __ret;					\
+    DIAG_PUSH_NEEDS_COMMENT;					\
+    DIAG_IGNORE_NEEDS_COMMENT (4.7, "-Wpointer-to-int-cast");	\
+    __ret = (sizeof (1 ? (__x) : 0ULL) < 8 ?			\
+      (unsigned long int) (__x) : (long long int) (__x));	\
+    DIAG_POP_NEEDS_COMMENT;					\
+    __ret;							\
+  })
+#endif
+
 /* There is some commonality.  */
 #include <sysdeps/unix/sysv/linux/x86_64/sysdep.h>
 #include <sysdeps/x86_64/x32/sysdep.h>

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=038f81873d773a49f44beb270a6e1b2fa2b66b36

commit 038f81873d773a49f44beb270a6e1b2fa2b66b36
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Sep 29 09:48:34 2014 -0300

    nptl: x86_64: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patches adds the x86_64 modification required for the BZ#12683.
    It basically provide the required __pthread_get_ip symbol and remove
    the arch-specific libc-cancellation implementations.
    
    Checked on x86_64-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/x86_64/cancellation.S: Remove file.
    	* sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S: Remove file.
    	* sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S: Remove file.
    	* sysdeps/unix/sysv/linux/x86_64/lowlevellock.h (lll_wait_tid):
    	Use cancellable futex wait call.
    	* sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h (__pthread_get_ip):
    	New function.
    	* sysdeps/x86_64/nptl/tcb-offsets.sym (TCB_CANCELING_BITMASK):
    	Remove.
    	* sysdeps/x86_64/nptl/tls.h (THREAD_ATOMIC_BIT_SET): Remove
    	macro.

diff --git a/ChangeLog b/ChangeLog
index 073a2f2..73ef953 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/x86_64/cancellation.S: Remove file.
+	* sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S: Remove file.
+	* sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S: Remove file.
+	* sysdeps/unix/sysv/linux/x86_64/lowlevellock.h (lll_wait_tid):
+	Use cancellable futex wait call.
+	* sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h (__pthread_get_ip):
+	New function.
+	* sysdeps/x86_64/nptl/tcb-offsets.sym (TCB_CANCELING_BITMASK):
+	Remove.
+	* sysdeps/x86_64/nptl/tls.h (THREAD_ATOMIC_BIT_SET): Remove
+	macro.
+
 	* nptl/Makefile [routines]: Add syscall_cancel object.
 	[libpthread-routines]: Remove cancellation object.
 	(CFLAGS-cancellation.c): Remove rule.
diff --git a/sysdeps/unix/sysv/linux/x86_64/cancellation.S b/sysdeps/unix/sysv/linux/x86_64/cancellation.S
deleted file mode 100644
index ed804df..0000000
--- a/sysdeps/unix/sysv/linux/x86_64/cancellation.S
+++ /dev/null
@@ -1,115 +0,0 @@
-/* Copyright (C) 2009-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2009.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <sysdep.h>
-#include <tcb-offsets.h>
-#include <kernel-features.h>
-#include "lowlevellock.h"
-
-#define PTHREAD_UNWIND JUMPTARGET(__pthread_unwind)
-#if IS_IN (libpthread)
-# if defined SHARED && !defined NO_HIDDEN
-#  undef PTHREAD_UNWIND
-#  define PTHREAD_UNWIND __GI___pthread_unwind
-# endif
-#else
-# ifndef SHARED
-	.weak __pthread_unwind
-# endif
-#endif
-
-
-#ifdef __ASSUME_PRIVATE_FUTEX
-# define LOAD_PRIVATE_FUTEX_WAIT(reg) \
-	movl	$(FUTEX_WAIT | FUTEX_PRIVATE_FLAG), reg
-#else
-# if FUTEX_WAIT == 0
-#  define LOAD_PRIVATE_FUTEX_WAIT(reg) \
-	movl	%fs:PRIVATE_FUTEX, reg
-# else
-#  define LOAD_PRIVATE_FUTEX_WAIT(reg) \
-	movl	%fs:PRIVATE_FUTEX, reg ; \
-	orl	$FUTEX_WAIT, reg
-# endif
-#endif
-
-/* It is crucial that the functions in this file don't modify registers
-   other than %rax and %r11.  The syscall wrapper code depends on this
-   because it doesn't explicitly save the other registers which hold
-   relevant values.  */
-	.text
-
-	.hidden __pthread_enable_asynccancel
-ENTRY(__pthread_enable_asynccancel)
-	movl	%fs:CANCELHANDLING, %eax
-2:	movl	%eax, %r11d
-	orl	$TCB_CANCELTYPE_BITMASK, %r11d
-	cmpl	%eax, %r11d
-	je	1f
-
-	lock
-	cmpxchgl %r11d, %fs:CANCELHANDLING
-	jnz	2b
-
-	andl	$(TCB_CANCELSTATE_BITMASK|TCB_CANCELTYPE_BITMASK|TCB_CANCELED_BITMASK|TCB_EXITING_BITMASK|TCB_CANCEL_RESTMASK|TCB_TERMINATED_BITMASK), %r11d
-	cmpl	$(TCB_CANCELTYPE_BITMASK|TCB_CANCELED_BITMASK), %r11d
-	je	3f
-
-1:	ret
-
-3:	subq	$8, %rsp
-	cfi_adjust_cfa_offset(8)
-	LP_OP(mov) $TCB_PTHREAD_CANCELED, %fs:RESULT
-	lock
-	orl	$TCB_EXITING_BITMASK, %fs:CANCELHANDLING
-	mov	%fs:CLEANUP_JMP_BUF, %RDI_LP
-	call	PTHREAD_UNWIND
-	hlt
-END(__pthread_enable_asynccancel)
-
-
-	.hidden __pthread_disable_asynccancel
-ENTRY(__pthread_disable_asynccancel)
-	testl	$TCB_CANCELTYPE_BITMASK, %edi
-	jnz	1f
-
-	movl	%fs:CANCELHANDLING, %eax
-2:	movl	%eax, %r11d
-	andl	$~TCB_CANCELTYPE_BITMASK, %r11d
-	lock
-	cmpxchgl %r11d, %fs:CANCELHANDLING
-	jnz	2b
-
-	movl	%r11d, %eax
-3:	andl	$(TCB_CANCELING_BITMASK|TCB_CANCELED_BITMASK), %eax
-	cmpl	$TCB_CANCELING_BITMASK, %eax
-	je	4f
-1:	ret
-
-	/* Performance doesn't matter in this loop.  We will
-	   delay until the thread is canceled.  And we will unlikely
-	   enter the loop twice.  */
-4:	mov	%fs:0, %RDI_LP
-	movl	$__NR_futex, %eax
-	xorq	%r10, %r10
-	addq	$CANCELHANDLING, %rdi
-	LOAD_PRIVATE_FUTEX_WAIT (%esi)
-	syscall
-	movl	%fs:CANCELHANDLING, %eax
-	jmp	3b
-END(__pthread_disable_asynccancel)
diff --git a/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S b/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S
deleted file mode 100644
index dc9d822..0000000
--- a/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Copyright (C) 2009-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2009.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#define __pthread_enable_asynccancel __libc_enable_asynccancel
-#define __pthread_disable_asynccancel __libc_disable_asynccancel
-#include "cancellation.S"
diff --git a/sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S b/sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S
deleted file mode 100644
index 8422939..0000000
--- a/sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Copyright (C) 2009-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2009.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#define __pthread_enable_asynccancel __librt_enable_asynccancel
-#define __pthread_disable_asynccancel __librt_disable_asynccancel
-#include "cancellation.S"
diff --git a/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h b/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
index cbf6597..bb6d9ee 100644
--- a/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
+++ b/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
@@ -232,10 +232,10 @@ extern int __lll_timedlock_elision (int *futex, short *adapt_count,
    afterwards.  The kernel up to version 3.16.3 does not use the private futex
    operations for futex wake-up when the clone terminates.  */
 #define lll_wait_tid(tid) \
-  do {					\
-    __typeof (tid) __tid;		\
-    while ((__tid = (tid)) != 0)	\
-      lll_futex_wait (&(tid), __tid, LLL_SHARED);\
+  do {									      \
+    __typeof (tid) __tid;						      \
+    while ((__tid = (tid)) != 0)					      \
+      lll_futex_wait_cancel (&(tid), __tid, LLL_SHARED);		      \
   } while (0)
 
 extern int __lll_timedwait_tid (int *, const struct timespec *)
diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h b/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h
index 0979bde..62b2e99 100644
--- a/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h
@@ -53,3 +53,9 @@ extern int __local_multiple_threads attribute_hidden;
 #define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
+
+static inline
+uintptr_t __pthread_get_pc (const ucontext_t *uc)
+{
+  return (long int)uc->uc_mcontext.gregs[REG_RIP];
+}
diff --git a/sysdeps/x86_64/nptl/tcb-offsets.sym b/sysdeps/x86_64/nptl/tcb-offsets.sym
index 8a25c48..b225e5b 100644
--- a/sysdeps/x86_64/nptl/tcb-offsets.sym
+++ b/sysdeps/x86_64/nptl/tcb-offsets.sym
@@ -19,7 +19,6 @@ PRIVATE_FUTEX		offsetof (tcbhead_t, private_futex)
 -- Not strictly offsets, but these values are also used in the TCB.
 TCB_CANCELSTATE_BITMASK	 CANCELSTATE_BITMASK
 TCB_CANCELTYPE_BITMASK	 CANCELTYPE_BITMASK
-TCB_CANCELING_BITMASK	 CANCELING_BITMASK
 TCB_CANCELED_BITMASK	 CANCELED_BITMASK
 TCB_EXITING_BITMASK	 EXITING_BITMASK
 TCB_CANCEL_RESTMASK	 CANCEL_RESTMASK
diff --git a/sysdeps/x86_64/nptl/tls.h b/sysdeps/x86_64/nptl/tls.h
index f2afe85..45f5f4a 100644
--- a/sysdeps/x86_64/nptl/tls.h
+++ b/sysdeps/x86_64/nptl/tls.h
@@ -315,17 +315,6 @@ typedef struct
 	      abort (); })
 
 
-/* Atomic set bit.  */
-# define THREAD_ATOMIC_BIT_SET(descr, member, bit) \
-  (void) ({ if (sizeof ((descr)->member) == 4)				      \
-	      asm volatile (LOCK_PREFIX "orl %1, %%fs:%P0"		      \
-			    :: "i" (offsetof (struct pthread, member)),	      \
-			       "ir" (1 << (bit)));			      \
-	    else							      \
-	      /* Not necessary for other sizes in the moment.  */	      \
-	      abort (); })
-
-
 # define CALL_THREAD_FCT(descr) \
   ({ void *__res;							      \
      asm volatile ("movq %%fs:%P2, %%rdi\n\t"				      \

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=d43c93d2300b825fe14ee2e354a8bcfc46cc4f55

commit d43c93d2300b825fe14ee2e354a8bcfc46cc4f55
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Fri Sep 18 18:26:35 2015 -0300

    nptl: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patches fixes some race conditions in NPTL cancellation code by
    redefining how cancellable syscalls are defined and handled.  Current
    approach is to enable asynchronous cancellation prior to making the syscall
    and restore the previous cancellation type once the syscall returns.
    
    As decribed in BZ#12683, this approach shows 2 important problems:
    
      1. Cancellation can act after the syscall has returned from kernel, but
         before userspace saves the return value.  It might result in a resource
         leak if the syscall allocated a resource or a side effect (partial
         read/write), and there is no way to program handle it with cancellation
         handlers.
    
      2. If a signal is handled while the thread is blocked at a cancellable
         syscall, the entire signal handler runs with asynchronous cancellation
         enabled.  This can lead to issues if the signal handler call functions
         which are async-signal-safe but not async-cancel-safe.
    
    For cancellation to work correctly, there are 5 points at which the
    cancellation signal could arrive:
    
      1. Before the final testcancel before the syscall is made.
      2. Between the testcancel and the syscall.
      3. While the syscall is blocked and no side effects have yet taken place.
      4. While the syscall is blocked but with some side effects already having
         taken place (e.g. a partial read or write).
      5. After the syscall has returned.
    
    And GLIBC wants to act on cancellation in cases 1, 2, and 3 but not in case
    4 or 5.  The proposed solution follows:
    
      * Handling case 1 is trivial: do a conditional branch based on whether the
        thread has received a cancellation request;
      * Case 2 can be caught by the signal handler determining that the saved
        program counter (from the ucontext_t) is in some address range beginning
        just before the "testcancel" and ending with the syscall instruction.
      * In this case, except for certain syscalls that ALWAYS fail with EINTR
        even for non-interrupting signals, the kernel will reset the program
        counter to point at the syscall instruction during signal handling, so
        that the syscall is restarted when the signal handler returns. So, from
        the signal handler's standpoint, this looks the same as case 2, and thus
        it's taken care of.
      * In this case, the kernel cannot restart the syscall; when it's
        interrupted by a signal, the kernel must cause the syscall to return
        with whatever partial result it obtained (e.g. partial read or write).
      * In this case, the saved program counter points just after the syscall
        instruction, so the signal handler won't act on cancellation.
        This one is equal to 4. since the program counter is past the syscall
        instruction already.
    
    Another case that needs handling is syscalls that fail with EINTR even
    when the signal handler is non-interrupting. In this case, the syscall
    wrapper code can just check the cancellation flag when the errno result
    is EINTR, and act on cancellation if it's set.
    
    The proposed GLIBC adjustments are:
    
      1. Remove the enable_asynccancel/disable_asynccancel function usage in
         syscall definition and instead make them call a common symbol that will
         check if cancellation is enabled (__syscall_cancel at
         nptl/libc-cancellation.c), call the arch-specific cancellable
         entry-point (__syscall_cancel_arch) and cancel the thread when required.
      2. Provide a arch-specific symbol that contains global markers. These
         markers will be used in SIGCANCEL handler to check if the interruption
         has been called in a valid syscall and if the syscalls has been
         completed or not.
         A default version is provided (sysdeps/unix/sysv/linux/syscall_cancel.c),
         however the markers may not be set on correct expected places depeding
         of how INTERNAL_SYSCALL_NCS is implemented by the underlying architecture.
         In this case arch-specific implementation should be provided.
      3. Rewrite SIGCANCEL asynchronous handler to check for both cancelling type
         and if current IP from signal handler falls between the global markes
         and act accordingly (sigcancel_handler at nptl/nptl-init.c).
      4. Adjust nptl/pthread_cancel.c to send an signal instead of acting
         directly. This avoid synchronization issues when updating the
         cancellation status and also focus the logic on signal handler and
         cancellation syscall code.
      5. Adjust pthread code to replace CANCEL_ASYNC/CANCEL_RESET calls to
         appropriated cancelable futex syscalls.
      6. Adjust libc code to replace LIBC_CANCEL_ASYNC/LIBC_CANCEL_RESET to
         appropriated cancelable syscalls.
      7. Adjust 'lowlevellock-futex.h' arch-specific implementations to provide
         cancelable futex calls (used in libpthread code).
    
    This patch adds the proposed changes to NPTL.  The code leaves all the ports
    broken without further patches in the list.
    
    	* nptl/Makefile [routines]: Add syscall_cancel object.
    	[libpthread-routines]: Remove cancellation object.
    	(CFLAGS-cancellation.c): Remove rule.
    	(CFLAGS-syscall_cancel.c): New rule.
    	(tests): Add tst-cancel28.
    	* nptl/Versions [GLIBC_PRIVATE] (libc): Add __syscall_cancel,
    	__syscall_cancel_arch_start, and __syscall_cancel_arch_end.
    	* nptl/cancellation.c: Remove file.
    	* nptl/descr.h (CANCELING_BIT): Remove define.
    	(CANCELING_BITMASK): Likewise.
    	(CANCEL_RESTMASK): Adjust value with CANCELED_BIT remove.
    	* nptl/libc-cancellation.c (__syscall_cancel): Add non-cancellable
    	implementation for loader and cancellable one for libc.
    	(__syscall_do_cancel): New function: cancel call for syscall wrappers.
    	* nptl/lll_timedlock_wait.c (__lll_timedlock_wait): Use cancellable
    	futex operation.
    	(__lll_timedwait_tid): Likewise.
    	* nptl/nptl-init.c (sigcancel_handler): Rewrite function to avoid race
    	conditions.
    	(__pthread_initialize_minimal_internal): Add SA_RESTART to SIGCANCEL
    	handler.
    	* nptl/pt-system.c [LIBC_CANCEL_HANDLED]: Remove definition.
    	* io/creat.c (LIBC_CANCEL_HANDLED): Likewise.
    	* io/ppoll.c [ppoll] (LIBC_CANCEL_HANDLED): Likewise.
    	* misc/pselect [__pselect] (LIBC_CANCEL_HANDLED): Likewise.
    	* sysdeps/posix/pause.c (LIBC_CANCEL_HANDLED): Likewise.
    	* sysdeps/unix/sysv/linux/generic/creat.c (LIBC_CANCEL_HANDLED):
    	Likewise.
    	* nptl/pthreadP.h (__do_cancel): Rewrite to both disable asynchronous
    	cancellation and setting the thread as cancelled.
    	(CANCEL_ASYNC): Remove definition.
    	(CANCEL_RESET): Likewise.
    	(LIBC_CANCEL_ASYNC): Likewise.
    	(LIBC_CANCEL_RESET): Likewise.
    	(LIBC_CANCEL_HANDLED): Likewise.
    	(__syscall_cancel_arch): Add prototype.
    	(__pthread_enable_asynccancel): Remove prototype.
    	(__pthread_disable_asynccancel): Likewise.
    	(__libc_enable_asynccancel): Likewise.
    	(__libc_disable_asynccancel): Likewise.
    	(__librt_enable_asynccancel): Likewise.
    	(__librt_disable_asynccancel): Likewise.
    	(__syscall_cancel_arch): Add prototype.
    	(__syscall_do_cancel): Likewise.
    	* nptl/pthread_cancel.c (pthread_cancel): Rewrite to just set
    	CANCELLED_BIT and call __pthread_kill.
    	* nptl/pthread_create.c (start_thread): Likewise.
    	* nptl/pthread_timedjoin.c (pthread_timedjoin_np): Likewise.
    	* nptl/sem_timedwait.c (sem_timedwait):  Likewise.
    	* nptl/sem_wait.c (__new_sem_wait): Likewise.
    	* nptl/sem_waitcommon.c (futex_abstimed_wait): Likewise.
    	* sysdeps/nptl/aio_misc.h (AIO_MISC_WAIT): Likewise.
    	* sysdeps/nptl/gai_misc.h (GAI_MISC_WAIT): Likewise.
    	* sysdeps/posix/sigpause.c (do_sigpause): Likewise.
    	* sysdeps/posix/sigwait.c (__sigwait): Likewise.
    	* sysdeps/posix/waitid.c (__waitid): Likewise.
    	* sysdeps/nptl/lowlevellock.h (lll_wait_tid): Likewise.
    	* sysdeps/posix/open64.c (__libc_open64): Likewise.
    	* sysdeps/unix/sysv/linux/sigwait.c (__sigwait): Likewise.
    	* nptl/pthread_exit.c (pthread_exit): Rewrite to set EXITING_BIT
    	before call __pthread_unwind.
    	* nptl/pthread_join.c (pthread_join): Remove CANCEL_ASYNC/CANCEL_RESET
    	usage.
    	* rt/Makefile [CFLAGS-librt-cancellation.c]: Remove rule.
    	* sysdeps/generic/sysdep-cancel.h (LIBC_CANCEL_ASYNC): Remove define.
    	(LIBC_CANCEL_RESET): Likewise.
    	(LIBC_CANCEL_HANDLED): Likewise.
    	* sysdeps/unix/sysv/linux/clock_nanosleep.c (__clock_nanosleep):
    	Likewise.
    	* sysdeps/unix/sysv/linux/fcntl.c (__libc_fcntl): Likewise.
    	* sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c (__libc_fcntl):
    	Likewise.
    	* sysdeps/nptl/Makefile [$(subdir) = rt] (librt-sysdep_routines):
    	Remove librt-cancellation object.
    	[$(subdir) = rt] (librt-cancellation.c): Remove rule.
    	* sysdeps/nptl/librt-cancellation.c: Remove file.
    	* sysdeps/unix/sysv/linux/futex-internal.h (lll_futex_wait_cancel):
    	Use lll_futex_timed_wait_cancel.
    	(futex_reltimed_wait_cancelable): Likewise.
    	(futex_abstimed_wait_cancelable)): Use
    	lll_futex_timed_wait_bitset_cancel.
    	* sysdeps/unix/sysv/linux/lowlevellock-futex.h
    	(lll_futex_wait_cancel): New macro.
    	(lll_futex_timed_wait_cancel): Likewise.
    	(lll_futex_timed_wait_bitset_cancel): Likewise.
    	* sysdeps/unix/sysdep.h (SYSCALL_CANCEL): New macro: cancelable
    	syscall calls.
    	(INTERNAL_SYSCALL_NCS_CALL): New macro.
    	(__syscall_cancel): New prototype.
    	* sysdeps/unix/sysv/linux/socketcall.h (SOCKETCALL): Use __SSC macros.
    	(SOCKETCALL_CANCEL): Use SYSCALL_CANCEL macros.
    	* sysdeps/generic/sysdep-cancel.h (LIBC_CANCEL_ASYNC): Remove define.
    	(LIBC_CANCEL_RESET): Likewise.
    	(LIBC_CANCEL_HANDLED): Likewise.
    	* sysdeps/unix/sysv/linux/pthread_kill.c (__pthread_kill): Allow
    	SIGCANCEL to be sent.
    	* nptl/tst-cancel28.c: New file.
    	* sysdeps/unix/sysv/linux/syscall_cancel.c: Likewise.
    	* support/temp_file.c (create_temp_fifo): New function.
    	* support/temp_file.h (create_temp_fifo): Likewise.

diff --git a/ChangeLog b/ChangeLog
index c6ebf0b..073a2f2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,104 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* nptl/Makefile [routines]: Add syscall_cancel object.
+	[libpthread-routines]: Remove cancellation object.
+	(CFLAGS-cancellation.c): Remove rule.
+	(CFLAGS-syscall_cancel.c): New rule.
+	(tests): Add tst-cancel28.
+	* nptl/Versions [GLIBC_PRIVATE] (libc): Add __syscall_cancel,
+	__syscall_cancel_arch_start, and __syscall_cancel_arch_end.
+	* nptl/cancellation.c: Remove file.
+	* nptl/descr.h (CANCELING_BIT): Remove define.
+	(CANCELING_BITMASK): Likewise.
+	(CANCEL_RESTMASK): Adjust value with CANCELED_BIT remove.
+	* nptl/libc-cancellation.c (__syscall_cancel): Add non-cancellable
+	implementation for loader and cancellable one for libc.
+	(__syscall_do_cancel): New function: cancel call for syscall wrappers.
+	* nptl/lll_timedlock_wait.c (__lll_timedlock_wait): Use cancellable
+	futex operation.
+	(__lll_timedwait_tid): Likewise.
+	* nptl/nptl-init.c (sigcancel_handler): Rewrite function to avoid race
+	conditions.
+	(__pthread_initialize_minimal_internal): Add SA_RESTART to SIGCANCEL
+	handler.
+	* nptl/pt-system.c [LIBC_CANCEL_HANDLED]: Remove definition.
+	* io/creat.c (LIBC_CANCEL_HANDLED): Likewise.
+	* io/ppoll.c [ppoll] (LIBC_CANCEL_HANDLED): Likewise.
+	* misc/pselect [__pselect] (LIBC_CANCEL_HANDLED): Likewise.
+	* sysdeps/posix/pause.c (LIBC_CANCEL_HANDLED): Likewise.
+	* sysdeps/unix/sysv/linux/generic/creat.c (LIBC_CANCEL_HANDLED):
+	Likewise.
+	* nptl/pthreadP.h (__do_cancel): Rewrite to both disable asynchronous
+	cancellation and setting the thread as cancelled.
+	(CANCEL_ASYNC): Remove definition.
+	(CANCEL_RESET): Likewise.
+	(LIBC_CANCEL_ASYNC): Likewise.
+	(LIBC_CANCEL_RESET): Likewise.
+	(LIBC_CANCEL_HANDLED): Likewise.
+	(__syscall_cancel_arch): Add prototype.
+	(__pthread_enable_asynccancel): Remove prototype.
+	(__pthread_disable_asynccancel): Likewise.
+	(__libc_enable_asynccancel): Likewise.
+	(__libc_disable_asynccancel): Likewise.
+	(__librt_enable_asynccancel): Likewise.
+	(__librt_disable_asynccancel): Likewise.
+	(__syscall_cancel_arch): Add prototype.
+	(__syscall_do_cancel): Likewise.
+	* nptl/pthread_cancel.c (pthread_cancel): Rewrite to just set
+	CANCELLED_BIT and call __pthread_kill.
+	* nptl/pthread_create.c (start_thread): Likewise.
+	* nptl/pthread_timedjoin.c (pthread_timedjoin_np): Likewise.
+	* nptl/sem_timedwait.c (sem_timedwait):  Likewise.
+	* nptl/sem_wait.c (__new_sem_wait): Likewise.
+	* nptl/sem_waitcommon.c (futex_abstimed_wait): Likewise.
+	* sysdeps/nptl/aio_misc.h (AIO_MISC_WAIT): Likewise.
+	* sysdeps/nptl/gai_misc.h (GAI_MISC_WAIT): Likewise.
+	* sysdeps/posix/sigpause.c (do_sigpause): Likewise.
+	* sysdeps/posix/sigwait.c (__sigwait): Likewise.
+	* sysdeps/posix/waitid.c (__waitid): Likewise.
+	* sysdeps/nptl/lowlevellock.h (lll_wait_tid): Likewise.
+	* sysdeps/posix/open64.c (__libc_open64): Likewise.
+	* sysdeps/unix/sysv/linux/sigwait.c (__sigwait): Likewise.
+	* nptl/pthread_exit.c (pthread_exit): Rewrite to set EXITING_BIT
+	before call __pthread_unwind.
+	* nptl/pthread_join.c (pthread_join): Remove CANCEL_ASYNC/CANCEL_RESET
+	usage.
+	* rt/Makefile [CFLAGS-librt-cancellation.c]: Remove rule.
+	* sysdeps/generic/sysdep-cancel.h (LIBC_CANCEL_ASYNC): Remove define.
+	(LIBC_CANCEL_RESET): Likewise.
+	(LIBC_CANCEL_HANDLED): Likewise.
+	* sysdeps/unix/sysv/linux/clock_nanosleep.c (__clock_nanosleep):
+	Likewise.
+	* sysdeps/unix/sysv/linux/fcntl.c (__libc_fcntl): Likewise.
+	* sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c (__libc_fcntl):
+	Likewise.
+	* sysdeps/nptl/Makefile [$(subdir) = rt] (librt-sysdep_routines):
+	Remove librt-cancellation object.
+	[$(subdir) = rt] (librt-cancellation.c): Remove rule.
+	* sysdeps/nptl/librt-cancellation.c: Remove file.
+	* sysdeps/unix/sysv/linux/futex-internal.h (lll_futex_wait_cancel):
+	Use lll_futex_timed_wait_cancel.
+	(futex_reltimed_wait_cancelable): Likewise.
+	(futex_abstimed_wait_cancelable)): Use
+	lll_futex_timed_wait_bitset_cancel.
+	* sysdeps/unix/sysv/linux/lowlevellock-futex.h
+	(lll_futex_wait_cancel): New macro.
+	(lll_futex_timed_wait_cancel): Likewise.
+	(lll_futex_timed_wait_bitset_cancel): Likewise.
+	* sysdeps/unix/sysdep.h (SYSCALL_CANCEL): New macro: cancelable
+	syscall calls.
+	(INTERNAL_SYSCALL_NCS_CALL): New macro.
+	(__syscall_cancel): New prototype.
+	* sysdeps/unix/sysv/linux/socketcall.h (SOCKETCALL): Use __SSC macros.
+	(SOCKETCALL_CANCEL): Use SYSCALL_CANCEL macros.
+	* sysdeps/generic/sysdep-cancel.h (LIBC_CANCEL_ASYNC): Remove define.
+	(LIBC_CANCEL_RESET): Likewise.
+	(LIBC_CANCEL_HANDLED): Likewise.
+	* sysdeps/unix/sysv/linux/pthread_kill.c (__pthread_kill): Allow
+	SIGCANCEL to be sent.
+	* nptl/tst-cancel28.c: New file.
+	* sysdeps/unix/sysv/linux/syscall_cancel.c: Likewise.
+
 	* debug/tst-backtrace5.c (handle_signal): Check for syscall
 	instead of read.
 	(fn): Issue the read syscall instead of call the cancellable
diff --git a/io/creat.c b/io/creat.c
index 4e095d6..031cc78 100644
--- a/io/creat.c
+++ b/io/creat.c
@@ -27,6 +27,3 @@ creat (const char *file, mode_t mode)
 {
   return __open (file, O_WRONLY|O_CREAT|O_TRUNC, mode);
 }
-
-/* __open handles cancellation.  */
-LIBC_CANCEL_HANDLED ();
diff --git a/io/ppoll.c b/io/ppoll.c
index e2919a7..f8cb3a4 100644
--- a/io/ppoll.c
+++ b/io/ppoll.c
@@ -70,7 +70,5 @@ ppoll (struct pollfd *fds, nfds_t nfds, const struct timespec *timeout,
 }
 
 #ifndef ppoll
-/* __poll handles cancellation.  */
-LIBC_CANCEL_HANDLED ();
 libc_hidden_def (ppoll);
 #endif
diff --git a/manual/llio.texi b/manual/llio.texi
index 9643bcb..0f47250 100644
--- a/manual/llio.texi
+++ b/manual/llio.texi
@@ -2185,13 +2185,13 @@ aiocb64}, since the LFS transparently replaces the old interface.
 @c     sigemptyset ok
 @c     sigaddset ok
 @c     setjmp ok
-@c     CANCEL_ASYNC -> pthread_enable_asynccancel ok
+@c     __pthread_setcanceltype ok
 @c      do_cancel ok
 @c       pthread_unwind ok
 @c        Unwind_ForcedUnwind or longjmp ok [@ascuheap @acsmem?]
 @c     lll_lock @asulock @aculock
 @c     lll_unlock @asulock @aculock
-@c     CANCEL_RESET -> pthread_disable_asynccancel ok
+@c     __pthread_setcanceltype ok
 @c      lll_futex_wait ok
 @c     ->start_routine ok -----
 @c     call_tls_dtors @asulock @ascuheap @aculock @acsmem
diff --git a/misc/pselect.c b/misc/pselect.c
index 2292219..17492f0 100644
--- a/misc/pselect.c
+++ b/misc/pselect.c
@@ -73,6 +73,4 @@ __pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
 }
 #ifndef __pselect
 weak_alias (__pselect, pselect)
-/* __select handles cancellation.  */
-LIBC_CANCEL_HANDLED ();
 #endif
diff --git a/nptl/Makefile b/nptl/Makefile
index bbf4c7b..ab61c49 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -30,7 +30,7 @@ install-lib-ldscripts := libpthread.so
 
 routines = alloca_cutoff forward libc-lowlevellock libc-cancellation \
 	   libc-cleanup libc_pthread_init libc_multiple_threads \
-	   register-atfork unregister-atfork
+	   register-atfork unregister-atfork syscall_cancel
 shared-only-routines = forward
 
 # We need to provide certain routines for compatibility with existing
@@ -116,7 +116,6 @@ libpthread-routines = nptl-init vars events version pt-interp \
 		      cleanup cleanup_defer cleanup_compat \
 		      cleanup_defer_compat unwind \
 		      pt-longjmp pt-cleanup\
-		      cancellation \
 		      lowlevellock \
 		      lll_timedlock_wait lll_timedwait_tid \
 		      pt-fork pt-vfork \
@@ -165,7 +164,6 @@ CFLAGS-pthread_setcanceltype.c = -fexceptions -fasynchronous-unwind-tables
 
 # These are internal functions which similar functionality as setcancelstate
 # and setcanceltype.
-CFLAGS-cancellation.c = -fasynchronous-unwind-tables
 CFLAGS-libc-cancellation.c = -fasynchronous-unwind-tables
 
 # Calling pthread_exit() must cause the registered cancel handlers to
@@ -223,6 +221,8 @@ CFLAGS-fsync.c = -fexceptions -fasynchronous-unwind-tables
 
 CFLAGS-pt-system.c = -fexceptions
 
+CFLAGS-syscall_cancel.c = -fexceptions
+
 LDLIBS-tst-once5 = -lstdc++
 CFLAGS-tst-thread_local1.o = -std=gnu++11
 LDLIBS-tst-thread_local1 = -lstdc++
@@ -273,7 +273,7 @@ tests = tst-typesizes \
 	tst-cancel11 tst-cancel12 tst-cancel13 tst-cancel14 tst-cancel15 \
 	tst-cancel16 tst-cancel17 tst-cancel18 tst-cancel19 tst-cancel20 \
 	tst-cancel21 tst-cancel22 tst-cancel23 tst-cancel24 tst-cancel25 \
-	tst-cancel26 tst-cancel27 \
+	tst-cancel26 tst-cancel27 tst-cancel28 \
 	tst-cancel-self tst-cancel-self-cancelstate \
 	tst-cancel-self-canceltype tst-cancel-self-testcancel \
 	tst-cleanup0 tst-cleanup1 tst-cleanup2 tst-cleanup3 tst-cleanup4 \
diff --git a/nptl/Versions b/nptl/Versions
index 0ae5def..734d47a 100644
--- a/nptl/Versions
+++ b/nptl/Versions
@@ -36,6 +36,9 @@ libc {
     __libc_pthread_init;
     __libc_current_sigrtmin_private; __libc_current_sigrtmax_private;
     __libc_allocate_rtsig_private;
+    __syscall_cancel;
+    __syscall_cancel_arch_start;
+    __syscall_cancel_arch_end;
   }
 }
 
diff --git a/nptl/cancellation.c b/nptl/cancellation.c
deleted file mode 100644
index e3f0b61..0000000
--- a/nptl/cancellation.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/* Copyright (C) 2002-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <setjmp.h>
-#include <stdlib.h>
-#include "pthreadP.h"
-#include <futex-internal.h>
-
-
-/* The next two functions are similar to pthread_setcanceltype() but
-   more specialized for the use in the cancelable functions like write().
-   They do not need to check parameters etc.  */
-int
-attribute_hidden
-__pthread_enable_asynccancel (void)
-{
-  struct pthread *self = THREAD_SELF;
-  int oldval = THREAD_GETMEM (self, cancelhandling);
-
-  while (1)
-    {
-      int newval = oldval | CANCELTYPE_BITMASK;
-
-      if (newval == oldval)
-	break;
-
-      int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
-					      oldval);
-      if (__glibc_likely (curval == oldval))
-	{
-	  if (CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS (newval))
-	    {
-	      THREAD_SETMEM (self, result, PTHREAD_CANCELED);
-	      __do_cancel ();
-	    }
-
-	  break;
-	}
-
-      /* Prepare the next round.  */
-      oldval = curval;
-    }
-
-  return oldval;
-}
-
-
-void
-internal_function attribute_hidden
-__pthread_disable_asynccancel (int oldtype)
-{
-  /* If asynchronous cancellation was enabled before we do not have
-     anything to do.  */
-  if (oldtype & CANCELTYPE_BITMASK)
-    return;
-
-  struct pthread *self = THREAD_SELF;
-  int newval;
-
-  int oldval = THREAD_GETMEM (self, cancelhandling);
-
-  while (1)
-    {
-      newval = oldval & ~CANCELTYPE_BITMASK;
-
-      int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
-					      oldval);
-      if (__glibc_likely (curval == oldval))
-	break;
-
-      /* Prepare the next round.  */
-      oldval = curval;
-    }
-
-  /* We cannot return when we are being canceled.  Upon return the
-     thread might be things which would have to be undone.  The
-     following loop should loop until the cancellation signal is
-     delivered.  */
-  while (__builtin_expect ((newval & (CANCELING_BITMASK | CANCELED_BITMASK))
-			   == CANCELING_BITMASK, 0))
-    {
-      futex_wait_simple ((unsigned int *) &self->cancelhandling, newval,
-			 FUTEX_PRIVATE);
-      newval = THREAD_GETMEM (self, cancelhandling);
-    }
-}
diff --git a/nptl/descr.h b/nptl/descr.h
index a145860..a7349fa 100644
--- a/nptl/descr.h
+++ b/nptl/descr.h
@@ -280,23 +280,20 @@ struct pthread
   /* Bit set if asynchronous cancellation mode is selected.  */
 #define CANCELTYPE_BIT		1
 #define CANCELTYPE_BITMASK	(0x01 << CANCELTYPE_BIT)
-  /* Bit set if canceling has been initiated.  */
-#define CANCELING_BIT		2
-#define CANCELING_BITMASK	(0x01 << CANCELING_BIT)
-  /* Bit set if canceled.  */
-#define CANCELED_BIT		3
+  /* Bit set if threads is canceled.  */
+#define CANCELED_BIT		2
 #define CANCELED_BITMASK	(0x01 << CANCELED_BIT)
   /* Bit set if thread is exiting.  */
-#define EXITING_BIT		4
+#define EXITING_BIT		3
 #define EXITING_BITMASK		(0x01 << EXITING_BIT)
   /* Bit set if thread terminated and TCB is freed.  */
-#define TERMINATED_BIT		5
+#define TERMINATED_BIT		4
 #define TERMINATED_BITMASK	(0x01 << TERMINATED_BIT)
   /* Bit set if thread is supposed to change XID.  */
-#define SETXID_BIT		6
+#define SETXID_BIT		5
 #define SETXID_BITMASK		(0x01 << SETXID_BIT)
   /* Mask for the rest.  Helps the compiler to optimize.  */
-#define CANCEL_RESTMASK		0xffffff80
+#define CANCEL_RESTMASK		0xffffffc0
 
 #define CANCEL_ENABLED_AND_CANCELED(value) \
   (((value) & (CANCELSTATE_BITMASK | CANCELED_BITMASK | EXITING_BITMASK	      \
diff --git a/nptl/libc-cancellation.c b/nptl/libc-cancellation.c
index cb675ce..b013435 100644
--- a/nptl/libc-cancellation.c
+++ b/nptl/libc-cancellation.c
@@ -16,9 +16,50 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include <setjmp.h>
+#include <stdlib.h>
 #include "pthreadP.h"
 
+/* Cancellation function called by all cancellable syscalls.  */
+long int
+__syscall_cancel (__syscall_arg_t nr, __syscall_arg_t a1,
+		  __syscall_arg_t a2, __syscall_arg_t a3,
+		  __syscall_arg_t a4, __syscall_arg_t a5,
+		  __syscall_arg_t a6)
+{
+  pthread_t self = (pthread_t) THREAD_SELF;
+  volatile struct pthread *pd = (volatile struct pthread *) self;
+  long int result;
 
-#define __pthread_enable_asynccancel __libc_enable_asynccancel
-#define __pthread_disable_asynccancel __libc_disable_asynccancel
-#include <nptl/cancellation.c>
+  /* If cancellation is not enabled, call the syscall directly.  */
+  if (pd->cancelhandling & CANCELSTATE_BITMASK)
+    {
+      INTERNAL_SYSCALL_DECL (err);
+      result = INTERNAL_SYSCALL_NCS_CALL (nr, err, a1, a2, a3, a4, a5, a6);
+      if (INTERNAL_SYSCALL_ERROR_P (result, err))
+	return -INTERNAL_SYSCALL_ERRNO (result, err);
+      return result;
+    }
+
+  /* Call the arch-specific entry points that contains the globals markers
+     to be checked by SIGCANCEL handler.  */
+  result = __syscall_cancel_arch (&pd->cancelhandling, nr, a1, a2, a3, a4, a5,
+			          a6);
+
+  if ((result == -EINTR)
+      && (pd->cancelhandling & CANCELED_BITMASK)
+      && !(pd->cancelhandling & CANCELSTATE_BITMASK))
+    __syscall_do_cancel ();
+
+  return result;
+}
+libc_hidden_def (__syscall_cancel)
+
+/* Since __do_cancel is a always inline function, this creates a symbol the
+   arch-specific symbol can call to cancel the thread.  */
+void
+__cleanup_fct_attribute attribute_hidden __attribute ((noreturn))
+__syscall_do_cancel (void)
+{
+  __do_cancel ();
+}
diff --git a/nptl/lll_timedlock_wait.c b/nptl/lll_timedlock_wait.c
index 604953c..630c028 100644
--- a/nptl/lll_timedlock_wait.c
+++ b/nptl/lll_timedlock_wait.c
@@ -52,7 +52,7 @@ __lll_timedlock_wait (int *futex, const struct timespec *abstime, int private)
         return ETIMEDOUT;
 
       /* If *futex == 2, wait until woken or timeout.  */
-      lll_futex_timed_wait (futex, 2, &rt, private);
+      lll_futex_timed_wait_cancel (futex, 2, &rt, private);
     }
 
   return 0;
diff --git a/nptl/lll_timedwait_tid.c b/nptl/lll_timedwait_tid.c
index e4c8de0..950d1aa 100644
--- a/nptl/lll_timedwait_tid.c
+++ b/nptl/lll_timedwait_tid.c
@@ -62,7 +62,8 @@ __lll_timedwait_tid (int *tidp, const struct timespec *abstime)
          The kernel up to version 3.16.3 does not use the private futex
          operations for futex wake-up when the clone terminates.
       */
-      if (lll_futex_timed_wait (tidp, tid, &rt, LLL_SHARED) == -ETIMEDOUT)
+      if (lll_futex_timed_wait_cancel (tidp, tid, &rt, LLL_SHARED)
+	  == -ETIMEDOUT)
         return ETIMEDOUT;
     }
 
diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c
index 2f8599b..5febd77 100644
--- a/nptl/nptl-init.c
+++ b/nptl/nptl-init.c
@@ -38,6 +38,7 @@
 #include <kernel-features.h>
 #include <libc-internal.h>
 #include <pthread-pids.h>
+#include <sysdep-cancel.h>
 
 #ifndef TLS_MULTIPLE_THREADS_IN_TCB
 /* Pointer to the corresponding variable in libc.  */
@@ -176,49 +177,57 @@ __nptl_set_robust (struct pthread *self)
 
 
 #ifdef SIGCANCEL
+
 /* For asynchronous cancellation we use a signal.  This is the handler.  */
 static void
 sigcancel_handler (int sig, siginfo_t *si, void *ctx)
 {
+  INTERNAL_SYSCALL_DECL (err);
+  pid_t pid = INTERNAL_SYSCALL_CALL (getpid, err);
+
   /* Safety check.  It would be possible to call this function for
      other signals and send a signal from another process.  This is not
      correct and might even be a security problem.  Try to catch as
      many incorrect invocations as possible.  */
   if (sig != SIGCANCEL
-      || si->si_pid != __getpid()
+      || si->si_pid != pid
       || si->si_code != SI_TKILL)
     return;
 
   struct pthread *self = THREAD_SELF;
+  volatile struct pthread *pd = (volatile struct pthread *) self;
+  ucontext_t *uc = ctx;
+
+  if (((pd->cancelhandling & (CANCELSTATE_BITMASK)) != 0)
+      || ((pd->cancelhandling & CANCELED_BITMASK) == 0))
+    return;
 
-  int oldval = THREAD_GETMEM (self, cancelhandling);
-  while (1)
+  __sigaddset (&uc->uc_sigmask, SIGCANCEL);
+
+  /* Check if asynchronous cancellation mode is set and if interrupted
+     instruction pointer falls within the cancellable syscall bridge.  For
+     interruptable syscalls that might generate external side-effects (partial
+     reads or writes, for instance), the kernel will set the IP to after
+     '__syscall_cancel_arch_end', thus disabling the cancellation and allowing
+     the process to handle such conditions.  */
+  extern const char __syscall_cancel_arch_start[1];
+  extern const char __syscall_cancel_arch_end[1];
+  uintptr_t pc = __pthread_get_pc (ctx);
+  if (pd->cancelhandling & CANCELTYPE_BITMASK
+      || (pc >= (uintptr_t) __syscall_cancel_arch_start
+          && pc < (uintptr_t) __syscall_cancel_arch_end))
     {
-      /* We are canceled now.  When canceled by another thread this flag
-	 is already set but if the signal is directly send (internally or
-	 from another process) is has to be done here.  */
-      int newval = oldval | CANCELING_BITMASK | CANCELED_BITMASK;
-
-      if (oldval == newval || (oldval & EXITING_BITMASK) != 0)
-	/* Already canceled or exiting.  */
-	break;
-
-      int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
-					      oldval);
-      if (curval == oldval)
-	{
-	  /* Set the return value.  */
-	  THREAD_SETMEM (self, result, PTHREAD_CANCELED);
-
-	  /* Make sure asynchronous cancellation is still enabled.  */
-	  if ((newval & CANCELTYPE_BITMASK) != 0)
-	    /* Run the registered destructors and terminate the thread.  */
-	    __do_cancel ();
-
-	  break;
-	}
-
-      oldval = curval;
+      THREAD_ATOMIC_BIT_SET (self, cancelhandling, EXITING_BIT);
+      THREAD_SETMEM (self, result, PTHREAD_CANCELED);
+
+      /* Add SIGCANCEL on ignored sigmask to avoid the handler to be called
+	 again.  */
+      sigaddset_cancel (&uc->uc_sigmask);
+      INTERNAL_SYSCALL_CALL (rt_sigprocmask, err, SIG_SETMASK, &uc->uc_sigmask,
+			     NULL, _NSIG / 8);
+
+      __do_cancel ();
+      return;
     }
 }
 #endif
@@ -373,7 +382,10 @@ __pthread_initialize_minimal_internal (void)
      cannot install the handler we do not abort.  Maybe we should, but
      it is only asynchronous cancellation which is affected.  */
   sa.sa_sigaction = sigcancel_handler;
-  sa.sa_flags = SA_SIGINFO;
+  /* The signal handle should be non-interruptible to avoid the risk of
+     spurious EINTR caused by SIGCANCEL sent to process or if pthread_cancel
+     is called while cancellation is disabled in the target thread.  */
+  sa.sa_flags = SA_SIGINFO | SA_RESTART;
   (void) __libc_sigaction (SIGCANCEL, &sa, NULL);
 # endif
 
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index 4f76cbb..7b2cf71 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -291,51 +291,37 @@ __do_cancel (void)
 {
   struct pthread *self = THREAD_SELF;
 
-  /* Make sure we get no more cancellations.  */
-  THREAD_ATOMIC_BIT_SET (self, cancelhandling, EXITING_BIT);
+  /* Make sure we get no more cancellations by clearing the cancel
+     state.  */
+  int oldval = THREAD_GETMEM (self, cancelhandling);
+  while (1)
+    {
+      int newval = (oldval | CANCELSTATE_BITMASK);
+      newval &= ~(CANCELTYPE_BITMASK);
+      if (oldval == newval)
+	break;
+
+      int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
+					  oldval);
+      if (__glibc_likely (curval == oldval))
+	break;
+      oldval = curval;
+    }
+
+  THREAD_SETMEM (self, result, PTHREAD_CANCELED);
 
   __pthread_unwind ((__pthread_unwind_buf_t *)
 		    THREAD_GETMEM (self, cleanup_jmp_buf));
 }
 
 
-/* Set cancellation mode to asynchronous.  */
-#define CANCEL_ASYNC() \
-  __pthread_enable_asynccancel ()
-/* Reset to previous cancellation mode.  */
-#define CANCEL_RESET(oldtype) \
-  __pthread_disable_asynccancel (oldtype)
-
-#if IS_IN (libc)
-/* Same as CANCEL_ASYNC, but for use in libc.so.  */
-# define LIBC_CANCEL_ASYNC() \
-  __libc_enable_asynccancel ()
-/* Same as CANCEL_RESET, but for use in libc.so.  */
-# define LIBC_CANCEL_RESET(oldtype) \
-  __libc_disable_asynccancel (oldtype)
-# define LIBC_CANCEL_HANDLED() \
-  __asm (".globl " __SYMBOL_PREFIX "__libc_enable_asynccancel"); \
-  __asm (".globl " __SYMBOL_PREFIX "__libc_disable_asynccancel")
-#elif IS_IN (libpthread)
-# define LIBC_CANCEL_ASYNC() CANCEL_ASYNC ()
-# define LIBC_CANCEL_RESET(val) CANCEL_RESET (val)
-# define LIBC_CANCEL_HANDLED() \
-  __asm (".globl " __SYMBOL_PREFIX "__pthread_enable_asynccancel"); \
-  __asm (".globl " __SYMBOL_PREFIX "__pthread_disable_asynccancel")
-#elif IS_IN (librt)
-# define LIBC_CANCEL_ASYNC() \
-  __librt_enable_asynccancel ()
-# define LIBC_CANCEL_RESET(val) \
-  __librt_disable_asynccancel (val)
-# define LIBC_CANCEL_HANDLED() \
-  __asm (".globl " __SYMBOL_PREFIX "__librt_enable_asynccancel"); \
-  __asm (".globl " __SYMBOL_PREFIX "__librt_disable_asynccancel")
-#else
-# define LIBC_CANCEL_ASYNC()	0 /* Just a dummy value.  */
-# define LIBC_CANCEL_RESET(val)	((void)(val)) /* Nothing, but evaluate it.  */
-# define LIBC_CANCEL_HANDLED()	/* Nothing.  */
-#endif
+extern long int __syscall_cancel_arch (volatile int *, __syscall_arg_t nr,
+     __syscall_arg_t arg1, __syscall_arg_t arg2, __syscall_arg_t arg3,
+     __syscall_arg_t arg4, __syscall_arg_t arg5, __syscall_arg_t arg6);
+libc_hidden_proto (__syscall_cancel_arch);
 
+extern void __syscall_do_cancel (void)
+     __cleanup_fct_attribute attribute_hidden __attribute ((__noreturn__));
 
 /* Internal prototypes.  */
 
@@ -502,9 +488,6 @@ extern int __pthread_equal (pthread_t thread1, pthread_t thread2);
 extern int __pthread_kill (pthread_t threadid, int signo);
 extern void __pthread_exit (void *value) __attribute__ ((__noreturn__));
 extern int __pthread_setcanceltype (int type, int *oldtype);
-extern int __pthread_enable_asynccancel (void) attribute_hidden;
-extern void __pthread_disable_asynccancel (int oldtype)
-     internal_function attribute_hidden;
 extern void __pthread_testcancel (void);
 
 #if IS_IN (libpthread)
@@ -537,16 +520,6 @@ extern int __pthread_cond_wait_2_0 (pthread_cond_2_0_t *cond,
 extern int __pthread_getaffinity_np (pthread_t th, size_t cpusetsize,
 				     cpu_set_t *cpuset);
 
-/* The two functions are in libc.so and not exported.  */
-extern int __libc_enable_asynccancel (void) attribute_hidden;
-extern void __libc_disable_asynccancel (int oldtype)
-     internal_function attribute_hidden;
-
-
-/* The two functions are in librt.so and not exported.  */
-extern int __librt_enable_asynccancel (void) attribute_hidden;
-extern void __librt_disable_asynccancel (int oldtype)
-     internal_function attribute_hidden;
 
 #if IS_IN (libpthread)
 /* Special versions which use non-exported functions.  */
diff --git a/nptl/pthread_cancel.c b/nptl/pthread_cancel.c
index 231a58d..d2e7737 100644
--- a/nptl/pthread_cancel.c
+++ b/nptl/pthread_cancel.c
@@ -37,67 +37,23 @@ pthread_cancel (pthread_t th)
 #ifdef SHARED
   pthread_cancel_init ();
 #endif
-  int result = 0;
-  int oldval;
-  int newval;
-  do
-    {
-    again:
-      oldval = pd->cancelhandling;
-      newval = oldval | CANCELING_BITMASK | CANCELED_BITMASK;
 
-      /* Avoid doing unnecessary work.  The atomic operation can
-	 potentially be expensive if the bug has to be locked and
-	 remote cache lines have to be invalidated.  */
-      if (oldval == newval)
-	break;
+  THREAD_ATOMIC_BIT_SET (pd, cancelhandling, CANCELED_BIT);
 
-      /* If the cancellation is handled asynchronously just send a
-	 signal.  We avoid this if possible since it's more
-	 expensive.  */
-      if (CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS (newval))
-	{
-	  /* Mark the cancellation as "in progress".  */
-	  if (atomic_compare_and_exchange_bool_acq (&pd->cancelhandling,
-						    oldval | CANCELING_BITMASK,
-						    oldval))
-	    goto again;
-
-#ifdef SIGCANCEL
-	  /* The cancellation handler will take care of marking the
-	     thread as canceled.  */
-	  pid_t pid = getpid ();
-
-	  INTERNAL_SYSCALL_DECL (err);
-	  int val = INTERNAL_SYSCALL_CALL (tgkill, err, pid, pd->tid,
-					   SIGCANCEL);
-	  if (INTERNAL_SYSCALL_ERROR_P (val, err))
-	    result = INTERNAL_SYSCALL_ERRNO (val, err);
-#else
-          /* It should be impossible to get here at all, since
-             pthread_setcanceltype should never have allowed
-             PTHREAD_CANCEL_ASYNCHRONOUS to be set.  */
-          abort ();
-#endif
-
-	  break;
-	}
-
-	/* A single-threaded process should be able to kill itself, since
-	   there is nothing in the POSIX specification that says that it
-	   cannot.  So we set multiple_threads to true so that cancellation
-	   points get executed.  */
-	THREAD_SETMEM (THREAD_SELF, header.multiple_threads, 1);
+  /* A single-threaded process should be able to kill itself, since there is
+     nothing in the POSIX specification that says that it cannot.  So we set
+     multiple_threads to true so that cancellation points get executed.  */
+  THREAD_SETMEM (THREAD_SELF, header.multiple_threads, 1);
 #ifndef TLS_MULTIPLE_THREADS_IN_TCB
-	__pthread_multiple_threads = *__libc_multiple_threads_ptr = 1;
+  __pthread_multiple_threads = *__libc_multiple_threads_ptr = 1;
 #endif
-    }
-  /* Mark the thread as canceled.  This has to be done
-     atomically since other bits could be modified as well.  */
-  while (atomic_compare_and_exchange_bool_acq (&pd->cancelhandling, newval,
-					       oldval));
 
-  return result;
+  /* Avoid signaling when thread attempts cancel itself (pthread_kill
+     is expensive).  */
+  if (pd == THREAD_SELF && !(pd->canceltype & CANCELTYPE_BITMASK))
+    return 0;
+
+  return __pthread_kill (th, SIGCANCEL);
 }
 
 PTHREAD_STATIC_FN_REQUIRE (pthread_create)
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index 2ef2bcb..40dc557 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -404,7 +404,7 @@ START_THREAD_DEFN
   /* If the parent was running cancellation handlers while creating
      the thread the new thread inherited the signal mask.  Reset the
      cancellation signal mask.  */
-  if (__glibc_unlikely (pd->parent_cancelhandling & CANCELING_BITMASK))
+  if (__glibc_unlikely (pd->parent_cancelhandling & CANCELED_BITMASK))
     {
       INTERNAL_SYSCALL_DECL (err);
       sigset_t mask;
@@ -436,7 +436,8 @@ START_THREAD_DEFN
 	 have ownership (see CONCURRENCY NOTES above).  */
       if (__glibc_unlikely (pd->stopped_start))
 	{
-	  int oldtype = CANCEL_ASYNC ();
+	  int ct;
+	  __pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &ct);
 
 	  /* Get the lock the parent locked to force synchronization.  */
 	  lll_lock (pd->lock, LLL_PRIVATE);
@@ -446,7 +447,7 @@ START_THREAD_DEFN
 	  /* And give it up right away.  */
 	  lll_unlock (pd->lock, LLL_PRIVATE);
 
-	  CANCEL_RESET (oldtype);
+	  __pthread_setcanceltype (ct, NULL);
 	}
 
       LIBC_PROBE (pthread_start, 3, (pthread_t) pd, pd->start_routine, pd->arg);
diff --git a/nptl/pthread_exit.c b/nptl/pthread_exit.c
index dffab09..0f29609 100644
--- a/nptl/pthread_exit.c
+++ b/nptl/pthread_exit.c
@@ -23,9 +23,14 @@
 void
 __pthread_exit (void *value)
 {
-  THREAD_SETMEM (THREAD_SELF, result, value);
+  struct pthread *self = THREAD_SELF;
 
-  __do_cancel ();
+  THREAD_SETMEM (self, result, value);
+
+  THREAD_ATOMIC_BIT_SET (self, cancelhandling, EXITING_BIT);
+
+  __pthread_unwind ((__pthread_unwind_buf_t *)
+		    THREAD_GETMEM (self, cleanup_jmp_buf));
 }
 strong_alias (__pthread_exit, pthread_exit)
 
diff --git a/nptl/pthread_join.c b/nptl/pthread_join.c
index 0192f69..bcdfea8 100644
--- a/nptl/pthread_join.c
+++ b/nptl/pthread_join.c
@@ -52,7 +52,7 @@ pthread_join (pthread_t threadid, void **thread_return)
     return EINVAL;
 
   struct pthread *self = THREAD_SELF;
-  int result = 0;
+  int result = 0, ct;
 
   LIBC_PROBE (pthread_join, 1, threadid);
 
@@ -62,12 +62,12 @@ pthread_join (pthread_t threadid, void **thread_return)
   pthread_cleanup_push (cleanup, &pd->joinid);
 
   /* Switch to asynchronous cancellation.  */
-  int oldtype = CANCEL_ASYNC ();
+  __pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &ct);
 
   if ((pd == self
        || (self->joinid == pd
 	   && (pd->cancelhandling
-	       & (CANCELING_BITMASK | CANCELED_BITMASK | EXITING_BITMASK
+	       & (CANCELED_BITMASK | EXITING_BITMASK
 		  | TERMINATED_BITMASK)) == 0))
       && !CANCEL_ENABLED_AND_CANCELED (self->cancelhandling))
     /* This is a deadlock situation.  The threads are waiting for each
@@ -89,9 +89,7 @@ pthread_join (pthread_t threadid, void **thread_return)
     /* Wait for the child.  */
     lll_wait_tid (pd->tid);
 
-
-  /* Restore cancellation mode.  */
-  CANCEL_RESET (oldtype);
+  __pthread_setcanceltype (ct, NULL);
 
   /* Remove the handler.  */
   pthread_cleanup_pop (0);
diff --git a/nptl/pthread_timedjoin.c b/nptl/pthread_timedjoin.c
index 567c171..75a9cfe 100644
--- a/nptl/pthread_timedjoin.c
+++ b/nptl/pthread_timedjoin.c
@@ -35,7 +35,7 @@ pthread_timedjoin_np (pthread_t threadid, void **thread_return,
 {
   struct pthread *self;
   struct pthread *pd = (struct pthread *) threadid;
-  int result;
+  int result, ct;
 
   /* Make sure the descriptor is valid.  */
   if (INVALID_NOT_TERMINATED_TD_P (pd))
@@ -72,15 +72,12 @@ pthread_timedjoin_np (pthread_t threadid, void **thread_return,
   pthread_cleanup_push (cleanup, &pd->joinid);
 
   /* Switch to asynchronous cancellation.  */
-  int oldtype = CANCEL_ASYNC ();
-
+  __pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &ct);
 
   /* Wait for the child.  */
   result = lll_timedwait_tid (pd->tid, abstime);
 
-
-  /* Restore cancellation mode.  */
-  CANCEL_RESET (oldtype);
+  __pthread_setcanceltype (ct, NULL);
 
   /* Remove the handler.  */
   pthread_cleanup_pop (0);
diff --git a/nptl/sem_wait.c b/nptl/sem_wait.c
index 625bf08..b6f4312 100644
--- a/nptl/sem_wait.c
+++ b/nptl/sem_wait.c
@@ -56,14 +56,8 @@ __old_sem_wait (sem_t *sem)
       if (atomic_decrement_if_positive (futex) > 0)
 	return 0;
 
-      /* Enable asynchronous cancellation.  Required by the standard.  */
-      int oldtype = __pthread_enable_asynccancel ();
-
       /* Always assume the semaphore is shared.  */
-      err = lll_futex_wait (futex, 0, LLL_SHARED);
-
-      /* Disable asynchronous cancellation.  */
-      __pthread_disable_asynccancel (oldtype);
+      err = lll_futex_wait_cancel (futex, 0, LLL_SHARED);
     }
   while (err == 0 || err == -EWOULDBLOCK);
 
diff --git a/nptl/tst-cancel28.c b/nptl/tst-cancel28.c
new file mode 100644
index 0000000..849c09a
--- /dev/null
+++ b/nptl/tst-cancel28.c
@@ -0,0 +1,94 @@
+/* Check side-effect act for cancellable syscalls (BZ #12683).
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* This testcase checks if there is resource leakage if the syscall has
+   returned from kernelspace, but before userspace saves the return
+   value.  The 'leaker' thread should be able to close the file descriptor
+   if the resource is already allocated, meaning that if the cancellation
+   signal arrives *after* the open syscal return from kernel, the
+   side-effect should be visible to application.  */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <support/xthread.h>
+#include <support/check.h>
+#include <support/temp_file.h>
+
+static void *
+writeopener (void *arg)
+{
+  int fd;
+  for (;;)
+    {
+      fd = open (arg, O_WRONLY);
+      close (fd);
+    }
+  return NULL;
+}
+
+static void *
+leaker (void *arg)
+{
+  int fd = open (arg, O_RDONLY);
+  pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, 0);
+  close (fd);
+  return NULL;
+}
+
+
+#define ITER_COUNT 1000
+#define MAX_FILENO 1024
+
+static int
+do_test (void)
+{
+  struct stat st;
+  int i;
+
+  char *name = NULL;
+  create_temp_fifo ("tst-cancel28", &name);
+
+  srand (1);
+
+  xpthread_create (NULL, writeopener, name);
+  for (i = 0; i < ITER_COUNT; i++)
+    {
+      pthread_t td = xpthread_create (NULL, leaker, name);
+      struct timespec ts =
+	{ .tv_nsec = rand () % 100000, .tv_sec = 0 };
+      nanosleep (&ts, NULL);
+      /* Ignore pthread_cancel result because it might be the
+	 case when pthread_cancel is called when thread is already
+	 exited.  */
+      pthread_cancel (td);
+      xpthread_join (td);
+    }
+
+  for (i = STDERR_FILENO+1; i < MAX_FILENO; i++)
+    if (!fstat (i, &st))
+      FAIL_EXIT1 ("leaked fd %d", i);
+
+  return 0;
+}
+
+#define TIMEOUT 10
+#include <support/test-driver.c>
diff --git a/rt/Makefile b/rt/Makefile
index 9740dc2..232e543 100644
--- a/rt/Makefile
+++ b/rt/Makefile
@@ -64,7 +64,6 @@ CFLAGS-aio_suspend.c = -fexceptions
 CFLAGS-mq_timedreceive.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-mq_timedsend.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-clock_nanosleep.c = -fexceptions -fasynchronous-unwind-tables
-CFLAGS-librt-cancellation.c = -fasynchronous-unwind-tables
 
 LDFLAGS-rt.so = -Wl,--enable-new-dtags,-z,nodelete
 
diff --git a/support/temp_file.c b/support/temp_file.c
index f06647a..a9eaeac 100644
--- a/support/temp_file.c
+++ b/support/temp_file.c
@@ -86,6 +86,31 @@ create_temp_file (const char *base, char **filename)
   return fd;
 }
 
+int
+create_temp_fifo (const char *base, char **fifoname)
+{
+  char *fname = (char *) xmalloc (strlen (test_dir) + 1 + strlen (base)
+				  + sizeof ("XXXXXX"));
+  strcpy (stpcpy (stpcpy (stpcpy (fname, test_dir), "/"), base), "XXXXXX");
+
+  mktemp (fname);
+  int fd = mkfifo (fname, 0600);
+  if (fd == -1)
+    {
+      printf ("cannot open temporary fifo '%s': %m\n", fname);
+      free (fname);
+      return -1;
+    }
+
+  add_temp_file (fname);
+  if (fifoname != NULL)
+    *fifoname = fname;
+  else
+    free (fname);
+
+  return fd;
+}
+
 /* Helper functions called by the test skeleton follow.  */
 
 void
diff --git a/support/temp_file.h b/support/temp_file.h
index 6fed8df..7525ec5 100644
--- a/support/temp_file.h
+++ b/support/temp_file.h
@@ -32,6 +32,12 @@ void add_temp_file (const char *name);
    *FILENAME.  */
 int create_temp_file (const char *base, char **filename);
 
+/* Create a temporary fifo.  Return the opened file descriptor on
+   success, or -1 on failure.  Write the file name to *FILENAME if
+   FILENAME is not NULL.  In this case, the caller is expected to free
+   *FILENAME.  */
+int create_temp_fifo (const char *name, char **fifoname);
+
 __END_DECLS
 
 #endif /* SUPPORT_TEMP_FILE_H */
diff --git a/sysdeps/generic/sysdep-cancel.h b/sysdeps/generic/sysdep-cancel.h
index ba6a1e0..5c84b44 100644
--- a/sysdeps/generic/sysdep-cancel.h
+++ b/sysdeps/generic/sysdep-cancel.h
@@ -3,6 +3,3 @@
 /* No multi-thread handling enabled.  */
 #define SINGLE_THREAD_P (1)
 #define RTLD_SINGLE_THREAD_P (1)
-#define LIBC_CANCEL_ASYNC()	0 /* Just a dummy value.  */
-#define LIBC_CANCEL_RESET(val)	((void)(val)) /* Nothing, but evaluate it.  */
-#define LIBC_CANCEL_HANDLED()	/* Nothing.  */
diff --git a/sysdeps/nptl/Makefile b/sysdeps/nptl/Makefile
index 4f4f4ff..708cab5 100644
--- a/sysdeps/nptl/Makefile
+++ b/sysdeps/nptl/Makefile
@@ -21,8 +21,7 @@ libpthread-sysdep_routines += errno-loc
 endif
 
 ifeq ($(subdir),rt)
-librt-sysdep_routines += timer_routines librt-cancellation
-CFLAGS-librt-cancellation.c += -fexceptions -fasynchronous-unwind-tables
+librt-sysdep_routines += timer_routines
 
 tests += tst-mqueue8x
 CFLAGS-tst-mqueue8x.c += -fexceptions
diff --git a/sysdeps/nptl/aio_misc.h b/sysdeps/nptl/aio_misc.h
index 47b1a36..817a75c 100644
--- a/sysdeps/nptl/aio_misc.h
+++ b/sysdeps/nptl/aio_misc.h
@@ -34,22 +34,18 @@
 
 #define AIO_MISC_WAIT(result, futex, timeout, cancel)			      \
   do {									      \
-    volatile unsigned int *futexaddr = &futex;				      \
+    unsigned int *futexaddr = (unsigned int *)&futex;			      \
     unsigned int oldval = futex;					      \
 									      \
     if (oldval != 0)							      \
       {									      \
 	pthread_mutex_unlock (&__aio_requests_mutex);			      \
 									      \
-	int oldtype;							      \
-	if (cancel)							      \
-	  oldtype = LIBC_CANCEL_ASYNC ();				      \
-									      \
 	int status;							      \
 	do								      \
 	  {								      \
-	    status = futex_reltimed_wait ((unsigned int *) futexaddr, oldval, \
-					  timeout, FUTEX_PRIVATE);	      \
+	    status = futex_reltimed_wait_cancelable (futexaddr, oldval,	      \
+						     timeout, FUTEX_PRIVATE); \
 	    if (status != EAGAIN)					      \
 	      break;							      \
 									      \
@@ -57,9 +53,6 @@
 	  }								      \
 	while (oldval != 0);						      \
 									      \
-	if (cancel)							      \
-	  LIBC_CANCEL_RESET (oldtype);					      \
-									      \
 	if (status == EINTR)						      \
 	  result = EINTR;						      \
 	else if (status == ETIMEDOUT)					      \
diff --git a/sysdeps/nptl/gai_misc.h b/sysdeps/nptl/gai_misc.h
index 8b2a2c1..df6b434 100644
--- a/sysdeps/nptl/gai_misc.h
+++ b/sysdeps/nptl/gai_misc.h
@@ -35,22 +35,18 @@
 
 #define GAI_MISC_WAIT(result, futex, timeout, cancel) \
   do {									      \
-    volatile unsigned int *futexaddr = &futex;				      \
+    unsigned int *futexaddr = (unsigned int *)&futex;			      \
     unsigned int oldval = futex;					      \
 									      \
     if (oldval != 0)							      \
       {									      \
 	pthread_mutex_unlock (&__gai_requests_mutex);			      \
 									      \
-	int oldtype;							      \
-	if (cancel)							      \
-	  oldtype = LIBC_CANCEL_ASYNC ();				      \
-									      \
 	int status;							      \
 	do								      \
 	  {								      \
-	    status = futex_reltimed_wait ((unsigned int *) futexaddr, oldval, \
-					  timeout, FUTEX_PRIVATE);	      \
+	    status = futex_reltimed_wait_cancelable (futexaddr, oldval,	      \
+						     timeout, FUTEX_PRIVATE); \
 	    if (status != EAGAIN)					      \
 	      break;							      \
 									      \
@@ -58,9 +54,6 @@
 	  }								      \
 	while (oldval != 0);						      \
 									      \
-	if (cancel)							      \
-	  LIBC_CANCEL_RESET (oldtype);					      \
-									      \
 	if (status == EINTR)						      \
 	  result = EINTR;						      \
 	else if (status == ETIMEDOUT)					      \
diff --git a/sysdeps/nptl/librt-cancellation.c b/sysdeps/nptl/librt-cancellation.c
deleted file mode 100644
index 1932242..0000000
--- a/sysdeps/nptl/librt-cancellation.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/* Copyright (C) 2002-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <nptl/pthreadP.h>
-
-
-#define __pthread_enable_asynccancel __librt_enable_asynccancel
-#define __pthread_disable_asynccancel __librt_disable_asynccancel
-#include <nptl/cancellation.c>
diff --git a/sysdeps/nptl/lowlevellock.h b/sysdeps/nptl/lowlevellock.h
index 42d9658..340db86 100644
--- a/sysdeps/nptl/lowlevellock.h
+++ b/sysdeps/nptl/lowlevellock.h
@@ -180,12 +180,13 @@ extern int __lll_timedlock_wait (int *futex, const struct timespec *,
    wake-up when the clone terminates.  The memory location contains the
    thread ID while the clone is running and is reset to zero by the kernel
    afterwards.  The kernel up to version 3.16.3 does not use the private futex
-   operations for futex wake-up when the clone terminates.  */
+   operations for futex wake-up when the clone terminates.
+   Both lll_wait_tid and lll_timewait_tid acts as cancellation points.  */
 #define lll_wait_tid(tid) \
   do {					\
     __typeof (tid) __tid;		\
     while ((__tid = (tid)) != 0)	\
-      lll_futex_wait (&(tid), __tid, LLL_SHARED);\
+      lll_futex_wait_cancel (&(tid), __tid, LLL_SHARED);\
   } while (0)
 
 extern int __lll_timedwait_tid (int *, const struct timespec *)
diff --git a/sysdeps/posix/open64.c b/sysdeps/posix/open64.c
index dd1b4d6..8e6f2b9 100644
--- a/sysdeps/posix/open64.c
+++ b/sysdeps/posix/open64.c
@@ -34,16 +34,8 @@ __libc_open64 (const char *file, int oflag, ...)
       va_end (arg);
     }
 
-  if (SINGLE_THREAD_P)
-    return __libc_open (file, oflag | O_LARGEFILE, mode);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = __libc_open (file, oflag | O_LARGEFILE, mode);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  /* __libc_open should be a cancellation point.  */
+  return __libc_open (file, oflag | O_LARGEFILE, mode);
 }
 weak_alias (__libc_open64, __open64)
 libc_hidden_weak (__open64)
diff --git a/sysdeps/posix/pause.c b/sysdeps/posix/pause.c
index 7996cd6..59bf6cc 100644
--- a/sysdeps/posix/pause.c
+++ b/sysdeps/posix/pause.c
@@ -38,8 +38,6 @@ __libc_pause (void)
 }
 weak_alias (__libc_pause, pause)
 
-LIBC_CANCEL_HANDLED ();		/* sigsuspend handles our cancellation.  */
-
 #ifndef NO_CANCELLATION
 # include <not-cancel.h>
 
diff --git a/sysdeps/posix/sigpause.c b/sysdeps/posix/sigpause.c
index 9038ed3..ffa9fc9 100644
--- a/sysdeps/posix/sigpause.c
+++ b/sysdeps/posix/sigpause.c
@@ -50,16 +50,7 @@ do_sigpause (int sig_or_mask, int is_sig)
 int
 __sigpause (int sig_or_mask, int is_sig)
 {
-  if (SINGLE_THREAD_P)
-    return do_sigpause (sig_or_mask, is_sig);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = do_sigpause (sig_or_mask, is_sig);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return do_sigpause (sig_or_mask, is_sig);
 }
 libc_hidden_def (__sigpause)
 
diff --git a/sysdeps/posix/sigwait.c b/sysdeps/posix/sigwait.c
index d807dbf..f86cce2 100644
--- a/sysdeps/posix/sigwait.c
+++ b/sysdeps/posix/sigwait.c
@@ -88,13 +88,8 @@ __sigwait (const sigset_t *set, int *sig)
   if (SINGLE_THREAD_P)
     return do_sigwait (set, sig);
 
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = do_sigwait (set, sig);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  /* do_sigwait should be a cancellation point.  */
+  return do_sigwait (set, sig);
 }
 libc_hidden_def (__sigwait)
 weak_alias (__sigwait, sigwait)
diff --git a/sysdeps/posix/waitid.c b/sysdeps/posix/waitid.c
index 2c23cdb..9925700 100644
--- a/sysdeps/posix/waitid.c
+++ b/sysdeps/posix/waitid.c
@@ -151,16 +151,7 @@ OUR_WAITID (idtype_t idtype, id_t id, siginfo_t *infop, int options)
 int
 __waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options)
 {
-  if (SINGLE_THREAD_P)
-    return do_waitid (idtype, id, infop, options);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = do_waitid (idtype, id, infop, options);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return do_waitid (idtype, id, infop, options);
 }
 weak_alias (__waitid, waitid)
 strong_alias (__waitid, __libc_waitid)
diff --git a/sysdeps/sparc/sparc32/lowlevellock.c b/sysdeps/sparc/sparc32/lowlevellock.c
index e502bf6..af3b227 100644
--- a/sysdeps/sparc/sparc32/lowlevellock.c
+++ b/sysdeps/sparc/sparc32/lowlevellock.c
@@ -122,7 +122,8 @@ __lll_timedwait_tid (int *tidp, const struct timespec *abstime)
 
       /* Wait until thread terminates.  The kernel so far does not use
 	 the private futex operations for this.  */
-      if (lll_futex_timed_wait (tidp, tid, &rt, LLL_SHARED) == -ETIMEDOUT)
+      if (lll_futex_timed_wait_cancel (tidp, tid, &rt, LLL_SHARED)
+	  == -ETIMEDOUT)
 	return ETIMEDOUT;
     }
 
diff --git a/sysdeps/unix/sysdep.h b/sysdeps/unix/sysdep.h
index c308547..10669ae 100644
--- a/sysdeps/unix/sysdep.h
+++ b/sysdeps/unix/sysdep.h
@@ -24,6 +24,9 @@
 #define	SYSCALL__(name, args)	PSEUDO (__##name, name, args)
 #define	SYSCALL(name, args)	PSEUDO (name, name, args)
 
+#ifndef __ASSEMBLER__
+# include <errno.h>
+
 #define __SYSCALL_CONCAT_X(a,b)     a##b
 #define __SYSCALL_CONCAT(a,b)       __SYSCALL_CONCAT_X (a, b)
 
@@ -57,6 +60,29 @@
 #define INTERNAL_SYSCALL_CALL(...) \
   __INTERNAL_SYSCALL_DISP (__INTERNAL_SYSCALL, __VA_ARGS__)
 
+#define __INTERNAL_SYSCALL_NCS0(name, err) \
+  INTERNAL_SYSCALL_NCS (name, err, 0)
+#define __INTERNAL_SYSCALL_NCS1(name, err, a1) \
+  INTERNAL_SYSCALL_NCS (name, err, 1, a1)
+#define __INTERNAL_SYSCALL_NCS2(name, err, a1, a2) \
+  INTERNAL_SYSCALL_NCS (name, err, 2, a1, a2)
+#define __INTERNAL_SYSCALL_NCS3(name, err, a1, a2, a3) \
+  INTERNAL_SYSCALL_NCS (name, err, 3, a1, a2, a3)
+#define __INTERNAL_SYSCALL_NCS4(name, err, a1, a2, a3, a4) \
+  INTERNAL_SYSCALL_NCS (name, err, 4, a1, a2, a3, a4)
+#define __INTERNAL_SYSCALL_NCS5(name, err, a1, a2, a3, a4, a5) \
+  INTERNAL_SYSCALL_NCS (name, err, 5, a1, a2, a3, a4, a5)
+#define __INTERNAL_SYSCALL_NCS6(name, err, a1, a2, a3, a4, a5, a6) \
+  INTERNAL_SYSCALL_NCS (name, err, 6, a1, a2, a3, a4, a5, a6)
+#define __INTERNAL_SYSCALL_NCS7(name, err, a1, a2, a3, a4, a5, a6, a7) \
+  INTERNAL_SYSCALL_NCS (name, err, 7, a1, a2, a3, a4, a5, a6, a7)
+
+/* Issue a syscall defined by syscall number plus any other argument required.
+   It is similar to INTERNAL_SYSCALL_NCS macro, but without the need to pass
+   the expected argument number as third parameter.  */
+#define INTERNAL_SYSCALL_NCS_CALL(...) \
+  __INTERNAL_SYSCALL_DISP (__INTERNAL_SYSCALL_NCS, __VA_ARGS__)
+
 #define __INLINE_SYSCALL0(name) \
   INLINE_SYSCALL (name, 0)
 #define __INLINE_SYSCALL1(name, a1) \
@@ -88,19 +114,65 @@
 #define INLINE_SYSCALL_CALL(...) \
   __INLINE_SYSCALL_DISP (__INLINE_SYSCALL, __VA_ARGS__)
 
-#define SYSCALL_CANCEL(...) \
-  ({									     \
-    long int sc_ret;							     \
-    if (SINGLE_THREAD_P) 						     \
-      sc_ret = INLINE_SYSCALL_CALL (__VA_ARGS__); 			     \
-    else								     \
-      {									     \
-	int sc_cancel_oldtype = LIBC_CANCEL_ASYNC ();			     \
-	sc_ret = INLINE_SYSCALL_CALL (__VA_ARGS__);			     \
-        LIBC_CANCEL_RESET (sc_cancel_oldtype);				     \
-      }									     \
-    sc_ret;								     \
+
+/* Cancellation macros.  */
+#ifndef __SSC
+typedef long int __syscall_arg_t;
+# define __SSC(__x) ((__syscall_arg_t) (__x))
+#endif
+
+long int __syscall_cancel (__syscall_arg_t nr, __syscall_arg_t arg1,
+			   __syscall_arg_t arg2, __syscall_arg_t arg3,
+			   __syscall_arg_t arg4, __syscall_arg_t arg5,
+			   __syscall_arg_t arg6);
+libc_hidden_proto (__syscall_cancel);
+
+#define __SYSCALL_CANCEL0(name) \
+  (__syscall_cancel)(__NR_##name, 0, 0, 0, 0, 0, 0)
+#define __SYSCALL_CANCEL1(name, a1) \
+  (__syscall_cancel)(__NR_##name, __SSC(a1), 0, 0, 0, 0, 0)
+#define __SYSCALL_CANCEL2(name, a1, a2) \
+  (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), 0, 0, 0, 0)
+#define __SYSCALL_CANCEL3(name, a1, a2, a3) \
+  (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), __SSC(a3), 0, 0, 0)
+#define __SYSCALL_CANCEL4(name, a1, a2, a3, a4) \
+  (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), __SSC(a3), \
+		     __SSC(a4), 0, 0)
+#define __SYSCALL_CANCEL5(name, a1, a2, a3, a4, a5) \
+  (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), __SSC(a3), \
+		     __SSC(a4), __SSC(a5), 0)
+#define __SYSCALL_CANCEL6(name, a1, a2, a3, a4, a5, a6) \
+  (__syscall_cancel)(__NR_##name, __SSC(a1), __SSC(a2), __SSC(a3), \
+		     __SSC(a4), __SSC(a5), __SSC(a6))
+
+#define __SYSCALL_CANCEL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n
+#define __SYSCALL_CANCEL_NARGS(...) \
+  __SYSCALL_CANCEL_NARGS_X (__VA_ARGS__,7,6,5,4,3,2,1,0,)
+#define __SYSCALL_CANCEL_CONCAT_X(a,b)     a##b
+#define __SYSCALL_CANCEL_CONCAT(a,b)       __SYSCALL_CANCEL_CONCAT_X (a, b)
+#define __SYSCALL_CANCEL_DISP(b,...) \
+  __SYSCALL_CANCEL_CONCAT (b,__SYSCALL_CANCEL_NARGS(__VA_ARGS__))(__VA_ARGS__)
+
+#define __SYSCALL_CANCEL_CALL(...) \
+  __SYSCALL_CANCEL_DISP (__SYSCALL_CANCEL, __VA_ARGS__)
+
+#define SYSCALL_CANCEL_NCS(name, nr, args...) \
+  __SYSCALL_CANCEL_CALL (name, nr, args)
+
+
+/* The loader does not need to handle thread cancellation, use direct
+   syscall instead.  */
+#if IS_IN (rtld)
+# define SYSCALL_CANCEL(...) INLINE_SYSCALL_CALL (__VA_ARGS__)
+#else
+# define SYSCALL_CANCEL(...) \
+  ({									\
+    long int sc_ret = __SYSCALL_CANCEL_CALL (__VA_ARGS__);		\
+    SYSCALL_CANCEL_RET ((sc_ret));					\
   })
+#endif
+
+#endif /* __ASSEMBLER__  */
 
 /* Machine-dependent sysdep.h files are expected to define the macro
    PSEUDO (function_name, syscall_name) to emit assembly code to define the
diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions
index 202ffcc..ba197f6 100644
--- a/sysdeps/unix/sysv/linux/Versions
+++ b/sysdeps/unix/sysv/linux/Versions
@@ -169,6 +169,7 @@ libc {
   GLIBC_PRIVATE {
     # functions used in other libraries
     __syscall_rt_sigqueueinfo;
+    __sigtimedwait;
     # functions used by nscd
     __netlink_assert_response;
   }
diff --git a/sysdeps/unix/sysv/linux/clock_nanosleep.c b/sysdeps/unix/sysv/linux/clock_nanosleep.c
index 93bc4cf..b9a835a 100644
--- a/sysdeps/unix/sysv/linux/clock_nanosleep.c
+++ b/sysdeps/unix/sysv/linux/clock_nanosleep.c
@@ -28,27 +28,13 @@ int
 __clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req,
 		   struct timespec *rem)
 {
-  INTERNAL_SYSCALL_DECL (err);
-  int r;
-
   if (clock_id == CLOCK_THREAD_CPUTIME_ID)
     return EINVAL;
   if (clock_id == CLOCK_PROCESS_CPUTIME_ID)
     clock_id = MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED);
 
-  if (SINGLE_THREAD_P)
-    r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, clock_id, flags, req, rem);
-  else
-    {
-      int oldstate = LIBC_CANCEL_ASYNC ();
-
-      r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, clock_id, flags, req,
-			    rem);
-
-      LIBC_CANCEL_RESET (oldstate);
-    }
-
-  return (INTERNAL_SYSCALL_ERROR_P (r, err)
-	  ? INTERNAL_SYSCALL_ERRNO (r, err) : 0);
+  /* If the call is interrupted by a signal handler or encounters an error,
+     it returns a positive value similar to errno.  */
+  return -SYSCALL_CANCEL_NCS (clock_nanosleep, clock_id, flags, req, rem);
 }
 weak_alias (__clock_nanosleep, clock_nanosleep)
diff --git a/sysdeps/unix/sysv/linux/futex-internal.h b/sysdeps/unix/sysv/linux/futex-internal.h
index 1386807..a73fec8 100644
--- a/sysdeps/unix/sysv/linux/futex-internal.h
+++ b/sysdeps/unix/sysv/linux/futex-internal.h
@@ -83,10 +83,7 @@ static __always_inline int
 futex_wait_cancelable (unsigned int *futex_word, unsigned int expected,
 		       int private)
 {
-  int oldtype;
-  oldtype = __pthread_enable_asynccancel ();
-  int err = lll_futex_timed_wait (futex_word, expected, NULL, private);
-  __pthread_disable_asynccancel (oldtype);
+  int err = lll_futex_timed_wait_cancel (futex_word, expected, NULL, private);
   switch (err)
     {
     case 0:
@@ -137,10 +134,7 @@ futex_reltimed_wait_cancelable (unsigned int *futex_word,
 				unsigned int expected,
 			        const struct timespec *reltime, int private)
 {
-  int oldtype;
-  oldtype = __pthread_enable_asynccancel ();
-  int err = lll_futex_timed_wait (futex_word, expected, reltime, private);
-  __pthread_disable_asynccancel (oldtype);
+  int err = lll_futex_timed_wait_cancel (futex_word, expected, reltime, private);
   switch (err)
     {
     case 0:
@@ -200,11 +194,9 @@ futex_abstimed_wait_cancelable (unsigned int *futex_word,
      despite them being valid.  */
   if (__glibc_unlikely ((abstime != NULL) && (abstime->tv_sec < 0)))
     return ETIMEDOUT;
-  int oldtype;
-  oldtype = __pthread_enable_asynccancel ();
-  int err = lll_futex_timed_wait_bitset (futex_word, expected, abstime,
-					 FUTEX_CLOCK_REALTIME, private);
-  __pthread_disable_asynccancel (oldtype);
+  int err = lll_futex_timed_wait_bitset_cancel (futex_word, expected, abstime,
+						FUTEX_CLOCK_REALTIME,
+						private);
   switch (err)
     {
     case 0:
diff --git a/sysdeps/unix/sysv/linux/lowlevellock-futex.h b/sysdeps/unix/sysv/linux/lowlevellock-futex.h
index bb4fbae..04085a5 100644
--- a/sysdeps/unix/sysv/linux/lowlevellock-futex.h
+++ b/sysdeps/unix/sysv/linux/lowlevellock-futex.h
@@ -140,6 +140,34 @@
 					 private),                      \
 		     nr_wake, nr_move, mutex, val)
 
-#endif  /* !__ASSEMBLER__  */
+/* Cancellable futex macros.  */
+#define lll_futex_wait_cancel(futexp, val, private) \
+  lll_futex_timed_wait_cancel (futexp, val, NULL, private)
+
+#define lll_futex_timed_wait_cancel(futexp, val, timespec, private)	      \
+  ({									      \
+    long int __ret;							      \
+    int __op = FUTEX_WAIT;						      \
+                                                                              \
+    __ret = __syscall_cancel (__NR_futex, __SSC (futexp),		      \
+			      __SSC (__lll_private_flag (__op, private)),     \
+			      __SSC (val), __SSC (timespec), 0, 0);           \
+    __ret;								      \
+  })
+
+#define lll_futex_timed_wait_bitset_cancel(futexp, val, timespec, clockbit,   \
+					   private)			      \
+  ({                                                                          \
+    long int __ret;                                                           \
+    int __op = FUTEX_WAIT_BITSET | clockbit;                                  \
+                                                                              \
+    __ret = __syscall_cancel (__NR_futex, __SSC (futexp),		      \
+			      __SSC (__lll_private_flag (__op, private)),     \
+			      __SSC (val), __SSC (timespec), 0,	              \
+                              FUTEX_BITSET_MATCH_ANY);                        \
+    __ret;								      \
+  })
+
+# endif  /* !__ASSEMBLER__  */
 
 #endif  /* lowlevellock-futex.h */
diff --git a/sysdeps/unix/sysv/linux/pthread_kill.c b/sysdeps/unix/sysv/linux/pthread_kill.c
index cd6f16e..01377b0 100644
--- a/sysdeps/unix/sysv/linux/pthread_kill.c
+++ b/sysdeps/unix/sysv/linux/pthread_kill.c
@@ -42,9 +42,8 @@ __pthread_kill (pthread_t threadid, int signo)
     /* Not a valid thread handle.  */
     return ESRCH;
 
-  /* Disallow sending the signal we use for cancellation, timers,
-     for the setxid implementation.  */
-  if (signo == SIGCANCEL || signo == SIGTIMER || signo == SIGSETXID)
+  /* Disallow sending the signal we use for setxid implementation.  */
+  if (signo == SIGSETXID)
     return EINVAL;
 
   /* We have a special syscall to do the work.  */
diff --git a/sysdeps/unix/sysv/linux/sigtimedwait.c b/sysdeps/unix/sysv/linux/sigtimedwait.c
index ab1a84e..9ba609d 100644
--- a/sysdeps/unix/sysv/linux/sigtimedwait.c
+++ b/sysdeps/unix/sysv/linux/sigtimedwait.c
@@ -49,9 +49,12 @@ __sigtimedwait (const sigset_t *set, siginfo_t *info,
     }
 #endif
 
-    /* XXX The size argument hopefully will have to be changed to the
-       real size of the user-level sigset_t.  */
-  int result = SYSCALL_CANCEL (rt_sigtimedwait, set, info, timeout, _NSIG / 8);
+  /* XXX The size argument hopefully will have to be changed to the
+     real size of the user-level sigset_t.  */
+  int result;
+  do
+    result = SYSCALL_CANCEL (rt_sigtimedwait, set, info, timeout, _NSIG / 8);
+  while (result < 0 && errno == EINTR);
 
   /* The kernel generates a SI_TKILL code in si_code in case tkill is
      used.  tkill is transparently used in raise().  Since having
@@ -62,7 +65,7 @@ __sigtimedwait (const sigset_t *set, siginfo_t *info,
 
   return result;
 }
-libc_hidden_def (__sigtimedwait)
+hidden_def (__sigtimedwait)
 weak_alias (__sigtimedwait, sigtimedwait)
 #else
 # include <signal/sigtimedwait.c>
diff --git a/sysdeps/unix/sysv/linux/sigwait.c b/sysdeps/unix/sysv/linux/sigwait.c
index 48bcd2f..08a422f 100644
--- a/sysdeps/unix/sysv/linux/sigwait.c
+++ b/sysdeps/unix/sysv/linux/sigwait.c
@@ -28,76 +28,14 @@
 #ifdef __NR_rt_sigtimedwait
 
 /* Return any pending signal or wait for one for the given time.  */
-static int
-do_sigwait (const sigset_t *set, int *sig)
-{
-  int ret;
-
-#ifdef SIGCANCEL
-  sigset_t tmpset;
-  if (set != NULL
-      && (__builtin_expect (__sigismember (set, SIGCANCEL), 0)
-# ifdef SIGSETXID
-	  || __builtin_expect (__sigismember (set, SIGSETXID), 0)
-# endif
-	  ))
-    {
-      /* Create a temporary mask without the bit for SIGCANCEL set.  */
-      // We are not copying more than we have to.
-      memcpy (&tmpset, set, _NSIG / 8);
-      __sigdelset (&tmpset, SIGCANCEL);
-# ifdef SIGSETXID
-      __sigdelset (&tmpset, SIGSETXID);
-# endif
-      set = &tmpset;
-    }
-#endif
-
-  /* XXX The size argument hopefully will have to be changed to the
-     real size of the user-level sigset_t.  */
-#ifdef INTERNAL_SYSCALL
-  INTERNAL_SYSCALL_DECL (err);
-  do
-    ret = INTERNAL_SYSCALL (rt_sigtimedwait, err, 4, set,
-			    NULL, NULL, _NSIG / 8);
-  while (INTERNAL_SYSCALL_ERROR_P (ret, err)
-	 && INTERNAL_SYSCALL_ERRNO (ret, err) == EINTR);
-  if (! INTERNAL_SYSCALL_ERROR_P (ret, err))
-    {
-      *sig = ret;
-      ret = 0;
-    }
-  else
-    ret = INTERNAL_SYSCALL_ERRNO (ret, err);
-#else
-  do
-    ret = INLINE_SYSCALL (rt_sigtimedwait, 4, set, NULL, NULL, _NSIG / 8);
-  while (ret == -1 && errno == EINTR);
-  if (ret != -1)
-    {
-      *sig = ret;
-      ret = 0;
-    }
-  else
-    ret = errno;
-#endif
-
-  return ret;
-}
-
 int
 __sigwait (const sigset_t *set, int *sig)
 {
-  if (SINGLE_THREAD_P)
-    return do_sigwait (set, sig);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = do_sigwait (set, sig);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  siginfo_t si;
+  if (__sigtimedwait (set, &si, NULL) < 0)
+    return -1;
+  *sig = si.si_signo;
+  return 0;
 }
 libc_hidden_def (__sigwait)
 weak_alias (__sigwait, sigwait)
diff --git a/sysdeps/unix/sysv/linux/socketcall.h b/sysdeps/unix/sysv/linux/socketcall.h
index 75f70d0..e5a3a7a 100644
--- a/sysdeps/unix/sysv/linux/socketcall.h
+++ b/sysdeps/unix/sysv/linux/socketcall.h
@@ -87,16 +87,39 @@
   })
 
 
-#if IS_IN (libc)
-# define __pthread_enable_asynccancel  __libc_enable_asynccancel
-# define __pthread_disable_asynccancel __libc_disable_asynccancel
-#endif
+#define __SOCKETCALL_CANCEL1(__name, __a1) \
+  SYSCALL_CANCEL_NCS (socketcall, __name, \
+     ((long int [1]) { (long int) __a1 }))
+#define __SOCKETCALL_CANCEL2(__name, __a1, __a2) \
+  SYSCALL_CANCEL_NCS (socketcall, __name, \
+     ((long int [2]) { (long int) __a1, (long int) __a2 }))
+#define __SOCKETCALL_CANCEL3(__name, __a1, __a2, __a3) \
+  SYSCALL_CANCEL_NCS (socketcall, __name, \
+     ((long int [3]) { (long int) __a1, (long int) __a2, (long int) __a3 }))
+#define __SOCKETCALL_CANCEL4(__name, __a1, __a2, __a3, __a4) \
+  SYSCALL_CANCEL_NCS (socketcall, __name, \
+     ((long int [4]) { (long int) __a1, (long int) __a2, (long int) __a3, \
+                       (long int) __a4 }))
+#define __SOCKETCALL_CANCEL5(__name, __a1, __a2, __a3, __a4, __a5) \
+  SYSCALL_CANCEL_NCS (socketcall, __name, \
+     ((long int [5]) { (long int) __a1, (long int) __a2, (long int) __a3, \
+                       (long int) __a4, (long int) __a5 }))
+#define __SOCKETCALL_CANCEL6(__name, __a1, __a2, __a3, __a4, __a5, __a6) \
+  SYSCALL_CANCEL_NCS (socketcall, __name, \
+     ((long int [6]) { (long int) __a1, (long int) __a2, (long int) __a3, \
+                       (long int) __a4, (long int) __a5, (long int) __a6 }))
+
+#define __SOCKETCALL_CANCEL(...) __SOCKETCALL_DISP (__SOCKETCALL_CANCEL,\
+						    __VA_ARGS__)
 
 #define SOCKETCALL_CANCEL(name, args...)				\
   ({									\
-    int oldtype = LIBC_CANCEL_ASYNC ();					\
-    long int sc_ret = __SOCKETCALL (SOCKOP_##name, args);		\
-    LIBC_CANCEL_RESET (oldtype);					\
+    long int sc_ret = __SOCKETCALL_CANCEL (SOCKOP_##name, args);	\
+    if (sc_ret > -4096UL)						\
+      {									\
+        __set_errno (-sc_ret);						\
+        sc_ret = -1L;							\
+      }									\
     sc_ret;								\
   })
 
diff --git a/sysdeps/unix/sysv/linux/syscall_cancel.c b/sysdeps/unix/sysv/linux/syscall_cancel.c
new file mode 100644
index 0000000..cb8f6ae
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/syscall_cancel.c
@@ -0,0 +1,59 @@
+/* Default cancellation syscall bridge.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+#include <pthreadP.h>
+
+#define ADD_LABEL(__label)		\
+  asm volatile (			\
+    ".global " __label "\t\n"		\
+    ".type " __label ",@function\t\n" 	\
+    __label ":\n");
+
+/* This is the generic version of the cancellable syscall code which
+   basically adds the label guards (__syscall_cancel_arch_{start,end}) used
+   on sigcancel_handler (nptl-init.c) to check if the cancelled syscalls
+   have side-effects that need to be signel to program.
+
+   An important contrainst should be observed when using this generic
+   implementation: the __syscall_cancel_arch_end should point to the
+   immediate next instruction after the syscall one.  This is because
+   will signal interrupted syscall with side effects by setting the
+   signal frame PC right after the syscall instruction.
+
+   If the INTERNAL_SYSCALL_NCS macro use more instruction to get the
+   erro condition from kernel (from instance on powerpc), one should
+   either adjust the macro or provide a custom implementation.   */
+long int
+__syscall_cancel_arch (volatile int *ch, __syscall_arg_t nr,
+		       __syscall_arg_t a1, __syscall_arg_t a2,
+		       __syscall_arg_t a3, __syscall_arg_t a4,
+		       __syscall_arg_t a5, __syscall_arg_t a6)
+{
+  ADD_LABEL ("__syscall_cancel_arch_start");
+  if (__glibc_unlikely (*ch & CANCELED_BITMASK))
+    __syscall_do_cancel();
+
+  INTERNAL_SYSCALL_DECL(err);
+  long int result = INTERNAL_SYSCALL_NCS (nr, err, 6, a1, a2, a3, a4, a5, a6);
+  ADD_LABEL ("__syscall_cancel_arch_end");
+  if (INTERNAL_SYSCALL_ERROR_P (result, err))
+    return -INTERNAL_SYSCALL_ERRNO (result, err);
+  return result;
+}
+libc_hidden_def (__syscall_cancel_arch)
diff --git a/sysdeps/unix/sysv/linux/sysdep.h b/sysdeps/unix/sysv/linux/sysdep.h
index ed1c807..a0c6189 100644
--- a/sysdeps/unix/sysv/linux/sysdep.h
+++ b/sysdeps/unix/sysv/linux/sysdep.h
@@ -27,6 +27,23 @@
     -1l;					\
   })
 
+/* Check error from cancellable syscall and set errno accordingly.
+   Linux uses a negative return value to indicate syscall errors
+   and since version 2.1 the return value of a system call might be
+   negative even if the call succeeded (e.g., the `lseek' system call
+   might return a large offset).
+   Current contract is kernel make sure the no syscall returns a value
+   in -1 .. -4095 as a valid result so we can savely test with -4095.  */
+#define SYSCALL_CANCEL_RET(__ret)		\
+  ({						\
+    if (__ret > -4096UL)			\
+      {						\
+	__set_errno (-__ret);			\
+	__ret = -1;				\
+      }						\
+    __ret;					\
+   })
+
 /* Provide a dummy argument that can be used to force register
    alignment for register pairs if required by the syscall ABI.  */
 #ifdef __ASSUME_ALIGNED_REGISTER_PAIRS

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=5c98e2e12480958eeefe2a2b8f06c5ecd1695cff

commit 5c98e2e12480958eeefe2a2b8f06c5ecd1695cff
Author: Adhemerval Zanella <adhemerval.zanella@linaro.com>
Date:   Mon Sep 21 15:55:58 2015 -0700

    nptl: Fix testcases for new pthread cancellation mechanism
    
    With upcoming fix for BZ#12683, pthread cancellation does not act for:
    
      1. If syscall is blocked but with some side effects already having
         taken place (e.g. a partial read or write).
      2. After the syscall has returned.
    
    It is because program need to act on such cases (for instance, to avoid
    leak of allocated resources or handle partial read/write).
    
    This patches fixes the NPTL testcase that assumes the old behavior and
    also remove the tst-cancel-wrappers.sh test (which checks for symbols
    that will not exist anymore).  For tst-cancel{2,3} case it remove the
    pipe close because it might cause the write syscall to return with
    side effects if the close is executed before the pthread cancel.
    
    It also changes how to call the read syscall on tst-backtrace{5,6}
    to use syscall instead of read cancelable syscall to avoid need to
    handle the cancelable bridge function calls.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* debug/tst-backtrace5.c (handle_signal): Check for syscall
    	instead of read.
    	(fn): Issue the read syscall instead of call the cancellable
    	syscall.
    	* nptl/Makefile [$(run-built-tests) = yes] (tests-special): Remove
    	tst-cancel-wrappers.sh.
    	* nptl/tst-cancel-wrappers.sh: Remove file.
    	* nptl/tst-cancel2.c (do_test): Do not close pipe.
    	* nptl/tst-cancel3.c (do_test): Likewise.
    	* nptl/tst-cancel4.c (tf_write): Handle cancelled syscall with
    	side-effects.
    	(tf_send): Likewise.

diff --git a/ChangeLog b/ChangeLog
index 6fdb604..c6ebf0b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* debug/tst-backtrace5.c (handle_signal): Check for syscall
+	instead of read.
+	(fn): Issue the read syscall instead of call the cancellable
+	syscall.
+	* nptl/Makefile [$(run-built-tests) = yes] (tests-special): Remove
+	tst-cancel-wrappers.sh.
+	* nptl/tst-cancel-wrappers.sh: Remove file.
+	* nptl/tst-cancel2.c (do_test): Do not close pipe.
+	* nptl/tst-cancel3.c (do_test): Likewise.
+	* nptl/tst-cancel4.c (tf_write): Handle cancelled syscall with
+	side-effects.
+	(tf_send): Likewise.
+
 	* sysdeps/unix/make-syscalls.sh: Remove cancellable tagging for
 	syscall definitions.
 	* sysdeps/unix/syscall-template.S (SYSCALL_CANCELLABLE): Remove
diff --git a/debug/tst-backtrace5.c b/debug/tst-backtrace5.c
index 0b85e44..0ef2627 100644
--- a/debug/tst-backtrace5.c
+++ b/debug/tst-backtrace5.c
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#include <sys/syscall.h>
 #include <signal.h>
 #include <unistd.h>
 
@@ -33,7 +34,7 @@
 #endif
 
 /* The backtrace should include at least handle_signal, a signal
-   trampoline, read, 3 * fn, and do_test.  */
+   trampoline, syscall, 3 * fn, and do_test.  */
 #define NUM_FUNCTIONS 7
 
 void
@@ -71,15 +72,17 @@ handle_signal (int signum)
     }
   /* Do not check name for signal trampoline.  */
   i = 2;
-  if (!match (symbols[i++], "read"))
+
+  if (match (symbols[i], "__kernel_vsyscall"))
+    i++;
+
+  /* We are using syscall(...) instead of read.  */
+  if (!match (symbols[i++], "syscall"))
     {
-      /* Perhaps symbols[2] is __kernel_vsyscall?  */
-      if (!match (symbols[i++], "read"))
-	{
-	  FAIL ();
-	  return;
-	}
+      FAIL ();
+      return;
     }
+
   for (; i < n - 1; i++)
     if (!match (symbols[i], "fn"))
       {
@@ -123,8 +126,11 @@ fn (int c, int flags)
       _exit (0);
     }
 
-  /* In the parent.  */
-  read (pipefd[0], r, 1);
+  /* To avoid need to handle cancellation syscall backtrace (which call
+     the function using both the generic bridge (__syscall_cancel) and
+     the architecture defined one (__syscall_cancel_arch), issue the
+     syscall directly.  */
+  syscall (__NR_read, pipefd[0], r, 1);
 
   return 0;
 }
diff --git a/nptl/Makefile b/nptl/Makefile
index e7961f1..bbf4c7b 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -440,8 +440,7 @@ tests-reverse += tst-cancel5 tst-cancel23 tst-vfork1x tst-vfork2x
 ifeq ($(run-built-tests),yes)
 tests-special += $(objpfx)tst-stack3-mem.out $(objpfx)tst-oddstacklimit.out
 ifeq ($(build-shared),yes)
-tests-special += $(objpfx)tst-tls6.out $(objpfx)tst-cleanup0-cmp.out \
-		 $(objpfx)tst-cancel-wrappers.out
+tests-special += $(objpfx)tst-tls6.out $(objpfx)tst-cleanup0-cmp.out
 endif
 endif
 
@@ -664,7 +663,7 @@ $(objpfx)$(multidir)/crtn.o: $(objpfx)crtn.o $(objpfx)$(multidir)/
 endif
 
 generated += libpthread_nonshared.a \
-	     multidir.mk tst-atfork2.mtrace tst-cancel-wrappers.out \
+	     multidir.mk tst-atfork2.mtrace \
 	     tst-tls6.out
 
 generated += $(objpfx)tst-atfork2.mtrace \
@@ -681,18 +680,6 @@ LDFLAGS-pthread.so += -e __nptl_main
 $(objpfx)pt-interp.os: $(common-objpfx)runtime-linker.h
 endif
 
-ifeq ($(run-built-tests),yes)
-ifeq (yes,$(build-shared))
-$(objpfx)tst-cancel-wrappers.out: tst-cancel-wrappers.sh
-	$(SHELL) $< '$(NM)' \
-		    $(common-objpfx)libc_pic.a \
-		    $(common-objpfx)libc.a \
-		    $(objpfx)libpthread_pic.a \
-		    $(objpfx)libpthread.a > $@; \
-	$(evaluate-test)
-endif
-endif
-
 tst-exec4-ARGS = $(host-test-program-cmd)
 
 $(objpfx)tst-execstack: $(libdl)
diff --git a/nptl/tst-cancel-wrappers.sh b/nptl/tst-cancel-wrappers.sh
deleted file mode 100644
index 1795e3d..0000000
--- a/nptl/tst-cancel-wrappers.sh
+++ /dev/null
@@ -1,92 +0,0 @@
-#!/bin/sh
-# Test whether all cancelable functions are cancelable.
-# Copyright (C) 2002-2017 Free Software Foundation, Inc.
-# This file is part of the GNU C Library.
-# Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
-
-# The GNU C Library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-
-# The GNU C Library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-
-# You should have received a copy of the GNU Lesser General Public
-# License along with the GNU C Library; if not, see
-# <http://www.gnu.org/licenses/>.
-
-NM="$1"; shift
-while [ $# -gt 0 ]; do
-  ( $NM -P $1; echo 'end[end]:' ) | gawk ' BEGIN {
-C["accept"]=1
-C["close"]=1
-C["connect"]=1
-C["creat"]=1
-C["fcntl"]=1
-C["fdatasync"]=1
-C["fsync"]=1
-C["msgrcv"]=1
-C["msgsnd"]=1
-C["msync"]=1
-C["nanosleep"]=1
-C["open"]=1
-C["open64"]=1
-C["pause"]=1
-C["poll"]=1
-C["pread"]=1
-C["pread64"]=1
-C["pselect"]=1
-C["pwrite"]=1
-C["pwrite64"]=1
-C["read"]=1
-C["readv"]=1
-C["recv"]=1
-C["recvfrom"]=1
-C["recvmsg"]=1
-C["select"]=1
-C["send"]=1
-C["sendmsg"]=1
-C["sendto"]=1
-C["sigpause"]=1
-C["sigsuspend"]=1
-C["sigwait"]=1
-C["sigwaitinfo"]=1
-C["tcdrain"]=1
-C["wait"]=1
-C["waitid"]=1
-C["waitpid"]=1
-C["write"]=1
-C["writev"]=1
-C["__xpg_sigpause"]=1
-}
-/:$/ {
-  if (seen)
-    {
-      if (!seen_enable || !seen_disable)
-	{
-	  printf "in '$1'(%s) %s'\''s cancellation missing\n", object, seen
-	  ret = 1
-	}
-    }
-  seen=""
-  seen_enable=""
-  seen_disable=""
-  object=gensub(/^.*\[(.*)\]:$/, "\\1", 1, $0)
-  next
-}
-{
-  if (C[$1] && $2 ~ /^[TW]$/)
-    seen=$1
-  else if ($1 ~ /^([.]|)__(libc|pthread)_enable_asynccancel$/ && $2 == "U")
-    seen_enable=1
-  else if ($1 ~ /^([.]|)__(libc|pthread)_disable_asynccancel$/ && $2 == "U")
-    seen_disable=1
-}
-END {
-  exit ret
-}' || exit
-  shift
-done
diff --git a/nptl/tst-cancel2.c b/nptl/tst-cancel2.c
index bf7946c..25a6143 100644
--- a/nptl/tst-cancel2.c
+++ b/nptl/tst-cancel2.c
@@ -73,9 +73,6 @@ do_test (void)
       return 1;
     }
 
-  /* This will cause the write in the child to return.  */
-  close (fd[0]);
-
   if (pthread_join (th, &r) != 0)
     {
       puts ("join failed");
diff --git a/nptl/tst-cancel3.c b/nptl/tst-cancel3.c
index 228c478..c462a7e 100644
--- a/nptl/tst-cancel3.c
+++ b/nptl/tst-cancel3.c
@@ -75,9 +75,6 @@ do_test (void)
       return 1;
     }
 
-  /* This will cause the read in the child to return.  */
-  close (fd[0]);
-
   if (pthread_join (th, &r) != 0)
     {
       puts ("join failed");
diff --git a/nptl/tst-cancel4.c b/nptl/tst-cancel4.c
index 62e2622..7270841 100644
--- a/nptl/tst-cancel4.c
+++ b/nptl/tst-cancel4.c
@@ -199,6 +199,10 @@ tf_write  (void *arg)
   char buf[WRITE_BUFFER_SIZE];
   memset (buf, '\0', sizeof (buf));
   s = write (fd, buf, sizeof (buf));
+  /* The write can return a value higher than 0 (meaning partial write)
+     due to the SIGCANCEL, but the thread may still be pending
+     cancellation.  */
+  pthread_testcancel ();
 
   pthread_cleanup_pop (0);
 
@@ -1089,6 +1093,10 @@ tf_send (void *arg)
   char mem[700000];
 
   send (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0);
+  /* Thez send can return a value higher than 0 (meaning partial send)
+     due to the SIGCANCEL, but the thread may still be pending
+     cancellation.  */
+  pthread_testcancel ();
 
   pthread_cleanup_pop (0);
 

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=f83b6bb41cfd1b6d4e7ad4806472f023fb3a62be

commit f83b6bb41cfd1b6d4e7ad4806472f023fb3a62be
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Thu Nov 12 14:01:36 2015 -0200

    Remove cancellation support for syscall generation
    
    This patch removes the cancellation mark from the auto-generation syscall
    script.  Now all the cancellable syscalls are done throught C code using
    the SYSCALL_CANCEL macro.  It simplifies the assembly required to each
    architecture port, since the SYSCALL_CANCEL uses the already defined
    INLINE_SYSCALL macros, and allows a more straigh fix on cancellation
    machanism (since no more specific assembly fixes will be required).
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* sysdeps/unix/make-syscalls.sh: Remove cancellable tagging for
    	syscall definitions.
    	* sysdeps/unix/syscall-template.S (SYSCALL_CANCELLABLE): Remove
    	definition.
    	* sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h (PSEUDO): Remove
    	definition.
    	(PSEUDO_END): Likewise.
    	[IS_IN (libpthread)] (CENABLE): Likewise.
    	[IS_IN (libpthread)] (CDISABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
    	* sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h (PSEUDO): Remove
    	definition.
    	(PSEUDO_END): Likewise.
    	[IS_IN (libpthread)] (__local_enable_asynccancel): Likewise.
    	[IS_IN (libpthread)] (__local_disable_asynccancel): Likewise.
    	[IS_IN (libc)] (__local_enable_asynccancel): Likewise.
    	[IS_IN (libc)] (__local_enable_asynccancel): Likewise.
    	[IS_IN (librt)] (__local_disable_asynccancel): Likewise.
    	[IS_IN (librt)] (__local_disable_asynccancel): Likewise.
    	(CENABLE): Likewise.
    	(CDISABLE): Likewise.
    	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
    	* sysdeps/unix/sysv/linux/arm/sysdep-cancel.h (PSEUDO): Remove
    	defintion.
    	(PSEUDO_END): Likewise.
    	[IS_IN (libpthread)] (CENABLE): Likewise.
    	[IS_IN (libpthread)] (CDISABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
    	* sysdeps/unix/sysv/linux/hppa/sysdep-cancel.h (PSEUDO): Remove
    	definition.
    	(PSEUDO_END): Likewise.
    	[IS_IN (libpthread)] (CENABLE): Likewise.
    	[IS_IN (libpthread)] (CDISABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
    	* sysdeps/unix/sysv/linux/i386/sysdep-cancel.h (PSEUDO): Remove
    	definition.
    	(PSEUDO_END): Likewise.
    	[IS_IN (libpthread)] (CENABLE): Likewise.
    	[IS_IN (libpthread)] (CDISABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
    	* sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h (PSEUDO): Remove
    	definition.
    	(PSEUDO_END): Likewise.
    	[IS_IN (libpthread)] (CENABLE): Likewise.
    	[IS_IN (libpthread)] (CDISABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
    	* sysdeps/unix/sysv/linux/m68k/sysdep-cancel.h (PSEUDO): Remove
    	definition.
    	(PSEUDO_END): Likewise.
    	[IS_IN (libpthread)] (CENABLE): Likewise.
    	[IS_IN (libpthread)] (CDISABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
    	* sysdeps/unix/sysv/linux/microblaze/sysdep-cancel.h (PSEUDO): Remove
    	definition.
    	(PSEUDO_END): Likewise.
    	[IS_IN (libpthread)] (CENABLE): Likewise.
    	[IS_IN (libpthread)] (CDISABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
    	* sysdeps/unix/sysv/linux/mips/mips64/sysdep-cancel.h (PSEUDO):
    	Remove definition.
    	(PSEUDO_END): Likewise.
    	[IS_IN (libpthread)] (CENABLE): Likewise.
    	[IS_IN (libpthread)] (CDISABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	(SINGLE_THREAD_P): Likewise.
    	* sysdeps/unix/sysv/linux/mips/sysdep-cancel.h (PSEUDO): Remove
    	definition.
    	(PSEUDO_END): Likewise.
    	[IS_IN (libpthread)] (CENABLE): Likewise.
    	[IS_IN (libpthread)] (CDISABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
    	* sysdeps/unix/sysv/linux/nios2/sysdep-cancel.h (PSEUDO): Remove
    	definition.
    	(PSEUDO_END): Likewise.
    	[IS_IN (libpthread)] (CENABLE): Likewise.
    	[IS_IN (libpthread)] (CDISABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
    	* sysdeps/sysv/linux/powerpc/powerpc32/sysdep-cancel.h: Remove file.
    	* sysdeps/sysv/linux/powerpc/powerpc64/sysdep-cancel.h: Likewise.
    	* sysdeps/unix/sysv/linux/powerpc/sysdep-cancel.h: New file.
    	* sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h (PSEUDO): Remove
    	definition.
    	(PSEUDO_END): Likewise.
    	[IS_IN (libpthread)] (CENABLE): Likewise.
    	[IS_IN (libpthread)] (CDISABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
    	* sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h (PSEUDO): Remove
    	definition.
    	(PSEUDO_END): Likewise.
    	[IS_IN (libpthread)] (CENABLE): Likewise.
    	[IS_IN (libpthread)] (CDISABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
    	* sysdeps/unix/sysv/linux/sh/sysdep-cancel.h (PSEUDO): Remove
    	definition.
    	(PSEUDO_END): Likewise.
    	[IS_IN (libpthread)] (CENABLE): Likewise.
    	[IS_IN (libpthread)] (CDISABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
    	* sysdeps/unix/sysv/linux/sparc/sparc32/sysdep-cancel.h: Remove file.
    	* sysdeps/unix/sysv/linux/sparc/sparc64/sysdep-cancel.h: Likewise.
    	* sysdeps/unix/sysv/linux/sparc/sysdep-cancel.h: New file.
    	* sysdeps/unix/sysv/linux/tile/sysdep-cancel.h (PSEUDO): Remove
    	definition.
    	(PSEUDO_END): Likewise.
    	[IS_IN (libpthread)] (CENABLE): Likewise.
    	[IS_IN (libpthread)] (CDISABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
    	* sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h (PSEUDO): Remove
    	definition.
    	(PSEUDO_END): Likewise.
    	[IS_IN (libpthread)] (CENABLE): Likewise.
    	[IS_IN (libpthread)] (CDISABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (libc)] (CENABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[IS_IN (librt)] (CDISABLE): Likewise.
    	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.

diff --git a/ChangeLog b/ChangeLog
index af4ceac..6fdb604 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,178 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/make-syscalls.sh: Remove cancellable tagging for
+	syscall definitions.
+	* sysdeps/unix/syscall-template.S (SYSCALL_CANCELLABLE): Remove
+	definition.
+	* sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h (PSEUDO): Remove
+	definition.
+	(PSEUDO_END): Likewise.
+	[IS_IN (libpthread)] (CENABLE): Likewise.
+	[IS_IN (libpthread)] (CDISABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
+	* sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h (PSEUDO): Remove
+	definition.
+	(PSEUDO_END): Likewise.
+	[IS_IN (libpthread)] (__local_enable_asynccancel): Likewise.
+	[IS_IN (libpthread)] (__local_disable_asynccancel): Likewise.
+	[IS_IN (libc)] (__local_enable_asynccancel): Likewise.
+	[IS_IN (libc)] (__local_enable_asynccancel): Likewise.
+	[IS_IN (librt)] (__local_disable_asynccancel): Likewise.
+	[IS_IN (librt)] (__local_disable_asynccancel): Likewise.
+	(CENABLE): Likewise.
+	(CDISABLE): Likewise.
+	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
+	* sysdeps/unix/sysv/linux/arm/sysdep-cancel.h (PSEUDO): Remove
+	defintion.
+	(PSEUDO_END): Likewise.
+	[IS_IN (libpthread)] (CENABLE): Likewise.
+	[IS_IN (libpthread)] (CDISABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
+	* sysdeps/unix/sysv/linux/hppa/sysdep-cancel.h (PSEUDO): Remove
+	definition.
+	(PSEUDO_END): Likewise.
+	[IS_IN (libpthread)] (CENABLE): Likewise.
+	[IS_IN (libpthread)] (CDISABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
+	* sysdeps/unix/sysv/linux/i386/sysdep-cancel.h (PSEUDO): Remove
+	definition.
+	(PSEUDO_END): Likewise.
+	[IS_IN (libpthread)] (CENABLE): Likewise.
+	[IS_IN (libpthread)] (CDISABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
+	* sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h (PSEUDO): Remove
+	definition.
+	(PSEUDO_END): Likewise.
+	[IS_IN (libpthread)] (CENABLE): Likewise.
+	[IS_IN (libpthread)] (CDISABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
+	* sysdeps/unix/sysv/linux/m68k/sysdep-cancel.h (PSEUDO): Remove
+	definition.
+	(PSEUDO_END): Likewise.
+	[IS_IN (libpthread)] (CENABLE): Likewise.
+	[IS_IN (libpthread)] (CDISABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
+	* sysdeps/unix/sysv/linux/microblaze/sysdep-cancel.h (PSEUDO): Remove
+	definition.
+	(PSEUDO_END): Likewise.
+	[IS_IN (libpthread)] (CENABLE): Likewise.
+	[IS_IN (libpthread)] (CDISABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
+	* sysdeps/unix/sysv/linux/mips/mips64/sysdep-cancel.h (PSEUDO):
+	Remove definition.
+	(PSEUDO_END): Likewise.
+	[IS_IN (libpthread)] (CENABLE): Likewise.
+	[IS_IN (libpthread)] (CDISABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	(SINGLE_THREAD_P): Likewise.
+	* sysdeps/unix/sysv/linux/mips/sysdep-cancel.h (PSEUDO): Remove
+	definition.
+	(PSEUDO_END): Likewise.
+	[IS_IN (libpthread)] (CENABLE): Likewise.
+	[IS_IN (libpthread)] (CDISABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
+	* sysdeps/unix/sysv/linux/nios2/sysdep-cancel.h (PSEUDO): Remove
+	definition.
+	(PSEUDO_END): Likewise.
+	[IS_IN (libpthread)] (CENABLE): Likewise.
+	[IS_IN (libpthread)] (CDISABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
+	* sysdeps/sysv/linux/powerpc/powerpc32/sysdep-cancel.h: Remove file.
+	* sysdeps/sysv/linux/powerpc/powerpc64/sysdep-cancel.h: Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/sysdep-cancel.h: New file.
+	* sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h (PSEUDO): Remove
+	definition.
+	(PSEUDO_END): Likewise.
+	[IS_IN (libpthread)] (CENABLE): Likewise.
+	[IS_IN (libpthread)] (CDISABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
+	* sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h (PSEUDO): Remove
+	definition.
+	(PSEUDO_END): Likewise.
+	[IS_IN (libpthread)] (CENABLE): Likewise.
+	[IS_IN (libpthread)] (CDISABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
+	* sysdeps/unix/sysv/linux/sh/sysdep-cancel.h (PSEUDO): Remove
+	definition.
+	(PSEUDO_END): Likewise.
+	[IS_IN (libpthread)] (CENABLE): Likewise.
+	[IS_IN (libpthread)] (CDISABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc32/sysdep-cancel.h: Remove file.
+	* sysdeps/unix/sysv/linux/sparc/sparc64/sysdep-cancel.h: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sysdep-cancel.h: New file.
+	* sysdeps/unix/sysv/linux/tile/sysdep-cancel.h (PSEUDO): Remove
+	definition.
+	(PSEUDO_END): Likewise.
+	[IS_IN (libpthread)] (CENABLE): Likewise.
+	[IS_IN (libpthread)] (CDISABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
+	* sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h (PSEUDO): Remove
+	definition.
+	(PSEUDO_END): Likewise.
+	[IS_IN (libpthread)] (CENABLE): Likewise.
+	[IS_IN (libpthread)] (CDISABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (libc)] (CENABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[IS_IN (librt)] (CDISABLE): Likewise.
+	[__ASSEMBLER__] (SINGLE_THREAD_P): Likewise.
+
 	* sysdeps/unix/sysv/linux/arm/setegid.c: Remove file.
 	* sysdeps/unix/sysv/linux/arm/seteuid.c: Likewise.
 	* sysdeps/unix/sysv/linux/arm/setgid.c: Likewise.
diff --git a/sysdeps/unix/make-syscalls.sh b/sysdeps/unix/make-syscalls.sh
index 123553c..042cfac 100644
--- a/sysdeps/unix/make-syscalls.sh
+++ b/sysdeps/unix/make-syscalls.sh
@@ -12,7 +12,6 @@
 #
 # Syscall Signature Prefixes:
 #
-# C: cancellable (i.e., this syscall is a cancellation point)
 # E: errno and return value are not set by the call
 # V: errno is not set, but errno or zero (success) is returned from the call
 #
@@ -171,11 +170,9 @@ while read file srcfile caller syscall args strong weak; do
   ;;
   esac
 
-  cancellable=0
   noerrno=0
   errval=0
   case $args in
-  C*) cancellable=1; args=`echo $args | sed 's/C:\?//'`;;
   E*) noerrno=1; args=`echo $args | sed 's/E:\?//'`;;
   V*) errval=1; args=`echo $args | sed 's/V:\?//'`;;
   esac
@@ -258,7 +255,6 @@ while read file srcfile caller syscall args strong weak; do
 	(echo '#define SYSCALL_NAME $syscall'; \\
 	 echo '#define SYSCALL_NARGS $nargs'; \\
 	 echo '#define SYSCALL_SYMBOL $strong'; \\
-	 echo '#define SYSCALL_CANCELLABLE $cancellable'; \\
 	 echo '#define SYSCALL_NOERRNO $noerrno'; \\
 	 echo '#define SYSCALL_ERRVAL $errval'; \\
 	 echo '#include <syscall-template.S>'; \\"
diff --git a/sysdeps/unix/syscall-template.S b/sysdeps/unix/syscall-template.S
index 4993ff5..d4584a9 100644
--- a/sysdeps/unix/syscall-template.S
+++ b/sysdeps/unix/syscall-template.S
@@ -27,7 +27,6 @@
 	SYSCALL_NAME		syscall name
 	SYSCALL_NARGS		number of arguments this call takes
 	SYSCALL_SYMBOL		primary symbol name
-	SYSCALL_CANCELLABLE	1 if the call is a cancelation point
 	SYSCALL_NOERRNO		1 to define a no-errno version (see below)
 	SYSCALL_ERRVAL		1 to define an error-value version (see below)
 
@@ -41,11 +40,7 @@
    instructions long and the untrained eye might not distinguish them from
    some compiled code that inexplicably lacks source line information.  */
 
-#if SYSCALL_CANCELLABLE
-# include <sysdep-cancel.h>
-#else
-# include <sysdep.h>
-#endif
+#include <sysdep.h>
 
 /* This indirection is needed so that SYMBOL gets macro-expanded.  */
 #define syscall_hidden_def(SYMBOL)		hidden_def (SYMBOL)
diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h b/sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h
index 4be2259..d39b6a2 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h
@@ -24,102 +24,23 @@
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
 
-# undef PSEUDO
-# define PSEUDO(name, syscall_name, args)				\
-	.section ".text";						\
-ENTRY (__##syscall_name##_nocancel);					\
-.Lpseudo_nocancel:							\
-	DO_CALL (syscall_name, args);					\
-.Lpseudo_finish:							\
-	cmn	x0, 4095;						\
-	b.cs	.Lsyscall_error;					\
-	.subsection 2;							\
-	.size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
-ENTRY (name);								\
-	SINGLE_THREAD_P(16);						\
-	cbz	w16, .Lpseudo_nocancel;					\
-	/* Setup common stack frame no matter the number of args.	\
-	   Also save the first arg, since it's basically free.  */	\
-	stp	x30, x0, [sp, -64]!;					\
-	cfi_adjust_cfa_offset (64);					\
-	cfi_rel_offset (x30, 0);					\
-	DOCARGS_##args;		/* save syscall args around CENABLE.  */ \
-	CENABLE;							\
-	mov	x16, x0;	/* save mask around syscall.  */	\
-	UNDOCARGS_##args;	/* restore syscall args.  */		\
-	DO_CALL (syscall_name, args);					\
-	str	x0, [sp, 8];	/* save result around CDISABLE.  */	\
-	mov	x0, x16;	/* restore mask for CDISABLE.  */	\
-	CDISABLE;							\
-	/* Break down the stack frame, restoring result at once.  */	\
-	ldp	x30, x0, [sp], 64;					\
-	cfi_adjust_cfa_offset (-64);					\
-	cfi_restore (x30);						\
-	b	.Lpseudo_finish;					\
-	cfi_endproc;							\
-	.size	name, .-name;						\
-	.previous
-
-# undef PSEUDO_END
-# define PSEUDO_END(name)						\
-	SYSCALL_ERROR_HANDLER;						\
-	cfi_endproc
-
-# define DOCARGS_0
-# define DOCARGS_1
-# define DOCARGS_2	str x1, [sp, 16]
-# define DOCARGS_3	stp x1, x2, [sp, 16]
-# define DOCARGS_4	DOCARGS_3; str x3, [sp, 32]
-# define DOCARGS_5	DOCARGS_3; stp x3, x4, [sp, 32]
-# define DOCARGS_6	DOCARGS_5; str x5, [sp, 48]
-
-# define UNDOCARGS_0
-# define UNDOCARGS_1	ldr x0, [sp, 8]
-# define UNDOCARGS_2	ldp x0, x1, [sp, 8]
-# define UNDOCARGS_3	UNDOCARGS_1; ldp x1, x2, [sp, 16]
-# define UNDOCARGS_4	UNDOCARGS_2; ldp x2, x3, [sp, 24]
-# define UNDOCARGS_5	UNDOCARGS_3; ldp x3, x4, [sp, 32]
-# define UNDOCARGS_6	UNDOCARGS_4; ldp x4, x5, [sp, 40]
-
 # if IS_IN (libpthread)
-#  define CENABLE	bl __pthread_enable_asynccancel
-#  define CDISABLE	bl __pthread_disable_asynccancel
 #  define __local_multiple_threads __pthread_multiple_threads
 # elif IS_IN (libc)
-#  define CENABLE	bl __libc_enable_asynccancel
-#  define CDISABLE	bl __libc_disable_asynccancel
 #  define __local_multiple_threads __libc_multiple_threads
-# elif IS_IN (librt)
-#  define CENABLE	bl __librt_enable_asynccancel
-#  define CDISABLE	bl __librt_disable_asynccancel
-# else
-#  error Unsupported library
 # endif
 
 # if IS_IN (libpthread) || IS_IN (libc)
-#  ifndef __ASSEMBLER__
 extern int __local_multiple_threads attribute_hidden;
-#   define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
-#  else
-#   define SINGLE_THREAD_P(R)						\
-	adrp	x##R, __local_multiple_threads;				\
-	ldr	w##R, [x##R, :lo12:__local_multiple_threads]
-#  endif
+#  define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
 # else
 /*  There is no __local_multiple_threads for librt, so use the TCB.  */
-#  ifndef __ASSEMBLER__
-#   define SINGLE_THREAD_P						\
+#  define SINGLE_THREAD_P						\
   __builtin_expect (THREAD_GETMEM (THREAD_SELF,				\
 				   header.multiple_threads) == 0, 1)
-#  else
-#   define SINGLE_THREAD_P(R)						\
-	mrs     x##R, tpidr_el0;					\
-	sub	x##R, x##R, PTHREAD_SIZEOF;				\
-	ldr	w##R, [x##R, PTHREAD_MULTIPLE_THREADS_OFFSET]
-#  endif
 # endif
 
-#elif !defined __ASSEMBLER__
+#else
 
 /* For rtld, et cetera.  */
 # define SINGLE_THREAD_P 1
@@ -127,8 +48,6 @@ extern int __local_multiple_threads attribute_hidden;
 
 #endif
 
-#ifndef __ASSEMBLER__
 # define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
-#endif
diff --git a/sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h b/sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h
index 66d6962..366cf31 100644
--- a/sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h
@@ -17,147 +17,24 @@
 
 #include <sysdep.h>
 #include <tls.h>
-#ifndef __ASSEMBLER__
-# include <nptl/pthreadP.h>
-#endif
+#include <nptl/pthreadP.h>
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
 
-/* ??? Assumes that nothing comes between PSEUDO and PSEUDO_END
-   besides "ret".  */
-
-# undef PSEUDO
-# define PSEUDO(name, syscall_name, args)			\
-	.globl	__##syscall_name##_nocancel;			\
-	.type	__##syscall_name##_nocancel, @function;		\
-	.usepv	__##syscall_name##_nocancel, std;		\
-	.align 4;						\
-	cfi_startproc;						\
-__LABEL(__##syscall_name##_nocancel)				\
-	ldgp	gp, 0(pv);					\
-	PSEUDO_PROF;						\
-__LABEL($pseudo_nocancel)					\
-	PSEUDO_PREPARE_ARGS;					\
-	lda	v0, SYS_ify(syscall_name);			\
-	call_pal PAL_callsys;					\
-	bne	a3, SYSCALL_ERROR_LABEL;			\
-__LABEL($pseudo_ret)						\
-	.subsection 2;						\
-	.size __##syscall_name##_nocancel, .-__##syscall_name##_nocancel; \
-	.globl	name;						\
-	.type	name, @function;				\
-	.usepv	name, std;					\
-	.align 4;						\
-	cfi_startproc;						\
-__LABEL(name)							\
-	ldgp	gp, 0(pv);					\
-	PSEUDO_PROF;						\
-	SINGLE_THREAD_P(t0);					\
-	beq	t0, $pseudo_nocancel;				\
-	subq	sp, 64, sp;					\
-	cfi_def_cfa_offset(64);					\
-	stq	ra, 0(sp);					\
-	cfi_offset(ra, -64);					\
-	SAVE_ARGS_##args;					\
-	CENABLE;						\
-	LOAD_ARGS_##args;					\
-	/* Save the CENABLE return value in RA.  That register	\
-	   is preserved across syscall and the real return 	\
-	   address is saved on the stack.  */			\
-	mov	v0, ra;						\
-	lda	v0, SYS_ify(syscall_name);			\
-	call_pal PAL_callsys;					\
-	stq	v0, 8(sp);					\
-	mov	ra, a0;						\
-	bne	a3, $multi_error;				\
-	CDISABLE;						\
-	ldq	ra, 0(sp);					\
-	ldq	v0, 8(sp);					\
-	addq	sp, 64, sp;					\
-	cfi_remember_state;					\
-	cfi_restore(ra);					\
-	cfi_def_cfa_offset(0);					\
-	ret;							\
-	cfi_restore_state;					\
-__LABEL($multi_error)						\
-	CDISABLE;						\
-	ldq	ra, 0(sp);					\
-	ldq	v0, 8(sp);					\
-	addq	sp, 64, sp;					\
-	cfi_restore(ra);					\
-	cfi_def_cfa_offset(0);					\
-	SYSCALL_ERROR_FALLTHRU;					\
-	SYSCALL_ERROR_HANDLER;					\
-	cfi_endproc;						\
-	.previous
-
-# undef PSEUDO_END
-# define PSEUDO_END(sym)					\
-	cfi_endproc;						\
-	.subsection 2;						\
-	.size sym, .-sym
-
-# define SAVE_ARGS_0	/* Nothing.  */
-# define SAVE_ARGS_1	SAVE_ARGS_0; stq a0, 8(sp)
-# define SAVE_ARGS_2	SAVE_ARGS_1; stq a1, 16(sp)
-# define SAVE_ARGS_3	SAVE_ARGS_2; stq a2, 24(sp)
-# define SAVE_ARGS_4	SAVE_ARGS_3; stq a3, 32(sp)
-# define SAVE_ARGS_5	SAVE_ARGS_4; stq a4, 40(sp)
-# define SAVE_ARGS_6	SAVE_ARGS_5; stq a5, 48(sp)
-
-# define LOAD_ARGS_0	/* Nothing.  */
-# define LOAD_ARGS_1	LOAD_ARGS_0; ldq a0, 8(sp)
-# define LOAD_ARGS_2	LOAD_ARGS_1; ldq a1, 16(sp)
-# define LOAD_ARGS_3	LOAD_ARGS_2; ldq a2, 24(sp)
-# define LOAD_ARGS_4	LOAD_ARGS_3; ldq a3, 32(sp)
-# define LOAD_ARGS_5	LOAD_ARGS_4; ldq a4, 40(sp)
-# define LOAD_ARGS_6	LOAD_ARGS_5; ldq a5, 48(sp)
-
 # if IS_IN (libpthread)
-#  define __local_enable_asynccancel	__pthread_enable_asynccancel
-#  define __local_disable_asynccancel	__pthread_disable_asynccancel
 #  define __local_multiple_threads	__pthread_multiple_threads
 # elif IS_IN (libc)
-#  define __local_enable_asynccancel	__libc_enable_asynccancel
-#  define __local_disable_asynccancel	__libc_disable_asynccancel
 #  define __local_multiple_threads	__libc_multiple_threads
-# elif IS_IN (librt)
-#  define __local_enable_asynccancel	__librt_enable_asynccancel
-#  define __local_disable_asynccancel	__librt_disable_asynccancel
-# else
-#  error Unsupported library
-# endif
-
-# ifdef PIC
-#  define CENABLE	bsr ra, __local_enable_asynccancel !samegp
-#  define CDISABLE	bsr ra, __local_disable_asynccancel !samegp
-# else
-#  define CENABLE	jsr ra, __local_enable_asynccancel; ldgp ra, 0(gp)
-#  define CDISABLE	jsr ra, __local_disable_asynccancel; ldgp ra, 0(gp)
 # endif
 
 # if IS_IN (libpthread) || IS_IN (libc)
-#  ifndef __ASSEMBLER__
 extern int __local_multiple_threads attribute_hidden;
-#   define SINGLE_THREAD_P \
+#  define SINGLE_THREAD_P \
 	__builtin_expect (__local_multiple_threads == 0, 1)
-#  elif defined(PIC)
-#   define SINGLE_THREAD_P(reg)  ldl reg, __local_multiple_threads(gp) !gprel
-#  else
-#   define SINGLE_THREAD_P(reg)					\
-	ldah	reg, __local_multiple_threads(gp) !gprelhigh;	\
-	ldl	reg, __local_multiple_threads(reg) !gprellow
-#  endif
 # else
-#  ifndef __ASSEMBLER__
-#   define SINGLE_THREAD_P \
+#  define SINGLE_THREAD_P \
 	__builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
-#  else
-#   define SINGLE_THREAD_P(reg)					\
-	call_pal PAL_rduniq;					\
-	ldl reg, MULTIPLE_THREADS_OFFSET($0)
-#  endif
 # endif
 
 #else
@@ -167,8 +44,6 @@ extern int __local_multiple_threads attribute_hidden;
 
 #endif
 
-#ifndef __ASSEMBLER__
 # define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
-#endif
diff --git a/sysdeps/unix/sysv/linux/arm/sysdep-cancel.h b/sysdeps/unix/sysv/linux/arm/sysdep-cancel.h
index de12acf..738e749 100644
--- a/sysdeps/unix/sysv/linux/arm/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/arm/sysdep-cancel.h
@@ -23,210 +23,23 @@
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
 
-/* NOTE: We do mark syscalls with unwind annotations, for the benefit of
-   cancellation; but they're really only accurate at the point of the
-   syscall.  The ARM unwind directives are not rich enough without adding
-   a custom personality function.  */
-
-# undef PSEUDO
-# define PSEUDO(name, syscall_name, args)				\
-	.text;								\
-  ENTRY (__##syscall_name##_nocancel);					\
-	CFI_SECTIONS;							\
-	DO_CALL (syscall_name, args);					\
-	cmn	r0, $4096;						\
-	PSEUDO_RET;							\
-  END (__##syscall_name##_nocancel);					\
-  ENTRY (name);								\
-	SINGLE_THREAD_P;						\
-	DOARGS_##args;							\
-	bne .Lpseudo_cancel;						\
-	cfi_remember_state;						\
-	ldr	r7, =SYS_ify (syscall_name);				\
-	swi	0x0;							\
-	UNDOARGS_##args;						\
-	cmn	r0, $4096;						\
-	PSEUDO_RET;							\
-	cfi_restore_state;						\
-  .Lpseudo_cancel:							\
-	.fnstart;	/* matched by the .fnend in UNDOARGS below.  */	\
-	DOCARGS_##args;	/* save syscall args etc. around CENABLE.  */	\
-	CENABLE;							\
-	mov ip, r0;		/* put mask in safe place.  */		\
-	UNDOCARGS_##args;	/* restore syscall args.  */		\
-	ldr	r7, =SYS_ify (syscall_name);				\
-	swi	0x0;		/* do the call.  */			\
-	mov	r7, r0;		/* save syscall return value.  */	\
-	mov	r0, ip;		/* get mask back.  */			\
-	CDISABLE;							\
-	mov	r0, r7;		/* retrieve return value.  */		\
-	RESTORE_LR_##args;						\
-	UNDOARGS_##args;						\
-	cmn	r0, $4096
-
-/* DOARGS pushes eight bytes on the stack for five arguments, twelve bytes for
-   six arguments, and four bytes for fewer.  In order to preserve doubleword
-   alignment, sometimes we must save an extra register.  */
-
-# define RESTART_UNWIND				\
-	.fnend;					\
-	.fnstart;				\
-	.save	{r7};				\
-	.save	{lr}
-
-# define DOCARGS_0				\
-	.save {r7};				\
-	push	{lr};				\
-	cfi_adjust_cfa_offset (4);		\
-	cfi_rel_offset (lr, 0);			\
-	.save	{lr}
-# define UNDOCARGS_0
-# define RESTORE_LR_0				\
-	pop	{lr};				\
-	cfi_adjust_cfa_offset (-4);		\
-	cfi_restore (lr)
-
-# define DOCARGS_1				\
-	.save	{r7};				\
-	push	{r0, r1, lr};			\
-	cfi_adjust_cfa_offset (12);		\
-	cfi_rel_offset (lr, 8);			\
-	.save	{lr};				\
-	.pad	#8
-# define UNDOCARGS_1				\
-	ldr r0, [sp], #8;			\
-	cfi_adjust_cfa_offset (-8);		\
-	RESTART_UNWIND
-# define RESTORE_LR_1				\
-	RESTORE_LR_0
-
-# define DOCARGS_2				\
-	.save	{r7};				\
-	push	{r0, r1, lr};			\
-	cfi_adjust_cfa_offset (12);		\
-	cfi_rel_offset (lr, 8);			\
-	.save	{lr};				\
-	.pad	#8
-# define UNDOCARGS_2				\
-	pop	{r0, r1};			\
-	cfi_adjust_cfa_offset (-8);		\
-	RESTART_UNWIND
-# define RESTORE_LR_2				\
-	RESTORE_LR_0
-
-# define DOCARGS_3				\
-	.save	{r7};				\
-	push	{r0, r1, r2, r3, lr};		\
-	cfi_adjust_cfa_offset (20);		\
-	cfi_rel_offset (lr, 16);		\
-	.save	{lr};				\
-	.pad	#16
-# define UNDOCARGS_3				\
-	pop	{r0, r1, r2, r3};		\
-	cfi_adjust_cfa_offset (-16);		\
-	RESTART_UNWIND
-# define RESTORE_LR_3				\
-	RESTORE_LR_0
-
-# define DOCARGS_4				\
-	.save	{r7};				\
-	push	{r0, r1, r2, r3, lr};		\
-	cfi_adjust_cfa_offset (20);		\
-	cfi_rel_offset (lr, 16);		\
-	.save	{lr};				\
-	.pad	#16
-# define UNDOCARGS_4				\
-	pop	{r0, r1, r2, r3};		\
-	cfi_adjust_cfa_offset (-16);		\
-	RESTART_UNWIND
-# define RESTORE_LR_4				\
-	RESTORE_LR_0
-
-/* r4 is only stmfd'ed for correct stack alignment.  */
-# define DOCARGS_5				\
-	.save	{r4, r7};			\
-	push	{r0, r1, r2, r3, r4, lr};	\
-	cfi_adjust_cfa_offset (24);		\
-	cfi_rel_offset (lr, 20);		\
-	.save	{lr};				\
-	.pad	#20
-# define UNDOCARGS_5				\
-	pop	{r0, r1, r2, r3};		\
-	cfi_adjust_cfa_offset (-16);		\
-	.fnend;					\
-	.fnstart;				\
-	.save	{r4, r7};			\
-	.save	{lr};				\
-	.pad	#4
-# define RESTORE_LR_5				\
-	pop	{r4, lr};			\
-	cfi_adjust_cfa_offset (-8);		\
-	/* r4 will be marked as restored later.  */ \
-	cfi_restore (lr)
-
-# define DOCARGS_6				\
-	.save	{r4, r5, r7};			\
-	push	{r0, r1, r2, r3, lr};		\
-	cfi_adjust_cfa_offset (20);		\
-	cfi_rel_offset (lr, 16);		\
-	.save	{lr};				\
-	.pad	#16
-# define UNDOCARGS_6				\
-	pop	{r0, r1, r2, r3};		\
-	cfi_adjust_cfa_offset (-16);		\
-	.fnend;					\
-	.fnstart;				\
-	.save	{r4, r5, r7};			\
-	.save	{lr};
-# define RESTORE_LR_6				\
-	RESTORE_LR_0
-
 # if IS_IN (libpthread)
-#  define CENABLE	bl PLTJMP(__pthread_enable_asynccancel)
-#  define CDISABLE	bl PLTJMP(__pthread_disable_asynccancel)
 #  define __local_multiple_threads __pthread_multiple_threads
 # elif IS_IN (libc)
-#  define CENABLE	bl PLTJMP(__libc_enable_asynccancel)
-#  define CDISABLE	bl PLTJMP(__libc_disable_asynccancel)
 #  define __local_multiple_threads __libc_multiple_threads
-# elif IS_IN (librt)
-#  define CENABLE	bl PLTJMP(__librt_enable_asynccancel)
-#  define CDISABLE	bl PLTJMP(__librt_disable_asynccancel)
-# else
-#  error Unsupported library
 # endif
 
 # if IS_IN (libpthread) || IS_IN (libc)
-#  ifndef __ASSEMBLER__
 extern int __local_multiple_threads attribute_hidden;
-#   define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
-#  else
-#   define SINGLE_THREAD_P						\
-	LDST_PCREL(ldr, ip, ip, __local_multiple_threads);		\
-	teq ip, #0
-#  endif
+#  define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
 # else
 /*  There is no __local_multiple_threads for librt, so use the TCB.  */
-#  ifndef __ASSEMBLER__
-#   define SINGLE_THREAD_P						\
+#  define SINGLE_THREAD_P						\
   __builtin_expect (THREAD_GETMEM (THREAD_SELF,				\
 				   header.multiple_threads) == 0, 1)
-#  else
-#   define SINGLE_THREAD_P						\
-	push	{r0, lr};						\
-	cfi_adjust_cfa_offset (8);					\
-	cfi_rel_offset (lr, 4);						\
-	GET_TLS (lr);							\
-	NEGOFF_ADJ_BASE (r0, MULTIPLE_THREADS_OFFSET);			\
-	ldr	ip, NEGOFF_OFF1 (r0, MULTIPLE_THREADS_OFFSET);		\
-	pop	{r0, lr};						\
-	cfi_adjust_cfa_offset (-8);					\
-	cfi_restore (lr);						\
-	teq	ip, #0
-#  endif
 # endif
 
-#elif !defined __ASSEMBLER__
+#else
 
 /* For rtld, et cetera.  */
 # define SINGLE_THREAD_P 1
@@ -234,8 +47,6 @@ extern int __local_multiple_threads attribute_hidden;
 
 #endif
 
-#ifndef __ASSEMBLER__
-# define RTLD_SINGLE_THREAD_P \
+#define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
-#endif
diff --git a/sysdeps/unix/sysv/linux/hppa/sysdep-cancel.h b/sysdeps/unix/sysv/linux/hppa/sysdep-cancel.h
index 5ea2972..a6189a7 100644
--- a/sysdeps/unix/sysv/linux/hppa/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/hppa/sysdep-cancel.h
@@ -23,226 +23,6 @@
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
 
-# ifndef NO_ERROR
-#  define NO_ERROR -0x1000
-# endif
-
-/* The syscall cancellation mechanism requires userspace
-   assistance, the following code does roughly this:
-
-	do arguments (read arg5 and arg6 to registers)
-	setup frame
-
-	check if there are threads, yes jump to pseudo_cancel
-
-	unthreaded:
-		syscall
-		check syscall return (jump to pre_end)
-		set errno
-		set return to -1
-		(jump to pre_end)
-
-	pseudo_cancel:
-		cenable
-		syscall
-		cdisable
-		check syscall return (jump to pre_end)
-		set errno
-		set return to -1
-
-	pre_end
-		restore stack
-
-	It is expected that 'ret' and 'END' macros will
-	append an 'undo arguments' and 'return' to the
-	this PSEUDO macro. */
-
-# undef PSEUDO
-# define PSEUDO(name, syscall_name, args)				\
-	ENTRY (__##syscall_name##_nocancel)				\
-	DOARGS_##args					ASM_LINE_SEP	\
-	stwm TREG, 64(%sp)				ASM_LINE_SEP	\
-	.cfi_offset TREG, 0				ASM_LINE_SEP	\
-	.cfi_adjust_cfa_offset 64			ASM_LINE_SEP	\
-	stw %sp, -4(%sp)				ASM_LINE_SEP	\
-	.cfi_offset 30, -4				ASM_LINE_SEP	\
-	stw %r19, -32(%sp)				ASM_LINE_SEP	\
-	.cfi_offset 19, -32				ASM_LINE_SEP	\
-	/* Save r19 */					ASM_LINE_SEP	\
-	SAVE_PIC(TREG)					ASM_LINE_SEP	\
-	/* Do syscall, delay loads # */			ASM_LINE_SEP	\
-	ble  0x100(%sr2,%r0)				ASM_LINE_SEP	\
-	ldi SYS_ify (syscall_name), %r20 /* delay */	ASM_LINE_SEP	\
-	ldi NO_ERROR,%r1				ASM_LINE_SEP	\
-	cmpb,>>=,n %r1,%ret0,L(pre_nc_end)		ASM_LINE_SEP	\
-	/* Restore r19 from TREG */			ASM_LINE_SEP	\
-	LOAD_PIC(TREG) /* delay */			ASM_LINE_SEP	\
-	SYSCALL_ERROR_HANDLER				ASM_LINE_SEP	\
-	/* Use TREG for temp storage */			ASM_LINE_SEP	\
-	copy %ret0, TREG /* delay */			ASM_LINE_SEP	\
-	/* OPTIMIZE: Don't reload r19 */		ASM_LINE_SEP	\
-	/* do a -1*syscall_ret0 */			ASM_LINE_SEP	\
-	sub %r0, TREG, TREG				ASM_LINE_SEP	\
-	/* Store into errno location */			ASM_LINE_SEP	\
-	stw TREG, 0(%sr0,%ret0)				ASM_LINE_SEP	\
-	/* return -1 as error */			ASM_LINE_SEP	\
-	ldi -1, %ret0					ASM_LINE_SEP	\
-L(pre_nc_end):						ASM_LINE_SEP	\
-	/* No need to LOAD_PIC */			ASM_LINE_SEP	\
-	/* Undo frame */				ASM_LINE_SEP	\
-	ldwm -64(%sp),TREG				ASM_LINE_SEP	\
-	.cfi_adjust_cfa_offset -64			ASM_LINE_SEP	\
-	/* Restore rp before exit */			ASM_LINE_SEP	\
-	ldw -20(%sp), %rp				ASM_LINE_SEP	\
-	.cfi_restore 2					ASM_LINE_SEP	\
-	ret						ASM_LINE_SEP	\
-	END(__##syscall_name##_nocancel)		ASM_LINE_SEP	\
-	/**********************************************/ASM_LINE_SEP	\
-	ENTRY (name)							\
-	DOARGS_##args					ASM_LINE_SEP	\
-	stwm TREG, 64(%sp)				ASM_LINE_SEP	\
-	.cfi_adjust_cfa_offset 64			ASM_LINE_SEP	\
-	stw %sp, -4(%sp)				ASM_LINE_SEP	\
-	.cfi_offset 30, -4				ASM_LINE_SEP	\
-	stw %r19, -32(%sp)				ASM_LINE_SEP	\
-	.cfi_offset 19, -32				ASM_LINE_SEP	\
-	/* Done setting up frame, continue... */	ASM_LINE_SEP	\
-	SINGLE_THREAD_P					ASM_LINE_SEP	\
-	cmpib,<>,n 0,%ret0,L(pseudo_cancel)		ASM_LINE_SEP	\
-L(unthreaded):						ASM_LINE_SEP	\
-	/* Save r19 */					ASM_LINE_SEP	\
-	SAVE_PIC(TREG)					ASM_LINE_SEP	\
-	/* Do syscall, delay loads # */			ASM_LINE_SEP	\
-	ble  0x100(%sr2,%r0)				ASM_LINE_SEP	\
-	ldi SYS_ify (syscall_name), %r20 /* delay */	ASM_LINE_SEP	\
-	ldi NO_ERROR,%r1				ASM_LINE_SEP	\
-	cmpb,>>=,n %r1,%ret0,L(pre_end)			ASM_LINE_SEP	\
-	/* Restore r19 from TREG */			ASM_LINE_SEP	\
-	LOAD_PIC(TREG) /* delay */			ASM_LINE_SEP	\
-	SYSCALL_ERROR_HANDLER				ASM_LINE_SEP	\
-	/* Use TREG for temp storage */			ASM_LINE_SEP	\
-	copy %ret0, TREG /* delay */			ASM_LINE_SEP	\
-	/* OPTIMIZE: Don't reload r19 */		ASM_LINE_SEP	\
-	/* do a -1*syscall_ret0 */			ASM_LINE_SEP	\
-	sub %r0, TREG, TREG				ASM_LINE_SEP	\
-	/* Store into errno location */			ASM_LINE_SEP	\
-	stw TREG, 0(%sr0,%ret0)				ASM_LINE_SEP	\
-	b L(pre_end)					ASM_LINE_SEP	\
-	/* return -1 as error */			ASM_LINE_SEP	\
-	ldi -1, %ret0 /* delay */			ASM_LINE_SEP	\
-L(pseudo_cancel):					ASM_LINE_SEP	\
-	PUSHARGS_##args /* Save args */			ASM_LINE_SEP	\
-	/* Save r19 into TREG */			ASM_LINE_SEP	\
-	CENABLE /* FUNC CALL */				ASM_LINE_SEP	\
-	SAVE_PIC(TREG) /* delay */			ASM_LINE_SEP	\
-	/* restore syscall args */			ASM_LINE_SEP	\
-	POPARGS_##args					ASM_LINE_SEP	\
-	/* save mask from cenable (use stub rp slot) */	ASM_LINE_SEP	\
-	stw %ret0, -24(%sp)				ASM_LINE_SEP	\
-	/* ... SYSCALL ... */				ASM_LINE_SEP	\
-	ble 0x100(%sr2,%r0)				ASM_LINE_SEP    \
-	ldi SYS_ify (syscall_name), %r20 /* delay */	ASM_LINE_SEP	\
-	/* ............... */				ASM_LINE_SEP	\
-	LOAD_PIC(TREG)					ASM_LINE_SEP	\
-	/* pass mask as arg0 to cdisable */		ASM_LINE_SEP	\
-	ldw -24(%sp), %r26				ASM_LINE_SEP	\
-	CDISABLE					ASM_LINE_SEP	\
-	stw %ret0, -24(%sp) /* delay */			ASM_LINE_SEP	\
-	/* Restore syscall return */			ASM_LINE_SEP	\
-	ldw -24(%sp), %ret0				ASM_LINE_SEP	\
-	/* compare error */				ASM_LINE_SEP	\
-	ldi NO_ERROR,%r1				ASM_LINE_SEP	\
-	/* branch if no error */			ASM_LINE_SEP	\
-	cmpb,>>=,n %r1,%ret0,L(pre_end)			ASM_LINE_SEP	\
-	LOAD_PIC(TREG)	/* cond. nullify */		ASM_LINE_SEP	\
-	copy %ret0, TREG /* save syscall return */	ASM_LINE_SEP	\
-	SYSCALL_ERROR_HANDLER				ASM_LINE_SEP	\
-	/* make syscall res value positive */		ASM_LINE_SEP	\
-	sub %r0, TREG, TREG	/* delay */		ASM_LINE_SEP	\
-	/* No need to LOAD_PIC */			ASM_LINE_SEP	\
-	/* store into errno location */			ASM_LINE_SEP	\
-	stw TREG, 0(%sr0,%ret0)				ASM_LINE_SEP	\
-	/* return -1 */					ASM_LINE_SEP	\
-	ldi -1, %ret0					ASM_LINE_SEP	\
-L(pre_end):						ASM_LINE_SEP	\
-	/* No need to LOAD_PIC */			ASM_LINE_SEP	\
-	/* Undo frame */				ASM_LINE_SEP	\
-	ldwm -64(%sp),TREG				ASM_LINE_SEP	\
-	.cfi_adjust_cfa_offset -64			ASM_LINE_SEP	\
-	/* Restore rp before exit */			ASM_LINE_SEP	\
-	ldw -20(%sp), %rp				ASM_LINE_SEP	\
-	.cfi_restore 2					ASM_LINE_SEP
-
-/* Save arguments into our frame */
-# define PUSHARGS_0	/* nothing to do */
-# define PUSHARGS_1	PUSHARGS_0 stw %r26, -36(%sr0,%sp)	ASM_LINE_SEP	\
-			.cfi_offset 26, -36			ASM_LINE_SEP
-# define PUSHARGS_2	PUSHARGS_1 stw %r25, -40(%sr0,%sp)	ASM_LINE_SEP	\
-			.cfi_offset 25, -40			ASM_LINE_SEP
-# define PUSHARGS_3	PUSHARGS_2 stw %r24, -44(%sr0,%sp)	ASM_LINE_SEP	\
-			.cfi_offset 24, -44			ASM_LINE_SEP
-# define PUSHARGS_4	PUSHARGS_3 stw %r23, -48(%sr0,%sp)	ASM_LINE_SEP	\
-			.cfi_offset 23, -48			ASM_LINE_SEP
-# define PUSHARGS_5	PUSHARGS_4 stw %r22, -52(%sr0,%sp)	ASM_LINE_SEP	\
-			.cfi_offset 22, -52			ASM_LINE_SEP
-# define PUSHARGS_6	PUSHARGS_5 stw %r21, -56(%sr0,%sp)	ASM_LINE_SEP	\
-			.cfi_offset 21, -56			ASM_LINE_SEP
-
-/* Bring them back from the stack */
-# define POPARGS_0	/* nothing to do */
-# define POPARGS_1	POPARGS_0 ldw -36(%sr0,%sp), %r26	ASM_LINE_SEP	\
-			.cfi_restore 26				ASM_LINE_SEP
-# define POPARGS_2	POPARGS_1 ldw -40(%sr0,%sp), %r25	ASM_LINE_SEP	\
-			.cfi_restore 25				ASM_LINE_SEP
-# define POPARGS_3	POPARGS_2 ldw -44(%sr0,%sp), %r24	ASM_LINE_SEP	\
-			.cfi_restore 24				ASM_LINE_SEP
-# define POPARGS_4	POPARGS_3 ldw -48(%sr0,%sp), %r23	ASM_LINE_SEP	\
-			.cfi_restore 23				ASM_LINE_SEP
-# define POPARGS_5	POPARGS_4 ldw -52(%sr0,%sp), %r22	ASM_LINE_SEP	\
-			.cfi_restore 22				ASM_LINE_SEP
-# define POPARGS_6	POPARGS_5 ldw -56(%sr0,%sp), %r21	ASM_LINE_SEP	\
-			.cfi_restore 21				ASM_LINE_SEP
-
-# if IS_IN (libpthread)
-#  ifdef PIC
-#   define CENABLE .import __pthread_enable_asynccancel,code ASM_LINE_SEP \
-			bl __pthread_enable_asynccancel,%r2 ASM_LINE_SEP
-#   define CDISABLE .import __pthread_disable_asynccancel,code ASM_LINE_SEP \
-			bl __pthread_disable_asynccancel,%r2 ASM_LINE_SEP
-#  else
-#   define CENABLE .import __pthread_enable_asynccancel,code ASM_LINE_SEP \
-			bl __pthread_enable_asynccancel,%r2 ASM_LINE_SEP
-#   define CDISABLE .import __pthread_disable_asynccancel,code ASM_LINE_SEP \
-			bl __pthread_disable_asynccancel,%r2 ASM_LINE_SEP
-#  endif
-# elif IS_IN (libc)
-#  ifdef PIC
-#   define CENABLE .import __libc_enable_asynccancel,code ASM_LINE_SEP \
-			bl __libc_enable_asynccancel,%r2 ASM_LINE_SEP
-#   define CDISABLE	.import __libc_disable_asynccancel,code ASM_LINE_SEP \
-			bl __libc_disable_asynccancel,%r2 ASM_LINE_SEP
-#  else
-#   define CENABLE .import __libc_enable_asynccancel,code ASM_LINE_SEP \
-			bl __libc_enable_asynccancel,%r2 ASM_LINE_SEP
-#   define CDISABLE	.import __libc_disable_asynccancel,code ASM_LINE_SEP \
-			bl __libc_disable_asynccancel,%r2 ASM_LINE_SEP
-#  endif
-# elif IS_IN (librt)
-#  ifdef PIC
-#   define CENABLE .import __librt_enable_asynccancel,code ASM_LINE_SEP \
-			bl __librt_enable_asynccancel,%r2 ASM_LINE_SEP
-#   define CDISABLE .import __librt_disable_asynccancel,code ASM_LINE_SEP \
-			bl __librt_disable_asynccancel,%r2 ASM_LINE_SEP
-#  else
-#   define CENABLE .import __librt_enable_asynccancel,code ASM_LINE_SEP \
-			bl __librt_enable_asynccancel,%r2 ASM_LINE_SEP
-#   define CDISABLE .import __librt_disable_asynccancel,code ASM_LINE_SEP \
-			bl __librt_disable_asynccancel,%r2 ASM_LINE_SEP
-#  endif
-# else
-#  error Unsupported library
-# endif
-
 # if IS_IN (libpthread)
 #  define __local_multiple_threads __pthread_multiple_threads
 # elif IS_IN (libc)
@@ -253,17 +33,11 @@ L(pre_end):						ASM_LINE_SEP	\
 #  error Unsupported library
 # endif
 
-# ifndef __ASSEMBLER__
-#  define SINGLE_THREAD_P \
+# define SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
-# else
-/* Read the value of header.multiple_threads from the thread pointer */
-#  define SINGLE_THREAD_P							\
-	mfctl %cr27, %ret0					ASM_LINE_SEP	\
-	ldw MULTIPLE_THREADS_THREAD_OFFSET(%sr0,%ret0),%ret0	ASM_LINE_SEP
-# endif
-#elif !defined __ASSEMBLER__
+
+#else
 
 /* This code should never be used but we define it anyhow.  */
 # define SINGLE_THREAD_P (1)
@@ -272,8 +46,6 @@ L(pre_end):						ASM_LINE_SEP	\
 #endif
 /* IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt) */
 
-#ifndef __ASSEMBLER__
-# define RTLD_SINGLE_THREAD_P \
+#define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
-#endif
diff --git a/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h b/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h
index ebf6019..34e2b6f 100644
--- a/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h
@@ -24,130 +24,17 @@
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
 
-# undef PSEUDO
-# define PSEUDO(name, syscall_name, args)				      \
-  .text;								      \
-  ENTRY (name)								      \
-    cmpl $0, %gs:MULTIPLE_THREADS_OFFSET;				      \
-    jne L(pseudo_cancel);						      \
-  .type __##syscall_name##_nocancel,@function;				      \
-  .globl __##syscall_name##_nocancel;					      \
-  __##syscall_name##_nocancel:						      \
-    DO_CALL (syscall_name, args);					      \
-    cmpl $-4095, %eax;							      \
-    jae SYSCALL_ERROR_LABEL;						      \
-    ret;								      \
-  .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel;	      \
-  L(pseudo_cancel):							      \
-    CENABLE								      \
-    SAVE_OLDTYPE_##args							      \
-    PUSHCARGS_##args							      \
-    DOCARGS_##args							      \
-    movl $SYS_ify (syscall_name), %eax;					      \
-    ENTER_KERNEL;							      \
-    POPCARGS_##args;							      \
-    POPSTATE_##args							      \
-    cmpl $-4095, %eax;							      \
-    jae SYSCALL_ERROR_LABEL
-
-# define SAVE_OLDTYPE_0	movl %eax, %ecx;
-# define SAVE_OLDTYPE_1	SAVE_OLDTYPE_0
-# define SAVE_OLDTYPE_2	pushl %eax; cfi_adjust_cfa_offset (4);
-# define SAVE_OLDTYPE_3	SAVE_OLDTYPE_2
-# define SAVE_OLDTYPE_4	SAVE_OLDTYPE_2
-# define SAVE_OLDTYPE_5	SAVE_OLDTYPE_2
-# define SAVE_OLDTYPE_6	SAVE_OLDTYPE_2
-
-# define PUSHCARGS_0	/* No arguments to push.  */
-# define DOCARGS_0	/* No arguments to frob.  */
-# define POPCARGS_0	/* No arguments to pop.  */
-# define _PUSHCARGS_0	/* No arguments to push.  */
-# define _POPCARGS_0	/* No arguments to pop.  */
-
-# define PUSHCARGS_1	movl %ebx, %edx; cfi_register (ebx, edx); PUSHCARGS_0
-# define DOCARGS_1	_DOARGS_1 (4)
-# define POPCARGS_1	POPCARGS_0; movl %edx, %ebx; cfi_restore (ebx);
-# define _PUSHCARGS_1	pushl %ebx; cfi_adjust_cfa_offset (4); \
-			cfi_rel_offset (ebx, 0); _PUSHCARGS_0
-# define _POPCARGS_1	_POPCARGS_0; popl %ebx; \
-			cfi_adjust_cfa_offset (-4); cfi_restore (ebx);
-
-# define PUSHCARGS_2	PUSHCARGS_1
-# define DOCARGS_2	_DOARGS_2 (12)
-# define POPCARGS_2	POPCARGS_1
-# define _PUSHCARGS_2	_PUSHCARGS_1
-# define _POPCARGS_2	_POPCARGS_1
-
-# define PUSHCARGS_3	_PUSHCARGS_2
-# define DOCARGS_3	_DOARGS_3 (20)
-# define POPCARGS_3	_POPCARGS_3
-# define _PUSHCARGS_3	_PUSHCARGS_2
-# define _POPCARGS_3	_POPCARGS_2
-
-# define PUSHCARGS_4	_PUSHCARGS_4
-# define DOCARGS_4	_DOARGS_4 (28)
-# define POPCARGS_4	_POPCARGS_4
-# define _PUSHCARGS_4	pushl %esi; cfi_adjust_cfa_offset (4); \
-			cfi_rel_offset (esi, 0); _PUSHCARGS_3
-# define _POPCARGS_4	_POPCARGS_3; popl %esi; \
-			cfi_adjust_cfa_offset (-4); cfi_restore (esi);
-
-# define PUSHCARGS_5	_PUSHCARGS_5
-# define DOCARGS_5	_DOARGS_5 (36)
-# define POPCARGS_5	_POPCARGS_5
-# define _PUSHCARGS_5	pushl %edi; cfi_adjust_cfa_offset (4); \
-			cfi_rel_offset (edi, 0); _PUSHCARGS_4
-# define _POPCARGS_5	_POPCARGS_4; popl %edi; \
-			cfi_adjust_cfa_offset (-4); cfi_restore (edi);
-
-# define PUSHCARGS_6	_PUSHCARGS_6
-# define DOCARGS_6	_DOARGS_6 (44)
-# define POPCARGS_6	_POPCARGS_6
-# define _PUSHCARGS_6	pushl %ebp; cfi_adjust_cfa_offset (4); \
-			cfi_rel_offset (ebp, 0); _PUSHCARGS_5
-# define _POPCARGS_6	_POPCARGS_5; popl %ebp; \
-			cfi_adjust_cfa_offset (-4); cfi_restore (ebp);
-
-# if IS_IN (libpthread)
-#  define CENABLE	call __pthread_enable_asynccancel;
-#  define CDISABLE	call __pthread_disable_asynccancel
-# elif IS_IN (libc)
-#  define CENABLE	call __libc_enable_asynccancel;
-#  define CDISABLE	call __libc_disable_asynccancel
-# elif IS_IN (librt)
-#  define CENABLE	call __librt_enable_asynccancel;
-#  define CDISABLE	call __librt_disable_asynccancel
-# else
-#  error Unsupported library
-# endif
-# define POPSTATE_0 \
- pushl %eax; cfi_adjust_cfa_offset (4); movl %ecx, %eax; \
- CDISABLE; popl %eax; cfi_adjust_cfa_offset (-4);
-# define POPSTATE_1	POPSTATE_0
-# define POPSTATE_2	xchgl (%esp), %eax; CDISABLE; popl %eax; \
-			cfi_adjust_cfa_offset (-4);
-# define POPSTATE_3	POPSTATE_2
-# define POPSTATE_4	POPSTATE_3
-# define POPSTATE_5	POPSTATE_4
-# define POPSTATE_6	POPSTATE_5
-
-# ifndef __ASSEMBLER__
-#  define SINGLE_THREAD_P \
+# define SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
-# else
-#  define SINGLE_THREAD_P cmpl $0, %gs:MULTIPLE_THREADS_OFFSET
-# endif
 
-#elif !defined __ASSEMBLER__
+#else
 
 # define SINGLE_THREAD_P (1)
 # define NO_CANCELLATION 1
 
 #endif
 
-#ifndef __ASSEMBLER__
-# define RTLD_SINGLE_THREAD_P \
+#define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
-#endif
diff --git a/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h b/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h
index 7c7f619..96d04de 100644
--- a/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h
@@ -23,201 +23,13 @@
 #endif
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
-
-# undef PSEUDO
-
-# if IS_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
-
-# ifndef USE_DL_SYSINFO
-
-#  define PSEUDO(name, syscall_name, args)				      \
-.text;									      \
-ENTRY (name)								      \
-     adds r14 = MULTIPLE_THREADS_OFFSET, r13;;				      \
-     ld4 r14 = [r14];							      \
-     mov r15 = SYS_ify(syscall_name);;					      \
-     cmp4.ne p6, p7 = 0, r14;						      \
-(p6) br.cond.spnt .Lpseudo_cancel;;					      \
-     break __BREAK_SYSCALL;;						      \
-     cmp.eq p6,p0=-1,r10;						      \
-(p6) br.cond.spnt.few __syscall_error;					      \
-     ret;;								      \
-     .endp name;							      \
-     .proc __GC_##name;							      \
-     .globl __GC_##name;						      \
-     .hidden __GC_##name;						      \
-__GC_##name:								      \
-.Lpseudo_cancel:							      \
-     .prologue;								      \
-     .regstk args, 5, args, 0;						      \
-     .save ar.pfs, loc0;						      \
-     alloc loc0 = ar.pfs, args, 5, args, 0;				      \
-     .save rp, loc1;							      \
-     mov loc1 = rp;;							      \
-     .body;								      \
-     CENABLE;;								      \
-     mov loc2 = r8;							      \
-     COPY_ARGS_##args							      \
-     mov r15 = SYS_ify(syscall_name);					      \
-     break __BREAK_SYSCALL;;						      \
-     mov loc3 = r8;							      \
-     mov loc4 = r10;							      \
-     mov out0 = loc2;							      \
-     CDISABLE;;								      \
-     cmp.eq p6,p0=-1,loc4;						      \
-(p6) br.cond.spnt.few __syscall_error_##args;				      \
-     mov r8 = loc3;							      \
-     mov rp = loc1;							      \
-     mov ar.pfs = loc0;							      \
-.Lpseudo_end:								      \
-     ret;								      \
-     .endp __GC_##name;							      \
-     SYSDEP_CANCEL_ERROR(args)
-
-# else /* USE_DL_SYSINFO */
-
-#  define PSEUDO(name, syscall_name, args)				      \
-.text;									      \
-ENTRY (name)								      \
-     .prologue;								      \
-     adds r2 = SYSINFO_OFFSET, r13;					      \
-     adds r14 = MULTIPLE_THREADS_OFFSET, r13;				      \
-     .save ar.pfs, r11;							      \
-     mov r11 = ar.pfs;;							      \
-     .body;								      \
-     ld4 r14 = [r14];							      \
-     ld8 r2 = [r2];							      \
-     mov r15 = SYS_ify(syscall_name);;					      \
-     cmp4.ne p6, p7 = 0, r14;						      \
-     mov b7 = r2;							      \
-(p6) br.cond.spnt .Lpseudo_cancel;					      \
-     br.call.sptk.many b6 = b7;;					      \
-     mov ar.pfs = r11;							      \
-     cmp.eq p6,p0 = -1, r10;						      \
-(p6) br.cond.spnt.few __syscall_error;					      \
-     ret;;								      \
-     .endp name;							      \
-									      \
-      .proc __##syscall_name##_nocancel;				      \
-     .globl __##syscall_name##_nocancel;				      \
-__##syscall_name##_nocancel:						      \
-     .prologue;								      \
-     adds r2 = SYSINFO_OFFSET, r13;					      \
-     .save ar.pfs, r11;							      \
-     mov r11 = ar.pfs;;							      \
-     .body;								      \
-     ld8 r2 = [r2];							      \
-     mov r15 = SYS_ify(syscall_name);;					      \
-     mov b7 = r2;							      \
-     br.call.sptk.many b6 = b7;;					      \
-     mov ar.pfs = r11;							      \
-     cmp.eq p6,p0 = -1, r10;						      \
-(p6) br.cond.spnt.few __syscall_error;					      \
-     ret;;								      \
-     .endp __##syscall_name##_nocancel;					      \
-									      \
-     .proc __GC_##name;							      \
-     .globl __GC_##name;						      \
-     .hidden __GC_##name;						      \
-__GC_##name:								      \
-.Lpseudo_cancel:							      \
-     .prologue;								      \
-     .regstk args, 5, args, 0;						      \
-     .save ar.pfs, loc0;						      \
-     alloc loc0 = ar.pfs, args, 5, args, 0;				      \
-     adds loc4 = SYSINFO_OFFSET, r13;					      \
-     .save rp, loc1;							      \
-     mov loc1 = rp;;							      \
-     .body;								      \
-     ld8 loc4 = [loc4];							      \
-     CENABLE;;								      \
-     mov loc2 = r8;							      \
-     mov b7 = loc4;							      \
-     COPY_ARGS_##args							      \
-     mov r15 = SYS_ify(syscall_name);					      \
-     br.call.sptk.many b6 = b7;;					      \
-     mov loc3 = r8;							      \
-     mov loc4 = r10;							      \
-     mov out0 = loc2;							      \
-     CDISABLE;;								      \
-     cmp.eq p6,p0=-1,loc4;						      \
-(p6) br.cond.spnt.few __syscall_error_##args;				      \
-     mov r8 = loc3;							      \
-     mov rp = loc1;							      \
-     mov ar.pfs = loc0;							      \
-.Lpseudo_end:								      \
-     ret;								      \
-     .endp __GC_##name;							      \
-     SYSDEP_CANCEL_ERROR(args)
-
-# endif /* USE_DL_SYSINFO */
-
-# undef PSEUDO_END
-# define PSEUDO_END(name) .endp
-
-# if IS_IN (libpthread)
-#  define CENABLE	br.call.sptk.many b0 = __pthread_enable_asynccancel
-#  define CDISABLE	br.call.sptk.many b0 = __pthread_disable_asynccancel
-# elif IS_IN (libc)
-#  define CENABLE	br.call.sptk.many b0 = __libc_enable_asynccancel
-#  define CDISABLE	br.call.sptk.many b0 = __libc_disable_asynccancel
-# elif IS_IN (librt)
-#  define CENABLE	br.call.sptk.many b0 = __librt_enable_asynccancel
-#  define CDISABLE	br.call.sptk.many b0 = __librt_disable_asynccancel
-# else
-#  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;
-
-# ifndef __ASSEMBLER__
-#  define SINGLE_THREAD_P \
+# define SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, header.multiple_threads) == 0, 1)
-# else
-#  define SINGLE_THREAD_P \
-  adds r14 = MULTIPLE_THREADS_OFFSET, r13 ;; ld4 r14 = [r14] ;; cmp4.ne p6, p7 = 0, r14
-# endif
-
-#elif !defined __ASSEMBLER__
-
+#else
 # define SINGLE_THREAD_P (1)
 # define NO_CANCELLATION 1
-
 #endif
 
-#ifndef __ASSEMBLER__
-# define RTLD_SINGLE_THREAD_P \
+#define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
-#endif
diff --git a/sysdeps/unix/sysv/linux/m68k/sysdep-cancel.h b/sysdeps/unix/sysv/linux/m68k/sysdep-cancel.h
index 9bc9e13..1603c5f 100644
--- a/sysdeps/unix/sysv/linux/m68k/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/m68k/sysdep-cancel.h
@@ -18,121 +18,21 @@
 
 #include <sysdep.h>
 #include <tls.h>
-#ifndef __ASSEMBLER__
-# include <nptl/pthreadP.h>
-#endif
+#include <nptl/pthreadP.h>
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
 
-# undef PSEUDO
-# define PSEUDO(name, syscall_name, args)				      \
-  .text;								      \
-  ENTRY (name)								      \
-    SINGLE_THREAD_P;							      \
-    jne .Lpseudo_cancel;						      \
-  .type __##syscall_name##_nocancel,@function;			              \
-  .globl __##syscall_name##_nocancel;				 	      \
-  __##syscall_name##_nocancel:					              \
-    DO_CALL (syscall_name, args);					      \
-    cmp.l &-4095, %d0;							      \
-    jcc SYSCALL_ERROR_LABEL;						      \
-    rts;								      \
-  .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel;	      \
-  .Lpseudo_cancel:							      \
-    CENABLE;								      \
-    DOCARGS_##args							      \
-    move.l %d0, -(%sp); /* Save result of CENABLE.  */  		      \
-    cfi_adjust_cfa_offset (4); \
-    move.l &SYS_ify (syscall_name), %d0;				      \
-    trap &0;								      \
-    move.l %d0, %d2;							      \
-    CDISABLE;								      \
-    addq.l &4, %sp; /* Remove result of CENABLE from the stack.  */           \
-    cfi_adjust_cfa_offset (-4); \
-    move.l %d2, %d0;							      \
-    UNDOCARGS_##args							      \
-    cmp.l &-4095, %d0;							      \
-    jcc SYSCALL_ERROR_LABEL
-
-/* Note: we use D2 to save syscall's return value as D0 will be clobbered in
-   CDISABLE.  */
-# define DOCARGS_0	move.l %d2, -(%sp);		\
-  cfi_adjust_cfa_offset (4); cfi_rel_offset (%d2, 0);
-# define UNDOCARGS_0	move.l (%sp)+, %d2;	\
-  cfi_adjust_cfa_offset (-4); cfi_restore (%d2);
-
-# define DOCARGS_1	_DOCARGS_1 (4); DOCARGS_0
-# define _DOCARGS_1(n)	move.l n(%sp), %d1;
-# define UNDOCARGS_1	UNDOCARGS_0
-
-# define DOCARGS_2	_DOCARGS_2 (8)
-# define _DOCARGS_2(n)	DOCARGS_0 move.l n+4(%sp), %d2; _DOCARGS_1 (n)
-# define UNDOCARGS_2	UNDOCARGS_0
-
-# define DOCARGS_3	_DOCARGS_3 (12)
-# define _DOCARGS_3(n)	move.l %d3, -(%sp);				\
-  cfi_adjust_cfa_offset (4); cfi_rel_offset (%d3, 0);			\
-  move.l n+4(%sp), %d3; _DOCARGS_2 (n)
-# define UNDOCARGS_3	UNDOCARGS_2 move.l (%sp)+, %d3;		\
-  cfi_adjust_cfa_offset (-4); cfi_restore (%d3);
-
-# define DOCARGS_4	_DOCARGS_4 (16)
-# define _DOCARGS_4(n)	move.l %d4, -(%sp);			\
-  cfi_adjust_cfa_offset (4); cfi_rel_offset (%d4, 0);		\
-  move.l n+4(%sp), %d4; _DOCARGS_3 (n)
-# define UNDOCARGS_4	UNDOCARGS_3 move.l (%sp)+, %d4;	\
-  cfi_adjust_cfa_offset (-4); cfi_restore (%d4);
-
-# define DOCARGS_5	_DOCARGS_5 (20)
-# define _DOCARGS_5(n)	move.l %d5, -(%sp);			\
-  cfi_adjust_cfa_offset (4); cfi_rel_offset (%d5, 0);		\
-  move.l n+4(%sp), %d5; _DOCARGS_4 (n)
-# define UNDOCARGS_5	UNDOCARGS_4 move.l (%sp)+, %d5; \
-  cfi_adjust_cfa_offset (-4); cfi_restore (%d5);
-
-# define DOCARGS_6	_DOCARGS_6 (24)
-# define _DOCARGS_6(n)	move.l n(%sp), %a0; _DOCARGS_5 (n-4)
-# define UNDOCARGS_6	UNDOCARGS_5
-
-# ifdef PIC
-#  define PSEUDO_JMP(sym) jbsr sym ## @PLTPC
-# else
-#  define PSEUDO_JMP(sym) jbsr sym
-# endif
-
-# if IS_IN (libpthread)
-#  define CENABLE	PSEUDO_JMP (__pthread_enable_asynccancel)
-#  define CDISABLE	PSEUDO_JMP (__pthread_disable_asynccancel)
-# elif IS_IN (libc)
-#  define CENABLE	PSEUDO_JMP (__libc_enable_asynccancel)
-#  define CDISABLE	PSEUDO_JMP (__libc_disable_asynccancel)
-# elif IS_IN (librt)
-#  define CENABLE	PSEUDO_JMP (__librt_enable_asynccancel)
-#  define CDISABLE	PSEUDO_JMP (__librt_disable_asynccancel)
-# else
-#  error Unsupported library
-# endif
-
-# ifndef __ASSEMBLER__
-#  define SINGLE_THREAD_P						\
+# define SINGLE_THREAD_P						\
   __builtin_expect (THREAD_GETMEM (THREAD_SELF,				\
 				   header.multiple_threads) == 0, 1)
-# else
-#  define SINGLE_THREAD_P			\
-  PSEUDO_JMP (__m68k_read_tp);		        \
-  tst.l MULTIPLE_THREADS_OFFSET(%a0)
-# endif
-
-#elif !defined __ASSEMBLER__
+#else
 
 # define SINGLE_THREAD_P (1)
 # define NO_CANCELLATION (1)
 
 #endif
 
-#ifndef __ASSEMBLER__
-# define RTLD_SINGLE_THREAD_P					  \
+#define RTLD_SINGLE_THREAD_P					  \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF,			  \
 				   header.multiple_threads) == 0, \
 		    1)
-#endif
diff --git a/sysdeps/unix/sysv/linux/microblaze/sysdep-cancel.h b/sysdeps/unix/sysv/linux/microblaze/sysdep-cancel.h
index dbcc2b2..7fe030b 100644
--- a/sysdeps/unix/sysv/linux/microblaze/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/microblaze/sysdep-cancel.h
@@ -23,136 +23,28 @@
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
 
-# if !IS_IN (librt) || !defined(PIC)
-#  define AC_STACK_SIZE  16  /* space for r15, async_cancel arg and 2 temp words */
-#  define AC_SET_GOT /* empty */
-#  define AC_RESTORE_GOT /* empty */
-# else
-#  define AC_STACK_SIZE  20  /* extra 4 bytes for r20 */
-#  define AC_SET_GOT                                                 \
-    swi   r20, r1, AC_STACK_SIZE-4;                                  \
-    mfs   r20, rpc;                                                  \
-    addik r20, r20, _GLOBAL_OFFSET_TABLE_+8;
-#  define AC_RESTORE_GOT                                             \
-    lwi   r20, r1, AC_STACK_SIZE-4;
-# endif
-
-# undef PSEUDO
-# define PSEUDO(name, syscall_name, args)                            \
-  .text;                                                             \
-  ENTRY (name)                                                       \
-    SINGLE_THREAD_P(r12);                                            \
-    bnei r12, L(pseudo_cancel);                                      \
-  .globl __##syscall_name##_nocancel;                                \
-  .type __##syscall_name##_nocancel,@function;                       \
-__##syscall_name##_nocancel:                                         \
-    DO_CALL (syscall_name, args);                                    \
-    addik r4, r0, -4095;                                             \
-    cmpu  r4, r4, r3;                                                \
-    bgei  r4, SYSCALL_ERROR_LABEL;                                   \
-    rtsd  r15, 8;                                                    \
-    nop;                                                             \
-  .size __##syscall_name##_nocancel, .-__##syscall_name##_nocancel;  \
-L(pseudo_cancel):                                                    \
-    addik r1, r1, -AC_STACK_SIZE;                                    \
-    swi   r15, r1, 0;                                                \
-    AC_SET_GOT                                                       \
-    DOCARGS_##args                                                   \
-    CENABLE;                                                         \
-    swi   r3, r1, 8;                                                 \
-    UNDOCARGS_##args                                                 \
-    DO_CALL (syscall_name, args);                                    \
-    swi   r3, r1, 12;                                                \
-    lwi   r5, r1, 8;                                                 \
-    CDISABLE;                                                        \
-    lwi   r3, r1, 12;                                                \
-    lwi   r15, r1, 0;                                                \
-    AC_RESTORE_GOT                                                   \
-    addik r1, r1, AC_STACK_SIZE;                                     \
-    addik r4, r0, -4095;                                             \
-    cmpu  r4, r4, r3;                                                \
-    bgei  r4, SYSCALL_ERROR_LABEL;                                   \
-    rtsd  r15, 8;                                                    \
-    nop;
-
-/*
- * Macros to save/restore syscall arguments across CENABLE
- * The arguments are saved into the caller's stack (original r1 + 4)
- */
-
-# define DOCARGS_0
-# define DOCARGS_1  swi   r5, r1, AC_STACK_SIZE + 4;
-# define DOCARGS_2  swi   r6, r1, AC_STACK_SIZE + 8; DOCARGS_1
-# define DOCARGS_3  swi   r7, r1, AC_STACK_SIZE + 12; DOCARGS_2
-# define DOCARGS_4  swi   r8, r1, AC_STACK_SIZE + 16; DOCARGS_3
-# define DOCARGS_5  swi   r9, r1, AC_STACK_SIZE + 20; DOCARGS_4
-# define DOCARGS_6  swi   r10, r1, AC_STACK_SIZE + 24; DOCARGS_5
-
-# define UNDOCARGS_0
-# define UNDOCARGS_1  lwi   r5, r1, AC_STACK_SIZE + 4;
-# define UNDOCARGS_2  UNDOCARGS_1 lwi   r6, r1, AC_STACK_SIZE + 8;
-# define UNDOCARGS_3  UNDOCARGS_2 lwi   r7, r1, AC_STACK_SIZE + 12;
-# define UNDOCARGS_4  UNDOCARGS_3 lwi   r8, r1, AC_STACK_SIZE + 16;
-# define UNDOCARGS_5  UNDOCARGS_4 lwi   r9, r1, AC_STACK_SIZE + 20;
-# define UNDOCARGS_6  UNDOCARGS_5 lwi   r10, r1, AC_STACK_SIZE + 24;
-
-# ifdef PIC
-#  define PSEUDO_JMP(sym)  brlid r15, sym##@PLTPC; addk r0, r0, r0
-# else
-#  define PSEUDO_JMP(sym)  brlid r15, sym; addk r0, r0, r0
-# endif
-
 # if IS_IN (libpthread)
-#  define CENABLE PSEUDO_JMP (__pthread_enable_asynccancel)
-#  define CDISABLE  PSEUDO_JMP (__pthread_disable_asynccancel)
 #  define __local_multiple_threads __pthread_multiple_threads
 # elif IS_IN (libc)
-#  define CENABLE PSEUDO_JMP (__libc_enable_asynccancel)
-#  define CDISABLE  PSEUDO_JMP (__libc_disable_asynccancel)
 #  define __local_multiple_threads __libc_multiple_threads
-# elif IS_IN (librt)
-#  define CENABLE PSEUDO_JMP (__librt_enable_asynccancel)
-#  define CDISABLE  PSEUDO_JMP (__librt_disable_asynccancel)
-# else
-#  error Unsupported library
 # endif
 
-
 # if IS_IN (libpthread) || IS_IN (libc)
-#  ifndef __ASSEMBLER__
 extern int __local_multiple_threads attribute_hidden;
-#   define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
-#  else
-#   if !defined PIC
-#    define SINGLE_THREAD_P(reg) lwi reg, r0, __local_multiple_threads;
-#   else
-#    define SINGLE_THREAD_P(reg)                                     \
-      mfs   reg, rpc;                                                \
-      addik reg, reg, _GLOBAL_OFFSET_TABLE_+8;                       \
-      lwi   reg, reg, __local_multiple_threads@GOT;                  \
-      lwi   reg, reg, 0;
-#   endif
-#  endif
+#  define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
 # else
-#  ifndef __ASSEMBLER__
-#   define SINGLE_THREAD_P                                           \
+#  define SINGLE_THREAD_P                                           \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF,                      \
                                    header.multiple_threads) == 0, 1)
-#  else
-#   define SINGLE_THREAD_P(reg)                                      \
-     lwi reg, r0, MULTIPLE_THREADS_OFFSET(reg)
-#  endif
 # endif
 
-#elif !defined __ASSEMBLER__
+#else
 
 # define SINGLE_THREAD_P (1)
 # define NO_CANCELLATION (1)
 
 #endif
 
-#ifndef __ASSEMBLER__
-# define RTLD_SINGLE_THREAD_P                                        \
+#define RTLD_SINGLE_THREAD_P                                        \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF,                      \
                                    header.multiple_threads) == 0, 1)
-#endif
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/sysdep-cancel.h b/sysdeps/unix/sysv/linux/mips/mips64/sysdep-cancel.h
deleted file mode 100644
index 0ed3e3d..0000000
--- a/sysdeps/unix/sysv/linux/mips/mips64/sysdep-cancel.h
+++ /dev/null
@@ -1,249 +0,0 @@
-/* Copyright (C) 2003-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library.  If not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <sysdep.h>
-#include <sysdeps/generic/sysdep.h>
-#include <tls.h>
-#ifndef __ASSEMBLER__
-# include <nptl/pthreadP.h>
-#endif
-#include <sys/asm.h>
-
-/* Gas will put the initial save of $gp into the CIE, because it appears to
-   happen before any instructions.  So we use cfi_same_value instead of
-   cfi_restore.  */
-
-#if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
-
-#ifdef __PIC__
-# undef PSEUDO
-# define PSEUDO(name, syscall_name, args)				      \
-      .align 2;								      \
-  L(pseudo_start):							      \
-      cfi_startproc;							      \
-      cfi_adjust_cfa_offset (STKSPACE);					      \
-      cfi_rel_offset (gp, STKOFF_GP);					      \
-  99: PTR_LA t9,__syscall_error;					      \
-      /* manual cpreturn */						      \
-      REG_L gp, STKOFF_GP(sp);						      \
-      cfi_same_value (gp);						      \
-      RESTORESTK;							      \
-      jr t9;								      \
-  .type __##syscall_name##_nocancel, @function;				      \
-  .globl __##syscall_name##_nocancel;					      \
-  __##syscall_name##_nocancel:						      \
-    SAVESTK;								      \
-    .cpsetup t9, STKOFF_GP, __##syscall_name##_nocancel;		      \
-    cfi_rel_offset (gp, STKOFF_GP);					      \
-    li v0, SYS_ify(syscall_name);					      \
-    syscall;								      \
-    bne a3, zero, SYSCALL_ERROR_LABEL;			       		      \
-    /* manual cpreturn */						      \
-    REG_L gp, STKOFF_GP(sp);						      \
-    cfi_same_value (gp);						      \
-    RESTORESTK;								      \
-    ret;								      \
-    cfi_endproc;							      \
-  .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel;	      \
-  ENTRY (name)								      \
-    SAVESTK;								      \
-    .cpsetup t9, STKOFF_GP, name;					      \
-    cfi_rel_offset (gp, STKOFF_GP);					      \
-    SINGLE_THREAD_P(v1);						      \
-    bne zero, v1, L(pseudo_cancel);					      \
-    .set noreorder;							      \
-    li v0, SYS_ify(syscall_name);					      \
-    syscall;								      \
-    .set reorder;							      \
-    bne a3, zero, SYSCALL_ERROR_LABEL;			       		      \
-    /* manual cpreturn */						      \
-    REG_L gp, STKOFF_GP(sp);						      \
-    cfi_same_value (gp);						      \
-    RESTORESTK;								      \
-    ret;								      \
-  L(pseudo_cancel):							      \
-    cfi_adjust_cfa_offset (STKSPACE);					      \
-    cfi_rel_offset (gp, STKOFF_GP);					      \
-    REG_S ra, STKOFF_RA(sp);						      \
-    cfi_rel_offset (ra, STKOFF_RA);					      \
-    PUSHARGS_##args;			/* save syscall args */	      	      \
-    CENABLE;								      \
-    REG_S v0, STKOFF_SVMSK(sp);		/* save mask */			      \
-    POPARGS_##args;			/* restore syscall args */	      \
-    .set noreorder;							      \
-    li v0, SYS_ify (syscall_name);				      	      \
-    syscall;								      \
-    .set reorder;							      \
-    REG_S v0, STKOFF_SC_V0(sp);		/* save syscall result */             \
-    REG_S a3, STKOFF_SC_ERR(sp);	/* save syscall error flag */	      \
-    REG_L a0, STKOFF_SVMSK(sp);		/* pass mask as arg1 */		      \
-    CDISABLE;								      \
-    REG_L a3, STKOFF_SC_ERR(sp);	/* restore syscall error flag */      \
-    REG_L ra, STKOFF_RA(sp);		/* restore return address */	      \
-    REG_L v0, STKOFF_SC_V0(sp);		/* restore syscall result */          \
-    bne a3, zero, SYSCALL_ERROR_LABEL;					      \
-    /* manual cpreturn */						      \
-    REG_L gp, STKOFF_GP(sp);						      \
-    cfi_same_value (gp);						      \
-    RESTORESTK;								      \
-  L(pseudo_end):
-#else
-# undef PSEUDO
-# define PSEUDO(name, syscall_name, args)				      \
-      .align 2;								      \
-  L(pseudo_start):							      \
-      cfi_startproc;							      \
-      cfi_adjust_cfa_offset (STKSPACE);					      \
-  99: RESTORESTK;							      \
-      j __syscall_error;						      \
-  .type __##syscall_name##_nocancel, @function;				      \
-  .globl __##syscall_name##_nocancel;					      \
-  __##syscall_name##_nocancel:						      \
-    SAVESTK;								      \
-    li v0, SYS_ify(syscall_name);					      \
-    syscall;								      \
-    bne a3, zero, SYSCALL_ERROR_LABEL;			       		      \
-    RESTORESTK;								      \
-    ret;								      \
-    cfi_endproc;							      \
-  .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel;	      \
-  ENTRY (name)								      \
-    SAVESTK;								      \
-    SINGLE_THREAD_P(v1);						      \
-    bne zero, v1, L(pseudo_cancel);					      \
-    .set noreorder;							      \
-    li v0, SYS_ify(syscall_name);					      \
-    syscall;								      \
-    .set reorder;							      \
-    bne a3, zero, SYSCALL_ERROR_LABEL;			       		      \
-    RESTORESTK;								      \
-    ret;								      \
-  L(pseudo_cancel):							      \
-    cfi_adjust_cfa_offset (STKSPACE);					      \
-    REG_S ra, STKOFF_RA(sp);						      \
-    cfi_rel_offset (ra, STKOFF_RA);					      \
-    PUSHARGS_##args;			/* save syscall args */	      	      \
-    CENABLE;								      \
-    REG_S v0, STKOFF_SVMSK(sp);		/* save mask */			      \
-    POPARGS_##args;			/* restore syscall args */	      \
-    .set noreorder;							      \
-    li v0, SYS_ify (syscall_name);				      	      \
-    syscall;								      \
-    .set reorder;							      \
-    REG_S v0, STKOFF_SC_V0(sp);		/* save syscall result */             \
-    REG_S a3, STKOFF_SC_ERR(sp);	/* save syscall error flag */	      \
-    REG_L a0, STKOFF_SVMSK(sp);		/* pass mask as arg1 */		      \
-    CDISABLE;								      \
-    REG_L a3, STKOFF_SC_ERR(sp);	/* restore syscall error flag */      \
-    REG_L ra, STKOFF_RA(sp);		/* restore return address */	      \
-    REG_L v0, STKOFF_SC_V0(sp);		/* restore syscall result */          \
-    bne a3, zero, SYSCALL_ERROR_LABEL;					      \
-    RESTORESTK;								      \
-  L(pseudo_end):
-#endif
-
-# undef PSEUDO_END
-# define PSEUDO_END(sym) cfi_endproc; .end sym; .size sym,.-sym
-
-# define PUSHARGS_0	/* nothing to do */
-# define PUSHARGS_1	PUSHARGS_0 REG_S a0, STKOFF_A0(sp); cfi_rel_offset (a0, STKOFF_A0);
-# define PUSHARGS_2	PUSHARGS_1 REG_S a1, STKOFF_A1(sp); cfi_rel_offset (a1, STKOFF_A1);
-# define PUSHARGS_3	PUSHARGS_2 REG_S a2, STKOFF_A2(sp); cfi_rel_offset (a2, STKOFF_A2);
-# define PUSHARGS_4	PUSHARGS_3 REG_S a3, STKOFF_A3(sp); cfi_rel_offset (a3, STKOFF_A3);
-# define PUSHARGS_5	PUSHARGS_4 REG_S a4, STKOFF_A4(sp); cfi_rel_offset (a3, STKOFF_A4);
-# define PUSHARGS_6	PUSHARGS_5 REG_S a5, STKOFF_A5(sp); cfi_rel_offset (a3, STKOFF_A5);
-
-# define POPARGS_0	/* nothing to do */
-# define POPARGS_1	POPARGS_0 REG_L a0, STKOFF_A0(sp);
-# define POPARGS_2	POPARGS_1 REG_L a1, STKOFF_A1(sp);
-# define POPARGS_3	POPARGS_2 REG_L a2, STKOFF_A2(sp);
-# define POPARGS_4	POPARGS_3 REG_L a3, STKOFF_A3(sp);
-# define POPARGS_5	POPARGS_4 REG_L a4, STKOFF_A4(sp);
-# define POPARGS_6	POPARGS_5 REG_L a5, STKOFF_A5(sp);
-
-/* Save an even number of slots.  Should be 0 if an even number of slots
-   are used below, or SZREG if an odd number are used.  */
-# ifdef __PIC__
-#  define STK_PAD	SZREG
-# else
-#  define STK_PAD	0
-# endif
-
-/* Place values that we are more likely to use later in this sequence, i.e.
-   closer to the SP at function entry.  If you do that, the are more
-   likely to already be in your d-cache.  */
-# define STKOFF_A5	(STK_PAD)
-# define STKOFF_A4	(STKOFF_A5 + SZREG)
-# define STKOFF_A3	(STKOFF_A4 + SZREG)
-# define STKOFF_A2	(STKOFF_A3 + SZREG)	/* MT and more args.  */
-# define STKOFF_A1	(STKOFF_A2 + SZREG)	/* MT and 2 args.  */
-# define STKOFF_A0	(STKOFF_A1 + SZREG)	/* MT and 1 arg.  */
-# define STKOFF_RA	(STKOFF_A0 + SZREG)	/* Used if MT.  */
-# define STKOFF_SC_V0	(STKOFF_RA + SZREG)	/* Used if MT.  */
-# define STKOFF_SC_ERR	(STKOFF_SC_V0 + SZREG)	/* Used if MT.  */
-# define STKOFF_SVMSK	(STKOFF_SC_ERR + SZREG)	/* Used if MT.  */
-
-# ifdef __PIC__
-#  define STKOFF_GP	(STKOFF_SVMSK + SZREG)	/* Always used.  */
-#  define STKSPACE	(STKOFF_GP + SZREG)
-# else
-#  define STKSPACE	(STKOFF_SVMSK + SZREG)
-# endif
-
-# define SAVESTK 	PTR_SUBU sp, STKSPACE; cfi_adjust_cfa_offset(STKSPACE)
-# define RESTORESTK 	PTR_ADDU sp, STKSPACE; cfi_adjust_cfa_offset(-STKSPACE)
-
-# ifdef __PIC__
-#  define PSEUDO_JMP(sym) PTR_LA t9, sym; jalr t9
-# else
-#  define PSEUDO_JMP(sym) jal sym
-# endif
-
-# if IS_IN (libpthread)
-#  define CENABLE	PSEUDO_JMP (__pthread_enable_asynccancel)
-#  define CDISABLE	PSEUDO_JMP (__pthread_disable_asynccancel)
-# elif IS_IN (librt)
-#  define CENABLE	PSEUDO_JMP (__librt_enable_asynccancel)
-#  define CDISABLE	PSEUDO_JMP (__librt_disable_asynccancel)
-# else
-#  define CENABLE	PSEUDO_JMP (__libc_enable_asynccancel)
-#  define CDISABLE	PSEUDO_JMP (__libc_disable_asynccancel)
-# endif
-
-# ifndef __ASSEMBLER__
-#  define SINGLE_THREAD_P						\
-	__builtin_expect (THREAD_GETMEM (THREAD_SELF,			\
-					 header.multiple_threads)	\
-			  == 0, 1)
-# else
-#  define SINGLE_THREAD_P(reg)						\
-	READ_THREAD_POINTER(reg);					\
-	lw reg, MULTIPLE_THREADS_OFFSET(reg)
-#endif
-
-#elif !defined __ASSEMBLER__
-
-# define SINGLE_THREAD_P 1
-# define NO_CANCELLATION 1
-
-#endif
-
-#ifndef __ASSEMBLER__
-# define RTLD_SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
-				   header.multiple_threads) == 0, 1)
-#endif
diff --git a/sysdeps/unix/sysv/linux/mips/sysdep-cancel.h b/sysdeps/unix/sysv/linux/mips/sysdep-cancel.h
index 0e45f00..fe9a3fc 100644
--- a/sysdeps/unix/sysv/linux/mips/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/mips/sysdep-cancel.h
@@ -18,173 +18,22 @@
 #include <sysdep.h>
 #include <sysdeps/generic/sysdep.h>
 #include <tls.h>
-#ifndef __ASSEMBLER__
-# include <nptl/pthreadP.h>
-#endif
+#include <nptl/pthreadP.h>
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
 
-# ifdef __PIC__
-#  define PSEUDO_CPLOAD .cpload t9;
-#  define PSEUDO_ERRJMP la t9, __syscall_error; jr t9;
-#  define PSEUDO_SAVEGP sw gp, 32(sp); cfi_rel_offset (gp, 32);
-#  define PSEUDO_LOADGP lw gp, 32(sp);
-# else
-#  define PSEUDO_CPLOAD
-#  define PSEUDO_ERRJMP j __syscall_error;
-#  define PSEUDO_SAVEGP
-#  define PSEUDO_LOADGP
-# endif
-
-# undef PSEUDO
-# define PSEUDO(name, syscall_name, args)				      \
-      .align 2;								      \
-      .set nomips16;							      \
-  L(pseudo_start):							      \
-      cfi_startproc;							      \
-  99: PSEUDO_ERRJMP							      \
-  .type __##syscall_name##_nocancel, @function;				      \
-  .globl __##syscall_name##_nocancel;					      \
-  __##syscall_name##_nocancel:						      \
-    .set noreorder;							      \
-    PSEUDO_CPLOAD							      \
-    li v0, SYS_ify(syscall_name);					      \
-    syscall;								      \
-    .set reorder;							      \
-    bne a3, zero, 99b;					       		      \
-    ret;								      \
-    cfi_endproc;							      \
-  .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel;	      \
-  ENTRY (name)								      \
-    .set noreorder;							      \
-    PSEUDO_CPLOAD							      \
-    .set reorder;							      \
-    SINGLE_THREAD_P(v1);						      \
-    bne zero, v1, L(pseudo_cancel);					      \
-    .set noreorder;							      \
-    li v0, SYS_ify(syscall_name);					      \
-    syscall;								      \
-    .set reorder;							      \
-    bne a3, zero, 99b;					       		      \
-    ret;								      \
-  L(pseudo_cancel):							      \
-    SAVESTK_##args;						              \
-    sw ra, 28(sp);							      \
-    cfi_rel_offset (ra, 28);						      \
-    PSEUDO_SAVEGP							      \
-    PUSHARGS_##args;			/* save syscall args */	      	      \
-    CENABLE;								      \
-    PSEUDO_LOADGP							      \
-    sw v0, 44(sp);			/* save mask */			      \
-    POPARGS_##args;			/* restore syscall args */	      \
-    .set noreorder;							      \
-    li v0, SYS_ify (syscall_name);				      	      \
-    syscall;								      \
-    .set reorder;							      \
-    sw v0, 36(sp);			/* save syscall result */             \
-    sw a3, 40(sp);			/* save syscall error flag */	      \
-    lw a0, 44(sp);			/* pass mask as arg1 */		      \
-    CDISABLE;								      \
-    PSEUDO_LOADGP							      \
-    lw v0, 36(sp);			/* restore syscall result */          \
-    lw a3, 40(sp);			/* restore syscall error flag */      \
-    lw ra, 28(sp);			/* restore return address */	      \
-    .set noreorder;							      \
-    bne a3, zero, 99b;							      \
-     RESTORESTK;						              \
-  L(pseudo_end):							      \
-    .set reorder;
-
-# undef PSEUDO_END
-# define PSEUDO_END(sym) cfi_endproc; .end sym; .size sym,.-sym
-
-# define PUSHARGS_0	/* nothing to do */
-# define PUSHARGS_1	PUSHARGS_0 sw a0, 0(sp); cfi_rel_offset (a0, 0);
-# define PUSHARGS_2	PUSHARGS_1 sw a1, 4(sp); cfi_rel_offset (a1, 4);
-# define PUSHARGS_3	PUSHARGS_2 sw a2, 8(sp); cfi_rel_offset (a2, 8);
-# define PUSHARGS_4	PUSHARGS_3 sw a3, 12(sp); cfi_rel_offset (a3, 12);
-# define PUSHARGS_5	PUSHARGS_4 /* handled by SAVESTK_## */
-# define PUSHARGS_6	PUSHARGS_5
-# define PUSHARGS_7	PUSHARGS_6
-
-# define POPARGS_0	/* nothing to do */
-# define POPARGS_1	POPARGS_0 lw a0, 0(sp);
-# define POPARGS_2	POPARGS_1 lw a1, 4(sp);
-# define POPARGS_3	POPARGS_2 lw a2, 8(sp);
-# define POPARGS_4	POPARGS_3 lw a3, 12(sp);
-# define POPARGS_5	POPARGS_4 /* args already in new stackframe */
-# define POPARGS_6	POPARGS_5
-# define POPARGS_7	POPARGS_6
-
-
-# define STKSPACE	48
-# define SAVESTK_0 	subu sp, STKSPACE; cfi_adjust_cfa_offset(STKSPACE)
-# define SAVESTK_1      SAVESTK_0
-# define SAVESTK_2      SAVESTK_1
-# define SAVESTK_3      SAVESTK_2
-# define SAVESTK_4      SAVESTK_3
-# define SAVESTK_5      lw t0, 16(sp);		\
-			SAVESTK_0;		\
-			sw t0, 16(sp)
-
-# define SAVESTK_6      lw t0, 16(sp);		\
-			lw t1, 20(sp);		\
-			SAVESTK_0;		\
-			sw t0, 16(sp);		\
-			sw t1, 20(sp)
-
-# define SAVESTK_7      lw t0, 16(sp);		\
-			lw t1, 20(sp);		\
-			lw t2, 24(sp);		\
-			SAVESTK_0;		\
-			sw t0, 16(sp);		\
-			sw t1, 20(sp);		\
-			sw t2, 24(sp)
-
-# define RESTORESTK 	addu sp, STKSPACE; cfi_adjust_cfa_offset(-STKSPACE)
-
-
-# ifdef __PIC__
-/* We use jalr rather than jal.  This means that the assembler will not
-   automatically restore $gp (in case libc has multiple GOTs) so we must
-   do it manually - which we have to do anyway since we don't use .cprestore.
-   It also shuts up the assembler warning about not using .cprestore.  */
-#  define PSEUDO_JMP(sym) la t9, sym; jalr t9;
-# else
-#  define PSEUDO_JMP(sym) jal sym;
-# endif
-
-# if IS_IN (libpthread)
-#  define CENABLE	PSEUDO_JMP (__pthread_enable_asynccancel)
-#  define CDISABLE	PSEUDO_JMP (__pthread_disable_asynccancel)
-# elif IS_IN (librt)
-#  define CENABLE	PSEUDO_JMP (__librt_enable_asynccancel)
-#  define CDISABLE	PSEUDO_JMP (__librt_disable_asynccancel)
-# else
-#  define CENABLE	PSEUDO_JMP (__libc_enable_asynccancel)
-#  define CDISABLE	PSEUDO_JMP (__libc_disable_asynccancel)
-# endif
-
-# ifndef __ASSEMBLER__
-#  define SINGLE_THREAD_P						\
+# define SINGLE_THREAD_P						\
 	__builtin_expect (THREAD_GETMEM (THREAD_SELF,			\
 					 header.multiple_threads)	\
 			  == 0, 1)
-# else
-#  define SINGLE_THREAD_P(reg)						\
-	READ_THREAD_POINTER(reg);					\
-	lw reg, MULTIPLE_THREADS_OFFSET(reg)
-#endif
 
-#elif !defined __ASSEMBLER__
+#else
 
 # define SINGLE_THREAD_P 1
 # define NO_CANCELLATION 1
 
 #endif
 
-#ifndef __ASSEMBLER__
-# define RTLD_SINGLE_THREAD_P \
+#define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
-#endif
diff --git a/sysdeps/unix/sysv/linux/nios2/sysdep-cancel.h b/sysdeps/unix/sysv/linux/nios2/sysdep-cancel.h
index 47b92d9..7647363 100644
--- a/sysdeps/unix/sysv/linux/nios2/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/nios2/sysdep-cancel.h
@@ -18,124 +18,22 @@
 
 #include <sysdep.h>
 #include <tls.h>
-#ifndef __ASSEMBLER__
-# include <nptl/pthreadP.h>
-#endif
+#include <nptl/pthreadP.h>
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
 
-# undef PSEUDO
-# define PSEUDO(name, syscall_name, args)				      \
-  .type __##syscall_name##_nocancel, @function;				      \
-  .globl __##syscall_name##_nocancel;					      \
-  __##syscall_name##_nocancel:						      \
-    cfi_startproc;                                                            \
-    DO_CALL (syscall_name, args);                                             \
-    bne r7, zero, SYSCALL_ERROR_LABEL;                                        \
-    ret;                                                                      \
-    cfi_endproc;                                                              \
-  .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel;	      \
-  ENTRY (name)								      \
-    SINGLE_THREAD_P(r2);						      \
-    bne r2, zero, pseudo_cancel;					      \
-    DO_CALL (syscall_name, args);					      \
-    bne r7, zero, SYSCALL_ERROR_LABEL;                                        \
-    ret;								      \
-  pseudo_cancel:							      \
-    SAVESTK_##args;                 /* save syscall args and adjust stack */  \
-    SAVEREG(ra, 0);                     /* save return address */             \
-    SAVEREG(r22, 4);                    /* save GOT pointer */                \
-    nextpc r22;                                                               \
-1:  movhi r2, %hiadj(_gp_got - 1b);					      \
-    addi r2, r2, %lo(_gp_got - 1b);					      \
-    add r22, r22, r2;                                                         \
-    CENABLE;                                                                  \
-    callr r3;                                                                 \
-    stw r2, 8(sp);                      /* save mask */                       \
-    LOADARGS_##args;                                                          \
-    movi r2, SYS_ify(syscall_name);                                           \
-    trap;                                                                     \
-    stw r2, 12(sp);                     /* save syscall result */             \
-    stw r7, 16(sp);                     /* save syscall error flag */         \
-    ldw r4, 8(sp);                      /* pass mask as argument 1 */         \
-    CDISABLE;                                                                 \
-    callr r3;                                                                 \
-    ldw r7, 16(sp);                     /* restore syscall error flag */      \
-    ldw r2, 12(sp);                     /* restore syscall result */          \
-    ldw ra, 0(sp);                      /* restore return address */          \
-    ldw r22, 4(sp);                     /* restore GOT pointer */             \
-    RESTORESTK_##args;                                                        \
-    bne r7, zero, SYSCALL_ERROR_LABEL;
-
-
-# undef PSEUDO_END
-# define PSEUDO_END(sym) \
-  SYSCALL_ERROR_HANDLER \
-  END (sym)
-
-#define SAVEREG(REG, LOC) stw REG, LOC(sp); cfi_rel_offset (REG, LOC)
-#define SAVESTK(X) subi sp, sp, X; cfi_adjust_cfa_offset(X)
-#define SAVESTK_0 SAVESTK(20)
-#define SAVEARG_1 SAVEREG(r4, 20)
-#define SAVESTK_1 SAVESTK(24); SAVEARG_1
-#define SAVEARG_2 SAVEREG(r5, 24); SAVEARG_1
-#define SAVESTK_2 SAVESTK(28); SAVEARG_2
-#define SAVEARG_3 SAVEREG(r6, 28); SAVEARG_2
-#define SAVESTK_3 SAVESTK(32); SAVEARG_3
-#define SAVEARG_4 SAVEREG(r7, 32); SAVEARG_3
-#define SAVESTK_4 SAVESTK(36); SAVEARG_4
-#define SAVESTK_5 SAVESTK_4
-#define SAVESTK_6 SAVESTK_5
-
-#define LOADARGS_0
-#define LOADARGS_1 ldw r4, 20(sp)
-#define LOADARGS_2 LOADARGS_1; ldw r5, 24(sp)
-#define LOADARGS_3 LOADARGS_2; ldw r6, 28(sp)
-#define LOADARGS_4 LOADARGS_3; ldw r7, 32(sp)
-#define LOADARGS_5 LOADARGS_4; ldw r8, 36(sp)
-#define LOADARGS_6 LOADARGS_5; ldw r9, 40(sp)
-
-#define RESTORESTK(X) addi sp, sp, X; cfi_adjust_cfa_offset(-X)
-#define RESTORESTK_0 RESTORESTK(20)
-#define RESTORESTK_1 RESTORESTK(24)
-#define RESTORESTK_2 RESTORESTK(28)
-#define RESTORESTK_3 RESTORESTK(32)
-#define RESTORESTK_4 RESTORESTK(36)
-#define RESTORESTK_5 RESTORESTK(36)
-#define RESTORESTK_6 RESTORESTK(36)
-
-# if IS_IN (libpthread)
-#  define CENABLE	ldw r3, %call(__pthread_enable_asynccancel)(r22)
-#  define CDISABLE	ldw r3, %call(__pthread_disable_asynccancel)(r22)
-# elif IS_IN (librt)
-#  define CENABLE	ldw r3, %call(__librt_enable_asynccancel)(r22)
-#  define CDISABLE	ldw r3, %call(__librt_disable_asynccancel)(r22)
-# elif IS_IN (libc)
-#  define CENABLE	ldw r3, %call(__libc_enable_asynccancel)(r22)
-#  define CDISABLE	ldw r3, %call(__libc_disable_asynccancel)(r22)
-# else
-#  error Unsupported library
-# endif
-
-# ifndef __ASSEMBLER__
-#  define SINGLE_THREAD_P						\
+# define SINGLE_THREAD_P						\
 	__builtin_expect (THREAD_GETMEM (THREAD_SELF,			\
 					 header.multiple_threads)	\
 			  == 0, 1)
-# else
-#  define SINGLE_THREAD_P(reg)						\
-	ldw reg, MULTIPLE_THREADS_OFFSET(r23)
-#endif
 
-#elif !defined __ASSEMBLER__
+#else
 
 # define SINGLE_THREAD_P 1
 # define NO_CANCELLATION 1
 
 #endif
 
-#ifndef __ASSEMBLER__
-# define RTLD_SINGLE_THREAD_P \
+#define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
-#endif
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h b/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h
deleted file mode 100644
index 35d3f05..0000000
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/* Cancellable system call stubs.  Linux/PowerPC version.
-   Copyright (C) 2003-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Franz Sirl <Franz.Sirl-kernel@lauterbach.com>, 2003.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <sysdep.h>
-#include <tls.h>
-#ifndef __ASSEMBLER__
-# include <nptl/pthreadP.h>
-#endif
-
-#if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
-
-# undef PSEUDO
-# define PSEUDO(name, syscall_name, args)				\
-  .section ".text";							\
-  ENTRY (name)								\
-    SINGLE_THREAD_P;							\
-    bne- .Lpseudo_cancel;						\
-  .type __##syscall_name##_nocancel,@function;				\
-  .globl __##syscall_name##_nocancel;					\
-  __##syscall_name##_nocancel:						\
-    DO_CALL (SYS_ify (syscall_name));					\
-    PSEUDO_RET;								\
-  .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel;	\
-  .Lpseudo_cancel:							\
-    stwu 1,-48(1);							\
-    cfi_adjust_cfa_offset (48);						\
-    mflr 9;								\
-    stw 9,52(1);							\
-    cfi_offset (lr, 4);							\
-    DOCARGS_##args;	/* save syscall args around CENABLE.  */	\
-    CENABLE;								\
-    stw 3,16(1);	/* store CENABLE return value (MASK).  */	\
-    UNDOCARGS_##args;	/* restore syscall args.  */			\
-    DO_CALL (SYS_ify (syscall_name));					\
-    mfcr 0;		/* save CR/R3 around CDISABLE.  */		\
-    stw 3,8(1);								\
-    stw 0,12(1);							\
-    lwz 3,16(1);	/* pass MASK to CDISABLE.  */			\
-    CDISABLE;								\
-    lwz 4,52(1);							\
-    lwz 0,12(1);	/* restore CR/R3. */				\
-    lwz 3,8(1);								\
-    mtlr 4;								\
-    mtcr 0;								\
-    addi 1,1,48;
-
-# define DOCARGS_0
-# define UNDOCARGS_0
-
-# define DOCARGS_1	stw 3,20(1); DOCARGS_0
-# define UNDOCARGS_1	lwz 3,20(1); UNDOCARGS_0
-
-# define DOCARGS_2	stw 4,24(1); DOCARGS_1
-# define UNDOCARGS_2	lwz 4,24(1); UNDOCARGS_1
-
-# define DOCARGS_3	stw 5,28(1); DOCARGS_2
-# define UNDOCARGS_3	lwz 5,28(1); UNDOCARGS_2
-
-# define DOCARGS_4	stw 6,32(1); DOCARGS_3
-# define UNDOCARGS_4	lwz 6,32(1); UNDOCARGS_3
-
-# define DOCARGS_5	stw 7,36(1); DOCARGS_4
-# define UNDOCARGS_5	lwz 7,36(1); UNDOCARGS_4
-
-# define DOCARGS_6	stw 8,40(1); DOCARGS_5
-# define UNDOCARGS_6	lwz 8,40(1); UNDOCARGS_5
-
-# if IS_IN (libpthread)
-#  define CENABLE	bl __pthread_enable_asynccancel@local
-#  define CDISABLE	bl __pthread_disable_asynccancel@local
-# elif IS_IN (libc)
-#  define CENABLE	bl __libc_enable_asynccancel@local
-#  define CDISABLE	bl __libc_disable_asynccancel@local
-# elif IS_IN (librt)
-#  define CENABLE	bl __librt_enable_asynccancel@local
-#  define CDISABLE	bl __librt_disable_asynccancel@local
-# else
-#  error Unsupported library
-# endif
-
-# ifndef __ASSEMBLER__
-#  define SINGLE_THREAD_P						\
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF,				\
-				   header.multiple_threads) == 0, 1)
-# else
-#  define SINGLE_THREAD_P						\
-  lwz 10,MULTIPLE_THREADS_OFFSET(2);					\
-  cmpwi 10,0
-# endif
-
-#elif !defined __ASSEMBLER__
-
-# define SINGLE_THREAD_P (1)
-# define NO_CANCELLATION 1
-
-#endif
-
-#ifndef __ASSEMBLER__
-# define RTLD_SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
-				   header.multiple_threads) == 0, 1)
-#endif
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h b/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h
deleted file mode 100644
index cad13da..0000000
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h
+++ /dev/null
@@ -1,147 +0,0 @@
-/* Cancellable system call stubs.  Linux/PowerPC64 version.
-   Copyright (C) 2003-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Franz Sirl <Franz.Sirl-kernel@lauterbach.com>, 2003.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <sysdep.h>
-#include <tls.h>
-#ifndef __ASSEMBLER__
-# include <nptl/pthreadP.h>
-#endif
-
-#if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
-
-# define DASHDASHPFX(str) __##str
-
-#if _CALL_ELF == 2
-#define CANCEL_FRAMESIZE (FRAME_MIN_SIZE+16+48)
-#define CANCEL_PARM_SAVE (FRAME_MIN_SIZE+16)
-#else
-#define CANCEL_FRAMESIZE (FRAME_MIN_SIZE+16)
-#define CANCEL_PARM_SAVE (CANCEL_FRAMESIZE+FRAME_PARM_SAVE)
-#endif
-
-# undef PSEUDO
-# define PSEUDO(name, syscall_name, args)				\
-  .section ".text";							\
-  ENTRY (name)								\
-    SINGLE_THREAD_P;							\
-    bne- .Lpseudo_cancel;						\
-  .type DASHDASHPFX(syscall_name##_nocancel),@function;			\
-  .globl DASHDASHPFX(syscall_name##_nocancel);				\
-  DASHDASHPFX(syscall_name##_nocancel):					\
-    DO_CALL (SYS_ify (syscall_name));					\
-    PSEUDO_RET;								\
-  .size DASHDASHPFX(syscall_name##_nocancel),.-DASHDASHPFX(syscall_name##_nocancel);	\
-  .Lpseudo_cancel:							\
-    stdu 1,-CANCEL_FRAMESIZE(1);					\
-    cfi_adjust_cfa_offset (CANCEL_FRAMESIZE);				\
-    mflr 9;								\
-    std  9,CANCEL_FRAMESIZE+FRAME_LR_SAVE(1);				\
-    cfi_offset (lr, FRAME_LR_SAVE);					\
-    DOCARGS_##args;	/* save syscall args around CENABLE.  */	\
-    CENABLE;								\
-    std  3,FRAME_MIN_SIZE(1); /* store CENABLE return value (MASK).  */	\
-    UNDOCARGS_##args;	/* restore syscall args.  */			\
-    DO_CALL (SYS_ify (syscall_name));					\
-    mfcr 0;		/* save CR/R3 around CDISABLE.  */		\
-    std  3,FRAME_MIN_SIZE+8(1);						\
-    std  0,CANCEL_FRAMESIZE+FRAME_CR_SAVE(1);				\
-    cfi_offset (cr, FRAME_CR_SAVE);					\
-    ld   3,FRAME_MIN_SIZE(1); /* pass MASK to CDISABLE.  */		\
-    CDISABLE;								\
-    ld   9,CANCEL_FRAMESIZE+FRAME_LR_SAVE(1);				\
-    ld   0,CANCEL_FRAMESIZE+FRAME_CR_SAVE(1); /* restore CR/R3. */	\
-    ld   3,FRAME_MIN_SIZE+8(1);						\
-    mtlr 9;								\
-    mtcr 0;								\
-    addi 1,1,CANCEL_FRAMESIZE;						\
-    cfi_adjust_cfa_offset (-CANCEL_FRAMESIZE);				\
-    cfi_restore (lr);							\
-    cfi_restore (cr)
-
-# define DOCARGS_0
-# define UNDOCARGS_0
-
-# define DOCARGS_1	std 3,CANCEL_PARM_SAVE(1); DOCARGS_0
-# define UNDOCARGS_1	ld 3,CANCEL_PARM_SAVE(1); UNDOCARGS_0
-
-# define DOCARGS_2	std 4,CANCEL_PARM_SAVE+8(1); DOCARGS_1
-# define UNDOCARGS_2	ld 4,CANCEL_PARM_SAVE+8(1); UNDOCARGS_1
-
-# define DOCARGS_3	std 5,CANCEL_PARM_SAVE+16(1); DOCARGS_2
-# define UNDOCARGS_3	ld 5,CANCEL_PARM_SAVE+16(1); UNDOCARGS_2
-
-# define DOCARGS_4	std 6,CANCEL_PARM_SAVE+24(1); DOCARGS_3
-# define UNDOCARGS_4	ld 6,CANCEL_PARM_SAVE+24(1); UNDOCARGS_3
-
-# define DOCARGS_5	std 7,CANCEL_PARM_SAVE+32(1); DOCARGS_4
-# define UNDOCARGS_5	ld 7,CANCEL_PARM_SAVE+32(1); UNDOCARGS_4
-
-# define DOCARGS_6	std 8,CANCEL_PARM_SAVE+40(1); DOCARGS_5
-# define UNDOCARGS_6	ld 8,CANCEL_PARM_SAVE+40(1); UNDOCARGS_5
-
-# if IS_IN (libpthread)
-#  ifdef SHARED
-#   define CENABLE	bl JUMPTARGET(__pthread_enable_asynccancel)
-#   define CDISABLE	bl JUMPTARGET(__pthread_disable_asynccancel)
-#  else
-#   define CENABLE	bl JUMPTARGET(__pthread_enable_asynccancel); nop
-#   define CDISABLE	bl JUMPTARGET(__pthread_disable_asynccancel); nop
-#  endif
-# elif IS_IN (libc)
-#  ifdef SHARED
-#   define CENABLE	bl JUMPTARGET(__libc_enable_asynccancel)
-#   define CDISABLE	bl JUMPTARGET(__libc_disable_asynccancel)
-#  else
-#   define CENABLE	bl JUMPTARGET(__libc_enable_asynccancel); nop
-#   define CDISABLE	bl JUMPTARGET(__libc_disable_asynccancel); nop
-#  endif
-# elif IS_IN (librt)
-#  ifdef SHARED
-#   define CENABLE	bl JUMPTARGET(__librt_enable_asynccancel)
-#   define CDISABLE	bl JUMPTARGET(__librt_disable_asynccancel)
-#  else
-#   define CENABLE	bl JUMPTARGET(__librt_enable_asynccancel); nop
-#   define CDISABLE	bl JUMPTARGET(__librt_disable_asynccancel); nop
-#  endif
-# else
-#  error Unsupported library
-# endif
-
-# ifndef __ASSEMBLER__
-#  define SINGLE_THREAD_P						\
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF,				\
-				   header.multiple_threads) == 0, 1)
-# else
-#   define SINGLE_THREAD_P						\
-  lwz   10,MULTIPLE_THREADS_OFFSET(13);				\
-  cmpwi 10,0
-# endif
-
-#elif !defined __ASSEMBLER__
-
-# define SINGLE_THREAD_P (1)
-# define NO_CANCELLATION 1
-
-#endif
-
-#ifndef __ASSEMBLER__
-# define RTLD_SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
-				   header.multiple_threads) == 0, 1)
-#endif
diff --git a/sysdeps/unix/sysv/linux/powerpc/sysdep-cancel.h b/sysdeps/unix/sysv/linux/powerpc/sysdep-cancel.h
new file mode 100644
index 0000000..85af880
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/powerpc/sysdep-cancel.h
@@ -0,0 +1,38 @@
+/* Cancellable system call stubs.  Linux/PowerPC version.
+   Copyright (C) 2015 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+#include <tls.h>
+#include <nptl/pthreadP.h>
+
+#if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
+
+# define SINGLE_THREAD_P						\
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF,				\
+				   header.multiple_threads) == 0, 1)
+
+#else
+
+# define SINGLE_THREAD_P (1)
+# define NO_CANCELLATION 1
+
+#endif
+
+#define RTLD_SINGLE_THREAD_P \
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+				   header.multiple_threads) == 0, 1)
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h b/sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h
index b1e80bc..82763b7 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h
@@ -24,116 +24,17 @@
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
 
-# undef PSEUDO
-# define PSEUDO(name, syscall_name, args)				      \
-	.text;								      \
-L(pseudo_cancel):							      \
-	cfi_startproc;							      \
-	STM_##args							      \
-	stm	%r12,%r15,48(%r15);					      \
-	cfi_offset (%r15, -36);						      \
-	cfi_offset (%r14, -40);						      \
-	cfi_offset (%r13, -44);						      \
-	cfi_offset (%r12, -48);						      \
-	lr	%r14,%r15;						      \
-	ahi	%r15,-96;						      \
-	cfi_adjust_cfa_offset (96);					      \
-	st	%r14,0(%r15);						      \
-	basr    %r13,0;							      \
-0:	l	%r1,1f-0b(%r13);					      \
-	bas	%r14,0(%r1,%r13);					      \
-	lr	%r0,%r2;						      \
-	LM_##args							      \
-	.if SYS_ify (syscall_name) < 256;				      \
-	svc SYS_ify (syscall_name);					      \
-	.else;								      \
-	lhi %r1,SYS_ify (syscall_name);					      \
-	svc 0;								      \
-	.endif;								      \
-	LR7_##args							      \
-	l	%r1,2f-0b(%r13);					      \
-	lr	%r12,%r2;						      \
-	lr	%r2,%r0;						      \
-	bas	%r14,0(%r1,%r13);					      \
-	lr	%r2,%r12;						      \
-	lm	%r12,%r15,48+96(%r15);					      \
-	cfi_endproc;							      \
-	j	L(pseudo_check);					      \
-1:	.long	CENABLE-0b;						      \
-2:	.long	CDISABLE-0b;						      \
-ENTRY(name)								      \
-	SINGLE_THREAD_P(%r1)						      \
-	jne	L(pseudo_cancel);					      \
-.type	__##syscall_name##_nocancel,@function;				      \
-.globl	__##syscall_name##_nocancel;					      \
-__##syscall_name##_nocancel:						      \
-	DO_CALL(syscall_name, args);					      \
-L(pseudo_check):							      \
-	lhi	%r4,-4095;						      \
-	clr	%r2,%r4;						      \
-	jnl	SYSCALL_ERROR_LABEL;					      \
-.size	__##syscall_name##_nocancel,.-__##syscall_name##_nocancel;	      \
-L(pseudo_end):
-
-# if IS_IN (libpthread)
-#  define CENABLE	__pthread_enable_asynccancel
-#  define CDISABLE	__pthread_disable_asynccancel
-# elif IS_IN (libc)
-#  define CENABLE	__libc_enable_asynccancel
-#  define CDISABLE	__libc_disable_asynccancel
-# elif IS_IN (librt)
-#  define CENABLE	__librt_enable_asynccancel
-#  define CDISABLE	__librt_disable_asynccancel
-# else
-#  error Unsupported library
-# endif
-
-#define STM_0		/* Nothing */
-#define STM_1		st %r2,8(%r15);
-#define STM_2		stm %r2,%r3,8(%r15);
-#define STM_3		stm %r2,%r4,8(%r15);
-#define STM_4		stm %r2,%r5,8(%r15);
-#define STM_5		stm %r2,%r5,8(%r15);
-#define STM_6		stm %r2,%r7,8(%r15);
-
-#define LM_0		/* Nothing */
-#define LM_1		l %r2,8+96(%r15);
-#define LM_2		lm %r2,%r3,8+96(%r15);
-#define LM_3		lm %r2,%r4,8+96(%r15);
-#define LM_4		lm %r2,%r5,8+96(%r15);
-#define LM_5		lm %r2,%r5,8+96(%r15);
-#define LM_6		lm %r2,%r5,8+96(%r15); \
-			cfi_offset (%r7, -68); \
-			l %r7,96+96(%r15);
-
-#define LR7_0		/* Nothing */
-#define LR7_1		/* Nothing */
-#define LR7_2		/* Nothing */
-#define LR7_3		/* Nothing */
-#define LR7_4		/* Nothing */
-#define LR7_5		/* Nothing */
-#define LR7_6		l %r7,28+96(%r15); \
-			cfi_restore (%r7);
-
-# ifndef __ASSEMBLER__
-#  define SINGLE_THREAD_P \
+# define SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF,				      \
 				   header.multiple_threads) == 0, 1)
-# else
-#  define SINGLE_THREAD_P(reg) \
-	ear	reg,%a0;						      \
-	icm	reg,15,MULTIPLE_THREADS_OFFSET(reg);
-# endif
 
-#elif !defined __ASSEMBLER__
+#else
 
 # define SINGLE_THREAD_P (1)
 # define NO_CANCELLATION 1
 
 #endif
 
-#ifndef __ASSEMBLER__
-# define RTLD_SINGLE_THREAD_P \
+#define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
-#endif
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h b/sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h
index 9b2c546..952d2af 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h
@@ -18,135 +18,36 @@
 
 #include <sysdep.h>
 #include <tls.h>
-#ifndef __ASSEMBLER__
-# include <nptl/pthreadP.h>
-#endif
+#include <nptl/pthreadP.h>
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
 
-# undef PSEUDO
-# define PSEUDO(name, syscall_name, args)				      \
-	.text;								      \
-L(pseudo_cancel):							      \
-	cfi_startproc;							      \
-	STM_##args							      \
-	stmg	%r13,%r15,104(%r15);					      \
-	cfi_offset (%r15,-40);						      \
-	cfi_offset (%r14,-48);						      \
-	cfi_offset (%r13,-56);						      \
-	lgr	%r14,%r15;						      \
-	aghi	%r15,-160;						      \
-	cfi_adjust_cfa_offset (160);					      \
-	stg	%r14,0(%r15);						      \
-	brasl	%r14,CENABLE;						      \
-	lgr	%r0,%r2;						      \
-	LM_##args							      \
-	.if SYS_ify (syscall_name) < 256;				      \
-	svc SYS_ify (syscall_name);					      \
-	.else;								      \
-	lghi %r1,SYS_ify (syscall_name);				      \
-	svc 0;								      \
-	.endif;								      \
-	LR7_##args							      \
-	lgr	%r13,%r2;						      \
-	lgr	%r2,%r0;						      \
-	brasl	%r14,CDISABLE;						      \
-	lgr	%r2,%r13;						      \
-	lmg	%r13,%r15,104+160(%r15);				      \
-	cfi_endproc;							      \
-	j	L(pseudo_check);					      \
-ENTRY(name)								      \
-	SINGLE_THREAD_P							      \
-	jne	L(pseudo_cancel);					      \
-.type	__##syscall_name##_nocancel,@function;				      \
-.globl	__##syscall_name##_nocancel;					      \
-__##syscall_name##_nocancel:						      \
-	DO_CALL(syscall_name, args);					      \
-L(pseudo_check):							      \
-	lghi	%r4,-4095;						      \
-	clgr	%r2,%r4;						      \
-	jgnl	SYSCALL_ERROR_LABEL;					      \
-.size	__##syscall_name##_nocancel,.-__##syscall_name##_nocancel;	      \
-L(pseudo_end):
-
 # if IS_IN (libpthread)
-#  define CENABLE	__pthread_enable_asynccancel
-#  define CDISABLE	__pthread_disable_asynccancel
 #  define __local_multiple_threads	__pthread_multiple_threads
 # elif IS_IN (libc)
-#  define CENABLE	__libc_enable_asynccancel
-#  define CDISABLE	__libc_disable_asynccancel
 #  define __local_multiple_threads	__libc_multiple_threads
-# elif IS_IN (librt)
-#  define CENABLE	__librt_enable_asynccancel
-#  define CDISABLE	__librt_disable_asynccancel
-# else
-#  error Unsupported library
 # endif
 
-#define STM_0		/* Nothing */
-#define STM_1		stg %r2,16(%r15);
-#define STM_2		stmg %r2,%r3,16(%r15);
-#define STM_3		stmg %r2,%r4,16(%r15);
-#define STM_4		stmg %r2,%r5,16(%r15);
-#define STM_5		stmg %r2,%r5,16(%r15);
-#define STM_6		stmg %r2,%r7,16(%r15);
-
-#define LM_0		/* Nothing */
-#define LM_1		lg %r2,16+160(%r15);
-#define LM_2		lmg %r2,%r3,16+160(%r15);
-#define LM_3		lmg %r2,%r4,16+160(%r15);
-#define LM_4		lmg %r2,%r5,16+160(%r15);
-#define LM_5		lmg %r2,%r5,16+160(%r15);
-#define LM_6		lmg %r2,%r5,16+160(%r15); \
-			cfi_offset (%r7, -104); \
-			lg %r7,160+160(%r15);
-
-#define LR7_0		/* Nothing */
-#define LR7_1		/* Nothing */
-#define LR7_2		/* Nothing */
-#define LR7_3		/* Nothing */
-#define LR7_4		/* Nothing */
-#define LR7_5		/* Nothing */
-#define LR7_6		lg %r7,56+160(%r15); \
-			cfi_restore (%r7);
-
 # if IS_IN (libpthread) || IS_IN (libc)
-#  ifndef __ASSEMBLER__
 extern int __local_multiple_threads attribute_hidden;
-#   define SINGLE_THREAD_P \
+#  define SINGLE_THREAD_P \
   __builtin_expect (__local_multiple_threads == 0, 1)
-#  else
-#   define SINGLE_THREAD_P \
-	larl	%r1,__local_multiple_threads;				      \
-	icm	%r0,15,0(%r1);
-#  endif
 
 # else
 
-#  ifndef __ASSEMBLER__
-#   define SINGLE_THREAD_P \
+#  define SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF,				      \
 				   header.multiple_threads) == 0, 1)
-#  else
-#   define SINGLE_THREAD_P \
-	ear	%r1,%a0;						      \
-	sllg	%r1,%r1,32;						      \
-	ear	%r1,%a1;						      \
-	icm	%r1,15,MULTIPLE_THREADS_OFFSET(%r1);
-#  endif
 
 # endif
 
-#elif !defined __ASSEMBLER__
+#else
 
 # define SINGLE_THREAD_P (1)
 # define NO_CANCELLATION 1
 
 #endif
 
-#ifndef __ASSEMBLER__
-# define RTLD_SINGLE_THREAD_P \
+#define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
-#endif
diff --git a/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h b/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h
index 5645cad..1ea501b 100644
--- a/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h
@@ -23,147 +23,17 @@
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
 
-# define _IMM12 #-12
-# define _IMM16 #-16
-# define _IMP16 #16
-# undef PSEUDO
-# define PSEUDO(name, syscall_name, args) \
-  .text; \
-  ENTRY (name); \
-  .Lpseudo_start: \
-    SINGLE_THREAD_P; \
-    bf .Lpseudo_cancel; \
-    .type __##syscall_name##_nocancel,@function; \
-    .globl __##syscall_name##_nocancel; \
-    __##syscall_name##_nocancel: \
-    DO_CALL (syscall_name, args); \
-    mov r0,r1; \
-    mov _IMM12,r2; \
-    shad r2,r1; \
-    not r1,r1; \
-    tst r1,r1; \
-    bt .Lsyscall_error; \
-    bra .Lpseudo_end; \
-     nop; \
-    .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
- .Lpseudo_cancel: \
-    sts.l pr,@-r15; \
-    cfi_adjust_cfa_offset (4); \
-    cfi_rel_offset (pr, 0); \
-    add _IMM16,r15; \
-    cfi_adjust_cfa_offset (16); \
-    SAVE_ARGS_##args; \
-    CENABLE; \
-    LOAD_ARGS_##args; \
-    add _IMP16,r15; \
-    cfi_adjust_cfa_offset (-16); \
-    lds.l @r15+,pr; \
-    cfi_adjust_cfa_offset (-4); \
-    cfi_restore (pr); \
-    DO_CALL(syscall_name, args); \
-    SYSCALL_INST_PAD; \
-    sts.l pr,@-r15; \
-    cfi_adjust_cfa_offset (4); \
-    cfi_rel_offset (pr, 0); \
-    mov.l r0,@-r15; \
-    cfi_adjust_cfa_offset (4); \
-    cfi_rel_offset (r0, 0); \
-    CDISABLE; \
-    mov.l @r15+,r0; \
-    cfi_adjust_cfa_offset (-4); \
-    cfi_restore (r0); \
-    lds.l @r15+,pr; \
-    cfi_adjust_cfa_offset (-4); \
-    cfi_restore (pr); \
-    mov r0,r1; \
-    mov _IMM12,r2; \
-    shad r2,r1; \
-    not r1,r1; \
-    tst r1,r1; \
-    bf .Lpseudo_end; \
- .Lsyscall_error: \
-    SYSCALL_ERROR_HANDLER; \
- .Lpseudo_end:
-
-# undef PSEUDO_END
-# define PSEUDO_END(sym) \
-  END (sym)
-
-# define SAVE_ARGS_0	/* Nothing.  */
-# define SAVE_ARGS_1	SAVE_ARGS_0; mov.l r4,@(0,r15); cfi_offset (r4,-4)
-# define SAVE_ARGS_2	SAVE_ARGS_1; mov.l r5,@(4,r15); cfi_offset (r5,-8)
-# define SAVE_ARGS_3	SAVE_ARGS_2; mov.l r6,@(8,r15); cfi_offset (r6,-12)
-# define SAVE_ARGS_4	SAVE_ARGS_3; mov.l r7,@(12,r15); cfi_offset (r7,-16)
-# define SAVE_ARGS_5	SAVE_ARGS_4
-# define SAVE_ARGS_6	SAVE_ARGS_5
-
-# define LOAD_ARGS_0	/* Nothing.  */
-# define LOAD_ARGS_1	LOAD_ARGS_0; mov.l @(0,r15),r4; cfi_restore (r4)
-# define LOAD_ARGS_2	LOAD_ARGS_1; mov.l @(4,r15),r5; cfi_restore (r5)
-# define LOAD_ARGS_3	LOAD_ARGS_2; mov.l @(8,r15),r6; cfi_restore (r6)
-# define LOAD_ARGS_4	LOAD_ARGS_3; mov.l @(12,r15),r7; cfi_restore (r7)
-# define LOAD_ARGS_5	LOAD_ARGS_4
-# define LOAD_ARGS_6	LOAD_ARGS_5
-
-# if IS_IN (libpthread)
-#  define __local_enable_asynccancel	__pthread_enable_asynccancel
-#  define __local_disable_asynccancel	__pthread_disable_asynccancel
-# elif IS_IN (libc)
-#  define __local_enable_asynccancel	__libc_enable_asynccancel
-#  define __local_disable_asynccancel	__libc_disable_asynccancel
-# elif IS_IN (librt)
-#  define __local_enable_asynccancel	__librt_enable_asynccancel
-#  define __local_disable_asynccancel	__librt_disable_asynccancel
-# else
-#  error Unsupported library
-# endif
-
-# define CENABLE \
-	mov.l 1f,r0; \
-	bsrf r0; \
-	 nop; \
-     0: bra 2f; \
-	 mov r0,r2; \
-	.align 2; \
-     1: .long __local_enable_asynccancel - 0b; \
-     2:
-
-# define CDISABLE \
-	mov.l 1f,r0; \
-	bsrf r0; \
-	 mov r2,r4; \
-     0: bra 2f; \
-	 nop; \
-	.align 2; \
-     1: .long __local_disable_asynccancel - 0b; \
-     2:
-
-# ifndef __ASSEMBLER__
-#  define SINGLE_THREAD_P \
+# define SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
-# else
-#  define SINGLE_THREAD_P \
-	stc gbr,r0; \
-	mov.w 0f,r1; \
-	sub r1,r0; \
-	mov.l @(MULTIPLE_THREADS_OFFSET,r0),r0; \
-	bra 1f; \
-	 tst r0,r0; \
-     0: .word TLS_PRE_TCB_SIZE; \
-     1:
-
-# endif
 
-#elif !defined __ASSEMBLER__
+#else
 
 # define SINGLE_THREAD_P (1)
 # define NO_CANCELLATION 1
 
 #endif
 
-#ifndef __ASSEMBLER__
-# define RTLD_SINGLE_THREAD_P \
+#define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
-#endif
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep-cancel.h b/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep-cancel.h
deleted file mode 100644
index c513212..0000000
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep-cancel.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/* Copyright (C) 2002-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <sysdep.h>
-#include <tls.h>
-#ifndef __ASSEMBLER__
-# include <nptl/pthreadP.h>
-#endif
-
-#if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
-
-# undef PSEUDO
-# define PSEUDO(name, syscall_name, args)	\
-	.text;					\
-	.globl		__syscall_error;	\
-ENTRY(name)					\
-	ld [%g7 + MULTIPLE_THREADS_OFFSET], %g1;\
-	cmp %g1, 0;				\
-	bne 1f;					\
-.type	__##syscall_name##_nocancel,@function;	\
-.globl	__##syscall_name##_nocancel;		\
-__##syscall_name##_nocancel:			\
-	 mov SYS_ify(syscall_name), %g1;	\
-	ta 0x10;				\
-	bcc 8f;					\
-	 mov %o7, %g1;				\
-	call __syscall_error;			\
-	 mov %g1, %o7;				\
-8:	jmpl %o7 + 8, %g0;			\
-	 nop;					\
-.size	__##syscall_name##_nocancel,.-__##syscall_name##_nocancel;\
-1:	save %sp, -96, %sp;			\
-	cfi_def_cfa_register(%fp);		\
-	cfi_window_save;			\
-	cfi_register(%o7, %i7);			\
-	CENABLE;				\
-	 nop;					\
-	mov %o0, %l0;				\
-	COPY_ARGS_##args			\
-	mov SYS_ify(syscall_name), %g1;		\
-	ta 0x10;				\
-	bcc 1f;					\
-	 mov %o0, %l1;				\
-	CDISABLE;				\
-	 mov %l0, %o0;				\
-	call __syscall_error;			\
-	 mov %l1, %o0;				\
-	b 2f;					\
-	 mov -1, %l1;				\
-1:	CDISABLE;				\
-	 mov %l0, %o0;				\
-2:	jmpl %i7 + 8, %g0;			\
-	 restore %g0, %l1, %o0;
-
-
-# if IS_IN (libpthread)
-#  define CENABLE	call __pthread_enable_asynccancel
-#  define CDISABLE	call __pthread_disable_asynccancel
-# elif IS_IN (libc)
-#  define CENABLE	call __libc_enable_asynccancel
-#  define CDISABLE	call __libc_disable_asynccancel
-# elif IS_IN (librt)
-#  define CENABLE	call __librt_enable_asynccancel
-#  define CDISABLE	call __librt_disable_asynccancel
-# else
-#  error Unsupported library
-# endif
-
-#define COPY_ARGS_0	/* Nothing */
-#define COPY_ARGS_1	COPY_ARGS_0 mov %i0, %o0;
-#define COPY_ARGS_2	COPY_ARGS_1 mov %i1, %o1;
-#define COPY_ARGS_3	COPY_ARGS_2 mov %i2, %o2;
-#define COPY_ARGS_4	COPY_ARGS_3 mov %i3, %o3;
-#define COPY_ARGS_5	COPY_ARGS_4 mov %i4, %o4;
-#define COPY_ARGS_6	COPY_ARGS_5 mov %i5, %o5;
-
-# ifndef __ASSEMBLER__
-#  define SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF,				      \
-				   header.multiple_threads) == 0, 1)
-# else
-#  define SINGLE_THREAD_P ld [%g7 + MULTIPLE_THREADS_OFFSET], %g1
-# endif
-
-#elif !defined __ASSEMBLER__
-
-# define SINGLE_THREAD_P (1)
-# define NO_CANCELLATION 1
-
-#endif
-
-#ifndef __ASSEMBLER__
-# define RTLD_SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
-				   header.multiple_threads) == 0, 1)
-#endif
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep-cancel.h b/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep-cancel.h
deleted file mode 100644
index 45fbd73..0000000
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep-cancel.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/* Copyright (C) 2002-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <sysdep.h>
-#include <tls.h>
-#ifndef __ASSEMBLER__
-# include <nptl/pthreadP.h>
-#endif
-
-#if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
-
-# undef PSEUDO
-# define PSEUDO(name, syscall_name, args)	\
-	.text;					\
-	.globl		__syscall_error;	\
-ENTRY(name)					\
-	ld [%g7 + MULTIPLE_THREADS_OFFSET], %g1;\
-	brnz,pn %g1, 1f;			\
-.type	__##syscall_name##_nocancel,@function;	\
-.globl	__##syscall_name##_nocancel;		\
-__##syscall_name##_nocancel:			\
-	 mov SYS_ify(syscall_name), %g1;	\
-	ta 0x6d;				\
-	bcc,pt %xcc, 8f;			\
-	 mov %o7, %g1;				\
-	call __syscall_error;			\
-	 mov %g1, %o7;				\
-8:	jmpl %o7 + 8, %g0;			\
-	 nop;					\
-.size	__##syscall_name##_nocancel,.-__##syscall_name##_nocancel;\
-1:	save %sp, -192, %sp;			\
-	cfi_def_cfa_register(%fp);		\
-	cfi_window_save;			\
-	cfi_register(%o7, %i7);			\
-	CENABLE;				\
-	 nop;					\
-	mov %o0, %l0;				\
-	COPY_ARGS_##args			\
-	mov SYS_ify(syscall_name), %g1;		\
-	ta 0x6d;				\
-	bcc,pt %xcc, 1f;			\
-	 mov %o0, %l1;				\
-	CDISABLE;				\
-	 mov %l0, %o0;				\
-	call __syscall_error;			\
-	 mov %l1, %o0;				\
-	ba,pt %xcc, 2f;				\
-	 mov -1, %l1;				\
-1:	CDISABLE;				\
-	 mov %l0, %o0;				\
-2:	jmpl %i7 + 8, %g0;			\
-	 restore %g0, %l1, %o0;
-
-# if IS_IN (libpthread)
-#  define CENABLE	call __pthread_enable_asynccancel
-#  define CDISABLE	call __pthread_disable_asynccancel
-# elif IS_IN (libc)
-#  define CENABLE	call __libc_enable_asynccancel
-#  define CDISABLE	call __libc_disable_asynccancel
-# elif IS_IN (librt)
-#  define CENABLE	call __librt_enable_asynccancel
-#  define CDISABLE	call __librt_disable_asynccancel
-# else
-#  error Unsupported library
-# endif
-
-#define COPY_ARGS_0	/* Nothing */
-#define COPY_ARGS_1	COPY_ARGS_0 mov %i0, %o0;
-#define COPY_ARGS_2	COPY_ARGS_1 mov %i1, %o1;
-#define COPY_ARGS_3	COPY_ARGS_2 mov %i2, %o2;
-#define COPY_ARGS_4	COPY_ARGS_3 mov %i3, %o3;
-#define COPY_ARGS_5	COPY_ARGS_4 mov %i4, %o4;
-#define COPY_ARGS_6	COPY_ARGS_5 mov %i5, %o5;
-
-# ifndef __ASSEMBLER__
-#  define SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF,				      \
-				   header.multiple_threads) == 0, 1)
-# else
-#  define SINGLE_THREAD_P ld [%g7 + MULTIPLE_THREADS_OFFSET], %g1
-# endif
-
-#elif !defined __ASSEMBLER__
-
-# define SINGLE_THREAD_P (1)
-# define NO_CANCELLATION 1
-
-#endif
-
-#ifndef __ASSEMBLER__
-# define RTLD_SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
-				   header.multiple_threads) == 0, 1)
-#endif
diff --git a/sysdeps/unix/sysv/linux/sparc/sysdep-cancel.h b/sysdeps/unix/sysv/linux/sparc/sysdep-cancel.h
new file mode 100644
index 0000000..61bfa33
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sparc/sysdep-cancel.h
@@ -0,0 +1,38 @@
+/* Copyright (C) 2002-2015 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+#include <tls.h>
+#include <nptl/pthreadP.h>
+
+#if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
+
+# define SINGLE_THREAD_P \
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF,				      \
+				   header.multiple_threads) == 0, 1)
+
+#else
+
+# define SINGLE_THREAD_P (1)
+# define NO_CANCELLATION 1
+
+#endif
+
+#define RTLD_SINGLE_THREAD_P \
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+				   header.multiple_threads) == 0, 1)
diff --git a/sysdeps/unix/sysv/linux/tile/sysdep-cancel.h b/sysdeps/unix/sysv/linux/tile/sysdep-cancel.h
index 092a90c..c8994db 100644
--- a/sysdeps/unix/sysv/linux/tile/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/tile/sysdep-cancel.h
@@ -18,137 +18,22 @@
 
 #include <sysdep.h>
 #include <tls.h>
-#ifndef __ASSEMBLER__
-# include <nptl/pthreadP.h>
-#endif
+#include <nptl/pthreadP.h>
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
 
-/* Allow hacking in some extra code if desired. */
-#ifndef PSEUDO_EXTRA
-#define PSEUDO_EXTRA
-#endif
-
-#undef PSEUDO
-#define PSEUDO(name, syscall_name, args)				      \
-  ENTRY(__##syscall_name##_nocancel);					      \
-    PSEUDO_EXTRA							      \
-    moveli TREG_SYSCALL_NR_NAME, SYS_ify(syscall_name);			      \
-    swint1;								      \
-    BNEZ r1, 0f;							      \
-    jrp lr;								      \
-  END(__##syscall_name##_nocancel);					      \
-  ENTRY (name)								      \
-    SINGLE_THREAD_P(r11);						      \
-    BEQZ r11, L(pseudo_cancel);						      \
-    PSEUDO_EXTRA							      \
-    moveli TREG_SYSCALL_NR_NAME, SYS_ify(syscall_name);			      \
-    swint1;								      \
-    BNEZ r1, 0f;							      \
-    jrp lr;								      \
-  L(pseudo_cancel):							      \
-    {									      \
-     move r11, sp;							      \
-     ST sp, lr;								      \
-     ADDI_PTR sp, sp, -STKSPACE;					      \
-    };									      \
-    cfi_offset (lr, 0);							      \
-    cfi_def_cfa_offset (STKSPACE);					      \
-    {									      \
-     ADDI_PTR r12, sp, REGSIZE;						      \
-     ADDI_PTR r13, sp, 2 * REGSIZE;	/* set up for PUSHARGS_0 */	      \
-    };									      \
-    ST r12, r11;							      \
-    PUSHARGS_##args			/* save syscall args */	      	      \
-    CENABLE;								      \
-    ADDI_PTR r12, sp, 10 * REGSIZE;					      \
-    {									      \
-     ST r12, r0;			/* save mask */			      \
-     ADDI_PTR r13, sp, 2 * REGSIZE;	/* set up for POPARGS_0 */	      \
-    };									      \
-    POPARGS_##args			/* restore syscall args */	      \
-    PSEUDO_EXTRA							      \
-    moveli TREG_SYSCALL_NR_NAME, SYS_ify(syscall_name);			      \
-    swint1;								      \
-    ADDI_PTR r12, sp, 12 * REGSIZE;					      \
-    {									      \
-     ST r12, r1;			/* save syscall result */             \
-     ADDI_PTR r12, sp, 11 * REGSIZE;					      \
-    };									      \
-    {									      \
-     ST r12, r0;			                                      \
-     ADDI_PTR r13, sp, 10 * REGSIZE;					      \
-    };									      \
-    LD r0, r13;				/* pass mask as arg1 */		      \
-    CDISABLE;								      \
-    {									      \
-     ADDI_PTR lr, sp, STKSPACE;						      \
-     ADDI_PTR r0, sp, 11 * REGSIZE;					      \
-    };									      \
-    {									      \
-     LD r0, r0;								      \
-     ADDI_PTR r1, sp, 12 * REGSIZE;					      \
-    };									      \
-    LD r1, r1;								      \
-    {									      \
-     LD lr, lr;								      \
-     ADDI_PTR sp, sp, STKSPACE;						      \
-    };									      \
-    cfi_def_cfa_offset (0);						      \
-    BNEZ r1, 0f
-
-# define PUSHARGS_0 /* nothing to do */
-# define PUSHARGS_1 PUSHARGS_0 { ADDI_PTR r14, sp, 3 * REGSIZE; ST r13, r0 };
-# define PUSHARGS_2 PUSHARGS_1 { ADDI_PTR r13, sp, 4 * REGSIZE; ST r14, r1 };
-# define PUSHARGS_3 PUSHARGS_2 { ADDI_PTR r14, sp, 5 * REGSIZE; ST r13, r2 };
-# define PUSHARGS_4 PUSHARGS_3 { ADDI_PTR r13, sp, 6 * REGSIZE; ST r14, r3 };
-# define PUSHARGS_5 PUSHARGS_4 { ADDI_PTR r14, sp, 7 * REGSIZE; ST r13, r4 };
-# define PUSHARGS_6 PUSHARGS_5 { ADDI_PTR r13, sp, 8 * REGSIZE; ST r14, r5 };
-# define PUSHARGS_7 PUSHARGS_6 { ADDI_PTR r14, sp, 9 * REGSIZE; ST r13, r6 };
-
-# define POPARGS_0  /* nothing to do */
-# define POPARGS_1  POPARGS_0 { ADDI_PTR r14, sp, 3 * REGSIZE; LD r0, r13 };
-# define POPARGS_2  POPARGS_1 { ADDI_PTR r13, sp, 4 * REGSIZE; LD r1, r14 };
-# define POPARGS_3  POPARGS_2 { ADDI_PTR r14, sp, 5 * REGSIZE; LD r2, r13 };
-# define POPARGS_4  POPARGS_3 { ADDI_PTR r13, sp, 6 * REGSIZE; LD r3, r14 };
-# define POPARGS_5  POPARGS_4 { ADDI_PTR r14, sp, 7 * REGSIZE; LD r4, r13 };
-# define POPARGS_6  POPARGS_5 { ADDI_PTR r13, sp, 8 * REGSIZE; LD r5, r14 };
-# define POPARGS_7  POPARGS_6 { ADDI_PTR r14, sp, 9 * REGSIZE; LD r6, r13 };
-
-# define STKSPACE	(13 * REGSIZE)
-
-# if IS_IN (libpthread)
-#  define CENABLE	jal __pthread_enable_asynccancel
-#  define CDISABLE	jal __pthread_disable_asynccancel
-# elif IS_IN (librt)
-#  define CENABLE	jal __librt_enable_asynccancel
-#  define CDISABLE	jal __librt_disable_asynccancel
-# else
-#  define CENABLE	jal __libc_enable_asynccancel
-#  define CDISABLE	jal __libc_disable_asynccancel
-# endif
-
-# ifndef __ASSEMBLER__
-#  define SINGLE_THREAD_P						\
+# define SINGLE_THREAD_P						\
 	__builtin_expect (THREAD_GETMEM (THREAD_SELF,			\
 					 header.multiple_threads)	\
 			  == 0, 1)
-# else
-#  define SINGLE_THREAD_P(reg)						\
-  ADDLI_PTR reg, tp, MULTIPLE_THREADS_OFFSET;                           \
-  LD reg, reg;                                                          \
-  CMPEQI reg, reg, 0
-#endif
 
-#elif !defined __ASSEMBLER__
+#else
 
 # define SINGLE_THREAD_P 1
 # define NO_CANCELLATION 1
 
 #endif
 
-#ifndef __ASSEMBLER__
-# define RTLD_SINGLE_THREAD_P                                           \
+#define RTLD_SINGLE_THREAD_P                                           \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF,                         \
                                    header.multiple_threads) == 0, 1)
-#endif
diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h b/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h
index 6598010..0979bde 100644
--- a/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h
@@ -24,86 +24,32 @@
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
 
-/* The code to disable cancellation depends on the fact that the called
-   functions are special.  They don't modify registers other than %rax
-   and %r11 if they return.  Therefore we don't have to preserve other
-   registers around these calls.  */
-# undef PSEUDO
-# define PSEUDO(name, syscall_name, args)				      \
-  .text;								      \
-  ENTRY (name)								      \
-    SINGLE_THREAD_P;							      \
-    jne L(pseudo_cancel);						      \
-  .type __##syscall_name##_nocancel,@function;				      \
-  .globl __##syscall_name##_nocancel;					      \
-  __##syscall_name##_nocancel:						      \
-    DO_CALL (syscall_name, args);					      \
-    cmpq $-4095, %rax;							      \
-    jae SYSCALL_ERROR_LABEL;						      \
-    ret;								      \
-  .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel;	      \
-  L(pseudo_cancel):							      \
-    /* We always have to align the stack before calling a function.  */	      \
-    subq $8, %rsp; cfi_adjust_cfa_offset (8);				      \
-    CENABLE								      \
-    /* The return value from CENABLE is argument for CDISABLE.  */	      \
-    movq %rax, (%rsp);							      \
-    DO_CALL (syscall_name, args);					      \
-    movq (%rsp), %rdi;							      \
-    /* Save %rax since it's the error code from the syscall.  */	      \
-    movq %rax, %rdx;							      \
-    CDISABLE								      \
-    movq %rdx, %rax;							      \
-    addq $8,%rsp; cfi_adjust_cfa_offset (-8);				      \
-    cmpq $-4095, %rax;							      \
-    jae SYSCALL_ERROR_LABEL
-
-
 # if IS_IN (libpthread)
-#  define CENABLE	call __pthread_enable_asynccancel;
-#  define CDISABLE	call __pthread_disable_asynccancel;
 #  define __local_multiple_threads __pthread_multiple_threads
 # elif IS_IN (libc)
-#  define CENABLE	call __libc_enable_asynccancel;
-#  define CDISABLE	call __libc_disable_asynccancel;
 #  define __local_multiple_threads __libc_multiple_threads
 # elif IS_IN (librt)
-#  define CENABLE	call __librt_enable_asynccancel;
-#  define CDISABLE	call __librt_disable_asynccancel;
 # else
 #  error Unsupported library
 # endif
 
 # if IS_IN (libpthread) || IS_IN (libc)
-#  ifndef __ASSEMBLER__
 extern int __local_multiple_threads attribute_hidden;
-#   define SINGLE_THREAD_P \
+#  define SINGLE_THREAD_P \
   __builtin_expect (__local_multiple_threads == 0, 1)
-#  else
-#   define SINGLE_THREAD_P cmpl $0, __local_multiple_threads(%rip)
-#  endif
-
 # else
-
-#  ifndef __ASSEMBLER__
-#   define SINGLE_THREAD_P \
+#  define SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
-#  else
-#   define SINGLE_THREAD_P cmpl $0, %fs:MULTIPLE_THREADS_OFFSET
-#  endif
-
 # endif
 
-#elif !defined __ASSEMBLER__
+#else
 
 # define SINGLE_THREAD_P (1)
 # define NO_CANCELLATION 1
 
 #endif
 
-#ifndef __ASSEMBLER__
-# define RTLD_SINGLE_THREAD_P \
+#define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
-#endif

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=858eb38e1fb9a6edc649b8898105715d1ac24378

commit 858eb38e1fb9a6edc649b8898105715d1ac24378
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Fri Jan 20 19:01:59 2017 -0200

    Consolidate set* Linux implementation
    
    This patch consolidates the Linux setegid, seteuid, setgid, setgroups,
    setregid, setresgid, setresuid, setreuid, and setuid implementation on
    default sysdeps/unix/sysv/linux/sh/set*.c implementation.  It basically
    removes all the architecture define implementations and add support for
    __NR_set*32 syscall on Linux default implementation.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/arm/setegid.c: Remove file.
    	* sysdeps/unix/sysv/linux/arm/seteuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/arm/setgid.c: Likewise.
    	* sysdeps/unix/sysv/linux/arm/setgroups.c: Likewise.
    	* sysdeps/unix/sysv/linux/arm/setregid.c: Likewise.
    	* sysdeps/unix/sysv/linux/arm/setresgid.c: Likewise.
    	* sysdeps/unix/sysv/linux/arm/setresuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/arm/setreuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/arm/setuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/i386/setegid.c: Likewise.
    	* sysdeps/unix/sysv/linux/i386/seteuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/i386/setgid.c: Likewise.
    	* sysdeps/unix/sysv/linux/i386/setgroups.c: Likewise.
    	* sysdeps/unix/sysv/linux/i386/setregid.c: Likewise.
    	* sysdeps/unix/sysv/linux/i386/setresgid.c: Likewise.
    	* sysdeps/unix/sysv/linux/i386/setresuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/i386/setreuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/i386/setuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/m68k/setegid.c: Likewise.
    	* sysdeps/unix/sysv/linux/m68k/seteuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/m68k/setgid.c: Likewise.
    	* sysdeps/unix/sysv/linux/m68k/setgroups.c: Likewise.
    	* sysdeps/unix/sysv/linux/m68k/setregid.c: Likewise.
    	* sysdeps/unix/sysv/linux/m68k/setresgid.c: Likewise.
    	* sysdeps/unix/sysv/linux/m68k/setresuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/m68k/setreuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/m68k/setuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/microblaze/setgroups.c: Likewise.
    	* sysdeps/unix/sysv/linux/s390/s390-32/setegid.c: Likewise.
    	* sysdeps/unix/sysv/linux/s390/s390-32/seteuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/s390/s390-32/setgid.c: Likewise.
    	* sysdeps/unix/sysv/linux/s390/s390-32/setgroups.c: Likewise.
    	* sysdeps/unix/sysv/linux/s390/s390-32/setregid.c: Likewise.
    	* sysdeps/unix/sysv/linux/s390/s390-32/setresgid.c: Likewise.
    	* sysdeps/unix/sysv/linux/s390/s390-32/setresuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/s390/s390-32/setreuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/s390/s390-32/setuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/sh/setegid.c: Likewise.
    	* sysdeps/unix/sysv/linux/sh/seteuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/sh/setgid.c: Likewise.
    	* sysdeps/unix/sysv/linux/sh/setgroups.c: Likewise.
    	* sysdeps/unix/sysv/linux/sh/setregid.c: Likewise.
    	* sysdeps/unix/sysv/linux/sh/setresgid.c: Likewise.
    	* sysdeps/unix/sysv/linux/sh/setresuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/sh/setreuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/sh/setuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/sparc/sparc32/setegid.c: Likewise.
    	* sysdeps/unix/sysv/linux/sparc/sparc32/seteuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/sparc/sparc32/setgid.c: Likewise.
    	* sysdeps/unix/sysv/linux/sparc/sparc32/setgroups.c: Likewise.
    	* sysdeps/unix/sysv/linux/sparc/sparc32/setregid.c: Likewise.
    	* sysdeps/unix/sysv/linux/sparc/sparc32/setresgid.c: Likewise.
    	* sysdeps/unix/sysv/linux/sparc/sparc32/setresuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/sparc/sparc32/setreuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/sparc/sparc32/setuid.c: Likewise.
    	* sysdeps/unix/sysv/linux/setegid.c (setegid): Use
    	INLINE_SYSCALL_ERROR_RETURN_VALUE.
    	* sysdeps/unix/sysv/linux/seteuid.c (seteuid): Likewise.
    	* sysdeps/unix/sysv/linux/setgid.c (setgid): Use __NR_setgid32 if
    	defined.
    	* sysdeps/unix/sysv/linux/setgroups.c (setgroups): Use
    	__NR_setgroups32 if defined.
    	* sysdeps/unix/sysv/linux/setregid.c (__setregid): Use __NR_setregid32
    	if defined.
    	* sysdeps/unix/sysv/linux/setresgid.c (__setresgid): Use
    	__NR_setresgid32 is defined.
    	* sysdeps/unix/sysv/linux/setresuid.c (__setresuid): Use
    	__NR_setresuid32 if defined.
    	* sysdeps/unix/sysv/linux/setreuid.c (__setreuid): Use
    	__NR_setreuid32 if defined.
    	* sysdeps/unix/sysv/linux/setuid.c (__setuid): Use __NR_setuid32 if
    	defined.

diff --git a/ChangeLog b/ChangeLog
index f642bc2..af4ceac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,78 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/arm/setegid.c: Remove file.
+	* sysdeps/unix/sysv/linux/arm/seteuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/arm/setgid.c: Likewise.
+	* sysdeps/unix/sysv/linux/arm/setgroups.c: Likewise.
+	* sysdeps/unix/sysv/linux/arm/setregid.c: Likewise.
+	* sysdeps/unix/sysv/linux/arm/setresgid.c: Likewise.
+	* sysdeps/unix/sysv/linux/arm/setresuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/arm/setreuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/arm/setuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/i386/setegid.c: Likewise.
+	* sysdeps/unix/sysv/linux/i386/seteuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/i386/setgid.c: Likewise.
+	* sysdeps/unix/sysv/linux/i386/setgroups.c: Likewise.
+	* sysdeps/unix/sysv/linux/i386/setregid.c: Likewise.
+	* sysdeps/unix/sysv/linux/i386/setresgid.c: Likewise.
+	* sysdeps/unix/sysv/linux/i386/setresuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/i386/setreuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/i386/setuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/m68k/setegid.c: Likewise.
+	* sysdeps/unix/sysv/linux/m68k/seteuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/m68k/setgid.c: Likewise.
+	* sysdeps/unix/sysv/linux/m68k/setgroups.c: Likewise.
+	* sysdeps/unix/sysv/linux/m68k/setregid.c: Likewise.
+	* sysdeps/unix/sysv/linux/m68k/setresgid.c: Likewise.
+	* sysdeps/unix/sysv/linux/m68k/setresuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/m68k/setreuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/m68k/setuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/microblaze/setgroups.c: Likewise.
+	* sysdeps/unix/sysv/linux/s390/s390-32/setegid.c: Likewise.
+	* sysdeps/unix/sysv/linux/s390/s390-32/seteuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/s390/s390-32/setgid.c: Likewise.
+	* sysdeps/unix/sysv/linux/s390/s390-32/setgroups.c: Likewise.
+	* sysdeps/unix/sysv/linux/s390/s390-32/setregid.c: Likewise.
+	* sysdeps/unix/sysv/linux/s390/s390-32/setresgid.c: Likewise.
+	* sysdeps/unix/sysv/linux/s390/s390-32/setresuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/s390/s390-32/setreuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/s390/s390-32/setuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/sh/setegid.c: Likewise.
+	* sysdeps/unix/sysv/linux/sh/seteuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/sh/setgid.c: Likewise.
+	* sysdeps/unix/sysv/linux/sh/setgroups.c: Likewise.
+	* sysdeps/unix/sysv/linux/sh/setregid.c: Likewise.
+	* sysdeps/unix/sysv/linux/sh/setresgid.c: Likewise.
+	* sysdeps/unix/sysv/linux/sh/setresuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/sh/setreuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/sh/setuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc32/setegid.c: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc32/seteuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc32/setgid.c: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc32/setgroups.c: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc32/setregid.c: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc32/setresgid.c: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc32/setresuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc32/setreuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc32/setuid.c: Likewise.
+	* sysdeps/unix/sysv/linux/setegid.c (setegid): Use
+	INLINE_SYSCALL_ERROR_RETURN_VALUE.
+	* sysdeps/unix/sysv/linux/seteuid.c (seteuid): Likewise.
+	* sysdeps/unix/sysv/linux/setgid.c (setgid): Use __NR_setgid32 if
+	defined.
+	* sysdeps/unix/sysv/linux/setgroups.c (setgroups): Use
+	__NR_setgroups32 if defined.
+	* sysdeps/unix/sysv/linux/setregid.c (__setregid): Use __NR_setregid32
+	if defined.
+	* sysdeps/unix/sysv/linux/setresgid.c (__setresgid): Use
+	__NR_setresgid32 is defined.
+	* sysdeps/unix/sysv/linux/setresuid.c (__setresuid): Use
+	__NR_setresuid32 if defined.
+	* sysdeps/unix/sysv/linux/setreuid.c (__setreuid): Use
+	__NR_setreuid32 if defined.
+	* sysdeps/unix/sysv/linux/setuid.c (__setuid): Use __NR_setuid32 if
+	defined.
+
 	* sysdeps/unix/sysv/linux/arm/fcntl.c: Remove file.
 	* sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c: Likewise.
 	* sysdeps/unix/sysv/linux/hppa/fcntl.c: Likewise.
diff --git a/sysdeps/unix/sysv/linux/arm/setegid.c b/sysdeps/unix/sysv/linux/arm/setegid.c
deleted file mode 100644
index 2e3a54c..0000000
--- a/sysdeps/unix/sysv/linux/arm/setegid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setegid.c>
diff --git a/sysdeps/unix/sysv/linux/arm/seteuid.c b/sysdeps/unix/sysv/linux/arm/seteuid.c
deleted file mode 100644
index 18e41d0..0000000
--- a/sysdeps/unix/sysv/linux/arm/seteuid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/seteuid.c>
diff --git a/sysdeps/unix/sysv/linux/arm/setgid.c b/sysdeps/unix/sysv/linux/arm/setgid.c
deleted file mode 100644
index 377021d..0000000
--- a/sysdeps/unix/sysv/linux/arm/setgid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setgid.c>
diff --git a/sysdeps/unix/sysv/linux/arm/setgroups.c b/sysdeps/unix/sysv/linux/arm/setgroups.c
deleted file mode 100644
index 0e70862..0000000
--- a/sysdeps/unix/sysv/linux/arm/setgroups.c
+++ /dev/null
@@ -1,2 +0,0 @@
-/* We also have to rewrite the kernel gid_t to the user land type.  */
-#include <sysdeps/unix/sysv/linux/i386/setgroups.c>
diff --git a/sysdeps/unix/sysv/linux/arm/setregid.c b/sysdeps/unix/sysv/linux/arm/setregid.c
deleted file mode 100644
index 99c57ad..0000000
--- a/sysdeps/unix/sysv/linux/arm/setregid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setregid.c>
diff --git a/sysdeps/unix/sysv/linux/arm/setresgid.c b/sysdeps/unix/sysv/linux/arm/setresgid.c
deleted file mode 100644
index daca1a4..0000000
--- a/sysdeps/unix/sysv/linux/arm/setresgid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setresgid.c>
diff --git a/sysdeps/unix/sysv/linux/arm/setresuid.c b/sysdeps/unix/sysv/linux/arm/setresuid.c
deleted file mode 100644
index 3aeabe9..0000000
--- a/sysdeps/unix/sysv/linux/arm/setresuid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setresuid.c>
diff --git a/sysdeps/unix/sysv/linux/arm/setreuid.c b/sysdeps/unix/sysv/linux/arm/setreuid.c
deleted file mode 100644
index 8ad6122..0000000
--- a/sysdeps/unix/sysv/linux/arm/setreuid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setreuid.c>
diff --git a/sysdeps/unix/sysv/linux/arm/setuid.c b/sysdeps/unix/sysv/linux/arm/setuid.c
deleted file mode 100644
index de39437..0000000
--- a/sysdeps/unix/sysv/linux/arm/setuid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setuid.c>
diff --git a/sysdeps/unix/sysv/linux/i386/setegid.c b/sysdeps/unix/sysv/linux/i386/setegid.c
deleted file mode 100644
index 5a009e7..0000000
--- a/sysdeps/unix/sysv/linux/i386/setegid.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Copyright (C) 1995-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <unistd.h>
-#include <setxid.h>
-
-
-int
-setegid (gid_t gid)
-{
-  int result;
-
-  if (gid == (gid_t) ~0)
-    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
-
-  result = INLINE_SETXID_SYSCALL (setresgid32, 3, -1, gid, -1);
-
-  return result;
-}
-libc_hidden_def (setegid)
diff --git a/sysdeps/unix/sysv/linux/i386/seteuid.c b/sysdeps/unix/sysv/linux/i386/seteuid.c
deleted file mode 100644
index 7f5b84c..0000000
--- a/sysdeps/unix/sysv/linux/i386/seteuid.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Copyright (C) 1998-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <unistd.h>
-#include <setxid.h>
-
-
-int
-seteuid (uid_t uid)
-{
-  int result;
-
-  if (uid == (uid_t) ~0)
-    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
-
-  result = INLINE_SETXID_SYSCALL (setresuid32, 3, -1, uid, -1);
-
-  return result;
-}
-libc_hidden_def (seteuid)
diff --git a/sysdeps/unix/sysv/linux/i386/setgid.c b/sysdeps/unix/sysv/linux/i386/setgid.c
deleted file mode 100644
index 9b58e7b..0000000
--- a/sysdeps/unix/sysv/linux/i386/setgid.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/* Copyright (C) 1998-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <unistd.h>
-#include <setxid.h>
-#include <linux/posix_types.h>
-
-int
-__setgid (gid_t gid)
-{
-  int result;
-
-  result = INLINE_SETXID_SYSCALL (setgid32, 1, gid);
-
-  return result;
-}
-#ifndef __setgid
-weak_alias (__setgid, setgid)
-#endif
diff --git a/sysdeps/unix/sysv/linux/i386/setgroups.c b/sysdeps/unix/sysv/linux/i386/setgroups.c
deleted file mode 100644
index 13ab4fd..0000000
--- a/sysdeps/unix/sysv/linux/i386/setgroups.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/* Copyright (C) 1997-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <grp.h>
-#include <unistd.h>
-#include <sys/types.h>
-
-#include <sysdep.h>
-#include <sys/syscall.h>
-
-#include <setxid.h>
-#include <linux/posix_types.h>
-
-/* Set the group set for the current user to GROUPS (N of them).  For
-   Linux we must convert the array of groups into the format that the
-   kernel expects.  */
-int
-setgroups (size_t n, const gid_t *groups)
-{
-  return INLINE_SETXID_SYSCALL (setgroups32, 2, n, groups);
-}
-libc_hidden_def (setgroups)
diff --git a/sysdeps/unix/sysv/linux/i386/setregid.c b/sysdeps/unix/sysv/linux/i386/setregid.c
deleted file mode 100644
index 3314f55..0000000
--- a/sysdeps/unix/sysv/linux/i386/setregid.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/* Copyright (C) 1998-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <unistd.h>
-#include <setxid.h>
-#include <linux/posix_types.h>
-
-int
-__setregid (gid_t rgid, gid_t egid)
-{
-  int result;
-
-  result = INLINE_SETXID_SYSCALL (setregid32, 2, rgid, egid);
-
-  return result;
-}
-#ifndef __setregid
-weak_alias (__setregid, setregid)
-#endif
diff --git a/sysdeps/unix/sysv/linux/i386/setresgid.c b/sysdeps/unix/sysv/linux/i386/setresgid.c
deleted file mode 100644
index 45d6769..0000000
--- a/sysdeps/unix/sysv/linux/i386/setresgid.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/* Copyright (C) 1998-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <unistd.h>
-#include <setxid.h>
-#include <linux/posix_types.h>
-
-
-int
-__setresgid (gid_t rgid, gid_t egid, gid_t sgid)
-{
-  int result;
-
-  result = INLINE_SETXID_SYSCALL (setresgid32, 3, rgid, egid, sgid);
-
-  return result;
-}
-libc_hidden_def (__setresgid)
-#ifndef __setresgid
-weak_alias (__setresgid, setresgid)
-#endif
diff --git a/sysdeps/unix/sysv/linux/i386/setresuid.c b/sysdeps/unix/sysv/linux/i386/setresuid.c
deleted file mode 100644
index 94a117e..0000000
--- a/sysdeps/unix/sysv/linux/i386/setresuid.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/* Copyright (C) 1998-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <unistd.h>
-#include <setxid.h>
-#include <linux/posix_types.h>
-
-
-int
-__setresuid (uid_t ruid, uid_t euid, uid_t suid)
-{
-  int result;
-
-  result = INLINE_SETXID_SYSCALL (setresuid32, 3, ruid, euid, suid);
-
-  return result;
-}
-libc_hidden_def (__setresuid)
-#ifndef __setresuid
-weak_alias (__setresuid, setresuid)
-#endif
diff --git a/sysdeps/unix/sysv/linux/i386/setreuid.c b/sysdeps/unix/sysv/linux/i386/setreuid.c
deleted file mode 100644
index ad18330..0000000
--- a/sysdeps/unix/sysv/linux/i386/setreuid.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Copyright (C) 1998-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <unistd.h>
-#include <setxid.h>
-#include <linux/posix_types.h>
-
-
-int
-__setreuid (uid_t ruid, uid_t euid)
-{
-  int result;
-
-  result = INLINE_SETXID_SYSCALL (setreuid32, 2, ruid, euid);
-
-  return result;
-}
-#ifndef __setreuid
-weak_alias (__setreuid, setreuid)
-#endif
diff --git a/sysdeps/unix/sysv/linux/i386/setuid.c b/sysdeps/unix/sysv/linux/i386/setuid.c
deleted file mode 100644
index b1fc9aa..0000000
--- a/sysdeps/unix/sysv/linux/i386/setuid.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Copyright (C) 1998-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <unistd.h>
-#include <setxid.h>
-#include <linux/posix_types.h>
-
-
-int
-__setuid (uid_t uid)
-{
-  int result;
-
-  result = INLINE_SETXID_SYSCALL (setuid32, 1, uid);
-
-  return result;
-}
-#ifndef __setuid
-weak_alias (__setuid, setuid)
-#endif
diff --git a/sysdeps/unix/sysv/linux/m68k/setegid.c b/sysdeps/unix/sysv/linux/m68k/setegid.c
deleted file mode 100644
index 2e3a54c..0000000
--- a/sysdeps/unix/sysv/linux/m68k/setegid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setegid.c>
diff --git a/sysdeps/unix/sysv/linux/m68k/seteuid.c b/sysdeps/unix/sysv/linux/m68k/seteuid.c
deleted file mode 100644
index 18e41d0..0000000
--- a/sysdeps/unix/sysv/linux/m68k/seteuid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/seteuid.c>
diff --git a/sysdeps/unix/sysv/linux/m68k/setgid.c b/sysdeps/unix/sysv/linux/m68k/setgid.c
deleted file mode 100644
index 377021d..0000000
--- a/sysdeps/unix/sysv/linux/m68k/setgid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setgid.c>
diff --git a/sysdeps/unix/sysv/linux/m68k/setgroups.c b/sysdeps/unix/sysv/linux/m68k/setgroups.c
deleted file mode 100644
index 0e70862..0000000
--- a/sysdeps/unix/sysv/linux/m68k/setgroups.c
+++ /dev/null
@@ -1,2 +0,0 @@
-/* We also have to rewrite the kernel gid_t to the user land type.  */
-#include <sysdeps/unix/sysv/linux/i386/setgroups.c>
diff --git a/sysdeps/unix/sysv/linux/m68k/setregid.c b/sysdeps/unix/sysv/linux/m68k/setregid.c
deleted file mode 100644
index 99c57ad..0000000
--- a/sysdeps/unix/sysv/linux/m68k/setregid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setregid.c>
diff --git a/sysdeps/unix/sysv/linux/m68k/setresgid.c b/sysdeps/unix/sysv/linux/m68k/setresgid.c
deleted file mode 100644
index daca1a4..0000000
--- a/sysdeps/unix/sysv/linux/m68k/setresgid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setresgid.c>
diff --git a/sysdeps/unix/sysv/linux/m68k/setresuid.c b/sysdeps/unix/sysv/linux/m68k/setresuid.c
deleted file mode 100644
index 3aeabe9..0000000
--- a/sysdeps/unix/sysv/linux/m68k/setresuid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setresuid.c>
diff --git a/sysdeps/unix/sysv/linux/m68k/setreuid.c b/sysdeps/unix/sysv/linux/m68k/setreuid.c
deleted file mode 100644
index 8ad6122..0000000
--- a/sysdeps/unix/sysv/linux/m68k/setreuid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setreuid.c>
diff --git a/sysdeps/unix/sysv/linux/m68k/setuid.c b/sysdeps/unix/sysv/linux/m68k/setuid.c
deleted file mode 100644
index de39437..0000000
--- a/sysdeps/unix/sysv/linux/m68k/setuid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setuid.c>
diff --git a/sysdeps/unix/sysv/linux/microblaze/setgroups.c b/sysdeps/unix/sysv/linux/microblaze/setgroups.c
deleted file mode 100644
index cb9a770..0000000
--- a/sysdeps/unix/sysv/linux/microblaze/setgroups.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setgroups.c>
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/setegid.c b/sysdeps/unix/sysv/linux/s390/s390-32/setegid.c
deleted file mode 100644
index 2e3a54c..0000000
--- a/sysdeps/unix/sysv/linux/s390/s390-32/setegid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setegid.c>
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/seteuid.c b/sysdeps/unix/sysv/linux/s390/s390-32/seteuid.c
deleted file mode 100644
index 18e41d0..0000000
--- a/sysdeps/unix/sysv/linux/s390/s390-32/seteuid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/seteuid.c>
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/setgid.c b/sysdeps/unix/sysv/linux/s390/s390-32/setgid.c
deleted file mode 100644
index 377021d..0000000
--- a/sysdeps/unix/sysv/linux/s390/s390-32/setgid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setgid.c>
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/setgroups.c b/sysdeps/unix/sysv/linux/s390/s390-32/setgroups.c
deleted file mode 100644
index 0e70862..0000000
--- a/sysdeps/unix/sysv/linux/s390/s390-32/setgroups.c
+++ /dev/null
@@ -1,2 +0,0 @@
-/* We also have to rewrite the kernel gid_t to the user land type.  */
-#include <sysdeps/unix/sysv/linux/i386/setgroups.c>
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/setregid.c b/sysdeps/unix/sysv/linux/s390/s390-32/setregid.c
deleted file mode 100644
index 99c57ad..0000000
--- a/sysdeps/unix/sysv/linux/s390/s390-32/setregid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setregid.c>
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/setresgid.c b/sysdeps/unix/sysv/linux/s390/s390-32/setresgid.c
deleted file mode 100644
index daca1a4..0000000
--- a/sysdeps/unix/sysv/linux/s390/s390-32/setresgid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setresgid.c>
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/setresuid.c b/sysdeps/unix/sysv/linux/s390/s390-32/setresuid.c
deleted file mode 100644
index 3aeabe9..0000000
--- a/sysdeps/unix/sysv/linux/s390/s390-32/setresuid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setresuid.c>
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/setreuid.c b/sysdeps/unix/sysv/linux/s390/s390-32/setreuid.c
deleted file mode 100644
index 8ad6122..0000000
--- a/sysdeps/unix/sysv/linux/s390/s390-32/setreuid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setreuid.c>
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/setuid.c b/sysdeps/unix/sysv/linux/s390/s390-32/setuid.c
deleted file mode 100644
index c8fa23e..0000000
--- a/sysdeps/unix/sysv/linux/s390/s390-32/setuid.c
+++ /dev/null
@@ -1,2 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setuid.c>
-
diff --git a/sysdeps/unix/sysv/linux/setegid.c b/sysdeps/unix/sysv/linux/setegid.c
index 62ca4ef..7d08027 100644
--- a/sysdeps/unix/sysv/linux/setegid.c
+++ b/sysdeps/unix/sysv/linux/setegid.c
@@ -26,10 +26,7 @@ setegid (gid_t gid)
   int result;
 
   if (gid == (gid_t) ~0)
-    {
-      __set_errno (EINVAL);
-      return -1;
-    }
+    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
 
 #ifdef __NR_setresgid32
   result = INLINE_SETXID_SYSCALL (setresgid32, 3, -1, gid, -1);
diff --git a/sysdeps/unix/sysv/linux/seteuid.c b/sysdeps/unix/sysv/linux/seteuid.c
index 469bc9a..ece0f45 100644
--- a/sysdeps/unix/sysv/linux/seteuid.c
+++ b/sysdeps/unix/sysv/linux/seteuid.c
@@ -26,10 +26,7 @@ seteuid (uid_t uid)
   int result;
 
   if (uid == (uid_t) ~0)
-    {
-      __set_errno (EINVAL);
-      return -1;
-    }
+    return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
 
 #ifdef __NR_setresuid32
   result = INLINE_SETXID_SYSCALL (setresuid32, 3, -1, uid, -1);
diff --git a/sysdeps/unix/sysv/linux/setgid.c b/sysdeps/unix/sysv/linux/setgid.c
index 401f998..59aaa10 100644
--- a/sysdeps/unix/sysv/linux/setgid.c
+++ b/sysdeps/unix/sysv/linux/setgid.c
@@ -23,7 +23,11 @@
 int
 __setgid (gid_t gid)
 {
+#ifdef __NR_setgid32
+  return INLINE_SETXID_SYSCALL (setgid32, 1, gid);
+#else
   return INLINE_SETXID_SYSCALL (setgid, 1, gid);
+#endif
 }
 #ifndef __setgid
 weak_alias (__setgid, setgid)
diff --git a/sysdeps/unix/sysv/linux/setgroups.c b/sysdeps/unix/sysv/linux/setgroups.c
index 25fad17..c556ebb 100644
--- a/sysdeps/unix/sysv/linux/setgroups.c
+++ b/sysdeps/unix/sysv/linux/setgroups.c
@@ -28,8 +28,9 @@ int
 setgroups (size_t n, const gid_t *groups)
 {
 #ifdef __NR_setgroups32
-# error "wrong setgroups.c file used"
-#endif
+  return INLINE_SETXID_SYSCALL (setgroups32, 2, n, groups);
+#else
   return INLINE_SETXID_SYSCALL (setgroups, 2, n, groups);
+#endif
 }
 libc_hidden_def (setgroups)
diff --git a/sysdeps/unix/sysv/linux/setregid.c b/sysdeps/unix/sysv/linux/setregid.c
index c48e524..b50842b 100644
--- a/sysdeps/unix/sysv/linux/setregid.c
+++ b/sysdeps/unix/sysv/linux/setregid.c
@@ -23,7 +23,11 @@
 int
 __setregid (gid_t rgid, gid_t egid)
 {
+#ifdef __NR_setregid32
+  return INLINE_SETXID_SYSCALL (setregid32, 2, rgid, egid);
+#else
   return INLINE_SETXID_SYSCALL (setregid, 2, rgid, egid);
+#endif
 }
 #ifndef __setregid
 weak_alias (__setregid, setregid)
diff --git a/sysdeps/unix/sysv/linux/setresgid.c b/sysdeps/unix/sysv/linux/setresgid.c
index d3496c2..1e9a9b7 100644
--- a/sysdeps/unix/sysv/linux/setresgid.c
+++ b/sysdeps/unix/sysv/linux/setresgid.c
@@ -23,7 +23,11 @@
 int
 __setresgid (gid_t rgid, gid_t egid, gid_t sgid)
 {
+#ifdef __NR_setresgid32
+  return INLINE_SETXID_SYSCALL (setresgid32, 3, rgid, egid, sgid);
+#else
   return INLINE_SETXID_SYSCALL (setresgid, 3, rgid, egid, sgid);
+#endif
 }
 libc_hidden_def (__setresgid)
 #ifndef __setresgid
diff --git a/sysdeps/unix/sysv/linux/setresuid.c b/sysdeps/unix/sysv/linux/setresuid.c
index 0f582f4..3d3faa9 100644
--- a/sysdeps/unix/sysv/linux/setresuid.c
+++ b/sysdeps/unix/sysv/linux/setresuid.c
@@ -23,7 +23,11 @@
 int
 __setresuid (uid_t ruid, uid_t euid, uid_t suid)
 {
+#ifdef __NR_setresuid32
+  return INLINE_SETXID_SYSCALL (setresuid32, 3, ruid, euid, suid);
+#else
   return INLINE_SETXID_SYSCALL (setresuid, 3, ruid, euid, suid);
+#endif
 }
 libc_hidden_def (__setresuid)
 #ifndef __setresuid
diff --git a/sysdeps/unix/sysv/linux/setreuid.c b/sysdeps/unix/sysv/linux/setreuid.c
index 377f5e5..5cc68ae 100644
--- a/sysdeps/unix/sysv/linux/setreuid.c
+++ b/sysdeps/unix/sysv/linux/setreuid.c
@@ -23,7 +23,11 @@
 int
 __setreuid (uid_t ruid, uid_t euid)
 {
+#ifdef __NR_setreuid32
+  return INLINE_SETXID_SYSCALL (setreuid32, 2, ruid, euid);
+#else
   return INLINE_SETXID_SYSCALL (setreuid, 2, ruid, euid);
+#endif
 }
 #ifndef __setreuid
 weak_alias (__setreuid, setreuid)
diff --git a/sysdeps/unix/sysv/linux/setuid.c b/sysdeps/unix/sysv/linux/setuid.c
index 6308e1a..2d07752 100644
--- a/sysdeps/unix/sysv/linux/setuid.c
+++ b/sysdeps/unix/sysv/linux/setuid.c
@@ -22,7 +22,11 @@
 int
 __setuid (uid_t uid)
 {
+#ifdef __NR_setuid32
+  return INLINE_SETXID_SYSCALL (setuid32, 1, uid);
+#else
   return INLINE_SETXID_SYSCALL (setuid, 1, uid);
+#endif
 }
 #ifndef __setuid
 weak_alias (__setuid, setuid)
diff --git a/sysdeps/unix/sysv/linux/sh/setegid.c b/sysdeps/unix/sysv/linux/sh/setegid.c
deleted file mode 100644
index 2e3a54c..0000000
--- a/sysdeps/unix/sysv/linux/sh/setegid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setegid.c>
diff --git a/sysdeps/unix/sysv/linux/sh/seteuid.c b/sysdeps/unix/sysv/linux/sh/seteuid.c
deleted file mode 100644
index 18e41d0..0000000
--- a/sysdeps/unix/sysv/linux/sh/seteuid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/seteuid.c>
diff --git a/sysdeps/unix/sysv/linux/sh/setgid.c b/sysdeps/unix/sysv/linux/sh/setgid.c
deleted file mode 100644
index 377021d..0000000
--- a/sysdeps/unix/sysv/linux/sh/setgid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setgid.c>
diff --git a/sysdeps/unix/sysv/linux/sh/setgroups.c b/sysdeps/unix/sysv/linux/sh/setgroups.c
deleted file mode 100644
index 0e70862..0000000
--- a/sysdeps/unix/sysv/linux/sh/setgroups.c
+++ /dev/null
@@ -1,2 +0,0 @@
-/* We also have to rewrite the kernel gid_t to the user land type.  */
-#include <sysdeps/unix/sysv/linux/i386/setgroups.c>
diff --git a/sysdeps/unix/sysv/linux/sh/setregid.c b/sysdeps/unix/sysv/linux/sh/setregid.c
deleted file mode 100644
index 99c57ad..0000000
--- a/sysdeps/unix/sysv/linux/sh/setregid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setregid.c>
diff --git a/sysdeps/unix/sysv/linux/sh/setresgid.c b/sysdeps/unix/sysv/linux/sh/setresgid.c
deleted file mode 100644
index daca1a4..0000000
--- a/sysdeps/unix/sysv/linux/sh/setresgid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setresgid.c>
diff --git a/sysdeps/unix/sysv/linux/sh/setresuid.c b/sysdeps/unix/sysv/linux/sh/setresuid.c
deleted file mode 100644
index 3aeabe9..0000000
--- a/sysdeps/unix/sysv/linux/sh/setresuid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setresuid.c>
diff --git a/sysdeps/unix/sysv/linux/sh/setreuid.c b/sysdeps/unix/sysv/linux/sh/setreuid.c
deleted file mode 100644
index 8ad6122..0000000
--- a/sysdeps/unix/sysv/linux/sh/setreuid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setreuid.c>
diff --git a/sysdeps/unix/sysv/linux/sh/setuid.c b/sysdeps/unix/sysv/linux/sh/setuid.c
deleted file mode 100644
index de39437..0000000
--- a/sysdeps/unix/sysv/linux/sh/setuid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setuid.c>
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/setegid.c b/sysdeps/unix/sysv/linux/sparc/sparc32/setegid.c
deleted file mode 100644
index 2e3a54c..0000000
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/setegid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setegid.c>
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/seteuid.c b/sysdeps/unix/sysv/linux/sparc/sparc32/seteuid.c
deleted file mode 100644
index 18e41d0..0000000
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/seteuid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/seteuid.c>
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/setgid.c b/sysdeps/unix/sysv/linux/sparc/sparc32/setgid.c
deleted file mode 100644
index 377021d..0000000
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/setgid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setgid.c>
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/setgroups.c b/sysdeps/unix/sysv/linux/sparc/sparc32/setgroups.c
deleted file mode 100644
index 0e70862..0000000
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/setgroups.c
+++ /dev/null
@@ -1,2 +0,0 @@
-/* We also have to rewrite the kernel gid_t to the user land type.  */
-#include <sysdeps/unix/sysv/linux/i386/setgroups.c>
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/setregid.c b/sysdeps/unix/sysv/linux/sparc/sparc32/setregid.c
deleted file mode 100644
index 99c57ad..0000000
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/setregid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setregid.c>
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/setresgid.c b/sysdeps/unix/sysv/linux/sparc/sparc32/setresgid.c
deleted file mode 100644
index daca1a4..0000000
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/setresgid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setresgid.c>
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/setresuid.c b/sysdeps/unix/sysv/linux/sparc/sparc32/setresuid.c
deleted file mode 100644
index 3aeabe9..0000000
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/setresuid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setresuid.c>
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/setreuid.c b/sysdeps/unix/sysv/linux/sparc/sparc32/setreuid.c
deleted file mode 100644
index 8ad6122..0000000
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/setreuid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setreuid.c>
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/setuid.c b/sysdeps/unix/sysv/linux/sparc/sparc32/setuid.c
deleted file mode 100644
index de39437..0000000
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/setuid.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/setuid.c>

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=57f0c99b3e0f7cca2b3f8182c9a431b7dc6be6fd

commit 57f0c99b3e0f7cca2b3f8182c9a431b7dc6be6fd
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Nov 28 15:18:22 2016 -0200

    Consolidate Linux fcntl implementation
    
    This patch consolidates the fcntl Linux syscall generation on
    sysdeps/unix/sysv/linux/fcntl.c.  It basically removes all the
    architecture define implementations.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/arm/fcntl.c: Remove file.
    	* sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c: Likewise.
    	* sysdeps/unix/sysv/linux/hppa/fcntl.c: Likewise.
    	* sysdeps/unix/sysv/linux/i386/fcntl.c: Likewise.
    	* sysdeps/unix/sysv/linux/m68k/fcntl.c: Likewise.
    	* sysdeps/unix/sysv/linux/microblaze/fcntl.c: Likewise.
    	* sysdeps/unix/sysv/linux/mips/mips32/fcntl.c: Likewise.
    	* sysdeps/unix/sysv/linux/mips/mips64/n32/fcntl.c: Likewise.
    	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fcntl.c: Likewise.
    	* sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c: Likewise.
    	* sysdeps/unix/sysv/linux/s390/s390-32/fcntl.c: Likewise.
    	* sysdeps/unix/sysv/linux/sh/fcntl.c: Likewise.
    	* sysdeps/unix/sysv/linux/sparc/sparc32/fcntl.c: Likewise.
    	* sysdeps/unix/sysv/linux/fcntl.c: New file.

diff --git a/ChangeLog b/ChangeLog
index 89e90c4..f642bc2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/arm/fcntl.c: Remove file.
+	* sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c: Likewise.
+	* sysdeps/unix/sysv/linux/hppa/fcntl.c: Likewise.
+	* sysdeps/unix/sysv/linux/i386/fcntl.c: Likewise.
+	* sysdeps/unix/sysv/linux/m68k/fcntl.c: Likewise.
+	* sysdeps/unix/sysv/linux/microblaze/fcntl.c: Likewise.
+	* sysdeps/unix/sysv/linux/mips/mips32/fcntl.c: Likewise.
+	* sysdeps/unix/sysv/linux/mips/mips64/n32/fcntl.c: Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fcntl.c: Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c: Likewise.
+	* sysdeps/unix/sysv/linux/s390/s390-32/fcntl.c: Likewise.
+	* sysdeps/unix/sysv/linux/sh/fcntl.c: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc32/fcntl.c: Likewise.
+	* sysdeps/unix/sysv/linux/fcntl.c: New file.
+
 	* rt/Makefile (CFLAGS-mq_timedsend.c): New flag.
 	* sysdeps/unix/sysv/linux/mq_timedsend.c: New file.
 	* sysdeps/unix/sysv/linux/syscalls.list (mq_timedsend): Remove from
diff --git a/sysdeps/unix/sysv/linux/arm/fcntl.c b/sysdeps/unix/sysv/linux/arm/fcntl.c
deleted file mode 100644
index ea951bc..0000000
--- a/sysdeps/unix/sysv/linux/arm/fcntl.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/fcntl.c>
diff --git a/sysdeps/unix/sysv/linux/fcntl.c b/sysdeps/unix/sysv/linux/fcntl.c
index 02f3252..1f0b661 100644
--- a/sysdeps/unix/sysv/linux/fcntl.c
+++ b/sysdeps/unix/sysv/linux/fcntl.c
@@ -15,31 +15,32 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <assert.h>
-#include <errno.h>
-#include <sysdep-cancel.h>	/* Must come before <fcntl.h>.  */
 #include <fcntl.h>
 #include <stdarg.h>
+#include <errno.h>
+#include <sysdep-cancel.h>
 
-#include <sys/syscall.h>
-
+#ifndef __NR_fcntl64
+# define __NR_fcntl64 __NR_fcntl
+#endif
 
 static int
-do_fcntl (int fd, int cmd, void *arg)
+fcntl_common (int fd, int cmd, void *arg)
 {
-  if (cmd != F_GETOWN)
-    return INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
-
-  INTERNAL_SYSCALL_DECL (err);
-  struct f_owner_ex fex;
-  int res = INTERNAL_SYSCALL (fcntl, err, 3, fd, F_GETOWN_EX, &fex);
-  if (!INTERNAL_SYSCALL_ERROR_P (res, err))
-    return fex.type == F_OWNER_GID ? -fex.pid : fex.pid;
-
-  return INLINE_SYSCALL_ERROR_RETURN_VALUE (INTERNAL_SYSCALL_ERRNO (res,
+  if (cmd == F_GETOWN)
+    {
+      INTERNAL_SYSCALL_DECL (err);
+      struct f_owner_ex fex;
+      int res = INTERNAL_SYSCALL_CALL (fcntl64, err, fd, F_GETOWN_EX, &fex);
+      if (!INTERNAL_SYSCALL_ERROR_P (res, err))
+	return fex.type == F_OWNER_GID ? -fex.pid : fex.pid;
+
+      return INLINE_SYSCALL_ERROR_RETURN_VALUE (INTERNAL_SYSCALL_ERRNO (res,
 								    err));
-}
+    }
 
+  return INLINE_SYSCALL_CALL (fcntl64, fd, cmd, (void *) arg);
+}
 
 #ifndef NO_CANCELLATION
 int
@@ -52,11 +53,10 @@ __fcntl_nocancel (int fd, int cmd, ...)
   arg = va_arg (ap, void *);
   va_end (ap);
 
-  return do_fcntl (fd, cmd, arg);
+  return fcntl_common (fd, cmd, arg);
 }
 #endif
 
-
 int
 __libc_fcntl (int fd, int cmd, ...)
 {
@@ -67,16 +67,10 @@ __libc_fcntl (int fd, int cmd, ...)
   arg = va_arg (ap, void *);
   va_end (ap);
 
-  if (SINGLE_THREAD_P || cmd != F_SETLKW)
-    return do_fcntl (fd, cmd, arg);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = do_fcntl (fd, cmd, arg);
-
-  LIBC_CANCEL_RESET (oldtype);
+  if (cmd == F_SETLKW || cmd == F_SETLKW64)
+    return SYSCALL_CANCEL (fcntl64, fd, cmd, (void *) arg);
 
-  return result;
+  return fcntl_common (fd, cmd, arg);
 }
 libc_hidden_def (__libc_fcntl)
 
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c
deleted file mode 100644
index 20399f9..0000000
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/* Copyright (C) 2011-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library.  If not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <assert.h>
-#include <errno.h>
-#include <sysdep-cancel.h>	/* Must come before <fcntl.h>.  */
-#include <fcntl.h>
-#include <stdarg.h>
-
-#include <sys/syscall.h>
-
-
-static int
-do_fcntl (int fd, int cmd, void *arg)
-{
-  if (cmd != F_GETOWN)
-    return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
-
-  INTERNAL_SYSCALL_DECL (err);
-  struct f_owner_ex fex;
-  int res = INTERNAL_SYSCALL (fcntl64, err, 3, fd, F_GETOWN_EX, &fex);
-  if (!INTERNAL_SYSCALL_ERROR_P (res, err))
-    return fex.type == F_OWNER_GID ? -fex.pid : fex.pid;
-
-  __set_errno (INTERNAL_SYSCALL_ERRNO (res, err));
-  return -1;
-}
-
-
-#ifndef NO_CANCELLATION
-int
-__fcntl_nocancel (int fd, int cmd, ...)
-{
-  va_list ap;
-  void *arg;
-
-  va_start (ap, cmd);
-  arg = va_arg (ap, void *);
-  va_end (ap);
-
-  return do_fcntl (fd, cmd, arg);
-}
-#endif
-
-
-int
-__libc_fcntl (int fd, int cmd, ...)
-{
-  va_list ap;
-  void *arg;
-
-  va_start (ap, cmd);
-  arg = va_arg (ap, void *);
-  va_end (ap);
-
-  if (SINGLE_THREAD_P || cmd != F_SETLKW)
-    return do_fcntl (fd, cmd, arg);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = do_fcntl (fd, cmd, arg);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
-}
-libc_hidden_def (__libc_fcntl)
-
-weak_alias (__libc_fcntl, __fcntl)
-libc_hidden_weak (__fcntl)
-weak_alias (__libc_fcntl, fcntl)
diff --git a/sysdeps/unix/sysv/linux/hppa/fcntl.c b/sysdeps/unix/sysv/linux/hppa/fcntl.c
deleted file mode 100644
index ea951bc..0000000
--- a/sysdeps/unix/sysv/linux/hppa/fcntl.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/fcntl.c>
diff --git a/sysdeps/unix/sysv/linux/i386/fcntl.c b/sysdeps/unix/sysv/linux/i386/fcntl.c
deleted file mode 100644
index b0a5783..0000000
--- a/sysdeps/unix/sysv/linux/i386/fcntl.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/* Copyright (C) 2000-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <assert.h>
-#include <errno.h>
-#include <sysdep-cancel.h>	/* Must come before <fcntl.h>.  */
-#include <fcntl.h>
-#include <stdarg.h>
-
-#include <sys/syscall.h>
-
-#ifndef NO_CANCELLATION
-int
-__fcntl_nocancel (int fd, int cmd, ...)
-{
-  va_list ap;
-  void *arg;
-
-  va_start (ap, cmd);
-  arg = va_arg (ap, void *);
-  va_end (ap);
-
-  return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
-}
-#endif /* NO_CANCELLATION */
-
-
-int
-__libc_fcntl (int fd, int cmd, ...)
-{
-  va_list ap;
-  void *arg;
-
-  va_start (ap, cmd);
-  arg = va_arg (ap, void *);
-  va_end (ap);
-
-  if ((cmd != F_SETLKW) && (cmd != F_SETLKW64))
-    return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
-
-  return SYSCALL_CANCEL (fcntl64, fd, cmd, arg);
-}
-libc_hidden_def (__libc_fcntl)
-
-weak_alias (__libc_fcntl, __fcntl)
-libc_hidden_weak (__fcntl)
-weak_alias (__libc_fcntl, fcntl)
diff --git a/sysdeps/unix/sysv/linux/m68k/fcntl.c b/sysdeps/unix/sysv/linux/m68k/fcntl.c
deleted file mode 100644
index ea951bc..0000000
--- a/sysdeps/unix/sysv/linux/m68k/fcntl.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/fcntl.c>
diff --git a/sysdeps/unix/sysv/linux/microblaze/fcntl.c b/sysdeps/unix/sysv/linux/microblaze/fcntl.c
deleted file mode 100644
index ea951bc..0000000
--- a/sysdeps/unix/sysv/linux/microblaze/fcntl.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/fcntl.c>
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/fcntl.c b/sysdeps/unix/sysv/linux/mips/mips32/fcntl.c
deleted file mode 100644
index ea951bc..0000000
--- a/sysdeps/unix/sysv/linux/mips/mips32/fcntl.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/fcntl.c>
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/fcntl.c b/sysdeps/unix/sysv/linux/mips/mips64/n32/fcntl.c
deleted file mode 100644
index ea951bc..0000000
--- a/sysdeps/unix/sysv/linux/mips/mips64/n32/fcntl.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/fcntl.c>
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fcntl.c b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fcntl.c
deleted file mode 100644
index ea951bc..0000000
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fcntl.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/fcntl.c>
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c b/sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c
deleted file mode 100644
index 85ae8a2..0000000
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/* Copyright (C) 2000-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <assert.h>
-#include <errno.h>
-#include <sysdep-cancel.h>	/* Must come before <fcntl.h>.  */
-#include <fcntl.h>
-#include <stdarg.h>
-
-#include <sys/syscall.h>
-
-
-#ifndef NO_CANCELLATION
-int
-__fcntl_nocancel (int fd, int cmd, ...)
-{
-  va_list ap;
-  void *arg;
-
-  va_start (ap, cmd);
-  arg = va_arg (ap, void *);
-  va_end (ap);
-
-  return INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
-}
-#endif
-
-
-int
-__libc_fcntl (int fd, int cmd, ...)
-{
-  va_list ap;
-  void *arg;
-
-  va_start (ap, cmd);
-  arg = va_arg (ap, void *);
-  va_end (ap);
-
-  if (cmd >= F_GETLK64 && cmd <= F_SETLKW64)
-    cmd -= F_GETLK64 - F_GETLK;
-
-  if (cmd != F_SETLKW)
-    return INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
-
-  return SYSCALL_CANCEL (fcntl, fd, cmd, arg);
-}
-libc_hidden_def (__libc_fcntl)
-
-weak_alias (__libc_fcntl, __fcntl)
-libc_hidden_weak (__fcntl)
-weak_alias (__libc_fcntl, fcntl)
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/fcntl.c b/sysdeps/unix/sysv/linux/s390/s390-32/fcntl.c
deleted file mode 100644
index ea951bc..0000000
--- a/sysdeps/unix/sysv/linux/s390/s390-32/fcntl.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/fcntl.c>
diff --git a/sysdeps/unix/sysv/linux/sh/fcntl.c b/sysdeps/unix/sysv/linux/sh/fcntl.c
deleted file mode 100644
index ea951bc..0000000
--- a/sysdeps/unix/sysv/linux/sh/fcntl.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/fcntl.c>
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/fcntl.c b/sysdeps/unix/sysv/linux/sparc/sparc32/fcntl.c
deleted file mode 100644
index ea951bc..0000000
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/fcntl.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/fcntl.c>

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=a09c5b85d23e2e835d68ea873888e58ac95c7968

commit a09c5b85d23e2e835d68ea873888e58ac95c7968
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Wed Nov 4 10:40:20 2015 -0200

    Consolidate Linux mq_timedsend syscall
    
    This patch consolidates the mq_timedsend Linux syscall generation
    on sysdeps/unix/sysv/linux/mq_timedsend.c.  It basically removes it
    from architecture auto-generation list.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* rt/Makefile (CFLAGS-mq_timedsend.c): New flag.
    	* sysdeps/unix/sysv/linux/mq_timedsend.c: New file.
    	* sysdeps/unix/sysv/linux/syscalls.list (mq_timedsend): Remove from
    	auto-generation list.

diff --git a/ChangeLog b/ChangeLog
index 4fa44c6..89e90c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* rt/Makefile (CFLAGS-mq_timedsend.c): New flag.
+	* sysdeps/unix/sysv/linux/mq_timedsend.c: New file.
+	* sysdeps/unix/sysv/linux/syscalls.list (mq_timedsend): Remove from
+	auto-generation list.
+
 	* rt/Makefile (CFLAGS-mq_timedreceive.c): New flag.
 	* sysdeps/unix/sysv/linux/mq_timedreceive.c: New file.
 	* sysdeps/unix/sysv/linux/syscalls.list (mq_timedreceive): Remove
diff --git a/rt/Makefile b/rt/Makefile
index 0ffa12d..9740dc2 100644
--- a/rt/Makefile
+++ b/rt/Makefile
@@ -62,6 +62,7 @@ include ../Rules
 
 CFLAGS-aio_suspend.c = -fexceptions
 CFLAGS-mq_timedreceive.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-mq_timedsend.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-clock_nanosleep.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-librt-cancellation.c = -fasynchronous-unwind-tables
 
diff --git a/sysdeps/unix/sysv/linux/mq_timedsend.c b/sysdeps/unix/sysv/linux/mq_timedsend.c
new file mode 100644
index 0000000..7995554
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/mq_timedsend.c
@@ -0,0 +1,33 @@
+/* Send a message to a message queue with a timeout.  Linux version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <mqueue.h>
+#include <sysdep-cancel.h>
+
+/* Add message pointed by MSG_PTR to message queue MQDES, stop blocking
+   on full message queue if ABS_TIMEOUT expires.  */
+int
+__mq_timedsend (mqd_t mqdes, const char *msg_ptr, size_t msg_len,
+		unsigned int msg_prio, const struct timespec *abs_timeout)
+{
+  return SYSCALL_CANCEL (mq_timedsend, mqdes, msg_ptr, msg_len, msg_prio,
+			 abs_timeout);
+}
+hidden_def (__mq_timedsend)
+weak_alias (__mq_timedsend, mq_timedsend)
+hidden_weak (mq_timedsend)
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index 63914bc..8bfb080 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -95,7 +95,6 @@ removexattr	-	removexattr	i:ss	removexattr
 lremovexattr	-	lremovexattr	i:ss	lremovexattr
 fremovexattr	-	fremovexattr	i:is	fremovexattr
 
-mq_timedsend	-	mq_timedsend	Ci:ipiip	__mq_timedsend	mq_timedsend
 mq_setattr	-	mq_getsetattr	i:ipp	mq_setattr
 
 timerfd_create	EXTRA	timerfd_create	i:ii	timerfd_create

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=5063c8b286bab603ea07639aba9964a2774fa565

commit 5063c8b286bab603ea07639aba9964a2774fa565
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Wed Nov 4 10:32:58 2015 -0200

    Consolidate Linux mq_timedreceive syscall
    
    This patch consolidates the mq_timedreceive Linux syscall generation
    on sysdeps/unix/sysv/linux/mq_timedreceive.c.  It basically removes it
    from architecture auto-generation list.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* rt/Makefile (CFLAGS-mq_timedreceive.c): New flag.
    	* sysdeps/unix/sysv/linux/mq_timedreceive.c: New file.
    	* sysdeps/unix/sysv/linux/syscalls.list (mq_timedreceive): Remove
    	from auto-generation list.

diff --git a/ChangeLog b/ChangeLog
index 96b32ff..4fa44c6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* rt/Makefile (CFLAGS-mq_timedreceive.c): New flag.
+	* sysdeps/unix/sysv/linux/mq_timedreceive.c: New file.
+	* sysdeps/unix/sysv/linux/syscalls.list (mq_timedreceive): Remove
+	from auto-generation list.
+
 	* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Add
 	open_by_handle_at.
 	(CFLAGS-open_by_handle_at.c): New flag.
diff --git a/rt/Makefile b/rt/Makefile
index 5283839..0ffa12d 100644
--- a/rt/Makefile
+++ b/rt/Makefile
@@ -61,6 +61,7 @@ extra-libs-others := $(extra-libs)
 include ../Rules
 
 CFLAGS-aio_suspend.c = -fexceptions
+CFLAGS-mq_timedreceive.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-clock_nanosleep.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-librt-cancellation.c = -fasynchronous-unwind-tables
 
diff --git a/sysdeps/unix/sysv/linux/mq_timedreceive.c b/sysdeps/unix/sysv/linux/mq_timedreceive.c
new file mode 100644
index 0000000..6d1c145
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/mq_timedreceive.c
@@ -0,0 +1,34 @@
+/* Receive a message from a message queue with a timeout.  Linux version.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <mqueue.h>
+#include <sysdep-cancel.h>
+
+/* Receive the oldest from highest priority messages in message queue
+   MQDES, stop waiting if ABS_TIMEOUT expires.  */
+ssize_t
+__mq_timedreceive (mqd_t mqdes, char *__restrict msg_ptr, size_t msg_len,
+		   unsigned int *__restrict msg_prio,
+		   const struct timespec *__restrict abs_timeout)
+{
+  return SYSCALL_CANCEL (mq_timedreceive, mqdes, msg_ptr, msg_len, msg_prio,
+			 abs_timeout);
+}
+hidden_def (__mq_timedreceive)
+weak_alias (__mq_timedreceive, mq_timedreceive)
+hidden_weak (mq_timedreceive)
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index a8d1299..63914bc 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -96,7 +96,6 @@ lremovexattr	-	lremovexattr	i:ss	lremovexattr
 fremovexattr	-	fremovexattr	i:is	fremovexattr
 
 mq_timedsend	-	mq_timedsend	Ci:ipiip	__mq_timedsend	mq_timedsend
-mq_timedreceive	-	mq_timedreceive	Ci:ipipp	__mq_timedreceive	mq_timedreceive
 mq_setattr	-	mq_getsetattr	i:ipp	mq_setattr
 
 timerfd_create	EXTRA	timerfd_create	i:ii	timerfd_create

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=5774bf26e75a5a759346633a91078bd72f81de90

commit 5774bf26e75a5a759346633a91078bd72f81de90
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Nov 2 11:42:09 2015 -0200

    Consolidate Linux open_by_handle_at syscall
    
    This patch consolidates the open_by_handle_at Linux syscall generation on
    sysdeps/unix/sysv/linux/fdatasync.c.  It basically removes it from
    architectures auto-generation list.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Add
    	open_by_handle_at.
    	(CFLAGS-open_by_handle_at.c): New flag.
    	* sysdeps/unix/sysv/linux/open_by_handle_at.c: New file.
    	* sysdeps/unix/sysv/linux/syscalls.list (open_by_handle_at): New
    	file.

diff --git a/ChangeLog b/ChangeLog
index 521a90f..96b32ff 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Add
+	open_by_handle_at.
+	(CFLAGS-open_by_handle_at.c): New flag.
+	* sysdeps/unix/sysv/linux/open_by_handle_at.c: New file.
+	* sysdeps/unix/sysv/linux/syscalls.list (open_by_handle_at): New
+	file.
+
 	* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Add splice.
 	(CFLAGS-splice.c): New flag.
 	* sysdeps/unix/sysv/linux/splice.c: New file.
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index fcdfa31..5610784 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -17,7 +17,8 @@ include $(firstword $(wildcard $(sysdirs:=/sysctl.mk)))
 sysdep_routines += clone umount umount2 readahead \
 		   setfsuid setfsgid epoll_pwait signalfd \
 		   eventfd eventfd_read eventfd_write prlimit \
-		   personality epoll_wait tee vmsplice splice
+		   personality epoll_wait tee vmsplice splice \
+		   open_by_handle_at
 
 CFLAGS-gethostid.c = -fexceptions
 CFLAGS-tst-writev.c += "-DARTIFICIAL_LIMIT=0x80000000-__getpagesize()"
diff --git a/sysdeps/unix/sysv/linux/open_by_handle_at.c b/sysdeps/unix/sysv/linux/open_by_handle_at.c
new file mode 100644
index 0000000..e69f041
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/open_by_handle_at.c
@@ -0,0 +1,37 @@
+/* Obtain handle for an open file via a handle.  Linux implementation.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sysdep-cancel.h>
+
+int
+open_by_handle_at (int mount_fd, struct file_handle *handle, int flags)
+{
+#ifdef __NR_open_by_handle_at
+  return SYSCALL_CANCEL (open_by_handle_at, mount_fd, handle, flags);
+#else
+  __set_errno (ENOSYS);
+  return -1;
+#endif
+}
+
+#ifndef __NR_open_by_handle_at
+stub_warning (open_by_handle_at)
+#endif
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index b40825a..a8d1299 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -106,7 +106,6 @@ timerfd_gettime	EXTRA	timerfd_gettime	i:ip	timerfd_gettime
 fanotify_init	EXTRA	fanotify_init	i:ii	fanotify_init
 
 name_to_handle_at EXTRA	name_to_handle_at i:isppi name_to_handle_at
-open_by_handle_at EXTRA	open_by_handle_at Ci:ipi  open_by_handle_at
 
 setns		EXTRA	setns		i:ii	setns
 

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=a783eb75c2f24501c15b8ba40d093f346470c341

commit a783eb75c2f24501c15b8ba40d093f346470c341
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Nov 2 11:22:30 2015 -0200

    Consolidate Linux splice syscall
    
    This patch consolidates the splice Linux syscall generation on
    sysdeps/unix/sysv/linux/splice.c.  It basically removes it from
    architectures auto-generation list.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Add splice.
    	(CFLAGS-splice.c): New flag.
    	* sysdeps/unix/sysv/linux/splice.c: New file.
    	* sysdeps/unix/sysv/linux/syscalls.list (splice): Remove from
    	auto-generation syscall list.

diff --git a/ChangeLog b/ChangeLog
index 874ea90..521a90f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Add splice.
+	(CFLAGS-splice.c): New flag.
+	* sysdeps/unix/sysv/linux/splice.c: New file.
+	* sysdeps/unix/sysv/linux/syscalls.list (splice): Remove from
+	auto-generation syscall list.
+
 	* sysdeps/unix/sysv/linux/Makefile (CFLAGS-vmsplice.c): New flag.
 	* sysdeps/unix/sysv/linux/syscalls.list (vmsplice): Remove from
 	auto-generation syscall list.
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 8e7c6e5..fcdfa31 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -17,7 +17,7 @@ include $(firstword $(wildcard $(sysdirs:=/sysctl.mk)))
 sysdep_routines += clone umount umount2 readahead \
 		   setfsuid setfsgid epoll_pwait signalfd \
 		   eventfd eventfd_read eventfd_write prlimit \
-		   personality epoll_wait tee vmsplice
+		   personality epoll_wait tee vmsplice splice
 
 CFLAGS-gethostid.c = -fexceptions
 CFLAGS-tst-writev.c += "-DARTIFICIAL_LIMIT=0x80000000-__getpagesize()"
diff --git a/sysdeps/unix/sysv/linux/splice.c b/sysdeps/unix/sysv/linux/splice.c
new file mode 100644
index 0000000..2aaf878
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/splice.c
@@ -0,0 +1,27 @@
+/* Splice data to/from a pipe Linux implementation.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fcntl.h>
+#include <sysdep-cancel.h>
+
+ssize_t
+splice (int fd_in, loff_t *off_in, int fd_out, loff_t *off_out, size_t len,
+	unsigned int flags)
+{
+  return SYSCALL_CANCEL (splice, fd_in, off_in, fd_out, off_out, len, flags);
+}
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index 9d7bd65..b40825a 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -64,7 +64,6 @@ setfsgid	EXTRA	setfsgid	i:i	setfsgid
 setfsuid	EXTRA	setfsuid	i:i	setfsuid
 setpgid		-	setpgid		i:ii	__setpgid	setpgid
 sigaltstack	-	sigaltstack	i:PP	__sigaltstack	sigaltstack
-splice		EXTRA	splice		Ci:iPiPii	splice
 stime		-	stime		i:p	stime
 sysinfo		EXTRA	sysinfo		i:p	__sysinfo	sysinfo
 swapon		-	swapon		i:si	__swapon	swapon

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=2cda1d90c811f2dbdd2300f0f374555cf2c2f934

commit 2cda1d90c811f2dbdd2300f0f374555cf2c2f934
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Nov 2 11:13:24 2015 -0200

    Consolidate Linux vmsplice syscall
    
    This patch consolidates the vmsplice Linux syscall generation on
    sysdeps/unix/sysv/linux/vmsplice.c.  It basically removes it from
    architectures auto-generation list.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/Makefile (CFLAGS-vmsplice.c): New flag.
    	* sysdeps/unix/sysv/linux/syscalls.list (vmsplice): Remove from
    	auto-generation syscall list.
    	* sysdeps/unix/sysv/linux/vmsplice.c: New file.

diff --git a/ChangeLog b/ChangeLog
index 5c38bad..874ea90 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/Makefile (CFLAGS-vmsplice.c): New flag.
+	* sysdeps/unix/sysv/linux/syscalls.list (vmsplice): Remove from
+	auto-generation syscall list.
+	* sysdeps/unix/sysv/linux/vmsplice.c: New file.
+
 	* misc/Makefile (CFLAGS-fsync.c): New flag.
 	* nptl/Makefile (CFLAGS-fsync.c): Likewise.
 	* sysdeps/unix/syscalls.list (fsync): Remove from auto-generation
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index f292d5b..8e7c6e5 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -17,7 +17,7 @@ include $(firstword $(wildcard $(sysdirs:=/sysctl.mk)))
 sysdep_routines += clone umount umount2 readahead \
 		   setfsuid setfsgid epoll_pwait signalfd \
 		   eventfd eventfd_read eventfd_write prlimit \
-		   personality epoll_wait tee
+		   personality epoll_wait tee vmsplice
 
 CFLAGS-gethostid.c = -fexceptions
 CFLAGS-tst-writev.c += "-DARTIFICIAL_LIMIT=0x80000000-__getpagesize()"
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index c69eff4..9d7bd65 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -72,7 +72,6 @@ swapoff		-	swapoff		i:s	__swapoff	swapoff
 unshare		EXTRA	unshare		i:i	unshare
 uselib		EXTRA	uselib		i:s	__compat_uselib	uselib@GLIBC_2.0:GLIBC_2.23
 utime		-	utime		i:sP	utime
-vmsplice	EXTRA	vmsplice	Ci:iPii	vmsplice
 wait4		-	wait4		i:iWiP	__wait4		wait4
 
 chown		-	chown		i:sii	__libc_chown	__chown chown
diff --git a/sysdeps/unix/sysv/linux/vmsplice.c b/sysdeps/unix/sysv/linux/vmsplice.c
new file mode 100644
index 0000000..01dac13
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/vmsplice.c
@@ -0,0 +1,27 @@
+/* Splice user pages into a pipe Linux implementation.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fcntl.h>
+#include <sys/uio.h>
+#include <sysdep-cancel.h>
+
+ssize_t
+vmsplice (int fd, const struct iovec *iov, size_t count, unsigned int flags)
+{
+  return SYSCALL_CANCEL (vmsplice, fd, iov, count, flags);
+}

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=c25f98fc4499f6b5016308eba758eca97fd7adb5

commit c25f98fc4499f6b5016308eba758eca97fd7adb5
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Nov 2 12:14:35 2015 -0200

    Consolidate Linux fsync syscall
    
    This patch consolidates the fsync Linux syscall generation on
    sysdeps/unix/sysv/linux/fsync.c.  It basically removes it from
    architectures auto-generation list.
    
    	* misc/Makefile (CFLAGS-fsync.c): New flag.
    	* nptl/Makefile (CFLAGS-fsync.c): Likewise.
    	* sysdeps/unix/syscalls.list (fsync): Remove from auto-generation
    	syscall list.
    	* sysdeps/unix/sysv/linux/fsync.c: New file.

diff --git a/ChangeLog b/ChangeLog
index b5ce399..5c38bad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* misc/Makefile (CFLAGS-fsync.c): New flag.
+	* nptl/Makefile (CFLAGS-fsync.c): Likewise.
+	* sysdeps/unix/syscalls.list (fsync): Remove from auto-generation
+	syscall list.
+	* sysdeps/unix/sysv/linux/fsync.c: New file.
+
 	* misc/Makefile (CFLAGS-fdatasync.c): New rule.
 	* nptl/Makefile (CFLAGS-fdatasync.c): Likewise.
 	* sysdeps/unix/syscalls.list: Remove fdatasync from auto-generation
diff --git a/misc/Makefile b/misc/Makefile
index 54e9169..c7063b3 100644
--- a/misc/Makefile
+++ b/misc/Makefile
@@ -109,6 +109,7 @@ CFLAGS-err.c = -fexceptions
 CFLAGS-tst-tsearch.c = $(stack-align-test-flags)
 CFLAGS-msync.c = -fexceptions
 CFLAGS-fdatasync.c = -fexceptions
+CFLAGS-fsync.c = -fexceptions
 
 # Called during static library initialization, so turn stack-protection
 # off for non-shared builds.
diff --git a/nptl/Makefile b/nptl/Makefile
index c380b4f..e7961f1 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -219,6 +219,7 @@ CFLAGS-write.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-nanosleep.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-msync.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-fdatasync.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-fsync.c = -fexceptions -fasynchronous-unwind-tables
 
 CFLAGS-pt-system.c = -fexceptions
 
diff --git a/sysdeps/unix/syscalls.list b/sysdeps/unix/syscalls.list
index c4135d8..61e5360 100644
--- a/sysdeps/unix/syscalls.list
+++ b/sysdeps/unix/syscalls.list
@@ -19,7 +19,6 @@ fchmod		-	fchmod		i:ii	__fchmod	fchmod
 fchown		-	fchown		i:iii	__fchown	fchown
 fcntl		-	fcntl		Ci:iiF	__libc_fcntl	__fcntl fcntl
 fstatfs		-	fstatfs		i:ip	__fstatfs	fstatfs
-fsync		-	fsync		Ci:i	__libc_fsync	fsync
 ftruncate	-	ftruncate	i:ii	__ftruncate	ftruncate
 getdomain	-	getdomainname	i:si	getdomainname
 getgid		-	getgid		Ei:	__getgid	getgid
diff --git a/sysdeps/unix/sysv/linux/fsync.c b/sysdeps/unix/sysv/linux/fsync.c
new file mode 100644
index 0000000..ac4827b
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/fsync.c
@@ -0,0 +1,28 @@
+/* Synchronize a file's in-core state with storage device Linux
+   implementation.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <unistd.h>
+#include <sysdep-cancel.h>
+
+/* Make all changes done to FD actually appear on disk.  */
+int
+fsync (int fd)
+{
+  return SYSCALL_CANCEL (fsync, fd);
+}

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=99371f3c1659624e8a7dd4b9877573ba968725bb

commit 99371f3c1659624e8a7dd4b9877573ba968725bb
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Nov 2 11:00:39 2015 -0200

    Consolidate Linux fdatasync syscall
    
    This patch consolidates the fdatasync Linux syscall generation on
    sysdeps/unix/sysv/linux/fdatasync.c.  It basically removes it from
    architectures auto-generation list.
    
    	* misc/makefile (CFLAGS-datasync.c): New flag.
    	* nptl/makefile (CFLAGS-datasync.c): Likewise.
    	* sysdeps/unix/sysv/linux/syscalls.list (fdatasync): Remove from
    	auto-generation syscall list.
    	* sysdeps/unix/sysv/linux/fdatasync.c: New file.

diff --git a/ChangeLog b/ChangeLog
index 7dc38e6..b5ce399 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* misc/Makefile (CFLAGS-fdatasync.c): New rule.
+	* nptl/Makefile (CFLAGS-fdatasync.c): Likewise.
+	* sysdeps/unix/syscalls.list: Remove fdatasync from auto-generation
+	list.
+	* sysdeps/unix/sysv/linux/fdatasync.c: New file.
+
 	* misc/Makefile (CFLAGS-msync.c): New rule.
 	* nptl/Makefile (CFLAGS-msync.c): Likewise.
 	* sysdeps/unix/syscalls.list: Remove msync from auto-generation list.
diff --git a/misc/Makefile b/misc/Makefile
index c64db2e..54e9169 100644
--- a/misc/Makefile
+++ b/misc/Makefile
@@ -108,6 +108,7 @@ CFLAGS-getusershell.c = -fexceptions
 CFLAGS-err.c = -fexceptions
 CFLAGS-tst-tsearch.c = $(stack-align-test-flags)
 CFLAGS-msync.c = -fexceptions
+CFLAGS-fdatasync.c = -fexceptions
 
 # Called during static library initialization, so turn stack-protection
 # off for non-shared builds.
diff --git a/nptl/Makefile b/nptl/Makefile
index d9aafc4..c380b4f 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -218,6 +218,7 @@ CFLAGS-read.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-write.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-nanosleep.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-msync.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-fdatasync.c = -fexceptions -fasynchronous-unwind-tables
 
 CFLAGS-pt-system.c = -fexceptions
 
diff --git a/sysdeps/unix/sysv/linux/fdatasync.c b/sysdeps/unix/sysv/linux/fdatasync.c
new file mode 100644
index 0000000..09a07fb
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/fdatasync.c
@@ -0,0 +1,29 @@
+/* Synchronize a file's in-core state with storage device Linux
+   implementation.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <unistd.h>
+#include <sysdep-cancel.h>
+
+/* Synchronize at least the data part of a file with the underlying
+   media.  */
+int
+fdatasync (int fd)
+{
+  return SYSCALL_CANCEL (fdatasync, fd);
+}
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index ae99acd..c69eff4 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -13,7 +13,6 @@ epoll_create1	EXTRA	epoll_create1	i:i	epoll_create1
 epoll_ctl	EXTRA	epoll_ctl	i:iiip	epoll_ctl
 eventfd		EXTRA	eventfd2	i:ii	eventfd
 execve		-	execve		i:spp	__execve	execve
-fdatasync	-	fdatasync	Ci:i	fdatasync
 flock		-	flock		i:ii	__flock		flock
 get_kernel_syms	EXTRA	get_kernel_syms	i:p	__compat_get_kernel_syms	get_kernel_syms@GLIBC_2.0:GLIBC_2.23
 getpid          -       getpid          Ei:     __getpid        getpid

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=9b714e881747270326529c3a0dd5d6d13dfe73ff

commit 9b714e881747270326529c3a0dd5d6d13dfe73ff
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Nov 2 10:53:29 2015 -0200

    Consolidate Linux msync syscall
    
    This patch consolidates the msync Linux syscall generation on
    sysdeps/unix/sysv/linux/msync.c.  It basically removes it from
    architectures auto-generation list.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    arch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* misc/Makefile (CFLAGS-msync.c): New rule.
    	* nptl/Makefile (CFLAGS-msync.c): Likewise.
    	* sysdeps/unix/syscalls.list: Remove msync from auto-generation list.
    	* sysdeps/unix/sysv/linux/msync.c: New file.

diff --git a/ChangeLog b/ChangeLog
index 7cedd95..7dc38e6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* misc/Makefile (CFLAGS-msync.c): New rule.
+	* nptl/Makefile (CFLAGS-msync.c): Likewise.
+	* sysdeps/unix/syscalls.list: Remove msync from auto-generation list.
+	* sysdeps/unix/sysv/linux/msync.c: New file.
+
 	* sysdeps/unix/sysv/linux/alpha/sigsuspend.S: Remove file.
 	* sysdeps/unix/sysv/linux/sigsuspend.c: Simplify include list.
 
diff --git a/misc/Makefile b/misc/Makefile
index ed988c3..c64db2e 100644
--- a/misc/Makefile
+++ b/misc/Makefile
@@ -107,6 +107,7 @@ CFLAGS-getsysstats.c = -fexceptions
 CFLAGS-getusershell.c = -fexceptions
 CFLAGS-err.c = -fexceptions
 CFLAGS-tst-tsearch.c = $(stack-align-test-flags)
+CFLAGS-msync.c = -fexceptions
 
 # Called during static library initialization, so turn stack-protection
 # off for non-shared builds.
diff --git a/nptl/Makefile b/nptl/Makefile
index 21fc7e7..d9aafc4 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -217,6 +217,7 @@ CFLAGS-close.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-read.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-write.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-nanosleep.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-msync.c = -fexceptions -fasynchronous-unwind-tables
 
 CFLAGS-pt-system.c = -fexceptions
 
diff --git a/sysdeps/unix/syscalls.list b/sysdeps/unix/syscalls.list
index 2254c76..c4135d8 100644
--- a/sysdeps/unix/syscalls.list
+++ b/sysdeps/unix/syscalls.list
@@ -45,7 +45,6 @@ madvise		-	madvise		i:pii	__madvise	madvise
 mkdir		-	mkdir		i:si	__mkdir		mkdir
 mmap		-	mmap		b:aniiii __mmap		mmap
 mprotect	-	mprotect	i:aii	__mprotect	mprotect
-msync		-	msync		Ci:aii	__libc_msync	msync
 munmap		-	munmap		i:ai	__munmap	munmap
 open		-	open		Ci:siv	__libc_open __open open
 profil		-	profil		i:piii	__profil	profil
diff --git a/sysdeps/unix/sysv/linux/msync.c b/sysdeps/unix/sysv/linux/msync.c
new file mode 100644
index 0000000..28aba11
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/msync.c
@@ -0,0 +1,26 @@
+/* Linux synchronize a file with a memory map implementation.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/mman.h>
+#include <sysdep-cancel.h>
+
+int
+msync (void *addr, size_t length, int flags)
+{
+  return SYSCALL_CANCEL (msync, addr, length, flags);
+}

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=887e12c79e0c36ce0b88be76d385e1ef78b45402

commit 887e12c79e0c36ce0b88be76d385e1ef78b45402
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Thu Nov 24 10:12:37 2016 -0200

    Consolidate Linux sigsuspend implementation
    
    This patch consolidates the sigsuspend Linux syscall generation on
    sysdeps/unix/sysv/linux/sigsuspend.c.  It basically removes the alpha
    assembly version which call the old sigsusped interface using only
    the first doubleword from sigset. Current minimum supported kernel
    on alpha (3.2) enforces rt_sigsuspend on the architecture
    (__ARCH_WANT_SYS_RT_SIGSUSPEND option on kernel), so it is possible
    to use the default implementation.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    arch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/alpha/sigsuspend.S: Remove file.
    	* sysdeps/unix/sysv/linux/sigsuspend.c: Simplify include list.

diff --git a/ChangeLog b/ChangeLog
index a0affa3..7cedd95 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/alpha/sigsuspend.S: Remove file.
+	* sysdeps/unix/sysv/linux/sigsuspend.c: Simplify include list.
+
 	* sysdeps/unix/sysv/linux/Makefile (sysdeps_routines): Add tee.
 	* sysdeps/unix/sysv/linux/syscalls.list: Remove tee from
 	auto-generated list.
diff --git a/sysdeps/unix/sysv/linux/alpha/sigsuspend.S b/sysdeps/unix/sysv/linux/alpha/sigsuspend.S
deleted file mode 100644
index c226be1..0000000
--- a/sysdeps/unix/sysv/linux/alpha/sigsuspend.S
+++ /dev/null
@@ -1,32 +0,0 @@
-/* Copyright (C) 1993-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by David Mosberger <davidm@cs.arizona.edu>, 1995.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library.  If not, see
-   <http://www.gnu.org/licenses/>.  */
-
-/* sigsuspend is a special syscall since it needs to dereference the
-   sigset.  This will have to change when we have more than 64 signals.  */
-
-#include <sysdep-cancel.h>
-
-#undef PSEUDO_PREPARE_ARGS
-#define PSEUDO_PREPARE_ARGS	ldq	a0, 0(a0);
-
-PSEUDO(__sigsuspend, sigsuspend, 1)
-	ret
-PSEUDO_END(__sigsuspend)
-libc_hidden_def (__sigsuspend)
-weak_alias (__sigsuspend, sigsuspend)
-strong_alias (__sigsuspend, __libc_sigsuspend)
diff --git a/sysdeps/unix/sysv/linux/sigsuspend.c b/sysdeps/unix/sysv/linux/sigsuspend.c
index 8bb0cd4..df29abf 100644
--- a/sysdeps/unix/sysv/linux/sigsuspend.c
+++ b/sysdeps/unix/sysv/linux/sigsuspend.c
@@ -15,12 +15,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
 #include <signal.h>
-#include <unistd.h>
-
 #include <sysdep-cancel.h>
-#include <sys/syscall.h>
 
 /* Change the set of blocked signals to SET,
    wait until a signal arrives, and restore the set of blocked signals.  */

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=26dc052cb5f977e56cca4b68f2831b5e85cc5b35

commit 26dc052cb5f977e56cca4b68f2831b5e85cc5b35
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Thu Nov 24 09:55:09 2016 -0200

    Consolidate Linux tee implementation
    
    This patch consolidates the tee Linux syscall generation on
    sysdeps/unix/sysv/linux/tee.c.  It basically removes it from
    architectures auto-generation list.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    arch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/Makefile (sysdeps_routines): Add tee.
    	* sysdeps/unix/sysv/linux/syscalls.list: Remove tee from
    	auto-generated list.
    	* sysdeps/unix/sysv/linux/tee.c: New file.

diff --git a/ChangeLog b/ChangeLog
index b2213ad..a0affa3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/Makefile (sysdeps_routines): Add tee.
+	* sysdeps/unix/sysv/linux/syscalls.list: Remove tee from
+	auto-generated list.
+	* sysdeps/unix/sysv/linux/tee.c: New file.
+
 	* nptl/Makefile (CFLAGS-nanosleep.c): New rule.
 	* posix/Makefile (CFLAGS-nanosleep.c): Likewise.
 	* sysdeps/unix/sysv/linux/nanosleep.c: New file.
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 99b7313..f292d5b 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -17,7 +17,7 @@ include $(firstword $(wildcard $(sysdirs:=/sysctl.mk)))
 sysdep_routines += clone umount umount2 readahead \
 		   setfsuid setfsgid epoll_pwait signalfd \
 		   eventfd eventfd_read eventfd_write prlimit \
-		   personality epoll_wait
+		   personality epoll_wait tee
 
 CFLAGS-gethostid.c = -fexceptions
 CFLAGS-tst-writev.c += "-DARTIFICIAL_LIMIT=0x80000000-__getpagesize()"
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index 7fca6f8..ae99acd 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -70,7 +70,6 @@ stime		-	stime		i:p	stime
 sysinfo		EXTRA	sysinfo		i:p	__sysinfo	sysinfo
 swapon		-	swapon		i:si	__swapon	swapon
 swapoff		-	swapoff		i:s	__swapoff	swapoff
-tee		EXTRA	tee		Ci:iiii	tee
 unshare		EXTRA	unshare		i:i	unshare
 uselib		EXTRA	uselib		i:s	__compat_uselib	uselib@GLIBC_2.0:GLIBC_2.23
 utime		-	utime		i:sP	utime
diff --git a/sysdeps/unix/sysv/linux/tee.c b/sysdeps/unix/sysv/linux/tee.c
new file mode 100644
index 0000000..3d503fb
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tee.c
@@ -0,0 +1,26 @@
+/* Linux duplicating pipe content implementation.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fcntl.h>
+#include <sysdep-cancel.h>
+
+ssize_t
+tee (int src, int dest, size_t len, unsigned int flags)
+{
+  return SYSCALL_CANCEL (tee, src, dest, len, flags);
+}

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=9cc25393c4791bae5a489f93ffed961c9efc7870

commit 9cc25393c4791bae5a489f93ffed961c9efc7870
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Nov 3 16:03:56 2015 -0200

    Consolidate Linux nanosleep syscall
    
    This patch consolidates the nanosleep Linux syscall generation on
    sysdeps/unix/sysv/linux/nanosleep.c.  It basically removes it from
    architectures auto-generation list.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    arch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* nptl/Makefile (CFLAGS-nanosleep.c): New rule.
    	* posix/Makefile (CFLAGS-nanosleep.c): Likewise.
    	* sysdeps/unix/sysv/linux/nanosleep.c: New file.
    	* sysdeps/unix/sysv/linux/syscalls.list: Remove nanosleep from
    	auto-generated list.

diff --git a/ChangeLog b/ChangeLog
index 3169738..b2213ad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* nptl/Makefile (CFLAGS-nanosleep.c): New rule.
+	* posix/Makefile (CFLAGS-nanosleep.c): Likewise.
+	* sysdeps/unix/sysv/linux/nanosleep.c: New file.
+	* sysdeps/unix/sysv/linux/syscalls.list: Remove nanosleep from
+	auto-generated list.
+
 	* sysdeps/unix/sysv/linux/sh/syscalls.list: Remove waitid from
 	auto-generated list.
 	* sysdeps/unix/sysv/linux/m68k/syscalls.list: Likewise.
diff --git a/nptl/Makefile b/nptl/Makefile
index 5b34b5c..21fc7e7 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -216,6 +216,7 @@ CFLAGS-sendmsg.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-close.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-read.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-write.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-nanosleep.c = -fexceptions -fasynchronous-unwind-tables
 
 CFLAGS-pt-system.c = -fexceptions
 
diff --git a/posix/Makefile b/posix/Makefile
index 8f23d64..af5d41b 100644
--- a/posix/Makefile
+++ b/posix/Makefile
@@ -226,6 +226,7 @@ CFLAGS-execle.os = -fomit-frame-pointer
 CFLAGS-execl.os = -fomit-frame-pointer
 CFLAGS-execvp.os = -fomit-frame-pointer
 CFLAGS-execlp.os = -fomit-frame-pointer
+CFLAGS-nanosleep.c = -fexceptions
 
 tstgetopt-ARGS = -a -b -cfoobar --required foobar --optional=bazbug \
 		--none random --col --color --colour
diff --git a/sysdeps/unix/sysv/linux/nanosleep.c b/sysdeps/unix/sysv/linux/nanosleep.c
new file mode 100644
index 0000000..b352f84
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/nanosleep.c
@@ -0,0 +1,30 @@
+/* Linux high resolution nanosleep implementation.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <time.h>
+#include <sysdep-cancel.h>
+
+/* Pause execution for a number of nanoseconds.  */
+int
+__nanosleep (const struct timespec *requested_time,
+	     struct timespec *remaining)
+{
+  return SYSCALL_CANCEL (nanosleep, requested_time, remaining);
+}
+libc_hidden_def (__nanosleep)
+weak_alias (__nanosleep, nanosleep)
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index eab30dd..7fca6f8 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -42,7 +42,6 @@ mount		EXTRA	mount		i:sssip	__mount	mount
 mremap		EXTRA	mremap		b:ainip	__mremap	mremap
 munlock		-	munlock		i:ai	munlock
 munlockall	-	munlockall	i:	munlockall
-nanosleep	-	nanosleep	Ci:pp	__nanosleep	nanosleep
 nfsservctl	EXTRA	nfsservctl	i:ipp	nfsservctl
 pipe		-	pipe		i:f	__pipe		pipe
 pipe2		-	pipe2		i:fi	__pipe2		pipe2

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=a32e2d6a39d5a99dc28cbdae1c35ec699ef9fc41

commit a32e2d6a39d5a99dc28cbdae1c35ec699ef9fc41
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Jan 17 15:57:33 2017 -0200

    Consolidate Linux waitpid syscall
    
    This patch consolidates the waitpid Linux syscall generation on
    sysdeps/unix/sysv/linux/waitpid.c.  It basically removes it from
    architecture auto-generation list and also remove arch specific
    implementations.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    arch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/sh/syscalls.list: Remove waitpid from
    	auto-generated list.
    	* sysdeps/unix/sysv/linux/m68k/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/i386/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/sparc/syscalls.list: Remove file.
    	* sysdeps/unix/sysv/linux/tile/waitpid.S: Likewise.
    	* sysdeps/unix/sysv/linux/powerpc/syscalls.list: Likewise.

diff --git a/ChangeLog b/ChangeLog
index 6be2c24..3169738 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/sh/syscalls.list: Remove waitid from
+	auto-generated list.
+	* sysdeps/unix/sysv/linux/m68k/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/i386/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/syscalls.list: Remove file.
+	* sysdeps/unix/sysv/linux/tile/waitpid.S: Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/syscalls.list: Likewise.
+
 	* sysdeps/unix/sysv/linux/epoll_wait.c: New file.
 	* sysdeps/unix/sysv/linux/generic/epoll_wait.c: Remove file.
 	* sysdeps/unix/sysv/linux/syscalls.list: Remove epoll_wait from
diff --git a/sysdeps/unix/sysv/linux/i386/syscalls.list b/sysdeps/unix/sysv/linux/i386/syscalls.list
index 145393f..58020df 100644
--- a/sysdeps/unix/sysv/linux/i386/syscalls.list
+++ b/sysdeps/unix/sysv/linux/i386/syscalls.list
@@ -18,7 +18,6 @@ setfsuid	-	setfsuid32	Ei:i	setfsuid
 modify_ldt	EXTRA	modify_ldt	i:ipi	__modify_ldt	modify_ldt
 vm86old		EXTRA	vm86old		i:p	__vm86old	vm86@GLIBC_2.0
 vm86		-	vm86		i:ip	__vm86		vm86@@GLIBC_2.3.4
-waitpid		-	waitpid		Ci:ipi	__waitpid	waitpid
 
 prlimit64	EXTRA	prlimit64	i:iipp	prlimit64
 
diff --git a/sysdeps/unix/sysv/linux/m68k/syscalls.list b/sysdeps/unix/sysv/linux/m68k/syscalls.list
index 4260f3e..55a377b 100644
--- a/sysdeps/unix/sysv/linux/m68k/syscalls.list
+++ b/sysdeps/unix/sysv/linux/m68k/syscalls.list
@@ -3,7 +3,6 @@
 chown		-	chown32		i:sii	__chown		chown
 lchown		-	lchown32	i:sii	__lchown	lchown
 fchown		-	fchown32	i:iii	__fchown	fchown
-waitpid		-	waitpid		Ci:ipi	__waitpid	waitpid
 
 getegid		-	getegid32	Ei:	__getegid	getegid
 geteuid		-	geteuid32	Ei:	__geteuid	geteuid
diff --git a/sysdeps/unix/sysv/linux/powerpc/syscalls.list b/sysdeps/unix/sysv/linux/powerpc/syscalls.list
deleted file mode 100644
index 4f821e9..0000000
--- a/sysdeps/unix/sysv/linux/powerpc/syscalls.list
+++ /dev/null
@@ -1,3 +0,0 @@
-# File name	Caller	Syscall name	# args	Strong name	Weak names
-
-waitpid		-	waitpid		Ci:ipi	__waitpid	waitpid
diff --git a/sysdeps/unix/sysv/linux/sh/syscalls.list b/sysdeps/unix/sysv/linux/sh/syscalls.list
index 169d40f..32badd1 100644
--- a/sysdeps/unix/sysv/linux/sh/syscalls.list
+++ b/sysdeps/unix/sysv/linux/sh/syscalls.list
@@ -15,8 +15,6 @@ getgroups	-	getgroups32	i:ip	__getgroups	getgroups
 setfsgid	-	setfsgid32	Ei:i	setfsgid
 setfsuid	-	setfsuid32	Ei:i	setfsuid
 
-waitpid		-	waitpid		Ci:ipi	__waitpid	waitpid
-
 prlimit64	EXTRA	prlimit64	i:iipp	prlimit64
 
 fanotify_mark	EXTRA	fanotify_mark	i:iiiiis	__fanotify_mark	fanotify_mark@@GLIBC_2.16
diff --git a/sysdeps/unix/sysv/linux/sparc/syscalls.list b/sysdeps/unix/sysv/linux/sparc/syscalls.list
deleted file mode 100644
index 4f821e9..0000000
--- a/sysdeps/unix/sysv/linux/sparc/syscalls.list
+++ /dev/null
@@ -1,3 +0,0 @@
-# File name	Caller	Syscall name	# args	Strong name	Weak names
-
-waitpid		-	waitpid		Ci:ipi	__waitpid	waitpid
diff --git a/sysdeps/unix/sysv/linux/tile/waitpid.S b/sysdeps/unix/sysv/linux/tile/waitpid.S
deleted file mode 100644
index dee1b0c..0000000
--- a/sysdeps/unix/sysv/linux/tile/waitpid.S
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
-extern pid_t __waitpid_nocancel (pid_t, int *, int) attribute_hidden;
-*/
-#if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
-
-/* Call __NR_wait4, providing fourth argument (struct rusage *) as NULL. */
-#define PSEUDO_EXTRA move r3, zero;
-#include <sysdep-cancel.h>
-
-PSEUDO (__waitpid, wait4, 3)
-ret
-PSEUDO_END(__waitpid)
-
-libc_hidden_def (__waitpid)
-weak_alias (__waitpid, waitpid)
-libc_hidden_weak (waitpid)
-
-#endif

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=246d63434ad7b1964b1b4b57059ef998237cc663

commit 246d63434ad7b1964b1b4b57059ef998237cc663
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Nov 21 17:40:19 2016 -0200

    Consolidate Linux epoll_wait syscall
    
    This patch consolidates the epoll_wait Linux syscall generation on
    sysdeps/unix/sysv/linux/epoll_wait.c.  The implementation tries to
    use __NR_epoll_wait if defined, otherwise calls epoll_pwait.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    arch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/epoll_wait.c: New file.
    	* sysdeps/unix/sysv/linux/generic/epoll_wait.c: Remove file.
    	* sysdeps/unix/sysv/linux/syscalls.list: Remove epoll_wait from
    	auto-generation list.

diff --git a/ChangeLog b/ChangeLog
index ed5eeb2..6be2c24 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/epoll_wait.c: New file.
+	* sysdeps/unix/sysv/linux/generic/epoll_wait.c: Remove file.
+	* sysdeps/unix/sysv/linux/syscalls.list: Remove epoll_wait from
+	auto-generation list.
+	* sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Add
+	epoll_wait.
+	* sysdeps/unix/sysv/linux/generic/Makefile (sysdep_routines):
+	Remove epoll_wait.
+
 	* sysdeps/unix/sysv/linux/generic/pause.c: Remove file.
 	* sysdeps/unix/sysv/linux/sparc/sparc64/pause.c: Likewise.
 	* sysdeps/unix/sysv/linux/pause.c: New file.
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index b3d6866..99b7313 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -17,7 +17,7 @@ include $(firstword $(wildcard $(sysdirs:=/sysctl.mk)))
 sysdep_routines += clone umount umount2 readahead \
 		   setfsuid setfsgid epoll_pwait signalfd \
 		   eventfd eventfd_read eventfd_write prlimit \
-		   personality
+		   personality epoll_wait
 
 CFLAGS-gethostid.c = -fexceptions
 CFLAGS-tst-writev.c += "-DARTIFICIAL_LIMIT=0x80000000-__getpagesize()"
diff --git a/sysdeps/unix/sysv/linux/generic/epoll_wait.c b/sysdeps/unix/sysv/linux/epoll_wait.c
similarity index 82%
rename from sysdeps/unix/sysv/linux/generic/epoll_wait.c
rename to sysdeps/unix/sysv/linux/epoll_wait.c
index d9363f1..eb6e6d3 100644
--- a/sysdeps/unix/sysv/linux/generic/epoll_wait.c
+++ b/sysdeps/unix/sysv/linux/epoll_wait.c
@@ -1,6 +1,6 @@
-/* Copyright (C) 2011-2017 Free Software Foundation, Inc.
+/* Linux epoll_wait syscall implementation.
+   Copyright (C) 2017 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -24,5 +24,9 @@
 int
 epoll_wait (int epfd, struct epoll_event *events, int maxevents, int timeout)
 {
+#ifdef __NR_epoll_wait
+  return SYSCALL_CANCEL (epoll_wait, epfd, events, maxevents, timeout);
+#else
   return epoll_pwait (epfd, events, maxevents, timeout, NULL);
+#endif
 }
diff --git a/sysdeps/unix/sysv/linux/generic/Makefile b/sysdeps/unix/sysv/linux/generic/Makefile
index c1daee2..7e27e79 100644
--- a/sysdeps/unix/sysv/linux/generic/Makefile
+++ b/sysdeps/unix/sysv/linux/generic/Makefile
@@ -1,3 +1,3 @@
 ifeq ($(subdir),misc)
-sysdep_routines += epoll_create epoll_wait inotify_init
+sysdep_routines += epoll_create inotify_init
 endif
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index 88caa7c..eab30dd 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -11,7 +11,6 @@ delete_module	EXTRA	delete_module	3	delete_module
 epoll_create	EXTRA	epoll_create	i:i	epoll_create
 epoll_create1	EXTRA	epoll_create1	i:i	epoll_create1
 epoll_ctl	EXTRA	epoll_ctl	i:iiip	epoll_ctl
-epoll_wait	EXTRA	epoll_wait	Ci:ipii	epoll_wait
 eventfd		EXTRA	eventfd2	i:ii	eventfd
 execve		-	execve		i:spp	__execve	execve
 fdatasync	-	fdatasync	Ci:i	fdatasync

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=0fa9126d9840311fc2328e3aa0784a4db580de02

commit 0fa9126d9840311fc2328e3aa0784a4db580de02
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Nov 21 17:26:35 2016 -0200

    Consolidate Linux pause syscall
    
    This patch consolidates the pause Linux implementation on
    sysdeps/unix/sysv/linux/pause.c.  If defined the pause syscall
    (__NR_pause) will be used, other ppoll with 0 arguments will be
    used instead.
    
    It has the small advantage of generic pause implementation with
    uses rt_sigprocmask plus rt_sigsuspend because it requires only
    one syscall and the pause is done atomically regarding signal
    handling (for instance, pause may not be interrupted if the
    signal arrives between the rt_sigprocmask and rt_sigsuspend
    syscall).
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    arch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/generic/pause.c: Remove file.
    	* sysdeps/unix/sysv/linux/sparc/sparc64/pause.c: Likewise.
    	* sysdeps/unix/sysv/linux/pause.c: New file.
    	* sysdeps/unix/sysv/linux/syscalls.list: Remove pause from
    	auto-generation list.

diff --git a/ChangeLog b/ChangeLog
index 50f0bbf..ed5eeb2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/generic/pause.c: Remove file.
+	* sysdeps/unix/sysv/linux/sparc/sparc64/pause.c: Likewise.
+	* sysdeps/unix/sysv/linux/pause.c: New file.
+	* sysdeps/unix/sysv/linux/syscalls.list: Remove pause from
+	auto-generation list.
+
 	* sysdeps/unix/sysv/linux/writev.c: New file.
 
 	* sysdeps/unix/sysv/linux/readv.c: New file.
diff --git a/sysdeps/unix/sysv/linux/generic/pause.c b/sysdeps/unix/sysv/linux/pause.c
similarity index 75%
rename from sysdeps/unix/sysv/linux/generic/pause.c
rename to sysdeps/unix/sysv/linux/pause.c
index a8b3e33..c6b252a 100644
--- a/sysdeps/unix/sysv/linux/generic/pause.c
+++ b/sysdeps/unix/sysv/linux/pause.c
@@ -1,6 +1,6 @@
-/* Copyright (C) 2011-2017 Free Software Foundation, Inc.
+/* Linux pause syscall implementation.
+   Copyright (C) 2017 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -26,14 +26,10 @@
 int
 __libc_pause (void)
 {
-  sigset_t set;
-
-  int rc =
-    SYSCALL_CANCEL (rt_sigprocmask, SIG_BLOCK, NULL, &set, _NSIG / 8);
-  if (rc == 0)
-    rc = SYSCALL_CANCEL (rt_sigsuspend, &set, _NSIG / 8);
-
-  return rc;
+#ifdef __NR_pause
+  return SYSCALL_CANCEL (pause);
+#else
+  return SYSCALL_CANCEL (ppoll, 0, 0, 0, 0, 0);
+#endif
 }
-
 weak_alias (__libc_pause, pause)
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/pause.c b/sysdeps/unix/sysv/linux/sparc/sparc64/pause.c
deleted file mode 100644
index e399e7c..0000000
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/pause.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <errno.h>
-#include <signal.h>
-#include <unistd.h>
-#include <sysdep-cancel.h>
-
-#define __sigprocmask(how, set, oset) \
-  INLINE_SYSCALL (rt_sigprocmask, 4, how, set, oset, _NSIG / 8)
-
-#include <sysdeps/posix/pause.c>
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index 78ee8cd..88caa7c 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -45,7 +45,6 @@ munlock		-	munlock		i:ai	munlock
 munlockall	-	munlockall	i:	munlockall
 nanosleep	-	nanosleep	Ci:pp	__nanosleep	nanosleep
 nfsservctl	EXTRA	nfsservctl	i:ipp	nfsservctl
-pause		-	pause		Ci:	__libc_pause	pause
 pipe		-	pipe		i:f	__pipe		pipe
 pipe2		-	pipe2		i:fi	__pipe2		pipe2
 pivot_root	EXTRA	pivot_root	i:ss	pivot_root

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=103f5a262ff3f99eea376bf58d01d138210462ec

commit 103f5a262ff3f99eea376bf58d01d138210462ec
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Nov 3 10:33:52 2015 -0200

    Consolidate Linux writev implementation
    
    This patch consolidates the writev Linux syscall implementation on
    sysdeps/unix/sysv/linux/writev.c.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    arch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/writev.c: New file.

diff --git a/ChangeLog b/ChangeLog
index 7e4b897..50f0bbf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/writev.c: New file.
+
 	* sysdeps/unix/sysv/linux/readv.c: New file.
 
 	* io/Makefile (CFLAGS-write.c): New rule.
diff --git a/sysdeps/unix/sysv/linux/writev.c b/sysdeps/unix/sysv/linux/writev.c
new file mode 100644
index 0000000..1b56cbb
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/writev.c
@@ -0,0 +1,27 @@
+/* Linux writev syscall implementation.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <unistd.h>
+#include <sysdep-cancel.h>
+
+ssize_t
+__writev (int fd, const struct iovec *iov, int iovcnt)
+{
+  return SYSCALL_CANCEL (writev, fd, iov, iovcnt);
+}
+weak_alias (__writev, writev)

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=24206daacc55013fa20d0bad43983083cb132212

commit 24206daacc55013fa20d0bad43983083cb132212
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Nov 3 10:26:18 2015 -0200

    Consolidate Linux readv implementation
    
    This patch consolidates the readv Linux syscall implementation on
    sysdeps/unix/sysv/linux/readv.c.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    arch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/readv.c: New file.

diff --git a/ChangeLog b/ChangeLog
index 1f018d1..7e4b897 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/readv.c: New file.
+
 	* io/Makefile (CFLAGS-write.c): New rule.
 	* nptl/Makefile (CFLAGS-write.c): Likewise.
 	* sysdeps/unix/sysv/linux/write.c: New file.
diff --git a/sysdeps/unix/sysv/linux/readv.c b/sysdeps/unix/sysv/linux/readv.c
new file mode 100644
index 0000000..b2a0537
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/readv.c
@@ -0,0 +1,27 @@
+/* Linux implementation for readv syscall.
+   Copyright (C) 2016 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <unistd.h>
+#include <sysdep-cancel.h>
+
+ssize_t
+__readv (int fd, const struct iovec *iov, int iovcnt)
+{
+  return SYSCALL_CANCEL (readv, fd, iov, iovcnt);
+}
+weak_alias (__readv, readv)

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=6539c616eade757ebad4fa2b857b629a2ba3c86a

commit 6539c616eade757ebad4fa2b857b629a2ba3c86a
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Nov 3 10:04:25 2015 -0200

    Consolidate Linux write syscall
    
    This patch consolidates the write Linux syscall implementation on
    sysdeps/unix/sysv/linux/write.c.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    arch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* io/Makefile (CFLAGS-write.c): New rule.
    	* nptl/Makefile (CFLAGS-write.c): Likewise.
    	* sysdeps/unix/sysv/linux/write.c: New file.

diff --git a/ChangeLog b/ChangeLog
index 5ceb677..1f018d1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* io/Makefile (CFLAGS-write.c): New rule.
+	* nptl/Makefile (CFLAGS-write.c): Likewise.
+	* sysdeps/unix/sysv/linux/write.c: New file.
+
 	* io/Makefile (CFLAGS-read.c): New rule.
 	* nptl/Makefile (CFLAGS-read.c): New rule.
 	* sysdeps/unix/sysv/linux/read.c: New file.
diff --git a/io/Makefile b/io/Makefile
index e2c6646..8478591 100644
--- a/io/Makefile
+++ b/io/Makefile
@@ -103,6 +103,7 @@ CFLAGS-fallocate.c = -fexceptions
 CFLAGS-fallocate64.c = -fexceptions
 CFLAGS-sync_file_range.c = -fexceptions
 CFLAGS-read.c = -fexceptions
+CFLAGS-write.c = -fexceptions
 
 CFLAGS-test-stat.c = -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
 CFLAGS-test-lfs.c = -D_LARGEFILE64_SOURCE
diff --git a/nptl/Makefile b/nptl/Makefile
index faabd45..5b34b5c 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -215,6 +215,7 @@ CFLAGS-recvmsg.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-sendmsg.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-close.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-read.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-write.c = -fexceptions -fasynchronous-unwind-tables
 
 CFLAGS-pt-system.c = -fexceptions
 
diff --git a/sysdeps/unix/sysv/linux/write.c b/sysdeps/unix/sysv/linux/write.c
new file mode 100644
index 0000000..e576e74
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/write.c
@@ -0,0 +1,32 @@
+/* Linux write syscall implementation.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <unistd.h>
+#include <sysdep-cancel.h>
+
+/* Write NBYTES of BUF to FD.  Return the number written, or -1.  */
+ssize_t
+__libc_write (int fd, const void *buf, size_t nbytes)
+{
+  return SYSCALL_CANCEL (write, fd, buf, nbytes);
+}
+libc_hidden_def (__libc_write)
+
+weak_alias (__libc_write, __write)
+libc_hidden_weak (__write)
+weak_alias (__libc_write, write)

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=6fdb774e6b2d6406a96ac84314b649ab16ab58a5

commit 6fdb774e6b2d6406a96ac84314b649ab16ab58a5
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Nov 3 10:13:18 2015 -0200

    Consolidate Linux read syscall
    
    This patch consolidates the read Linux syscall implementation on
    sysdeps/unix/sysv/linux/read.c.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    arch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* io/Makefile (CFLAGS-read.c): New rule.
    	* nptl/Makefile (CFLAGS-read.c): New rule.
    	* sysdeps/unix/sysv/linux/read.c: New file.

diff --git a/ChangeLog b/ChangeLog
index a38da6d..5ceb677 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* io/Makefile (CFLAGS-read.c): New rule.
+	* nptl/Makefile (CFLAGS-read.c): New rule.
+	* sysdeps/unix/sysv/linux/read.c: New file.
+
 	* io/Makefile (CFLAGS-creat.c): New rule.
 	(CFLAGS-creat64.c): Likewise.
 	* sysdeps/unix/sysv/linux/alpha/creat.c: Remove file.
diff --git a/io/Makefile b/io/Makefile
index 17445d0..e2c6646 100644
--- a/io/Makefile
+++ b/io/Makefile
@@ -102,6 +102,7 @@ CFLAGS-posix_fallocate64.c = -fexceptions
 CFLAGS-fallocate.c = -fexceptions
 CFLAGS-fallocate64.c = -fexceptions
 CFLAGS-sync_file_range.c = -fexceptions
+CFLAGS-read.c = -fexceptions
 
 CFLAGS-test-stat.c = -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
 CFLAGS-test-lfs.c = -D_LARGEFILE64_SOURCE
diff --git a/nptl/Makefile b/nptl/Makefile
index 8251ac4..faabd45 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -214,6 +214,7 @@ CFLAGS-recvfrom.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-recvmsg.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-sendmsg.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-close.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-read.c = -fexceptions -fasynchronous-unwind-tables
 
 CFLAGS-pt-system.c = -fexceptions
 
diff --git a/sysdeps/unix/sysv/linux/read.c b/sysdeps/unix/sysv/linux/read.c
new file mode 100644
index 0000000..932153e
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/read.c
@@ -0,0 +1,31 @@
+/* Linux read syscall implementation.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <unistd.h>
+#include <sysdep-cancel.h>
+
+/* Read NBYTES into BUF from FD.  Return the number read or -1.  */
+ssize_t
+__libc_read (int fd, void *buf, size_t nbytes)
+{
+  return SYSCALL_CANCEL (read, fd, buf, nbytes);
+}
+libc_hidden_def (__libc_read)
+weak_alias (__libc_read, __read)
+libc_hidden_weak (__read)
+weak_alias (__libc_read, read)

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=e6778a653ede76a2039378f0af9a447f829974b5

commit e6778a653ede76a2039378f0af9a447f829974b5
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Fri Nov 11 14:50:03 2016 -0200

    Consolidate Linux creat implementation
    
    This patch consolidates the creat Linux syscall implementation on
    sysdeps/unix/sysv/linux/creat{64}.c.  The changes are:
    
      1. Remove open{64} from auto-generation syscalls.list.
      2. Add a new open{64}.c implementation.  For WORDSIZE == 64 the default
         open.c will create alias for open64 symbols.
      3. Use __NR_creat where possible, otherwise use internal open{64} call
         expected flags.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    arch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* io/Makefile (CFLAGS-creat.c): New rule.
    	(CFLAGS-creat64.c): Likewise.
    	* sysdeps/unix/sysv/linux/alpha/creat.c: Remove file.
    	* sysdeps/unix/sysv/linux/generic/creat.c: Likewise.
    	* sysdeps/unix/sysv/linux/wordsize-64/creat64.c: Likewise.
    	* sysdeps/unix/sysv/linux/creat.c: New file.
    	* sysdeps/unix/sysv/linux/creat64.c: Likewise.
    	* sysdeps/unix/sysv/linux/syscalls.list: Remove create from
    	auto-generated list.
    	* sysdeps/unix/sysv/linux/wordsize-64/syscalls.list: Likewise.

diff --git a/ChangeLog b/ChangeLog
index 110bf18..a38da6d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* io/Makefile (CFLAGS-creat.c): New rule.
+	(CFLAGS-creat64.c): Likewise.
+	* sysdeps/unix/sysv/linux/alpha/creat.c: Remove file.
+	* sysdeps/unix/sysv/linux/generic/creat.c: Likewise.
+	* sysdeps/unix/sysv/linux/wordsize-64/creat64.c: Likewise.
+	* sysdeps/unix/sysv/linux/creat.c: New file.
+	* sysdeps/unix/sysv/linux/creat64.c: Likewise.
+	* sysdeps/unix/sysv/linux/syscalls.list: Remove create from
+	auto-generated list.
+	* sysdeps/unix/sysv/linux/wordsize-64/syscalls.list: Likewise.
+
 	* sysdeps/unix/sysv/linux/generic/open.c: Remove file.
 	* sysdeps/unix/sysv/linux/generic/open64.c: Likewise.
 	* sysdeps/unix/sysv/linux/wordsize-64/open64.c: Likewise.
diff --git a/io/Makefile b/io/Makefile
index 333a049..17445d0 100644
--- a/io/Makefile
+++ b/io/Makefile
@@ -82,6 +82,8 @@ include ../Rules
 
 CFLAGS-open.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-open64.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-creat.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-creat64.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-fcntl.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-poll.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-ppoll.c = -fexceptions -fasynchronous-unwind-tables
diff --git a/sysdeps/unix/sysv/linux/alpha/creat.c b/sysdeps/unix/sysv/linux/alpha/creat.c
deleted file mode 100644
index 7a5afed..0000000
--- a/sysdeps/unix/sysv/linux/alpha/creat.c
+++ /dev/null
@@ -1,8 +0,0 @@
-/* sysdeps/unix/sysv/linux/wordsize-64/syscalls.list defines creat and
-   creat64 for most linux targets, but on alpha creat is not a syscall.
-   If we do nothing, we'll wind up with creat64 being undefined, because
-   the syscalls.list assumes the creat->creat64 alias was created.  We
-   could have overridden that with a create64.c, but we might as well do
-   the right thing and set up creat64 as an alias.  */
-#include <io/creat.c>
-weak_alias(creat, creat64)
diff --git a/sysdeps/unix/sysv/linux/generic/creat.c b/sysdeps/unix/sysv/linux/creat.c
similarity index 77%
copy from sysdeps/unix/sysv/linux/generic/creat.c
copy to sysdeps/unix/sysv/linux/creat.c
index 34cb210..45f755b 100644
--- a/sysdeps/unix/sysv/linux/generic/creat.c
+++ b/sysdeps/unix/sysv/linux/creat.c
@@ -1,6 +1,6 @@
-/* Copyright (C) 2011-2017 Free Software Foundation, Inc.
+/* Linux default implementation for creat.
+   Copyright (C) 2017 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -20,18 +20,17 @@
 #include <sys/types.h>
 #include <sysdep-cancel.h>
 
-#undef	creat
-
 /* Create FILE with protections MODE.  */
 int
-creat (const char *file, mode_t mode)
+__creat (const char *file, mode_t mode)
 {
+#ifdef __NR_creat
+  return SYSCALL_CANCEL (creat, file, mode);
+#else
   return __open (file, O_WRONLY | O_CREAT | O_TRUNC, mode);
+#endif
 }
-
-/* __open handles cancellation.  */
-LIBC_CANCEL_HANDLED ();
-
+weak_alias (__creat, creat)
 #if __WORDSIZE == 64
-weak_alias (creat, creat64)
+weak_alias (__creat, creat64)
 #endif
diff --git a/sysdeps/unix/sysv/linux/generic/creat.c b/sysdeps/unix/sysv/linux/creat64.c
similarity index 71%
rename from sysdeps/unix/sysv/linux/generic/creat.c
rename to sysdeps/unix/sysv/linux/creat64.c
index 34cb210..6a8f8dc 100644
--- a/sysdeps/unix/sysv/linux/generic/creat.c
+++ b/sysdeps/unix/sysv/linux/creat64.c
@@ -1,6 +1,6 @@
-/* Copyright (C) 2011-2017 Free Software Foundation, Inc.
+/* Linux default implementation for LFS creat.
+   Copyright (C) 2016 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -20,18 +20,13 @@
 #include <sys/types.h>
 #include <sysdep-cancel.h>
 
-#undef	creat
-
 /* Create FILE with protections MODE.  */
+#if __WORDSIZE != 64
 int
-creat (const char *file, mode_t mode)
+__creat64 (const char *file, mode_t mode)
 {
-  return __open (file, O_WRONLY | O_CREAT | O_TRUNC, mode);
+  /* We need to pass O_LARGEFILE.  */
+  return __open64 (file, O_WRONLY | O_CREAT | O_TRUNC, mode);
 }
-
-/* __open handles cancellation.  */
-LIBC_CANCEL_HANDLED ();
-
-#if __WORDSIZE == 64
-weak_alias (creat, creat64)
+weak_alias (__creat64, creat64)
 #endif
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index 4d550b8..78ee8cd 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -6,7 +6,6 @@ bdflush		EXTRA	bdflush		i:ii	__compat_bdflush	bdflush@GLIBC_2.0:GLIBC_2.23
 capget		EXTRA	capget		i:pp	capget
 capset		EXTRA	capset		i:pp	capset
 clock_adjtime	EXTRA	clock_adjtime	i:ip	clock_adjtime
-creat		-	creat		Ci:si	creat
 create_module	EXTRA	create_module	3	__compat_create_module	create_module@GLIBC_2.0:GLIBC_2.23
 delete_module	EXTRA	delete_module	3	delete_module
 epoll_create	EXTRA	epoll_create	i:i	epoll_create
diff --git a/sysdeps/unix/sysv/linux/wordsize-64/creat64.c b/sysdeps/unix/sysv/linux/wordsize-64/creat64.c
deleted file mode 100644
index c106e2b..0000000
--- a/sysdeps/unix/sysv/linux/wordsize-64/creat64.c
+++ /dev/null
@@ -1 +0,0 @@
-/* Defined as alias for the syscall.  */
diff --git a/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list b/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list
index 2b10b62..dcca5f4 100644
--- a/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list
@@ -6,7 +6,6 @@ mmap		-	mmap		b:aniiii __mmap		mmap __mmap64 mmap64
 readahead	-	readahead	i:iii	__readahead	readahead
 sendfile	-	sendfile	i:iipi	sendfile	sendfile64
 sync_file_range	-	sync_file_range	Ci:iiii	sync_file_range
-creat		-	creat		Ci:si	creat		creat64
 prlimit		EXTRA	prlimit64	i:iipp	prlimit		prlimit64
 
 fanotify_mark	EXTRA	fanotify_mark	i:iiiis	fanotify_mark

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=54d4abef3c0d5eb9550dff7ae22e8114d63c0d18

commit 54d4abef3c0d5eb9550dff7ae22e8114d63c0d18
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Fri Nov 11 15:00:03 2016 -0200

    Consolidate Linux open implementation
    
    This patch consolidates the open Linux syscall implementation on
    sysdeps/unix/sysv/linux/open{64}.c.  The changes are:
    
      1. Remove open{64} from auto-generation syscalls.list.
      2. Add a new open{64}.c implementation.  For WORDSIZE == 64 the default
         open.c will create alias for open64 symbols.
      3. Use __NR_open where possible, otherwise use __NR_openat.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    arch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/generic/open.c: Remove file.
    	* sysdeps/unix/sysv/linux/generic/open64.c: Likewise.
    	* sysdeps/unix/sysv/linux/wordsize-64/open64.c: Likewise.
    	* sysdeps/unix/sysv/linux/open.c: New file.
    	* sysdeps/unix/sysv/linux/open64.c (__libc_open64): Define symbol
    	iff __WORDSIZE != 64 and use __NR_openat when available.
    	* sysdeps/unix/sysv/linux/wordsize-64/syscalls.list: Remove open
    	from auto-generated list.

diff --git a/ChangeLog b/ChangeLog
index d28df7a..110bf18 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/generic/open.c: Remove file.
+	* sysdeps/unix/sysv/linux/generic/open64.c: Likewise.
+	* sysdeps/unix/sysv/linux/wordsize-64/open64.c: Likewise.
+	* sysdeps/unix/sysv/linux/open.c: New file.
+	* sysdeps/unix/sysv/linux/open64.c (__libc_open64): Define symbol
+	iff __WORDSIZE != 64 and use __NR_openat when available.
+	* sysdeps/unix/sysv/linux/wordsize-64/syscalls.list: Remove open
+	from auto-generated list.
+
 	* nptl/Makefile (CFLAGS-close.c): New flag.
 	* sysdeps/unix/sysv/linux/close.c: New file.
 
diff --git a/sysdeps/unix/sysv/linux/generic/open64.c b/sysdeps/unix/sysv/linux/generic/open64.c
deleted file mode 100644
index 88312a1..0000000
--- a/sysdeps/unix/sysv/linux/generic/open64.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/* Copyright (C) 2011-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library.  If not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <fcntl.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <sysdep-cancel.h>
-
-/* Open FILE with access OFLAG.  If O_CREAT or O_TMPFILE is in OFLAG,
-   a third argument is the file protection.  */
-int
-__libc_open64 (const char *file, int oflag, ...)
-{
-  int mode = 0;
-
-  if (__OPEN_NEEDS_MODE (oflag))
-    {
-      va_list arg;
-      va_start (arg, oflag);
-      mode = va_arg (arg, int);
-      va_end (arg);
-    }
-
-  return SYSCALL_CANCEL (openat, AT_FDCWD, file, oflag | O_LARGEFILE, mode);
-}
-weak_alias (__libc_open64, __open64)
-libc_hidden_weak (__open64)
-weak_alias (__libc_open64, open64)
diff --git a/sysdeps/unix/sysv/linux/generic/open.c b/sysdeps/unix/sysv/linux/open.c
similarity index 80%
rename from sysdeps/unix/sysv/linux/generic/open.c
rename to sysdeps/unix/sysv/linux/open.c
index 10cdbe0..10023d5 100644
--- a/sysdeps/unix/sysv/linux/generic/open.c
+++ b/sysdeps/unix/sysv/linux/open.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2011-2017 Free Software Foundation, Inc.
+/* Copyright (C) 2017 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
 
@@ -37,7 +37,11 @@ __libc_open (const char *file, int oflag, ...)
       va_end (arg);
     }
 
+#ifdef __NR_open
+  return SYSCALL_CANCEL (open, file, oflag, mode);
+#else
   return SYSCALL_CANCEL (openat, AT_FDCWD, file, oflag, mode);
+#endif
 }
 libc_hidden_def (__libc_open)
 
@@ -45,18 +49,8 @@ weak_alias (__libc_open, __open)
 libc_hidden_weak (__open)
 weak_alias (__libc_open, open)
 
-int
-__open_nocancel (const char *file, int oflag, ...)
-{
-  int mode = 0;
-
-  if (__OPEN_NEEDS_MODE (oflag))
-    {
-      va_list arg;
-      va_start (arg, oflag);
-      mode = va_arg (arg, int);
-      va_end (arg);
-    }
-
-  return INLINE_SYSCALL (openat, 4, AT_FDCWD, file, oflag, mode);
-}
+#if __WORDSIZE == 64
+weak_alias (__libc_open, __open64)
+libc_hidden_weak (__open64)
+weak_alias (__libc_open, open64)
+#endif
diff --git a/sysdeps/unix/sysv/linux/open64.c b/sysdeps/unix/sysv/linux/open64.c
index 5e209ee..886700e 100644
--- a/sysdeps/unix/sysv/linux/open64.c
+++ b/sysdeps/unix/sysv/linux/open64.c
@@ -21,6 +21,7 @@
 #include <stdio.h>
 #include <sysdep-cancel.h>
 
+#if __WORDSIZE != 64
 /* Open FILE with access OFLAG.  If O_CREAT or O_TMPFILE is in OFLAG,
    a third argument is the file protection.  */
 int
@@ -36,8 +37,13 @@ __libc_open64 (const char *file, int oflag, ...)
       va_end (arg);
     }
 
+#ifdef __NR_open
   return SYSCALL_CANCEL (open, file, oflag | O_LARGEFILE, mode);
+#else
+  return SYSCALL_CANCEL (openat, AT_FDCWD, file, oflag | O_LARGEFILE, mode);
+#endif
 }
 weak_alias (__libc_open64, __open64)
 libc_hidden_weak (__open64)
 weak_alias (__libc_open64, open64)
+#endif
diff --git a/sysdeps/unix/sysv/linux/wordsize-64/open64.c b/sysdeps/unix/sysv/linux/wordsize-64/open64.c
deleted file mode 100644
index 0abe30e..0000000
--- a/sysdeps/unix/sysv/linux/wordsize-64/open64.c
+++ /dev/null
@@ -1 +0,0 @@
-/* Defined in open syscall.  */
diff --git a/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list b/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list
index e71cd7b..2b10b62 100644
--- a/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/wordsize-64/syscalls.list
@@ -7,7 +7,6 @@ readahead	-	readahead	i:iii	__readahead	readahead
 sendfile	-	sendfile	i:iipi	sendfile	sendfile64
 sync_file_range	-	sync_file_range	Ci:iiii	sync_file_range
 creat		-	creat		Ci:si	creat		creat64
-open		-	open		Ci:siv	__libc_open	__open open __open64 open64
 prlimit		EXTRA	prlimit64	i:iipp	prlimit		prlimit64
 
 fanotify_mark	EXTRA	fanotify_mark	i:iiiis	fanotify_mark

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=0d54280454fc9a94f6756dd3b137e6621e321188

commit 0d54280454fc9a94f6756dd3b137e6621e321188
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Thu Oct 29 19:26:05 2015 -0200

    Consolidate Linux close syscall generation
    
    This patch consolidates the close Linux syscall generation on
    sysdeps/unix/sysv/linux/close.c.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    arch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* nptl/Makefile (CFLAGS-close.c): New flag.
    	* sysdeps/unix/sysv/linux/close.c: New file.

diff --git a/ChangeLog b/ChangeLog
index 28f4a70..d28df7a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* nptl/Makefile (CFLAGS-close.c): New flag.
+	* sysdeps/unix/sysv/linux/close.c: New file.
+
 	* sysdeps/unix/sysv/linux/alpha/Makefile (sysdep_routines): Add
 	osf_select.
 	* sysdeps/unix/sysv/linux/alpha/select.c: New file.
diff --git a/nptl/Makefile b/nptl/Makefile
index 6d48c0c..8251ac4 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -213,6 +213,7 @@ CFLAGS-connect.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-recvfrom.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-recvmsg.c = -fexceptions -fasynchronous-unwind-tables
 CFLAGS-sendmsg.c = -fexceptions -fasynchronous-unwind-tables
+CFLAGS-close.c = -fexceptions -fasynchronous-unwind-tables
 
 CFLAGS-pt-system.c = -fexceptions
 
diff --git a/sysdeps/unix/sysv/linux/close.c b/sysdeps/unix/sysv/linux/close.c
new file mode 100644
index 0000000..1ac71ce
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/close.c
@@ -0,0 +1,30 @@
+/* Linux close syscall implementation.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <unistd.h>
+#include <sysdep-cancel.h>
+
+/* Close the file descriptor FD.  */
+int
+__close (int fd)
+{
+  return SYSCALL_CANCEL (close, fd);
+}
+libc_hidden_def (__close)
+strong_alias (__close, __libc_close)
+weak_alias (__close, close)

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=eeae4fbccb4084a35272af85b6891b6ec9fb2a4a

commit eeae4fbccb4084a35272af85b6891b6ec9fb2a4a
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Fri Nov 18 14:27:03 2016 -0200

    Consolidate Linux select implementation
    
    This patch consolidates the select Linux syscall implementation on
    sysdeps/unix/sysv/linux/select.c.  The changes are:
    
      1. Remove select from auto-generation syscalls.list on the architecture
         that uses __NR_select.
      2. Remove generic implementation add a default one that handle all
         current cases (with the expection of alpha)
         The new default implementation will either use __NR_select if
         available of fallback to __NR_pselect6 otherwise.
      3. Add a alpha outlier implementation which requires old compatibility
         symbols.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    arch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/alpha/Makefile (sysdep_routines): Add
    	osf_select.
    	* sysdeps/unix/sysv/linux/alpha/select.c: New file.
    	* sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove select and
    	osf_select from auto-generation list.
    	* sysdeps/unix/sysv/linux/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/generic/select.c: Remove file.
    	* sysdeps/unix/sysv/linux/select.c: New file.

diff --git a/ChangeLog b/ChangeLog
index 4cd7c76..28f4a70 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/alpha/Makefile (sysdep_routines): Add
+	osf_select.
+	* sysdeps/unix/sysv/linux/alpha/select.c: New file.
+	* sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove select and
+	osf_select from auto-generation list.
+	* sysdeps/unix/sysv/linux/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/generic/select.c: Remove file.
+	* sysdeps/unix/sysv/linux/select.c: New file.
+
 	* sysdeps/unix/sysv/linux/generic/poll.c: Remove file.
 	* sysdeps/unix/sysv/linux/poll.c: New file.
 	* sysdeps/unix/sysv/linux/syscalls.list: Remove poll from
diff --git a/sysdeps/unix/sysv/linux/alpha/Makefile b/sysdeps/unix/sysv/linux/alpha/Makefile
index 4bbe9bf..0d1793e 100644
--- a/sysdeps/unix/sysv/linux/alpha/Makefile
+++ b/sysdeps/unix/sysv/linux/alpha/Makefile
@@ -13,7 +13,7 @@ sysdep_routines += ieee_get_fp_control ieee_set_fp_control \
 		   ioperm
 
 # Support old timeval32 entry points
-sysdep_routines += osf_select osf_gettimeofday osf_settimeofday \
+sysdep_routines += osf_gettimeofday osf_settimeofday \
 		   osf_getitimer osf_setitimer osf_utimes \
 		   osf_getrusage osf_wait4
 
diff --git a/sysdeps/unix/sysv/linux/alpha/select.c b/sysdeps/unix/sysv/linux/alpha/select.c
new file mode 100644
index 0000000..bb0298f
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/select.c
@@ -0,0 +1,53 @@
+/* Linux/alpha select implementation.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/select.h>
+#include <errno.h>
+#include <sysdep-cancel.h>
+#include <shlib-compat.h>
+
+int
+__new_select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
+	      struct timeval *timeout)
+{
+  return SYSCALL_CANCEL (select, nfds, readfds, writefds, exceptfds, timeout);
+}
+strong_alias (__new_select, __select)
+libc_hidden_def (__select)
+
+default_symbol_version (__new_select, select, GLIBC_2.1);
+
+strong_alias (__new_select, __new_select_private);
+symbol_version (__new_select_private, __select, GLIBC_2.1);
+
+/* Old timeval32 compat calls.  */
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
+int
+__select_tv32 (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
+	       struct timeval *timeout)
+{
+  return SYSCALL_CANCEL (osf_select, nfds, readfds, writefds, exceptfds,
+                        timeout);
+}
+strong_alias (__select_tv32, __select_tv32_1)
+
+compat_symbol (libc, __select_tv32, __select, GLIBC_2_0);
+compat_symbol (libc, __select_tv32_1, select, GLIBC_2_0);
+#endif
diff --git a/sysdeps/unix/sysv/linux/alpha/syscalls.list b/sysdeps/unix/sysv/linux/alpha/syscalls.list
index aa21b10..12cd021 100644
--- a/sysdeps/unix/sysv/linux/alpha/syscalls.list
+++ b/sysdeps/unix/sysv/linux/alpha/syscalls.list
@@ -23,7 +23,6 @@ pciconfig_write	EXTRA	pciconfig_write	5	pciconfig_write
 pciconfig_iobase EXTRA	pciconfig_iobase 3	__pciconfig_iobase pciconfig_iobase
 
 # support old timeval32 entry points
-osf_select	-	osf_select	C:5	__select_tv32  __select@GLIBC_2.0 select@GLIBC_2.0
 osf_gettimeofday -	osf_gettimeofday 2	__gettimeofday_tv32  __gettimeofday@GLIBC_2.0 gettimeofday@GLIBC_2.0
 osf_settimeofday -	osf_settimeofday 2	__settimeofday_tv32  settimeofday@GLIBC_2.0
 osf_getitimer	-	osf_getitimer	2	__getitimer_tv32  getitimer@GLIBC_2.0
@@ -33,7 +32,6 @@ osf_getrusage	-	osf_getrusage	2	__getrusage_tv32  getrusage@GLIBC_2.0
 osf_wait4	-	osf_wait4	4	__wait4_tv32  wait4@GLIBC_2.0
 
 # support new timeval64 entry points
-select		-	select		C:5	__GI___select select@@GLIBC_2.1 __select@@GLIBC_2.1
 gettimeofday	-	gettimeofday	2	__GI___gettimeofday gettimeofday@@GLIBC_2.1 __gettimeofday@@GLIBC_2.1
 settimeofday	-	settimeofday	2	__settimeofday settimeofday@@GLIBC_2.1
 getitimer	-	getitimer	2	__getitimer getitimer@@GLIBC_2.1
diff --git a/sysdeps/unix/sysv/linux/generic/select.c b/sysdeps/unix/sysv/linux/select.c
similarity index 82%
rename from sysdeps/unix/sysv/linux/generic/select.c
rename to sysdeps/unix/sysv/linux/select.c
index 7743ea3..6e03450 100644
--- a/sysdeps/unix/sysv/linux/generic/select.c
+++ b/sysdeps/unix/sysv/linux/select.c
@@ -1,6 +1,6 @@
-/* Copyright (C) 2011-2017 Free Software Foundation, Inc.
+/* Linux select implementation.
+   Copyright (C) 2017 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -28,11 +28,19 @@
    after waiting the interval specified therein.  Returns the number of ready
    descriptors, or -1 for errors.  */
 
+#ifdef __NR__newselect
+# undef __NR_select
+# define __RN_select __NR__newselect
+#endif
+
 int
-__select(int nfds, fd_set *readfds,
-         fd_set *writefds, fd_set *exceptfds,
-         struct timeval *timeout)
+__select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
+	  struct timeval *timeout)
 {
+#ifdef __NR_select
+  return SYSCALL_CANCEL (select, nfds, readfds, writefds, exceptfds,
+			 timeout);
+#else
   int result;
   struct timespec ts, *tsp = NULL;
 
@@ -55,6 +63,7 @@ __select(int nfds, fd_set *readfds,
     }
 
   return result;
+#endif
 }
 libc_hidden_def (__select)
 
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list b/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list
index 1e85118..33082f3 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list
@@ -1,7 +1,5 @@
 # File name	Caller	Syscall name	# args	Strong name	Weak names
 
-# Override select.S in parent directory:
-select		-	select		C:5	__select	select
 bind		-	bind		3	__bind		bind
 getpeername	-	getpeername	3	__getpeername	getpeername
 getsockname	-	getsockname	3	__getsockname	getsockname
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index fcefefc..4d550b8 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -63,7 +63,6 @@ sched_rr_gi	-	sched_rr_get_interval	i:ip	__sched_rr_get_interval	sched_rr_get_in
 sched_setp	-	sched_setparam	i:ip	__sched_setparam	sched_setparam
 sched_sets	-	sched_setscheduler	i:iip	__sched_setscheduler	sched_setscheduler
 sched_yield	-	sched_yield	i:	__sched_yield	sched_yield
-select		-	_newselect	Ci:iPPPP	__select	__libc_select select
 sendfile	-	sendfile	i:iipi	sendfile
 sendfile64	-	sendfile64	i:iipi	sendfile64
 setfsgid	EXTRA	setfsgid	i:i	setfsgid

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=460c197a632b76529d1b126d2aa62f09e59c6e72

commit 460c197a632b76529d1b126d2aa62f09e59c6e72
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Fri Nov 18 13:56:05 2016 -0200

    Consolidate Linux poll implementation
    
    This patch consolidates the poll Linux syscall implementation on
    sysdeps/unix/sysv/linux/poll.c.  It basically removes poll from
    auto-generation list and add a default implementation that either
    call __NR_poll directly (if the kernel headers defines it) or
    ppoll adjusting the timeout argument (as the generic implementation).
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/generic/poll.c: Remove file.
    	* sysdeps/unix/sysv/linux/poll.c: New file.
    	* sysdeps/unix/sysv/linux/syscalls.list: Remove poll from
    	auto-generation list.

diff --git a/ChangeLog b/ChangeLog
index 3a424c8..4cd7c76 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/generic/poll.c: Remove file.
+	* sysdeps/unix/sysv/linux/poll.c: New file.
+	* sysdeps/unix/sysv/linux/syscalls.list: Remove poll from
+	auto-generation list.
+
 	* sysdeps/unix/sysv/linux/generic/send.c: Remove file.
 	* sysdeps/unix/sysv/linux/x86_64/send.c: Likewise.
 	* sysdeps/unix/sysv/linux/mips/mips64/send.c: Likewise.
diff --git a/sysdeps/unix/sysv/linux/generic/poll.c b/sysdeps/unix/sysv/linux/poll.c
similarity index 88%
rename from sysdeps/unix/sysv/linux/generic/poll.c
rename to sysdeps/unix/sysv/linux/poll.c
index c06d383..5a781dd 100644
--- a/sysdeps/unix/sysv/linux/generic/poll.c
+++ b/sysdeps/unix/sysv/linux/poll.c
@@ -1,6 +1,6 @@
-/* Copyright (C) 2011-2017 Free Software Foundation, Inc.
+/* Linux poll implementation.
+   Copyright (C) 2017 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -25,6 +25,9 @@
 int
 __poll (struct pollfd *fds, nfds_t nfds, int timeout)
 {
+#ifdef __NR_poll
+  return SYSCALL_CANCEL (poll, fds, nfds, timeout);
+#else
   struct timespec timeout_ts;
   struct timespec *timeout_ts_p = NULL;
 
@@ -36,6 +39,7 @@ __poll (struct pollfd *fds, nfds_t nfds, int timeout)
     }
 
   return SYSCALL_CANCEL (ppoll, fds, nfds, timeout_ts_p, NULL, 0);
+#endif
 }
 libc_hidden_def (__poll)
 weak_alias (__poll, poll)
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index 5d3c417..fcefefc 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -50,7 +50,6 @@ pause		-	pause		Ci:	__libc_pause	pause
 pipe		-	pipe		i:f	__pipe		pipe
 pipe2		-	pipe2		i:fi	__pipe2		pipe2
 pivot_root	EXTRA	pivot_root	i:ss	pivot_root
-poll		-	poll		Ci:pii	__libc_poll	__poll poll
 prctl		EXTRA	prctl		i:iiiii	__prctl		prctl
 putpmsg		-	putpmsg		i:ippii	putpmsg
 query_module	EXTRA	query_module	i:sipip	__compat_query_module	query_module@GLIBC_2.0:GLIBC_2.23

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=f82e84d94d41c206a4692b9f91e0e055218f7e12

commit f82e84d94d41c206a4692b9f91e0e055218f7e12
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Fri Nov 18 09:47:36 2016 -0200

    Consolidate Linux send and sendto implementation
    
    This patch consolidates the send Linux syscall implementation on
    sysdeps/unix/sysv/linux/send{to}.c.  The changes are:
    
      1. Remove send and sendto from auto-generation syscalls.list on the
         architecture that uses __NR_send.
      2. Define __NR_send for such architectures.  It was done instead of
         defining in default kernel-features.h because current Linux practice
         for new ports are to implement only __NR_sendto [1] and it will
         require adding new kernel-features for ports that do not require it
         (aarch64 for instance).
      3. Define __NR_sendto as default (__ASSUME_SENDTO_SYSCALL) and undef
         for architectures that do not support it.
      4. Remove __ASSUME_SENDTO_FOR_SEND_SYSCALL and decide to use
         __NR_sendto for send generation based on __ASSUME_SENDTO_SYSCALL.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/generic/send.c: Remove file.
    	* sysdeps/unix/sysv/linux/x86_64/send.c: Likewise.
    	* sysdeps/unix/sysv/linux/mips/mips64/send.c: Likewise.
    	* sysdeps/unix/sysv/linux/alpha/kernel-features.h
    	(__ASSUME_SEND_SYSCALL): Define.
    	* sysdeps/unix/sysv/linux/arm/kernel-features.h
    	(__ASSUME_SEND_SYSCALL): Likewise.
    	* sysdeps/unix/sysv/linux/hppa/kernel-features.h
    	(__ASSUME_SEND_SYSCALL): Likewise.
    	* sysdeps/unix/sysv/linux/ia64/kernel-features.h
    	(__ASSUME_SEND_SYSCALL): Likewise.
    	* sysdeps/unix/sysv/linux/microblaze/kernel-features.h
    	(__ASSUME_SEND_SYSCALL): Likewise.
    	* sysdeps/unix/sysv/linux/mips/kernel-features.h
    	[_MIPS_SIM == _ABIO32] (__ASSUME_SEND_SYSCALL): Likewise.
    	* sysdeps/unix/sysv/linux/sh/kernel-features.h
    	(__ASSUME_SEND_SYSCALL): Likewise.
    	* sysdeps/unix/sysv/linux/i386/kernel-features.h
    	(__ASSUME_SENDTO_FOR_SEND_SYSCALL): Remove.
    	(__ASSUME_SENDTO_SYSCALL): Define wheter the kernel supports it.
    	* sysdeps/unix/sysv/linux/m68k/kernel-features.h
    	(__ASSUME_SENDTO_FOR_SEND_SYSCALL): Remove.
    	(__ASSUME_SENDTO_SYSCALL): Define wheter the kernel supports it.
    	* sysdeps/unix/sysv/linux/s390/kernel-features.h
    	(__ASSUME_SENDTO_FOR_SEND_SYSCALL): Remove.
    	(__ASSUME_SENDTO_SYSCALL): Define wheter the kernel supports it.
    	* sysdeps/unix/sysv/linux/kernel-features.h
    	(__ASSUME_SENDTO_SYSCALL): Define as default.
    	* sysdeps/unix/sysv/linux/microblaze/kernel-features.h
    	(__ASSUME_SENDTO_FOR_SEND_SYSCALL): Define.
    	(__ASSUME_SENDTO_SYSCALL): Likewise.
    	* sysdeps/unix/sysv/linux/powerpc/kernel-features.h
    	(__ASSUME_SENDTO_SYSCALL): Remove defune.
    	* sysdeps/unix/sysv/linux/send.c (__ASSUME_SENDTO_FOR_SEND_SYSCALL):
    	Replace by __ASSUME_SENDTO_SYSCALL.
    	* sysdeps/unix/sysv/linux/sh/kernel-features.h
    	(__ASSUME_SEND_SYSCALL): Remove define.
    	(__ASSUME_SENDTO_SYSCALL): Likewise.
    	* sysdeps/unix/sysv/linux/sysdep.h (HAVE_INTERNAL_SEND_SYMBOl)
    	* sysdeps/unix/sysv/linux/aarch64/sysdep.h
    	(HAVE_INTERNAL_SEND_SYMBOl): Undefine.
    	* sysdeps/unix/sysv/linux/nios2/sysdep.h
    	(HAVE_INTERNAL_SEND_SYMBOl): Likewise.
    	* sysdeps/unix/sysv/linux/tile/sysdep.h
    	(HAVE_INTERNAL_SEND_SYMBOl): Likewise.
    	* sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove send and
    	sendto from auto-generation list.
    	* sysdeps/unix/sysv/linux/arm/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/generic/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/hppa/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/ia64/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/mips/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/x86_64/syscalls.list: Likewise.
    
    [1] include/asm-generic/unistd.h (__ARCH_WANT_SYSCALL_DEPRECATED)

diff --git a/ChangeLog b/ChangeLog
index daf2f0f..3a424c8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,60 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/generic/send.c: Remove file.
+	* sysdeps/unix/sysv/linux/x86_64/send.c: Likewise.
+	* sysdeps/unix/sysv/linux/mips/mips64/send.c: Likewise.
+	* sysdeps/unix/sysv/linux/alpha/kernel-features.h
+	(__ASSUME_SEND_SYSCALL): Define.
+	* sysdeps/unix/sysv/linux/arm/kernel-features.h
+	(__ASSUME_SEND_SYSCALL): Likewise.
+	* sysdeps/unix/sysv/linux/hppa/kernel-features.h
+	(__ASSUME_SEND_SYSCALL): Likewise.
+	* sysdeps/unix/sysv/linux/ia64/kernel-features.h
+	(__ASSUME_SEND_SYSCALL): Likewise.
+	* sysdeps/unix/sysv/linux/microblaze/kernel-features.h
+	(__ASSUME_SEND_SYSCALL): Likewise.
+	* sysdeps/unix/sysv/linux/mips/kernel-features.h
+	[_MIPS_SIM == _ABIO32] (__ASSUME_SEND_SYSCALL): Likewise.
+	* sysdeps/unix/sysv/linux/sh/kernel-features.h
+	(__ASSUME_SEND_SYSCALL): Likewise.
+	* sysdeps/unix/sysv/linux/i386/kernel-features.h
+	(__ASSUME_SENDTO_FOR_SEND_SYSCALL): Remove.
+	(__ASSUME_SENDTO_SYSCALL): Define wheter the kernel supports it.
+	* sysdeps/unix/sysv/linux/m68k/kernel-features.h
+	(__ASSUME_SENDTO_FOR_SEND_SYSCALL): Remove.
+	(__ASSUME_SENDTO_SYSCALL): Define wheter the kernel supports it.
+	* sysdeps/unix/sysv/linux/s390/kernel-features.h
+	(__ASSUME_SENDTO_FOR_SEND_SYSCALL): Remove.
+	(__ASSUME_SENDTO_SYSCALL): Define wheter the kernel supports it.
+	* sysdeps/unix/sysv/linux/kernel-features.h
+	(__ASSUME_SENDTO_SYSCALL): Define as default.
+	* sysdeps/unix/sysv/linux/microblaze/kernel-features.h
+	(__ASSUME_SENDTO_FOR_SEND_SYSCALL): Define.
+	(__ASSUME_SENDTO_SYSCALL): Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/kernel-features.h
+	(__ASSUME_SENDTO_SYSCALL): Remove defune.
+	* sysdeps/unix/sysv/linux/send.c (__ASSUME_SENDTO_FOR_SEND_SYSCALL):
+	Replace by __ASSUME_SENDTO_SYSCALL.
+	* sysdeps/unix/sysv/linux/sh/kernel-features.h
+	(__ASSUME_SEND_SYSCALL): Remove define.
+	(__ASSUME_SENDTO_SYSCALL): Likewise.
+	* sysdeps/unix/sysv/linux/sysdep.h (HAVE_INTERNAL_SEND_SYMBOl)
+	* sysdeps/unix/sysv/linux/aarch64/sysdep.h
+	(HAVE_INTERNAL_SEND_SYMBOl): Undefine.
+	* sysdeps/unix/sysv/linux/nios2/sysdep.h
+	(HAVE_INTERNAL_SEND_SYMBOl): Likewise.
+	* sysdeps/unix/sysv/linux/tile/sysdep.h
+	(HAVE_INTERNAL_SEND_SYMBOl): Likewise.
+	* sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove send and
+	sendto from auto-generation list.
+	* sysdeps/unix/sysv/linux/arm/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/generic/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/hppa/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/ia64/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/mips/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/x86_64/syscalls.list: Likewise.
+
 	* sysdeps/unix/sysv/linux/alpha/kernel-features.h
 	(__ASSUME_RECV_SYSCALL): Define.
 	* sysdeps/unix/sysv/linux/arm/kernel-features.h
diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
index ad49241..ea38588 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
@@ -157,6 +157,10 @@
 # define HAVE_CLOCK_GETTIME_VSYSCALL	1
 # define HAVE_GETTIMEOFDAY_VSYSCALL	1
 
+/* Previously AArch64 used the generic version withouth the libc_hidden_def
+   which lead in a non existent __send symbol in libc.so.  */
+# undef HAVE_INTERNAL_SEND_SYMBOl
+
 /* Define a macro which expands into the inline wrapper code for a system
    call.  */
 # undef INLINE_SYSCALL
diff --git a/sysdeps/unix/sysv/linux/alpha/kernel-features.h b/sysdeps/unix/sysv/linux/alpha/kernel-features.h
index 3383a98..53f7611 100644
--- a/sysdeps/unix/sysv/linux/alpha/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/alpha/kernel-features.h
@@ -33,5 +33,6 @@
 #define __NR_shmat __NR_osf_shmat
 
 #define __ASSUME_RECV_SYSCALL	1
+#define __ASSUME_SEND_SYSCALL	1
 
 #endif /* _KERNEL_FEATURES_H */
diff --git a/sysdeps/unix/sysv/linux/alpha/syscalls.list b/sysdeps/unix/sysv/linux/alpha/syscalls.list
index 8a62b6e..aa21b10 100644
--- a/sysdeps/unix/sysv/linux/alpha/syscalls.list
+++ b/sysdeps/unix/sysv/linux/alpha/syscalls.list
@@ -10,8 +10,6 @@ getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
 listen		-	listen		i:ii	__listen	listen
-send		-	send		Ci:ibni	__libc_send	__send send
-sendto		-	sendto		Ci:ibnibn	__libc_sendto	__sendto sendto
 setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
 socket		-	socket		i:iii	__socket	socket
diff --git a/sysdeps/unix/sysv/linux/arm/kernel-features.h b/sysdeps/unix/sysv/linux/arm/kernel-features.h
index 104c9f9..4923dfd 100644
--- a/sysdeps/unix/sysv/linux/arm/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/arm/kernel-features.h
@@ -39,3 +39,4 @@
 #define __NR_fadvise64_64 __NR_arm_fadvise64_64
 
 #define __ASSUME_RECV_SYSCALL   1
+#define __ASSUME_SEND_SYSCALL	1
diff --git a/sysdeps/unix/sysv/linux/arm/syscalls.list b/sysdeps/unix/sysv/linux/arm/syscalls.list
index 9f445e6..13441f7 100644
--- a/sysdeps/unix/sysv/linux/arm/syscalls.list
+++ b/sysdeps/unix/sysv/linux/arm/syscalls.list
@@ -27,8 +27,6 @@ getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
 listen		-	listen		i:ii	__listen	listen
-send		-	send		Ci:ibni	__libc_send	__send send
-sendto		-	sendto		Ci:ibnibn	__libc_sendto	__sendto sendto
 setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
 socket		-	socket		i:iii	__socket	socket
diff --git a/sysdeps/unix/sysv/linux/generic/send.c b/sysdeps/unix/sysv/linux/generic/send.c
deleted file mode 100644
index d0cb035..0000000
--- a/sysdeps/unix/sysv/linux/generic/send.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/* Copyright (C) 2011-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library.  If not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sysdep-cancel.h>
-#include <libc-symbols.h>
-
-ssize_t
-__libc_send (int sockfd, const void *buffer, size_t len, int flags)
-{
-  return SYSCALL_CANCEL (sendto, sockfd, buffer, len, flags, NULL, 0);
-}
-strong_alias (__libc_send, __send)
-weak_alias (__libc_send, send)
diff --git a/sysdeps/unix/sysv/linux/generic/syscalls.list b/sysdeps/unix/sysv/linux/generic/syscalls.list
index c16ee52..ed8b216 100644
--- a/sysdeps/unix/sysv/linux/generic/syscalls.list
+++ b/sysdeps/unix/sysv/linux/generic/syscalls.list
@@ -7,7 +7,6 @@ bind		-	bind		i:ipi	__bind		bind
 listen		-	listen		i:ii	__listen	listen
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
-sendto		-	sendto		Ci:ibnibn	__libc_sendto	__sendto sendto
 setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
diff --git a/sysdeps/unix/sysv/linux/hppa/kernel-features.h b/sysdeps/unix/sysv/linux/hppa/kernel-features.h
index 1fd7398..0e73a5c 100644
--- a/sysdeps/unix/sysv/linux/hppa/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/hppa/kernel-features.h
@@ -26,3 +26,4 @@
 #include_next <kernel-features.h>
 
 #define __ASSUME_RECV_SYSCALL   1
+#define __ASSUME_SEND_SYSCALL	1
diff --git a/sysdeps/unix/sysv/linux/hppa/syscalls.list b/sysdeps/unix/sysv/linux/hppa/syscalls.list
index 1248877..cd37573 100644
--- a/sysdeps/unix/sysv/linux/hppa/syscalls.list
+++ b/sysdeps/unix/sysv/linux/hppa/syscalls.list
@@ -6,8 +6,6 @@ getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
 listen		-	listen		i:ii	__listen	listen
-send		-	send		Ci:ibni	__libc_send	__send send
-sendto		-	sendto		Ci:ibnibn	__libc_sendto	__sendto sendto
 setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
 socket		-	socket		i:iii	__socket	socket
diff --git a/sysdeps/unix/sysv/linux/i386/kernel-features.h b/sysdeps/unix/sysv/linux/i386/kernel-features.h
index a886442..96a8e3b 100644
--- a/sysdeps/unix/sysv/linux/i386/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/i386/kernel-features.h
@@ -36,8 +36,6 @@
 # define __ASSUME_SETSOCKOPT_SYSCALL         1
 # define __ASSUME_GETSOCKNAME_SYSCALL        1
 # define __ASSUME_GETPEERNAME_SYSCALL        1
-# define __ASSUME_SENDTO_SYSCALL             1
-# define __ASSUME_SENDTO_FOR_SEND_SYSCALL    1
 # define __ASSUME_SHUTDOWN_SYSCALL           1
 #endif
 
@@ -51,6 +49,7 @@
 # undef __ASSUME_RECVMSG_SYSCALL
 # undef __ASSUME_CONNECT_SYSCALL
 # undef __ASSUME_RECVFROM_SYSCALL
+# undef __ASSUME_SENDTO_SYSCALL
 #endif
 
 /* i686 only supports ipc syscall.  */
diff --git a/sysdeps/unix/sysv/linux/ia64/kernel-features.h b/sysdeps/unix/sysv/linux/ia64/kernel-features.h
index 80e41b6..ac9403e 100644
--- a/sysdeps/unix/sysv/linux/ia64/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/ia64/kernel-features.h
@@ -29,5 +29,6 @@
 #endif
 
 #define __ASSUME_RECV_SYSCALL   	1
+#define __ASSUME_SEND_SYSCALL		1
 
 #endif /* _KERNEL_FEATURES_H */
diff --git a/sysdeps/unix/sysv/linux/ia64/syscalls.list b/sysdeps/unix/sysv/linux/ia64/syscalls.list
index 24e9c98..56f4138 100644
--- a/sysdeps/unix/sysv/linux/ia64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/ia64/syscalls.list
@@ -10,8 +10,6 @@ getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
 listen		-	listen		i:ii	__listen	listen
-send		-	send		Ci:ibni	__libc_send	__send send
-sendto		-	sendto		Ci:ibnibn	__libc_sendto	__sendto sendto
 setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
 socket		-	socket		i:iii	__socket	socket
diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h
index c6c816e..318fcf9 100644
--- a/sysdeps/unix/sysv/linux/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/kernel-features.h
@@ -150,6 +150,7 @@
 #define __ASSUME_ACCEPT_SYSCALL		1
 #define __ASSUME_CONNECT_SYSCALL	1
 #define __ASSUME_RECVFROM_SYSCALL	1
+#define __ASSUME_SENDTO_SYSCALL		1
 
 /* Support for SysV IPC through wired syscalls.  All supported architectures
    either support ipc syscall and/or all the ipc correspondent syscalls.  */
diff --git a/sysdeps/unix/sysv/linux/m68k/kernel-features.h b/sysdeps/unix/sysv/linux/m68k/kernel-features.h
index 5e756ab..3bcd1c2 100644
--- a/sysdeps/unix/sysv/linux/m68k/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/m68k/kernel-features.h
@@ -30,8 +30,6 @@
 # define __ASSUME_SETSOCKOPT_SYSCALL         1
 # define __ASSUME_GETSOCKNAME_SYSCALL        1
 # define __ASSUME_GETPEERNAME_SYSCALL        1
-# define __ASSUME_SENDTO_SYSCALL             1
-# define __ASSUME_SENDTO_FOR_SEND_SYSCALL    1
 # define __ASSUME_SHUTDOWN_SYSCALL           1
 #endif
 
@@ -48,6 +46,7 @@
 # undef __ASSUME_RECVMSG_SYSCALL
 # undef __ASSUME_CONNECT_SYSCALL
 # undef __ASSUME_RECVFROM_SYSCALL
+# undef __ASSUME_SENDTO_SYSCALL
 #endif
 
 /* No support for PI futexes or robust mutexes before 3.10 for m68k.  */
diff --git a/sysdeps/unix/sysv/linux/mips/kernel-features.h b/sysdeps/unix/sysv/linux/mips/kernel-features.h
index 276d12f..cf21681 100644
--- a/sysdeps/unix/sysv/linux/mips/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/mips/kernel-features.h
@@ -36,6 +36,7 @@
 # undef __ASSUME_DIRECT_SYSVIPC_SYSCALLS
 /* mips32 support wire-up network syscalls.  */
 # define __ASSUME_RECV_SYSCALL		1
+# define __ASSUME_SEND_SYSCALL		1
 #endif
 
 /* Define that mips64-n32 is a ILP32 ABI to set the correct interface to
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/send.c b/sysdeps/unix/sysv/linux/mips/mips64/send.c
deleted file mode 100644
index d2c2996..0000000
--- a/sysdeps/unix/sysv/linux/mips/mips64/send.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/x86_64/send.c>
diff --git a/sysdeps/unix/sysv/linux/mips/syscalls.list b/sysdeps/unix/sysv/linux/mips/syscalls.list
index 48a33bb..f3621cd 100644
--- a/sysdeps/unix/sysv/linux/mips/syscalls.list
+++ b/sysdeps/unix/sysv/linux/mips/syscalls.list
@@ -17,8 +17,6 @@ getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
 listen		-	listen		i:ii	__listen	listen
-send		-	send		Ci:ibni	__libc_send	__send send
-sendto		-	sendto		Ci:ibnibn __libc_sendto	__sendto sendto
 setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
 socket		-	socket		i:iii	__socket	socket
diff --git a/sysdeps/unix/sysv/linux/nios2/sysdep.h b/sysdeps/unix/sysv/linux/nios2/sysdep.h
index b1c04cd..7b3efb2 100644
--- a/sysdeps/unix/sysv/linux/nios2/sysdep.h
+++ b/sysdeps/unix/sysv/linux/nios2/sysdep.h
@@ -140,6 +140,10 @@
 /* In order to get __set_errno() definition in INLINE_SYSCALL.  */
 #include <errno.h>
 
+/* Previously AArch64 used the generic version withouth the libc_hidden_def
+   which lead in a non existent __send symbol in libc.so.  */
+# undef HAVE_INTERNAL_SEND_SYMBOl
+
 /* Define a macro which expands into the inline wrapper code for a system
    call.  */
 #undef INLINE_SYSCALL
diff --git a/sysdeps/unix/sysv/linux/s390/kernel-features.h b/sysdeps/unix/sysv/linux/s390/kernel-features.h
index 59bc434..f44d429 100644
--- a/sysdeps/unix/sysv/linux/s390/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/s390/kernel-features.h
@@ -30,8 +30,6 @@
 # define __ASSUME_SETSOCKOPT_SYSCALL         1
 # define __ASSUME_GETSOCKNAME_SYSCALL        1
 # define __ASSUME_GETPEERNAME_SYSCALL        1
-# define __ASSUME_SENDTO_SYSCALL             1
-# define __ASSUME_SENDTO_FOR_SEND_SYSCALL    1
 # define __ASSUME_SHUTDOWN_SYSCALL           1
 #endif
 
@@ -47,6 +45,7 @@
 # undef __ASSUME_RECVMSG_SYSCALL
 # undef __ASSUME_CONNECT_SYSCALL
 # undef __ASSUME_RECVFROM_SYSCALL
+# undef __ASSUME_SENDTO_SYSCALL
 #endif
 
 /* s390 only supports ipc syscall.  */
diff --git a/sysdeps/unix/sysv/linux/send.c b/sysdeps/unix/sysv/linux/send.c
index 4c02c8b..8a0ea67 100644
--- a/sysdeps/unix/sysv/linux/send.c
+++ b/sysdeps/unix/sysv/linux/send.c
@@ -15,21 +15,16 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <signal.h>
 #include <sys/socket.h>
-
 #include <sysdep-cancel.h>
 #include <socketcall.h>
-#include <kernel-features.h>
-#include <sys/syscall.h>
 
 ssize_t
 __libc_send (int fd, const void *buf, size_t len, int flags)
 {
 #ifdef __ASSUME_SEND_SYSCALL
   return SYSCALL_CANCEL (send, fd, buf, len, flags);
-#elif defined __ASSUME_SENDTO_FOR_SEND_SYSCALL
+#elif defined __ASSUME_SENDTO_SYSCALL
   return SYSCALL_CANCEL (sendto, fd, buf, len, flags, NULL, 0);
 #else
   return SOCKETCALL_CANCEL (send, fd, buf, len, flags);
@@ -37,4 +32,6 @@ __libc_send (int fd, const void *buf, size_t len, int flags)
 }
 weak_alias (__libc_send, send)
 weak_alias (__libc_send, __send)
+#ifdef HAVE_INTERNAL_SEND_SYMBOl
 libc_hidden_def (__send)
+#endif
diff --git a/sysdeps/unix/sysv/linux/sendto.c b/sysdeps/unix/sysv/linux/sendto.c
index 2b9e1d7..be1bc6f 100644
--- a/sysdeps/unix/sysv/linux/sendto.c
+++ b/sysdeps/unix/sysv/linux/sendto.c
@@ -15,14 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <signal.h>
 #include <sys/socket.h>
-
 #include <sysdep-cancel.h>
 #include <socketcall.h>
-#include <kernel-features.h>
-#include <sys/syscall.h>
 
 ssize_t
 __libc_sendto (int fd, const void *buf, size_t len, int flags,
diff --git a/sysdeps/unix/sysv/linux/sh/kernel-features.h b/sysdeps/unix/sysv/linux/sh/kernel-features.h
index 61bdd45..72ec394 100644
--- a/sysdeps/unix/sysv/linux/sh/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/sh/kernel-features.h
@@ -32,7 +32,6 @@
 #define __ASSUME_GETPEERNAME_SYSCALL	1
 #define __ASSUME_SOCKETPAIR_SYSCALL	1
 #define __ASSUME_SEND_SYSCALL		1
-#define __ASSUME_SENDTO_SYSCALL		1
 #define __ASSUME_SHUTDOWN_SYSCALL	1
 #define __ASSUME_GETSOCKOPT_SYSCALL	1
 #define __ASSUME_SETSOCKOPT_SYSCALL	1
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list b/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list
index bf2cfdc..1e85118 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list
@@ -7,8 +7,6 @@ getpeername	-	getpeername	3	__getpeername	getpeername
 getsockname	-	getsockname	3	__getsockname	getsockname
 getsockopt	-	getsockopt	5	__getsockopt	getsockopt
 listen		-	listen		2	__listen	listen
-send		-	send		C:4	__libc_send	__send send
-sendto		-	sendto		C:6	__libc_sendto	__sendto sendto
 setsockopt	-	setsockopt	5	__setsockopt	setsockopt
 shutdown	-	shutdown	2	__shutdown	shutdown
 socketpair	-	socketpair	4	__socketpair	socketpair
diff --git a/sysdeps/unix/sysv/linux/sysdep.h b/sysdeps/unix/sysv/linux/sysdep.h
index 02c957e..ed1c807 100644
--- a/sysdeps/unix/sysv/linux/sysdep.h
+++ b/sysdeps/unix/sysv/linux/sysdep.h
@@ -62,3 +62,7 @@
 #define LO_HI_LONG(val) \
  (long) (val), \
  (long) (((uint64_t) (val)) >> 32)
+
+/* Exports the __send symbol on send.c linux implementation (some ABI have
+   it missing due the usage of a old generic version without it).  */
+#define HAVE_INTERNAL_SEND_SYMBOl	1
diff --git a/sysdeps/unix/sysv/linux/tile/sysdep.h b/sysdeps/unix/sysv/linux/tile/sysdep.h
index 70ff6b9..f8cfe66 100644
--- a/sysdeps/unix/sysv/linux/tile/sysdep.h
+++ b/sysdeps/unix/sysv/linux/tile/sysdep.h
@@ -218,6 +218,10 @@
 #define HAVE_CLOCK_GETTIME_VSYSCALL	1
 #define HAVE_GETTIMEOFDAY_VSYSCALL	1
 
+/* Previously tile used the generic version withouth the libc_hidden_def
+   which lead in a non existent __send symbol in libc.so.  */
+# undef HAVE_INTERNAL_SEND_SYMBOl
+
 #endif /* __ASSEMBLER__  */
 
 /* Pointer mangling support.  */
diff --git a/sysdeps/unix/sysv/linux/x86_64/send.c b/sysdeps/unix/sysv/linux/x86_64/send.c
deleted file mode 100644
index c4af9cd..0000000
--- a/sysdeps/unix/sysv/linux/x86_64/send.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/* Copyright (C) 2001-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <sys/socket.h>
-#include <sysdep-cancel.h>
-
-/* Send N bytes of BUF to socket FD.  Returns the number sent or -1.  */
-ssize_t
-__libc_send (int fd, const void *buf, size_t n, int flags)
-{
-  return SYSCALL_CANCEL (sendto, fd, buf, n, flags, NULL, (size_t) 0);
-}
-
-weak_alias (__libc_send, __send)
-libc_hidden_weak (__send)
-weak_alias (__send, send)
diff --git a/sysdeps/unix/sysv/linux/x86_64/syscalls.list b/sysdeps/unix/sysv/linux/x86_64/syscalls.list
index 365e115..d46524e 100644
--- a/sysdeps/unix/sysv/linux/x86_64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/x86_64/syscalls.list
@@ -11,7 +11,6 @@ getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
 listen		-	listen		i:ii	__listen	listen
-sendto		-	sendto		Ci:ibnibn	__libc_sendto	__sendto sendto
 setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
 socket		-	socket		i:iii	__socket	socket

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=a9448269fb2ec34412d5657b1eb02310b0b5cdd2

commit a9448269fb2ec34412d5657b1eb02310b0b5cdd2
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Thu Nov 17 18:47:00 2016 -0200

    Consolidate Linux recv and recvfrom implementation
    
    This patch consolidates the recv Linux syscall implementation on
    sysdeps/unix/sysv/linux/recv.c.  The changes are:
    
      1. Remove recv and recvfrom from auto-generation syscalls.list on the
         architecture that uses __NR_recv.
      2. Define __NR_recv for such architectures.  It was done instead of
         defining in default kernel-features.h because current Linux practice
         for new ports are to implement only __NR_recvfrom [1] and it will
         require adding new kernel-features for ports that do not require it
         (aarch64 for instance).
      3. Define __NR_recvfrom as default (__ASSUME_RECVFROM_SYSCALL) and undef
         for architectures that do not support it.
      4. Remove __ASSUME_RECVFROM_FOR_RECV_SYSCALL and decide to use
         __NR_recvfrom for recv generation based on __ASSUME_RECVFROM__SYSCALL.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/alpha/kernel-features.h
    	(__ASSUME_RECV_SYSCALL): Define.
    	* sysdeps/unix/sysv/linux/arm/kernel-features.h
    	(__ASSUME_RECV_SYSCALL): Likewise.
    	* sysdeps/unix/sysv/linux/hppa/kernel-features.h
    	(__ASSUME_RECV_SYSCALL): Likewise.
    	* sysdeps/unix/sysv/linux/ia64/kernel-features.h
    	(__ASSUME_RECV_SYSCALL): Likewise.
    	* sysdeps/unix/sysv/linux/mips/kernel-features.h
    	[_MIPS_SIM == _ABIO32] (__ASSUME_RECV_SYSCALL): Likewise.
    	* sysdeps/unix/sysv/linux/i386/kernel-features.h
    	(__ASSUME_RECVFROM_SYSCALL): Define whether the kernel supports it.
    	(__ASSUME_RECVFROM_FOR_RECV_SYSCALL): Undefine.
    	* sysdeps/unix/sysv/linux/m68k/kernel-features.h
    	(__ASSUME_RECVFROM_SYSCALL): Define whether the kernel supports it.
    	(__ASSUME_RECVFROM_FOR_RECV_SYSCALL): Undefine.
    	* sysdeps/unix/sysv/linux/s390/kernel-features.h
    	(__ASSUME_RECVFROM_SYSCALL): Define whether the kernel supports it.
    	(__ASSUME_RECVFROM_FOR_RECV_SYSCALL): Undefine.
    	* sysdeps/unix/sysv/linux/kernel-features.h
    	(__ASSUME_RECVFROM_SYSCALL): Define as default.
    	* sysdeps/unix/sysv/linux/microblaze/kernel-features.h
    	(__ASSUME_RECVFROM_SYSCALL): Define.
    	(__ASSUME_RECVFROM_FOR_RECV_SYSCALL): Likewise.
    	* sysdeps/unix/sysv/linux/powerpc/kernel-features.h
    	(__ASSUME_RECVFROM_SYSCALL): Define.
    	(__ASSUME_RECVFROM_FOR_RECV_SYSCALL): Likewise.
    	* sysdeps/unix/sysv/linux/sh/kernel-features.h
    	(__ASSUME_RECVFROM_SYSCALL): Define.
    	(__ASSUME_RECVFROM_FOR_RECV_SYSCALL): Likewise.
    	* sysdeps/unix/sysv/linux/sparc/kernel-features.h
    	(__ASSUME_RECVFROM_SYSCALL): Define whether the kernel supports it.
    	* sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove recv and
    	recvfrom from uto-generation list.
    	* sysdeps/unix/sysv/linux/arm/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/generic/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/hppa/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/ia64/syscalls.list: Likwise.
    	* sysdeps/unix/sysv/linux/mips/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/generic/recv.c: Remove file.
    	* sysdeps/unix/sysv/linux/x86_64/recv.c: Likewise.
    	* sysdeps/unix/sysv/linux/mips/mips64/recv.c: Likewise.
    	* sysdeps/unix/sysv/linux/recv.c
    	(__ASSUME_RECVFROM_FOR_RECV_SYSCALL): Replace by
    	__ASSUME_RECVFROM_SYSCALL.
    
    [1] include/asm-generic/unistd.h (__ARCH_WANT_SYSCALL_DEPRECATED)

diff --git a/ChangeLog b/ChangeLog
index c21294e..daf2f0f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,54 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/alpha/kernel-features.h
+	(__ASSUME_RECV_SYSCALL): Define.
+	* sysdeps/unix/sysv/linux/arm/kernel-features.h
+	(__ASSUME_RECV_SYSCALL): Likewise.
+	* sysdeps/unix/sysv/linux/hppa/kernel-features.h
+	(__ASSUME_RECV_SYSCALL): Likewise.
+	* sysdeps/unix/sysv/linux/ia64/kernel-features.h
+	(__ASSUME_RECV_SYSCALL): Likewise.
+	* sysdeps/unix/sysv/linux/mips/kernel-features.h
+	[_MIPS_SIM == _ABIO32] (__ASSUME_RECV_SYSCALL): Likewise.
+	* sysdeps/unix/sysv/linux/hppa/syscalls.list
+	(__ASSUME_RECV_SYSCALL): Likewise.
+	* sysdeps/unix/sysv/linux/i386/kernel-features.h
+	(__ASSUME_RECVFROM_SYSCALL): Define whether the kernel supports it.
+	(__ASSUME_RECVFROM_FOR_RECV_SYSCALL): Undefine.
+	* sysdeps/unix/sysv/linux/m68k/kernel-features.h
+	(__ASSUME_RECVFROM_SYSCALL): Define whether the kernel supports it.
+	(__ASSUME_RECVFROM_FOR_RECV_SYSCALL): Undefine.
+	* sysdeps/unix/sysv/linux/s390/kernel-features.h
+	(__ASSUME_RECVFROM_SYSCALL): Define whether the kernel supports it.
+	(__ASSUME_RECVFROM_FOR_RECV_SYSCALL): Undefine.
+	* sysdeps/unix/sysv/linux/kernel-features.h
+	(__ASSUME_RECVFROM_SYSCALL): Define as default.
+	* sysdeps/unix/sysv/linux/microblaze/kernel-features.h
+	(__ASSUME_RECVFROM_SYSCALL): Define.
+	(__ASSUME_RECVFROM_FOR_RECV_SYSCALL): Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/kernel-features.h
+	(__ASSUME_RECVFROM_SYSCALL): Define.
+	(__ASSUME_RECVFROM_FOR_RECV_SYSCALL): Likewise.
+	* sysdeps/unix/sysv/linux/sh/kernel-features.h
+	(__ASSUME_RECVFROM_SYSCALL): Define.
+	(__ASSUME_RECVFROM_FOR_RECV_SYSCALL): Likewise.
+	* sysdeps/unix/sysv/linux/sparc/kernel-features.h
+	(__ASSUME_RECVFROM_SYSCALL): Define whether the kernel supports it.
+	* sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove recv and
+	recvfrom from uto-generation list.
+	* sysdeps/unix/sysv/linux/arm/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/generic/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/hppa/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/ia64/syscalls.list: Likwise.
+	* sysdeps/unix/sysv/linux/mips/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/generic/recv.c: Remove file.
+	* sysdeps/unix/sysv/linux/x86_64/recv.c: Likewise.
+	* sysdeps/unix/sysv/linux/mips/mips64/recv.c: Likewise.
+	* sysdeps/unix/sysv/linux/recv.c
+	(__ASSUME_RECVFROM_FOR_RECV_SYSCALL): Replace by
+	__ASSUME_RECVFROM_SYSCALL.
+
 	* sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove connect from
 	auto-generation list.
 	* sysdeps/unix/sysv/linux/arm/syscalls.list: Likewise.
diff --git a/sysdeps/unix/sysv/linux/alpha/kernel-features.h b/sysdeps/unix/sysv/linux/alpha/kernel-features.h
index 0614c78..3383a98 100644
--- a/sysdeps/unix/sysv/linux/alpha/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/alpha/kernel-features.h
@@ -32,4 +32,6 @@
 /* Alpha defines SysV ipc shmat syscall with a different name.  */
 #define __NR_shmat __NR_osf_shmat
 
+#define __ASSUME_RECV_SYSCALL	1
+
 #endif /* _KERNEL_FEATURES_H */
diff --git a/sysdeps/unix/sysv/linux/alpha/syscalls.list b/sysdeps/unix/sysv/linux/alpha/syscalls.list
index e9efb43..8a62b6e 100644
--- a/sysdeps/unix/sysv/linux/alpha/syscalls.list
+++ b/sysdeps/unix/sysv/linux/alpha/syscalls.list
@@ -10,8 +10,6 @@ getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
 listen		-	listen		i:ii	__listen	listen
-recv		-	recv		Ci:ibni	__libc_recv	__recv recv
-recvfrom	-	recvfrom	Ci:ibniBN	__libc_recvfrom	__recvfrom recvfrom
 send		-	send		Ci:ibni	__libc_send	__send send
 sendto		-	sendto		Ci:ibnibn	__libc_sendto	__sendto sendto
 setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
diff --git a/sysdeps/unix/sysv/linux/arm/kernel-features.h b/sysdeps/unix/sysv/linux/arm/kernel-features.h
index a3c0d9a..104c9f9 100644
--- a/sysdeps/unix/sysv/linux/arm/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/arm/kernel-features.h
@@ -37,3 +37,5 @@
 /* ARM only has a syscall for fadvise64{_64} and it is defined with a
    non-standard name.  */
 #define __NR_fadvise64_64 __NR_arm_fadvise64_64
+
+#define __ASSUME_RECV_SYSCALL   1
diff --git a/sysdeps/unix/sysv/linux/arm/syscalls.list b/sysdeps/unix/sysv/linux/arm/syscalls.list
index 1c12be4..9f445e6 100644
--- a/sysdeps/unix/sysv/linux/arm/syscalls.list
+++ b/sysdeps/unix/sysv/linux/arm/syscalls.list
@@ -27,8 +27,6 @@ getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
 listen		-	listen		i:ii	__listen	listen
-recv		-	recv		Ci:ibni	__libc_recv	__recv recv
-recvfrom	-	recvfrom	Ci:ibniBN	__libc_recvfrom	__recvfrom recvfrom
 send		-	send		Ci:ibni	__libc_send	__send send
 sendto		-	sendto		Ci:ibnibn	__libc_sendto	__sendto sendto
 setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
diff --git a/sysdeps/unix/sysv/linux/generic/recv.c b/sysdeps/unix/sysv/linux/generic/recv.c
deleted file mode 100644
index c1aebd7..0000000
--- a/sysdeps/unix/sysv/linux/generic/recv.c
+++ /dev/null
@@ -1,32 +0,0 @@
-/* Copyright (C) 2011-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library.  If not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sysdep-cancel.h>
-#include <libc-symbols.h>
-
-ssize_t
-__libc_recv (int sockfd, void *buffer, size_t len, int flags)
-{
-  return SYSCALL_CANCEL (recvfrom, sockfd, buffer, len, flags,
-			 NULL, NULL);
-}
-strong_alias (__libc_recv, __recv)
-libc_hidden_def (__recv)
-weak_alias (__libc_recv, recv)
diff --git a/sysdeps/unix/sysv/linux/generic/syscalls.list b/sysdeps/unix/sysv/linux/generic/syscalls.list
index 2874a1f..c16ee52 100644
--- a/sysdeps/unix/sysv/linux/generic/syscalls.list
+++ b/sysdeps/unix/sysv/linux/generic/syscalls.list
@@ -8,7 +8,6 @@ listen		-	listen		i:ii	__listen	listen
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 sendto		-	sendto		Ci:ibnibn	__libc_sendto	__sendto sendto
-recvfrom	-	recvfrom	Ci:ibniBN	__libc_recvfrom	__recvfrom recvfrom
 setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown
diff --git a/sysdeps/unix/sysv/linux/hppa/kernel-features.h b/sysdeps/unix/sysv/linux/hppa/kernel-features.h
index 7ff5434..1fd7398 100644
--- a/sysdeps/unix/sysv/linux/hppa/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/hppa/kernel-features.h
@@ -24,3 +24,5 @@
 #endif
 
 #include_next <kernel-features.h>
+
+#define __ASSUME_RECV_SYSCALL   1
diff --git a/sysdeps/unix/sysv/linux/hppa/syscalls.list b/sysdeps/unix/sysv/linux/hppa/syscalls.list
index 288d096..1248877 100644
--- a/sysdeps/unix/sysv/linux/hppa/syscalls.list
+++ b/sysdeps/unix/sysv/linux/hppa/syscalls.list
@@ -6,8 +6,6 @@ getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
 listen		-	listen		i:ii	__listen	listen
-recv		-	recv		Ci:ibni	__libc_recv	__recv recv
-recvfrom	-	recvfrom	Ci:ibniBN	__libc_recvfrom	__recvfrom recvfrom
 send		-	send		Ci:ibni	__libc_send	__send send
 sendto		-	sendto		Ci:ibnibn	__libc_sendto	__sendto sendto
 setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
diff --git a/sysdeps/unix/sysv/linux/i386/kernel-features.h b/sysdeps/unix/sysv/linux/i386/kernel-features.h
index 23ca794..a886442 100644
--- a/sysdeps/unix/sysv/linux/i386/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/i386/kernel-features.h
@@ -38,8 +38,6 @@
 # define __ASSUME_GETPEERNAME_SYSCALL        1
 # define __ASSUME_SENDTO_SYSCALL             1
 # define __ASSUME_SENDTO_FOR_SEND_SYSCALL    1
-# define __ASSUME_RECVFROM_SYSCALL           1
-# define __ASSUME_RECVFROM_FOR_RECV_SYSCALL  1
 # define __ASSUME_SHUTDOWN_SYSCALL           1
 #endif
 
@@ -52,6 +50,7 @@
 # undef __ASSUME_SENDMSG_SYSCALL
 # undef __ASSUME_RECVMSG_SYSCALL
 # undef __ASSUME_CONNECT_SYSCALL
+# undef __ASSUME_RECVFROM_SYSCALL
 #endif
 
 /* i686 only supports ipc syscall.  */
diff --git a/sysdeps/unix/sysv/linux/ia64/kernel-features.h b/sysdeps/unix/sysv/linux/ia64/kernel-features.h
index d13e403..80e41b6 100644
--- a/sysdeps/unix/sysv/linux/ia64/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/ia64/kernel-features.h
@@ -28,4 +28,6 @@
 # undef __ASSUME_ACCEPT4
 #endif
 
+#define __ASSUME_RECV_SYSCALL   	1
+
 #endif /* _KERNEL_FEATURES_H */
diff --git a/sysdeps/unix/sysv/linux/ia64/syscalls.list b/sysdeps/unix/sysv/linux/ia64/syscalls.list
index 32fdb08..24e9c98 100644
--- a/sysdeps/unix/sysv/linux/ia64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/ia64/syscalls.list
@@ -10,8 +10,6 @@ getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
 listen		-	listen		i:ii	__listen	listen
-recv		-	recv		Ci:ibni	__libc_recv	__recv recv
-recvfrom	-	recvfrom	Ci:ibniBN	__libc_recvfrom	__recvfrom recvfrom
 send		-	send		Ci:ibni	__libc_send	__send send
 sendto		-	sendto		Ci:ibnibn	__libc_sendto	__sendto sendto
 setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h
index e93f5f4..c6c816e 100644
--- a/sysdeps/unix/sysv/linux/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/kernel-features.h
@@ -149,6 +149,7 @@
 #define __ASSUME_RECVMSG_SYSCALL	1
 #define __ASSUME_ACCEPT_SYSCALL		1
 #define __ASSUME_CONNECT_SYSCALL	1
+#define __ASSUME_RECVFROM_SYSCALL	1
 
 /* Support for SysV IPC through wired syscalls.  All supported architectures
    either support ipc syscall and/or all the ipc correspondent syscalls.  */
diff --git a/sysdeps/unix/sysv/linux/m68k/kernel-features.h b/sysdeps/unix/sysv/linux/m68k/kernel-features.h
index a58c168..5e756ab 100644
--- a/sysdeps/unix/sysv/linux/m68k/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/m68k/kernel-features.h
@@ -32,8 +32,6 @@
 # define __ASSUME_GETPEERNAME_SYSCALL        1
 # define __ASSUME_SENDTO_SYSCALL             1
 # define __ASSUME_SENDTO_FOR_SEND_SYSCALL    1
-# define __ASSUME_RECVFROM_SYSCALL           1
-# define __ASSUME_RECVFROM_FOR_RECV_SYSCALL  1
 # define __ASSUME_SHUTDOWN_SYSCALL           1
 #endif
 
@@ -49,6 +47,7 @@
 # undef __ASSUME_SENDMSG_SYSCALL
 # undef __ASSUME_RECVMSG_SYSCALL
 # undef __ASSUME_CONNECT_SYSCALL
+# undef __ASSUME_RECVFROM_SYSCALL
 #endif
 
 /* No support for PI futexes or robust mutexes before 3.10 for m68k.  */
diff --git a/sysdeps/unix/sysv/linux/microblaze/kernel-features.h b/sysdeps/unix/sysv/linux/microblaze/kernel-features.h
index 9532d57..8c59c89 100644
--- a/sysdeps/unix/sysv/linux/microblaze/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/microblaze/kernel-features.h
@@ -28,9 +28,8 @@
 #define __ASSUME_GETPEERNAME_SYSCALL	1
 #define __ASSUME_SOCKETPAIR_SYSCALL	1
 #define __ASSUME_SEND_SYSCALL		1
-#define __ASSUME_SENDTO_SYSCALL		1
 #define __ASSUME_RECV_SYSCALL		1
-#define __ASSUME_RECVFROM_SYSCALL	1
+#define __ASSUME_SENDTO_SYSCALL		1
 #define __ASSUME_SHUTDOWN_SYSCALL	1
 #define __ASSUME_GETSOCKOPT_SYSCALL	1
 #define __ASSUME_SETSOCKOPT_SYSCALL	1
diff --git a/sysdeps/unix/sysv/linux/mips/kernel-features.h b/sysdeps/unix/sysv/linux/mips/kernel-features.h
index 83a5c8f..276d12f 100644
--- a/sysdeps/unix/sysv/linux/mips/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/mips/kernel-features.h
@@ -34,6 +34,8 @@
 # define __ASSUME_ALIGNED_REGISTER_PAIRS	1
 /* mips32 only supports ipc syscall.  */
 # undef __ASSUME_DIRECT_SYSVIPC_SYSCALLS
+/* mips32 support wire-up network syscalls.  */
+# define __ASSUME_RECV_SYSCALL		1
 #endif
 
 /* Define that mips64-n32 is a ILP32 ABI to set the correct interface to
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/recv.c b/sysdeps/unix/sysv/linux/mips/mips64/recv.c
deleted file mode 100644
index b910525..0000000
--- a/sysdeps/unix/sysv/linux/mips/mips64/recv.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/x86_64/recv.c>
diff --git a/sysdeps/unix/sysv/linux/mips/syscalls.list b/sysdeps/unix/sysv/linux/mips/syscalls.list
index 8b0c5a3..48a33bb 100644
--- a/sysdeps/unix/sysv/linux/mips/syscalls.list
+++ b/sysdeps/unix/sysv/linux/mips/syscalls.list
@@ -17,8 +17,6 @@ getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
 listen		-	listen		i:ii	__listen	listen
-recv		-	recv		Ci:ibni	__libc_recv	__recv recv
-recvfrom	-	recvfrom	Ci:ibniBN __libc_recvfrom __recvfrom recvfrom
 send		-	send		Ci:ibni	__libc_send	__send send
 sendto		-	sendto		Ci:ibnibn __libc_sendto	__sendto sendto
 setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
diff --git a/sysdeps/unix/sysv/linux/powerpc/kernel-features.h b/sysdeps/unix/sysv/linux/powerpc/kernel-features.h
index 272800c..a0d2e8f 100644
--- a/sysdeps/unix/sysv/linux/powerpc/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/powerpc/kernel-features.h
@@ -31,7 +31,6 @@
 #define __ASSUME_SEND_SYSCALL		1
 #define __ASSUME_SENDTO_SYSCALL		1
 #define __ASSUME_RECV_SYSCALL		1
-#define __ASSUME_RECVFROM_SYSCALL	1
 #define __ASSUME_SHUTDOWN_SYSCALL	1
 #define __ASSUME_GETSOCKOPT_SYSCALL	1
 #define __ASSUME_SETSOCKOPT_SYSCALL	1
diff --git a/sysdeps/unix/sysv/linux/recv.c b/sysdeps/unix/sysv/linux/recv.c
index 6d62cf8..2467d99 100644
--- a/sysdeps/unix/sysv/linux/recv.c
+++ b/sysdeps/unix/sysv/linux/recv.c
@@ -15,21 +15,16 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <signal.h>
 #include <sys/socket.h>
-
 #include <sysdep-cancel.h>
 #include <socketcall.h>
-#include <kernel-features.h>
-#include <sys/syscall.h>
 
 ssize_t
 __libc_recv (int fd, void *buf, size_t len, int flags)
 {
 #ifdef __ASSUME_RECV_SYSCALL
   return SYSCALL_CANCEL (recv, fd, buf, len, flags);
-#elif defined __ASSUME_RECVFROM_FOR_RECV_SYSCALL
+#elif defined __ASSUME_RECVFROM_SYSCALL
   return SYSCALL_CANCEL (recvfrom, fd, buf, len, flags, NULL, NULL);
 #else
   return SOCKETCALL_CANCEL (recv, fd, buf, len, flags);
diff --git a/sysdeps/unix/sysv/linux/recvfrom.c b/sysdeps/unix/sysv/linux/recvfrom.c
index 10ffb26..27c2360 100644
--- a/sysdeps/unix/sysv/linux/recvfrom.c
+++ b/sysdeps/unix/sysv/linux/recvfrom.c
@@ -15,14 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <signal.h>
 #include <sys/socket.h>
-
 #include <sysdep-cancel.h>
 #include <socketcall.h>
-#include <kernel-features.h>
-#include <sys/syscall.h>
 
 ssize_t
 __libc_recvfrom (int fd, void *buf, size_t len, int flags,
diff --git a/sysdeps/unix/sysv/linux/s390/kernel-features.h b/sysdeps/unix/sysv/linux/s390/kernel-features.h
index 50a7e8c..59bc434 100644
--- a/sysdeps/unix/sysv/linux/s390/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/s390/kernel-features.h
@@ -32,8 +32,6 @@
 # define __ASSUME_GETPEERNAME_SYSCALL        1
 # define __ASSUME_SENDTO_SYSCALL             1
 # define __ASSUME_SENDTO_FOR_SEND_SYSCALL    1
-# define __ASSUME_RECVFROM_SYSCALL           1
-# define __ASSUME_RECVFROM_FOR_RECV_SYSCALL  1
 # define __ASSUME_SHUTDOWN_SYSCALL           1
 #endif
 
@@ -48,6 +46,7 @@
 # undef __ASSUME_SENDMSG_SYSCALL
 # undef __ASSUME_RECVMSG_SYSCALL
 # undef __ASSUME_CONNECT_SYSCALL
+# undef __ASSUME_RECVFROM_SYSCALL
 #endif
 
 /* s390 only supports ipc syscall.  */
diff --git a/sysdeps/unix/sysv/linux/sh/kernel-features.h b/sysdeps/unix/sysv/linux/sh/kernel-features.h
index 7a83211..61bdd45 100644
--- a/sysdeps/unix/sysv/linux/sh/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/sh/kernel-features.h
@@ -33,8 +33,6 @@
 #define __ASSUME_SOCKETPAIR_SYSCALL	1
 #define __ASSUME_SEND_SYSCALL		1
 #define __ASSUME_SENDTO_SYSCALL		1
-#define __ASSUME_RECV_SYSCALL		1
-#define __ASSUME_RECVFROM_SYSCALL	1
 #define __ASSUME_SHUTDOWN_SYSCALL	1
 #define __ASSUME_GETSOCKOPT_SYSCALL	1
 #define __ASSUME_SETSOCKOPT_SYSCALL	1
diff --git a/sysdeps/unix/sysv/linux/sparc/kernel-features.h b/sysdeps/unix/sysv/linux/sparc/kernel-features.h
index ba6e4c4..8e74478 100644
--- a/sysdeps/unix/sysv/linux/sparc/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/sparc/kernel-features.h
@@ -41,6 +41,7 @@
 #if !defined __arch64__
 # undef __ASSUME_ACCEPT_SYSCALL
 # undef __ASSUME_CONNECT_SYSCALL
+# undef __ASSUME_RECVFROM_SYSCALL
 #endif
 
 /* sparc only supports ipc syscall.  */
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list b/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list
index 4c785fd..bf2cfdc 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list
@@ -7,8 +7,6 @@ getpeername	-	getpeername	3	__getpeername	getpeername
 getsockname	-	getsockname	3	__getsockname	getsockname
 getsockopt	-	getsockopt	5	__getsockopt	getsockopt
 listen		-	listen		2	__listen	listen
-recv		-	recv		C:4	__libc_recv	__recv recv
-recvfrom	-	recvfrom	C:6	__libc_recvfrom	__recvfrom recvfrom
 send		-	send		C:4	__libc_send	__send send
 sendto		-	sendto		C:6	__libc_sendto	__sendto sendto
 setsockopt	-	setsockopt	5	__setsockopt	setsockopt
diff --git a/sysdeps/unix/sysv/linux/x86_64/recv.c b/sysdeps/unix/sysv/linux/x86_64/recv.c
deleted file mode 100644
index 10be5d5..0000000
--- a/sysdeps/unix/sysv/linux/x86_64/recv.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/* Copyright (C) 2001-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <sys/socket.h>
-#include <sysdep-cancel.h>
-
-/* Read N bytes into BUF from socket FD.
-   Returns the number read or -1 for errors.  */
-
-ssize_t
-__libc_recv (int fd, void *buf, size_t n, int flags)
-{
-  return SYSCALL_CANCEL (recvfrom, fd, buf, n, flags, NULL, NULL);
-}
-
-weak_alias (__libc_recv, __recv)
-libc_hidden_weak (__recv)
-weak_alias (__recv, recv)
diff --git a/sysdeps/unix/sysv/linux/x86_64/syscalls.list b/sysdeps/unix/sysv/linux/x86_64/syscalls.list
index adf6ae6..365e115 100644
--- a/sysdeps/unix/sysv/linux/x86_64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/x86_64/syscalls.list
@@ -11,7 +11,6 @@ getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
 listen		-	listen		i:ii	__listen	listen
-recvfrom	-	recvfrom	Ci:ibniBN	__libc_recvfrom	__recvfrom recvfrom
 sendto		-	sendto		Ci:ibnibn	__libc_sendto	__sendto sendto
 setsockopt	-	setsockopt	i:iiibn	__setsockopt	setsockopt
 shutdown	-	shutdown	i:ii	__shutdown	shutdown

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=5344092b29b1c205af5615d5725056c8c50c8ffa

commit 5344092b29b1c205af5615d5725056c8c50c8ffa
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Thu Nov 17 18:15:52 2016 -0200

    Consolidate Linux connect implementation
    
    This patch consolidates the connect Linux syscall implementation on
    sysdeps/unix/sysv/linux/accept.c.  The changes are:
    
      1. Remove connect from auto-generation syscalls.list on the architecture
         that uses __NR_connect.
      2. Define __NR_conect as default (__ASSUME_CONNECT_SYSCALL) and undef for
         architectures that do not support it.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove connect from
    	auto-generation list.
    	* sysdeps/unix/sysv/linux/arm/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/generic/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/x86_64/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/hppa/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/ia64/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/mips/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/connect.c: Simplify include list.
    	* sysdeps/unix/sysv/linux/kernel-features.h
    	(__ASSUME_CONNECT_SYSCALL): Define.
    	* sysdeps/unix/sysv/linux/i386/kernel-features.h
    	(__ASSUME_CONNECT_SYSCALL): Undef if kernel does not support it.
    	* sysdeps/unix/sysv/linux/m68k/kernel-features.h
    	(__ASSUME_CONNECT_SYSCALL): Likewise.
    	* sysdeps/unix/sysv/linux/s390/kernel-features.h
    	(__ASSUME_CONNECT_SYSCALL): Likewise.
    	* sysdeps/unix/sysv/linux/sparc/kernel-features.h
    	(__ASSUME_CONNECT_SYSCALL): Likewise.

diff --git a/ChangeLog b/ChangeLog
index d1cf349..c21294e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,26 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove connect from
+	auto-generation list.
+	* sysdeps/unix/sysv/linux/arm/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/generic/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/x86_64/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/hppa/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/ia64/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/mips/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/connect.c: Simplify include list.
+	* sysdeps/unix/sysv/linux/kernel-features.h
+	(__ASSUME_CONNECT_SYSCALL): Define.
+	* sysdeps/unix/sysv/linux/i386/kernel-features.h
+	(__ASSUME_CONNECT_SYSCALL): Undef if kernel does not support it.
+	* sysdeps/unix/sysv/linux/m68k/kernel-features.h
+	(__ASSUME_CONNECT_SYSCALL): Likewise.
+	* sysdeps/unix/sysv/linux/s390/kernel-features.h
+	(__ASSUME_CONNECT_SYSCALL): Likewise.
+	* sysdeps/unix/sysv/linux/sparc/kernel-features.h
+	(__ASSUME_CONNECT_SYSCALL): Likewise.
+
 	* sysdeps/unix/sysv/linux/accept.c (__libc_accept): Replace
 	__ASSUME_ACCEPT4_FOR_ACCEPT_SYSCALL by __ASSUME_ACCEPT4_SYSCALL.
 	* sysdeps/unix/sysv/linux/alpha/syscalls.list?: Remove accept from
diff --git a/sysdeps/unix/sysv/linux/alpha/syscalls.list b/sysdeps/unix/sysv/linux/alpha/syscalls.list
index 4cfe19e..e9efb43 100644
--- a/sysdeps/unix/sysv/linux/alpha/syscalls.list
+++ b/sysdeps/unix/sysv/linux/alpha/syscalls.list
@@ -6,7 +6,6 @@ getpriority	-	getpriority	i:ii	__getpriority	getpriority
 
 # proper socket implementations:
 bind		-	bind		i:ipi	__bind		bind
-connect		-	connect		Ci:ipi	__libc_connect	__connect connect
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
diff --git a/sysdeps/unix/sysv/linux/arm/syscalls.list b/sysdeps/unix/sysv/linux/arm/syscalls.list
index 1c4f61f..1c12be4 100644
--- a/sysdeps/unix/sysv/linux/arm/syscalls.list
+++ b/sysdeps/unix/sysv/linux/arm/syscalls.list
@@ -23,7 +23,6 @@ personality	EXTRA	personality	Ei:i	__personality	personality
 
 # proper socket implementations:
 bind		-	bind		i:ipi	__bind		bind
-connect		-	connect		Ci:ipi	__libc_connect	__connect connect
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
diff --git a/sysdeps/unix/sysv/linux/connect.c b/sysdeps/unix/sysv/linux/connect.c
index 3837a5b..f6ab5df 100644
--- a/sysdeps/unix/sysv/linux/connect.c
+++ b/sysdeps/unix/sysv/linux/connect.c
@@ -15,14 +15,9 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <signal.h>
 #include <sys/socket.h>
-
 #include <sysdep-cancel.h>
 #include <socketcall.h>
-#include <kernel-features.h>
-#include <sys/syscall.h>
 
 int
 __libc_connect (int fd, __CONST_SOCKADDR_ARG addr, socklen_t len)
diff --git a/sysdeps/unix/sysv/linux/generic/syscalls.list b/sysdeps/unix/sysv/linux/generic/syscalls.list
index b176a72..2874a1f 100644
--- a/sysdeps/unix/sysv/linux/generic/syscalls.list
+++ b/sysdeps/unix/sysv/linux/generic/syscalls.list
@@ -5,7 +5,6 @@ socket		-	socket		i:iii	__socket	socket
 socketpair	-	socketpair	i:iiif	__socketpair	socketpair
 bind		-	bind		i:ipi	__bind		bind
 listen		-	listen		i:ii	__listen	listen
-connect		-	connect		Ci:ipi	__libc_connect	__connect connect
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 sendto		-	sendto		Ci:ibnibn	__libc_sendto	__sendto sendto
diff --git a/sysdeps/unix/sysv/linux/hppa/syscalls.list b/sysdeps/unix/sysv/linux/hppa/syscalls.list
index ee814fb..288d096 100644
--- a/sysdeps/unix/sysv/linux/hppa/syscalls.list
+++ b/sysdeps/unix/sysv/linux/hppa/syscalls.list
@@ -2,7 +2,6 @@
 
 # proper socket implementations:
 bind		-	bind		i:ipi	__bind		bind
-connect		-	connect		Ci:ipi	__libc_connect	__connect connect
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
diff --git a/sysdeps/unix/sysv/linux/i386/kernel-features.h b/sysdeps/unix/sysv/linux/i386/kernel-features.h
index 07462f8..23ca794 100644
--- a/sysdeps/unix/sysv/linux/i386/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/i386/kernel-features.h
@@ -31,7 +31,6 @@
 # define __ASSUME_SOCKET_SYSCALL             1
 # define __ASSUME_SOCKETPAIR_SYSCALL         1
 # define __ASSUME_BIND_SYSCALL               1
-# define __ASSUME_CONNECT_SYSCALL            1
 # define __ASSUME_LISTEN_SYSCALL             1
 # define __ASSUME_GETSOCKOPT_SYSCALL         1
 # define __ASSUME_SETSOCKOPT_SYSCALL         1
@@ -52,6 +51,7 @@
 # undef __ASSUME_ACCEPT4_SYSCALL
 # undef __ASSUME_SENDMSG_SYSCALL
 # undef __ASSUME_RECVMSG_SYSCALL
+# undef __ASSUME_CONNECT_SYSCALL
 #endif
 
 /* i686 only supports ipc syscall.  */
diff --git a/sysdeps/unix/sysv/linux/ia64/syscalls.list b/sysdeps/unix/sysv/linux/ia64/syscalls.list
index 96db4c3..32fdb08 100644
--- a/sysdeps/unix/sysv/linux/ia64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/ia64/syscalls.list
@@ -6,7 +6,6 @@ getpriority	-	getpriority	i:ii	__getpriority	getpriority
 
 # proper socket implementations:
 bind		-	bind		i:ipi	__bind		bind
-connect		-	connect		Ci:ipi	__libc_connect	__connect connect
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h
index 78b091b..e93f5f4 100644
--- a/sysdeps/unix/sysv/linux/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/kernel-features.h
@@ -148,6 +148,7 @@
 #define __ASSUME_SENDMSG_SYSCALL	1
 #define __ASSUME_RECVMSG_SYSCALL	1
 #define __ASSUME_ACCEPT_SYSCALL		1
+#define __ASSUME_CONNECT_SYSCALL	1
 
 /* Support for SysV IPC through wired syscalls.  All supported architectures
    either support ipc syscall and/or all the ipc correspondent syscalls.  */
diff --git a/sysdeps/unix/sysv/linux/m68k/kernel-features.h b/sysdeps/unix/sysv/linux/m68k/kernel-features.h
index f583ae7..a58c168 100644
--- a/sysdeps/unix/sysv/linux/m68k/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/m68k/kernel-features.h
@@ -25,7 +25,6 @@
 # define __ASSUME_SOCKET_SYSCALL             1
 # define __ASSUME_SOCKETPAIR_SYSCALL         1
 # define __ASSUME_BIND_SYSCALL               1
-# define __ASSUME_CONNECT_SYSCALL            1
 # define __ASSUME_LISTEN_SYSCALL             1
 # define __ASSUME_GETSOCKOPT_SYSCALL         1
 # define __ASSUME_SETSOCKOPT_SYSCALL         1
@@ -49,6 +48,7 @@
 # undef __ASSUME_SENDMMSG_SYSCALL
 # undef __ASSUME_SENDMSG_SYSCALL
 # undef __ASSUME_RECVMSG_SYSCALL
+# undef __ASSUME_CONNECT_SYSCALL
 #endif
 
 /* No support for PI futexes or robust mutexes before 3.10 for m68k.  */
diff --git a/sysdeps/unix/sysv/linux/mips/syscalls.list b/sysdeps/unix/sysv/linux/mips/syscalls.list
index 81ea2a7..8b0c5a3 100644
--- a/sysdeps/unix/sysv/linux/mips/syscalls.list
+++ b/sysdeps/unix/sysv/linux/mips/syscalls.list
@@ -13,7 +13,6 @@ sysmips		-	sysmips		i:iiii	__sysmips	sysmips
 # it's provided for compatibility, though.
 #
 bind		-	bind		i:ipi	__bind		bind
-connect		-	connect		Ci:ipi	__libc_connect	__connect connect
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt
diff --git a/sysdeps/unix/sysv/linux/s390/kernel-features.h b/sysdeps/unix/sysv/linux/s390/kernel-features.h
index ccfb0a2..50a7e8c 100644
--- a/sysdeps/unix/sysv/linux/s390/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/s390/kernel-features.h
@@ -25,7 +25,6 @@
 # define __ASSUME_SOCKET_SYSCALL             1
 # define __ASSUME_SOCKETPAIR_SYSCALL         1
 # define __ASSUME_BIND_SYSCALL               1
-# define __ASSUME_CONNECT_SYSCALL            1
 # define __ASSUME_LISTEN_SYSCALL             1
 # define __ASSUME_GETSOCKOPT_SYSCALL         1
 # define __ASSUME_SETSOCKOPT_SYSCALL         1
@@ -48,6 +47,7 @@
 # undef __ASSUME_SENDMMSG_SYSCALL
 # undef __ASSUME_SENDMSG_SYSCALL
 # undef __ASSUME_RECVMSG_SYSCALL
+# undef __ASSUME_CONNECT_SYSCALL
 #endif
 
 /* s390 only supports ipc syscall.  */
diff --git a/sysdeps/unix/sysv/linux/sparc/kernel-features.h b/sysdeps/unix/sysv/linux/sparc/kernel-features.h
index 3ffa96e..ba6e4c4 100644
--- a/sysdeps/unix/sysv/linux/sparc/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/sparc/kernel-features.h
@@ -40,6 +40,7 @@
 
 #if !defined __arch64__
 # undef __ASSUME_ACCEPT_SYSCALL
+# undef __ASSUME_CONNECT_SYSCALL
 #endif
 
 /* sparc only supports ipc syscall.  */
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list b/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list
index 27ca5fa..4c785fd 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list
@@ -3,7 +3,6 @@
 # Override select.S in parent directory:
 select		-	select		C:5	__select	select
 bind		-	bind		3	__bind		bind
-connect		-	connect		C:3	__libc_connect	__connect connect
 getpeername	-	getpeername	3	__getpeername	getpeername
 getsockname	-	getsockname	3	__getsockname	getsockname
 getsockopt	-	getsockopt	5	__getsockopt	getsockopt
diff --git a/sysdeps/unix/sysv/linux/x86_64/syscalls.list b/sysdeps/unix/sysv/linux/x86_64/syscalls.list
index b059f80..adf6ae6 100644
--- a/sysdeps/unix/sysv/linux/x86_64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/x86_64/syscalls.list
@@ -7,7 +7,6 @@ syscall_clock_gettime	EXTRA	clock_gettime	Ei:ip		__syscall_clock_gettime
 
 # proper socket implementations:
 bind		-	bind		i:ipi	__bind		bind
-connect		-	connect		Ci:ipi	__libc_connect	__connect connect
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getsockopt	-	getsockopt	i:iiiBN	__getsockopt	getsockopt

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=30d9b2d3e34c9f47a3c49e3f14a952dcdaaa5f3a

commit 30d9b2d3e34c9f47a3c49e3f14a952dcdaaa5f3a
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Thu Nov 17 18:13:44 2016 -0200

    Consolidate Linux accept implementation
    
    This patch consolidates the accept Linux syscall implementation on
    sysdeps/unix/sysv/linux/accept.c.  The changes are:
    
      1. Remove accept from auto-generation syscalls.list on the architecture
         that uses __NR_accept.
      2. Define __NR_acccept as default (__ASSUME_ACCEPT_SYSCALL) and undef for
         architectures that do not support it.
      3. Remove __ASSUME_ACCEPT4_FOR_ACCEPT_SYSCALL and decide to use
         __NR_accept4 for accept generation based on __ASSUME_ACCEPT4_SYSCALL.
    
    Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
    aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.
    
    	* sysdeps/unix/sysv/linux/accept.c (__libc_accept): Replace
    	__ASSUME_ACCEPT4_FOR_ACCEPT_SYSCALL by __ASSUME_ACCEPT4_SYSCALL.
    	* sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove accept from
    	auto-generation list.
    	* sysdeps/unix/sysv/linux/arm/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/generic/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/hppa/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/ia64/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/mips/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/x86_64/syscalls.list: Likewise.
    	* sysdeps/unix/sysv/linux/i386/kernel-features.h
    	(__ASSUME_ACCEPT4_FOR_ACCEPT_SYSCALL): Remove define.
    	(__ASSUME_ACCEPT_SYSCALL): Undefine.
    	* sysdeps/unix/sysv/linux/kernel-features.h
    	(__ASSUME_ACCEPT_SYSCALL): New define.
    	* sysdeps/unix/sysv/linux/m68k/kernel-features.h
    	(__ASSUME_ACCEPT4_FOR_ACCEPT_SYSCALL): Remove define.
    	(__ASSUME_ACCEPT_SYSCALL): Define wheter kernel version supports.
    	* sysdeps/unix/sysv/linux/microblaze/kernel-features.h
    	(__ASSUME_ACCEPT_SYSCALL): Define.
    	* sysdeps/unix/sysv/linux/powerpc/kernel-features.h
    	(__ASSUME_ACCEPT_SYSCALL): Undefine.
    	* sysdeps/unix/sysv/linux/s390/kernel-features.h
    	(__ASSUME_ACCEPT4_FOR_ACCEPT_SYSCALL): Remove define.
    	(__ASSUME_ACCEPT_SYSCALL): Undefine.
    	* sysdeps/unix/sysv/linux/sh/kernel-features.h
    	(__ASSUME_ACCEPT_SYSCALL): Undefine.
    	* sysdeps/unix/sysv/linux/sparc/kernel-features.h
    	(__ASSUME_ACCEPT_SYSCALL): Undefine for 32 bits.

diff --git a/ChangeLog b/ChangeLog
index 031b662..d1cf349 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,36 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/accept.c (__libc_accept): Replace
+	__ASSUME_ACCEPT4_FOR_ACCEPT_SYSCALL by __ASSUME_ACCEPT4_SYSCALL.
+	* sysdeps/unix/sysv/linux/alpha/syscalls.list?: Remove accept from
+	auto-generation list.
+	* sysdeps/unix/sysv/linux/arm/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/generic/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/hppa/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/ia64/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/mips/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/x86_64/syscalls.list: Likewise.
+	* sysdeps/unix/sysv/linux/i386/kernel-features.h
+	(__ASSUME_ACCEPT4_FOR_ACCEPT_SYSCALL): Remove define.
+	(__ASSUME_ACCEPT_SYSCALL): Undefine.
+	* sysdeps/unix/sysv/linux/kernel-features.h
+	(__ASSUME_ACCEPT_SYSCALL): New define.
+	* sysdeps/unix/sysv/linux/m68k/kernel-features.h
+	(__ASSUME_ACCEPT4_FOR_ACCEPT_SYSCALL): Remove define.
+	(__ASSUME_ACCEPT_SYSCALL): Define wheter kernel version supports.
+	* sysdeps/unix/sysv/linux/microblaze/kernel-features.h
+	(__ASSUME_ACCEPT_SYSCALL): Define.
+	* sysdeps/unix/sysv/linux/powerpc/kernel-features.h
+	(__ASSUME_ACCEPT_SYSCALL): Undefine.
+	* sysdeps/unix/sysv/linux/s390/kernel-features.h
+	(__ASSUME_ACCEPT4_FOR_ACCEPT_SYSCALL): Remove define.
+	(__ASSUME_ACCEPT_SYSCALL): Undefine.
+	* sysdeps/unix/sysv/linux/sh/kernel-features.h
+	(__ASSUME_ACCEPT_SYSCALL): Undefine.
+	* sysdeps/unix/sysv/linux/sparc/kernel-features.h
+	(__ASSUME_ACCEPT_SYSCALL): Undefine for 32 bits.
+
 	* sysdeps/unix/sysv/linux/x86_64/syscalls.list (pread64): Remove.
 	(preadv64): Likewise.
 	(pwrite64(: Likewise.
diff --git a/sysdeps/unix/sysv/linux/accept.c b/sysdeps/unix/sysv/linux/accept.c
index c5935ab..2fb59b7 100644
--- a/sysdeps/unix/sysv/linux/accept.c
+++ b/sysdeps/unix/sysv/linux/accept.c
@@ -15,21 +15,16 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <signal.h>
 #include <sys/socket.h>
-
 #include <sysdep-cancel.h>
 #include <socketcall.h>
-#include <sys/syscall.h>
-#include <kernel-features.h>
 
 int
 __libc_accept (int fd, __SOCKADDR_ARG addr, socklen_t *len)
 {
 #ifdef __ASSUME_ACCEPT_SYSCALL
   return SYSCALL_CANCEL (accept, fd, addr.__sockaddr__, len);
-#elif defined __ASSUME_ACCEPT4_FOR_ACCEPT_SYSCALL
+#elif defined __ASSUME_ACCEPT4_SYSCALL
   return SYSCALL_CANCEL (accept4, fd, addr.__sockaddr__, len, 0);
 #else
   return SOCKETCALL_CANCEL (accept, fd, addr.__sockaddr__, len);
diff --git a/sysdeps/unix/sysv/linux/alpha/syscalls.list b/sysdeps/unix/sysv/linux/alpha/syscalls.list
index 4001020..4cfe19e 100644
--- a/sysdeps/unix/sysv/linux/alpha/syscalls.list
+++ b/sysdeps/unix/sysv/linux/alpha/syscalls.list
@@ -5,7 +5,6 @@ sigstack	-	sigstack	2	sigstack
 getpriority	-	getpriority	i:ii	__getpriority	getpriority
 
 # proper socket implementations:
-accept		-	accept		Ci:iBN	__libc_accept	__accept accept
 bind		-	bind		i:ipi	__bind		bind
 connect		-	connect		Ci:ipi	__libc_connect	__connect connect
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
diff --git a/sysdeps/unix/sysv/linux/arm/syscalls.list b/sysdeps/unix/sysv/linux/arm/syscalls.list
index 0263eee..1c4f61f 100644
--- a/sysdeps/unix/sysv/linux/arm/syscalls.list
+++ b/sysdeps/unix/sysv/linux/arm/syscalls.list
@@ -22,7 +22,6 @@ fanotify_mark	EXTRA	fanotify_mark	i:iiiiis	fanotify_mark
 personality	EXTRA	personality	Ei:i	__personality	personality
 
 # proper socket implementations:
-accept		-	accept		Ci:iBN	__libc_accept	__accept accept
 bind		-	bind		i:ipi	__bind		bind
 connect		-	connect		Ci:ipi	__libc_connect	__connect connect
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
diff --git a/sysdeps/unix/sysv/linux/generic/syscalls.list b/sysdeps/unix/sysv/linux/generic/syscalls.list
index 3bb5473..b176a72 100644
--- a/sysdeps/unix/sysv/linux/generic/syscalls.list
+++ b/sysdeps/unix/sysv/linux/generic/syscalls.list
@@ -5,7 +5,6 @@ socket		-	socket		i:iii	__socket	socket
 socketpair	-	socketpair	i:iiif	__socketpair	socketpair
 bind		-	bind		i:ipi	__bind		bind
 listen		-	listen		i:ii	__listen	listen
-accept		-	accept		Ci:iBN	__libc_accept	__accept accept
 connect		-	connect		Ci:ipi	__libc_connect	__connect connect
 getsockname	-	getsockname	i:ipp	__getsockname	getsockname
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
diff --git a/sysdeps/unix/sysv/linux/hppa/syscalls.list b/sysdeps/unix/sysv/linux/hppa/syscalls.list
index 6d47b11..ee814fb 100644
--- a/sysdeps/unix/sysv/linux/hppa/syscalls.list
+++ b/sysdeps/unix/sysv/linux/hppa/syscalls.list
@@ -1,7 +1,6 @@
 # File name	Caller	Syscall name	# args	Strong name	Weak names
 
 # proper socket implementations:
-accept		-	accept		Ci:iBN	__libc_accept	__accept accept
 bind		-	bind		i:ipi	__bind		bind
 connect		-	connect		Ci:ipi	__libc_connect	__connect connect
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
diff --git a/sysdeps/unix/sysv/linux/i386/kernel-features.h b/sysdeps/unix/sysv/linux/i386/kernel-features.h
index 2696d1a..07462f8 100644
--- a/sysdeps/unix/sysv/linux/i386/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/i386/kernel-features.h
@@ -33,7 +33,6 @@
 # define __ASSUME_BIND_SYSCALL               1
 # define __ASSUME_CONNECT_SYSCALL            1
 # define __ASSUME_LISTEN_SYSCALL             1
-# define __ASSUME_ACCEPT4_FOR_ACCEPT_SYSCALL 1
 # define __ASSUME_GETSOCKOPT_SYSCALL         1
 # define __ASSUME_SETSOCKOPT_SYSCALL         1
 # define __ASSUME_GETSOCKNAME_SYSCALL        1
@@ -47,6 +46,8 @@
 
 #include_next <kernel-features.h>
 
+#undef __ASSUME_ACCEPT_SYSCALL
+
 #if __LINUX_KERNEL_VERSION < 0x040300
 # undef __ASSUME_ACCEPT4_SYSCALL
 # undef __ASSUME_SENDMSG_SYSCALL
diff --git a/sysdeps/unix/sysv/linux/ia64/syscalls.list b/sysdeps/unix/sysv/linux/ia64/syscalls.list
index dd07db3..96db4c3 100644
--- a/sysdeps/unix/sysv/linux/ia64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/ia64/syscalls.list
@@ -5,7 +5,6 @@ umount2		-	umount		2	__umount2	umount2
 getpriority	-	getpriority	i:ii	__getpriority	getpriority
 
 # proper socket implementations:
-accept		-	accept		Ci:iBN	__libc_accept	__accept accept
 bind		-	bind		i:ipi	__bind		bind
 connect		-	connect		Ci:ipi	__libc_connect	__connect connect
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h
index 08485cd..78b091b 100644
--- a/sysdeps/unix/sysv/linux/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/kernel-features.h
@@ -147,6 +147,7 @@
    separate syscalls were only added later.  */
 #define __ASSUME_SENDMSG_SYSCALL	1
 #define __ASSUME_RECVMSG_SYSCALL	1
+#define __ASSUME_ACCEPT_SYSCALL		1
 
 /* Support for SysV IPC through wired syscalls.  All supported architectures
    either support ipc syscall and/or all the ipc correspondent syscalls.  */
diff --git a/sysdeps/unix/sysv/linux/m68k/kernel-features.h b/sysdeps/unix/sysv/linux/m68k/kernel-features.h
index 6811a28..f583ae7 100644
--- a/sysdeps/unix/sysv/linux/m68k/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/m68k/kernel-features.h
@@ -27,7 +27,6 @@
 # define __ASSUME_BIND_SYSCALL               1
 # define __ASSUME_CONNECT_SYSCALL            1
 # define __ASSUME_LISTEN_SYSCALL             1
-# define __ASSUME_ACCEPT4_FOR_ACCEPT_SYSCALL 1
 # define __ASSUME_GETSOCKOPT_SYSCALL         1
 # define __ASSUME_SETSOCKOPT_SYSCALL         1
 # define __ASSUME_GETSOCKNAME_SYSCALL        1
@@ -41,7 +40,10 @@
 
 #include_next <kernel-features.h>
 
+#undef __ASSUME_ACCEPT_SYSCALL
+
 #if __LINUX_KERNEL_VERSION < 0x040300
+# undef __ASSUME_ACCCEPT_SYSCALL
 # undef __ASSUME_ACCEPT4_SYSCALL
 # undef __ASSUME_RECVMMSG_SYSCALL
 # undef __ASSUME_SENDMMSG_SYSCALL
diff --git a/sysdeps/unix/sysv/linux/microblaze/kernel-features.h b/sysdeps/unix/sysv/linux/microblaze/kernel-features.h
index f68e8c5..9532d57 100644
--- a/sysdeps/unix/sysv/linux/microblaze/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/microblaze/kernel-features.h
@@ -24,7 +24,6 @@
 #define __ASSUME_BIND_SYSCALL		1
 #define __ASSUME_CONNECT_SYSCALL	1
 #define __ASSUME_LISTEN_SYSCALL		1
-#define __ASSUME_ACCEPT_SYSCALL		1
 #define __ASSUME_GETSOCKNAME_SYSCALL	1
 #define __ASSUME_GETPEERNAME_SYSCALL	1
 #define __ASSUME_SOCKETPAIR_SYSCALL	1
diff --git a/sysdeps/unix/sysv/linux/mips/syscalls.list b/sysdeps/unix/sysv/linux/mips/syscalls.list
index cd946a0..81ea2a7 100644
--- a/sysdeps/unix/sysv/linux/mips/syscalls.list
+++ b/sysdeps/unix/sysv/linux/mips/syscalls.list
@@ -12,7 +12,6 @@ sysmips		-	sysmips		i:iiii	__sysmips	sysmips
 # Socket functions; Linux/MIPS doesn't use the socketcall(2) wrapper;
 # it's provided for compatibility, though.
 #
-accept		-	accept		Ci:iBN	__libc_accept	__accept accept
 bind		-	bind		i:ipi	__bind		bind
 connect		-	connect		Ci:ipi	__libc_connect	__connect connect
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername
diff --git a/sysdeps/unix/sysv/linux/powerpc/kernel-features.h b/sysdeps/unix/sysv/linux/powerpc/kernel-features.h
index 02dadc8..272800c 100644
--- a/sysdeps/unix/sysv/linux/powerpc/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/powerpc/kernel-features.h
@@ -25,7 +25,6 @@
 #define __ASSUME_BIND_SYSCALL		1
 #define __ASSUME_CONNECT_SYSCALL	1
 #define __ASSUME_LISTEN_SYSCALL		1
-#define __ASSUME_ACCEPT_SYSCALL		1
 #define __ASSUME_GETSOCKNAME_SYSCALL	1
 #define __ASSUME_GETPEERNAME_SYSCALL	1
 #define __ASSUME_SOCKETPAIR_SYSCALL	1
diff --git a/sysdeps/unix/sysv/linux/s390/kernel-features.h b/sysdeps/unix/sysv/linux/s390/kernel-features.h
index 4e04d26..ccfb0a2 100644
--- a/sysdeps/unix/sysv/linux/s390/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/s390/kernel-features.h
@@ -27,7 +27,6 @@
 # define __ASSUME_BIND_SYSCALL               1
 # define __ASSUME_CONNECT_SYSCALL            1
 # define __ASSUME_LISTEN_SYSCALL             1
-# define __ASSUME_ACCEPT4_FOR_ACCEPT_SYSCALL 1
 # define __ASSUME_GETSOCKOPT_SYSCALL         1
 # define __ASSUME_SETSOCKOPT_SYSCALL         1
 # define __ASSUME_GETSOCKNAME_SYSCALL        1
@@ -41,6 +40,8 @@
 
 #include_next <kernel-features.h>
 
+#undef __ASSUME_ACCEPT_SYSCALL
+
 #if __LINUX_KERNEL_VERSION < 0x040300
 # undef __ASSUME_ACCEPT4_SYSCALL
 # undef __ASSUME_RECVMMSG_SYSCALL
diff --git a/sysdeps/unix/sysv/linux/sh/kernel-features.h b/sysdeps/unix/sysv/linux/sh/kernel-features.h
index 10a669f..7a83211 100644
--- a/sysdeps/unix/sysv/linux/sh/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/sh/kernel-features.h
@@ -28,7 +28,6 @@
 #define __ASSUME_BIND_SYSCALL		1
 #define __ASSUME_CONNECT_SYSCALL	1
 #define __ASSUME_LISTEN_SYSCALL		1
-#define __ASSUME_ACCEPT_SYSCALL		1
 #define __ASSUME_GETSOCKNAME_SYSCALL	1
 #define __ASSUME_GETPEERNAME_SYSCALL	1
 #define __ASSUME_SOCKETPAIR_SYSCALL	1
diff --git a/sysdeps/unix/sysv/linux/sparc/kernel-features.h b/sysdeps/unix/sysv/linux/sparc/kernel-features.h
index f78ae85..3ffa96e 100644
--- a/sysdeps/unix/sysv/linux/sparc/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/sparc/kernel-features.h
@@ -38,5 +38,9 @@
 # undef __ASSUME_SET_ROBUST_LIST
 #endif
 
+#if !defined __arch64__
+# undef __ASSUME_ACCEPT_SYSCALL
+#endif
+
 /* sparc only supports ipc syscall.  */
 #undef __ASSUME_DIRECT_SYSVIPC_SYSCALLS
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list b/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list
index eecd837..27ca5fa 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list
@@ -2,7 +2,6 @@
 
 # Override select.S in parent directory:
 select		-	select		C:5	__select	select
-accept		-	accept		C:3	__libc_accept	__accept accept
 bind		-	bind		3	__bind		bind
 connect		-	connect		C:3	__libc_connect	__connect connect
 getpeername	-	getpeername	3	__getpeername	getpeername
diff --git a/sysdeps/unix/sysv/linux/x86_64/syscalls.list b/sysdeps/unix/sysv/linux/x86_64/syscalls.list
index 51a9177..b059f80 100644
--- a/sysdeps/unix/sysv/linux/x86_64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/x86_64/syscalls.list
@@ -6,7 +6,6 @@ syscall_clock_gettime	EXTRA	clock_gettime	Ei:ip		__syscall_clock_gettime
 
 
 # proper socket implementations:
-accept		-	accept		Ci:iBN	__libc_accept	__accept accept
 bind		-	bind		i:ipi	__bind		bind
 connect		-	connect		Ci:ipi	__libc_connect	__connect connect
 getpeername	-	getpeername	i:ipp	__getpeername	getpeername

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=7d81990d5e0923f4acc8d1fb1d3be18d45df7881

commit 7d81990d5e0923f4acc8d1fb1d3be18d45df7881
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Jul 19 10:23:49 2016 -0300

    Remove p{read,write}{v} and fallocate from x86 auto-generation list
    
    With {INLINE,INTERNAL}_SYSCALL macros fixed for 64-bits arguments on x32,
    we can remove the p{read,write}{v} from auto-generation list.
    
    Tested on x86_64 and x32.
    
    	* sysdeps/unix/sysv/linux/x86_64/syscalls.list (pread64): Remove.
    	(preadv64): Likewise.
    	(pwrite64(: Likewise.
    	(pwritev64): Likewise.

diff --git a/ChangeLog b/ChangeLog
index 3a8287d..031b662 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/x86_64/syscalls.list (pread64): Remove.
+	(preadv64): Likewise.
+	(pwrite64(: Likewise.
+	(pwritev64): Likewise.
+
 	* sysdeps/unix/sysv/linux/x86_64/sysdep.h
 	(INTERNAL_SYSCALL_NCS_TYPES): Remove define.
 	(LOAD_ARGS_0): Likewise.
diff --git a/sysdeps/unix/sysv/linux/x86_64/syscalls.list b/sysdeps/unix/sysv/linux/x86_64/syscalls.list
index 45d5ebf..51a9177 100644
--- a/sysdeps/unix/sysv/linux/x86_64/syscalls.list
+++ b/sysdeps/unix/sysv/linux/x86_64/syscalls.list
@@ -2,10 +2,6 @@
 
 arch_prctl	EXTRA	arch_prctl	i:ii	__arch_prctl	arch_prctl
 modify_ldt	EXTRA	modify_ldt	i:ipi	__modify_ldt	modify_ldt
-pread64		-	pread64		Ci:ipii	__libc_pread	__libc_pread64 __pread64 pread64 __pread pread
-preadv64	-	preadv		Ci:ipii	preadv64	preadv
-pwrite64	-	pwrite64	Ci:ipii	__libc_pwrite	__libc_pwrite64 __pwrite64 pwrite64 __pwrite pwrite
-pwritev64	-	pwritev		Ci:ipii	pwritev64	pwritev
 syscall_clock_gettime	EXTRA	clock_gettime	Ei:ip		__syscall_clock_gettime
 
 
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list b/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list
index a41c8ac..b44f6f9 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list
@@ -1,6 +1,5 @@
 # File name	Caller	Syscall name	# args	Strong name	Weak names
 
-fallocate	-	fallocate	Ci:iiii	fallocate	fallocate64
 gettimeofday	-	gettimeofday:__vdso_gettimeofday@LINUX_2.6	i:pP	__gettimeofday	gettimeofday
 personality	EXTRA	personality	Ei:i	__personality	personality
 posix_fadvise64	-	fadvise64	Vi:iiii	posix_fadvise	posix_fadvise64

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=844f7762a9509c7c6d53051cbe2915e5c5e5cb22

commit 844f7762a9509c7c6d53051cbe2915e5c5e5cb22
Author: Adhemerval Zanella <adhemerval.zanella@linaro.com>
Date:   Wed Jul 13 10:50:05 2016 +0100

    Fix {INLINE,INTERNAL}_SYSCALL macros for x32
    
    The problem for x32 is the {INTERNAL,INLINE}_SYSCALL C macros explicit
    cast the arguments to 'long int', thus passing as 32 bits arguments
    that should be passed to 64 bits.
    
    Previous x32 implementation uses the auto-generated syscalls from
    assembly macros (syscalls.list), so the {INTERNAL,INLINE}_SYSCALL
    macros are never used with 64 bit argument in x32 (which are
    internally broken for this ILP).
    
    To fix it I used a strategy similar to MIPS64n32 (although both
    ABI differs for some syscalls on how top pass 64-bits arguments)
    where argument types for kernel call are defined using GCC extension
    'typeof' with a arithmetic operation.  This allows 64-bits arguments
    to be defined while 32-bits argument will still passed as 32-bits.
    
    I also cleanup the {INLINE,INTERNAL}_SYSCALL definition by defining
    'inline_syscallX' instead of constructing the argument passing using
    macros (it adds some readability) and removed the ununsed
    INTERNAL_SYSCALL_NCS_TYPES define (since the patch idea is exactly to
    avoid requiric explicit types passing).
    
    Tested on x86_64 and x32.
    
    	* sysdeps/unix/sysv/linux/x86_64/sysdep.h
    	(INTERNAL_SYSCALL_NCS_TYPES): Remove define.
    	(LOAD_ARGS_0): Likewise.
    	(LOAD_ARGS_1): Likewise.
    	(LOAD_ARGS_2): Likewise.
    	(LOAD_ARGS_3): Likewise.
    	(LOAD_ARGS_4): Likewise.
    	(LOAD_ARGS_5): Likewise.
    	(LOAD_ARGS_6): Likewise.
    	(LOAD_REGS_0): Likewise.
    	(LOAD_REGS_1): Likewise.
    	(LOAD_REGS_2): Likewise.
    	(LOAD_REGS_3): Likewise.
    	(LOAD_REGS_4): Likewise.
    	(LOAD_REGS_5): Likewise.
    	(LOAD_REGS_6): Likewise.
    	(ASM_ARGS_0): Likewise.
    	(ASM_ARGS_1): Likewise.
    	(ASM_ARGS_2): Likewise.
    	(ASM_ARGS_3): Likewise.
    	(ASM_ARGS_4): Likewise.
    	(ASM_ARGS_5): Likewise.
    	(ASM_ARGS_6): Likewise.
    	(LOAD_ARGS_TYPES_1): Likewise.
    	(LOAD_ARGS_TYPES_2): Likewise.
    	(LOAD_ARGS_TYPES_3): Likewise.
    	(LOAD_ARGS_TYPES_4): Likewise.
    	(LOAD_ARGS_TYPES_5): Likewise.
    	(LOAD_ARGS_TYPES_6): Likewise.
    	(LOAD_REGS_TYPES_1): Likewise.
    	(LOAD_REGS_TYPES_2): Likewise.
    	(LOAD_REGS_TYPES_3): Likewise.
    	(LOAD_REGS_TYPES_4): Likewise.
    	(LOAD_REGS_TYPES_5): Likewise.
    	(LOAD_REGS_TYPES_6): Likewise.
    	(TYPEFY): New define.
    	(ARGIFY): Likewise.
    	(internal_syscall0): Likewise.
    	(internal_syscall1): Likewise.
    	(internal_syscall2): Likewise.
    	(internal_syscall3): Likewise.
    	(internal_syscall4): Likewise.
    	(internal_syscall5): Likewise.
    	(internal_syscall6): Likewise.
    	* sysdeps/unix/sysv/linux/x86_64/x32/times.c
    	(INTERNAL_SYSCALL_NCS): Remove define.
    	(internal_syscall1): Add define.

diff --git a/ChangeLog b/ChangeLog
index 4e0d788..3a8287d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,53 @@
+2016-01-30  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
+
+	* sysdeps/unix/sysv/linux/x86_64/sysdep.h
+	(INTERNAL_SYSCALL_NCS_TYPES): Remove define.
+	(LOAD_ARGS_0): Likewise.
+	(LOAD_ARGS_1): Likewise.
+	(LOAD_ARGS_2): Likewise.
+	(LOAD_ARGS_3): Likewise.
+	(LOAD_ARGS_4): Likewise.
+	(LOAD_ARGS_5): Likewise.
+	(LOAD_ARGS_6): Likewise.
+	(LOAD_REGS_0): Likewise.
+	(LOAD_REGS_1): Likewise.
+	(LOAD_REGS_2): Likewise.
+	(LOAD_REGS_3): Likewise.
+	(LOAD_REGS_4): Likewise.
+	(LOAD_REGS_5): Likewise.
+	(LOAD_REGS_6): Likewise.
+	(ASM_ARGS_0): Likewise.
+	(ASM_ARGS_1): Likewise.
+	(ASM_ARGS_2): Likewise.
+	(ASM_ARGS_3): Likewise.
+	(ASM_ARGS_4): Likewise.
+	(ASM_ARGS_5): Likewise.
+	(ASM_ARGS_6): Likewise.
+	(LOAD_ARGS_TYPES_1): Likewise.
+	(LOAD_ARGS_TYPES_2): Likewise.
+	(LOAD_ARGS_TYPES_3): Likewise.
+	(LOAD_ARGS_TYPES_4): Likewise.
+	(LOAD_ARGS_TYPES_5): Likewise.
+	(LOAD_ARGS_TYPES_6): Likewise.
+	(LOAD_REGS_TYPES_1): Likewise.
+	(LOAD_REGS_TYPES_2): Likewise.
+	(LOAD_REGS_TYPES_3): Likewise.
+	(LOAD_REGS_TYPES_4): Likewise.
+	(LOAD_REGS_TYPES_5): Likewise.
+	(LOAD_REGS_TYPES_6): Likewise.
+	(TYPEFY): New define.
+	(ARGIFY): Likewise.
+	(internal_syscall0): Likewise.
+	(internal_syscall1): Likewise.
+	(internal_syscall2): Likewise.
+	(internal_syscall3): Likewise.
+	(internal_syscall4): Likewise.
+	(internal_syscall5): Likewise.
+	(internal_syscall6): Likewise.
+	* sysdeps/unix/sysv/linux/x86_64/x32/times.c
+	(INTERNAL_SYSCALL_NCS): Remove define.
+	(internal_syscall1): Add define.
+
 2016-01-28  Carlos O'Donell  <carlos@redhat.com>
 	    Alexey Makhalov <amakhalov@vmware.com>
 	    Florian Weimer <fweimer@redhat.com>
diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
index 7b8bd79..81fd7a7 100644
--- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
@@ -188,6 +188,7 @@
 # define DOARGS_6 DOARGS_5
 
 #else	/* !__ASSEMBLER__ */
+
 /* Define a macro which expands inline into the wrapper code for a system
    call.  */
 # undef INLINE_SYSCALL
@@ -221,33 +222,148 @@
 /* Registers clobbered by syscall.  */
 # define REGISTERS_CLOBBERED_BY_SYSCALL "cc", "r11", "cx"
 
-# define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
-  ({									      \
-    unsigned long int resultvar;					      \
-    LOAD_ARGS_##nr (args)						      \
-    LOAD_REGS_##nr							      \
-    asm volatile (							      \
-    "syscall\n\t"							      \
-    : "=a" (resultvar)							      \
-    : "0" (name) ASM_ARGS_##nr : "memory", REGISTERS_CLOBBERED_BY_SYSCALL);   \
-    (long int) resultvar; })
-# undef INTERNAL_SYSCALL
-# define INTERNAL_SYSCALL(name, err, nr, args...) \
-  INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
-
-# define INTERNAL_SYSCALL_NCS_TYPES(name, err, nr, args...) \
-  ({									      \
-    unsigned long int resultvar;					      \
-    LOAD_ARGS_TYPES_##nr (args)						      \
-    LOAD_REGS_TYPES_##nr (args)						      \
-    asm volatile (							      \
-    "syscall\n\t"							      \
-    : "=a" (resultvar)							      \
-    : "0" (name) ASM_ARGS_##nr : "memory", REGISTERS_CLOBBERED_BY_SYSCALL);   \
-    (long int) resultvar; })
-# undef INTERNAL_SYSCALL_TYPES
-# define INTERNAL_SYSCALL_TYPES(name, err, nr, args...) \
-  INTERNAL_SYSCALL_NCS_TYPES (__NR_##name, err, nr, ##args)
+/* Create a variable 'name' based on type 'X' to avoid explicit types.
+   This is mainly used set use 64-bits arguments in x32.   */
+#define TYPEFY(X, name) __typeof__ ((X) - (X)) name
+/* Explicit cast the argument to avoid integer from pointer warning on
+   x32.  */
+#define ARGIFY(X) ((__typeof__ ((X) - (X))) (X))
+
+#undef INTERNAL_SYSCALL
+#define INTERNAL_SYSCALL(name, err, nr, args...)			\
+	internal_syscall##nr (SYS_ify (name), err, args)
+
+#undef INTERNAL_SYSCALL_NCS
+#define INTERNAL_SYSCALL_NCS(number, err, nr, args...)			\
+	internal_syscall##nr (number, err, args)
+
+#undef internal_syscall0
+#define internal_syscall0(number, err, dummy...)			\
+({									\
+    unsigned long int resultvar;					\
+    asm volatile (							\
+    "syscall\n\t"							\
+    : "=a" (resultvar)							\
+    : "0" (number)							\
+    : "memory", REGISTERS_CLOBBERED_BY_SYSCALL);			\
+    (long int) resultvar;						\
+})
+
+#undef internal_syscall1
+#define internal_syscall1(number, err, arg1)				\
+({									\
+    unsigned long int resultvar;					\
+    TYPEFY (arg1, __arg1) = ARGIFY (arg1);			 	\
+    register TYPEFY (arg1, _a1) asm ("rdi") = __arg1;			\
+    asm volatile (							\
+    "syscall\n\t"							\
+    : "=a" (resultvar)							\
+    : "0" (number), "r" (_a1)						\
+    : "memory", REGISTERS_CLOBBERED_BY_SYSCALL);			\
+    (long int) resultvar;						\
+})
+
+#undef internal_syscall2
+#define internal_syscall2(number, err, arg1, arg2)			\
+({									\
+    unsigned long int resultvar;					\
+    TYPEFY (arg2, __arg2) = ARGIFY (arg2);			 	\
+    TYPEFY (arg1, __arg1) = ARGIFY (arg1);			 	\
+    register TYPEFY (arg2, _a2) asm ("rsi") = __arg2;			\
+    register TYPEFY (arg1, _a1) asm ("rdi") = __arg1;			\
+    asm volatile (							\
+    "syscall\n\t"							\
+    : "=a" (resultvar)							\
+    : "0" (number), "r" (_a1), "r" (_a2)				\
+    : "memory", REGISTERS_CLOBBERED_BY_SYSCALL);			\
+    (long int) resultvar;						\
+})
+
+#undef internal_syscall3
+#define internal_syscall3(number, err, arg1, arg2, arg3)		\
+({									\
+    unsigned long int resultvar;					\
+    TYPEFY (arg3, __arg3) = ARGIFY (arg3);			 	\
+    TYPEFY (arg2, __arg2) = ARGIFY (arg2);			 	\
+    TYPEFY (arg1, __arg1) = ARGIFY (arg1);			 	\
+    register TYPEFY (arg3, _a3) asm ("rdx") = __arg3;			\
+    register TYPEFY (arg2, _a2) asm ("rsi") = __arg2;			\
+    register TYPEFY (arg1, _a1) asm ("rdi") = __arg1;			\
+    asm volatile (							\
+    "syscall\n\t"							\
+    : "=a" (resultvar)							\
+    : "0" (number), "r" (_a1), "r" (_a2), "r" (_a3)			\
+    : "memory", REGISTERS_CLOBBERED_BY_SYSCALL);			\
+    (long int) resultvar;						\
+})
+
+#undef internal_syscall4
+#define internal_syscall4(number, err, arg1, arg2, arg3, arg4)		\
+({									\
+    unsigned long int resultvar;					\
+    TYPEFY (arg4, __arg4) = ARGIFY (arg4);			 	\
+    TYPEFY (arg3, __arg3) = ARGIFY (arg3);			 	\
+    TYPEFY (arg2, __arg2) = ARGIFY (arg2);			 	\
+    TYPEFY (arg1, __arg1) = ARGIFY (arg1);			 	\
+    register TYPEFY (arg4, _a4) asm ("r10") = __arg4;			\
+    register TYPEFY (arg3, _a3) asm ("rdx") = __arg3;			\
+    register TYPEFY (arg2, _a2) asm ("rsi") = __arg2;			\
+    register TYPEFY (arg1, _a1) asm ("rdi") = __arg1;			\
+    asm volatile (							\
+    "syscall\n\t"							\
+    : "=a" (resultvar)							\
+    : "0" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4)		\
+    : "memory", REGISTERS_CLOBBERED_BY_SYSCALL);			\
+    (long int) resultvar;						\
+})
+
+#undef internal_syscall5
+#define internal_syscall5(number, err, arg1, arg2, arg3, arg4, arg5)	\
+({									\
+    unsigned long int resultvar;					\
+    TYPEFY (arg5, __arg5) = ARGIFY (arg5);			 	\
+    TYPEFY (arg4, __arg4) = ARGIFY (arg4);			 	\
+    TYPEFY (arg3, __arg3) = ARGIFY (arg3);			 	\
+    TYPEFY (arg2, __arg2) = ARGIFY (arg2);			 	\
+    TYPEFY (arg1, __arg1) = ARGIFY (arg1);			 	\
+    register TYPEFY (arg5, _a5) asm ("r8") = __arg5;			\
+    register TYPEFY (arg4, _a4) asm ("r10") = __arg4;			\
+    register TYPEFY (arg3, _a3) asm ("rdx") = __arg3;			\
+    register TYPEFY (arg2, _a2) asm ("rsi") = __arg2;			\
+    register TYPEFY (arg1, _a1) asm ("rdi") = __arg1;			\
+    asm volatile (							\
+    "syscall\n\t"							\
+    : "=a" (resultvar)							\
+    : "0" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4),		\
+      "r" (_a5)								\
+    : "memory", REGISTERS_CLOBBERED_BY_SYSCALL);			\
+    (long int) resultvar;						\
+})
+
+#undef internal_syscall6
+#define internal_syscall6(number, err, arg1, arg2, arg3, arg4, arg5, arg6) \
+({									\
+    unsigned long int resultvar;					\
+    TYPEFY (arg6, __arg6) = ARGIFY (arg6);			 	\
+    TYPEFY (arg5, __arg5) = ARGIFY (arg5);			 	\
+    TYPEFY (arg4, __arg4) = ARGIFY (arg4);			 	\
+    TYPEFY (arg3, __arg3) = ARGIFY (arg3);			 	\
+    TYPEFY (arg2, __arg2) = ARGIFY (arg2);			 	\
+    TYPEFY (arg1, __arg1) = ARGIFY (arg1);			 	\
+    register TYPEFY (arg6, _a6) asm ("r9") = __arg6;			\
+    register TYPEFY (arg5, _a5) asm ("r8") = __arg5;			\
+    register TYPEFY (arg4, _a4) asm ("r10") = __arg4;			\
+    register TYPEFY (arg3, _a3) asm ("rdx") = __arg3;			\
+    register TYPEFY (arg2, _a2) asm ("rsi") = __arg2;			\
+    register TYPEFY (arg1, _a1) asm ("rdi") = __arg1;			\
+    asm volatile (							\
+    "syscall\n\t"							\
+    : "=a" (resultvar)							\
+    : "0" (number), "r" (_a1), "r" (_a2), "r" (_a3), "r" (_a4),		\
+      "r" (_a5), "r" (_a6)						\
+    : "memory", REGISTERS_CLOBBERED_BY_SYSCALL);			\
+    (long int) resultvar;						\
+})
 
 # undef INTERNAL_SYSCALL_ERROR_P
 # define INTERNAL_SYSCALL_ERROR_P(val, err) \
@@ -261,88 +377,6 @@
 # define HAVE_GETTIMEOFDAY_VSYSCALL     1
 # define HAVE_GETCPU_VSYSCALL		1
 
-# define LOAD_ARGS_0()
-# define LOAD_REGS_0
-# define ASM_ARGS_0
-
-# define LOAD_ARGS_TYPES_1(t1, a1)					   \
-  t1 __arg1 = (t1) (a1);						   \
-  LOAD_ARGS_0 ()
-# define LOAD_REGS_TYPES_1(t1, a1)					   \
-  register t1 _a1 asm ("rdi") = __arg1;					   \
-  LOAD_REGS_0
-# define ASM_ARGS_1	ASM_ARGS_0, "r" (_a1)
-# define LOAD_ARGS_1(a1)						   \
-  LOAD_ARGS_TYPES_1 (long int, a1)
-# define LOAD_REGS_1							   \
-  LOAD_REGS_TYPES_1 (long int, a1)
-
-# define LOAD_ARGS_TYPES_2(t1, a1, t2, a2)				   \
-  t2 __arg2 = (t2) (a2);						   \
-  LOAD_ARGS_TYPES_1 (t1, a1)
-# define LOAD_REGS_TYPES_2(t1, a1, t2, a2)				   \
-  register t2 _a2 asm ("rsi") = __arg2;					   \
-  LOAD_REGS_TYPES_1(t1, a1)
-# define ASM_ARGS_2	ASM_ARGS_1, "r" (_a2)
-# define LOAD_ARGS_2(a1, a2)						   \
-  LOAD_ARGS_TYPES_2 (long int, a1, long int, a2)
-# define LOAD_REGS_2							   \
-  LOAD_REGS_TYPES_2 (long int, a1, long int, a2)
-
-# define LOAD_ARGS_TYPES_3(t1, a1, t2, a2, t3, a3)			   \
-  t3 __arg3 = (t3) (a3);						   \
-  LOAD_ARGS_TYPES_2 (t1, a1, t2, a2)
-# define LOAD_REGS_TYPES_3(t1, a1, t2, a2, t3, a3)			   \
-  register t3 _a3 asm ("rdx") = __arg3;					   \
-  LOAD_REGS_TYPES_2(t1, a1, t2, a2)
-# define ASM_ARGS_3	ASM_ARGS_2, "r" (_a3)
-# define LOAD_ARGS_3(a1, a2, a3)					   \
-  LOAD_ARGS_TYPES_3 (long int, a1, long int, a2, long int, a3)
-# define LOAD_REGS_3							   \
-  LOAD_REGS_TYPES_3 (long int, a1, long int, a2, long int, a3)
-
-# define LOAD_ARGS_TYPES_4(t1, a1, t2, a2, t3, a3, t4, a4)		   \
-  t4 __arg4 = (t4) (a4);						   \
-  LOAD_ARGS_TYPES_3 (t1, a1, t2, a2, t3, a3)
-# define LOAD_REGS_TYPES_4(t1, a1, t2, a2, t3, a3, t4, a4)		   \
-  register t4 _a4 asm ("r10") = __arg4;					   \
-  LOAD_REGS_TYPES_3(t1, a2, t2, a2, t3, a3)
-# define ASM_ARGS_4	ASM_ARGS_3, "r" (_a4)
-# define LOAD_ARGS_4(a1, a2, a3, a4)					   \
-  LOAD_ARGS_TYPES_4 (long int, a1, long int, a2, long int, a3,		   \
-		     long int, a4)
-# define LOAD_REGS_4							   \
-  LOAD_REGS_TYPES_4 (long int, a1, long int, a2, long int, a3,		   \
-		     long int, a4)
-
-# define LOAD_ARGS_TYPES_5(t1, a1, t2, a2, t3, a3, t4, a4, t5, a5)	   \
-  t5 __arg5 = (t5) (a5);						   \
-  LOAD_ARGS_TYPES_4 (t1, a1, t2, a2, t3, a3, t4, a4)
-# define LOAD_REGS_TYPES_5(t1, a1, t2, a2, t3, a3, t4, a4, t5, a5)	   \
-  register t5 _a5 asm ("r8") = __arg5;					   \
-  LOAD_REGS_TYPES_4 (t1, a1, t2, a2, t3, a3, t4, a4)
-# define ASM_ARGS_5	ASM_ARGS_4, "r" (_a5)
-# define LOAD_ARGS_5(a1, a2, a3, a4, a5)				   \
-  LOAD_ARGS_TYPES_5 (long int, a1, long int, a2, long int, a3,		   \
-		     long int, a4, long int, a5)
-# define LOAD_REGS_5							   \
-  LOAD_REGS_TYPES_5 (long int, a1, long int, a2, long int, a3,		   \
-		     long int, a4, long int, a5)
-
-# define LOAD_ARGS_TYPES_6(t1, a1, t2, a2, t3, a3, t4, a4, t5, a5, t6, a6) \
-  t6 __arg6 = (t6) (a6);						   \
-  LOAD_ARGS_TYPES_5 (t1, a1, t2, a2, t3, a3, t4, a4, t5, a5)
-# define LOAD_REGS_TYPES_6(t1, a1, t2, a2, t3, a3, t4, a4, t5, a5, t6, a6) \
-  register t6 _a6 asm ("r9") = __arg6;					   \
-  LOAD_REGS_TYPES_5 (t1, a1, t2, a2, t3, a3, t4, a4, t5, a5)
-# define ASM_ARGS_6	ASM_ARGS_5, "r" (_a6)
-# define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6)				   \
-  LOAD_ARGS_TYPES_6 (long int, a1, long int, a2, long int, a3,		   \
-		     long int, a4, long int, a5, long int, a6)
-# define LOAD_REGS_6							   \
-  LOAD_REGS_TYPES_6 (long int, a1, long int, a2, long int, a3,		   \
-		     long int, a4, long int, a5, long int, a6)
-
 #endif	/* __ASSEMBLER__ */
 
 
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/times.c b/sysdeps/unix/sysv/linux/x86_64/x32/times.c
index d56106e..8763047 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/times.c
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/times.c
@@ -19,17 +19,19 @@
 #include <sysdep.h>
 
 /* Linux times system call returns 64-bit integer.  */
-#undef INTERNAL_SYSCALL_NCS
-#define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
-  ({									      \
-    unsigned long long int resultvar;					      \
-    LOAD_ARGS_##nr (args)						      \
-    LOAD_REGS_##nr							      \
-    asm volatile (							      \
-    "syscall\n\t"							      \
-    : "=a" (resultvar)							      \
-    : "0" (name) ASM_ARGS_##nr : "memory", REGISTERS_CLOBBERED_BY_SYSCALL);   \
-    (long long int) resultvar; })
+#undef internal_syscall1
+#define internal_syscall1(number, err, arg1)				\
+({									\
+    unsigned long long int resultvar;					\
+    TYPEFY (arg1, __arg1) = ARGIFY (arg1);			 	\
+    register TYPEFY (arg1, _a1) asm ("rdi") = __arg1;			\
+    asm volatile (							\
+    "syscall\n\t"							\
+    : "=a" (resultvar)							\
+    : "0" (number), "r" (_a1)						\
+    : "memory", REGISTERS_CLOBBERED_BY_SYSCALL);			\
+    (long long int) resultvar;						\
+})
 
 #undef INTERNAL_SYSCALL_ERROR_P
 #define INTERNAL_SYSCALL_ERROR_P(val, err) \

-----------------------------------------------------------------------


hooks/post-receive
-- 
GNU C Library master sources


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