Merge "Update timezone data to 2016d"
diff --git a/benchmarks/property_benchmark.cpp b/benchmarks/property_benchmark.cpp
index 2f72d60..4e82117 100644
--- a/benchmarks/property_benchmark.cpp
+++ b/benchmarks/property_benchmark.cpp
@@ -36,7 +36,7 @@
     Arg(1)->Arg(4)->Arg(16)->Arg(64)->Arg(128)->Arg(256)->Arg(512)
 
 struct LocalPropertyTestState {
-  LocalPropertyTestState(int nprops) : nprops(nprops), valid(false) {
+  explicit LocalPropertyTestState(int nprops) : nprops(nprops), valid(false) {
     static const char prop_name_chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_.";
 
     const char* android_data = getenv("ANDROID_DATA");
diff --git a/libc/Android.bp b/libc/Android.bp
index c5a513c..9c521d1 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -195,7 +195,6 @@
     cflags: [
         "-DANDROID_CHANGES",
         "-DINET6",
-        "-fvisibility=hidden",
         "-Wno-unused-parameter",
         "-include netbsd-compat.h",
     ],
diff --git a/libc/Android.mk b/libc/Android.mk
index 02682af..a8581ac 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -133,6 +133,7 @@
     bionic/lockf.cpp \
     bionic/lstat.cpp \
     bionic/malloc_info.cpp \
+    bionic/mblen.cpp \
     bionic/mbrtoc16.cpp \
     bionic/mbrtoc32.cpp \
     bionic/mbstate.cpp \
@@ -589,11 +590,6 @@
 
 use_clang := true
 
-# b/25291096, Clang/llvm compiled libc.so for mips/mips64 failed to boot.
-ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),mips mips64))
-  use_clang := false
-endif
-
 # Try to catch typical 32-bit assumptions that break with 64-bit pointers.
 libc_common_cflags += \
     -Werror=pointer-to-int-cast \
@@ -755,7 +751,6 @@
     $(libc_common_cflags) \
     -DANDROID_CHANGES \
     -DINET6 \
-    -fvisibility=hidden \
     -Wno-unused-parameter \
     -include netbsd-compat.h \
 
