Enable -Wold-style-cast warnings for linker

  And fix old style casts.

Change-Id: I37e7a3e3fd852528ea76f02d967c7bd8cd5b06c9
diff --git a/linker/Android.mk b/linker/Android.mk
index e1302db..cc7fadf 100644
--- a/linker/Android.mk
+++ b/linker/Android.mk
@@ -35,6 +35,7 @@
 
 LOCAL_CPPFLAGS += \
     -std=gnu++11 \
+    -Wold-style-cast \
 
 ifeq ($(TARGET_IS_64_BIT),true)
 LOCAL_CPPFLAGS += -DTARGET_IS_64_BIT
diff --git a/linker/debugger.cpp b/linker/debugger.cpp
index decc22c..c889544 100644
--- a/linker/debugger.cpp
+++ b/linker/debugger.cpp
@@ -151,7 +151,7 @@
   }
 
   char thread_name[MAX_TASK_NAME_LEN + 1]; // one more for termination
-  if (prctl(PR_GET_NAME, (unsigned long)thread_name, 0, 0, 0) != 0) {
+  if (prctl(PR_GET_NAME, reinterpret_cast<unsigned long>(thread_name), 0, 0, 0) != 0) {
     strcpy(thread_name, "<name unknown>");
   } else {
     // short names are null terminated by prctl, but the man page
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 0b0afc3..df6a4e2 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -71,6 +71,10 @@
  *   and NOEXEC
  */
 
+// Override macros to use C++ style casts
+#undef ELF_ST_TYPE
+#define ELF_ST_TYPE(x) (static_cast<uint32_t>(x) & 0xf)
+
 #if defined(__LP64__)
 #define SEARCH_NAME(x) x
 #else
@@ -364,12 +368,12 @@
 //
 // This function is exposed via dlfcn.cpp and libdl.so.
 _Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount) {
-  unsigned addr = (unsigned)pc;
+  uintptr_t addr = reinterpret_cast<uintptr_t>(pc);
 
   for (soinfo* si = solist; si != 0; si = si->next) {
     if ((addr >= si->base) && (addr < (si->base + si->size))) {
         *pcount = si->ARM_exidx_count;
-        return (_Unwind_Ptr)si->ARM_exidx;
+        return reinterpret_cast<_Unwind_Ptr>(si->ARM_exidx);
     }
   }
   *pcount = 0;
@@ -2090,7 +2094,7 @@
         break;
 
       case DT_INIT_ARRAYSZ:
-        init_array_count_ = ((unsigned)d->d_un.d_val) / sizeof(ElfW(Addr));
+        init_array_count_ = static_cast<uint32_t>(d->d_un.d_val) / sizeof(ElfW(Addr));
         break;
 
       case DT_FINI_ARRAY:
@@ -2099,7 +2103,7 @@
         break;
 
       case DT_FINI_ARRAYSZ:
-        fini_array_count_ = ((unsigned)d->d_un.d_val) / sizeof(ElfW(Addr));
+        fini_array_count_ = static_cast<uint32_t>(d->d_un.d_val) / sizeof(ElfW(Addr));
         break;
 
       case DT_PREINIT_ARRAY:
@@ -2108,7 +2112,7 @@
         break;
 
       case DT_PREINIT_ARRAYSZ:
-        preinit_array_count_ = ((unsigned)d->d_un.d_val) / sizeof(ElfW(Addr));
+        preinit_array_count_ = static_cast<uint32_t>(d->d_un.d_val) / sizeof(ElfW(Addr));
         break;
 
       case DT_TEXTREL:
diff --git a/linker/linker_phdr.cpp b/linker/linker_phdr.cpp
index ffd4de2..af4dc25 100644
--- a/linker/linker_phdr.cpp
+++ b/linker/linker_phdr.cpp
@@ -688,7 +688,7 @@
  */
 int phdr_table_get_arm_exidx(const ElfW(Phdr)* phdr_table, size_t phdr_count,
                              ElfW(Addr) load_bias,
-                             ElfW(Addr)** arm_exidx, unsigned* arm_exidx_count) {
+                             ElfW(Addr)** arm_exidx, size_t* arm_exidx_count) {
   const ElfW(Phdr)* phdr = phdr_table;
   const ElfW(Phdr)* phdr_limit = phdr + phdr_count;
 
@@ -698,7 +698,7 @@
     }
 
     *arm_exidx = reinterpret_cast<ElfW(Addr)*>(load_bias + phdr->p_vaddr);
-    *arm_exidx_count = (unsigned)(phdr->p_memsz / 8);
+    *arm_exidx_count = phdr->p_memsz / 8;
     return 0;
   }
   *arm_exidx = nullptr;
@@ -757,7 +757,7 @@
         ElfW(Addr)  elf_addr = load_bias_ + phdr->p_vaddr;
         const ElfW(Ehdr)* ehdr = reinterpret_cast<const ElfW(Ehdr)*>(elf_addr);
         ElfW(Addr)  offset = ehdr->e_phoff;
-        return CheckPhdr((ElfW(Addr))ehdr + offset);
+        return CheckPhdr(reinterpret_cast<ElfW(Addr)>(ehdr) + offset);
       }
       break;
     }
diff --git a/linker/linker_phdr.h b/linker/linker_phdr.h
index 65d302c..6b917b4 100644
--- a/linker/linker_phdr.h
+++ b/linker/linker_phdr.h
@@ -98,7 +98,7 @@
 
 #if defined(__arm__)
 int phdr_table_get_arm_exidx(const ElfW(Phdr)* phdr_table, size_t phdr_count, ElfW(Addr) load_bias,
-                             ElfW(Addr)** arm_exidx, unsigned* arm_exidix_count);
+                             ElfW(Addr)** arm_exidx, size_t* arm_exidix_count);
 #endif
 
 void phdr_table_get_dynamic_section(const ElfW(Phdr)* phdr_table, size_t phdr_count,