Merge "Android is all-PIC/PIE."
diff --git a/libc/Android.mk b/libc/Android.mk
index 9554e18..3b6e3cb 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -227,7 +227,6 @@
     bionic/unlink.cpp \
     bionic/utimes.cpp \
     bionic/vdso.cpp \
-    bionic/vfork.cpp \
     bionic/wait.cpp \
     bionic/wchar.cpp \
     bionic/wctype.cpp \
diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT
index 128ec6b..38ae831 100644
--- a/libc/SYSCALLS.TXT
+++ b/libc/SYSCALLS.TXT
@@ -77,6 +77,7 @@
 int     setgroups:setgroups32(int, const gid_t*)   arm,x86
 int     setgroups:setgroups(int, const gid_t*)     arm64,mips,mips64,x86_64
 int     setpgid(pid_t, pid_t)  all
+pid_t   vfork(void)  arm
 int     setregid:setregid32(gid_t, gid_t)  arm,x86
 int     setregid:setregid(gid_t, gid_t)    arm64,mips,mips64,x86_64
 int     chroot(const char*)  all
diff --git a/libc/arch-arm/syscalls/vfork.S b/libc/arch-arm/syscalls/vfork.S
new file mode 100644
index 0000000..e12fba5
--- /dev/null
+++ b/libc/arch-arm/syscalls/vfork.S
@@ -0,0 +1,14 @@
+/* Generated by gensyscalls.py. Do not edit. */
+
+#include <private/bionic_asm.h>
+
+ENTRY(vfork)
+    mov     ip, r7
+    ldr     r7, =__NR_vfork
+    swi     #0
+    mov     r7, ip
+    cmn     r0, #(MAX_ERRNO + 1)
+    bxls    lr
+    neg     r0, r0
+    b       __set_errno
+END(vfork)
diff --git a/libc/arch-arm64/arm64.mk b/libc/arch-arm64/arm64.mk
index 314358e..ed991ce 100644
--- a/libc/arch-arm64/arm64.mk
+++ b/libc/arch-arm64/arm64.mk
@@ -36,6 +36,7 @@
     arch-arm64/bionic/__set_tls.c \
     arch-arm64/bionic/sigsetjmp.S \
     arch-arm64/bionic/syscall.S \
+    arch-arm64/bionic/vfork.S \
 
 
 libc_crt_target_cflags_arm64 := \
diff --git a/libc/bionic/vfork.cpp b/libc/arch-arm64/bionic/vfork.S
similarity index 75%
rename from libc/bionic/vfork.cpp
rename to libc/arch-arm64/bionic/vfork.S
index b706a7f..c700623 100644
--- a/libc/bionic/vfork.cpp
+++ b/libc/arch-arm64/bionic/vfork.S
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 The Android Open Source Project
+ * Copyright (C) 2013 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,10 +26,23 @@
  * SUCH DAMAGE.
  */
 
-#include <unistd.h>
+#include <private/bionic_asm.h>
+#include <asm/signal.h>
+#include <linux/sched.h>
 
-// vfork(2) was removed from POSIX 2008, but it's common enough that we can't
-// actually remove it entirely.
-extern "C" pid_t vfork(void) {
-  return fork();
-}
+ENTRY(vfork)
+    mov     x0, #(CLONE_VM | CLONE_VFORK | SIGCHLD)
+    mov     x1, xzr
+    mov     x2, xzr
+    mov     x3, xzr
+    mov     x4, xzr
+
+    mov     x8, __NR_clone
+    svc     #0
+
+    cmn     x0, #(MAX_ERRNO + 1)
+    cneg    x0, x0, hi
+    b.hi    __set_errno
+
+    ret
+END(vfork)
diff --git a/libc/bionic/vfork.cpp b/libc/arch-mips/bionic/vfork.S
similarity index 72%
copy from libc/bionic/vfork.cpp
copy to libc/arch-mips/bionic/vfork.S
index b706a7f..96de69e 100644
--- a/libc/bionic/vfork.cpp
+++ b/libc/arch-mips/bionic/vfork.S
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 The Android Open Source Project
+ * Copyright (C) 2008 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,10 +26,33 @@
  * SUCH DAMAGE.
  */
 