diff --git a/libc/arch-arm/syscalls/___clock_nanosleep.S b/libc/arch-arm/syscalls/___clock_nanosleep.S
index 31420bb..ef8f065 100644
--- a/libc/arch-arm/syscalls/___clock_nanosleep.S
+++ b/libc/arch-arm/syscalls/___clock_nanosleep.S
@@ -4,9 +4,11 @@
 
 ENTRY(___clock_nanosleep)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_clock_nanosleep
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/___close.S b/libc/arch-arm/syscalls/___close.S
index db8a230..05d3352 100644
--- a/libc/arch-arm/syscalls/___close.S
+++ b/libc/arch-arm/syscalls/___close.S
@@ -4,9 +4,11 @@
 
 ENTRY(___close)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_close
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/___faccessat.S b/libc/arch-arm/syscalls/___faccessat.S
index 1d09cf7..8bb4cf8 100644
--- a/libc/arch-arm/syscalls/___faccessat.S
+++ b/libc/arch-arm/syscalls/___faccessat.S
@@ -4,9 +4,11 @@
 
 ENTRY(___faccessat)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_faccessat
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/___fchmod.S b/libc/arch-arm/syscalls/___fchmod.S
index c6da4f8..b2312cb 100644
--- a/libc/arch-arm/syscalls/___fchmod.S
+++ b/libc/arch-arm/syscalls/___fchmod.S
@@ -4,9 +4,11 @@
 
 ENTRY(___fchmod)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_fchmod
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/___fchmodat.S b/libc/arch-arm/syscalls/___fchmodat.S
index 91bbda5..4773610 100644
--- a/libc/arch-arm/syscalls/___fchmodat.S
+++ b/libc/arch-arm/syscalls/___fchmodat.S
@@ -4,9 +4,11 @@
 
 ENTRY(___fchmodat)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_fchmodat
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/___fgetxattr.S b/libc/arch-arm/syscalls/___fgetxattr.S
index e776cd6..25be039 100644
--- a/libc/arch-arm/syscalls/___fgetxattr.S
+++ b/libc/arch-arm/syscalls/___fgetxattr.S
@@ -4,9 +4,11 @@
 
 ENTRY(___fgetxattr)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_fgetxattr
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/___flistxattr.S b/libc/arch-arm/syscalls/___flistxattr.S
index 8ae8b7e..904e4ca 100644
--- a/libc/arch-arm/syscalls/___flistxattr.S
+++ b/libc/arch-arm/syscalls/___flistxattr.S
@@ -4,9 +4,11 @@
 
 ENTRY(___flistxattr)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_flistxattr
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/___rt_sigqueueinfo.S b/libc/arch-arm/syscalls/___rt_sigqueueinfo.S
index 25b0d57..1367e56 100644
--- a/libc/arch-arm/syscalls/___rt_sigqueueinfo.S
+++ b/libc/arch-arm/syscalls/___rt_sigqueueinfo.S
@@ -4,9 +4,11 @@
 
 ENTRY(___rt_sigqueueinfo)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_rt_sigqueueinfo
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__accept4.S b/libc/arch-arm/syscalls/__accept4.S
index dca5699..42aa47c 100644
--- a/libc/arch-arm/syscalls/__accept4.S
+++ b/libc/arch-arm/syscalls/__accept4.S
@@ -4,9 +4,11 @@
 
 ENTRY(__accept4)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_accept4
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__brk.S b/libc/arch-arm/syscalls/__brk.S
index be304da..246924c 100644
--- a/libc/arch-arm/syscalls/__brk.S
+++ b/libc/arch-arm/syscalls/__brk.S
@@ -4,9 +4,11 @@
 
 ENTRY(__brk)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_brk
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__connect.S b/libc/arch-arm/syscalls/__connect.S
index a2a997e..873b14d 100644
--- a/libc/arch-arm/syscalls/__connect.S
+++ b/libc/arch-arm/syscalls/__connect.S
@@ -4,9 +4,11 @@
 
 ENTRY(__connect)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_connect
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__exit.S b/libc/arch-arm/syscalls/__exit.S
index 6ebd5b3..4ed31b0 100644
--- a/libc/arch-arm/syscalls/__exit.S
+++ b/libc/arch-arm/syscalls/__exit.S
@@ -4,9 +4,11 @@
 
 ENTRY(__exit)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_exit
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__fcntl64.S b/libc/arch-arm/syscalls/__fcntl64.S
index 229c5c6..0afdbee 100644
--- a/libc/arch-arm/syscalls/__fcntl64.S
+++ b/libc/arch-arm/syscalls/__fcntl64.S
@@ -4,9 +4,11 @@
 
 ENTRY(__fcntl64)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_fcntl64
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__fstatfs64.S b/libc/arch-arm/syscalls/__fstatfs64.S
index 9c0c439..9117313 100644
--- a/libc/arch-arm/syscalls/__fstatfs64.S
+++ b/libc/arch-arm/syscalls/__fstatfs64.S
@@ -4,9 +4,11 @@
 
 ENTRY(__fstatfs64)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_fstatfs64
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__getcpu.S b/libc/arch-arm/syscalls/__getcpu.S
index d523d8e..430acb3 100644
--- a/libc/arch-arm/syscalls/__getcpu.S
+++ b/libc/arch-arm/syscalls/__getcpu.S
@@ -4,9 +4,11 @@
 
 ENTRY(__getcpu)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_getcpu
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__getcwd.S b/libc/arch-arm/syscalls/__getcwd.S
index 4ff6667..53000b8 100644
--- a/libc/arch-arm/syscalls/__getcwd.S
+++ b/libc/arch-arm/syscalls/__getcwd.S
@@ -4,9 +4,11 @@
 
 ENTRY(__getcwd)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_getcwd
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__getdents64.S b/libc/arch-arm/syscalls/__getdents64.S
index dac3bfc..0ea61b8 100644
--- a/libc/arch-arm/syscalls/__getdents64.S
+++ b/libc/arch-arm/syscalls/__getdents64.S
@@ -4,9 +4,11 @@
 
 ENTRY(__getdents64)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_getdents64
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__getpid.S b/libc/arch-arm/syscalls/__getpid.S
index dbb192e..b555385 100644
--- a/libc/arch-arm/syscalls/__getpid.S
+++ b/libc/arch-arm/syscalls/__getpid.S
@@ -4,9 +4,11 @@
 
 ENTRY(__getpid)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_getpid
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__getpriority.S b/libc/arch-arm/syscalls/__getpriority.S
index e637d6f..34f4bea 100644
--- a/libc/arch-arm/syscalls/__getpriority.S
+++ b/libc/arch-arm/syscalls/__getpriority.S
@@ -4,9 +4,11 @@
 
 ENTRY(__getpriority)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_getpriority
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__ioctl.S b/libc/arch-arm/syscalls/__ioctl.S
index fcd1157..5871e58 100644
--- a/libc/arch-arm/syscalls/__ioctl.S
+++ b/libc/arch-arm/syscalls/__ioctl.S
@@ -4,9 +4,11 @@
 
 ENTRY(__ioctl)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_ioctl
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__openat.S b/libc/arch-arm/syscalls/__openat.S
index 9b774db..403d9b5 100644
--- a/libc/arch-arm/syscalls/__openat.S
+++ b/libc/arch-arm/syscalls/__openat.S
@@ -4,9 +4,11 @@
 
 ENTRY(__openat)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_openat
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__ptrace.S b/libc/arch-arm/syscalls/__ptrace.S
index 975ab0f..8ad554d 100644
--- a/libc/arch-arm/syscalls/__ptrace.S
+++ b/libc/arch-arm/syscalls/__ptrace.S
@@ -4,9 +4,11 @@
 
 ENTRY(__ptrace)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_ptrace
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__reboot.S b/libc/arch-arm/syscalls/__reboot.S
index 03f8c89..15ca814 100644
--- a/libc/arch-arm/syscalls/__reboot.S
+++ b/libc/arch-arm/syscalls/__reboot.S
@@ -4,9 +4,11 @@
 
 ENTRY(__reboot)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_reboot
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__rt_sigaction.S b/libc/arch-arm/syscalls/__rt_sigaction.S
index 2c21012..21d9977 100644
--- a/libc/arch-arm/syscalls/__rt_sigaction.S
+++ b/libc/arch-arm/syscalls/__rt_sigaction.S
@@ -4,9 +4,11 @@
 
 ENTRY(__rt_sigaction)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_rt_sigaction
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__rt_sigpending.S b/libc/arch-arm/syscalls/__rt_sigpending.S
index 6a32e50..b726b85 100644
--- a/libc/arch-arm/syscalls/__rt_sigpending.S
+++ b/libc/arch-arm/syscalls/__rt_sigpending.S
@@ -4,9 +4,11 @@
 
 ENTRY(__rt_sigpending)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_rt_sigpending
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__rt_sigprocmask.S b/libc/arch-arm/syscalls/__rt_sigprocmask.S
index 136dc79..11b326f 100644
--- a/libc/arch-arm/syscalls/__rt_sigprocmask.S
+++ b/libc/arch-arm/syscalls/__rt_sigprocmask.S
@@ -4,9 +4,11 @@
 
 ENTRY(__rt_sigprocmask)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_rt_sigprocmask
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__rt_sigsuspend.S b/libc/arch-arm/syscalls/__rt_sigsuspend.S
index 2cef4a4..5d06418 100644
--- a/libc/arch-arm/syscalls/__rt_sigsuspend.S
+++ b/libc/arch-arm/syscalls/__rt_sigsuspend.S
@@ -4,9 +4,11 @@
 
 ENTRY(__rt_sigsuspend)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_rt_sigsuspend
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__rt_sigtimedwait.S b/libc/arch-arm/syscalls/__rt_sigtimedwait.S
index cb43ad1..dc7c3e7 100644
--- a/libc/arch-arm/syscalls/__rt_sigtimedwait.S
+++ b/libc/arch-arm/syscalls/__rt_sigtimedwait.S
@@ -4,9 +4,11 @@
 
 ENTRY(__rt_sigtimedwait)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_rt_sigtimedwait
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__sched_getaffinity.S b/libc/arch-arm/syscalls/__sched_getaffinity.S
index 6613ea5..21f8330 100644
--- a/libc/arch-arm/syscalls/__sched_getaffinity.S
+++ b/libc/arch-arm/syscalls/__sched_getaffinity.S
@@ -4,9 +4,11 @@
 
 ENTRY(__sched_getaffinity)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_sched_getaffinity
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__set_tid_address.S b/libc/arch-arm/syscalls/__set_tid_address.S
index d3558f5..79dfd7f 100644
--- a/libc/arch-arm/syscalls/__set_tid_address.S
+++ b/libc/arch-arm/syscalls/__set_tid_address.S
@@ -4,9 +4,11 @@
 
 ENTRY(__set_tid_address)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_set_tid_address
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__set_tls.S b/libc/arch-arm/syscalls/__set_tls.S
index 4d5d963..a9a4b9a 100644
--- a/libc/arch-arm/syscalls/__set_tls.S
+++ b/libc/arch-arm/syscalls/__set_tls.S
@@ -4,9 +4,11 @@
 
 ENTRY(__set_tls)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__ARM_NR_set_tls
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__sigaction.S b/libc/arch-arm/syscalls/__sigaction.S
index 600593d..8f3f143 100644
--- a/libc/arch-arm/syscalls/__sigaction.S
+++ b/libc/arch-arm/syscalls/__sigaction.S
@@ -4,9 +4,11 @@
 
 ENTRY(__sigaction)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_sigaction
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__signalfd4.S b/libc/arch-arm/syscalls/__signalfd4.S
index 630a71f..51a27c8 100644
--- a/libc/arch-arm/syscalls/__signalfd4.S
+++ b/libc/arch-arm/syscalls/__signalfd4.S
@@ -4,9 +4,11 @@
 
 ENTRY(__signalfd4)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_signalfd4
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__socket.S b/libc/arch-arm/syscalls/__socket.S
index fffe0cc..c50cd6f 100644
--- a/libc/arch-arm/syscalls/__socket.S
+++ b/libc/arch-arm/syscalls/__socket.S
@@ -4,9 +4,11 @@
 
 ENTRY(__socket)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_socket
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__statfs64.S b/libc/arch-arm/syscalls/__statfs64.S
index ec43218..320b0ee 100644
--- a/libc/arch-arm/syscalls/__statfs64.S
+++ b/libc/arch-arm/syscalls/__statfs64.S
@@ -4,9 +4,11 @@
 
 ENTRY(__statfs64)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_statfs64
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__timer_create.S b/libc/arch-arm/syscalls/__timer_create.S
index 2e4c634..fd7567b 100644
--- a/libc/arch-arm/syscalls/__timer_create.S
+++ b/libc/arch-arm/syscalls/__timer_create.S
@@ -4,9 +4,11 @@
 
 ENTRY(__timer_create)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_timer_create
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__timer_delete.S b/libc/arch-arm/syscalls/__timer_delete.S
index 237024c..6761abb 100644
--- a/libc/arch-arm/syscalls/__timer_delete.S
+++ b/libc/arch-arm/syscalls/__timer_delete.S
@@ -4,9 +4,11 @@
 
 ENTRY(__timer_delete)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_timer_delete
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__timer_getoverrun.S b/libc/arch-arm/syscalls/__timer_getoverrun.S
index f29d5b3..a925d83 100644
--- a/libc/arch-arm/syscalls/__timer_getoverrun.S
+++ b/libc/arch-arm/syscalls/__timer_getoverrun.S
@@ -4,9 +4,11 @@
 
 ENTRY(__timer_getoverrun)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_timer_getoverrun
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__timer_gettime.S b/libc/arch-arm/syscalls/__timer_gettime.S
index e6dc2ed..c0da770 100644
--- a/libc/arch-arm/syscalls/__timer_gettime.S
+++ b/libc/arch-arm/syscalls/__timer_gettime.S
@@ -4,9 +4,11 @@
 
 ENTRY(__timer_gettime)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_timer_gettime
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/__timer_settime.S b/libc/arch-arm/syscalls/__timer_settime.S
index 4aea279..de4e7e6 100644
--- a/libc/arch-arm/syscalls/__timer_settime.S
+++ b/libc/arch-arm/syscalls/__timer_settime.S
@@ -4,9 +4,11 @@
 
 ENTRY(__timer_settime)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_timer_settime
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/_exit.S b/libc/arch-arm/syscalls/_exit.S
index 77da743..1c3d174 100644
--- a/libc/arch-arm/syscalls/_exit.S
+++ b/libc/arch-arm/syscalls/_exit.S
@@ -4,9 +4,11 @@
 
 ENTRY(_exit)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_exit_group
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/acct.S b/libc/arch-arm/syscalls/acct.S
index dbc5d58..cdf1099 100644
--- a/libc/arch-arm/syscalls/acct.S
+++ b/libc/arch-arm/syscalls/acct.S
@@ -4,9 +4,11 @@
 
 ENTRY(acct)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_acct
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/adjtimex.S b/libc/arch-arm/syscalls/adjtimex.S
index 614036e..6ebae7e 100644
--- a/libc/arch-arm/syscalls/adjtimex.S
+++ b/libc/arch-arm/syscalls/adjtimex.S
@@ -4,9 +4,11 @@
 
 ENTRY(adjtimex)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_adjtimex
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/bind.S b/libc/arch-arm/syscalls/bind.S
index c901417..af518d8 100644
--- a/libc/arch-arm/syscalls/bind.S
+++ b/libc/arch-arm/syscalls/bind.S
@@ -4,9 +4,11 @@
 
 ENTRY(bind)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_bind
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/cacheflush.S b/libc/arch-arm/syscalls/cacheflush.S
index 76f4623..752749a 100644
--- a/libc/arch-arm/syscalls/cacheflush.S
+++ b/libc/arch-arm/syscalls/cacheflush.S
@@ -4,9 +4,11 @@
 
 ENTRY(cacheflush)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__ARM_NR_cacheflush
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/capget.S b/libc/arch-arm/syscalls/capget.S
index 59a5a3c..9be110b 100644
--- a/libc/arch-arm/syscalls/capget.S
+++ b/libc/arch-arm/syscalls/capget.S
@@ -4,9 +4,11 @@
 
 ENTRY(capget)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_capget
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/capset.S b/libc/arch-arm/syscalls/capset.S
index af284ab..0bd5009 100644
--- a/libc/arch-arm/syscalls/capset.S
+++ b/libc/arch-arm/syscalls/capset.S
@@ -4,9 +4,11 @@
 
 ENTRY(capset)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_capset
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/chdir.S b/libc/arch-arm/syscalls/chdir.S
index 25f27ba..c75f5e2 100644
--- a/libc/arch-arm/syscalls/chdir.S
+++ b/libc/arch-arm/syscalls/chdir.S
@@ -4,9 +4,11 @@
 
 ENTRY(chdir)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_chdir
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/chroot.S b/libc/arch-arm/syscalls/chroot.S
index 6f829a6..d197d42 100644
--- a/libc/arch-arm/syscalls/chroot.S
+++ b/libc/arch-arm/syscalls/chroot.S
@@ -4,9 +4,11 @@
 
 ENTRY(chroot)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_chroot
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/clock_adjtime.S b/libc/arch-arm/syscalls/clock_adjtime.S
index fa778e1..e59a240 100644
--- a/libc/arch-arm/syscalls/clock_adjtime.S
+++ b/libc/arch-arm/syscalls/clock_adjtime.S
@@ -4,9 +4,11 @@
 
 ENTRY(clock_adjtime)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_clock_adjtime
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/clock_getres.S b/libc/arch-arm/syscalls/clock_getres.S
index 48fa07c..e101127 100644
--- a/libc/arch-arm/syscalls/clock_getres.S
+++ b/libc/arch-arm/syscalls/clock_getres.S
@@ -4,9 +4,11 @@
 
 ENTRY(clock_getres)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_clock_getres
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/clock_gettime.S b/libc/arch-arm/syscalls/clock_gettime.S
index 317481d..61a95dd 100644
--- a/libc/arch-arm/syscalls/clock_gettime.S
+++ b/libc/arch-arm/syscalls/clock_gettime.S
@@ -4,9 +4,11 @@
 
 ENTRY(clock_gettime)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_clock_gettime
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/clock_settime.S b/libc/arch-arm/syscalls/clock_settime.S
index bf54702..f00a072 100644
--- a/libc/arch-arm/syscalls/clock_settime.S
+++ b/libc/arch-arm/syscalls/clock_settime.S
@@ -4,9 +4,11 @@
 
 ENTRY(clock_settime)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_clock_settime
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/delete_module.S b/libc/arch-arm/syscalls/delete_module.S
index 57580c9..80dd0f5 100644
--- a/libc/arch-arm/syscalls/delete_module.S
+++ b/libc/arch-arm/syscalls/delete_module.S
@@ -4,9 +4,11 @@
 
 ENTRY(delete_module)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_delete_module
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/dup.S b/libc/arch-arm/syscalls/dup.S
index 2cd69d7..0d06bdc 100644
--- a/libc/arch-arm/syscalls/dup.S
+++ b/libc/arch-arm/syscalls/dup.S
@@ -4,9 +4,11 @@
 
 ENTRY(dup)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_dup
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/dup3.S b/libc/arch-arm/syscalls/dup3.S
index 4613d63..7dea858 100644
--- a/libc/arch-arm/syscalls/dup3.S
+++ b/libc/arch-arm/syscalls/dup3.S
@@ -4,9 +4,11 @@
 
 ENTRY(dup3)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_dup3
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/epoll_create1.S b/libc/arch-arm/syscalls/epoll_create1.S
index 108c24f..8b413d9 100644
--- a/libc/arch-arm/syscalls/epoll_create1.S
+++ b/libc/arch-arm/syscalls/epoll_create1.S
@@ -4,9 +4,11 @@
 
 ENTRY(epoll_create1)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_epoll_create1
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/epoll_ctl.S b/libc/arch-arm/syscalls/epoll_ctl.S
index 473af6a..807dd69 100644
--- a/libc/arch-arm/syscalls/epoll_ctl.S
+++ b/libc/arch-arm/syscalls/epoll_ctl.S
@@ -4,9 +4,11 @@
 
 ENTRY(epoll_ctl)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_epoll_ctl
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/eventfd.S b/libc/arch-arm/syscalls/eventfd.S
index ca6bcee..51f4a49 100644
--- a/libc/arch-arm/syscalls/eventfd.S
+++ b/libc/arch-arm/syscalls/eventfd.S
@@ -4,9 +4,11 @@
 
 ENTRY(eventfd)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_eventfd2
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/execve.S b/libc/arch-arm/syscalls/execve.S
index 3eca810..1b72f0e 100644
--- a/libc/arch-arm/syscalls/execve.S
+++ b/libc/arch-arm/syscalls/execve.S
@@ -4,9 +4,11 @@
 
 ENTRY(execve)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_execve
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/fchdir.S b/libc/arch-arm/syscalls/fchdir.S
index 705ad32..dca18c4 100644
--- a/libc/arch-arm/syscalls/fchdir.S
+++ b/libc/arch-arm/syscalls/fchdir.S
@@ -4,9 +4,11 @@
 
 ENTRY(fchdir)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_fchdir
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/fchown.S b/libc/arch-arm/syscalls/fchown.S
index 45ad9bf..51ee60c 100644
--- a/libc/arch-arm/syscalls/fchown.S
+++ b/libc/arch-arm/syscalls/fchown.S
@@ -4,9 +4,11 @@
 
 ENTRY(fchown)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_fchown32
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/fdatasync.S b/libc/arch-arm/syscalls/fdatasync.S
index 7fefd22..f97adc6 100644
--- a/libc/arch-arm/syscalls/fdatasync.S
+++ b/libc/arch-arm/syscalls/fdatasync.S
@@ -4,9 +4,11 @@
 
 ENTRY(fdatasync)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_fdatasync
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/flock.S b/libc/arch-arm/syscalls/flock.S
index c946fe9..e2874f6 100644
--- a/libc/arch-arm/syscalls/flock.S
+++ b/libc/arch-arm/syscalls/flock.S
@@ -4,9 +4,11 @@
 
 ENTRY(flock)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_flock
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/fremovexattr.S b/libc/arch-arm/syscalls/fremovexattr.S
index f4e950b..89be704 100644
--- a/libc/arch-arm/syscalls/fremovexattr.S
+++ b/libc/arch-arm/syscalls/fremovexattr.S
@@ -4,9 +4,11 @@
 
 ENTRY(fremovexattr)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_fremovexattr
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/fstat64.S b/libc/arch-arm/syscalls/fstat64.S
index 798bba7..c2c7101 100644
--- a/libc/arch-arm/syscalls/fstat64.S
+++ b/libc/arch-arm/syscalls/fstat64.S
@@ -4,9 +4,11 @@
 
 ENTRY(fstat64)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_fstat64
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/fstatat64.S b/libc/arch-arm/syscalls/fstatat64.S
index 03e0052..545dc16 100644
--- a/libc/arch-arm/syscalls/fstatat64.S
+++ b/libc/arch-arm/syscalls/fstatat64.S
@@ -4,9 +4,11 @@
 
 ENTRY(fstatat64)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_fstatat64
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/fsync.S b/libc/arch-arm/syscalls/fsync.S
index 1dfff05..24b9a87 100644
--- a/libc/arch-arm/syscalls/fsync.S
+++ b/libc/arch-arm/syscalls/fsync.S
@@ -4,9 +4,11 @@
 
 ENTRY(fsync)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_fsync
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/ftruncate64.S b/libc/arch-arm/syscalls/ftruncate64.S
index ac0caa8..ee1a2a6 100644
--- a/libc/arch-arm/syscalls/ftruncate64.S
+++ b/libc/arch-arm/syscalls/ftruncate64.S
@@ -4,9 +4,11 @@
 
 ENTRY(ftruncate64)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_ftruncate64
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/getegid.S b/libc/arch-arm/syscalls/getegid.S
index afa9cc8..f4e17b5 100644
--- a/libc/arch-arm/syscalls/getegid.S
+++ b/libc/arch-arm/syscalls/getegid.S
@@ -4,9 +4,11 @@
 
 ENTRY(getegid)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_getegid32
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/geteuid.S b/libc/arch-arm/syscalls/geteuid.S
index 10c8a25..01898f8 100644
--- a/libc/arch-arm/syscalls/geteuid.S
+++ b/libc/arch-arm/syscalls/geteuid.S
@@ -4,9 +4,11 @@
 
 ENTRY(geteuid)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_geteuid32
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/getgid.S b/libc/arch-arm/syscalls/getgid.S
index 8772762..ee124a6 100644
--- a/libc/arch-arm/syscalls/getgid.S
+++ b/libc/arch-arm/syscalls/getgid.S
@@ -4,9 +4,11 @@
 
 ENTRY(getgid)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_getgid32
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/getgroups.S b/libc/arch-arm/syscalls/getgroups.S
index 366299b..4c1bfdb 100644
--- a/libc/arch-arm/syscalls/getgroups.S
+++ b/libc/arch-arm/syscalls/getgroups.S
@@ -4,9 +4,11 @@
 
 ENTRY(getgroups)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_getgroups32
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/getitimer.S b/libc/arch-arm/syscalls/getitimer.S
index 80fb0f2..b9773ad 100644
--- a/libc/arch-arm/syscalls/getitimer.S
+++ b/libc/arch-arm/syscalls/getitimer.S
@@ -4,9 +4,11 @@
 
 ENTRY(getitimer)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_getitimer
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/getpeername.S b/libc/arch-arm/syscalls/getpeername.S
index 25f0026..6bf6002 100644
--- a/libc/arch-arm/syscalls/getpeername.S
+++ b/libc/arch-arm/syscalls/getpeername.S
@@ -4,9 +4,11 @@
 
 ENTRY(getpeername)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_getpeername
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/getpgid.S b/libc/arch-arm/syscalls/getpgid.S
index 36c4c19..d5c9c8a 100644
--- a/libc/arch-arm/syscalls/getpgid.S
+++ b/libc/arch-arm/syscalls/getpgid.S
@@ -4,9 +4,11 @@
 
 ENTRY(getpgid)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_getpgid
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/getppid.S b/libc/arch-arm/syscalls/getppid.S
index 606b2e0..91db24e 100644
--- a/libc/arch-arm/syscalls/getppid.S
+++ b/libc/arch-arm/syscalls/getppid.S
@@ -4,9 +4,11 @@
 
 ENTRY(getppid)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_getppid
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/getresgid.S b/libc/arch-arm/syscalls/getresgid.S
index a5e4689..8fb7f28 100644
--- a/libc/arch-arm/syscalls/getresgid.S
+++ b/libc/arch-arm/syscalls/getresgid.S
@@ -4,9 +4,11 @@
 
 ENTRY(getresgid)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_getresgid32
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/getresuid.S b/libc/arch-arm/syscalls/getresuid.S
index 74c26a7..ebec6e1 100644
--- a/libc/arch-arm/syscalls/getresuid.S
+++ b/libc/arch-arm/syscalls/getresuid.S
@@ -4,9 +4,11 @@
 
 ENTRY(getresuid)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_getresuid32
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/getrlimit.S b/libc/arch-arm/syscalls/getrlimit.S
index 166da63..0c9e662 100644
--- a/libc/arch-arm/syscalls/getrlimit.S
+++ b/libc/arch-arm/syscalls/getrlimit.S
@@ -4,9 +4,11 @@
 
 ENTRY(getrlimit)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_ugetrlimit
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/getrusage.S b/libc/arch-arm/syscalls/getrusage.S
index 93979c6..e74a4ad 100644
--- a/libc/arch-arm/syscalls/getrusage.S
+++ b/libc/arch-arm/syscalls/getrusage.S
@@ -4,9 +4,11 @@
 
 ENTRY(getrusage)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_getrusage
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/getsid.S b/libc/arch-arm/syscalls/getsid.S
index 87d38fb..c918820 100644
--- a/libc/arch-arm/syscalls/getsid.S
+++ b/libc/arch-arm/syscalls/getsid.S
@@ -4,9 +4,11 @@
 
 ENTRY(getsid)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_getsid
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/getsockname.S b/libc/arch-arm/syscalls/getsockname.S
index 5dc4eab..a30a291 100644
--- a/libc/arch-arm/syscalls/getsockname.S
+++ b/libc/arch-arm/syscalls/getsockname.S
@@ -4,9 +4,11 @@
 
 ENTRY(getsockname)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_getsockname
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/gettimeofday.S b/libc/arch-arm/syscalls/gettimeofday.S
index 174f94b..f5ed674 100644
--- a/libc/arch-arm/syscalls/gettimeofday.S
+++ b/libc/arch-arm/syscalls/gettimeofday.S
@@ -4,9 +4,11 @@
 
 ENTRY(gettimeofday)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_gettimeofday
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/getuid.S b/libc/arch-arm/syscalls/getuid.S
index 3d07d3c..cdc86bc 100644
--- a/libc/arch-arm/syscalls/getuid.S
+++ b/libc/arch-arm/syscalls/getuid.S
@@ -4,9 +4,11 @@
 
 ENTRY(getuid)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_getuid32
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/getxattr.S b/libc/arch-arm/syscalls/getxattr.S
index 6661aaf..116d917 100644
--- a/libc/arch-arm/syscalls/getxattr.S
+++ b/libc/arch-arm/syscalls/getxattr.S
@@ -4,9 +4,11 @@
 
 ENTRY(getxattr)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_getxattr
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/init_module.S b/libc/arch-arm/syscalls/init_module.S
index 8251533..8fecf68 100644
--- a/libc/arch-arm/syscalls/init_module.S
+++ b/libc/arch-arm/syscalls/init_module.S
@@ -4,9 +4,11 @@
 
 ENTRY(init_module)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_init_module
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/inotify_add_watch.S b/libc/arch-arm/syscalls/inotify_add_watch.S
index b945bd1..61e666c 100644
--- a/libc/arch-arm/syscalls/inotify_add_watch.S
+++ b/libc/arch-arm/syscalls/inotify_add_watch.S
@@ -4,9 +4,11 @@
 
 ENTRY(inotify_add_watch)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_inotify_add_watch
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/inotify_init1.S b/libc/arch-arm/syscalls/inotify_init1.S
index 32090de..6cf066e 100644
--- a/libc/arch-arm/syscalls/inotify_init1.S
+++ b/libc/arch-arm/syscalls/inotify_init1.S
@@ -4,9 +4,11 @@
 
 ENTRY(inotify_init1)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_inotify_init1
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/inotify_rm_watch.S b/libc/arch-arm/syscalls/inotify_rm_watch.S
index e8230e2..1455da1 100644
--- a/libc/arch-arm/syscalls/inotify_rm_watch.S
+++ b/libc/arch-arm/syscalls/inotify_rm_watch.S
@@ -4,9 +4,11 @@
 
 ENTRY(inotify_rm_watch)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_inotify_rm_watch
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/kill.S b/libc/arch-arm/syscalls/kill.S
index 0b5f4a4..82df861 100644
--- a/libc/arch-arm/syscalls/kill.S
+++ b/libc/arch-arm/syscalls/kill.S
@@ -4,9 +4,11 @@
 
 ENTRY(kill)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_kill
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/klogctl.S b/libc/arch-arm/syscalls/klogctl.S
index b76b2b5..47a03c6 100644
--- a/libc/arch-arm/syscalls/klogctl.S
+++ b/libc/arch-arm/syscalls/klogctl.S
@@ -4,9 +4,11 @@
 
 ENTRY(klogctl)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_syslog
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/lgetxattr.S b/libc/arch-arm/syscalls/lgetxattr.S
index b033a9a..157271c 100644
--- a/libc/arch-arm/syscalls/lgetxattr.S
+++ b/libc/arch-arm/syscalls/lgetxattr.S
@@ -4,9 +4,11 @@
 
 ENTRY(lgetxattr)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_lgetxattr
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/listen.S b/libc/arch-arm/syscalls/listen.S
index 3aaa801..5ad75c0 100644
--- a/libc/arch-arm/syscalls/listen.S
+++ b/libc/arch-arm/syscalls/listen.S
@@ -4,9 +4,11 @@
 
 ENTRY(listen)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_listen
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/listxattr.S b/libc/arch-arm/syscalls/listxattr.S
index 51ff267..093927d 100644
--- a/libc/arch-arm/syscalls/listxattr.S
+++ b/libc/arch-arm/syscalls/listxattr.S
@@ -4,9 +4,11 @@
 
 ENTRY(listxattr)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_listxattr
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/llistxattr.S b/libc/arch-arm/syscalls/llistxattr.S
index 46e8116..5d0e7c8 100644
--- a/libc/arch-arm/syscalls/llistxattr.S
+++ b/libc/arch-arm/syscalls/llistxattr.S
@@ -4,9 +4,11 @@
 
 ENTRY(llistxattr)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_llistxattr
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/lremovexattr.S b/libc/arch-arm/syscalls/lremovexattr.S
index a945062..4e0bcec 100644
--- a/libc/arch-arm/syscalls/lremovexattr.S
+++ b/libc/arch-arm/syscalls/lremovexattr.S
@@ -4,9 +4,11 @@
 
 ENTRY(lremovexattr)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_lremovexattr
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/lseek.S b/libc/arch-arm/syscalls/lseek.S
index 00aeab3..cbdc441 100644
--- a/libc/arch-arm/syscalls/lseek.S
+++ b/libc/arch-arm/syscalls/lseek.S
@@ -4,9 +4,11 @@
 
 ENTRY(lseek)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_lseek
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/madvise.S b/libc/arch-arm/syscalls/madvise.S
index 4d3cdcd..c2d7d20 100644
--- a/libc/arch-arm/syscalls/madvise.S
+++ b/libc/arch-arm/syscalls/madvise.S
@@ -4,9 +4,11 @@
 
 ENTRY(madvise)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_madvise
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/mincore.S b/libc/arch-arm/syscalls/mincore.S
index f1154d0..c93fe94 100644
--- a/libc/arch-arm/syscalls/mincore.S
+++ b/libc/arch-arm/syscalls/mincore.S
@@ -4,9 +4,11 @@
 
 ENTRY(mincore)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_mincore
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/mkdirat.S b/libc/arch-arm/syscalls/mkdirat.S
index 1f8957b..4f93c61 100644
--- a/libc/arch-arm/syscalls/mkdirat.S
+++ b/libc/arch-arm/syscalls/mkdirat.S
@@ -4,9 +4,11 @@
 
 ENTRY(mkdirat)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_mkdirat
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/mknodat.S b/libc/arch-arm/syscalls/mknodat.S
index 1a2bf6f..91baae8 100644
--- a/libc/arch-arm/syscalls/mknodat.S
+++ b/libc/arch-arm/syscalls/mknodat.S
@@ -4,9 +4,11 @@
 
 ENTRY(mknodat)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_mknodat
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/mlock.S b/libc/arch-arm/syscalls/mlock.S
index 8a4fc7a..eb72f6f 100644
--- a/libc/arch-arm/syscalls/mlock.S
+++ b/libc/arch-arm/syscalls/mlock.S
@@ -4,9 +4,11 @@
 
 ENTRY(mlock)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_mlock
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/mlockall.S b/libc/arch-arm/syscalls/mlockall.S
index b49ca05..2984087 100644
--- a/libc/arch-arm/syscalls/mlockall.S
+++ b/libc/arch-arm/syscalls/mlockall.S
@@ -4,9 +4,11 @@
 
 ENTRY(mlockall)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_mlockall
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/mprotect.S b/libc/arch-arm/syscalls/mprotect.S
index cb51306..9bb1282 100644
--- a/libc/arch-arm/syscalls/mprotect.S
+++ b/libc/arch-arm/syscalls/mprotect.S
@@ -4,9 +4,11 @@
 
 ENTRY(mprotect)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_mprotect
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/msync.S b/libc/arch-arm/syscalls/msync.S
index 220fb4d..bcbab04 100644
--- a/libc/arch-arm/syscalls/msync.S
+++ b/libc/arch-arm/syscalls/msync.S
@@ -4,9 +4,11 @@
 
 ENTRY(msync)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_msync
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/munlock.S b/libc/arch-arm/syscalls/munlock.S
index 05bf941..bf1b814 100644
--- a/libc/arch-arm/syscalls/munlock.S
+++ b/libc/arch-arm/syscalls/munlock.S
@@ -4,9 +4,11 @@
 
 ENTRY(munlock)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_munlock
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/munlockall.S b/libc/arch-arm/syscalls/munlockall.S
index e2c5dd5..b45a5a2 100644
--- a/libc/arch-arm/syscalls/munlockall.S
+++ b/libc/arch-arm/syscalls/munlockall.S
@@ -4,9 +4,11 @@
 
 ENTRY(munlockall)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_munlockall
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/munmap.S b/libc/arch-arm/syscalls/munmap.S
index 740c360..2b7a121 100644
--- a/libc/arch-arm/syscalls/munmap.S
+++ b/libc/arch-arm/syscalls/munmap.S
@@ -4,9 +4,11 @@
 
 ENTRY(munmap)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_munmap
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/nanosleep.S b/libc/arch-arm/syscalls/nanosleep.S
index fcd6e90..83fd323 100644
--- a/libc/arch-arm/syscalls/nanosleep.S
+++ b/libc/arch-arm/syscalls/nanosleep.S
@@ -4,9 +4,11 @@
 
 ENTRY(nanosleep)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_nanosleep
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/personality.S b/libc/arch-arm/syscalls/personality.S
index d43d763..5ad6132 100644
--- a/libc/arch-arm/syscalls/personality.S
+++ b/libc/arch-arm/syscalls/personality.S
@@ -4,9 +4,11 @@
 
 ENTRY(personality)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_personality
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/pipe2.S b/libc/arch-arm/syscalls/pipe2.S
index 1cbdfb2..f543f9d 100644
--- a/libc/arch-arm/syscalls/pipe2.S
+++ b/libc/arch-arm/syscalls/pipe2.S
@@ -4,9 +4,11 @@
 
 ENTRY(pipe2)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_pipe2
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/prlimit64.S b/libc/arch-arm/syscalls/prlimit64.S
index 3ae9e1b..0f04aaa 100644
--- a/libc/arch-arm/syscalls/prlimit64.S
+++ b/libc/arch-arm/syscalls/prlimit64.S
@@ -4,9 +4,11 @@
 
 ENTRY(prlimit64)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_prlimit64
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/quotactl.S b/libc/arch-arm/syscalls/quotactl.S
index 831d229..fde17f4 100644
--- a/libc/arch-arm/syscalls/quotactl.S
+++ b/libc/arch-arm/syscalls/quotactl.S
@@ -4,9 +4,11 @@
 
 ENTRY(quotactl)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_quotactl
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/read.S b/libc/arch-arm/syscalls/read.S
index 1c3b395..5051358 100644
--- a/libc/arch-arm/syscalls/read.S
+++ b/libc/arch-arm/syscalls/read.S
@@ -4,9 +4,11 @@
 
 ENTRY(read)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_read
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/readlinkat.S b/libc/arch-arm/syscalls/readlinkat.S
index e7cc8ff..36d46fa 100644
--- a/libc/arch-arm/syscalls/readlinkat.S
+++ b/libc/arch-arm/syscalls/readlinkat.S
@@ -4,9 +4,11 @@
 
 ENTRY(readlinkat)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_readlinkat
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/readv.S b/libc/arch-arm/syscalls/readv.S
index c7807bd..565af6a 100644
--- a/libc/arch-arm/syscalls/readv.S
+++ b/libc/arch-arm/syscalls/readv.S
@@ -4,9 +4,11 @@
 
 ENTRY(readv)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_readv
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/recvmsg.S b/libc/arch-arm/syscalls/recvmsg.S
index 995a9e3..19a9fca 100644
--- a/libc/arch-arm/syscalls/recvmsg.S
+++ b/libc/arch-arm/syscalls/recvmsg.S
@@ -4,9 +4,11 @@
 
 ENTRY(recvmsg)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_recvmsg
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/removexattr.S b/libc/arch-arm/syscalls/removexattr.S
index 3a32e5c..46f847d 100644
--- a/libc/arch-arm/syscalls/removexattr.S
+++ b/libc/arch-arm/syscalls/removexattr.S
@@ -4,9 +4,11 @@
 
 ENTRY(removexattr)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_removexattr
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/renameat.S b/libc/arch-arm/syscalls/renameat.S
index 98e86dc..89fc513 100644
--- a/libc/arch-arm/syscalls/renameat.S
+++ b/libc/arch-arm/syscalls/renameat.S
@@ -4,9 +4,11 @@
 
 ENTRY(renameat)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_renameat
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/sched_get_priority_max.S b/libc/arch-arm/syscalls/sched_get_priority_max.S
index 187e680..23b1d62 100644
--- a/libc/arch-arm/syscalls/sched_get_priority_max.S
+++ b/libc/arch-arm/syscalls/sched_get_priority_max.S
@@ -4,9 +4,11 @@
 
 ENTRY(sched_get_priority_max)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_sched_get_priority_max
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/sched_get_priority_min.S b/libc/arch-arm/syscalls/sched_get_priority_min.S
index 68bf7df..65a967c 100644
--- a/libc/arch-arm/syscalls/sched_get_priority_min.S
+++ b/libc/arch-arm/syscalls/sched_get_priority_min.S
@@ -4,9 +4,11 @@
 
 ENTRY(sched_get_priority_min)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_sched_get_priority_min
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/sched_getparam.S b/libc/arch-arm/syscalls/sched_getparam.S
index 32b97b8..700041e 100644
--- a/libc/arch-arm/syscalls/sched_getparam.S
+++ b/libc/arch-arm/syscalls/sched_getparam.S
@@ -4,9 +4,11 @@
 
 ENTRY(sched_getparam)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_sched_getparam
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/sched_getscheduler.S b/libc/arch-arm/syscalls/sched_getscheduler.S
index 330c208..b4f5d13 100644
--- a/libc/arch-arm/syscalls/sched_getscheduler.S
+++ b/libc/arch-arm/syscalls/sched_getscheduler.S
@@ -4,9 +4,11 @@
 
 ENTRY(sched_getscheduler)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_sched_getscheduler
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/sched_rr_get_interval.S b/libc/arch-arm/syscalls/sched_rr_get_interval.S
index 5d176ac..ea30b62 100644
--- a/libc/arch-arm/syscalls/sched_rr_get_interval.S
+++ b/libc/arch-arm/syscalls/sched_rr_get_interval.S
@@ -4,9 +4,11 @@
 
 ENTRY(sched_rr_get_interval)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_sched_rr_get_interval
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/sched_setaffinity.S b/libc/arch-arm/syscalls/sched_setaffinity.S
index 6653471..636845b 100644
--- a/libc/arch-arm/syscalls/sched_setaffinity.S
+++ b/libc/arch-arm/syscalls/sched_setaffinity.S
@@ -4,9 +4,11 @@
 
 ENTRY(sched_setaffinity)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_sched_setaffinity
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/sched_setparam.S b/libc/arch-arm/syscalls/sched_setparam.S
index 16e1997..f24b96e 100644
--- a/libc/arch-arm/syscalls/sched_setparam.S
+++ b/libc/arch-arm/syscalls/sched_setparam.S
@@ -4,9 +4,11 @@
 
 ENTRY(sched_setparam)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_sched_setparam
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/sched_setscheduler.S b/libc/arch-arm/syscalls/sched_setscheduler.S
index 2ec9fec..5bfa202 100644
--- a/libc/arch-arm/syscalls/sched_setscheduler.S
+++ b/libc/arch-arm/syscalls/sched_setscheduler.S
@@ -4,9 +4,11 @@
 
 ENTRY(sched_setscheduler)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_sched_setscheduler
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/sched_yield.S b/libc/arch-arm/syscalls/sched_yield.S
index 1ec328f..7b93a6e 100644
--- a/libc/arch-arm/syscalls/sched_yield.S
+++ b/libc/arch-arm/syscalls/sched_yield.S
@@ -4,9 +4,11 @@
 
 ENTRY(sched_yield)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_sched_yield
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/sendfile.S b/libc/arch-arm/syscalls/sendfile.S
index afae021..52e78d0 100644
--- a/libc/arch-arm/syscalls/sendfile.S
+++ b/libc/arch-arm/syscalls/sendfile.S
@@ -4,9 +4,11 @@
 
 ENTRY(sendfile)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_sendfile
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/sendfile64.S b/libc/arch-arm/syscalls/sendfile64.S
index d0ad0b8..416e9d2 100644
--- a/libc/arch-arm/syscalls/sendfile64.S
+++ b/libc/arch-arm/syscalls/sendfile64.S
@@ -4,9 +4,11 @@
 
 ENTRY(sendfile64)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_sendfile64
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/sendmmsg.S b/libc/arch-arm/syscalls/sendmmsg.S
index 8bb5f80..f97d264 100644
--- a/libc/arch-arm/syscalls/sendmmsg.S
+++ b/libc/arch-arm/syscalls/sendmmsg.S
@@ -4,9 +4,11 @@
 
 ENTRY(sendmmsg)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_sendmmsg
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/sendmsg.S b/libc/arch-arm/syscalls/sendmsg.S
index fd38140..215219a 100644
--- a/libc/arch-arm/syscalls/sendmsg.S
+++ b/libc/arch-arm/syscalls/sendmsg.S
@@ -4,9 +4,11 @@
 
 ENTRY(sendmsg)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_sendmsg
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/setdomainname.S b/libc/arch-arm/syscalls/setdomainname.S
index 20f1f6f..4014a48 100644
--- a/libc/arch-arm/syscalls/setdomainname.S
+++ b/libc/arch-arm/syscalls/setdomainname.S
@@ -4,9 +4,11 @@
 
 ENTRY(setdomainname)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_setdomainname
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/setfsgid.S b/libc/arch-arm/syscalls/setfsgid.S
index f677a94..2f0f08c 100644
--- a/libc/arch-arm/syscalls/setfsgid.S
+++ b/libc/arch-arm/syscalls/setfsgid.S
@@ -4,9 +4,11 @@
 
 ENTRY(setfsgid)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_setfsgid
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/setfsuid.S b/libc/arch-arm/syscalls/setfsuid.S
index 5d27a4d..ce663e0 100644
--- a/libc/arch-arm/syscalls/setfsuid.S
+++ b/libc/arch-arm/syscalls/setfsuid.S
@@ -4,9 +4,11 @@
 
 ENTRY(setfsuid)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_setfsuid
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/setgid.S b/libc/arch-arm/syscalls/setgid.S
index d9b2b88..6f1cbed 100644
--- a/libc/arch-arm/syscalls/setgid.S
+++ b/libc/arch-arm/syscalls/setgid.S
@@ -4,9 +4,11 @@
 
 ENTRY(setgid)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_setgid32
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/setgroups.S b/libc/arch-arm/syscalls/setgroups.S
index 169de73..1fb494c 100644
--- a/libc/arch-arm/syscalls/setgroups.S
+++ b/libc/arch-arm/syscalls/setgroups.S
@@ -4,9 +4,11 @@
 
 ENTRY(setgroups)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_setgroups32
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/sethostname.S b/libc/arch-arm/syscalls/sethostname.S
index 0a98fd3..c4c2db5 100644
--- a/libc/arch-arm/syscalls/sethostname.S
+++ b/libc/arch-arm/syscalls/sethostname.S
@@ -4,9 +4,11 @@
 
 ENTRY(sethostname)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_sethostname
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/setitimer.S b/libc/arch-arm/syscalls/setitimer.S
index 31b277b..511a5d1 100644
--- a/libc/arch-arm/syscalls/setitimer.S
+++ b/libc/arch-arm/syscalls/setitimer.S
@@ -4,9 +4,11 @@
 
 ENTRY(setitimer)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_setitimer
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/setns.S b/libc/arch-arm/syscalls/setns.S
index 59203ef..b1902dc 100644
--- a/libc/arch-arm/syscalls/setns.S
+++ b/libc/arch-arm/syscalls/setns.S
@@ -4,9 +4,11 @@
 
 ENTRY(setns)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_setns
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/setpgid.S b/libc/arch-arm/syscalls/setpgid.S
index 4a91520..fe05fc9 100644
--- a/libc/arch-arm/syscalls/setpgid.S
+++ b/libc/arch-arm/syscalls/setpgid.S
@@ -4,9 +4,11 @@
 
 ENTRY(setpgid)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_setpgid
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/setpriority.S b/libc/arch-arm/syscalls/setpriority.S
index 2053ce1..960eee0 100644
--- a/libc/arch-arm/syscalls/setpriority.S
+++ b/libc/arch-arm/syscalls/setpriority.S
@@ -4,9 +4,11 @@
 
 ENTRY(setpriority)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_setpriority
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/setregid.S b/libc/arch-arm/syscalls/setregid.S
index f1bdc60..0b5f444 100644
--- a/libc/arch-arm/syscalls/setregid.S
+++ b/libc/arch-arm/syscalls/setregid.S
@@ -4,9 +4,11 @@
 
 ENTRY(setregid)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_setregid32
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/setresgid.S b/libc/arch-arm/syscalls/setresgid.S
index 9b8968a..64677d3 100644
--- a/libc/arch-arm/syscalls/setresgid.S
+++ b/libc/arch-arm/syscalls/setresgid.S
@@ -4,9 +4,11 @@
 
 ENTRY(setresgid)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_setresgid32
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/setresuid.S b/libc/arch-arm/syscalls/setresuid.S
index c26a955..e3888f6 100644
--- a/libc/arch-arm/syscalls/setresuid.S
+++ b/libc/arch-arm/syscalls/setresuid.S
@@ -4,9 +4,11 @@
 
 ENTRY(setresuid)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_setresuid32
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/setreuid.S b/libc/arch-arm/syscalls/setreuid.S
index 796191a..15c2665 100644
--- a/libc/arch-arm/syscalls/setreuid.S
+++ b/libc/arch-arm/syscalls/setreuid.S
@@ -4,9 +4,11 @@
 
 ENTRY(setreuid)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_setreuid32
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/setrlimit.S b/libc/arch-arm/syscalls/setrlimit.S
index c87b21b..b9014eb 100644
--- a/libc/arch-arm/syscalls/setrlimit.S
+++ b/libc/arch-arm/syscalls/setrlimit.S
@@ -4,9 +4,11 @@
 
 ENTRY(setrlimit)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_setrlimit
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/setsid.S b/libc/arch-arm/syscalls/setsid.S
index 83bda1b..fb71474 100644
--- a/libc/arch-arm/syscalls/setsid.S
+++ b/libc/arch-arm/syscalls/setsid.S
@@ -4,9 +4,11 @@
 
 ENTRY(setsid)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_setsid
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/settimeofday.S b/libc/arch-arm/syscalls/settimeofday.S
index 5763f40..00dfdeb 100644
--- a/libc/arch-arm/syscalls/settimeofday.S
+++ b/libc/arch-arm/syscalls/settimeofday.S
@@ -4,9 +4,11 @@
 
 ENTRY(settimeofday)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_settimeofday
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/setuid.S b/libc/arch-arm/syscalls/setuid.S
index 55b349c..447ed1b 100644
--- a/libc/arch-arm/syscalls/setuid.S
+++ b/libc/arch-arm/syscalls/setuid.S
@@ -4,9 +4,11 @@
 
 ENTRY(setuid)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_setuid32
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/shutdown.S b/libc/arch-arm/syscalls/shutdown.S
index 889934a..51ed0cf 100644
--- a/libc/arch-arm/syscalls/shutdown.S
+++ b/libc/arch-arm/syscalls/shutdown.S
@@ -4,9 +4,11 @@
 
 ENTRY(shutdown)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_shutdown
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/sigaltstack.S b/libc/arch-arm/syscalls/sigaltstack.S
index b61b25d..2f97800 100644
--- a/libc/arch-arm/syscalls/sigaltstack.S
+++ b/libc/arch-arm/syscalls/sigaltstack.S
@@ -4,9 +4,11 @@
 
 ENTRY(sigaltstack)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_sigaltstack
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/socketpair.S b/libc/arch-arm/syscalls/socketpair.S
index f3c8a4b..e537235 100644
--- a/libc/arch-arm/syscalls/socketpair.S
+++ b/libc/arch-arm/syscalls/socketpair.S
@@ -4,9 +4,11 @@
 
 ENTRY(socketpair)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_socketpair
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/swapoff.S b/libc/arch-arm/syscalls/swapoff.S
index a7aaa82..25832ef 100644
--- a/libc/arch-arm/syscalls/swapoff.S
+++ b/libc/arch-arm/syscalls/swapoff.S
@@ -4,9 +4,11 @@
 
 ENTRY(swapoff)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_swapoff
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/swapon.S b/libc/arch-arm/syscalls/swapon.S
index 6ea93c3..df4c71e 100644
--- a/libc/arch-arm/syscalls/swapon.S
+++ b/libc/arch-arm/syscalls/swapon.S
@@ -4,9 +4,11 @@
 
 ENTRY(swapon)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_swapon
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/symlinkat.S b/libc/arch-arm/syscalls/symlinkat.S
index d330a54..ec2ee4f 100644
--- a/libc/arch-arm/syscalls/symlinkat.S
+++ b/libc/arch-arm/syscalls/symlinkat.S
@@ -4,9 +4,11 @@
 
 ENTRY(symlinkat)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_symlinkat
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/sync.S b/libc/arch-arm/syscalls/sync.S
index 48ecfc0..b73dcaa 100644
--- a/libc/arch-arm/syscalls/sync.S
+++ b/libc/arch-arm/syscalls/sync.S
@@ -4,9 +4,11 @@
 
 ENTRY(sync)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_sync
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/sysinfo.S b/libc/arch-arm/syscalls/sysinfo.S
index 709478e..1584ea4 100644
--- a/libc/arch-arm/syscalls/sysinfo.S
+++ b/libc/arch-arm/syscalls/sysinfo.S
@@ -4,9 +4,11 @@
 
 ENTRY(sysinfo)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_sysinfo
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/tee.S b/libc/arch-arm/syscalls/tee.S
index a019c00..efd12ca 100644
--- a/libc/arch-arm/syscalls/tee.S
+++ b/libc/arch-arm/syscalls/tee.S
@@ -4,9 +4,11 @@
 
 ENTRY(tee)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_tee
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/tgkill.S b/libc/arch-arm/syscalls/tgkill.S
index 2068465..43fe62c 100644
--- a/libc/arch-arm/syscalls/tgkill.S
+++ b/libc/arch-arm/syscalls/tgkill.S
@@ -4,9 +4,11 @@
 
 ENTRY(tgkill)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_tgkill
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/timerfd_create.S b/libc/arch-arm/syscalls/timerfd_create.S
index 89a80cd..4aa3107 100644
--- a/libc/arch-arm/syscalls/timerfd_create.S
+++ b/libc/arch-arm/syscalls/timerfd_create.S
@@ -4,9 +4,11 @@
 
 ENTRY(timerfd_create)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_timerfd_create
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/timerfd_gettime.S b/libc/arch-arm/syscalls/timerfd_gettime.S
index 4a7df76..6ae93e4 100644
--- a/libc/arch-arm/syscalls/timerfd_gettime.S
+++ b/libc/arch-arm/syscalls/timerfd_gettime.S
@@ -4,9 +4,11 @@
 
 ENTRY(timerfd_gettime)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_timerfd_gettime
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/timerfd_settime.S b/libc/arch-arm/syscalls/timerfd_settime.S
index 2e0fe93..2dd4aac 100644
--- a/libc/arch-arm/syscalls/timerfd_settime.S
+++ b/libc/arch-arm/syscalls/timerfd_settime.S
@@ -4,9 +4,11 @@
 
 ENTRY(timerfd_settime)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_timerfd_settime
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/times.S b/libc/arch-arm/syscalls/times.S
index 289c185..1ff636d 100644
--- a/libc/arch-arm/syscalls/times.S
+++ b/libc/arch-arm/syscalls/times.S
@@ -4,9 +4,11 @@
 
 ENTRY(times)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_times
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/truncate.S b/libc/arch-arm/syscalls/truncate.S
index bb33beb..0bee4d2 100644
--- a/libc/arch-arm/syscalls/truncate.S
+++ b/libc/arch-arm/syscalls/truncate.S
@@ -4,9 +4,11 @@
 
 ENTRY(truncate)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_truncate
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/truncate64.S b/libc/arch-arm/syscalls/truncate64.S
index 9cafbb5..74e9eb2 100644
--- a/libc/arch-arm/syscalls/truncate64.S
+++ b/libc/arch-arm/syscalls/truncate64.S
@@ -4,9 +4,11 @@
 
 ENTRY(truncate64)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_truncate64
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/umask.S b/libc/arch-arm/syscalls/umask.S
index 5dc4461..ca3e058 100644
--- a/libc/arch-arm/syscalls/umask.S
+++ b/libc/arch-arm/syscalls/umask.S
@@ -4,9 +4,11 @@
 
 ENTRY(umask)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_umask
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/umount2.S b/libc/arch-arm/syscalls/umount2.S
index 435eda4..6e1ba32 100644
--- a/libc/arch-arm/syscalls/umount2.S
+++ b/libc/arch-arm/syscalls/umount2.S
@@ -4,9 +4,11 @@
 
 ENTRY(umount2)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_umount2
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/uname.S b/libc/arch-arm/syscalls/uname.S
index 8af6123..4f2b8a2 100644
--- a/libc/arch-arm/syscalls/uname.S
+++ b/libc/arch-arm/syscalls/uname.S
@@ -4,9 +4,11 @@
 
 ENTRY(uname)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_uname
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/unlinkat.S b/libc/arch-arm/syscalls/unlinkat.S
index 96257e6..ac7bfae 100644
--- a/libc/arch-arm/syscalls/unlinkat.S
+++ b/libc/arch-arm/syscalls/unlinkat.S
@@ -4,9 +4,11 @@
 
 ENTRY(unlinkat)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_unlinkat
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/unshare.S b/libc/arch-arm/syscalls/unshare.S
index 8054171..4558a60 100644
--- a/libc/arch-arm/syscalls/unshare.S
+++ b/libc/arch-arm/syscalls/unshare.S
@@ -4,9 +4,11 @@
 
 ENTRY(unshare)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_unshare
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/utimensat.S b/libc/arch-arm/syscalls/utimensat.S
index f3c2fa2..9524507 100644
--- a/libc/arch-arm/syscalls/utimensat.S
+++ b/libc/arch-arm/syscalls/utimensat.S
@@ -4,9 +4,11 @@
 
 ENTRY(utimensat)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_utimensat
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/vmsplice.S b/libc/arch-arm/syscalls/vmsplice.S
index cc12ca5..90ab8b4 100644
--- a/libc/arch-arm/syscalls/vmsplice.S
+++ b/libc/arch-arm/syscalls/vmsplice.S
@@ -4,9 +4,11 @@
 
 ENTRY(vmsplice)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_vmsplice
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/wait4.S b/libc/arch-arm/syscalls/wait4.S
index 26a4929..40bb5a5 100644
--- a/libc/arch-arm/syscalls/wait4.S
+++ b/libc/arch-arm/syscalls/wait4.S
@@ -4,9 +4,11 @@
 
 ENTRY(wait4)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_wait4
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/write.S b/libc/arch-arm/syscalls/write.S
index bf89d7f..4abbe6b 100644
--- a/libc/arch-arm/syscalls/write.S
+++ b/libc/arch-arm/syscalls/write.S
@@ -4,9 +4,11 @@
 
 ENTRY(write)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_write
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-arm/syscalls/writev.S b/libc/arch-arm/syscalls/writev.S
index 15b5275..3103237 100644
--- a/libc/arch-arm/syscalls/writev.S
+++ b/libc/arch-arm/syscalls/writev.S
@@ -4,9 +4,11 @@
 
 ENTRY(writev)
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =__NR_writev
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/libc/arch-mips/string/memset.S b/libc/arch-mips/string/memset.S
index 6344af1..7ea6753 100644
--- a/libc/arch-mips/string/memset.S
+++ b/libc/arch-mips/string/memset.S
@@ -209,11 +209,14 @@
 LEAF(__memset_chk)
 #endif
 	.set	noreorder
