[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commits] r21882 - in /fsf/trunk/libc: ./ elf/ include/ libio/ nptl/ nptl/sysdeps/i386/ nptl/sysdeps/x86_64/ sysdeps/generic/ sysdeps/...



Author: eglibc
Date: Wed Nov 28 00:01:49 2012
New Revision: 21882

Log:
Import glibc-mainline for 2012-11-28

Added:
    fsf/trunk/libc/libio/tst-fwrite-error.c
Modified:
    fsf/trunk/libc/ChangeLog
    fsf/trunk/libc/elf/dl-load.c
    fsf/trunk/libc/include/libc-internal.h
    fsf/trunk/libc/libio/Makefile
    fsf/trunk/libc/libio/iofwrite.c
    fsf/trunk/libc/libio/iofwrite_u.c
    fsf/trunk/libc/nptl/ChangeLog
    fsf/trunk/libc/nptl/sysdeps/i386/tls.h
    fsf/trunk/libc/nptl/sysdeps/x86_64/tls.h
    fsf/trunk/libc/nptl/unwind.c
    fsf/trunk/libc/sysdeps/generic/unwind-dw2-fde.c
    fsf/trunk/libc/sysdeps/x86_64/bits/atomic.h

Modified: fsf/trunk/libc/ChangeLog
==============================================================================
--- fsf/trunk/libc/ChangeLog (original)
+++ fsf/trunk/libc/ChangeLog Wed Nov 28 00:01:49 2012
@@ -1,3 +1,36 @@
+2012-11-27  Siddhesh Poyarekar  <siddhesh@xxxxxxxxxx>
+
+	[BZ #11741]
+	* libio/Makefile (tests): Add test case tst-fwrite-error.
+	* libio/iofwrite.c (_IO_fwrite): Return 0 on EOF.
+	* libio/iofwrite_u.c (fwrite_unlocked): Likewise.
+	* libio/tst-fwrite-error.c: New test case.
+
+2012-11-26  H.J. Lu  <hongjiu.lu@xxxxxxxxx>
+
+	* elf/dl-load.c (_dl_map_object_from_fd): Cast to uintptr_t
+	before casting to void *.
+	* include/libc-internal.h (__pointer_type): New macro.
+	(__integer_if_pointer_type_sub): Likewise.
+	(__integer_if_pointer_type): Likewise.
+	(cast_to_integer): Likewise.
+	* sysdeps/x86_64/bits/atomic.h: Include <libc-internal.h>.
+	(__arch_c_compare_and_exchange_val_64_acq): Use cast_to_integer
+	before casting to atomic64_t.
+	(atomic_exchange_acq): Likewise.
+	(__arch_exchange_and_add_body): Likewise.
+	(__arch_add_body): Likewise.
+	(atomic_add_negative): Likewise.
+	(atomic_add_zero): Likewise.
+
+2012-11-26  Joseph Myers  <joseph@xxxxxxxxxxxxxxxx>
+
+	* sysdeps/generic/unwind-dw2-fde.c (get_pc_begin): New function.
+	(fde_unencoded_compare): Use get_pc_begin instead of type-punning.
+	(add_fdes): Likewise.
+	(linear_search_fdes): Likewise.
+	(binary_search_unencoded_fdes): Likewise.
+
 2012-11-26  Andreas Schwab  <schwab@xxxxxxxxxxxxxx>
 
 	* elf/sotruss.ksh: Correctly locate argument of -F and -T options.

Modified: fsf/trunk/libc/elf/dl-load.c
==============================================================================
--- fsf/trunk/libc/elf/dl-load.c (original)
+++ fsf/trunk/libc/elf/dl-load.c Wed Nov 28 00:01:49 2012
@@ -1351,7 +1351,8 @@
 	    && ((size_t) (c->mapend - c->mapstart + c->mapoff)
 		>= header->e_phoff + header->e_phnum * sizeof (ElfW(Phdr))))
 	  /* Found the program header in this segment.  */