-#include <unistd.h>
+#include <private/bionic_asm.h>
+#include <linux/sched.h>
 
-// vfork(2) was removed from POSIX 2008, but it's common enough that we can't
-// actually remove it entirely.
-extern "C" pid_t vfork(void) {
-  return fork();
-}
+// TODO: mips' uapi signal.h is missing #ifndef __ASSEMBLY__.
+// #include <asm/signal.h>
+#define SIGCHLD 18
+
+ENTRY(vfork)
+	.set	noreorder
+	.cpload	t9
+
+	li	a0, (CLONE_VM | CLONE_VFORK | SIGCHLD)
+	li	a1, 0
+	li	a2, 0
+	li	a3, 0
+	subu	sp, 8
+	sw	$0, 16(sp)
+	li	v0, __NR_clone
+	syscall
+	addu	sp, 8
+	bnez	a3, 1f
+	 move	a0, v0
+
+	j	ra
+	 nop
+1:
+	la	t9, __set_errno
+	j	t9
+	 nop
+END(vfork)
diff --git a/libc/arch-mips/mips.mk b/libc/arch-mips/mips.mk
index bf3b8ae..8e415f9 100644
--- a/libc/arch-mips/mips.mk
+++ b/libc/arch-mips/mips.mk
@@ -59,6 +59,7 @@
     arch-mips/bionic/setjmp.S \
     arch-mips/bionic/sigsetjmp.S \
     arch-mips/bionic/syscall.S \
+    arch-mips/bionic/vfork.S \
 
 ifndef ARCH_MIPS_REV6
 libc_bionic_src_files_mips += \
diff --git a/libc/bionic/vfork.cpp b/libc/arch-mips64/bionic/vfork.S
similarity index 62%
copy from libc/bionic/vfork.cpp
copy to libc/arch-mips64/bionic/vfork.S
index b706a7f..911a264 100644
--- a/libc/bionic/vfork.cpp
+++ b/libc/arch-mips64/bionic/vfork.S
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 The Android Open Source Project
+ * Copyright (C) 2008 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,10 +26,46 @@
  * SUCH DAMAGE.
  */
 
-#include <unistd.h>
+#include <private/bionic_asm.h>
+#include <linux/sched.h>
 
-// vfork(2) was removed from POSIX 2008, but it's common enough that we can't
-// actually remove it entirely.
-extern "C" pid_t vfork(void) {
-  return fork();
-}
+// TODO: mips' uapi signal.h is missing #ifndef __ASSEMBLY__.
+// #include <asm/signal.h>
+#define SIGCHLD 18
+
+	.text
+
+#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
+FRAMESZ		=	MKFSIZ(5,0)
+#else
+FRAMESZ		=	MKFSIZ(0,0)
+#endif
+
+LEAF(vfork,FRAMESZ)
+#if FRAMESZ!=0
+	PTR_SUBU sp, FRAMESZ
+#endif
+	SETUP_GP64(a5, vfork)
+	LI	a0, (CLONE_VM | CLONE_VFORK | SIGCHLD)
+	move	a1, $0
+	move	a2, $0
+	move	a3, $0
+#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
+	REG_S	$0, 4*REGSZ(sp)
+#else
+	move	a4, $0
+#endif
+	LI	v0, __NR_clone
+	syscall
+#if FRAMESZ!=0
+	PTR_ADDU sp,FRAMESZ
+#endif
+	move	a0, v0
+	bnez	a3, 1f
+	RESTORE_GP64
+	j	ra
+1:
+	LA	t9,__set_errno
+	RESTORE_GP64
+	j	t9
+	END(vfork)
diff --git a/libc/arch-mips64/mips64.mk b/libc/arch-mips64/mips64.mk
index 6f7a928..230cb26 100644
--- a/libc/arch-mips64/mips64.mk
+++ b/libc/arch-mips64/mips64.mk
@@ -46,6 +46,7 @@
     arch-mips64/bionic/setjmp.S \
     arch-mips64/bionic/sigsetjmp.S \
     arch-mips64/bionic/syscall.S \
+    arch-mips64/bionic/vfork.S \
 
 # FIXME TODO
 ## libc_bionic_src_files_mips64 += arch-mips64/string/memcpy.S