-  bgtu   a2, a3, __memset_chk_fail
-  la     t9, __memset_chk_fail
-	.set	reorder
-
-  // Fall through to memset...
+        sltu    t2, a3, a2
+        beq     t2, zero, memset
+        nop
+        .cpsetup t9, t8, __memset_chk
+        LA      t9, __memset_chk_fail
+        jr      t9
+        nop
+        .set	reorder
 END(__memset_chk)
 
 #ifdef __ANDROID__
diff --git a/libc/bionic/grp_pwd.cpp b/libc/bionic/grp_pwd.cpp
index d75b94d..332b2b8 100644
--- a/libc/bionic/grp_pwd.cpp
+++ b/libc/bionic/grp_pwd.cpp
@@ -54,6 +54,8 @@
   group group_;
   char* group_members_[2];
   char group_name_buffer_[32];
+  // Must be last so init_group_state can run a simple memset for the above
+  ssize_t getgrent_idx;
 };
 
 struct passwd_state_t {
@@ -61,13 +63,14 @@
   char name_buffer_[32];
   char dir_buffer_[32];
   char sh_buffer_[32];
+  ssize_t getpwent_idx;
 };
 
 static ThreadLocalBuffer<group_state_t> g_group_tls_buffer;
 static ThreadLocalBuffer<passwd_state_t> g_passwd_tls_buffer;
 
 static void init_group_state(group_state_t* state) {
-  memset(state, 0, sizeof(group_state_t));
+  memset(state, 0, sizeof(group_state_t) - sizeof(state->getgrent_idx));
   state->group_.gr_mem = state->group_members_;
 }
 
