Blame SOURCES/glibc-rh1163509-4.patch

147e83
This patch is based on the below upstream commit.
147e83
File deletions were altered to reflect file renames.
147e83
147e83
commit f50277c19df0937ea9691ab7e7c642ecd3ed3d94
147e83
Author: Torvald Riegel <triegel@redhat.com>
147e83
Date:   Sun Oct 19 21:59:26 2014 +0200
147e83
147e83
    pthread_once: Add fast path and remove x86 variants.
147e83
147e83
diff --git a/nptl/pthread_once.c b/nptl/pthread_once.c
147e83
index 595bd7e298003e00..2afb79c01fe0a61e 100644
147e83
--- a/nptl/pthread_once.c
147e83
+++ b/nptl/pthread_once.c
147e83
@@ -58,11 +58,13 @@ clear_once_control (void *arg)
147e83
    initialization is interrupted, we then fork 2^30 times (30 bits of
147e83
    once_control are used for the fork generation), and try to initialize
147e83
    again, we can deadlock because we can't distinguish the in-progress and
147e83
-   interrupted cases anymore.  */
147e83
-int
147e83
-__pthread_once (once_control, init_routine)
147e83
-     pthread_once_t *once_control;
147e83
-     void (*init_routine) (void);
147e83
+   interrupted cases anymore.
147e83
+   XXX: We split out this slow path because current compilers do not generate
147e83
+   as efficient code when the fast path in __pthread_once below is not in a
147e83
+   separate function.  */
147e83
+static int
147e83
+__attribute__ ((noinline))
147e83
+__pthread_once_slow (pthread_once_t *once_control, void (*init_routine) (void))
147e83
 {
147e83
   while (1)
147e83
     {
147e83
@@ -72,7 +74,7 @@ __pthread_once (once_control, init_routine)
147e83
          signals that initialization has finished, we need to see any
147e83
          data modifications done during initialization.  */
147e83
       val = *once_control;
147e83
-      atomic_read_barrier();
147e83
+      atomic_read_barrier ();
147e83
       do
147e83
 	{
147e83
 	  /* Check if the initialization has already been done.  */
147e83
@@ -130,5 +132,18 @@ __pthread_once (once_control, init_routine)
147e83
 
147e83
   return 0;
147e83
 }
147e83
+
147e83
+int
147e83
+__pthread_once (pthread_once_t *once_control, void (*init_routine) (void))
147e83
+{
147e83
+  /* Fast path.  See __pthread_once_slow.  */
147e83
+  int val;
147e83
+  val = *once_control;
147e83
+  atomic_read_barrier ();
147e83
+  if (__glibc_likely ((val & __PTHREAD_ONCE_DONE) != 0))
147e83
+    return 0;
147e83
+  else
147e83
+    return __pthread_once_slow (once_control, init_routine);
147e83
+}
147e83
 weak_alias (__pthread_once, pthread_once)
147e83
 hidden_def (__pthread_once)
147e83
diff --git a/nptl/sysdeps/unix/sysv/linux/i386/pthread_once.S b/nptl/sysdeps/unix/sysv/linux/i386/pthread_once.S
147e83
deleted file mode 100644
147e83
index ca3b860a7f6f95ae..0000000000000000
147e83
--- a/nptl/sysdeps/unix/sysv/linux/i386/pthread_once.S
147e83
+++ /dev/null
147e83
@@ -1,178 +0,0 @@
147e83
-/* Copyright (C) 2002-2012 Free Software Foundation, Inc.
147e83
-   This file is part of the GNU C Library.
147e83
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
147e83
-
147e83
-   The GNU C Library is free software; you can redistribute it and/or
147e83
-   modify it under the terms of the GNU Lesser General Public
147e83
-   License as published by the Free Software Foundation; either
147e83
-   version 2.1 of the License, or (at your option) any later version.
147e83
-
147e83
-   The GNU C Library is distributed in the hope that it will be useful,
147e83
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
-   Lesser General Public License for more details.
147e83
-
147e83
-   You should have received a copy of the GNU Lesser General Public
147e83
-   License along with the GNU C Library; if not, see
147e83
-   <http://www.gnu.org/licenses/>.  */
147e83
-
147e83
-#include <unwindbuf.h>
147e83
-#include <sysdep.h>
147e83
-#include <kernel-features.h>
147e83
-#include <lowlevellock.h>
147e83
-
147e83
-
147e83
-	.comm	__fork_generation, 4, 4
147e83
-
147e83
-	.text
147e83
-
147e83
-
147e83
-	.globl	__pthread_once
147e83
-	.type	__pthread_once,@function
147e83
-	.align	16
147e83
-	cfi_startproc
147e83
-__pthread_once:
147e83
-	movl	4(%esp), %ecx
147e83
-	testl	$2, (%ecx)
147e83
-	jz	1f
147e83
-	xorl	%eax, %eax
147e83
-	ret
147e83
-
147e83
-1:	pushl	%ebx
147e83
-	cfi_adjust_cfa_offset (4)
147e83
-	cfi_rel_offset (3, 0)
147e83
-	pushl	%esi
147e83
-	cfi_adjust_cfa_offset (4)
147e83
-	cfi_rel_offset (6, 0)
147e83
-	movl	%ecx, %ebx
147e83
-	xorl	%esi, %esi
147e83
-
147e83
-	/* Not yet initialized or initialization in progress.
147e83
-	   Get the fork generation counter now.  */
147e83
-6:	movl	(%ebx), %eax
147e83
-#ifdef PIC
147e83
-	LOAD_PIC_REG(cx)
147e83
-#endif
147e83
-
147e83
-5:	movl	%eax, %edx
147e83
-
147e83
-	testl	$2, %eax
147e83
-	jnz	4f
147e83
-
147e83
-	andl	$3, %edx
147e83
-#ifdef PIC
147e83
-	orl	__fork_generation@GOTOFF(%ecx), %edx
147e83
-#else
147e83
-	orl	__fork_generation, %edx
147e83
-#endif
147e83
-	orl	$1, %edx
147e83
-
147e83
-	LOCK
147e83
-	cmpxchgl %edx, (%ebx)
147e83
-	jnz	5b
147e83
-
147e83
-	/* Check whether another thread already runs the initializer.  */
147e83
-	testl	$1, %eax
147e83
-	jz	3f	/* No -> do it.  */
147e83
-
147e83
-	/* Check whether the initializer execution was interrupted
147e83
-	   by a fork.  */
147e83
-	xorl	%edx, %eax
147e83
-	testl	$0xfffffffc, %eax
147e83
-	jnz	3f	/* Different for generation -> run initializer.  */
147e83
-
147e83
-	/* Somebody else got here first.  Wait.  */
147e83
-#ifdef __ASSUME_PRIVATE_FUTEX
147e83
-	movl	$FUTEX_WAIT|FUTEX_PRIVATE_FLAG, %ecx
147e83
-#else
147e83
-# if FUTEX_WAIT == 0
147e83
-	movl	%gs:PRIVATE_FUTEX, %ecx
147e83
-# else
147e83
-	movl	$FUTEX_WAIT, %ecx
147e83
-	orl	%gs:PRIVATE_FUTEX, %ecx
147e83
-# endif
147e83
-#endif
147e83
-	movl	$SYS_futex, %eax
147e83
-	ENTER_KERNEL
147e83
-	jmp	6b
147e83
-
147e83
-3:	/* Call the initializer function after setting up the
147e83
-	   cancellation handler.  Note that it is not possible here
147e83
-	   to use the unwind-based cleanup handling.  This would require
147e83
-	   that the user-provided function and all the code it calls
147e83
-	   is compiled with exceptions.  Unfortunately this cannot be
147e83
-	   guaranteed.  */
147e83
-	subl	$UNWINDBUFSIZE+8, %esp
147e83
-	cfi_adjust_cfa_offset (UNWINDBUFSIZE+8)
147e83
-	movl	%ecx, %ebx		/* PIC register value.  */
147e83
-
147e83
-	leal	8+UWJMPBUF(%esp), %eax
147e83
-	movl	$0, 4(%esp)
147e83
-	movl	%eax, (%esp)
147e83
-	call	__sigsetjmp@PLT
147e83
-	testl	%eax, %eax
147e83
-	jne	7f
147e83
-
147e83
-	leal	8(%esp), %eax
147e83
-	call	HIDDEN_JUMPTARGET(__pthread_register_cancel)
147e83
-
147e83
-	/* Call the user-provided initialization function.  */
147e83
-	call	*24+UNWINDBUFSIZE(%esp)
147e83
-
147e83
-	/* Pop the cleanup handler.  */
147e83
-	leal	8(%esp), %eax
147e83
-	call	HIDDEN_JUMPTARGET(__pthread_unregister_cancel)
147e83
-	addl	$UNWINDBUFSIZE+8, %esp
147e83
-	cfi_adjust_cfa_offset (-UNWINDBUFSIZE-8)
147e83
-
147e83
-	/* Sucessful run of the initializer.  Signal that we are done.  */
147e83
-	movl	12(%esp), %ebx
147e83
-	LOCK
147e83
-	addl	$1, (%ebx)
147e83
-
147e83
-	/* Wake up all other threads.  */
147e83
-	movl	$0x7fffffff, %edx
147e83
-#ifdef __ASSUME_PRIVATE_FUTEX
147e83
-	movl	$FUTEX_WAKE|FUTEX_PRIVATE_FLAG, %ecx
147e83
-#else
147e83
-	movl	$FUTEX_WAKE, %ecx
147e83
-	orl	%gs:PRIVATE_FUTEX, %ecx
147e83
-#endif
147e83
-	movl	$SYS_futex, %eax
147e83
-	ENTER_KERNEL
147e83
-
147e83
-4:	popl	%esi
147e83
-	cfi_adjust_cfa_offset (-4)
147e83
-	cfi_restore (6)
147e83
-	popl	%ebx
147e83
-	cfi_adjust_cfa_offset (-4)
147e83
-	cfi_restore (3)
147e83
-	xorl	%eax, %eax
147e83
-	ret
147e83
-
147e83
-7:	/* __sigsetjmp returned for the second time.  */
147e83
-	movl	20+UNWINDBUFSIZE(%esp), %ebx
147e83
-	cfi_adjust_cfa_offset (UNWINDBUFSIZE+16)
147e83
-	cfi_offset (3, -8)
147e83
-	cfi_offset (6, -12)
147e83
-	movl	$0, (%ebx)
147e83
-
147e83
-	movl	$0x7fffffff, %edx
147e83
-#ifdef __ASSUME_PRIVATE_FUTEX
147e83
-	movl	$FUTEX_WAKE|FUTEX_PRIVATE_FLAG, %ecx
147e83
-#else
147e83
-	movl	$FUTEX_WAKE, %ecx
147e83
-	orl	%gs:PRIVATE_FUTEX, %ecx
147e83
-#endif
147e83
-	movl	$SYS_futex, %eax
147e83
-	ENTER_KERNEL
147e83
-
147e83
-	leal	8(%esp), %eax
147e83
-	call	HIDDEN_JUMPTARGET (__pthread_unwind_next)
147e83
-	/* NOTREACHED */
147e83
-	hlt
147e83
-	cfi_endproc
147e83
-	.size	__pthread_once,.-__pthread_once
147e83
-
147e83
-hidden_def (__pthread_once)
147e83
-strong_alias (__pthread_once, pthread_once)
147e83
diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
147e83
deleted file mode 100644
147e83
index 7f5c0810fa16b987..0000000000000000
147e83
--- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
147e83
+++ /dev/null
147e83
@@ -1,193 +0,0 @@
147e83
-/* Copyright (C) 2002-2012 Free Software Foundation, Inc.
147e83
-   This file is part of the GNU C Library.
147e83
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
147e83
-
147e83
-   The GNU C Library is free software; you can redistribute it and/or
147e83
-   modify it under the terms of the GNU Lesser General Public
147e83
-   License as published by the Free Software Foundation; either
147e83
-   version 2.1 of the License, or (at your option) any later version.
147e83
-
147e83
-   The GNU C Library is distributed in the hope that it will be useful,
147e83
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
-   Lesser General Public License for more details.
147e83
-
147e83
-   You should have received a copy of the GNU Lesser General Public
147e83
-   License along with the GNU C Library; if not, see
147e83
-   <http://www.gnu.org/licenses/>.  */
147e83
-
147e83
-#include <sysdep.h>
147e83
-#include <kernel-features.h>
147e83
-#include <tcb-offsets.h>
147e83
-#include <lowlevellock.h>
147e83
-
147e83
-
147e83
-	.comm	__fork_generation, 4, 4
147e83
-
147e83
-	.text
147e83
-
147e83
-
147e83
-	.globl	__pthread_once
147e83
-	.type	__pthread_once,@function
147e83
-	.align	16
147e83
-__pthread_once:
147e83
-.LSTARTCODE:
147e83
-	cfi_startproc
147e83
-#ifdef SHARED
147e83
-	cfi_personality(DW_EH_PE_pcrel | DW_EH_PE_sdata4 | DW_EH_PE_indirect,
147e83
-			DW.ref.__gcc_personality_v0)
147e83
-	cfi_lsda(DW_EH_PE_pcrel | DW_EH_PE_sdata4, .LexceptSTART)
147e83
-#else
147e83
-	cfi_personality(DW_EH_PE_udata4, __gcc_personality_v0)
147e83
-	cfi_lsda(DW_EH_PE_udata4, .LexceptSTART)
147e83
-#endif
147e83
-	testl	$2, (%rdi)
147e83
-	jz	1f
147e83
-	xorl	%eax, %eax
147e83
-	retq
147e83
-
147e83
-	/* Preserve the function pointer.  */
147e83
-1:	pushq	%rsi
147e83
-	cfi_adjust_cfa_offset(8)
147e83
-	xorq	%r10, %r10
147e83
-
147e83
-	/* Not yet initialized or initialization in progress.
147e83
-	   Get the fork generation counter now.  */
147e83
-6:	movl	(%rdi), %eax
147e83
-
147e83
-5:	movl	%eax, %edx
147e83
-
147e83
-	testl	$2, %eax
147e83
-	jnz	4f
147e83
-
147e83
-	andl	$3, %edx
147e83
-	orl	__fork_generation(%rip), %edx
147e83
-	orl	$1, %edx
147e83
-
147e83
-	LOCK
147e83
-	cmpxchgl %edx, (%rdi)
147e83
-	jnz	5b
147e83
-
147e83
-	/* Check whether another thread already runs the initializer.  */
147e83
-	testl	$1, %eax
147e83
-	jz	3f	/* No -> do it.  */
147e83
-
147e83
-	/* Check whether the initializer execution was interrupted
147e83
-	   by a fork.  */
147e83
-	xorl	%edx, %eax
147e83
-	testl	$0xfffffffc, %eax
147e83
-	jnz	3f	/* Different for generation -> run initializer.  */
147e83
-
147e83
-	/* Somebody else got here first.  Wait.  */
147e83
-#ifdef __ASSUME_PRIVATE_FUTEX
147e83
-	movl	$FUTEX_WAIT|FUTEX_PRIVATE_FLAG, %esi
147e83
-#else
147e83
-# if FUTEX_WAIT == 0
147e83
-	movl	%fs:PRIVATE_FUTEX, %esi
147e83
-# else
147e83
-	movl	$FUTEX_WAIT, %esi
147e83
-	orl	%fs:PRIVATE_FUTEX, %esi
147e83
-# endif
147e83
-#endif
147e83
-	movl	$SYS_futex, %eax
147e83
-	syscall
147e83
-	jmp	6b
147e83
-
147e83
-	/* Preserve the pointer to the control variable.  */
147e83
-3:	pushq	%rdi
147e83
-	cfi_adjust_cfa_offset(8)
147e83
-	pushq	%rdi
147e83
-	cfi_adjust_cfa_offset(8)
147e83
-
147e83
-.LcleanupSTART:
147e83
-	callq	*16(%rsp)
147e83
-.LcleanupEND:
147e83
-
147e83
-	/* Get the control variable address back.  */
147e83
-	popq	%rdi
147e83
-	cfi_adjust_cfa_offset(-8)
147e83
-
147e83
-	/* Sucessful run of the initializer.  Signal that we are done.  */
147e83
-	LOCK
147e83
-	incl	(%rdi)
147e83
-
147e83
-	addq	$8, %rsp
147e83
-	cfi_adjust_cfa_offset(-8)
147e83
-
147e83
-	/* Wake up all other threads.  */
147e83
-	movl	$0x7fffffff, %edx
147e83
-#ifdef __ASSUME_PRIVATE_FUTEX
147e83
-	movl	$FUTEX_WAKE|FUTEX_PRIVATE_FLAG, %esi
147e83
-#else
147e83
-	movl	$FUTEX_WAKE, %esi
147e83
-	orl	%fs:PRIVATE_FUTEX, %esi
147e83
-#endif
147e83
-	movl	$SYS_futex, %eax
147e83
-	syscall
147e83
-
147e83
-4:	addq	$8, %rsp
147e83
-	cfi_adjust_cfa_offset(-8)
147e83
-	xorl	%eax, %eax
147e83
-	retq
147e83
-	.size	__pthread_once,.-__pthread_once
147e83
-
147e83
-
147e83
-hidden_def (__pthread_once)
147e83
-strong_alias (__pthread_once, pthread_once)
147e83
-
147e83
-
147e83
-	.type	clear_once_control,@function
147e83
-	.align	16
147e83
-clear_once_control:
147e83
-	cfi_adjust_cfa_offset(3 * 8)
147e83
-	movq	(%rsp), %rdi
147e83
-	movq	%rax, %r8
147e83
-	movl	$0, (%rdi)
147e83
-
147e83
-	movl	$0x7fffffff, %edx
147e83
-#ifdef __ASSUME_PRIVATE_FUTEX
147e83
-	movl	$FUTEX_WAKE|FUTEX_PRIVATE_FLAG, %esi
147e83
-#else
147e83
-	movl	$FUTEX_WAKE, %esi
147e83
-	orl	%fs:PRIVATE_FUTEX, %esi
147e83
-#endif
147e83
-	movl	$SYS_futex, %eax
147e83
-	syscall
147e83
-
147e83
-	movq	%r8, %rdi
147e83
-.LcallUR:
147e83
-	call	_Unwind_Resume@PLT
147e83
-	hlt
147e83
-.LENDCODE:
147e83
-	cfi_endproc
147e83
-	.size	clear_once_control,.-clear_once_control
147e83
-
147e83
-
147e83
-	.section .gcc_except_table,"a",@progbits
147e83
-.LexceptSTART:
147e83
-	.byte	DW_EH_PE_omit			# @LPStart format
147e83
-	.byte	DW_EH_PE_omit			# @TType format
147e83
-	.byte	DW_EH_PE_uleb128		# call-site format
147e83
-	.uleb128 .Lcstend-.Lcstbegin
147e83
-.Lcstbegin:
147e83
-	.uleb128 .LcleanupSTART-.LSTARTCODE
147e83
-	.uleb128 .LcleanupEND-.LcleanupSTART
147e83
-	.uleb128 clear_once_control-.LSTARTCODE
147e83
-	.uleb128  0
147e83
-	.uleb128 .LcallUR-.LSTARTCODE
147e83
-	.uleb128 .LENDCODE-.LcallUR
147e83
-	.uleb128 0
147e83
-	.uleb128  0
147e83
-.Lcstend:
147e83
-
147e83
-
147e83
-#ifdef SHARED
147e83
-	.hidden	DW.ref.__gcc_personality_v0
147e83
-	.weak	DW.ref.__gcc_personality_v0
147e83
-	.section .gnu.linkonce.d.DW.ref.__gcc_personality_v0,"aw",@progbits
147e83
-	.align	LP_SIZE
147e83
-	.type	DW.ref.__gcc_personality_v0, @object
147e83
-	.size	DW.ref.__gcc_personality_v0, LP_SIZE
147e83
-DW.ref.__gcc_personality_v0:
147e83
-	ASM_ADDR __gcc_personality_v0
147e83
-#endif