diff --git a/libc/bionic/vfork.cpp b/libc/arch-x86/bionic/vfork.S
similarity index 75%
copy from libc/bionic/vfork.cpp
copy to libc/arch-x86/bionic/vfork.S
index b706a7f..ffa6b16 100644
--- a/libc/bionic/vfork.cpp
+++ b/libc/arch-x86/bionic/vfork.S
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 The Android Open Source Project
+ * Copyright (C) 2008 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,10 +26,19 @@
  * SUCH DAMAGE.
  */
 
-#include <unistd.h>
+#include <private/bionic_asm.h>
 
-// vfork(2) was removed from POSIX 2008, but it's common enough that we can't
-// actually remove it entirely.
-extern "C" pid_t vfork(void) {
-  return fork();
-}
+// This custom code preserves the return address across the system call.
+
+ENTRY(vfork)
+  popl    %ecx  // Grab the return address.
+  movl    $__NR_vfork, %eax
+  int     $0x80
+  cmpl    $-MAX_ERRNO, %eax
+  jb      1f
+  negl    %eax
+  pushl   %eax
+  call    __set_errno
+1:
+  jmp     *%ecx  // Jump to the stored return address.
+END(vfork)
diff --git a/libc/arch-x86/x86.mk b/libc/arch-x86/x86.mk
index 8aa2645..019dc8e 100644
--- a/libc/arch-x86/x86.mk
+++ b/libc/arch-x86/x86.mk
@@ -31,6 +31,7 @@
     arch-x86/bionic/__set_tls.c \
     arch-x86/bionic/sigsetjmp.S \
     arch-x86/bionic/syscall.S \
+    arch-x86/bionic/vfork.S \
 
 ## ARCH variant specific source files
 arch_variant_mk := $(LOCAL_PATH)/arch-x86/$(TARGET_ARCH_VARIANT)/$(TARGET_ARCH_VARIANT).mk
diff --git a/libc/bionic/vfork.cpp b/libc/arch-x86_64/bionic/vfork.S
similarity index 75%
copy from libc/bionic/vfork.cpp
copy to libc/arch-x86_64/bionic/vfork.S
index b706a7f..7c14cc0 100644
--- a/libc/bionic/vfork.cpp
+++ b/libc/arch-x86_64/bionic/vfork.S
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 The Android Open Source Project
+ * Copyright (C) 2013 The Android Open Source Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,10 +26,20 @@
  * SUCH DAMAGE.
  */
 
-#include <unistd.h>
+#include <private/bionic_asm.h>
 
-// vfork(2) was removed from POSIX 2008, but it's common enough that we can't
-// actually remove it entirely.
-extern "C" pid_t vfork(void) {
-  return fork();
-}
+// This custom code preserves the return address across the system call.
+
+ENTRY(vfork)
+  popq    %rdi  // Grab the return address.
+  movl    $__NR_vfork, %eax
+  syscall
+  pushq   %rdi  // Restore the return address.
+  cmpq    $-MAX_ERRNO, %rax
+  jb      1f
+  negl    %eax
+  movl    %eax, %edi
+  call    __set_errno
+1:
+  ret
+END(vfork)
diff --git a/libc/arch-x86_64/x86_64.mk b/libc/arch-x86_64/x86_64.mk
index 234cf67..7887c51 100644
--- a/libc/arch-x86_64/x86_64.mk
+++ b/libc/arch-x86_64/x86_64.mk
@@ -37,6 +37,7 @@
     arch-x86_64/bionic/__set_tls.c \
     arch-x86_64/bionic/sigsetjmp.S \
     arch-x86_64/bionic/syscall.S \
+    arch-x86_64/bionic/vfork.S \
 
 libc_bionic_src_files_x86_64 += \
     arch-x86_64/string/sse2-memcpy-slm.S \
diff --git a/libc/bionic/ndk_cruft.cpp b/libc/bionic/ndk_cruft.cpp
index e3e640a..0c72019 100644
--- a/libc/bionic/ndk_cruft.cpp
+++ b/libc/bionic/ndk_cruft.cpp
@@ -225,6 +225,7 @@
   return syscall(__NR_tkill, tid, sig);
 }
 