-	  l->l_phdr = (void *) (c->mapstart + header->e_phoff - c->mapoff);
+	  l->l_phdr = (void *) (uintptr_t) (c->mapstart + header->e_phoff
+					    - c->mapoff);
 
 	if (c->allocend > c->dataend)
 	  {

Modified: fsf/trunk/libc/include/libc-internal.h
==============================================================================
--- fsf/trunk/libc/include/libc-internal.h (original)
+++ fsf/trunk/libc/include/libc-internal.h Wed Nov 28 00:01:49 2012
@@ -34,4 +34,20 @@
 /* Define and initialize `__progname' et. al.  */
 extern void __init_misc (int, char **, char **);
 
+/* 1 if 'type' is a pointer type, 0 otherwise.  */
+# define __pointer_type(type) (__builtin_classify_type ((type) 0) == 5)
+
+/* __intptr_t if P is true, or T if P is false.  */
+# define __integer_if_pointer_type_sub(T, P) \
+  __typeof__ (*(0 ? (__typeof__ (0 ? (T *) 0 : (void *) (P))) 0 \
+		  : (__typeof__ (0 ? (__intptr_t *) 0 : (void *) (!(P)))) 0))
+
+/* __intptr_t if EXPR has a pointer type, or the type of EXPR otherwise.  */
+# define __integer_if_pointer_type(expr) \
+  __integer_if_pointer_type_sub(__typeof__ ((__typeof__ (expr)) 0), \
+				__pointer_type (__typeof__ (expr)))
+
+/* Cast an integer or a pointer VAL to integer with proper type.  */
+# define cast_to_integer(val) ((__integer_if_pointer_type (val)) (val))
+
 #endif /* _LIBC_INTERNAL  */

Modified: fsf/trunk/libc/libio/Makefile
==============================================================================
--- fsf/trunk/libc/libio/Makefile (original)
+++ fsf/trunk/libc/libio/Makefile Wed Nov 28 00:01:49 2012
@@ -59,7 +59,8 @@
 	tst-memstream1 tst-memstream2 \
 	tst-wmemstream1 tst-wmemstream2 \
 	bug-memstream1 bug-wmemstream1 \
-	tst-setvbuf1 tst-popen1 tst-fgetwc bug-wsetpos bug-fclose1 tst-fseek
+	tst-setvbuf1 tst-popen1 tst-fgetwc bug-wsetpos bug-fclose1 tst-fseek \
+	tst-fwrite-error
 ifeq (yes,$(build-shared))
 # Add test-fopenloc only if shared library is enabled since it depends on
 # shared localedata objects.

Modified: fsf/trunk/libc/libio/iofwrite.c
==============================================================================
--- fsf/trunk/libc/libio/iofwrite.c (original)
+++ fsf/trunk/libc/libio/iofwrite.c Wed Nov 28 00:01:49 2012
@@ -42,12 +42,12 @@
   if (_IO_vtable_offset (fp) != 0 || _IO_fwide (fp, -1) == -1)
     written = _IO_sputn (fp, (const char *) buf, request);
   _IO_release_lock (fp);
-  /* We have written all of the input in case the return value indicates
-     this or EOF is returned.  The latter is a special case where we
-     simply did not manage to flush the buffer.  But the data is in the
-     buffer and therefore written as far as fwrite is concerned.  */
-  if (written == request || written == EOF)
+  /* We are guaranteed to have written all of the input, none of it, or
+     some of it.  */
+  if (written == request)
     return count;
+  else if (written == EOF)
+    return 0;
   else
     return written / size;
 }

Modified: fsf/trunk/libc/libio/iofwrite_u.c
==============================================================================
--- fsf/trunk/libc/libio/iofwrite_u.c (original)
+++ fsf/trunk/libc/libio/iofwrite_u.c Wed Nov 28 00:01:49 2012
@@ -44,12 +44,12 @@
   if (_IO_fwide (fp, -1) == -1)
     {
       written = _IO_sputn (fp, (const char *) buf, request);
-      /* We have written all of the input in case the return value indicates
-	 this or EOF is returned.  The latter is a special case where we
-	 simply did not manage to flush the buffer.  But the data is in the
-	 buffer and therefore written as far as fwrite is concerned.  */
-      if (written == request || written == EOF)
+      /* We are guaranteed to have written all of the input, none of it, or
+	 some of it.  */
+      if (written == request)
 	return count;
+      else if (written == EOF)
+	return 0;
     }
 
   return written / size;