@@ -467,6 +470,60 @@
   return (pw != NULL) ? pw->pw_name : NULL;
 }
 
+void setpwent() {
+  passwd_state_t* state = g_passwd_tls_buffer.get();
+  if (state) {
+    state->getpwent_idx = 0;
+  }
+}
+
+void endpwent() {
+  setpwent();
+}
+
+passwd* getpwent() {
+  passwd_state_t* state = g_passwd_tls_buffer.get();
+  if (state == NULL) {
+    return NULL;
+  }
+  if (state->getpwent_idx < 0) {
+    return NULL;
+  }
+
+  size_t start = 0;
+  ssize_t end = android_id_count;
+  if (state->getpwent_idx < end) {
+    return android_iinfo_to_passwd(state, android_ids + state->getpwent_idx++);
+  }
+
+  start = end;
+  end += AID_OEM_RESERVED_END - AID_OEM_RESERVED_START + 1;
+
+  if (state->getpwent_idx < end) {
+    return oem_id_to_passwd(
+        state->getpwent_idx++ - start + AID_OEM_RESERVED_START, state);
+  }
+
+  start = end;
+  end += AID_OEM_RESERVED_2_END - AID_OEM_RESERVED_2_START + 1;
+
+  if (state->getpwent_idx < end) {
+    return oem_id_to_passwd(
+        state->getpwent_idx++ - start + AID_OEM_RESERVED_2_START, state);
+  }
+
+  start = end;
+  end += AID_USER - AID_APP; // Do not expose higher users
+
+  if (state->getpwent_idx < end) {
+    return app_id_to_passwd(state->getpwent_idx++ - start + AID_APP, state);
+  }
+
+  // We are not reporting u1_a* and higher or we will be here forever
+  state->getpwent_idx = -1;
+  return NULL;
+}
+
 static group* getgrgid_internal(gid_t gid, group_state_t* state) {
   group* grp = android_id_to_group(state, gid);
   if (grp != NULL) {
@@ -537,3 +594,61 @@
                struct group **result) {
   return getgroup_r(true, name, 0, grp, buf, buflen, result);
 }
+
+void setgrent() {
+  group_state_t* state = g_group_tls_buffer.get();
+  if (state) {
+    state->getgrent_idx = 0;
+  }
+}
+
+void endgrent() {
+  setgrent();
+}
+
+group* getgrent() {
+  group_state_t* state = g_group_tls_buffer.get();
+  if (state == NULL) {
+    return NULL;
+  }
+  if (state->getgrent_idx < 0) {
+    return NULL;
+  }
+
+  size_t start = 0;
+  ssize_t end = android_id_count;
+  if (state->getgrent_idx < end) {
+    init_group_state(state);
+    return android_iinfo_to_group(state, android_ids + state->getgrent_idx++);
+  }
+
+  start = end;
+  end += AID_OEM_RESERVED_END - AID_OEM_RESERVED_START + 1;
+
+  if (state->getgrent_idx < end) {
+    init_group_state(state);
+    return oem_id_to_group(
+        state->getgrent_idx++ - start + AID_OEM_RESERVED_START, state);
+  }
+
+  start = end;
+  end += AID_OEM_RESERVED_2_END - AID_OEM_RESERVED_2_START + 1;
+
+  if (state->getgrent_idx < end) {
+    init_group_state(state);
+    return oem_id_to_group(
+        state->getgrent_idx++ - start + AID_OEM_RESERVED_2_START, state);
+  }
+
+  start = end;
+  end += AID_USER - AID_APP; // Do not expose higher groups
+
+  if (state->getgrent_idx < end) {
+    init_group_state(state);
+    return app_id_to_group(state->getgrent_idx++ - start + AID_APP, state);
+  }
+
+  // We are not reporting u1_a* and higher or we will be here forever
+  state->getgrent_idx = -1;
+  return NULL;
+}
diff --git a/libc/bionic/mblen.cpp b/libc/bionic/mblen.cpp
new file mode 100644
index 0000000..7def6f1
--- /dev/null
+++ b/libc/bionic/mblen.cpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+#include <wchar.h>
+
+int mblen(const char* s, size_t n) {
+  mbstate_t state = {};
+  return mbrlen(s, n, &state);
+}
diff --git a/libc/bionic/ndk_cruft.cpp b/libc/bionic/ndk_cruft.cpp
index 95abc20..224cd41 100644
--- a/libc/bionic/ndk_cruft.cpp
+++ b/libc/bionic/ndk_cruft.cpp
@@ -366,10 +366,6 @@
   return __set_errno_internal(n);
 }
 