+// This was removed from POSIX 2008.
 extern "C" wchar_t* wcswcs(wchar_t* haystack, wchar_t* needle) {
   return wcsstr(haystack, needle);
 }
@@ -267,7 +268,7 @@
   return r.rlim_cur;
 }
 
-// Only used by ftime, which was removed from POSIX.
+// Only used by ftime, which was removed from POSIX 2008.
 struct timeb {
   time_t          time;
   unsigned short  millitm;
diff --git a/libc/bionic/pthread_exit.cpp b/libc/bionic/pthread_exit.cpp
index a6bb363..6cd5311 100644
--- a/libc/bionic/pthread_exit.cpp
+++ b/libc/bionic/pthread_exit.cpp
@@ -112,6 +112,12 @@
   }
   pthread_mutex_unlock(&g_thread_list_lock);
 
+  // Perform a second key cleanup. When using jemalloc, a call to free from
+  // _pthread_internal_remove_locked causes the memory associated with a key
+  // to be reallocated.
+  // TODO: When b/16847284 is fixed this call can be removed.
+  pthread_key_clean_all();
+
   if (user_allocated_stack) {
     // Cleaning up this thread's stack is the creator's responsibility, not ours.
     __exit(0);
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index 9c6bd3f..74e5732 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -38,6 +38,14 @@
 #ifndef	_STDIO_H_
 #define	_STDIO_H_
 
+/*
+ * This file must contain a reference to __gnuc_va_list so that GCC's
+ * fixincludes knows that that's what's being used for va_list, and so
+ * to leave our <stdio.h> alone. (fixincludes gets in the way of pointing
+ * one toolchain at various different sets of platform headers.)
+ * If you alter this comment, be sure to keep "__gnuc_va_list" in it!
+ */
+
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index 984ceb3..a5eb3d1 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
@@ -111,12 +111,6 @@
 
 #define RAND_MAX 0x7fffffff
 
-/* Work around x86/x86-64 libvpx build breakage caused by postproc_x86.c. */
-#if (defined(__i386__) || defined(__x86_64__)) && defined(rand)
-#undef rand
-#define __rand lrand48
-#endif
-
 int rand(void);
 int rand_r(unsigned int*);
 void srand(unsigned int);
diff --git a/libc/include/string.h b/libc/include/string.h
index af1c0c1..8df68e3 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -94,9 +94,6 @@
 
 #if defined(__BIONIC_FORTIFY)
 
-__errordecl(__memcpy_dest_size_error, "memcpy: prevented write past end of buffer");
-__errordecl(__memcpy_src_size_error, "memcpy: prevented read past end of buffer");
-
 __BIONIC_FORTIFY_INLINE
 void* memcpy(void* __restrict dest, const void* __restrict src, size_t copy_amount) {
     char *d = (char *) dest;
@@ -104,14 +101,6 @@
     size_t s_len = __bos0(s);
     size_t d_len = __bos0(d);
 
-    if (__builtin_constant_p(copy_amount) && (copy_amount > d_len)) {
-        __memcpy_dest_size_error();
-    }
-
-    if (__builtin_constant_p(copy_amount) && (copy_amount > s_len)) {
-        __memcpy_src_size_error();
-    }
-
     return __builtin___memcpy_chk(dest, src, copy_amount, d_len);
 }
 
@@ -130,16 +119,12 @@
     return __builtin___strcpy_chk(dest, src, __bos(dest));
 }
 