Added: fsf/trunk/libc/libio/tst-fwrite-error.c
==============================================================================
--- fsf/trunk/libc/libio/tst-fwrite-error.c (added)
+++ fsf/trunk/libc/libio/tst-fwrite-error.c Wed Nov 28 00:01:49 2012
@@ -1,0 +1,66 @@
+/* Test of fwrite() function, adapted from gnulib-tests in grep.
+   Copyright (C) 2011-2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+
+static int
+do_test (void)
+{
+  char tmpl[] = "/tmp/tst-fwrite-error.XXXXXX";
+  int fd = mkstemp (tmpl);
+  if (fd == -1)
+    {
+      printf ("mkstemp failed with errno %d\n", errno);
+      return 1;
+    }
+  FILE *fp = fdopen (fd, "w");
+  if (fp == NULL)
+    {
+      printf ("fdopen failed with errno %d\n", errno);
+      return 1;
+    }
+
+  char buf[5] = "world";
+  setvbuf (fp, NULL, _IONBF, 0);
+  close (fd);
+  unlink (tmpl);
+  errno = 0;
+
+  int ret = fwrite (buf, 1, sizeof (buf), fp);
+  if (ret != 0)
+    {
+      printf ("fwrite returned %d\n", ret);
+      return 1;
+    }
+  if (errno != EBADF)
+    {
+      printf ("Errno is not EBADF: %d\n", errno);
+      return 1;
+    }
+  if (ferror (fp) == 0)
+    {
+      printf ("ferror not set\n");
+      return 1;
+    }
+
+  return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"

Modified: fsf/trunk/libc/nptl/ChangeLog
==============================================================================
--- fsf/trunk/libc/nptl/ChangeLog (original)
+++ fsf/trunk/libc/nptl/ChangeLog Wed Nov 28 00:01:49 2012
@@ -1,3 +1,14 @@
+2012-11-26  H.J. Lu  <hongjiu.lu@xxxxxxxxx>
+
+	* unwind.c (__pthread_unwind): Pass address of unwind_cleanup
+	to THREAD_SETMEM.
+	* sysdeps/i386/tls.h: Include <libc-internal.h>.
+	(THREAD_SETMEM): Use cast_to_integer before casting to uint64_t.
+	(THREAD_SETMEM_NC): Likewise.
+	* sysdeps/x86_64/tls.h: Include <libc-internal.h>.
+	(THREAD_SETMEM): Use cast_to_integer before casting to uint64_t.
+	(THREAD_SETMEM_NC): Likewise.
+
 2012-11-21  Joseph Myers  <joseph@xxxxxxxxxxxxxxxx>
 
 	* sysdeps/unix/sysv/linux/sem_post.c (__old_sem_post): Cast result

Modified: fsf/trunk/libc/nptl/sysdeps/i386/tls.h
==============================================================================
--- fsf/trunk/libc/nptl/sysdeps/i386/tls.h (original)
+++ fsf/trunk/libc/nptl/sysdeps/i386/tls.h Wed Nov 28 00:01:49 2012
@@ -26,6 +26,7 @@
 # include <stdint.h>
 # include <stdlib.h>
 # include <sysdep.h>
+# include <libc-internal.h>
 # include <kernel-features.h>
 
 
@@ -343,7 +344,7 @@
 									      \
 	 asm volatile ("movl %%eax,%%gs:%P1\n\t"			      \
 		       "movl %%edx,%%gs:%P2" :				      \
-		       : "A" ((uint64_t) (value)),			      \
+		       : "A" ((uint64_t) cast_to_integer (value)),	      \
 			 "i" (offsetof (struct pthread, member)),	      \
 			 "i" (offsetof (struct pthread, member) + 4));	      \
        }})
@@ -370,7 +371,7 @@
 									      \
 	 asm volatile ("movl %%eax,%%gs:%P1(,%2,8)\n\t"			      \
 		       "movl %%edx,%%gs:4+%P1(,%2,8)" :			      \
-		       : "A" ((uint64_t) (value)),			      \
+		       : "A" ((uint64_t) cast_to_integer (value)),	      \
 			 "i" (offsetof (struct pthread, member)),	      \
 			 "r" (idx));					      \
        }})

Modified: fsf/trunk/libc/nptl/sysdeps/x86_64/tls.h
==============================================================================
--- fsf/trunk/libc/nptl/sysdeps/x86_64/tls.h (original)
+++ fsf/trunk/libc/nptl/sysdeps/x86_64/tls.h Wed Nov 28 00:01:49 2012
@@ -26,6 +26,7 @@
 # include <stdint.h>
 # include <stdlib.h>
 # include <sysdep.h>
+# include <libc-internal.h>
 # include <kernel-features.h>
 
 /* Replacement type for __m128 since this file is included by ld.so,
@@ -263,7 +264,7 @@
 	   abort ();							      \
 									      \
 	 asm volatile ("movq %q0,%%fs:%P1" :				      \
-		       : IMM_MODE ((uint64_t) (value)),			      \
+		       : IMM_MODE ((uint64_t) cast_to_integer (value)),	      \
 			 "i" (offsetof (struct pthread, member)));	      \
        }})
 
@@ -288,7 +289,7 @@
 	   abort ();							      \
 									      \
 	 asm volatile ("movq %q0,%%fs:%P1(,%q2,8)" :			      \
-		       : IMM_MODE ((uint64_t) (value)),			      \
+		       : IMM_MODE ((uint64_t) cast_to_integer (value)),	      \
 			 "i" (offsetof (struct pthread, member[0])),	      \
 			 "r" (idx));					      \
        }})

Modified: fsf/trunk/libc/nptl/unwind.c
==============================================================================
--- fsf/trunk/libc/nptl/unwind.c (original)
+++ fsf/trunk/libc/nptl/unwind.c Wed Nov 28 00:01:49 2012
@@ -124,7 +124,7 @@
   /* This is not a catchable exception, so don't provide any details about
      the exception type.  We do need to initialize the field though.  */
   THREAD_SETMEM (self, exc.exception_class, 0);