-// This was never implemented in bionic, only needed for ABI compatibility with the NDK.
-// In the M time frame, over 1000 apps have a reference to this!
-void endpwent() { }
-
 // Since dlmalloc_inspect_all and dlmalloc_trim are exported for systems
 // that use dlmalloc, be consistent and export them everywhere.
 void dlmalloc_inspect_all(void (*)(void*, void*, size_t, void*), void*) {
diff --git a/libc/dns/include/resolv_private.h b/libc/dns/include/resolv_private.h
index 3ab8ea6..8dad926 100644
--- a/libc/dns/include/resolv_private.h
+++ b/libc/dns/include/resolv_private.h
@@ -536,6 +536,15 @@
 
 #undef __socketcall
 
+// Symbols that are supposed to be in resolv.h, but that we aren't exporting.
+int ns_parserr2(ns_msg*, ns_sect, int, ns_rr2*);
+int ns_name_pton2(const char*, u_char*, size_t, size_t*);
+int ns_name_unpack2(const u_char*, const u_char*, const u_char*, u_char*, size_t, size_t*);
+int ns_name_eq(ns_nname_ct, size_t, ns_nname_ct, size_t);
+int ns_name_owned(ns_namemap_ct, int, ns_namemap_ct, int);
+int ns_name_map(ns_nname_ct, size_t, ns_namemap_t, int);
+int ns_name_labels(ns_nname_ct, size_t);
+
 __END_DECLS
 
 #pragma GCC visibility pop
diff --git a/libc/dns/resolv/res_cache.c b/libc/dns/resolv/res_cache.c
index 02887f2..212ee0a 100644
--- a/libc/dns/resolv/res_cache.c
+++ b/libc/dns/resolv/res_cache.c
@@ -2230,10 +2230,16 @@
             stats[i] = info->nsstats[i];
         }
         for (i = 0; i < MAXDNSRCH; i++) {
-            if (info->dnsrch_offset[i] == -1) {
+            const char* cur_domain = info->defdname + info->dnsrch_offset[i];
+            // dnsrch_offset[i] can either be -1 or point to an empty string to indicate the end
+            // of the search offsets. Checking for < 0 is not strictly necessary, but safer.
+            // TODO: Pass in a search domain array instead of a string to
+            // _resolv_set_nameservers_for_net() and make this double check unnecessary.
+            if (info->dnsrch_offset[i] < 0 ||
+                    ((size_t)info->dnsrch_offset[i]) >= sizeof(info->defdname) || !cur_domain[0]) {
                 break;
             }
-            strlcpy(domains[i], info->defdname + info->dnsrch_offset[i], MAXDNSRCHPATH);
+            strlcpy(domains[i], cur_domain, MAXDNSRCHPATH);
         }
         *dcount = i;
         *params = info->params;
diff --git a/libc/include/arpa/nameser.h b/libc/include/arpa/nameser.h
index 91561ce..3690f9c 100644
--- a/libc/include/arpa/nameser.h
+++ b/libc/include/arpa/nameser.h
@@ -566,70 +566,30 @@
 #endif
 
 __BEGIN_DECLS
-int		ns_msg_getflag(ns_msg, int) __LIBC_ABI_PUBLIC__;
-uint16_t	ns_get16(const u_char *) __LIBC_ABI_PUBLIC__;
-uint32_t	ns_get32(const u_char *) __LIBC_ABI_PUBLIC__;
-void		ns_put16(uint16_t, u_char *) __LIBC_ABI_PUBLIC__;
-void		ns_put32(uint32_t, u_char *) __LIBC_ABI_PUBLIC__;
-int		ns_initparse(const u_char *, int, ns_msg *) __LIBC_ABI_PUBLIC__;
-int		ns_skiprr(const u_char *, const u_char *, ns_sect, int) __LIBC_ABI_PUBLIC__;
-int		ns_parserr(ns_msg *, ns_sect, int, ns_rr *) __LIBC_ABI_PUBLIC__;
-int		ns_parserr2(ns_msg *, ns_sect, int, ns_rr2 *) __LIBC_HIDDEN__;
-int		ns_sprintrr(const ns_msg *, const ns_rr *,
-				 const char *, const char *, char *, size_t) __LIBC_ABI_PUBLIC__;
-int		ns_sprintrrf(const u_char *, size_t, const char *,
-				  ns_class, ns_type, u_long, const u_char *,
-				  size_t, const char *, const char *,
-				  char *, size_t) __LIBC_ABI_PUBLIC__;
-int		ns_format_ttl(u_long, char *, size_t) __LIBC_ABI_PUBLIC__;
-int		ns_parse_ttl(const char *, u_long *) __LIBC_ABI_PUBLIC__;
-uint32_t	ns_datetosecs(const char *cp, int *errp) __LIBC_ABI_PUBLIC__;
-int		ns_name_ntol(const u_char *, u_char *, size_t) __LIBC_ABI_PUBLIC__;
-int		ns_name_ntop(const u_char *, char *, size_t) __LIBC_ABI_PUBLIC__;
-int		ns_name_pton(const char *, u_char *, size_t) __LIBC_ABI_PUBLIC__;
-int		ns_name_pton2(const char *, u_char *, size_t, size_t *) __LIBC_HIDDEN__;
-int		ns_name_unpack(const u_char *, const u_char *,
-				    const u_char *, u_char *, size_t) __LIBC_ABI_PUBLIC__;
-int		ns_name_unpack2(const u_char *, const u_char *,
-				     const u_char *, u_char *, size_t,
-				     size_t *) __LIBC_HIDDEN__;
-int		ns_name_pack(const u_char *, u_char *, int,
-				  const u_char **, const u_char **) __LIBC_ABI_PUBLIC__;
-int		ns_name_uncompress(const u_char *, const u_char *,
-					const u_char *, char *, size_t) __LIBC_ABI_PUBLIC__;
-int		ns_name_compress(const char *, u_char *, size_t,
-				      const u_char **, const u_char **) __LIBC_ABI_PUBLIC__;
-int		ns_name_skip(const u_char **, const u_char *) __LIBC_ABI_PUBLIC__;
-void		ns_name_rollback(const u_char *, const u_char **,
-				      const u_char **) __LIBC_ABI_PUBLIC__;
-int		ns_sign(u_char *, int *, int, int, void *,
-			     const u_char *, int, u_char *, int *, time_t) __LIBC_ABI_PUBLIC__;
-int		ns_sign2(u_char *, int *, int, int, void *,
-			      const u_char *, int, u_char *, int *, time_t,
-			      u_char **, u_char **) __LIBC_ABI_PUBLIC__;
-ssize_t		ns_name_length(ns_nname_ct, size_t) __LIBC_HIDDEN__;
-int		ns_name_eq(ns_nname_ct, size_t, ns_nname_ct, size_t) __LIBC_HIDDEN__;
-int		ns_name_owned(ns_namemap_ct, int, ns_namemap_ct, int) __LIBC_HIDDEN__;
-int		ns_name_map(ns_nname_ct, size_t, ns_namemap_t, int) __LIBC_HIDDEN__;
-int		ns_name_labels(ns_nname_ct, size_t) __LIBC_HIDDEN__;
-int		ns_sign_tcp(u_char *, int *, int, int,
-				 ns_tcp_tsig_state *, int) __LIBC_ABI_PUBLIC__;
-int		ns_sign_tcp2(u_char *, int *, int, int,
-				  ns_tcp_tsig_state *, int,
-				  u_char **, u_char **) __LIBC_ABI_PUBLIC__;
-int		ns_sign_tcp_init(void *, const u_char *, int,
-					ns_tcp_tsig_state *) __LIBC_ABI_PUBLIC__;
-u_char		*ns_find_tsig(u_char *, u_char *) __LIBC_ABI_PUBLIC__;
-int		ns_verify(u_char *, int *, void *,
-			       const u_char *, int, u_char *, int *,
-			       time_t *, int) __LIBC_ABI_PUBLIC__;
-int		ns_verify_tcp(u_char *, int *, ns_tcp_tsig_state *, int);
-int		ns_verify_tcp_init(void *, const u_char *, int,
-					ns_tcp_tsig_state *) __LIBC_ABI_PUBLIC__;
-int		ns_samedomain(const char *, const char *) __LIBC_ABI_PUBLIC__;
-int		ns_subdomain(const char *, const char *) __LIBC_ABI_PUBLIC__;
-int		ns_makecanon(const char *, char *, size_t) __LIBC_ABI_PUBLIC__;
-int		ns_samename(const char *, const char *) __LIBC_ABI_PUBLIC__;
+int ns_msg_getflag(ns_msg, int);
+uint16_t ns_get16(const u_char*);
+uint32_t ns_get32(const u_char*);
+void ns_put16(uint16_t, u_char*);
+void ns_put32(uint32_t, u_char*);
+int ns_initparse(const u_char*, int, ns_msg*);
+int ns_skiprr(const u_char*, const u_char*, ns_sect, int);
+int ns_parserr(ns_msg*, ns_sect, int, ns_rr*);
+int ns_sprintrr(const ns_msg*, const ns_rr*, const char*, const char*, char*, size_t);
+int ns_sprintrrf(const u_char*, size_t, const char*, ns_class, ns_type, u_long, const u_char*,
+                 size_t, const char*, const char*, char*, size_t);
+int ns_format_ttl(u_long, char*, size_t);
+int ns_name_ntol(const u_char*, u_char*, size_t);
+int ns_name_ntop(const u_char*, char*, size_t);
+int ns_name_pton(const char*, u_char*, size_t);
+int ns_name_unpack(const u_char*, const u_char*, const u_char*, u_char*, size_t);
+int ns_name_pack(const u_char*, u_char*, int, const u_char**, const u_char**);
+int ns_name_uncompress(const u_char*, const u_char*, const u_char*, char*, size_t);
+int ns_name_compress(const char*, u_char*, size_t, const u_char**, const u_char**);
+int ns_name_skip(const u_char**, const u_char*);
+void ns_name_rollback(const u_char*, const u_char**, const u_char**);
+
+int ns_makecanon(const char*, char*, size_t);
+int ns_samename(const char*, const char*);
 __END_DECLS
 
 #ifdef BIND_4_COMPAT
diff --git a/libc/include/arpa/telnet.h b/libc/include/arpa/telnet.h
index d318e08..b8212f8 100644
--- a/libc/include/arpa/telnet.h
+++ b/libc/include/arpa/telnet.h
@@ -64,8 +64,6 @@
 	"SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC",
 	"EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC", 0,
 };