-__errordecl(__stpncpy_error, "stpncpy: prevented write past end of buffer");
 extern char* __stpncpy_chk2(char* __restrict, const char* __restrict, size_t, size_t, size_t);
 
 __BIONIC_FORTIFY_INLINE
 char* stpncpy(char* __restrict dest, const char* __restrict src, size_t n) {
     size_t bos_dest = __bos(dest);
     size_t bos_src = __bos(src);
-    if (__builtin_constant_p(n) && (n > bos_dest)) {
-        __stpncpy_error();
-    }
 
     if (bos_src == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
         return __builtin___stpncpy_chk(dest, src, n, bos_dest);
@@ -157,16 +142,12 @@
     return __stpncpy_chk2(dest, src, n, bos_dest, bos_src);
 }
 
-__errordecl(__strncpy_error, "strncpy: prevented write past end of buffer");
 extern char* __strncpy_chk2(char* __restrict, const char* __restrict, size_t, size_t, size_t);
 
 __BIONIC_FORTIFY_INLINE
 char* strncpy(char* __restrict dest, const char* __restrict src, size_t n) {
     size_t bos_dest = __bos(dest);
     size_t bos_src = __bos(src);
-    if (__builtin_constant_p(n) && (n > bos_dest)) {
-        __strncpy_error();
-    }
 
     if (bos_src == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
         return __builtin___strncpy_chk(dest, src, n, bos_dest);
@@ -201,7 +182,6 @@
 
 extern size_t __strlcpy_real(char* __restrict, const char* __restrict, size_t)
     __asm__(__USER_LABEL_PREFIX__ "strlcpy");
-__errordecl(__strlcpy_error, "strlcpy: prevented write past end of buffer");
 extern size_t __strlcpy_chk(char *, const char *, size_t, size_t);
 
 __BIONIC_FORTIFY_INLINE
@@ -219,12 +199,6 @@
     if (__builtin_constant_p(size) && (size <= bos)) {
         return __strlcpy_real(dest, src, size);
     }
-
-    // Compiler can prove, at compile time, that the passed in size
-    // is always > the actual object size. Force a compiler error.
-    if (__builtin_constant_p(size) && (size > bos)) {
-        __strlcpy_error();
-    }
 #endif /* !defined(__clang__) */
 
     return __strlcpy_chk(dest, src, size, bos);
@@ -232,7 +206,6 @@
 
 extern size_t __strlcat_real(char* __restrict, const char* __restrict, size_t)
     __asm__(__USER_LABEL_PREFIX__ "strlcat");
-__errordecl(__strlcat_error, "strlcat: prevented write past end of buffer");
 extern size_t __strlcat_chk(char* __restrict, const char* __restrict, size_t, size_t);
 
 
@@ -251,12 +224,6 @@
     if (__builtin_constant_p(size) && (size <= bos)) {
         return __strlcat_real(dest, src, size);
     }
-
-    // Compiler can prove, at compile time, that the passed in size
-    // is always > the actual object size. Force a compiler error.
-    if (__builtin_constant_p(size) && (size > bos)) {
-        __strlcat_error();
-    }
 #endif /* !defined(__clang__) */
 
     return __strlcat_chk(dest, src, size, bos);
diff --git a/libc/tools/zoneinfo/ZoneCompactor.java b/libc/tools/zoneinfo/ZoneCompactor.java
index f47afd1..bf3153e 100644
--- a/libc/tools/zoneinfo/ZoneCompactor.java
+++ b/libc/tools/zoneinfo/ZoneCompactor.java
@@ -1,9 +1,6 @@
 
 import java.io.*;
-import java.nio.ByteOrder;
 import java.util.*;
-import libcore.io.BufferIterator;
-import libcore.util.ZoneInfo;
 
 // usage: java ZoneCompiler <setup file> <data directory> <output directory> <tzdata version>
 //
@@ -27,66 +24,20 @@
 //
 
 public class ZoneCompactor {
-  public static class ByteArrayBufferIteratorBE extends BufferIterator {
-    private final byte[] bytes;
-    private int offset = 0;
-
-    public ByteArrayBufferIteratorBE(byte[] bytes) {
-      this.bytes = bytes;
-      this.offset = 0;
-    }
-
-    public void seek(int offset) {
-      this.offset = offset;
-    }
-
-    public void skip(int byteCount) {
-      this.offset += byteCount;
-    }
-
-    public void readByteArray(byte[] dst, int dstOffset, int byteCount) {
-      System.arraycopy(bytes, offset, dst, dstOffset, byteCount);
-      offset += byteCount;
-    }
-
-    public byte readByte() {
-      return bytes[offset++];
-    }
-
-    public int readInt() {
-      return ((readByte() & 0xff) << 24) | ((readByte() & 0xff) << 16) | ((readByte() & 0xff) << 8) | (readByte() & 0xff);
-    }
-
-    public void readIntArray(int[] dst, int dstOffset, int intCount) {
-      for (int i = 0; i < intCount; ++i) {
-        dst[dstOffset++] = readInt();
-      }
-    }
-
-    public short readShort() {
-      throw new UnsupportedOperationException();
-    }
-  }
-
-  // Maximum number of characters in a zone name, including '\0' terminator
+  // Maximum number of characters in a zone name, including '\0' terminator.
   private static final int MAXNAME = 40;
 
-  // Zone name synonyms
+  // Zone name synonyms.
   private Map<String,String> links = new HashMap<String,String>();
 
-  // File starting bytes by zone name
-  private Map<String,Integer> starts = new HashMap<String,Integer>();
+  // File offsets by zone name.
+  private Map<String,Integer> offsets = new HashMap<String,Integer>();
 
-  // File lengths by zone name
+  // File lengths by zone name.
   private Map<String,Integer> lengths = new HashMap<String,Integer>();
 
-  // Raw GMT offsets by zone name
-  private Map<String,Integer> offsets = new HashMap<String,Integer>();
-  private int start = 0;
-
-  // Concatenate the contents of 'inFile' onto 'out'
-  // and return the contents as a byte array.
-  private static byte[] copyFile(File inFile, OutputStream out) throws Exception {
+  // Concatenate the contents of 'inFile' onto 'out'.
+  private static void copyFile(File inFile, OutputStream out) throws Exception {
     byte[] ret = new byte[0];
 
     InputStream in = new FileInputStream(inFile);
@@ -104,14 +55,14 @@
       ret = nret;
     }
     out.flush();
-    return ret;
   }
 
   public ZoneCompactor(String setupFile, String dataDirectory, String zoneTabFile, String outputDirectory, String version) throws Exception {
-    // Read the setup file, and concatenate all the data.
+    // Read the setup file and concatenate all the data.
     ByteArrayOutputStream allData = new ByteArrayOutputStream();
     BufferedReader reader = new BufferedReader(new FileReader(setupFile));
     String s;
+    int offset = 0;
     while ((s = reader.readLine()) != null) {
       s = s.trim();
       if (s.startsWith("Link")) {
@@ -125,16 +76,11 @@
         if (link == null) {
           File sourceFile = new File(dataDirectory, s);
           long length = sourceFile.length();
-          starts.put(s, start);
+          offsets.put(s, offset);
           lengths.put(s, (int) length);
 
-          start += length;
-          byte[] data = copyFile(sourceFile, allData);
-
-          BufferIterator it = new ByteArrayBufferIteratorBE(data);
-          TimeZone tz = ZoneInfo.makeTimeZone(s, it);
-          int gmtOffset = tz.getRawOffset();
-          offsets.put(s, gmtOffset);
+          offset += length;
+          copyFile(sourceFile, allData);
         }
       }
     }
@@ -146,9 +92,8 @@
       String from = it.next();
       String to = links.get(from);
 
-      starts.put(from, starts.get(to));
-      lengths.put(from, lengths.get(to));
       offsets.put(from, offsets.get(to));
+      lengths.put(from, lengths.get(to));
     }
 
     // Create/truncate the destination file.
@@ -178,7 +123,7 @@
 
     // Write the index.
     ArrayList<String> sortedOlsonIds = new ArrayList<String>();
-    sortedOlsonIds.addAll(starts.keySet());
+    sortedOlsonIds.addAll(offsets.keySet());
     Collections.sort(sortedOlsonIds);
     it = sortedOlsonIds.iterator();
     while (it.hasNext()) {
@@ -188,9 +133,9 @@
       }
 
       f.write(toAscii(new byte[MAXNAME], zoneName));
-      f.writeInt(starts.get(zoneName));
-      f.writeInt(lengths.get(zoneName));
       f.writeInt(offsets.get(zoneName));
+      f.writeInt(lengths.get(zoneName));
+      f.writeInt(0); // Used to be raw GMT offset. No longer used.
     }
 
     int data_offset = (int) f.getFilePointer();
diff --git a/libc/tools/zoneinfo/update-tzdata.py b/libc/tools/zoneinfo/update-tzdata.py
index 6b69a5a..e800e8f 100755
--- a/libc/tools/zoneinfo/update-tzdata.py
+++ b/libc/tools/zoneinfo/update-tzdata.py
@@ -115,7 +115,7 @@
   print 'Configuring ICU tools...'
   subprocess.check_call(['%s/runConfigureICU' % icu_dir, 'Linux'])
   print 'Making ICU tools...'
-  subprocess.check_call(['make', '-j6'])
+  subprocess.check_call(['make', '-j32'])
 
   # Run the ICU tools.
   os.chdir('tools/tzcode')
@@ -169,11 +169,8 @@
   WriteSetupFile()
 
   print 'Calling ZoneCompactor to update bionic to %s...' % new_version
-  libcore_src_dir = '%s/../libcore/luni/src/main/java/' % bionic_dir
   subprocess.check_call(['javac', '-d', '.',
-                         '%s/ZoneCompactor.java' % bionic_libc_tools_zoneinfo_dir,
-                         '%s/libcore/util/ZoneInfo.java' % libcore_src_dir,
-                         '%s/libcore/io/BufferIterator.java' % libcore_src_dir])
+                         '%s/ZoneCompactor.java' % bionic_libc_tools_zoneinfo_dir])
   subprocess.check_call(['java', 'ZoneCompactor',
                          'setup', 'data', 'extracted/zone.tab',
                          bionic_libc_zoneinfo_dir, new_version])
diff --git a/libc/tzcode/localtime.c b/libc/tzcode/localtime.c
index 5e4e962..3bbed90 100644
--- a/libc/tzcode/localtime.c
+++ b/libc/tzcode/localtime.c
@@ -2210,7 +2210,7 @@
     char buf[NAME_LENGTH];
     int32_t start;
     int32_t length;
-    int32_t raw_gmt_offset;
+    int32_t unused; // Was raw GMT offset; always 0 since tzdata2014f (L).
   };
 
   size_t id_count = (ntohl(header.data_offset) - ntohl(header.index_offset)) / sizeof(struct index_entry_t);
