]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Cast to __intptr_t before casting pointer to int64
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 27 Nov 2012 00:42:38 +0000 (16:42 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 27 Nov 2012 00:45:36 +0000 (16:45 -0800)
ChangeLog
elf/dl-load.c
include/libc-internal.h
nptl/ChangeLog
nptl/sysdeps/i386/tls.h
nptl/sysdeps/x86_64/tls.h
nptl/unwind.c
sysdeps/x86_64/bits/atomic.h

index 6b0d5481888414cd92223dabb75b9698c361e209..dfe66718ec0032fd7c929ad30cff7a282a8b1499 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2012-11-26  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * 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@codesourcery.com>
 
        * sysdeps/generic/unwind-dw2-fde.c (get_pc_begin): New function.
index a6955561f3bd7f32ce507138f6b6c7dad58d63a1..70fe78f3e7bd661ae6c8d0e768763eaaa0264c3b 100644 (file)
@@ -1351,7 +1351,8 @@ cannot allocate TLS data structures for initial thread");
            && ((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)
          {
index e5fd5337ab4400b2ec196df4b3b6b7f14b532560..0c0fa024a745a458109c854b9adf74557b6f6b2d 100644 (file)
@@ -34,4 +34,20 @@ extern void __libc_thread_freeres (void);
 /* 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  */
index 7c8736cac31d2606e0099dcbcbfea68c8f121e6e..a9b00e7c7840c3c416d3bc74ca75acda6f714426 100644 (file)
@@ -1,3 +1,14 @@
+2012-11-26  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * 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@codesourcery.com>
 
        * sysdeps/unix/sysv/linux/sem_post.c (__old_sem_post): Cast result
index eb1ca312f9b2880b9d3a48c9de5d94e350c4af84..90c7a534bfd0ed16f48266f55c36c31ab36ac623 100644 (file)
@@ -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 @@ union user_desc_init
                                                                              \
         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 @@ union user_desc_init
                                                                              \
         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));                                          \
        }})
index bc60a511fbc0555f069888dc977ce39bd5326a46..f3b76495b303597ccbbb8feb2345b97befa1bda7 100644 (file)
@@ -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 @@ typedef struct
           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 @@ typedef struct
           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));                                          \
        }})
index 7ccb21382b7a581b3fee20874993707e73bdca7e..aedd0374521c6cfe4c1016b1253a33e541a2f32a 100644 (file)
@@ -124,7 +124,7 @@ __pthread_unwind (__pthread_unwind_buf_t *buf)
   /* 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
index 100943fa1e24385ec7f365832e4e4f93d985b875..552581c46e65c7c94c198e4383ed6eb9baa5cd72 100644 (file)
@@ -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 @@ typedef uintmax_t uatomic_max_t;
                       "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 @@ typedef uintmax_t uatomic_max_t;
      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 @@ typedef uintmax_t uatomic_max_t;
      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 @@ typedef uintmax_t uatomic_max_t;
     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 @@ typedef uintmax_t uatomic_max_t;
      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 @@ typedef uintmax_t uatomic_max_t;
      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; })