-  THREAD_SETMEM (self, exc.exception_cleanup, unwind_cleanup);
+  THREAD_SETMEM (self, exc.exception_cleanup, &unwind_cleanup);
 
   _Unwind_ForcedUnwind (&self->exc, unwind_stop, ibuf);
 #else

Modified: fsf/trunk/libc/sysdeps/generic/unwind-dw2-fde.c
==============================================================================
--- fsf/trunk/libc/sysdeps/generic/unwind-dw2-fde.c (original)
+++ fsf/trunk/libc/sysdeps/generic/unwind-dw2-fde.c Wed Nov 28 00:01:49 2012
@@ -1,6 +1,5 @@
 /* Subroutines needed for unwinding stack frames for exception handling.  */
-/* Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2006, 2007
-   Free Software Foundation, Inc.
+/* Copyright (C) 1997-2012 Free Software Foundation, Inc.
    Contributed by Jason Merrill <jason@xxxxxxxxxx>.
 
    This file is part of the GNU C Library.
@@ -342,14 +341,24 @@
    (Ideally we would have the linker sort the FDEs so we don't have to do
    it at run time. But the linkers are not yet prepared for this.)  */
 
+/* Return the Nth pc_begin value from FDE x.  */
+
+static inline _Unwind_Ptr
+get_pc_begin (fde *x, size_t n)
+{
+  _Unwind_Ptr p;
+  memcpy (&p, x->pc_begin + n * sizeof (_Unwind_Ptr), sizeof (_Unwind_Ptr));
+  return p;
+}
+
 /* Comparison routines.  Three variants of increasing complexity.  */
 
 static int
 fde_unencoded_compare (struct object *ob __attribute__((unused)),
 		       fde *x, fde *y)
 {
-  _Unwind_Ptr x_ptr = *(_Unwind_Ptr *) x->pc_begin;
-  _Unwind_Ptr y_ptr = *(_Unwind_Ptr *) y->pc_begin;
+  _Unwind_Ptr x_ptr = get_pc_begin (x, 0);
+  _Unwind_Ptr y_ptr = get_pc_begin (y, 0);
 
   if (x_ptr > y_ptr)
     return 1;
@@ -712,7 +721,7 @@
 
       if (encoding == DW_EH_PE_absptr)
 	{
-	  if (*(_Unwind_Ptr *) this_fde->pc_begin == 0)
+	  if (get_pc_begin (this_fde, 0) == 0)
 	    continue;
 	}
       else
@@ -830,8 +839,8 @@
 
       if (encoding == DW_EH_PE_absptr)
 	{
-	  pc_begin = ((_Unwind_Ptr *) this_fde->pc_begin)[0];
-	  pc_range = ((_Unwind_Ptr *) this_fde->pc_begin)[1];
+	  pc_begin = get_pc_begin (this_fde, 0);
+	  pc_range = get_pc_begin (this_fde, 1);
 	  if (pc_begin == 0)
 	    continue;
 	}
@@ -881,8 +890,8 @@
       void *pc_begin;
       uaddr pc_range;
 
-      pc_begin = ((void **) f->pc_begin)[0];
-      pc_range = ((uaddr *) f->pc_begin)[1];
+      pc_begin = (void *) get_pc_begin (f, 0);
+      pc_range = (uaddr) get_pc_begin (f, 1);
 
       if (pc < pc_begin)
 	hi = i;

Modified: fsf/trunk/libc/sysdeps/x86_64/bits/atomic.h
==============================================================================
--- fsf/trunk/libc/sysdeps/x86_64/bits/atomic.h (original)
+++ fsf/trunk/libc/sysdeps/x86_64/bits/atomic.h Wed Nov 28 00:01:49 2012
@@ -18,6 +18,7 @@
 
 #include <stdint.h>
 #include <tls.h>	/* For tcbhead_t.  */
+#include <libc-internal.h>
 
 
 typedef int8_t atomic8_t;
@@ -101,8 +102,9 @@
 		       "lock\n"						      \
 		       "0:\tcmpxchgq %q2, %1"				      \
 		       : "=a" (ret), "=m" (*mem)			      \
-		       : "q" ((atomic64_t) (newval)), "m" (*mem),	      \
-			 "0" ((atomic64_t) (oldval)),		      \
+		       : "q" ((atomic64_t) cast_to_integer (newval)),	      \
+			 "m" (*mem),					      \
+			 "0" ((atomic64_t) cast_to_integer (oldval)),	      \
 			 "i" (offsetof (tcbhead_t, multiple_threads)));	      \
      ret; })
 