diff --git a/libc/zoneinfo/tzdata b/libc/zoneinfo/tzdata
index a5ae1f6..9547f58 100644
--- a/libc/zoneinfo/tzdata
+++ b/libc/zoneinfo/tzdata
Binary files differ
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index 4da003f..5328e48 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -400,27 +400,36 @@
 }
 
 TEST(pthread, pthread_detach__leak) {
-  size_t initial_bytes = mallinfo().uordblks;
+  size_t initial_bytes = 0;
+  // Run this loop more than once since the first loop causes some memory
+  // to be allocated permenantly. Run an extra loop to help catch any subtle
+  // memory leaks.
+  for (size_t loop = 0; loop < 3; loop++) {
+    // Set the initial bytes on the second loop since the memory in use
+    // should have stabilized.
+    if (loop == 1) {
+      initial_bytes = mallinfo().uordblks;
+    }
 
-  pthread_attr_t attr;
-  ASSERT_EQ(0, pthread_attr_init(&attr));
-  ASSERT_EQ(0, pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE));
+    pthread_attr_t attr;
+    ASSERT_EQ(0, pthread_attr_init(&attr));
+    ASSERT_EQ(0, pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE));
 
-  std::vector<pthread_t> threads;
-  for (size_t i = 0; i < 32; ++i) {
-    pthread_t t;
-    ASSERT_EQ(0, pthread_create(&t, &attr, IdFn, NULL));
-    threads.push_back(t);
-  }
+    std::vector<pthread_t> threads;
+    for (size_t i = 0; i < 32; ++i) {
+      pthread_t t;
+      ASSERT_EQ(0, pthread_create(&t, &attr, IdFn, NULL));
+      threads.push_back(t);
+    }
 
-  sleep(1);
+    sleep(1);
 
-  for (size_t i = 0; i < 32; ++i) {
-    ASSERT_EQ(0, pthread_detach(threads[i])) << i;
+    for (size_t i = 0; i < 32; ++i) {
+      ASSERT_EQ(0, pthread_detach(threads[i])) << i;
+    }
   }
 
   size_t final_bytes = mallinfo().uordblks;
-
   int leaked_bytes = (final_bytes - initial_bytes);
 
   // User code (like this test) doesn't know how large pthread_internal_t is.