-#else
-extern char *telcmds[];
 #endif
 
 #define	TELCMD_FIRST	xEOF
@@ -206,8 +204,6 @@
 const char *slc_names[] = {
 	SLC_NAMELIST
 };
-#else
-extern char *slc_names[];
 #define	SLC_NAMES SLC_NAMELIST
 #endif
 
@@ -266,8 +262,6 @@
 const char *authtype_names[] = {
 	"NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK", 0,
 };
-#else
-extern char *authtype_names[];
 #endif
 
 #define	AUTHTYPE_NAME_OK(x)	((unsigned int)(x) < AUTHTYPE_CNT)
@@ -301,9 +295,6 @@
 const char *enctype_names[] = {
 	"ANY", "DES_CFB64",  "DES_OFB64",  0,
 };
-#else
-extern const char *encrypt_names[];
-extern const char *enctype_names[];
 #endif
 
 
diff --git a/libc/include/grp.h b/libc/include/grp.h
index df7a613..3ae0d6e 100644
--- a/libc/include/grp.h
+++ b/libc/include/grp.h
@@ -1,9 +1,9 @@
-/*	$OpenBSD: grp.h,v 1.8 2005/12/13 00:35:22 millert Exp $	*/
-/*	$NetBSD: grp.h,v 1.7 1995/04/29 05:30:40 cgd Exp $	*/
+/* $OpenBSD: grp.h,v 1.8 2005/12/13 00:35:22 millert Exp $ */
+/* $NetBSD: grp.h,v 1.7 1995/04/29 05:30:40 cgd Exp $ */
 
 /*-
  * Copyright (c) 1989, 1993
- *	The Regents of the University of California.  All rights reserved.
+ *    The Regents of the University of California.  All rights reserved.
  * (c) UNIX System Laboratories, Inc.
  * All or some portions of this file are derived from material licensed
  * to the University of California by American Telephone and Telegraph
@@ -34,39 +34,37 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *	@(#)grp.h	8.2 (Berkeley) 1/21/94
+ *    @(#)grp.h  8.2 (Berkeley) 1/21/94
  */
 
 #ifndef _GRP_H_
-#define	_GRP_H_
+#define _GRP_H_
 
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
 struct group {
-	char	*gr_name;		/* group name */
-	char	*gr_passwd;		/* group password */
-	gid_t	gr_gid;			/* group id */
-	char	**gr_mem;		/* group members */
+    char* gr_name; /* group name */
+    char* gr_passwd; /* group password */
+    gid_t gr_gid; /* group id */
+    char** gr_mem; /* group members */
 };
 
 __BEGIN_DECLS
-struct group	*getgrgid(gid_t);
-struct group	*getgrnam(const char *);
+struct group* getgrgid(gid_t);
+struct group* getgrnam(const char *);
 #if __POSIX_VISIBLE >= 200112 || __XPG_VISIBLE
-struct group	*getgrent(void)  __attribute__((deprecated("getgrent is meaningless on Android")));
-void setgrent(void) __attribute__((deprecated("setgrent is meaningless on Android")));
-void endgrent(void) __attribute__((deprecated("endgrent is meaningless on Android")));
-int		 getgrgid_r(gid_t, struct group *, char *,
-		    size_t, struct group **);
-int		 getgrnam_r(const char *, struct group *, char *,
-		    size_t, struct group **);
+/* Android has thousands and thousands of ids to iterate through */
+struct group* getgrent(void) __attribute__((warning("getgrent is inefficient on Android")));
+void setgrent(void);
+void endgrent(void);
+int getgrgid_r(gid_t, struct group *, char *, size_t, struct group **);
+int getgrnam_r(const char *, struct group *, char *, size_t, struct group **);
 #endif
 
-int   getgrouplist (const char *user, gid_t group,
-                  gid_t *groups, int *ngroups);
+int getgrouplist (const char *user, gid_t group, gid_t *groups, int *ngroups);
 
-int   initgroups (const char *user, gid_t group);
+int initgroups (const char *user, gid_t group);
 
 __END_DECLS
 
diff --git a/libc/include/net/if_ether.h b/libc/include/net/if_ether.h
index 8daa16b..6da96e4 100644
--- a/libc/include/net/if_ether.h
+++ b/libc/include/net/if_ether.h
@@ -205,12 +205,8 @@
  */
 #include <sys/cdefs.h>
 __BEGIN_DECLS
-char *	ether_ntoa __P((const struct ether_addr *));
-struct ether_addr *
-	ether_aton __P((const char *));
-int	ether_ntohost __P((char *, const struct ether_addr *));
-int	ether_hostton __P((const char *, struct ether_addr *));
-int	ether_line __P((const char *, struct ether_addr *, char *));
+char* ether_ntoa __P((const struct ether_addr*));
+struct ether_addr* ether_aton __P((const char*));
 __END_DECLS
 #endif
 
diff --git a/libc/include/netdb.h b/libc/include/netdb.h
index 3bb973c..339bac2 100644
--- a/libc/include/netdb.h
+++ b/libc/include/netdb.h
@@ -199,49 +199,29 @@
 #define  h_errno   (*__get_h_errno())
 int*  __get_h_errno(void);
 /* BIONIC-END */
-void endhostent(void);
-void endnetent(void);
-void endnetgrent(void);
-void endprotoent(void);
 void endservent(void);
-void freehostent(struct hostent *);
-struct hostent	*gethostbyaddr(const void *, socklen_t, int);
-int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, int *);
-struct hostent	*gethostbyname(const char *);
-int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);
-struct hostent	*gethostbyname2(const char *, int);
-int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *);
-struct hostent	*gethostent(void);
-int gethostent_r(struct hostent *, char *, size_t, struct hostent **, int *);
-struct hostent	*getipnodebyaddr(const void *, size_t, int, int *);
-struct hostent	*getipnodebyname(const char *, int, int, int *);
-struct netent	*getnetbyaddr(uint32_t, int);
-int getnetbyaddr_r(uint32_t, int, struct netent *, char *, size_t, struct netent**, int *);
-struct netent	*getnetbyname(const char *);
-int getnetbyname_r(const char *, struct netent *, char *, size_t, struct netent **, int *);
-struct netent	*getnetent(void);
-int getnetent_r(struct netent *, char *, size_t, struct netent **, int *);
-int getnetgrent(char **, char **, char **);
-struct protoent	*getprotobyname(const char *);
-int getprotobyname_r(const char *, struct protoent *, char *, size_t, struct protoent **);
-struct protoent	*getprotobynumber(int);
-int getprotobynumber_r(int, struct protoent *, char *, size_t, struct protoent **);
-struct protoent	*getprotoent(void);
-int getprotoent_r(struct protoent *, char *, size_t, struct protoent **);
-struct servent	*getservbyname(const char *, const char *);
-struct servent	*getservbyport(int, const char *);
-struct servent	*getservent(void);
-void herror(const char *);
-const char	*hstrerror(int);
-int innetgr(const char *, const char *, const char *, const char *);
-void sethostent(int);
-void setnetent(int);
-void setprotoent(int);
+struct hostent* gethostbyaddr(const void*, socklen_t, int);
+int gethostbyaddr_r(const void*, socklen_t, int, struct hostent*, char*, size_t, struct hostent**,
+                    int*);
+struct hostent* gethostbyname(const char*);
+int gethostbyname_r(const char*, struct hostent*, char*, size_t, struct hostent**, int*);
+struct hostent* gethostbyname2(const char*, int);
+int gethostbyname2_r(const char*, int, struct hostent*, char*, size_t, struct hostent**, int*);
+struct hostent* gethostent(void);
+struct netent* getnetbyaddr(uint32_t, int);
+struct netent* getnetbyname(const char*);
+struct protoent* getprotobyname(const char*);
+struct protoent* getprotobynumber(int);
+struct servent* getservbyname(const char*, const char*);
+struct servent* getservbyport(int, const char*);
+struct servent* getservent(void);
+void herror(const char*);
+const char* hstrerror(int);
+
 int getaddrinfo(const char *, const char *, const struct addrinfo *, struct addrinfo **);
 int getnameinfo(const struct sockaddr *, socklen_t, char *, size_t, char *, size_t, int);
 void freeaddrinfo(struct addrinfo *);
 const char	*gai_strerror(int);
-void setnetgrent(const char *);
 void setservent(int);
 
 #pragma GCC visibility pop
diff --git a/libc/include/nsswitch.h b/libc/include/nsswitch.h
index af88433..addbfc8 100644
--- a/libc/include/nsswitch.h
+++ b/libc/include/nsswitch.h
@@ -144,19 +144,6 @@
 
 
 /*
- * Default sourcelists (if nsswitch.conf is missing, corrupt,
- * or the requested database doesn't have an entry)
- */
-extern const ns_src __nsdefaultsrc[];
-extern const ns_src __nsdefaultcompat[];
-extern const ns_src __nsdefaultcompat_forceall[];
-extern const ns_src __nsdefaultfiles[];
-extern const ns_src __nsdefaultfiles_forceall[];
-extern const ns_src __nsdefaultnis[];
-extern const ns_src __nsdefaultnis_forceall[];
-
-
-/*
  * ns_mtab - `nsswitch method table'
  * An nsswitch module provides a mapping from (database name, method name)
  * tuples to the nss_method and associated callback data.  Effectively,
diff --git a/libc/include/pwd.h b/libc/include/pwd.h
index 905bc75..e32825e 100644
--- a/libc/include/pwd.h
+++ b/libc/include/pwd.h
@@ -1,6 +1,6 @@
 /*-
  * Copyright (c) 1989, 1993
- *	The Regents of the University of California.  All rights reserved.
+ *    The Regents of the University of California.  All rights reserved.
  * (c) UNIX System Laboratories, Inc.
  * All or some portions of this file are derived from material licensed
  * to the University of California by American Telephone and Telegraph
@@ -31,7 +31,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *	@(#)pwd.h	8.2 (Berkeley) 1/21/94
+ *    @(#)pwd.h  8.2 (Berkeley) 1/21/94
  */
 
 /*-
@@ -118,6 +118,10 @@
 
 struct passwd* getpwnam(const char*);
 struct passwd* getpwuid(uid_t);
+/* Android has thousands and thousands of ids to iterate through */
+struct passwd* getpwent(void) __attribute__((warning("getpwent is inefficient on Android")));
+void setpwent(void);
+void endpwent(void);
 
 int getpwnam_r(const char*, struct passwd*, char*, size_t, struct passwd**);
 int getpwuid_r(uid_t, struct passwd*, char*, size_t, struct passwd**);
diff --git a/libc/include/resolv.h b/libc/include/resolv.h
index c8899ed..b10aaf4 100644
--- a/libc/include/resolv.h
+++ b/libc/include/resolv.h
@@ -39,11 +39,6 @@
 __BEGIN_DECLS
 #pragma GCC visibility push(default)
 
-struct res_state;
-
-extern struct __res_state *__res_state(void);
-#define _res (*__res_state())
-
 #define b64_ntop __b64_ntop
 #define b64_pton __b64_pton
 extern int b64_ntop(u_char const*, size_t, char*, size_t);
diff --git a/libc/include/sgtty.h b/libc/include/sgtty.h
deleted file mode 100644
index 1ac3100..0000000
--- a/libc/include/sgtty.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*	$NetBSD: sgtty.h,v 1.8 2005/02/03 04:39:32 perry Exp $	*/
-
-/*
- * Copyright (c) 1985, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)sgtty.h	8.1 (Berkeley) 6/2/93
- */
-
-#ifndef _SGTTY_H_
-#define _SGTTY_H_
-
-#ifndef USE_OLD_TTY
-#define	USE_OLD_TTY
-#endif
-#include <sys/ioctl.h>
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-int gtty(int, struct sgttyb *);
-int stty(int, struct sgttyb *);
-__END_DECLS
-
-#endif /* _SGTTY_H_ */
diff --git a/libc/include/stdio_ext.h b/libc/include/stdio_ext.h
index f299e54..de5d715 100644
--- a/libc/include/stdio_ext.h
+++ b/libc/include/stdio_ext.h
@@ -39,8 +39,6 @@
 __BEGIN_DECLS
 
 size_t __fbufsize(FILE*);
-int __freading(FILE*);
-int __fwriting(FILE*);
 int __freadable(FILE*);
 int __fwritable(FILE*);
 int __flbf(FILE*);
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index d0fb0e8..ba4b149 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
@@ -162,14 +162,11 @@
 extern const char* getprogname(void);
 extern void setprogname(const char*);
 
-/* make STLPort happy */
-extern int      mblen(const char *, size_t);
-extern size_t   mbstowcs(wchar_t *, const char *, size_t);
-extern int      mbtowc(wchar_t *, const char *, size_t);
-
-/* Likewise, make libstdc++-v3 happy.  */
-extern int	wctomb(char *, wchar_t);
-extern size_t	wcstombs(char *, const wchar_t *, size_t);
+int mblen(const char*, size_t);
+size_t mbstowcs(wchar_t*, const char*, size_t);
+int mbtowc(wchar_t*, const char*, size_t);
+int wctomb(char*, wchar_t);
+size_t wcstombs(char*, const wchar_t*, size_t);
 
 extern size_t __ctype_get_mb_cur_max(void);
 #define MB_CUR_MAX __ctype_get_mb_cur_max()
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index 2bd058e..b0e7b76 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -454,11 +454,13 @@
 #define __INTRODUCED_IN(api_level) __AVAILABILITY(introduced=api_level)
 #define __DEPRECATED_IN(api_level) __AVAILABILITY(deprecated=api_level)
 #define __REMOVED_IN(api_level) __AVAILABILITY(obsoleted=api_level)