@@ -125,7 +127,8 @@
      else								      \
        __asm __volatile ("xchgq %q0, %1"				      \
 			 : "=r" (result), "=m" (*mem)			      \
-			 : "0" ((atomic64_t) (newvalue)), "m" (*mem));	      \
+			 : "0" ((atomic64_t) cast_to_integer (newvalue)),     \
+			   "m" (*mem));					      \
      result; })
 
 
@@ -149,7 +152,8 @@
      else								      \
        __asm __volatile (lock "xaddq %q0, %1"				      \
 			 : "=r" (result), "=m" (*mem)			      \
-			 : "0" ((atomic64_t) (value)), "m" (*mem),	      \
+			 : "0" ((atomic64_t) cast_to_integer (value)),	      \
+			   "m" (*mem),					      \
 			   "i" (offsetof (tcbhead_t, multiple_threads)));     \
      result; })
 
@@ -187,7 +191,8 @@
     else								      \
       __asm __volatile (lock "addq %q1, %0"				      \
 			: "=m" (*mem)					      \
-			: "ir" ((atomic64_t) (value)), "m" (*mem),	      \
+			: "ir" ((atomic64_t) cast_to_integer (value)),	      \
+			  "m" (*mem),					      \
 			  "i" (offsetof (tcbhead_t, multiple_threads)));      \
   } while (0)
 
@@ -218,7 +223,8 @@
      else								      \
        __asm __volatile (LOCK_PREFIX "addq %q2, %0; sets %1"		      \
 			 : "=m" (*mem), "=qm" (__result)		      \
-			 : "ir" ((atomic64_t) (value)), "m" (*mem));	      \
+			 : "ir" ((atomic64_t) cast_to_integer (value)),	      \
+			   "m" (*mem));					      \
      __result; })
 
 
@@ -239,7 +245,8 @@
      else								      \
        __asm __volatile (LOCK_PREFIX "addq %q2, %0; setz %1"		      \
 			 : "=m" (*mem), "=qm" (__result)		      \
-			 : "ir" ((atomic64_t) (value)), "m" (*mem));	      \
+			 : "ir" ((atomic64_t) cast_to_integer (value)),	      \
+			   "m" (*mem));					      \
      __result; })
 
 

_______________________________________________
Commits mailing list
Commits@xxxxxxxxxx
http://eglibc.org/cgi-bin/mailman/listinfo/commits