+#define __UNAVAILABLE __attribute__((unavailable))
 #else
 #define __AVAILABILITY(...)
 #define __INTRODUCED_IN(api_level)
 #define __DEPRECATED_IN(api_level)
 #define __REMOVED_IN(api_level)
+#define __UNAVAILABLE __attribute__((__error__("unavailable")))
 #endif // __clang__
 
 #if __has_builtin(__builtin_umul_overflow) || __GNUC__ >= 5
diff --git a/libc/include/sys/user.h b/libc/include/sys/user.h
index 3312981..13fecf9 100644
--- a/libc/include/sys/user.h
+++ b/libc/include/sys/user.h
@@ -31,6 +31,7 @@
 
 #include <sys/cdefs.h>
 #include <stddef.h> /* For size_t. */
+#include <stdint.h>
 
 __BEGIN_DECLS
 
diff --git a/libc/include/wchar.h b/libc/include/wchar.h
index fe068be..f65c988 100644
--- a/libc/include/wchar.h
+++ b/libc/include/wchar.h
@@ -169,8 +169,8 @@
 extern size_t wcslcpy(wchar_t*, const wchar_t*, size_t);
 
 typedef void *wctrans_t;
-extern wint_t towctrans(wint_t, wctrans_t);
-extern wctrans_t wctrans(const char*);
+extern wint_t towctrans(wint_t, wctrans_t) __UNAVAILABLE;
+extern wctrans_t wctrans(const char*) __UNAVAILABLE;
 
 #if __POSIX_VISIBLE >= 200809
 FILE* open_wmemstream(wchar_t**, size_t*);
diff --git a/libc/libc.arm.brillo.map b/libc/libc.arm.brillo.map
index b0c8299..a1373d8 100644
--- a/libc/libc.arm.brillo.map
+++ b/libc/libc.arm.brillo.map
@@ -627,10 +627,6 @@
     madvise;
     mallinfo;
     malloc;
-    malloc_backtrace;
-    malloc_disable;
-    malloc_enable;
-    malloc_iterate;
     malloc_info;
     malloc_usable_size;
     mbrlen;
@@ -1276,12 +1272,19 @@
     catclose;
     catgets;
     catopen;
+    endgrent;
+    endpwent;
     getdomainname;
+    getgrent;
+    getpwent;
     getsubopt;
     hasmntopt;
+    mblen;
     pthread_getname_np;
     quotactl;
     setdomainname;
+    setgrent;
+    setpwent;
     sighold;
     sigignore;
     sigpause;
@@ -1474,4 +1477,8 @@
     android_net_res_stats_get_info_for_net;
     android_net_res_stats_aggregate;
     android_net_res_stats_get_usable_servers;
+    malloc_backtrace;
+    malloc_disable;
+    malloc_enable;
+    malloc_iterate;
 } LIBC_O;
diff --git a/libc/libc.arm.map b/libc/libc.arm.map
index 7a3b8bd..4e69bf1 100644
--- a/libc/libc.arm.map
+++ b/libc/libc.arm.map
@@ -627,10 +627,6 @@
     madvise;
     mallinfo;
     malloc;
-    malloc_backtrace;
-    malloc_disable;
-    malloc_enable;
-    malloc_iterate;
     malloc_info;
     malloc_usable_size;
     mbrlen;
@@ -1276,12 +1272,19 @@
     catclose;
     catgets;
     catopen;
+    endgrent;
+    endpwent;
     getdomainname;
+    getgrent;
+    getpwent;
     getsubopt;
     hasmntopt;
+    mblen;
     pthread_getname_np;
     quotactl;
     setdomainname;
+    setgrent;
+    setpwent;
     sighold;
     sigignore;
     sigpause;
@@ -1480,7 +1483,6 @@
     dlmalloc_inspect_all; # arm x86 mips nobrillo
     dlmalloc_trim; # arm x86 mips nobrillo
     dlmalloc_usable_size; # arm x86 mips nobrillo
-    endpwent; # arm x86 mips nobrillo
     fdprintf; # arm x86 mips nobrillo
     free_malloc_leak_info;
     ftime; # arm x86 mips nobrillo
@@ -1513,4 +1515,8 @@
     android_net_res_stats_get_info_for_net;
     android_net_res_stats_aggregate;
     android_net_res_stats_get_usable_servers;
+    malloc_backtrace;
+    malloc_disable;
+    malloc_enable;
+    malloc_iterate;
 } LIBC_O;
diff --git a/libc/libc.arm64.map b/libc/libc.arm64.map
index 217d95e..7ea74a6 100644
--- a/libc/libc.arm64.map
+++ b/libc/libc.arm64.map
@@ -552,10 +552,6 @@
     madvise;
     mallinfo;
     malloc;
-    malloc_backtrace;
-    malloc_disable;
-    malloc_enable;
-    malloc_iterate;
     malloc_info;
     malloc_usable_size;
     mbrlen;
@@ -1198,12 +1194,19 @@
     catclose;
     catgets;
     catopen;
+    endgrent;
+    endpwent;
     getdomainname;
+    getgrent;
+    getpwent;
     getsubopt;
     hasmntopt;
+    mblen;
     pthread_getname_np;
     quotactl;
     setdomainname;
+    setgrent;
+    setpwent;
     sighold;
     sigignore;
     sigpause;
@@ -1228,4 +1231,8 @@
     android_net_res_stats_get_info_for_net;
     android_net_res_stats_aggregate;
     android_net_res_stats_get_usable_servers;
+    malloc_backtrace;
+    malloc_disable;
+    malloc_enable;
+    malloc_iterate;
 } LIBC_O;
diff --git a/libc/libc.map.txt b/libc/libc.map.txt
index c7f9058..8d1a1f9 100644
--- a/libc/libc.map.txt
+++ b/libc/libc.map.txt
@@ -629,10 +629,6 @@
     madvise;
     mallinfo;
     malloc;
-    malloc_backtrace;
-    malloc_disable;
-    malloc_enable;
-    malloc_iterate;
     malloc_info;
     malloc_usable_size;
     mbrlen;
@@ -1301,12 +1297,19 @@
     catclose;
     catgets;
     catopen;
+    endgrent;
+    endpwent;
     getdomainname;
+    getgrent;
+    getpwent;
     getsubopt;
     hasmntopt;
+    mblen;
     pthread_getname_np;
     quotactl;
     setdomainname;
+    setgrent;
+    setpwent;
     sighold;
     sigignore;
     sigpause;
@@ -1506,7 +1509,6 @@
     dlmalloc_inspect_all; # arm x86 mips nobrillo
     dlmalloc_trim; # arm x86 mips nobrillo
     dlmalloc_usable_size; # arm x86 mips nobrillo
-    endpwent; # arm x86 mips nobrillo
     fdprintf; # arm x86 mips nobrillo
     free_malloc_leak_info;
     ftime; # arm x86 mips nobrillo
@@ -1539,4 +1541,8 @@
     android_net_res_stats_get_info_for_net;
     android_net_res_stats_aggregate;
     android_net_res_stats_get_usable_servers;
+    malloc_backtrace;
+    malloc_disable;
+    malloc_enable;
+    malloc_iterate;
 } LIBC_O;
diff --git a/libc/libc.mips.brillo.map b/libc/libc.mips.brillo.map
index 2b92162..aac1d8c 100644
--- a/libc/libc.mips.brillo.map
+++ b/libc/libc.mips.brillo.map
@@ -625,10 +625,6 @@
     madvise;
     mallinfo;
     malloc;
-    malloc_backtrace;
-    malloc_disable;
-    malloc_enable;
-    malloc_iterate;
     malloc_info;
     malloc_usable_size;
     mbrlen;
@@ -1260,12 +1256,19 @@
     catclose;
     catgets;
     catopen;
+    endgrent;
+    endpwent;
     getdomainname;
+    getgrent;
+    getpwent;
     getsubopt;
     hasmntopt;
+    mblen;
     pthread_getname_np;
     quotactl;
     setdomainname;
+    setgrent;
+    setpwent;
     sighold;
     sigignore;
     sigpause;
@@ -1315,4 +1318,8 @@
     android_net_res_stats_get_info_for_net;
     android_net_res_stats_aggregate;
     android_net_res_stats_get_usable_servers;
+    malloc_backtrace;
+    malloc_disable;
+    malloc_enable;
+    malloc_iterate;
 } LIBC_O;
diff --git a/libc/libc.mips.map b/libc/libc.mips.map
index 934b23b..e514aa1 100644
--- a/libc/libc.mips.map
+++ b/libc/libc.mips.map
@@ -625,10 +625,6 @@
     madvise;
     mallinfo;
     malloc;
-    malloc_backtrace;
-    malloc_disable;
-    malloc_enable;
-    malloc_iterate;
     malloc_info;
     malloc_usable_size;
     mbrlen;
@@ -1260,12 +1256,19 @@
     catclose;
     catgets;
     catopen;
+    endgrent;
+    endpwent;
     getdomainname;
+    getgrent;
+    getpwent;
     getsubopt;
     hasmntopt;
+    mblen;
     pthread_getname_np;
     quotactl;
     setdomainname;
+    setgrent;
+    setpwent;
     sighold;
     sigignore;
     sigpause;
@@ -1322,7 +1325,6 @@
     dlmalloc_inspect_all; # arm x86 mips nobrillo
     dlmalloc_trim; # arm x86 mips nobrillo
     dlmalloc_usable_size; # arm x86 mips nobrillo
-    endpwent; # arm x86 mips nobrillo
     fdprintf; # arm x86 mips nobrillo
     free_malloc_leak_info;
     ftime; # arm x86 mips nobrillo
@@ -1354,4 +1356,8 @@
     android_net_res_stats_get_info_for_net;
     android_net_res_stats_aggregate;
     android_net_res_stats_get_usable_servers;
+    malloc_backtrace;
+    malloc_disable;
+    malloc_enable;
+    malloc_iterate;
 } LIBC_O;
diff --git a/libc/libc.mips64.map b/libc/libc.mips64.map
index 217d95e..7ea74a6 100644
--- a/libc/libc.mips64.map
+++ b/libc/libc.mips64.map
@@ -552,10 +552,6 @@
     madvise;
     mallinfo;
     malloc;
-    malloc_backtrace;
-    malloc_disable;
-    malloc_enable;
-    malloc_iterate;
     malloc_info;
     malloc_usable_size;
     mbrlen;
@@ -1198,12 +1194,19 @@
     catclose;
     catgets;
     catopen;
+    endgrent;
+    endpwent;
     getdomainname;
+    getgrent;
+    getpwent;
     getsubopt;
     hasmntopt;
+    mblen;
     pthread_getname_np;
     quotactl;
     setdomainname;
+    setgrent;
+    setpwent;
     sighold;
     sigignore;
     sigpause;
@@ -1228,4 +1231,8 @@
     android_net_res_stats_get_info_for_net;
     android_net_res_stats_aggregate;
     android_net_res_stats_get_usable_servers;
+    malloc_backtrace;
+    malloc_disable;
+    malloc_enable;
+    malloc_iterate;
 } LIBC_O;
diff --git a/libc/libc.x86.brillo.map b/libc/libc.x86.brillo.map
index d973ac1..f14861d 100644
--- a/libc/libc.x86.brillo.map
+++ b/libc/libc.x86.brillo.map
@@ -623,10 +623,6 @@
     madvise;
     mallinfo;
     malloc;
-    malloc_backtrace;
-    malloc_disable;
-    malloc_enable;
-    malloc_iterate;
     malloc_info;
     malloc_usable_size;
     mbrlen;
@@ -1258,12 +1254,19 @@
     catclose;
     catgets;
     catopen;
+    endgrent;
+    endpwent;
     getdomainname;
+    getgrent;
+    getpwent;
     getsubopt;
     hasmntopt;
+    mblen;
     pthread_getname_np;
     quotactl;
     setdomainname;
+    setgrent;
+    setpwent;
     sighold;
     sigignore;
     sigpause;
@@ -1314,4 +1317,8 @@
     android_net_res_stats_get_info_for_net;
     android_net_res_stats_aggregate;
     android_net_res_stats_get_usable_servers;
+    malloc_backtrace;
+    malloc_disable;
+    malloc_enable;
+    malloc_iterate;
 } LIBC_O;
diff --git a/libc/libc.x86.map b/libc/libc.x86.map
index b3f9394..f6b6ea1 100644
--- a/libc/libc.x86.map
+++ b/libc/libc.x86.map
@@ -623,10 +623,6 @@
     madvise;
     mallinfo;
     malloc;
-    malloc_backtrace;
-    malloc_disable;
-    malloc_enable;
-    malloc_iterate;
     malloc_info;
     malloc_usable_size;
     mbrlen;
@@ -1258,12 +1254,19 @@
     catclose;
     catgets;
     catopen;
+    endgrent;
+    endpwent;
     getdomainname;
+    getgrent;
+    getpwent;
     getsubopt;
     hasmntopt;
+    mblen;
     pthread_getname_np;
     quotactl;
     setdomainname;
+    setgrent;
+    setpwent;
     sighold;
     sigignore;
     sigpause;
@@ -1321,7 +1324,6 @@
     dlmalloc_inspect_all; # arm x86 mips nobrillo
     dlmalloc_trim; # arm x86 mips nobrillo
     dlmalloc_usable_size; # arm x86 mips nobrillo
-    endpwent; # arm x86 mips nobrillo
     fdprintf; # arm x86 mips nobrillo
     free_malloc_leak_info;
     ftime; # arm x86 mips nobrillo
@@ -1353,4 +1355,8 @@
     android_net_res_stats_get_info_for_net;
     android_net_res_stats_aggregate;
     android_net_res_stats_get_usable_servers;
+    malloc_backtrace;
+    malloc_disable;
+    malloc_enable;
+    malloc_iterate;
 } LIBC_O;
diff --git a/libc/libc.x86_64.map b/libc/libc.x86_64.map
index 217d95e..7ea74a6 100644
--- a/libc/libc.x86_64.map
+++ b/libc/libc.x86_64.map
@@ -552,10 +552,6 @@
     madvise;
     mallinfo;
     malloc;
-    malloc_backtrace;
-    malloc_disable;
-    malloc_enable;
-    malloc_iterate;
     malloc_info;
     malloc_usable_size;
     mbrlen;
@@ -1198,12 +1194,19 @@
     catclose;
     catgets;
     catopen;
+    endgrent;
+    endpwent;
     getdomainname;
+    getgrent;
+    getpwent;
     getsubopt;
     hasmntopt;
+    mblen;
     pthread_getname_np;
     quotactl;
     setdomainname;
+    setgrent;
+    setpwent;
     sighold;
     sigignore;
     sigpause;
@@ -1228,4 +1231,8 @@
     android_net_res_stats_get_info_for_net;
     android_net_res_stats_aggregate;
     android_net_res_stats_get_usable_servers;
+    malloc_backtrace;
+    malloc_disable;
+    malloc_enable;
+    malloc_iterate;
 } LIBC_O;
diff --git a/libc/tools/gensyscalls.py b/libc/tools/gensyscalls.py
index f7785d6..04ccf39 100755
--- a/libc/tools/gensyscalls.py
+++ b/libc/tools/gensyscalls.py
@@ -62,9 +62,11 @@
 
 arm_eabi_call_default = syscall_stub_header + """\
     mov     ip, r7
+    .cfi_register r7, ip
     ldr     r7, =%(__NR_name)s
     swi     #0
     mov     r7, ip
+    .cfi_restore r7
     cmn     r0, #(MAX_ERRNO + 1)
     bxls    lr
     neg     r0, r0
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 0fdf90d..c193861 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -2365,12 +2365,16 @@
 }
 
 bool init_namespaces(const char* public_ns_sonames, const char* anon_ns_library_path) {
-  CHECK(public_ns_sonames != nullptr);
   if (g_public_namespace_initialized) {
     DL_ERR("public namespace has already been initialized.");
     return false;
   }
 
+  if (public_ns_sonames == nullptr || public_ns_sonames[0] == '\0') {
+    DL_ERR("error initializing public namespace: the list of public libraries is empty.");
+    return false;
+  }
+
   std::vector<std::string> sonames = android::base::Split(public_ns_sonames, ":");
 
   ProtectedDataGuard guard;
diff --git a/tests/Android.mk b/tests/Android.mk
index 7292d9d..8e190ea 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -104,6 +104,7 @@
     sys_personality_test.cpp \
     sys_prctl_test.cpp \
     sys_procfs_test.cpp \
+    sys_ptrace_test.cpp \
     sys_quota_test.cpp \
     sys_resource_test.cpp \
     sys_select_test.cpp \
diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp
index 87e5dbc..420c934 100644
--- a/tests/dlext_test.cpp
+++ b/tests/dlext_test.cpp
@@ -629,6 +629,10 @@
   ASSERT_STREQ("android_init_namespaces failed: error initializing public namespace: "
                "\"libnstest_public.so\" was not found in the default namespace", dlerror());
 
+  ASSERT_FALSE(android_init_namespaces("", nullptr));
+  ASSERT_STREQ("android_init_namespaces failed: error initializing public namespace: "
+               "the list of public libraries is empty.", dlerror());
+
   const std::string lib_path = std::string(getenv("ANDROID_DATA")) + NATIVE_TESTS_PATH;
 
   const std::string lib_public_path = lib_path + "/public_namespace_libs/" + g_public_lib;
diff --git a/tests/grp_pwd_test.cpp b/tests/grp_pwd_test.cpp
index 29cd907..a684780 100644
--- a/tests/grp_pwd_test.cpp
+++ b/tests/grp_pwd_test.cpp
@@ -26,6 +26,10 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include <bitset>
+
+#include <private/android_filesystem_config.h>
+
 enum uid_type_t {
   TYPE_SYSTEM,
   TYPE_APP
@@ -179,6 +183,46 @@
   check_get_passwd("u1_i0", 199000, TYPE_APP);
 }
 
+TEST(getpwent, iterate) {
+  passwd* pwd;
+  std::bitset<10000> exist;
+  bool application = false;
+
+  exist.reset();
+
+  setpwent();
+  while ((pwd = getpwent()) != NULL) {
+    ASSERT_TRUE(NULL != pwd->pw_name);
+    ASSERT_EQ(pwd->pw_gid, pwd->pw_uid);
+    ASSERT_EQ(NULL, pwd->pw_passwd);
+#ifdef __LP64__
+    ASSERT_TRUE(NULL == pwd->pw_gecos);
+#endif
+    ASSERT_TRUE(NULL != pwd->pw_shell);
+    if (pwd->pw_uid >= exist.size()) {
+      ASSERT_STREQ("/data", pwd->pw_dir);
+      application = true;
+    } else {
+      ASSERT_STREQ("/", pwd->pw_dir);
+      ASSERT_FALSE(exist[pwd->pw_uid]);
+      exist[pwd->pw_uid] = true;
+    }
+  }
+  endpwent();
+
+  // Required content
+  for (size_t n = 0; n < android_id_count; ++n) {
+    ASSERT_TRUE(exist[android_ids[n].aid]);
+  }
+  for (size_t n = 2900; n < 2999; ++n) {
+    ASSERT_TRUE(exist[n]);
+  }
+  for (size_t n = 5000; n < 5999; ++n) {
+    ASSERT_TRUE(exist[n]);
+  }
+  ASSERT_TRUE(application);
+}
+
 static void check_group(const group* grp, const char* group_name, gid_t gid) {
   ASSERT_TRUE(grp != NULL);
   ASSERT_STREQ(group_name, grp->gr_name);
@@ -373,3 +417,38 @@
   ASSERT_EQ(0, getgrnam_r("root", &grp_storage, buf, size, &grp));
   check_group(grp, "root", 0);
 }
+
+TEST(getgrent, iterate) {
+  group* grp;
+  std::bitset<10000> exist;
+  bool application = false;
+
+  exist.reset();
+
+  setgrent();
+  while ((grp = getgrent()) != NULL) {
+    ASSERT_TRUE(grp->gr_name != NULL);
+    ASSERT_TRUE(grp->gr_mem != NULL);
+    ASSERT_STREQ(grp->gr_name, grp->gr_mem[0]);
+    ASSERT_TRUE(grp->gr_mem[1] == NULL);
+    if (grp->gr_gid >= exist.size()) {
+      application = true;
+    } else {
+      ASSERT_FALSE(exist[grp->gr_gid]);
+      exist[grp->gr_gid] = true;
+    }
+  }
+  endgrent();
+
+  // Required content
+  for (size_t n = 0; n < android_id_count; ++n) {
+    ASSERT_TRUE(exist[android_ids[n].aid]);
+  }
+  for (size_t n = 2900; n < 2999; ++n) {
+    ASSERT_TRUE(exist[n]);
+  }
+  for (size_t n = 5000; n < 5999; ++n) {
+    ASSERT_TRUE(exist[n]);
+  }
+  ASSERT_TRUE(application);
+}
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp
index 05438eb..773230f 100644
--- a/tests/stdlib_test.cpp
+++ b/tests/stdlib_test.cpp
@@ -537,3 +537,26 @@
 
   ASSERT_EQ(-1, getsubopt(&subopts, tokens, &value));
 }
+
+TEST(stdlib, mblen) {
+  // "If s is a null pointer, mblen() shall return a non-zero or 0 value, if character encodings,
+  // respectively, do or do not have state-dependent encodings." We're always UTF-8.
+  EXPECT_EQ(0, mblen(nullptr, 1));
+
+  ASSERT_STREQ("C.UTF-8", setlocale(LC_ALL, "C.UTF-8"));
+
+  // 1-byte UTF-8.
+  EXPECT_EQ(1, mblen("abcdef", 6));
+  // 2-byte UTF-8.
+  EXPECT_EQ(2, mblen("\xc2\xa2" "cdef", 6));
+  // 3-byte UTF-8.
+  EXPECT_EQ(3, mblen("\xe2\x82\xac" "def", 6));
+  // 4-byte UTF-8.
+  EXPECT_EQ(4, mblen("\xf0\xa4\xad\xa2" "ef", 6));
+
+  // Illegal over-long sequence.
+  ASSERT_EQ(-1, mblen("\xf0\x82\x82\xac" "ef", 6));
+
+  // "mblen() shall ... return 0 (if s points to the null byte)".
+  EXPECT_EQ(0, mblen("", 1));
+}
diff --git a/tests/sys_ptrace_test.cpp b/tests/sys_ptrace_test.cpp
new file mode 100644
index 0000000..bd84d30
--- /dev/null
+++ b/tests/sys_ptrace_test.cpp
@@ -0,0 +1,202 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <sys/ptrace.h>
+
+#include <elf.h>
+#include <sched.h>
+#include <sys/prctl.h>
+#include <sys/uio.h>
+#include <sys/user.h>
+#include <unistd.h>
+
+#include <gtest/gtest.h>
+
+// Host libc does not define this.
+#ifndef TRAP_HWBKPT
+#define TRAP_HWBKPT 4
+#endif
+
+template<typename T>
+static void __attribute__((noreturn)) fork_child(unsigned cpu, T &data) {
+  // Extra precaution: make sure we go away if anything happens to our parent.
+  if (prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0) == -1) {
+    perror("prctl(PR_SET_PDEATHSIG)");
+    _exit(1);
+  }
+
+  cpu_set_t cpus;
+  CPU_ZERO(&cpus);
+  CPU_SET(cpu, &cpus);
+  if (sched_setaffinity(0, sizeof cpus, &cpus) == -1) {
+    perror("sched_setaffinity");
+    _exit(2);
+  }
+  if (ptrace(PTRACE_TRACEME, 0, nullptr, nullptr) == -1) {
+    perror("ptrace(PTRACE_TRACEME)");
+    _exit(3);
+  }
+
+  raise(SIGSTOP); // Synchronize with the tracer, let it set the watchpoint.
+
+  data = 1; // Now trigger the watchpoint.
+
+  _exit(0);
+}
+
+class ChildGuard {
+ public:
+  ChildGuard(pid_t pid) : pid(pid) {}
+
+  ~ChildGuard() {
+    kill(pid, SIGKILL);
+    int status;
+    waitpid(pid, &status, 0);
+  }
+
+ private:
+  pid_t pid;
+};
+
+static bool are_watchpoints_supported(pid_t child) {
+#if defined(__arm__)
+  long capabilities;
+  long result = ptrace(PTRACE_GETHBPREGS, child, 0, &capabilities);
+  if (result == -1) {
+    EXPECT_EQ(EIO, errno);
+    return false;
+  }
+  return ((capabilities >> 8) & 0xff) > 0;
+#elif defined(__aarch64__)
+  user_hwdebug_state dreg_state;
+  iovec iov;
+  iov.iov_base = &dreg_state;
+  iov.iov_len = sizeof(dreg_state);
+
+  long result = ptrace(PTRACE_GETREGSET, child, NT_ARM_HW_WATCH, &iov);
+  if (result == -1) {
+    EXPECT_EQ(EINVAL, errno);
+    return false;
+  }
+  return (dreg_state.dbg_info & 0xff) > 0;
+#elif defined(__i386__) || defined(__x86_64__)
+  // We assume watchpoints are always supported on x86.
+  (void) child;
+  return true;
+#else
+  // TODO: mips support.
+  (void) child;
+  return false;
+#endif
+}
+
+static void set_watchpoint(pid_t child, const void *address, size_t size) {
+#if defined(__arm__) || defined(__aarch64__)
+  const unsigned byte_mask = (1 << size) - 1;
+  const unsigned type = 2; // Write.
+  const unsigned enable = 1;
+  const unsigned control = byte_mask << 5 | type << 3 | enable;
+
+#ifdef __arm__
+  ASSERT_EQ(0, ptrace(PTRACE_SETHBPREGS, child, -1, &address)) << strerror(errno);
+  ASSERT_EQ(0, ptrace(PTRACE_SETHBPREGS, child, -2, &control)) << strerror(errno);
+#else // aarch64
+  user_hwdebug_state dreg_state;
+  memset(&dreg_state, 0, sizeof dreg_state);
+  dreg_state.dbg_regs[0].addr = reinterpret_cast<uintptr_t>(address);
+  dreg_state.dbg_regs[0].ctrl = control;
+
+  iovec iov;
+  iov.iov_base = &dreg_state;
+  iov.iov_len = offsetof(user_hwdebug_state, dbg_regs) + sizeof(dreg_state.dbg_regs[0]);
+
+  ASSERT_EQ(0, ptrace(PTRACE_SETREGSET, child, NT_ARM_HW_WATCH, &iov)) << strerror(errno);
+#endif
+#elif defined(__i386__) || defined(__x86_64__)
+  ASSERT_EQ(0, ptrace(PTRACE_POKEUSER, child, offsetof(user, u_debugreg[0]), address)) << strerror(errno);
+  errno = 0;
+  unsigned data = ptrace(PTRACE_PEEKUSER, child, offsetof(user, u_debugreg[7]), nullptr);
+  ASSERT_EQ(0, errno);
+
+  const unsigned size_flag = (size == 8) ? 2 : size - 1;
+  const unsigned enable = 1;
+  const unsigned type = 1; // Write.
+
+  const unsigned mask = 3 << 18 | 3 << 16 | 1;
+  const unsigned value = size_flag << 18 | type << 16 | enable;
+  data &= mask;
+  data |= value;
+  ASSERT_EQ(0, ptrace(PTRACE_POKEUSER, child, offsetof(user, u_debugreg[7]), data)) << strerror(errno);
+#else
+  (void) child;
+  (void) address;
+  (void) size;
+#endif
+}
+
+template<typename T>
+static void run_watchpoint_test_impl(unsigned cpu) {
+  alignas(8) T data = 0;
+
+  pid_t child = fork();
+  ASSERT_NE(-1, child) << strerror(errno);
+  if (child == 0) fork_child(cpu, data);
+
+  ChildGuard guard(child);
+
+  int status;
+  ASSERT_EQ(child, waitpid(child, &status, __WALL)) << strerror(errno);
+  ASSERT_TRUE(WIFSTOPPED(status)) << "Status was: " << status;
+  ASSERT_EQ(SIGSTOP, WSTOPSIG(status)) << "Status was: " << status;
+
+  if (!are_watchpoints_supported(child)) return;
+
+  set_watchpoint(child, &data, sizeof data);
+
+  ASSERT_EQ(0, ptrace(PTRACE_CONT, child, nullptr, nullptr)) << strerror(errno);
+  ASSERT_EQ(child, waitpid(child, &status, __WALL)) << strerror(errno);
+  ASSERT_TRUE(WIFSTOPPED(status)) << "Status was: " << status;
+  ASSERT_EQ(SIGTRAP, WSTOPSIG(status)) << "Status was: " << status;
+
+  siginfo_t siginfo;
+  ASSERT_EQ(0, ptrace(PTRACE_GETSIGINFO, child, nullptr, &siginfo)) << strerror(errno);
+  ASSERT_EQ(TRAP_HWBKPT, siginfo.si_code);
+#if defined(__arm__) || defined(__aarch64__)
+  ASSERT_EQ(&data, siginfo.si_addr);
+#endif
+}
+
+static void run_watchpoint_test(unsigned cpu) {
+  run_watchpoint_test_impl<uint8_t>(cpu);
+  run_watchpoint_test_impl<uint16_t>(cpu);
+  run_watchpoint_test_impl<uint32_t>(cpu);
+#if __LP64__
+  run_watchpoint_test_impl<uint64_t>(cpu);
+#endif
+}
+
+// Test watchpoint API. The test is considered successful if our watchpoints get hit OR the
+// system reports that watchpoint support is not present. We run the test for different
+// watchpoint sizes, while pinning the process to each cpu in turn, for better coverage.
+TEST(ptrace, watchpoint_stress) {
+  cpu_set_t available_cpus;
+  ASSERT_EQ(0, sched_getaffinity(0, sizeof available_cpus, &available_cpus));
+
+  for (size_t cpu = 0; cpu < CPU_SETSIZE; ++cpu) {
+    if (!CPU_ISSET(cpu, &available_cpus)) continue;
+    run_watchpoint_test(cpu);
+  }
+}