Merge "Added ftw64, nftw64"
diff --git a/HACKING.txt b/HACKING.txt
new file mode 100644
index 0000000..f614b69
--- /dev/null
+++ b/HACKING.txt
@@ -0,0 +1,163 @@
+Working on bionic
+=================
+
+What are the big pieces of bionic?
+----------------------------------
+
+libc/ --- libc.so, libc.a
+  The C library. Stuff like fopen(3) and kill(2).
+libm/ --- libm.so, libm.a
+  The math library. Traditionally Unix systems kept stuff like sin(3) and
+  cos(3) in a separate library to save space in the days before shared
+  libraries.
+libdl/ --- libdl.so
+  The dynamic linker interface library. This is actually just a bunch of
+  stubs that the dynamic linker replaces with pointers to its own
+  implementation at runtime. This is where stuff like dlopen(3) lives.
+libstdc++/ --- libstdc++.so
+  The C++ ABI support functions. The C++ compiler doesn't know how to
+  implement thread-safe static initialization and the like, so it just calls
+  functions that are supplied by the system. Stuff like __cxa_guard_acquire
+  and __cxa_pure_virtual live here.
+
+linker/ --- /system/bin/linker and /system/bin/linker64
+  The dynamic linker. When you run a dynamically-linked executable, its ELF
+  file has a DT_INTERP entry that says "use the following program to start me".
+  On Android, that's either linker or linker64 (depending on whether it's a
+  32-bit or 64-bit executable). It's responsible for loading the ELF executable
+  into memory and resolving references to symbols (so that when your code tries
+  to jump to fopen(3), say, it lands in the right place).
+
+tests/ --- unit tests
+  The tests/ directory contains unit tests. Roughly arranged as one file per
+  publicly-exported header file.
+benchmarks/ --- benchmarks
+  The benchmarks/ directory contains benchmarks.
+
+
+What's in libc/?
+----------------
+
+libc/
+  arch-arm/
+  arch-arm64/
+  arch-common/
+  arch-mips/
+  arch-mips64/
+  arch-x86/
+  arch-x86_64/
+    # Each architecture has its own subdirectory for stuff that isn't shared
+    # because it's architecture-specific. There will be a .mk file in here that
+    # drags in all the architecture-specific files.
+    bionic/
+      # Every architecture needs a handful of machine-specific assembler files.
+      # They live here.
+    include/
+      machine/
+        # The majority of header files are actually in libc/include/, but many
+        # of them pull in a <machine/something.h> for things like limits,
+        # endianness, and how floating point numbers are represented. Those
+        # headers live here.
+    string/
+      # Most architectures have a handful of optional assembler files
+      # implementing optimized versions of various routines. The <string.h>
+      # functions are particular favorites.
+    syscalls/
+      # The syscalls directories contain script-generated assembler files.
+      # See 'Adding system calls' later.
+
+  include/
+    # The public header files on everyone's include path. These are a mixture of
+    # files written by us and files taken from BSD.
+
+  kernel/
+    # The kernel uapi header files. These are scrubbed copies of the originals
+    # in external/kernel-headers/. These files must not be edited directly. The
+    # generate_uapi_headers.sh script should be used to go from a kernel tree to
+    # external/kernel-headers/ --- this takes care of the architecture-specific
+    # details. The update_all.py script should be used to regenerate bionic's
+    # scrubbed headers from external/kernel-headers/.
+
+  private/
+    # These are private header files meant for use within bionic itself.
+
+  netbsd/
+  stdio/
+  stdlib/
+  string/
+  unistd/
+  wchar/
+    # These are legacy files of unknown provenance. In the past, bionic was a
+    # mess of random versions of random files from all three of FreeBSD, NetBSD,
+    # and OpenBSD! We've been working to clean that up, but these directories
+    # are basically where all the stuff we haven't got to yet lives.
+    # The 'netbsd' directory misleadingly contains the DNS resolver (which will
+    # probably be forked sometime soon, and that directory simply renamed).
+    # The other directories contain stuff that still needs to be sorted.
+
+  upstream-dlmalloc/
+  upstream-freebsd/
+  upstream-netbsd/
+  upstream-openbsd/
+    # These directories contain unmolested upstream source. Any time we can
+    # just use a BSD implementation of something unmodified, we should.
+    # See files like netbsd-compat.h for various ways in which we manage to
+    # build BSD source in bionic.
+
+  bionic/
+    # This is the biggest mess. The C++ files are files we own, typically
+    # because the Linux kernel interface is sufficiently different that we
+    # can't use any of the BSD implementations. The C files are usually
+    # legacy mess that needs to be sorted out, either by replacing it with
+    # current upstream source in one of the upstream directories or by
+    # switching the file to C++ and cleaning it up.
+
+  tools/
+    # Various tools used to maintain bionic.
+
+  tzcode/
+    # A modified superset of the IANA tzcode. Most of the modifications relate
+    # to Android's use of a single file (with corresponding index) to contain
+    # time zone data.
+  zoneinfo/
+    # Android-format time zone data.
+    # See 'Updating tzdata' later.
+
+
+Adding system calls
+-------------------
+
+Adding a system call usually involves:
+
+  1. Add entries to SYSCALLS.TXT.
+     See SYSCALLS.TXT itself for documentation on the format.
+  2. Run the gensyscalls.py script.
+  3. Add constants (and perhaps types) to the appropriate header file.
+     Note that you should check to see whether the constants are already in
+     kernel uapi header files, in which case you just need to make sure that
+     the appropriate POSIX header file in libc/include/ includes the
+     relevant file or files.
+  4. Add function declarations to the appropriate header file.
+  5. Add at least basic tests. Even a test that deliberately supplies
+     an invalid argument helps check that we're generating the right symbol
+     and have the right declaration in the header file. (And strace(1) can
+     confirm that the correct system call is being made.)
+
+
+Updating kernel header files
+----------------------------
+
+As mentioned above, this is currently a two-step process:
+
+  1. Use generate_uapi_headers.sh to go from a Linux source tree to appropriate
+     contents for external/kernel-headers/.
+  2. Run update_all.py to scrub those headers and import them into bionic.
+
+
+Updating tzdata
+---------------
+
+This is fully automated:
+
+  1. Run update-tzdata.py.
+
diff --git a/libc/Android.mk b/libc/Android.mk
index 41b1b82..1bee427 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -38,9 +38,6 @@
 # =========================================================
 libc_common_src_files := \
     bionic/arc4random.c \
-    bionic/atoi.c \
-    bionic/atol.c \
-    bionic/atoll.c \
     bionic/bindresvport.c \
     bionic/clearenv.c \
     bionic/daemon.c \
@@ -50,7 +47,6 @@
     bionic/fdprintf.c \
     bionic/flockfile.c \
     bionic/ftime.c \
-    bionic/ftok.c \
     bionic/fts.c \
     bionic/getdtablesize.c \
     bionic/gethostname.c \
@@ -68,7 +64,6 @@
     bionic/memmem.c \
     bionic/memswap.c \
     bionic/pathconf.c \
-    bionic/perror.c \
     bionic/ptsname.c \
     bionic/ptsname_r.c \
     bionic/pututline.c \
@@ -81,11 +76,9 @@
     bionic/sigblock.c \
     bionic/siginterrupt.c \
     bionic/sigsetmask.c \
-    bionic/strndup.c \
     bionic/strntoimax.c \
     bionic/strntoumax.c \
     bionic/strtotimeval.c \
-    bionic/system_properties.c \
     bionic/system_properties_compat.c \
     bionic/tcgetpgrp.c \
     bionic/tcsetpgrp.c \
@@ -95,99 +88,30 @@
     bionic/utmp.c \
     bionic/wcscoll.c \
     stdio/asprintf.c \
-    stdio/fflush.c \
-    stdio/fgetc.c \
     stdio/findfp.c \
     stdio/fprintf.c \
-    stdio/fputc.c \
     stdio/fread.c \
     stdio/freopen.c \
-    stdio/fscanf.c \
-    stdio/fseek.c \
-    stdio/ftell.c \
     stdio/fvwrite.c \
-    stdio/gets.c \
-    stdio/printf.c \
-    stdio/refill.c \
-    stdio/rewind.c \
-    stdio/scanf.c \
     stdio/snprintf.c\
     stdio/sprintf.c \
     stdio/sscanf.c \
-    stdio/stdio.c \
-    stdio/ungetc.c \
-    stdio/vasprintf.c \
     stdio/vfprintf.c \
     stdio/vfscanf.c \
-    stdio/vprintf.c \
-    stdio/vscanf.c \
-    stdio/vsnprintf.c \
-    stdio/vsprintf.c \
     stdio/vsscanf.c \
-    stdio/wbuf.c \
     stdlib/atexit.c \
     stdlib/ctype_.c \
     stdlib/getenv.c \
     stdlib/putenv.c \
     stdlib/setenv.c \
     stdlib/strtod.c \
-    stdlib/strtoimax.c \
-    stdlib/strtol.c \
-    stdlib/strtoll.c \
-    stdlib/strtoul.c \
-    stdlib/strtoull.c \
-    stdlib/strtoumax.c \
-    stdlib/tolower_.c \
-    stdlib/toupper_.c \
-    string/strcasecmp.c \
-    string/strcspn.c \
-    string/strdup.c \
-    string/strpbrk.c \
-    string/strsep.c \
-    string/strspn.c \
-    string/strstr.c \
-    string/strtok.c \
     unistd/alarm.c \
-    unistd/exec.c \
-    unistd/fnmatch.c \
     unistd/syslog.c \
     unistd/system.c \
     unistd/time.c \
     wchar/wcswidth.c \
     wchar/wcsxfrm.c \
 
-
-libc_dns_src_files += \
-    netbsd/gethnamaddr.c \
-    netbsd/inet/nsap_addr.c \
-    netbsd/nameser/ns_name.c \
-    netbsd/nameser/ns_netint.c \
-    netbsd/nameser/ns_parse.c \
-    netbsd/nameser/ns_print.c \
-    netbsd/nameser/ns_samedomain.c \
-    netbsd/nameser/ns_ttl.c \
-    netbsd/net/base64.c \
-    netbsd/net/getaddrinfo.c \
-    netbsd/net/getnameinfo.c \
-    netbsd/net/getservbyname.c \
-    netbsd/net/getservbyport.c \
-    netbsd/net/getservent.c \
-    netbsd/net/nsdispatch.c \
-    netbsd/resolv/__dn_comp.c \
-    netbsd/resolv/herror.c \
-    netbsd/resolv/res_cache.c \
-    netbsd/resolv/__res_close.c \
-    netbsd/resolv/res_comp.c \
-    netbsd/resolv/res_data.c \
-    netbsd/resolv/res_debug.c \
-    netbsd/resolv/res_init.c \
-    netbsd/resolv/res_mkquery.c \
-    netbsd/resolv/res_query.c \
-    netbsd/resolv/__res_send.c \
-    netbsd/resolv/res_send.c \
-    netbsd/resolv/res_state.c \
-
-
 # Fortify implementations of libc functions.
 libc_common_src_files += \
     bionic/__FD_chk.cpp \
@@ -299,6 +223,7 @@
     bionic/stubs.cpp \
     bionic/symlink.cpp \
     bionic/sysconf.cpp \
+    bionic/system_properties.cpp \
     bionic/sys_siglist.c \
     bionic/sys_signame.c \
     bionic/tdestroy.cpp \
@@ -310,42 +235,17 @@
     bionic/wait.cpp \
     bionic/wchar.cpp \
 
-
 libc_upstream_freebsd_src_files := \
     upstream-freebsd/lib/libc/gen/sleep.c \
     upstream-freebsd/lib/libc/gen/usleep.c \
-    upstream-freebsd/lib/libc/stdio/clrerr.c \
     upstream-freebsd/lib/libc/stdio/fclose.c \
-    upstream-freebsd/lib/libc/stdio/fdopen.c \
-    upstream-freebsd/lib/libc/stdio/feof.c \
-    upstream-freebsd/lib/libc/stdio/ferror.c \
-    upstream-freebsd/lib/libc/stdio/fgetln.c \
-    upstream-freebsd/lib/libc/stdio/fgetpos.c \
-    upstream-freebsd/lib/libc/stdio/fgets.c \
-    upstream-freebsd/lib/libc/stdio/fileno.c \
     upstream-freebsd/lib/libc/stdio/flags.c \
     upstream-freebsd/lib/libc/stdio/fopen.c \
-    upstream-freebsd/lib/libc/stdio/fpurge.c \
-    upstream-freebsd/lib/libc/stdio/fputs.c \
-    upstream-freebsd/lib/libc/stdio/fsetpos.c \
-    upstream-freebsd/lib/libc/stdio/funopen.c \
-    upstream-freebsd/lib/libc/stdio/fwalk.c \
     upstream-freebsd/lib/libc/stdio/fwrite.c \
-    upstream-freebsd/lib/libc/stdio/getc.c \
-    upstream-freebsd/lib/libc/stdio/getchar.c \
     upstream-freebsd/lib/libc/stdio/makebuf.c \
     upstream-freebsd/lib/libc/stdio/mktemp.c \
-    upstream-freebsd/lib/libc/stdio/putc.c \
-    upstream-freebsd/lib/libc/stdio/putchar.c \
-    upstream-freebsd/lib/libc/stdio/puts.c \
     upstream-freebsd/lib/libc/stdio/putw.c \
-    upstream-freebsd/lib/libc/stdio/remove.c \
-    upstream-freebsd/lib/libc/stdio/rget.c \
-    upstream-freebsd/lib/libc/stdio/setbuf.c \
-    upstream-freebsd/lib/libc/stdio/setbuffer.c \
     upstream-freebsd/lib/libc/stdio/setvbuf.c \
-    upstream-freebsd/lib/libc/stdio/tempnam.c \
-    upstream-freebsd/lib/libc/stdio/tmpnam.c \
     upstream-freebsd/lib/libc/stdio/wsetup.c \
     upstream-freebsd/lib/libc/stdlib/abs.c \
     upstream-freebsd/lib/libc/stdlib/getopt_long.c \
@@ -379,47 +279,45 @@
 libc_upstream_netbsd_src_files := \
     upstream-netbsd/common/lib/libc/hash/sha1/sha1.c \
     upstream-netbsd/common/lib/libc/inet/inet_addr.c \
-    upstream-netbsd/libc/gen/ftw.c \
-    upstream-netbsd/libc/gen/nftw.c \
-    upstream-netbsd/libc/gen/nice.c \
-    upstream-netbsd/libc/gen/popen.c \
-    upstream-netbsd/libc/gen/psignal.c \
-    upstream-netbsd/libc/gen/setjmperr.c \
-    upstream-netbsd/libc/gen/utime.c \
-    upstream-netbsd/libc/inet/inet_ntoa.c \
-    upstream-netbsd/libc/inet/inet_ntop.c \
-    upstream-netbsd/libc/inet/inet_pton.c \
-    upstream-netbsd/libc/isc/ev_streams.c \
-    upstream-netbsd/libc/isc/ev_timers.c \
-    upstream-netbsd/libc/regex/regcomp.c \
-    upstream-netbsd/libc/regex/regerror.c \
-    upstream-netbsd/libc/regex/regexec.c \
-    upstream-netbsd/libc/regex/regfree.c \
-    upstream-netbsd/libc/stdio/getdelim.c \
-    upstream-netbsd/libc/stdio/getline.c \
-    upstream-netbsd/libc/stdlib/bsearch.c \
-    upstream-netbsd/libc/stdlib/div.c \
-    upstream-netbsd/libc/stdlib/drand48.c \
-    upstream-netbsd/libc/stdlib/erand48.c \
-    upstream-netbsd/libc/stdlib/exit.c \
-    upstream-netbsd/libc/stdlib/jrand48.c \
-    upstream-netbsd/libc/stdlib/ldiv.c \
-    upstream-netbsd/libc/stdlib/lldiv.c \
-    upstream-netbsd/libc/stdlib/lrand48.c \
-    upstream-netbsd/libc/stdlib/mrand48.c \
-    upstream-netbsd/libc/stdlib/nrand48.c \
-    upstream-netbsd/libc/stdlib/_rand48.c \
-    upstream-netbsd/libc/stdlib/seed48.c \
-    upstream-netbsd/libc/stdlib/srand48.c \
-    upstream-netbsd/libc/stdlib/tdelete.c \
-    upstream-netbsd/libc/stdlib/tfind.c \
-    upstream-netbsd/libc/stdlib/tsearch.c \
-    upstream-netbsd/libc/string/memccpy.c \
-    upstream-netbsd/libc/string/strcasestr.c \
-    upstream-netbsd/libc/string/strcoll.c \
-    upstream-netbsd/libc/string/strxfrm.c \
-    upstream-netbsd/libc/thread-stub/__isthreaded.c \
-    upstream-netbsd/libc/unistd/killpg.c \
+    upstream-netbsd/lib/libc/gen/ftw.c \
+    upstream-netbsd/lib/libc/gen/nftw.c \
+    upstream-netbsd/lib/libc/gen/nice.c \
+    upstream-netbsd/lib/libc/gen/popen.c \
+    upstream-netbsd/lib/libc/gen/psignal.c \
+    upstream-netbsd/lib/libc/gen/setjmperr.c \
+    upstream-netbsd/lib/libc/gen/utime.c \
+    upstream-netbsd/lib/libc/inet/inet_ntoa.c \
+    upstream-netbsd/lib/libc/inet/inet_ntop.c \
+    upstream-netbsd/lib/libc/inet/inet_pton.c \
+    upstream-netbsd/lib/libc/isc/ev_streams.c \
+    upstream-netbsd/lib/libc/isc/ev_timers.c \
+    upstream-netbsd/lib/libc/regex/regcomp.c \
+    upstream-netbsd/lib/libc/regex/regerror.c \
+    upstream-netbsd/lib/libc/regex/regexec.c \
+    upstream-netbsd/lib/libc/regex/regfree.c \
+    upstream-netbsd/lib/libc/stdlib/bsearch.c \
+    upstream-netbsd/lib/libc/stdlib/div.c \
+    upstream-netbsd/lib/libc/stdlib/drand48.c \
+    upstream-netbsd/lib/libc/stdlib/erand48.c \
+    upstream-netbsd/lib/libc/stdlib/exit.c \
+    upstream-netbsd/lib/libc/stdlib/jrand48.c \
+    upstream-netbsd/lib/libc/stdlib/ldiv.c \
+    upstream-netbsd/lib/libc/stdlib/lldiv.c \
+    upstream-netbsd/lib/libc/stdlib/lrand48.c \
+    upstream-netbsd/lib/libc/stdlib/mrand48.c \
+    upstream-netbsd/lib/libc/stdlib/nrand48.c \
+    upstream-netbsd/lib/libc/stdlib/_rand48.c \
+    upstream-netbsd/lib/libc/stdlib/seed48.c \
+    upstream-netbsd/lib/libc/stdlib/srand48.c \
+    upstream-netbsd/lib/libc/stdlib/tdelete.c \
+    upstream-netbsd/lib/libc/stdlib/tfind.c \
+    upstream-netbsd/lib/libc/stdlib/tsearch.c \
+    upstream-netbsd/lib/libc/string/memccpy.c \
+    upstream-netbsd/lib/libc/string/strcasestr.c \
+    upstream-netbsd/lib/libc/string/strcoll.c \
+    upstream-netbsd/lib/libc/string/strxfrm.c \
+    upstream-netbsd/lib/libc/thread-stub/__isthreaded.c \
+    upstream-netbsd/lib/libc/unistd/killpg.c \
 
 libc_arch_static_src_files := \
     bionic/dl_iterate_phdr_static.cpp \
@@ -513,13 +411,7 @@
 
 include $(CLEAR_VARS)
 
-LOCAL_SRC_FILES := \
-    tzcode/asctime.c \
-    tzcode/difftime.c \
-    tzcode/localtime.c \
-    tzcode/strftime.c \
-    tzcode/strptime.c \
-
+LOCAL_SRC_FILES := $(call all-c-files-under,tzcode)
 LOCAL_CFLAGS := \
     $(libc_common_cflags) \
     -DSTD_INSPIRED=1 \
@@ -543,13 +435,12 @@
 
 include $(CLEAR_VARS)
 
-LOCAL_SRC_FILES := $(libc_dns_src_files)
+LOCAL_SRC_FILES := $(call all-c-files-under,netbsd)
 LOCAL_CFLAGS := \
     $(libc_common_cflags) \
     -DINET6 \
     -I$(LOCAL_PATH)/private \
-    -I$(LOCAL_PATH)/upstream-netbsd/libc/include # for NetBSD private headers
-
+    -I$(LOCAL_PATH)/upstream-netbsd/lib/libc/include # for NetBSD private headers
 LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
 LOCAL_CPPFLAGS := $(libc_common_cppflags)
 LOCAL_C_INCLUDES := $(libc_common_c_includes)
@@ -601,7 +492,7 @@
     $(libc_common_cflags) \
     -DPOSIX_MISTAKE \
     -I$(LOCAL_PATH)/upstream-netbsd \
-    -I$(LOCAL_PATH)/upstream-netbsd/libc/include \
+    -I$(LOCAL_PATH)/upstream-netbsd/lib/libc/include \
     -include upstream-netbsd/netbsd-compat.h
 LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
 LOCAL_CPPFLAGS := $(libc_common_cppflags)
@@ -615,6 +506,32 @@
 
 
 # ========================================================
+# libc_openbsd.a - upstream OpenBSD C library code
+# ========================================================
+#
+# These files are built with the openbsd-compat.h header file
+# automatically included.
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-c-files-under,upstream-openbsd)
+LOCAL_CFLAGS := \
+    $(libc_common_cflags) \
+    -I$(LOCAL_PATH)/upstream-openbsd \
+    -I$(LOCAL_PATH)/upstream-openbsd/lib/libc/include \
+    -include upstream-openbsd/openbsd-compat.h
+LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
+LOCAL_CPPFLAGS := $(libc_common_cppflags)
+LOCAL_C_INCLUDES := $(libc_common_c_includes)
+LOCAL_MODULE := libc_openbsd
+LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
+LOCAL_SYSTEM_SHARED_LIBRARIES :=
+
+$(eval $(call patch-up-arch-specific-flags,LOCAL_CFLAGS,libc_common_cflags))
+include $(BUILD_STATIC_LIBRARY)
+
+
+# ========================================================
 # libc_bionic.a - home-grown C library code
 # ========================================================
 
@@ -674,6 +591,7 @@
     libc_dns \
     libc_freebsd \
     libc_netbsd \
+    libc_openbsd \
     libc_syscalls \
     libc_tzcode \
 
diff --git a/libc/arch-arm/arm.mk b/libc/arch-arm/arm.mk
index ccdf5a1..55f9978 100644
--- a/libc/arch-arm/arm.mk
+++ b/libc/arch-arm/arm.mk
@@ -41,10 +41,7 @@
 #    bionic/__strcpy_chk.cpp \
 #    bionic/__strcat_chk.cpp \
 
-# cflags
-libc_common_cflags_arm := \
-    -DSOFTFLOAT \
-    -fstrict-aliasing
+libc_common_cflags_arm := -DSOFTFLOAT
 
 ##########################################
 ### CPU specific source files
@@ -64,13 +61,8 @@
     arch-arm/bionic/sigsetjmp.S \
     arch-arm/bionic/syscall.S \
 
-# These are used by the static and dynamic versions of the libc
-# respectively.
-libc_arch_static_src_files_arm := \
-    arch-arm/bionic/exidx_static.c \
-
-libc_arch_dynamic_src_files_arm := \
-    arch-arm/bionic/exidx_dynamic.c \
+libc_arch_static_src_files_arm := arch-arm/bionic/exidx_static.c
+libc_arch_dynamic_src_files_arm := arch-arm/bionic/exidx_dynamic.c
 
 ## CPU variant specific source files
 ifeq ($(strip $(TARGET_$(my_2nd_arch_prefix)CPU_VARIANT)),)
@@ -85,8 +77,7 @@
 
 cpu_variant_mk :=
 
-##########################################
-# crt-related
+
 libc_crt_target_cflags_arm := \
     -I$(LOCAL_PATH)/arch-arm/include \
     -mthumb-interwork
diff --git a/libc/arch-arm/bionic/__get_sp.S b/libc/arch-arm/bionic/__get_sp.S
index 2a7e7b7..aabec6d 100644
--- a/libc/arch-arm/bionic/__get_sp.S
+++ b/libc/arch-arm/bionic/__get_sp.S
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 ENTRY(__get_sp)
   mov r0, sp
diff --git a/libc/arch-arm/bionic/_setjmp.S b/libc/arch-arm/bionic/_setjmp.S
index 6b8aa50..64a0a31 100644
--- a/libc/arch-arm/bionic/_setjmp.S
+++ b/libc/arch-arm/bionic/_setjmp.S
@@ -34,7 +34,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/setjmp.h>
 #include <machine/cpu-features.h>
 
@@ -107,7 +107,7 @@
 
 	/* validation failed, die die die. */
 botch:
-	bl	PIC_SYM(_C_LABEL(longjmperror), PLT)
-	bl	PIC_SYM(_C_LABEL(abort), PLT)
+	bl	PIC_SYM(longjmperror, PLT)
+	bl	PIC_SYM(abort, PLT)
 	b	. - 8		/* Cannot get here */
 END(_longjmp)
diff --git a/libc/arch-arm/bionic/abort_arm.S b/libc/arch-arm/bionic/abort_arm.S
index 1aaf21a..6b181ef 100644
--- a/libc/arch-arm/bionic/abort_arm.S
+++ b/libc/arch-arm/bionic/abort_arm.S
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 /*
  * Coding the abort function in assembly so that registers are guaranteed to
@@ -40,5 +40,5 @@
     .cfi_def_cfa_offset 8
     .cfi_rel_offset r3, 0
     .cfi_rel_offset r14, 4
-    bl      PIC_SYM(_C_LABEL(__libc_android_abort), PLT)
+    bl      PIC_SYM(__libc_android_abort, PLT)
 END(abort)
diff --git a/libc/arch-arm/bionic/libgcc_compat.c b/libc/arch-arm/bionic/libgcc_compat.c
index f694060..c45e6e2 100644
--- a/libc/arch-arm/bionic/libgcc_compat.c
+++ b/libc/arch-arm/bionic/libgcc_compat.c
@@ -1,176 +1,90 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-/* This file contains dummy references to libgcc.a functions to force the
- * dynamic linker to copy their definition into the final libc.so binary.
- *
- * They are required to ensure backwards binary compatibility with
- * libc.so provided by the platform and binaries built with the NDK or
- * different versions/configurations of toolchains.
- *
- * Now, for a more elaborate description of the issue:
- *
- * libgcc.a is a compiler-specific library containing various helper
- * functions used to implement certain operations that are not necessarily
- * supported by the target CPU. For example, integer division doesn't have a
- * corresponding CPU instruction on ARMv5, and is instead implemented in the
- * compiler-generated machine code as a call to an __idiv helper function.
- *
- * Normally, one has to place libgcc.a in the link command used to generate
- * target binaries (shared libraries and executables) after all objects and
- * static libraries, but before dependent shared libraries, i.e. something
- * like:
- *         gcc <options> -o libfoo.so  foo.a libgcc.a -lc -lm
- *
- * This ensures that any helper function needed by the code in foo.a is copied
- * into the final libfoo.so. However, doing so will link a bunch of other __cxa
- * functions from libgcc.a into each .so and executable, causing 4k+ increase
- * in every binary. Therefore the Android platform build system has been
- * using this instead:
- *
- *         gcc <options> -o libfoo.so foo.a -lc -lm libgcc.a
- *
- * The problem with this is that if one helper function needed by foo.a has
- * already been copied into libc.so or libm.so, then nothing will be copied
- * into libfoo.so. Instead, a symbol import definition will be added to it
- * so libfoo.so can directly call the one in libc.so at runtime.
- *
- * When refreshing toolchains for new versions or using different architecture
- * flags, the set of helper functions copied to libc.so may change, which
- * resulted in some native shared libraries generated with the NDK or prebuilts
- * from vendors to fail to load properly.
- *
- * The NDK has been fixed after 1.6_r1 to use the correct link command, so
- * any native shared library generated with it should now be safe from that
- * problem. On the other hand, existing shared libraries distributed with
- * applications that were generated with a previous version of the NDK
- * still need all 1.5/1.6 helper functions in libc.so and libm.so
- *
- * After 3.2, the toolchain was updated again, adding __aeabi_f2uiz to the
- * list of requirements. Technically, this is due to mis-linked NDK libraries
- * but it is easier to add a single function here than asking several app
- * developers to fix their build.
- *
- * The __aeabi_idiv function is added to the list since cortex-a15 supports
- * HW idiv instructions so the system libc.so doesn't pull in the reference to
- * __aeabi_idiv but legacy libraries built against cortex-a9 targets still need
- * it.
- *
- * Final note: some of the functions below should really be in libm.so to
- *             completely reflect the state of 1.5/1.6 system images. However,
- *             since libm.so depends on libc.so, it's easier to put all of
- *             these in libc.so instead, since the dynamic linker will always
- *             search in libc.so before libm.so for dependencies.
- */
+/* Generated by genlibgcc_compat.py */
 
 #define   COMPAT_FUNCTIONS_LIST \
-    XX(__adddf3)             \
-    XX(__addsf3)             \
-    XX(__aeabi_cdcmpeq)      \
-    XX(__aeabi_cdcmple)      \
-    XX(__aeabi_cdrcmple)     \
-    XX(__aeabi_d2f)          \
-    XX(__aeabi_d2iz)         \
-    XX(__aeabi_dadd)         \
-    XX(__aeabi_dcmpeq)       \
-    XX(__aeabi_dcmpge)       \
-    XX(__aeabi_dcmpgt)       \
-    XX(__aeabi_dcmple)       \
-    XX(__aeabi_dcmplt)       \
-    XX(__aeabi_dcmpun)       \
-    XX(__aeabi_ddiv)         \
-    XX(__aeabi_dmul)         \
-    XX(__aeabi_drsub)        \
-    XX(__aeabi_dsub)         \
-    XX(__aeabi_f2d)          \
-    XX(__aeabi_f2iz)         \
-    XX(__aeabi_f2uiz)        \
-    XX(__aeabi_fadd)         \
-    XX(__aeabi_fcmpun)       \
-    XX(__aeabi_fdiv)         \
-    XX(__aeabi_fmul)         \
-    XX(__aeabi_frsub)        \
-    XX(__aeabi_fsub)         \
-    XX(__aeabi_i2d)          \
-    XX(__aeabi_i2f)          \
-    XX(__aeabi_idiv)         \
-    XX(__aeabi_idivmod)      \
-    XX(__aeabi_l2d)          \
-    XX(__aeabi_l2f)          \
-    XX(__aeabi_lasr)         \
-    XX(__aeabi_ldivmod)      \
-    XX(__aeabi_llsl)         \
-    XX(__aeabi_llsr)         \
-    XX(__aeabi_lmul)         \
-    XX(__aeabi_ui2d)         \
-    XX(__aeabi_ui2f)         \
-    XX(__aeabi_uidiv)        \
-    XX(__aeabi_uidivmod)     \
-    XX(__aeabi_ul2d)         \
-    XX(__aeabi_ul2f)         \
-    XX(__aeabi_uldivmod)     \
-    XX(__cmpdf2)             \
-    XX(__divdf3)             \
-    XX(__divsf3)             \
-    XX(__eqdf2)              \
-    XX(__extendsfdf2)        \
-    XX(__fixdfsi)            \
-    XX(__fixsfsi)            \
-    XX(__floatdidf)          \
-    XX(__floatdisf)          \
-    XX(__floatsidf)          \
-    XX(__floatsisf)          \
-    XX(__floatundidf)        \
-    XX(__floatundisf)        \
-    XX(__floatunsidf)        \
-    XX(__floatunsisf)        \
-    XX(__gedf2)              \
-    XX(__gtdf2)              \
-    XX(__ledf2)              \
-    XX(__ltdf2)              \
-    XX(__muldf3)             \
-    XX(__muldi3)             \
-    XX(__mulsf3)             \
-    XX(__nedf2)              \
-    XX(__popcountsi2)        \
-    XX(__popcount_tab)       \
-    XX(__subdf3)             \
-    XX(__subsf3)             \
-    XX(__truncdfsf2)         \
-    XX(__unorddf2)           \
-    XX(__unordsf2)           \
+    XX(__adddf3) \
+    XX(__addsf3) \
+    XX(__aeabi_cdcmpeq) \
+    XX(__aeabi_cdcmple) \
+    XX(__aeabi_cdrcmple) \
+    XX(__aeabi_d2f) \
+    XX(__aeabi_d2iz) \
+    XX(__aeabi_dadd) \
+    XX(__aeabi_dcmpeq) \
+    XX(__aeabi_dcmpge) \
+    XX(__aeabi_dcmpgt) \
+    XX(__aeabi_dcmple) \
+    XX(__aeabi_dcmplt) \
+    XX(__aeabi_dcmpun) \
+    XX(__aeabi_ddiv) \
+    XX(__aeabi_dmul) \
+    XX(__aeabi_drsub) \
+    XX(__aeabi_dsub) \
+    XX(__aeabi_f2d) \
+    XX(__aeabi_f2iz) \
+    XX(__aeabi_f2uiz) \
+    XX(__aeabi_fadd) \
+    XX(__aeabi_fcmpun) \
+    XX(__aeabi_fdiv) \
+    XX(__aeabi_fmul) \
+    XX(__aeabi_frsub) \
+    XX(__aeabi_fsub) \
+    XX(__aeabi_i2d) \
+    XX(__aeabi_i2f) \
+    XX(__aeabi_idiv) \
+    XX(__aeabi_idivmod) \
+    XX(__aeabi_l2d) \
+    XX(__aeabi_l2f) \
+    XX(__aeabi_lasr) \
+    XX(__aeabi_ldivmod) \
+    XX(__aeabi_llsl) \
+    XX(__aeabi_llsr) \
+    XX(__aeabi_lmul) \
+    XX(__aeabi_ui2d) \
+    XX(__aeabi_ui2f) \
+    XX(__aeabi_uidiv) \
+    XX(__aeabi_uidivmod) \
+    XX(__aeabi_ul2d) \
+    XX(__aeabi_ul2f) \
+    XX(__aeabi_uldivmod) \
+    XX(__aeabi_unwind_cpp_pr0) \
+    XX(__aeabi_unwind_cpp_pr1) \
+    XX(__cmpdf2) \
+    XX(__divdf3) \
+    XX(__divsf3) \
+    XX(__eqdf2) \
+    XX(__extendsfdf2) \
+    XX(__fixdfsi) \
+    XX(__fixsfsi) \
+    XX(__floatdidf) \
+    XX(__floatdisf) \
+    XX(__floatsidf) \
+    XX(__floatsisf) \
+    XX(__floatundidf) \
+    XX(__floatundisf) \
+    XX(__floatunsidf) \
+    XX(__floatunsisf) \
+    XX(__gedf2) \
+    XX(__gtdf2) \
+    XX(__ledf2) \
+    XX(__ltdf2) \
+    XX(__muldf3) \
+    XX(__muldi3) \
+    XX(__mulsf3) \
+    XX(__nedf2) \
+    XX(__popcount_tab) \
+    XX(__popcountsi2) \
+    XX(__subdf3) \
+    XX(__subsf3) \
+    XX(__truncdfsf2) \
+    XX(__unorddf2) \
+    XX(__unordsf2) \
+
 
 #define  XX(f)    extern void f(void);
 COMPAT_FUNCTIONS_LIST
 #undef XX
 
-void  __bionic_libgcc_compat_hooks(void)
-{
+void __bionic_libgcc_compat_hooks(void) {
 #define XX(f)    f();
 COMPAT_FUNCTIONS_LIST
 #undef XX
diff --git a/libc/arch-arm/bionic/memcmp.S b/libc/arch-arm/bionic/memcmp.S
index 0dc3af0..70a2a58 100644
--- a/libc/arch-arm/bionic/memcmp.S
+++ b/libc/arch-arm/bionic/memcmp.S
@@ -27,7 +27,7 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 
 #ifdef HAVE_32_BYTE_CACHE_LINE
diff --git a/libc/arch-arm/bionic/memcmp16.S b/libc/arch-arm/bionic/memcmp16.S
index afbb1b0..3f2f2f1 100644
--- a/libc/arch-arm/bionic/memcmp16.S
+++ b/libc/arch-arm/bionic/memcmp16.S
@@ -27,7 +27,7 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 /*
  * Optimized memcmp16() for ARM9.
diff --git a/libc/arch-arm/bionic/memcpy.S b/libc/arch-arm/bionic/memcpy.S
index f25b3e3..2c9b10c 100644
--- a/libc/arch-arm/bionic/memcpy.S
+++ b/libc/arch-arm/bionic/memcpy.S
@@ -27,7 +27,7 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 #if defined(__ARM_NEON__) && !defined(ARCH_ARM_USE_NON_NEON_MEMCPY)
 
diff --git a/libc/arch-arm/bionic/memcpy.a9.S b/libc/arch-arm/bionic/memcpy.a9.S
index 2ba1ff5..259701d 100644
--- a/libc/arch-arm/bionic/memcpy.a9.S
+++ b/libc/arch-arm/bionic/memcpy.a9.S
@@ -44,7 +44,7 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 	.syntax unified
 	/* This implementation requires ARM state.  */
diff --git a/libc/arch-arm/bionic/setjmp.S b/libc/arch-arm/bionic/setjmp.S
index 65b93fd..ed59d07 100644
--- a/libc/arch-arm/bionic/setjmp.S
+++ b/libc/arch-arm/bionic/setjmp.S
@@ -34,7 +34,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/setjmp.h>
 #include <machine/cpu-features.h>
 
@@ -56,7 +56,7 @@
 	.cfi_rel_offset r14, 4
 	mov	r0, #0x00000000
 
-	bl	PIC_SYM(_C_LABEL(sigblock), PLT)
+	bl	PIC_SYM(sigblock, PLT)
 	mov	r1, r0
 
 	ldmfd	sp!, {r0, r14}
@@ -108,11 +108,11 @@
 	.cfi_adjust_cfa_offset 4
 
 	mov	r0, r2
-	bl	PIC_SYM(_C_LABEL(sigsetmask), PLT)
+	bl	PIC_SYM(sigsetmask, PLT)
 
 	add	sp, sp, #4	/* unalign the stack */
 	.cfi_adjust_cfa_offset -4
-	ldmfd	sp!, {r0, r1, r14} 
+	ldmfd	sp!, {r0, r1, r14}
 	.cfi_def_cfa_offset 0
 
 #ifdef __ARM_HAVE_VFP
@@ -147,7 +147,7 @@
 
 	/* validation failed, die die die. */
 botch:
-	bl	PIC_SYM(_C_LABEL(longjmperror), PLT)
-	bl	PIC_SYM(_C_LABEL(abort), PLT)
+	bl	PIC_SYM(longjmperror, PLT)
+	bl	PIC_SYM(abort, PLT)
 	b	. - 8		/* Cannot get here */
 END(longjmp)
diff --git a/libc/arch-arm/bionic/sigsetjmp.S b/libc/arch-arm/bionic/sigsetjmp.S
index 12311e5..7016f50 100644
--- a/libc/arch-arm/bionic/sigsetjmp.S
+++ b/libc/arch-arm/bionic/sigsetjmp.S
@@ -35,7 +35,7 @@
 
 #define _ALIGN_TEXT .align 0
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/setjmp.h>
 
 /*
@@ -50,8 +50,8 @@
 
 ENTRY(sigsetjmp)
 	teq	r1, #0
-	beq	PIC_SYM(_C_LABEL(_setjmp), PLT)
-	b	PIC_SYM(_C_LABEL(setjmp), PLT)
+	beq	PIC_SYM(_setjmp, PLT)
+	b	PIC_SYM(setjmp, PLT)
 END(sigsetjmp)
 
 .L_setjmp_magic:
@@ -61,6 +61,6 @@
 	ldr	r2, .L_setjmp_magic
 	ldr	r3, [r0]
 	teq	r2, r3
-	beq	PIC_SYM(_C_LABEL(_longjmp), PLT)
-	b	PIC_SYM(_C_LABEL(longjmp), PLT)
+	beq	PIC_SYM(_longjmp, PLT)
+	b	PIC_SYM(longjmp, PLT)
 END(siglongjmp)
diff --git a/libc/arch-arm/bionic/strcmp.S b/libc/arch-arm/bionic/strcmp.S
index 42d41d1..6dba942 100644
--- a/libc/arch-arm/bionic/strcmp.S
+++ b/libc/arch-arm/bionic/strcmp.S
@@ -28,7 +28,7 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 	.text
 
diff --git a/libc/arch-arm/cortex-a15/bionic/__strcat_chk.S b/libc/arch-arm/cortex-a15/bionic/__strcat_chk.S
index dc86150..36da2d9 100644
--- a/libc/arch-arm/cortex-a15/bionic/__strcat_chk.S
+++ b/libc/arch-arm/cortex-a15/bionic/__strcat_chk.S
@@ -26,8 +26,8 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
     .syntax unified
 
diff --git a/libc/arch-arm/cortex-a15/bionic/__strcpy_chk.S b/libc/arch-arm/cortex-a15/bionic/__strcpy_chk.S
index 95aaf4f..c3e3e14 100644
--- a/libc/arch-arm/cortex-a15/bionic/__strcpy_chk.S
+++ b/libc/arch-arm/cortex-a15/bionic/__strcpy_chk.S
@@ -26,8 +26,8 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
     .syntax unified
 
diff --git a/libc/arch-arm/cortex-a15/bionic/memcpy.S b/libc/arch-arm/cortex-a15/bionic/memcpy.S
index badc93b..da4f3dd 100644
--- a/libc/arch-arm/cortex-a15/bionic/memcpy.S
+++ b/libc/arch-arm/cortex-a15/bionic/memcpy.S
@@ -55,8 +55,8 @@
 
 // Prototype: void *memcpy (void *dst, const void *src, size_t count).
 
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
         .text
         .syntax unified
diff --git a/libc/arch-arm/cortex-a15/bionic/memset.S b/libc/arch-arm/cortex-a15/bionic/memset.S
index 4e6d322..12c68d6 100644
--- a/libc/arch-arm/cortex-a15/bionic/memset.S
+++ b/libc/arch-arm/cortex-a15/bionic/memset.S
@@ -27,8 +27,8 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
         /*
          * Optimized memset() for ARM.
diff --git a/libc/arch-arm/cortex-a15/bionic/strcat.S b/libc/arch-arm/cortex-a15/bionic/strcat.S
index 72d4e9e..b95be94 100644
--- a/libc/arch-arm/cortex-a15/bionic/strcat.S
+++ b/libc/arch-arm/cortex-a15/bionic/strcat.S
@@ -53,7 +53,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
     .syntax unified
 
diff --git a/libc/arch-arm/cortex-a15/bionic/strcmp.S b/libc/arch-arm/cortex-a15/bionic/strcmp.S
index 0cccf06..12da115 100644
--- a/libc/arch-arm/cortex-a15/bionic/strcmp.S
+++ b/libc/arch-arm/cortex-a15/bionic/strcmp.S
@@ -27,7 +27,7 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 #ifdef __ARMEB__
 #define S2LOMEM lsl
diff --git a/libc/arch-arm/cortex-a15/bionic/strcpy.S b/libc/arch-arm/cortex-a15/bionic/strcpy.S
index 5773540..cb878c4 100644
--- a/libc/arch-arm/cortex-a15/bionic/strcpy.S
+++ b/libc/arch-arm/cortex-a15/bionic/strcpy.S
@@ -53,7 +53,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
     .syntax unified
 
diff --git a/libc/arch-arm/cortex-a15/bionic/strlen.S b/libc/arch-arm/cortex-a15/bionic/strlen.S
index 08f6d19..9a0ce62 100644
--- a/libc/arch-arm/cortex-a15/bionic/strlen.S
+++ b/libc/arch-arm/cortex-a15/bionic/strlen.S
@@ -53,7 +53,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
     .syntax unified
 
diff --git a/libc/arch-arm/cortex-a9/bionic/__strcat_chk.S b/libc/arch-arm/cortex-a9/bionic/__strcat_chk.S
index 7009168..651aefc 100644
--- a/libc/arch-arm/cortex-a9/bionic/__strcat_chk.S
+++ b/libc/arch-arm/cortex-a9/bionic/__strcat_chk.S
@@ -26,8 +26,8 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
     .syntax unified
     .fpu    neon
diff --git a/libc/arch-arm/cortex-a9/bionic/__strcpy_chk.S b/libc/arch-arm/cortex-a9/bionic/__strcpy_chk.S
index 908eec4..2447780 100644
--- a/libc/arch-arm/cortex-a9/bionic/__strcpy_chk.S
+++ b/libc/arch-arm/cortex-a9/bionic/__strcpy_chk.S
@@ -26,8 +26,8 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
     .syntax unified
     .fpu    neon
diff --git a/libc/arch-arm/cortex-a9/bionic/memcpy.S b/libc/arch-arm/cortex-a9/bionic/memcpy.S
index 72c1a66..8dcd937 100644
--- a/libc/arch-arm/cortex-a9/bionic/memcpy.S
+++ b/libc/arch-arm/cortex-a9/bionic/memcpy.S
@@ -26,8 +26,8 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
 /*
  * This code assumes it is running on a processor that supports all arm v7
diff --git a/libc/arch-arm/cortex-a9/bionic/memset.S b/libc/arch-arm/cortex-a9/bionic/memset.S
index 7f77dad..a5057eb 100644
--- a/libc/arch-arm/cortex-a9/bionic/memset.S
+++ b/libc/arch-arm/cortex-a9/bionic/memset.S
@@ -26,9 +26,8 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/cpu-features.h>
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
 /*
  * This code assumes it is running on a processor that supports all arm v7
diff --git a/libc/arch-arm/cortex-a9/bionic/strcat.S b/libc/arch-arm/cortex-a9/bionic/strcat.S
index 0f5baef..f5a855e 100644
--- a/libc/arch-arm/cortex-a9/bionic/strcat.S
+++ b/libc/arch-arm/cortex-a9/bionic/strcat.S
@@ -53,7 +53,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
     .syntax unified
 
diff --git a/libc/arch-arm/cortex-a9/bionic/strcmp.S b/libc/arch-arm/cortex-a9/bionic/strcmp.S
index eacdb89..2411c65 100644
--- a/libc/arch-arm/cortex-a9/bionic/strcmp.S
+++ b/libc/arch-arm/cortex-a9/bionic/strcmp.S
@@ -27,7 +27,7 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 #ifdef __ARMEB__
 #define S2LOMEM lsl
diff --git a/libc/arch-arm/cortex-a9/bionic/strcpy.S b/libc/arch-arm/cortex-a9/bionic/strcpy.S
index 9aa4f88..9e9610b 100644
--- a/libc/arch-arm/cortex-a9/bionic/strcpy.S
+++ b/libc/arch-arm/cortex-a9/bionic/strcpy.S
@@ -53,7 +53,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
     .syntax unified
 
diff --git a/libc/arch-arm/cortex-a9/bionic/strlen.S b/libc/arch-arm/cortex-a9/bionic/strlen.S
index 259eda0..b92b043 100644
--- a/libc/arch-arm/cortex-a9/bionic/strlen.S
+++ b/libc/arch-arm/cortex-a9/bionic/strlen.S
@@ -53,7 +53,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
     .syntax unified
 
diff --git a/libc/arch-arm/generic/bionic/memcpy.S b/libc/arch-arm/generic/bionic/memcpy.S
index 699b88d..cd4a13d 100644
--- a/libc/arch-arm/generic/bionic/memcpy.S
+++ b/libc/arch-arm/generic/bionic/memcpy.S
@@ -27,8 +27,8 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
         /*
          * Optimized memcpy() for ARM.
diff --git a/libc/arch-arm/generic/bionic/memset.S b/libc/arch-arm/generic/bionic/memset.S
index baeb519..be35de9 100644
--- a/libc/arch-arm/generic/bionic/memset.S
+++ b/libc/arch-arm/generic/bionic/memset.S
@@ -26,8 +26,8 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
         /*
          * Optimized memset() for ARM.
diff --git a/libc/arch-arm/generic/bionic/strcmp.S b/libc/arch-arm/generic/bionic/strcmp.S
index 42d41d1..6dba942 100644
--- a/libc/arch-arm/generic/bionic/strcmp.S
+++ b/libc/arch-arm/generic/bionic/strcmp.S
@@ -28,7 +28,7 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 	.text
 
diff --git a/libc/arch-arm/generic/bionic/strcpy.S b/libc/arch-arm/generic/bionic/strcpy.S
index cc997f4..802a62d 100644
--- a/libc/arch-arm/generic/bionic/strcpy.S
+++ b/libc/arch-arm/generic/bionic/strcpy.S
@@ -30,7 +30,7 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 ENTRY(strcpy)
 	pld	[r1, #0]
diff --git a/libc/arch-arm/include/machine/asm.h b/libc/arch-arm/include/machine/asm.h
index f16baf8..7954f05 100644
--- a/libc/arch-arm/include/machine/asm.h
+++ b/libc/arch-arm/include/machine/asm.h
@@ -38,107 +38,22 @@
 #ifndef _ARM32_ASM_H_
 #define _ARM32_ASM_H_
 
-#ifdef __ELF__
-# define _C_LABEL(x)	x
-#else
-# ifdef __STDC__
-#  define _C_LABEL(x)	_ ## x
-# else
-#  define _C_LABEL(x)	_/**/x
-# endif
-#endif
-#define	_ASM_LABEL(x)	x
-
-#ifdef __STDC__
-# define __CONCAT(x,y)	x ## y
-# define __STRING(x)	#x
-#else
-# define __CONCAT(x,y)	x/**/y
-# define __STRING(x)	"x"
-#endif
-
 #ifndef _ALIGN_TEXT
 # define _ALIGN_TEXT .align 0
 #endif
 
-/*
- * gas/arm uses @ as a single comment character and thus cannot be used here
- * Instead it recognised the # instead of an @ symbols in .type directives
- * We define a couple of macros so that assembly code will not be dependant
- * on one or the other.
- */
-#define _ASM_TYPE_FUNCTION	#function
-#define _ASM_TYPE_OBJECT	#object
-#define _ENTRY(x) \
-	.text; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; x: .fnstart; .cfi_startproc;
+#undef __bionic_asm_custom_entry
+#undef __bionic_asm_custom_end
+#define __bionic_asm_custom_entry(f) .fnstart
+#define __bionic_asm_custom_end(f) .fnend
 
-#define _ASM_SIZE(x)	.size x, .-x;
-
-#define _END(x) \
-	.fnend; .cfi_endproc; \
-	_ASM_SIZE(x)
-
-#ifdef GPROF
-# ifdef __ELF__
-#  define _PROF_PROLOGUE	\
-	mov ip, lr; bl __mcount
-# else
-#  define _PROF_PROLOGUE	\
-	mov ip,lr; bl mcount
-# endif
-#else
-# define _PROF_PROLOGUE
-#endif
-
-#define	ENTRY(y)	_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
-#define	ENTRY_NP(y)	_ENTRY(_C_LABEL(y))
-#define	END(y)		_END(_C_LABEL(y))
-#define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
-#define	ASENTRY_NP(y)	_ENTRY(_ASM_LABEL(y))
-#define	ASEND(y)	_END(_ASM_LABEL(y))
-
-#ifdef __ELF__
-#define ENTRY_PRIVATE(y)  ENTRY(y); .hidden _C_LABEL(y)
-#else
-#define ENTRY_PRIVATE(y)  ENTRY(y)
-#endif
-
-#define	ASMSTR		.asciz
+#undef __bionic_asm_function_type
+#define __bionic_asm_function_type #function
 
 #if defined(__ELF__) && defined(PIC)
-#ifdef __STDC__
-#define	PIC_SYM(x,y)	x ## ( ## y ## )
+#define PIC_SYM(x,y) x ## ( ## y ## )
 #else
-#define	PIC_SYM(x,y)	x/**/(/**/y/**/)
+#define PIC_SYM(x,y) x
 #endif
-#else
-#define	PIC_SYM(x,y)	x
-#endif
-
-#ifdef __ELF__
-#define RCSID(x)	.section ".ident"; .asciz x
-#else
-#define RCSID(x)	.text; .asciz x
-#endif
-
-#ifdef __ELF__
-#define	WEAK_ALIAS(alias,sym)						\
-	.weak alias;							\
-	alias = sym
-#endif
-
-#ifdef __STDC__
-#define	WARN_REFERENCES(sym,msg)					\
-	.stabs msg ## ,30,0,0,0 ;					\
-	.stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0
-#elif defined(__ELF__)
-#define	WARN_REFERENCES(sym,msg)					\
-	.stabs msg,30,0,0,0 ;						\
-	.stabs __STRING(sym),1,0,0,0
-#else
-#define	WARN_REFERENCES(sym,msg)					\
-	.stabs msg,30,0,0,0 ;						\
-	.stabs __STRING(_/**/sym),1,0,0,0
-#endif /* __STDC__ */
 
 #endif /* !_ARM_ASM_H_ */
diff --git a/libc/arch-arm/krait/bionic/__strcat_chk.S b/libc/arch-arm/krait/bionic/__strcat_chk.S
index a5d06f3..34becdb 100644
--- a/libc/arch-arm/krait/bionic/__strcat_chk.S
+++ b/libc/arch-arm/krait/bionic/__strcat_chk.S
@@ -26,8 +26,8 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
     .syntax unified
 
diff --git a/libc/arch-arm/krait/bionic/__strcpy_chk.S b/libc/arch-arm/krait/bionic/__strcpy_chk.S
index 95aaf4f..c3e3e14 100644
--- a/libc/arch-arm/krait/bionic/__strcpy_chk.S
+++ b/libc/arch-arm/krait/bionic/__strcpy_chk.S
@@ -26,8 +26,8 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
     .syntax unified
 
diff --git a/libc/arch-arm/krait/bionic/memcpy.S b/libc/arch-arm/krait/bionic/memcpy.S
index 54405fa..0b7b276 100644
--- a/libc/arch-arm/krait/bionic/memcpy.S
+++ b/libc/arch-arm/krait/bionic/memcpy.S
@@ -28,8 +28,8 @@
 
 /* Assumes neon instructions and a cache line size of 32 bytes. */
 
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
 /*
  * This code assumes it is running on a processor that supports all arm v7
diff --git a/libc/arch-arm/krait/bionic/memset.S b/libc/arch-arm/krait/bionic/memset.S
index 1563327..5d1943b 100644
--- a/libc/arch-arm/krait/bionic/memset.S
+++ b/libc/arch-arm/krait/bionic/memset.S
@@ -27,8 +27,8 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
-#include "private/libc_events.h"
+#include <private/bionic_asm.h>
+#include <private/libc_events.h>
 
 /*
  * This code assumes it is running on a processor that supports all arm v7
diff --git a/libc/arch-arm/krait/bionic/strcmp.S b/libc/arch-arm/krait/bionic/strcmp.S
index f735fb5..eacb82a 100644
--- a/libc/arch-arm/krait/bionic/strcmp.S
+++ b/libc/arch-arm/krait/bionic/strcmp.S
@@ -27,7 +27,7 @@
  */
 
 #include <machine/cpu-features.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 #ifdef __ARMEB__
 #define S2LOMEM lsl
diff --git a/libc/arch-arm64/arm64.mk b/libc/arch-arm64/arm64.mk
index 4b47c6d..a645949 100644
--- a/libc/arch-arm64/arm64.mk
+++ b/libc/arch-arm64/arm64.mk
@@ -53,14 +53,7 @@
     arch-arm64/bionic/syscall.S \
     arch-arm64/bionic/vfork.S \
 
-# These are used by the static and dynamic versions of the libc
-# respectively.
-libc_arch_static_src_files_arm64 :=
 
-libc_arch_dynamic_src_files_arm64 :=
-
-##########################################
-# crt-related
 libc_crt_target_cflags_arm64 := \
     -I$(LOCAL_PATH)/arch-arm64/include
 
diff --git a/libc/arch-arm64/bionic/__get_sp.S b/libc/arch-arm64/bionic/__get_sp.S
index 3cd4ceb..d495b6a 100644
--- a/libc/arch-arm64/bionic/__get_sp.S
+++ b/libc/arch-arm64/bionic/__get_sp.S
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 ENTRY(__get_sp)
     mov x0, sp
diff --git a/libc/arch-arm64/bionic/__rt_sigreturn.S b/libc/arch-arm64/bionic/__rt_sigreturn.S
index d176ea3..8fb6f0c 100644
--- a/libc/arch-arm64/bionic/__rt_sigreturn.S
+++ b/libc/arch-arm64/bionic/__rt_sigreturn.S
@@ -26,8 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 ENTRY_PRIVATE(__rt_sigreturn)
   mov     x8, __NR_rt_sigreturn
diff --git a/libc/arch-arm64/bionic/_setjmp.S b/libc/arch-arm64/bionic/_setjmp.S
index ea70a52..dfa861b 100644
--- a/libc/arch-arm64/bionic/_setjmp.S
+++ b/libc/arch-arm64/bionic/_setjmp.S
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/setjmp.h>
 
 /*
@@ -105,7 +105,7 @@
 
     /* validation failed, die die die */
 botch:
-    bl      PIC_SYM(_C_LABEL(longjmperror), PLT)
-    bl      PIC_SYM(_C_LABEL(abort), PLT)
+    bl      PIC_SYM(longjmperror, PLT)
+    bl      PIC_SYM(abort, PLT)
     b        . - 8       /* Cannot get here */
 END(_longjmp)
diff --git a/libc/arch-arm64/bionic/setjmp.S b/libc/arch-arm64/bionic/setjmp.S
index b1ec0a8..9a68d86 100644
--- a/libc/arch-arm64/bionic/setjmp.S
+++ b/libc/arch-arm64/bionic/setjmp.S
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/setjmp.h>
 
 /*
@@ -45,7 +45,7 @@
     stp     x0, x30, [sp, #-16]!
 
     mov     x0, xzr
-    bl      PIC_SYM(_C_LABEL(sigblock), PLT)
+    bl      PIC_SYM(sigblock, PLT)
     mov     w1, w0
 
     ldp     x0, x30, [sp], #16
@@ -117,7 +117,7 @@
 
     /* validation failed, die die die */
 botch:
-    bl      PIC_SYM(_C_LABEL(longjmperror), PLT)
-    bl      PIC_SYM(_C_LABEL(abort), PLT)
+    bl      PIC_SYM(longjmperror, PLT)
+    bl      PIC_SYM(abort, PLT)
     b       . - 8       /* Cannot get here */
 END(longjmp)
diff --git a/libc/arch-arm64/bionic/sigsetjmp.S b/libc/arch-arm64/bionic/sigsetjmp.S
index 3afceab..4fdb367 100644
--- a/libc/arch-arm64/bionic/sigsetjmp.S
+++ b/libc/arch-arm64/bionic/sigsetjmp.S
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/setjmp.h>
 
 /*
@@ -35,8 +35,8 @@
  */
 
 ENTRY(sigsetjmp)
-    cbz     w1, PIC_SYM(_C_LABEL(_setjmp), PLT)
-    b       PIC_SYM(_C_LABEL(setjmp), PLT)
+    cbz     w1, PIC_SYM(_setjmp, PLT)
+    b       PIC_SYM(setjmp, PLT)
 END(sigsetjmp)
 
 .L_setjmp_magic:
@@ -46,6 +46,6 @@
     ldr     w2, .L_setjmp_magic
     ldr     w3, [x0]
     cmp     w2, w3
-    b.eq    PIC_SYM(_C_LABEL(_longjmp), PLT)
-    b       PIC_SYM(_C_LABEL(longjmp), PLT)
+    b.eq    PIC_SYM(_longjmp, PLT)
+    b       PIC_SYM(longjmp, PLT)
 END(siglongjmp)
diff --git a/libc/arch-arm64/include/machine/asm.h b/libc/arch-arm64/include/machine/asm.h
index 3f8b908..4bfabaf 100644
--- a/libc/arch-arm64/include/machine/asm.h
+++ b/libc/arch-arm64/include/machine/asm.h
@@ -38,91 +38,17 @@
 #ifndef _AARCH64_ASM_H_
 #define _AARCH64_ASM_H_
 
-/* TODO: Add cfi directives for creating/restoring FP */
-#ifdef __ELF__
-# define	_C_LABEL(x)	x
-#else
-# ifdef __STDC__
-#  define	_C_LABEL(x)	_ ## x
-# else
-#  define	_C_LABEL(x)	_/**/x
-# endif
-#endif
-#define	_ASM_LABEL(x)	x
-
-#ifdef __STDC__
-# define	__CONCAT(x,y)	x ## y
-# define	__STRING(x)	#x
-#else
-# define	__CONCAT(x,y)	x/**/y
-# define	__STRING(x)	"x"
-#endif
-
 #ifndef _ALIGN_TEXT
-# define	_ALIGN_TEXT	.align 0
+# define _ALIGN_TEXT .align 0
 #endif
 
-#define	_ASM_TYPE_FUNCTION	%function
-#define	_ASM_TYPE_OBJECT	%object
-#define	_ENTRY(x) \
-	.text; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; x: .cfi_startproc
-
-#define	_ASM_SIZE(x)	.size x, .-x;
-
-#define _END(x) \
-	.cfi_endproc; \
-	_ASM_SIZE(x)
-
-#define	ENTRY(y)	_ENTRY(_C_LABEL(y));
-#define	ENTRY_NP(y)	_ENTRY(_C_LABEL(y))
-#define	END(y)		_END(_C_LABEL(y))
-#define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
-#define	ASENTRY_NP(y)	_ENTRY(_ASM_LABEL(y))
-#define	ASEND(y)	_END(_ASM_LABEL(y))
-
-#ifdef __ELF__
-#define	ENTRY_PRIVATE(y)  ENTRY(y); .hidden _C_LABEL(y)
-#else
-#define	ENTRY_PRIVATE(y)  ENTRY(y)
-#endif
-
-#define	ASMSTR		.asciz
+#undef __bionic_asm_function_type
+#define __bionic_asm_function_type %function
 
 #if defined(__ELF__) && defined(PIC)
-#ifdef __STDC__
-#define	PIC_SYM(x,y)	x ## ( ## y ## )
+#define PIC_SYM(x,y) x ## ( ## y ## )
 #else
-#define	PIC_SYM(x,y)	x/**/(/**/y/**/)
+#define PIC_SYM(x,y) x
 #endif
-#else
-#define	PIC_SYM(x,y)	x
-#endif
-
-#ifdef __ELF__
-#define	RCSID(x)	.section ".ident"; .asciz x
-#else
-#define	RCSID(x)	.text; .asciz x
-#endif
-
-#ifdef __ELF__
-#define	WEAK_ALIAS(alias,sym)						\
-	.weak alias;							\
-	alias = sym
-#endif
-
-#ifdef __STDC__
-#define	WARN_REFERENCES(sym,msg)					\
-	.stabs msg ## ,30,0,0,0 ;					\
-	.stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0
-#elif defined(__ELF__)
-#define	WARN_REFERENCES(sym,msg)					\
-	.stabs msg,30,0,0,0 ;						\
-	.stabs __STRING(sym),1,0,0,0
-#else
-#define	WARN_REFERENCES(sym,msg)					\
-	.stabs msg,30,0,0,0 ;						\
-	.stabs __STRING(_/**/sym),1,0,0,0
-#endif /* __STDC__ */
 
 #endif /* _AARCH64_ASM_H_ */
-
diff --git a/libc/arch-arm64/syscalls/__brk.S b/libc/arch-arm64/syscalls/__brk.S
index 98055cc..918edf0 100644
--- a/libc/arch-arm64/syscalls/__brk.S
+++ b/libc/arch-arm64/syscalls/__brk.S
@@ -19,4 +19,4 @@
 
     ret
 END(__brk)
-.hidden _C_LABEL(__brk)
+.hidden __brk
diff --git a/libc/arch-arm64/syscalls/__epoll_pwait.S b/libc/arch-arm64/syscalls/__epoll_pwait.S
index d512c7c..b487360 100644
--- a/libc/arch-arm64/syscalls/__epoll_pwait.S
+++ b/libc/arch-arm64/syscalls/__epoll_pwait.S
@@ -19,4 +19,4 @@
 
     ret
 END(__epoll_pwait)
-.hidden _C_LABEL(__epoll_pwait)
+.hidden __epoll_pwait
diff --git a/libc/arch-arm64/syscalls/__exit.S b/libc/arch-arm64/syscalls/__exit.S
index 50cd45a..5e97928 100644
--- a/libc/arch-arm64/syscalls/__exit.S
+++ b/libc/arch-arm64/syscalls/__exit.S
@@ -19,4 +19,4 @@
 
     ret
 END(__exit)
-.hidden _C_LABEL(__exit)
+.hidden __exit
diff --git a/libc/arch-arm64/syscalls/__getcpu.S b/libc/arch-arm64/syscalls/__getcpu.S
index 698e8ff..a312188 100644
--- a/libc/arch-arm64/syscalls/__getcpu.S
+++ b/libc/arch-arm64/syscalls/__getcpu.S
@@ -19,4 +19,4 @@
 
     ret
 END(__getcpu)
-.hidden _C_LABEL(__getcpu)
+.hidden __getcpu
diff --git a/libc/arch-arm64/syscalls/__getcwd.S b/libc/arch-arm64/syscalls/__getcwd.S
index f0543f0..4b27a9c 100644
--- a/libc/arch-arm64/syscalls/__getcwd.S
+++ b/libc/arch-arm64/syscalls/__getcwd.S
@@ -19,4 +19,4 @@
 
     ret
 END(__getcwd)
-.hidden _C_LABEL(__getcwd)
+.hidden __getcwd
diff --git a/libc/arch-arm64/syscalls/__getpriority.S b/libc/arch-arm64/syscalls/__getpriority.S
index f7fd1b8..3ccd104 100644
--- a/libc/arch-arm64/syscalls/__getpriority.S
+++ b/libc/arch-arm64/syscalls/__getpriority.S
@@ -19,4 +19,4 @@
 
     ret
 END(__getpriority)
-.hidden _C_LABEL(__getpriority)
+.hidden __getpriority
diff --git a/libc/arch-arm64/syscalls/__ioctl.S b/libc/arch-arm64/syscalls/__ioctl.S
index 2569fdf..68d89bc 100644
--- a/libc/arch-arm64/syscalls/__ioctl.S
+++ b/libc/arch-arm64/syscalls/__ioctl.S
@@ -19,4 +19,4 @@
 
     ret
 END(__ioctl)
-.hidden _C_LABEL(__ioctl)
+.hidden __ioctl
diff --git a/libc/arch-arm64/syscalls/__openat.S b/libc/arch-arm64/syscalls/__openat.S
index cca66ce..a49eaff 100644
--- a/libc/arch-arm64/syscalls/__openat.S
+++ b/libc/arch-arm64/syscalls/__openat.S
@@ -19,4 +19,4 @@
 
     ret
 END(__openat)
-.hidden _C_LABEL(__openat)
+.hidden __openat
diff --git a/libc/arch-arm64/syscalls/__ppoll.S b/libc/arch-arm64/syscalls/__ppoll.S
index 68efc09..370e768 100644
--- a/libc/arch-arm64/syscalls/__ppoll.S
+++ b/libc/arch-arm64/syscalls/__ppoll.S
@@ -19,4 +19,4 @@
 
     ret
 END(__ppoll)
-.hidden _C_LABEL(__ppoll)
+.hidden __ppoll
diff --git a/libc/arch-arm64/syscalls/__pselect6.S b/libc/arch-arm64/syscalls/__pselect6.S
index 295b71a..193e19f 100644
--- a/libc/arch-arm64/syscalls/__pselect6.S
+++ b/libc/arch-arm64/syscalls/__pselect6.S
@@ -19,4 +19,4 @@
 
     ret
 END(__pselect6)
-.hidden _C_LABEL(__pselect6)
+.hidden __pselect6
diff --git a/libc/arch-arm64/syscalls/__ptrace.S b/libc/arch-arm64/syscalls/__ptrace.S
index aa41071..ee63cb0 100644
--- a/libc/arch-arm64/syscalls/__ptrace.S
+++ b/libc/arch-arm64/syscalls/__ptrace.S
@@ -19,4 +19,4 @@
 
     ret
 END(__ptrace)
-.hidden _C_LABEL(__ptrace)
+.hidden __ptrace
diff --git a/libc/arch-arm64/syscalls/__reboot.S b/libc/arch-arm64/syscalls/__reboot.S
index 9680bdc..10b33ad 100644
--- a/libc/arch-arm64/syscalls/__reboot.S
+++ b/libc/arch-arm64/syscalls/__reboot.S
@@ -19,4 +19,4 @@
 
     ret
 END(__reboot)
-.hidden _C_LABEL(__reboot)
+.hidden __reboot
diff --git a/libc/arch-arm64/syscalls/__rt_sigaction.S b/libc/arch-arm64/syscalls/__rt_sigaction.S
index 77f83ea..cea0941 100644
--- a/libc/arch-arm64/syscalls/__rt_sigaction.S
+++ b/libc/arch-arm64/syscalls/__rt_sigaction.S
@@ -19,4 +19,4 @@
 
     ret
 END(__rt_sigaction)
-.hidden _C_LABEL(__rt_sigaction)
+.hidden __rt_sigaction
diff --git a/libc/arch-arm64/syscalls/__rt_sigpending.S b/libc/arch-arm64/syscalls/__rt_sigpending.S
index 59a2e1e..97db3b9 100644
--- a/libc/arch-arm64/syscalls/__rt_sigpending.S
+++ b/libc/arch-arm64/syscalls/__rt_sigpending.S
@@ -19,4 +19,4 @@
 
     ret
 END(__rt_sigpending)
-.hidden _C_LABEL(__rt_sigpending)
+.hidden __rt_sigpending
diff --git a/libc/arch-arm64/syscalls/__rt_sigprocmask.S b/libc/arch-arm64/syscalls/__rt_sigprocmask.S
index c5a51ed..97dabe1 100644
--- a/libc/arch-arm64/syscalls/__rt_sigprocmask.S
+++ b/libc/arch-arm64/syscalls/__rt_sigprocmask.S
@@ -19,4 +19,4 @@
 
     ret
 END(__rt_sigprocmask)
-.hidden _C_LABEL(__rt_sigprocmask)
+.hidden __rt_sigprocmask
diff --git a/libc/arch-arm64/syscalls/__rt_sigsuspend.S b/libc/arch-arm64/syscalls/__rt_sigsuspend.S
index 7a1c22e..d8eaa3e 100644
--- a/libc/arch-arm64/syscalls/__rt_sigsuspend.S
+++ b/libc/arch-arm64/syscalls/__rt_sigsuspend.S
@@ -19,4 +19,4 @@
 
     ret
 END(__rt_sigsuspend)
-.hidden _C_LABEL(__rt_sigsuspend)
+.hidden __rt_sigsuspend
diff --git a/libc/arch-arm64/syscalls/__rt_sigtimedwait.S b/libc/arch-arm64/syscalls/__rt_sigtimedwait.S
index b3d950c..95f031a 100644
--- a/libc/arch-arm64/syscalls/__rt_sigtimedwait.S
+++ b/libc/arch-arm64/syscalls/__rt_sigtimedwait.S
@@ -19,4 +19,4 @@
 
     ret
 END(__rt_sigtimedwait)
-.hidden _C_LABEL(__rt_sigtimedwait)
+.hidden __rt_sigtimedwait
diff --git a/libc/arch-arm64/syscalls/__sched_getaffinity.S b/libc/arch-arm64/syscalls/__sched_getaffinity.S
index 9b785ad..58715d0 100644
--- a/libc/arch-arm64/syscalls/__sched_getaffinity.S
+++ b/libc/arch-arm64/syscalls/__sched_getaffinity.S
@@ -19,4 +19,4 @@
 
     ret
 END(__sched_getaffinity)
-.hidden _C_LABEL(__sched_getaffinity)
+.hidden __sched_getaffinity
diff --git a/libc/arch-arm64/syscalls/__set_tid_address.S b/libc/arch-arm64/syscalls/__set_tid_address.S
index b7541fc..3cc452c 100644
--- a/libc/arch-arm64/syscalls/__set_tid_address.S
+++ b/libc/arch-arm64/syscalls/__set_tid_address.S
@@ -19,4 +19,4 @@
 
     ret
 END(__set_tid_address)
-.hidden _C_LABEL(__set_tid_address)
+.hidden __set_tid_address
diff --git a/libc/arch-arm64/syscalls/__syslog.S b/libc/arch-arm64/syscalls/__syslog.S
index 625a7eb..2e1fb1d 100644
--- a/libc/arch-arm64/syscalls/__syslog.S
+++ b/libc/arch-arm64/syscalls/__syslog.S
@@ -19,4 +19,4 @@
 
     ret
 END(__syslog)
-.hidden _C_LABEL(__syslog)
+.hidden __syslog
diff --git a/libc/arch-arm64/syscalls/__timer_create.S b/libc/arch-arm64/syscalls/__timer_create.S
index bfce448..b551048 100644
--- a/libc/arch-arm64/syscalls/__timer_create.S
+++ b/libc/arch-arm64/syscalls/__timer_create.S
@@ -19,4 +19,4 @@
 
     ret
 END(__timer_create)
-.hidden _C_LABEL(__timer_create)
+.hidden __timer_create
diff --git a/libc/arch-arm64/syscalls/__timer_delete.S b/libc/arch-arm64/syscalls/__timer_delete.S
index 03ed44e..2aff540 100644
--- a/libc/arch-arm64/syscalls/__timer_delete.S
+++ b/libc/arch-arm64/syscalls/__timer_delete.S
@@ -19,4 +19,4 @@
 
     ret
 END(__timer_delete)
-.hidden _C_LABEL(__timer_delete)
+.hidden __timer_delete
diff --git a/libc/arch-arm64/syscalls/__timer_getoverrun.S b/libc/arch-arm64/syscalls/__timer_getoverrun.S
index a458941..b11e356 100644
--- a/libc/arch-arm64/syscalls/__timer_getoverrun.S
+++ b/libc/arch-arm64/syscalls/__timer_getoverrun.S
@@ -19,4 +19,4 @@
 
     ret
 END(__timer_getoverrun)
-.hidden _C_LABEL(__timer_getoverrun)
+.hidden __timer_getoverrun
diff --git a/libc/arch-arm64/syscalls/__timer_gettime.S b/libc/arch-arm64/syscalls/__timer_gettime.S
index b6ae29e..c7c4d09 100644
--- a/libc/arch-arm64/syscalls/__timer_gettime.S
+++ b/libc/arch-arm64/syscalls/__timer_gettime.S
@@ -19,4 +19,4 @@
 
     ret
 END(__timer_gettime)
-.hidden _C_LABEL(__timer_gettime)
+.hidden __timer_gettime
diff --git a/libc/arch-arm64/syscalls/__timer_settime.S b/libc/arch-arm64/syscalls/__timer_settime.S
index 3c44b53..4f5f5fc 100644
--- a/libc/arch-arm64/syscalls/__timer_settime.S
+++ b/libc/arch-arm64/syscalls/__timer_settime.S
@@ -19,4 +19,4 @@
 
     ret
 END(__timer_settime)
-.hidden _C_LABEL(__timer_settime)
+.hidden __timer_settime
diff --git a/libc/arch-arm64/syscalls/__waitid.S b/libc/arch-arm64/syscalls/__waitid.S
index 4244018..66e986a 100644
--- a/libc/arch-arm64/syscalls/__waitid.S
+++ b/libc/arch-arm64/syscalls/__waitid.S
@@ -19,4 +19,4 @@
 
     ret
 END(__waitid)
-.hidden _C_LABEL(__waitid)
+.hidden __waitid
diff --git a/libc/arch-mips/bionic/__bionic_clone.S b/libc/arch-mips/bionic/__bionic_clone.S
index 8970b6e..9273134 100644
--- a/libc/arch-mips/bionic/__bionic_clone.S
+++ b/libc/arch-mips/bionic/__bionic_clone.S
@@ -26,49 +26,43 @@
  * SUCH DAMAGE.
  */
 
-#include <asm/unistd.h>
+#include <private/bionic_asm.h>
 #include <linux/errno.h>
 #include <linux/sched.h>
 
 // pid_t __bionic_clone(int flags, void* child_stack, pid_t* parent_tid, void* tls, pid_t* child_tid, int (*fn)(void*), void* arg);
-	.text
-	.type __bionic_clone, @function
-	.global __bionic_clone
-	.align 4
-        .ent __bionic_clone
-__bionic_clone:
+ENTRY(__bionic_clone)
         .set	noreorder
-        .cpload $t9
+        .cpload t9
         .set	reorder
 
 	# set up child stack
-	subu	$a1,16
-	lw	$t0,20($sp)     # fn
-	lw	$t1,24($sp)     # arg
-	sw	$t0,0($a1)	# fn
-	sw	$t1,4($a1)	# arg
+	subu	a1,16
+	lw	t0,20(sp)     # fn
+	lw	t1,24(sp)     # arg
+	sw	t0,0(a1)	# fn
+	sw	t1,4(a1)	# arg
 
 	# remainder of arguments are correct for clone system call
-        li	$v0,__NR_clone
+        li	v0,__NR_clone
         syscall
 
-        bnez	$a3,.L__error_bc
+        bnez	a3,.L__error_bc
 
-        beqz	$v0,.L__thread_start_bc
+        beqz	v0,.L__thread_start_bc
 
-        j $ra
+        j ra
 
 .L__thread_start_bc:
-        lw	$a0,0($sp)	#  fn
-        lw	$a1,4($sp)	#  arg
+        lw	a0,0(sp)	#  fn
+        lw	a1,4(sp)	#  arg
 
 	# void __bionic_clone_entry(int (*func)(void*), void *arg)
-        la	$t9,__bionic_clone_entry
-        j	$t9
+        la	t9,__bionic_clone_entry
+        j	t9
 
 .L__error_bc:
-	move	$a0,$v0
-	la	$t9,__set_errno
-	j	$t9
-
-        .end __bionic_clone
+	move	a0,v0
+	la	t9,__set_errno
+	j	t9
+END(__bionic_clone)
diff --git a/libc/arch-mips/bionic/__get_sp.S b/libc/arch-mips/bionic/__get_sp.S
index 834c89d..d4b278b 100644
--- a/libc/arch-mips/bionic/__get_sp.S
+++ b/libc/arch-mips/bionic/__get_sp.S
@@ -25,15 +25,11 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-	.text
 
-/* void *__get_sp(void) */
+#include <private/bionic_asm.h>
 
-	.type	__get_sp, @function
-	.global	__get_sp
-	.align	4
-	.ent	__get_sp
-__get_sp:
-	move	$v0, $sp
-	j	$ra
-	.end	__get_sp
+// void* __get_sp()
+ENTRY(__get_sp)
+  move v0, sp
+  j ra
+END(__get_sp)
diff --git a/libc/arch-mips/bionic/_exit_with_stack_teardown.S b/libc/arch-mips/bionic/_exit_with_stack_teardown.S
index 8f624c3..129e3f9 100644
--- a/libc/arch-mips/bionic/_exit_with_stack_teardown.S
+++ b/libc/arch-mips/bionic/_exit_with_stack_teardown.S
@@ -26,23 +26,16 @@
  * SUCH DAMAGE.
  */
 
-#include <asm/unistd.h>
-
-	.text
+#include <private/bionic_asm.h>
 
 // void _exit_with_stack_teardown(void* stackBase, size_t stackSize)
-
-	.type	_exit_with_stack_teardown, @function
-	.global	_exit_with_stack_teardown
-	.align	4
-	.ent	_exit_with_stack_teardown
-_exit_with_stack_teardown:
-	li	$v0, __NR_munmap
+ENTRY(_exit_with_stack_teardown)
+	li	v0, __NR_munmap
 	syscall
 	// If munmap failed, we ignore the failure and exit anyway.
 
-	li	$a0, 0
-	li	$v0, __NR_exit
+	li	a0, 0
+	li	v0, __NR_exit
 	syscall
         // The exit syscall does not return.
-	.end	_exit_with_stack_teardown
+END(_exit_with_stack_teardown)
diff --git a/libc/arch-mips/bionic/_setjmp.S b/libc/arch-mips/bionic/_setjmp.S
index e7083ae..4465cd2 100644
--- a/libc/arch-mips/bionic/_setjmp.S
+++ b/libc/arch-mips/bionic/_setjmp.S
@@ -2,7 +2,7 @@
 
 /*
  * Copyright (c) 2002 Opsycon AB  (www.opsycon.se / www.opsycon.com)
- * 
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -29,7 +29,7 @@
  *
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/regnum.h>
 #include <machine/signal.h>
 
@@ -48,13 +48,13 @@
         swc1    FPR, OFF(BASE)  ;       \
         mfhc1   t0, FPR         ;       \
         sw      t0, OFF+4(BASE) ;
-        
+
 #define FPREG64_L(FPR, OFF, BASE)       \
         lw      t0, OFF+4(BASE) ;       \
         lw      t1, OFF(BASE)   ;       \
         mtc1    t1, FPR         ;       \
         mthc1   t0, FPR         ;       \
-        
+
 LEAF(_setjmp, FRAMESZ)
 	PTR_SUBU sp, FRAMESZ
 	SETUP_GP64(GPOFF, _setjmp)
@@ -185,4 +185,3 @@
 	RESTORE_GP64
 	PTR_ADDU sp, FRAMESZ
 END(_longjmp)
-
diff --git a/libc/arch-mips/bionic/bzero.S b/libc/arch-mips/bionic/bzero.S
index 6739345..6e5d294 100644
--- a/libc/arch-mips/bionic/bzero.S
+++ b/libc/arch-mips/bionic/bzero.S
@@ -25,21 +25,15 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-	.text
 
-/*
- * void bzero(void *s, size_t n);
- */
-	.type	bzero, @function
-	.global	bzero
-	.align	4
-	.ent	bzero
+#include <private/bionic_asm.h>
+
+// void bzero(void*, size_t);
+ENTRY(bzero)
 	.set	noreorder
-bzero:
-	.cpload	$t9
-	move	$a2,$a1
-	la	$t9,memset
-	j	$t9
-	 move	$a1,$zero
-	.end	bzero
-
+	.cpload	t9
+	move	a2,a1
+	la	t9,memset
+	j	t9
+	 move	a1,zero
+END(bzero)
diff --git a/libc/arch-mips/bionic/futex_mips.S b/libc/arch-mips/bionic/futex_mips.S
index 5247b79..7626a7c 100644
--- a/libc/arch-mips/bionic/futex_mips.S
+++ b/libc/arch-mips/bionic/futex_mips.S
@@ -32,101 +32,85 @@
 #define FUTEX_WAKE 1
 
 // int __futex_wait(volatile void* ftx, int val, const struct timespec* timeout)
-	.type	__futex_wait, @function
-	.global	__futex_wait
-	.align	4
-	.ent	__futex_wait
-__futex_wait:
-	subu	$sp,4*6
-	sw	$0,20($sp)	/* val3 */
-	sw	$0,16($sp)	/* addr2 */
-	move	$a3,$a2		/* timespec */
-	move	$a2,$a1		/* val */
-	li	$a1,FUTEX_WAIT	/* op */
-#	move	$a0,$a0		/* ftx */
-	li	$v0,__NR_futex
+ENTRY(__futex_wait)
+	subu	sp,4*6
+	sw	$0,20(sp)	/* val3 */
+	sw	$0,16(sp)	/* addr2 */
+	move	a3,a2		/* timespec */
+	move	a2,a1		/* val */
+	li	a1,FUTEX_WAIT	/* op */
+#	move	a0,a0		/* ftx */
+	li	v0,__NR_futex
 	syscall
 	.set noreorder
-	bnez	$a3, 1f		/* Check for error */
-         neg	$v0		/* Negate error number if it's valid */
-	move	$v0,$0		/* Otherwise return 0 */
+	bnez	a3, 1f		/* Check for error */
+         neg	v0		/* Negate error number if it's valid */
+	move	v0,$0		/* Otherwise return 0 */
 1:
 	.set reorder
-	addu	$sp,4*6
-	j	$ra
-	.end	__futex_wait
+	addu	sp,4*6
+	j	ra
+END(__futex_wait)
 
 // int __futex_wake(volatile void* ftx, int count)
-	.type	__futex_wake, @function
-	.globl	__futex_wake
-	.align	4
-	.ent	__futex_wake
-__futex_wake:
-	subu	$sp,4*6
-	sw	$0,20($sp)	/* val3 */
-	sw	$0,16($sp)	/* addr2 */
-	move	$a3,$0		/* timespec */
-	move	$a2,$a1		/* val */
-	li	$a1,FUTEX_WAKE	/* op */
-#	move	$a0,$a0		/* ftx */
-	li	$v0,__NR_futex
+ENTRY(__futex_wake)
+	subu	sp,4*6
+	sw	$0,20(sp)	/* val3 */
+	sw	$0,16(sp)	/* addr2 */
+	move	a3,$0		/* timespec */
+	move	a2,a1		/* val */
+	li	a1,FUTEX_WAKE	/* op */
+#	move	a0,a0		/* ftx */
+	li	v0,__NR_futex
 	syscall
 	.set noreorder
-	bnez	$a3, 1f		/* Check for error */
-         neg	$v0		/* Negate error number if it's valid */
-	move	$v0,$0		/* Otherwise return 0 */
+	bnez	a3, 1f		/* Check for error */
+         neg	v0		/* Negate error number if it's valid */
+	move	v0,$0		/* Otherwise return 0 */
 1:
 	.set reorder
-	addu	$sp,4*6
-	j	$ra
-	.end	__futex_wake
+	addu	sp,4*6
+	j	ra
+END(__futex_wake)
 
 // int __futex_syscall3(volatile void* ftx, int op, int count)
-	.type	__futex_syscall3, @function
-	.global	__futex_syscall3
-	.align	4
-	.ent	__futex_syscall3
-__futex_syscall3:
-	subu	$sp,4*6
-	sw	$0,20($sp)	/* val3 */
-	sw	$0,16($sp)	/* addr2 */
-	move	$a3,$0		/* timespec */
-#	move	$a2,$a2		/* val */
-#	li	$a1,$a1		/* op */
-#	move	$a0,$a0		/* ftx */
-	li	$v0,__NR_futex
+ENTRY(__futex_syscall3)
+	subu	sp,4*6
+	sw	$0,20(sp)	/* val3 */
+	sw	$0,16(sp)	/* addr2 */
+	move	a3,$0		/* timespec */
+#	move	a2,a2		/* val */
+#	li	a1,a1		/* op */
+#	move	a0,a0		/* ftx */
+	li	v0,__NR_futex
 	syscall
 	.set noreorder
-	bnez	$a3, 1f		/* Check for error */
-         neg	$v0		/* Negate error number if it's valid */
-	move	$v0,$0		/* Otherwise return 0 */
+	bnez	a3, 1f		/* Check for error */
+         neg	v0		/* Negate error number if it's valid */
+	move	v0,$0		/* Otherwise return 0 */
 1:
 	.set reorder
-	addu	$sp,4*6
-	j	$ra
-	.end	__futex_syscall3
+	addu	sp,4*6
+	j	ra
+END(__futex_syscall3)
 
 // int __futex_syscall4(volatile void* ftx, int op, int val, const struct timespec* timeout)
-	.type	__futex_syscall4, @function
-	.global	__futex_syscall4
-	.align	4
-	.ent	__futex_syscall4
-__futex_syscall4:
-	subu	$sp,4*6
-	sw	$0,20($sp)	/* val3 */
-	sw	$0,16($sp)	/* addr2 */
-#	move	$a3,$a3		/* timespec */
-#	move	$a2,$a2		/* val */
-#	li	$a1,$a1		/* op */
-#	move	$a0,$a0		/* ftx */
-	li	$v0,__NR_futex
+ENTRY(__futex_syscall4)
+	subu	sp,4*6
+	sw	$0,20(sp)	/* val3 */
+	sw	$0,16(sp)	/* addr2 */
+#	move	a3,a3		/* timespec */
+#	move	a2,a2		/* val */
+#	li	a1,a1		/* op */
+#	move	a0,a0		/* ftx */
+	li	v0,__NR_futex
 	syscall
 	.set noreorder
-	bnez	$a3, 1f		/* Check for error */
-         neg	$v0		/* Negate error number if it's valid */
-	move	$v0,$0		/* Otherwise return 0 */
+	bnez	a3, 1f		/* Check for error */
+         neg	v0		/* Negate error number if it's valid */
+	move	v0,$0		/* Otherwise return 0 */
 1:
 	.set reorder
-	addu	$sp,4*6
-	j	$ra
-	.end	__futex_syscall4
+	addu	sp,4*6
+	j	ra
+END(__futex_syscall4)
diff --git a/libc/arch-mips/bionic/memcmp16.S b/libc/arch-mips/bionic/memcmp16.S
index a2b2544..f9d14a9 100644
--- a/libc/arch-mips/bionic/memcmp16.S
+++ b/libc/arch-mips/bionic/memcmp16.S
@@ -25,31 +25,26 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-	.text
 
-/*
- * u4 __memcmp16(const u2* s0, const u2* s1, size_t count);
- */
-	.type	__memcmp16, @function
-	.global	__memcmp16
-	.align	4
-	.ent __memcmp16
-__memcmp16:
-	li	$t0,0
-	li	$t1,0
-	beqz	$a2,done		/* 0 length string */ 
-	beq	$a0,$a1,done		/* strings are identical */
+#include <private/bionic_asm.h>
+
+// u4 __memcmp16(const u2*, const u2*, size_t);
+ENTRY(__memcmp16)
+	li	t0,0
+	li	t1,0
+	beqz	a2,done		/* 0 length string */ 
+	beq	a0,a1,done		/* strings are identical */
 
 	/* Unoptimised... */
-1:	lhu	$t0,0($a0)
-	lhu	$t1,0($a1)
-	addu	$a1,2
-	bne	$t0,$t1,done
-	addu	$a0,2
-	subu	$a2,1
-	bnez	$a2,1b
+1:	lhu	t0,0(a0)
+	lhu	t1,0(a1)
+	addu	a1,2
+	bne	t0,t1,done
+	addu	a0,2
+	subu	a2,1
+	bnez	a2,1b
 
 done:
-	subu	$v0,$t0,$t1
-	j	$ra
-        .end __memcmp16
+	subu	v0,t0,t1
+	j	ra
+END(__memcmp16)
diff --git a/libc/arch-mips/bionic/setjmp.S b/libc/arch-mips/bionic/setjmp.S
index 7c21195..2af1fbd 100644
--- a/libc/arch-mips/bionic/setjmp.S
+++ b/libc/arch-mips/bionic/setjmp.S
@@ -29,7 +29,7 @@
  *
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/regnum.h>
 #include <machine/signal.h>
 
@@ -49,13 +49,13 @@
         swc1    FPR, OFF(BASE)  ;       \
         mfhc1   t0, FPR         ;       \
         sw      t0, OFF+4(BASE) ;
-        
+
 #define FPREG64_L(FPR, OFF, BASE)       \
         lw      t0, OFF+4(BASE) ;       \
         lw      t1, OFF(BASE)   ;       \
         mtc1    t1, FPR         ;       \
         mthc1   t0, FPR         ;       \
-        
+
 NON_LEAF(setjmp, FRAMESZ, ra)
 	.mask	0x80000000, RAOFF
 	PTR_SUBU sp, FRAMESZ			# allocate stack frame
@@ -154,7 +154,7 @@
 	lw	a0, A0OFF(sp)
 	lw	a1, A1OFF(sp)
 
-	.set	noreorder	
+	.set	noreorder
 	REG_L	v0, SC_REGS+ZERO*REGSZ(a0)
 	bne	v0, 0xACEDBADE, botch		# jump if error
 	REG_L	ra, SC_PC(a0)
@@ -169,9 +169,9 @@
 	REG_L	s8, SC_REGS+S8*REGSZ(a0)
 	REG_L	gp, SC_REGS+GP*REGSZ(a0)
 	REG_L	sp, SC_REGS+SP*REGSZ(a0)
-	
+
 #if !defined(SOFTFLOAT)
-	REG_L	v0, SC_FPREGS+((FSR-F0)*REGSZ)(a0)	
+	REG_L	v0, SC_FPREGS+((FSR-F0)*REGSZ)(a0)
 	ctc1	v0, $31
 #if _MIPS_FPSET == 32
         FPREG64_L($f20, SC_FPREGS+((F20-F0)*REGSZ_FP), a0)
diff --git a/libc/arch-mips/bionic/sigsetjmp.S b/libc/arch-mips/bionic/sigsetjmp.S
index b05454c..9d2e5ea 100644
--- a/libc/arch-mips/bionic/sigsetjmp.S
+++ b/libc/arch-mips/bionic/sigsetjmp.S
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/regnum.h>
 #include <machine/setjmp.h>
 
diff --git a/libc/arch-mips/bionic/syscall.S b/libc/arch-mips/bionic/syscall.S
index af5bcc9..db477a5 100644
--- a/libc/arch-mips/bionic/syscall.S
+++ b/libc/arch-mips/bionic/syscall.S
@@ -26,11 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <asm/unistd.h>
-    .text
-    .globl syscall
-    .align 4
-    .ent syscall
+#include <private/bionic_asm.h>
 
 /*
  * The caller is only required to allocate 16 bytes of stack for a0-a3.
@@ -38,28 +34,28 @@
  */
 #define STACKSIZE 2*4
 
-syscall:
+ENTRY(syscall)
     .set noreorder
-    .cpload $t9
-    move    $v0, $a0
-    move    $a0, $a1
-    move    $a1, $a2
-    move    $a2, $a3
-    lw      $a3, 16($sp)
-    lw      $t0, 20($sp)
-    lw      $t1, 24($sp)
-    subu    $sp, STACKSIZE
-    sw      $t0, 16($sp)
-    sw      $t1, 20($sp)
+    .cpload t9
+    move    v0, a0
+    move    a0, a1
+    move    a1, a2
+    move    a2, a3
+    lw      a3, 16(sp)
+    lw      t0, 20(sp)
+    lw      t1, 24(sp)
+    subu    sp, STACKSIZE
+    sw      t0, 16(sp)
+    sw      t1, 20(sp)
     syscall
-    addu    $sp, STACKSIZE
-    bnez    $a3, 1f
-    move    $a0, $v0
-    j       $ra
+    addu    sp, STACKSIZE
+    bnez    a3, 1f
+    move    a0, v0
+    j       ra
     nop
 1:
-    la      $t9,__set_errno
-    j       $t9
+    la      t9,__set_errno
+    j       t9
     nop
     .set reorder
-    .end syscall
+END(syscall)
diff --git a/libc/arch-mips/bionic/vfork.S b/libc/arch-mips/bionic/vfork.S
index 414caaf..96de69e 100644
--- a/libc/arch-mips/bionic/vfork.S
+++ b/libc/arch-mips/bionic/vfork.S
@@ -26,39 +26,33 @@
  * SUCH DAMAGE.
  */
 
-#include <asm/unistd.h>
+#include <private/bionic_asm.h>
 #include <linux/sched.h>
 
 // TODO: mips' uapi signal.h is missing #ifndef __ASSEMBLY__.
 // #include <asm/signal.h>
 #define SIGCHLD 18
 
-	.text
-
-	.type	vfork, @function
-	.global	vfork
-	.align	4
-	.ent	vfork
-vfork:
+ENTRY(vfork)
 	.set	noreorder
-	.cpload	$t9
+	.cpload	t9
 
-	li	$a0, (CLONE_VM | CLONE_VFORK | SIGCHLD)
-	li	$a1, 0
-	li	$a2, 0
-	li	$a3, 0
-	subu	$sp, 8
-	sw	$0, 16($sp)
-	li	$v0, __NR_clone
+	li	a0, (CLONE_VM | CLONE_VFORK | SIGCHLD)
+	li	a1, 0
+	li	a2, 0
+	li	a3, 0
+	subu	sp, 8
+	sw	$0, 16(sp)
+	li	v0, __NR_clone
 	syscall
-	addu	$sp, 8
-	bnez	$a3, 1f
-	 move	$a0, $v0
+	addu	sp, 8
+	bnez	a3, 1f
+	 move	a0, v0
 
-	j	$ra
+	j	ra
 	 nop
 1:
-	la	$t9, __set_errno
-	j	$t9
+	la	t9, __set_errno
+	j	t9
 	 nop
-	.end	vfork
+END(vfork)
diff --git a/libc/arch-mips/include/machine/asm.h b/libc/arch-mips/include/machine/asm.h
index 43dbc09..5eacde3 100644
--- a/libc/arch-mips/include/machine/asm.h
+++ b/libc/arch-mips/include/machine/asm.h
@@ -28,25 +28,24 @@
 #ifndef _MIPS64_ASM_H
 #define _MIPS64_ASM_H
 
-#include <machine/regdef.h>
-
-#ifdef NEED_OLD_RM7KFIX
-#define ITLBNOPFIX      nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;
-#else
-#define ITLBNOPFIX      nop;nop;nop;nop
+#ifndef _ALIGN_TEXT
+# define _ALIGN_TEXT .align 4
 #endif
 
+#undef __bionic_asm_custom_entry
+#undef __bionic_asm_custom_end
+#define __bionic_asm_custom_entry(f) .ent f
+#define __bionic_asm_custom_end(f) .end f
+
+#include <machine/regdef.h>
+
 #define	_MIPS_ISA_MIPS1	1	/* R2000/R3000 */
 #define	_MIPS_ISA_MIPS2	2	/* R4000/R6000 */
 #define	_MIPS_ISA_MIPS3	3	/* R4000 */
 #define	_MIPS_ISA_MIPS4	4	/* TFP (R1x000) */
-#ifdef __linux__
 #define	_MIPS_ISA_MIPS5 5
 #define	_MIPS_ISA_MIPS32 6
 #define	_MIPS_ISA_MIPS64 7
-#else
-#define	_MIPS_ISA_MIPS32 32	/* MIPS32 */
-#endif
 
 #if !defined(ABICALLS) && !defined(_NO_ABICALLS)
 #define	ABICALLS	.abicalls
@@ -56,8 +55,6 @@
 	ABICALLS
 #endif
 
-#define _C_LABEL(x) x		/* XXX Obsolete but keep for a while */
-
 #if !defined(__MIPSEL__) && !defined(__MIPSEB__)
 #error "__MIPSEL__ or __MIPSEB__ must be defined"
 #endif
@@ -90,15 +87,6 @@
  */
 #if defined(ABICALLS) && !defined(_KERNEL) && !defined(_STANDALONE)
 
-#ifndef _MIPS_SIM
-#define _MIPS_SIM 1
-#define _ABIO32	1
-#endif
-#ifndef _MIPS_ISA
-#define _MIPS_ISA 2
-#define _MIPS_ISA_MIPS2 2
-#endif
-
 #if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
 #define NARGSAVE	4
 
@@ -151,7 +139,7 @@
 #define	CF_RA_OFFS	20	/* Call ra save offset */
 #endif
 
-#if (_MIPS_ISA == _MIPS_ISA_MIPS3 || _MIPS_ISA == _MIPS_ISA_MIPS4)
+#if (_MIPS_ISA == _MIPS_ISA_MIPS3 || _MIPS_ISA == _MIPS_ISA_MIPS4 || _MIPS_ISA == _MIPS_ISA_MIPS64)
 #define REGSZ		8	/* 64 bit mode register size */
 #define LOGREGSZ	3	/* log rsize */
 #define	REG_S	sd
@@ -190,28 +178,6 @@
 #endif
 
 /*
- * Define -pg profile entry code.
- */
-#if defined(XGPROF) || defined(XPROF)
-#define	MCOUNT			\
-	PTR_SUBU sp, sp, 32;	\
-	SAVE_GP(16);		\
-	sw	ra, 28(sp);	\
-	sw	gp, 24(sp);	\
-	.set	noat;		\
-	.set	noreorder;	\
-	move	AT, ra;		\
-	jal	_mcount;	\
-	PTR_SUBU sp, sp, 8;	\
-	lw	ra, 28(sp);	\
-	PTR_ADDU sp, sp, 32;	\
-	.set reorder;		\
-	.set	at;
-#else
-#define	MCOUNT
-#endif
-
-/*
  * LEAF(x, fsize)
  *
  *	Declare a leaf routine.
@@ -221,26 +187,9 @@
 	.globl x;		\
 	.ent x, 0;		\
 x: ;				\
+	.cfi_startproc; \
 	.frame sp, fsize, ra;	\
 	SETUP_GP		\
-	MCOUNT
-
-#define	ALEAF(x)		\
-	.globl	x;		\
-x:
-
-/*
- * NLEAF(x)
- *
- *	Declare a non-profiled leaf routine.
- */
-#define NLEAF(x, fsize)		\
-	.align	3;		\
-	.globl x;		\
-	.ent x, 0;		\
-x: ;				\
-	.frame sp, fsize, ra;	\
-	SETUP_GP
 
 /*
  * NON_LEAF(x)
@@ -252,54 +201,8 @@
 	.globl x;		\
 	.ent x, 0;		\
 x: ;				\
+	.cfi_startproc; \
 	.frame sp, fsize, retpc; \
 	SETUP_GP		\
-	MCOUNT
-
-/*
- * NNON_LEAF(x)
- *
- *	Declare a non-profiled non-leaf routine
- *	(a routine that makes other C calls).
- */
-#define NNON_LEAF(x, fsize, retpc) \
-	.align	3;		\
-	.globl x;		\
-	.ent x, 0;		\
-x: ;				\
-	.frame sp, fsize, retpc	\
-	SETUP_GP
-
-/*
- * END(x)
- *
- *	Mark end of a procedure.
- */
-#define END(x) \
-	.end x
-
-/*
- * Macros to panic and printf from assembly language.
- */
-#define PANIC(msg) \
-	LA	a0, 9f; \
-	jal	panic;	\
-	nop	;	\
-	MSG(msg)
-
-#define	PRINTF(msg) \
-	la	a0, 9f; \
-	jal	printf; \
-	nop	;	\
-	MSG(msg)
-
-#define	MSG(msg) \
-	.rdata; \
-9:	.asciiz	msg; \
-	.text
-
-#define ASMSTR(str) \
-	.asciiz str; \
-	.align	3
 
 #endif /* !_MIPS_ASM_H */
diff --git a/libc/arch-mips/include/machine/signal.h b/libc/arch-mips/include/machine/signal.h
index f02ec0d..b31715c 100644
--- a/libc/arch-mips/include/machine/signal.h
+++ b/libc/arch-mips/include/machine/signal.h
@@ -37,8 +37,6 @@
 #ifndef _MIPS_SIGNAL_H_
 #define _MIPS_SIGNAL_H_
 
-#include <machine/asm.h>
-
 #define	SC_REGMASK	(0*REGSZ)
 #define	SC_STATUS	(1*REGSZ)
 #define	SC_PC		(2*REGSZ)
diff --git a/libc/arch-mips/mips.mk b/libc/arch-mips/mips.mk
index 4e007e5..0fa1ed6 100644
--- a/libc/arch-mips/mips.mk
+++ b/libc/arch-mips/mips.mk
@@ -43,13 +43,10 @@
     bionic/__strcat_chk.cpp \
 
 
-# cflags
 ifneq ($(ARCH_MIPS_HAS_FPU),true)
 libc_common_cflags_mips := \
     -DSOFTFLOAT
 endif
-libc_common_cflags_mips += \
-    -fstrict-aliasing
 
 ##########################################
 ### CPU specific source files
@@ -71,15 +68,7 @@
     arch-mips/string/memset.S \
     arch-mips/string/mips_strlen.c \
 
-# These are used by the static and dynamic versions of the libc
-# respectively.
-libc_arch_static_src_files_mips :=
 
-libc_arch_dynamic_src_files_mips :=
-
-
-##########################################
-# crt-related
 libc_crt_target_cflags_mips := \
     $($(my_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS) \
     -I$(LOCAL_PATH)/arch-mips/include
diff --git a/libc/arch-mips/string/memcpy.S b/libc/arch-mips/string/memcpy.S
index aabdfcf..dc91096 100644
--- a/libc/arch-mips/string/memcpy.S
+++ b/libc/arch-mips/string/memcpy.S
@@ -39,13 +39,13 @@
  *  Include files
  ************************************************************************/
 
-#include "machine/asm.h"
+#include <private/bionic_asm.h>
 
 
-/* 
+/*
  * This routine could be optimized for MIPS64. The current code only
  * uses MIPS32 instructions.
- */	
+ */
 #if defined(__MIPSEB__)
 #  define LWHI	lwl		/* high part is left in big-endian	*/
 #  define SWHI	swl		/* high part is left in big-endian	*/
diff --git a/libc/arch-mips/string/memset.S b/libc/arch-mips/string/memset.S
index a1c5055..3e630ca 100644
--- a/libc/arch-mips/string/memset.S
+++ b/libc/arch-mips/string/memset.S
@@ -39,12 +39,12 @@
  *  Include files
  ************************************************************************/
 
-#include "machine/asm.h"
+#include <private/bionic_asm.h>
 
-/* 
+/*
  * This routine could be optimized for MIPS64. The current code only
  * uses MIPS32 instructions.
- */	
+ */
 
 #if defined(__MIPSEB__)
 #  define SWHI	swl		/* high part is left in big-endian	*/
@@ -220,7 +220,7 @@
 	sw	a1,-36(a0)
 	nop
 	nop			# the extra nop instructions help to balance
-	nop			# cycles needed for "store" + "fill" + "evict" 
+	nop			# cycles needed for "store" + "fill" + "evict"
 	nop			# For 64byte store there are needed 8 fill
 	nop			# and 8 evict cycles, i.e. at least 32 instr.
 	nop
@@ -320,4 +320,3 @@
 /************************************************************************
  *  Implementation : Static functions
  ************************************************************************/
-
diff --git a/libc/arch-mips/syscalls/__brk.S b/libc/arch-mips/syscalls/__brk.S
index 87e13bd..9325c26 100644
--- a/libc/arch-mips/syscalls/__brk.S
+++ b/libc/arch-mips/syscalls/__brk.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __brk
-    .align 4
-    .ent __brk
+#include <private/bionic_asm.h>
 
-__brk:
+ENTRY(__brk)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_brk
+    .cpload t9
+    li v0, __NR_brk
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __brk
+END(__brk)
diff --git a/libc/arch-mips/syscalls/__epoll_pwait.S b/libc/arch-mips/syscalls/__epoll_pwait.S
index 0a5fdae..a417cdd 100644
--- a/libc/arch-mips/syscalls/__epoll_pwait.S
+++ b/libc/arch-mips/syscalls/__epoll_pwait.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __epoll_pwait
-    .align 4
-    .ent __epoll_pwait
+#include <private/bionic_asm.h>
 
-__epoll_pwait:
+ENTRY(__epoll_pwait)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_epoll_pwait
+    .cpload t9
+    li v0, __NR_epoll_pwait
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __epoll_pwait
+END(__epoll_pwait)
diff --git a/libc/arch-mips/syscalls/__exit.S b/libc/arch-mips/syscalls/__exit.S
index 529e49c..1515b41 100644
--- a/libc/arch-mips/syscalls/__exit.S
+++ b/libc/arch-mips/syscalls/__exit.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __exit
-    .align 4
-    .ent __exit
+#include <private/bionic_asm.h>
 
-__exit:
+ENTRY(__exit)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_exit
+    .cpload t9
+    li v0, __NR_exit
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __exit
+END(__exit)
diff --git a/libc/arch-mips/syscalls/__fcntl64.S b/libc/arch-mips/syscalls/__fcntl64.S
index 39ed4cf..b9815a1 100644
--- a/libc/arch-mips/syscalls/__fcntl64.S
+++ b/libc/arch-mips/syscalls/__fcntl64.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __fcntl64
-    .align 4
-    .ent __fcntl64
+#include <private/bionic_asm.h>
 
-__fcntl64:
+ENTRY(__fcntl64)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fcntl64
+    .cpload t9
+    li v0, __NR_fcntl64
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __fcntl64
+END(__fcntl64)
diff --git a/libc/arch-mips/syscalls/__fstatfs64.S b/libc/arch-mips/syscalls/__fstatfs64.S
index 3389a8d..8774a53 100644
--- a/libc/arch-mips/syscalls/__fstatfs64.S
+++ b/libc/arch-mips/syscalls/__fstatfs64.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __fstatfs64
-    .align 4
-    .ent __fstatfs64
+#include <private/bionic_asm.h>
 
-__fstatfs64:
+ENTRY(__fstatfs64)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fstatfs64
+    .cpload t9
+    li v0, __NR_fstatfs64
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __fstatfs64
+END(__fstatfs64)
diff --git a/libc/arch-mips/syscalls/__getcpu.S b/libc/arch-mips/syscalls/__getcpu.S
index d29bd62..2352e01 100644
--- a/libc/arch-mips/syscalls/__getcpu.S
+++ b/libc/arch-mips/syscalls/__getcpu.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __getcpu
-    .align 4
-    .ent __getcpu
+#include <private/bionic_asm.h>
 
-__getcpu:
+ENTRY(__getcpu)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getcpu
+    .cpload t9
+    li v0, __NR_getcpu
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __getcpu
+END(__getcpu)
diff --git a/libc/arch-mips/syscalls/__getcwd.S b/libc/arch-mips/syscalls/__getcwd.S
index ce05d92..e844f9a 100644
--- a/libc/arch-mips/syscalls/__getcwd.S
+++ b/libc/arch-mips/syscalls/__getcwd.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __getcwd
-    .align 4
-    .ent __getcwd
+#include <private/bionic_asm.h>
 
-__getcwd:
+ENTRY(__getcwd)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getcwd
+    .cpload t9
+    li v0, __NR_getcwd
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __getcwd
+END(__getcwd)
diff --git a/libc/arch-mips/syscalls/__getpriority.S b/libc/arch-mips/syscalls/__getpriority.S
index 767b6d0..882386b 100644
--- a/libc/arch-mips/syscalls/__getpriority.S
+++ b/libc/arch-mips/syscalls/__getpriority.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __getpriority
-    .align 4
-    .ent __getpriority
+#include <private/bionic_asm.h>
 
-__getpriority:
+ENTRY(__getpriority)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getpriority
+    .cpload t9
+    li v0, __NR_getpriority
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __getpriority
+END(__getpriority)
diff --git a/libc/arch-mips/syscalls/__ioctl.S b/libc/arch-mips/syscalls/__ioctl.S
index 3d83c60..ddf5323 100644
--- a/libc/arch-mips/syscalls/__ioctl.S
+++ b/libc/arch-mips/syscalls/__ioctl.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __ioctl
-    .align 4
-    .ent __ioctl
+#include <private/bionic_asm.h>
 
-__ioctl:
+ENTRY(__ioctl)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_ioctl
+    .cpload t9
+    li v0, __NR_ioctl
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __ioctl
+END(__ioctl)
diff --git a/libc/arch-mips/syscalls/__llseek.S b/libc/arch-mips/syscalls/__llseek.S
index 9a3753b..10819f7 100644
--- a/libc/arch-mips/syscalls/__llseek.S
+++ b/libc/arch-mips/syscalls/__llseek.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __llseek
-    .align 4
-    .ent __llseek
+#include <private/bionic_asm.h>
 
-__llseek:
+ENTRY(__llseek)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR__llseek
+    .cpload t9
+    li v0, __NR__llseek
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __llseek
+END(__llseek)
diff --git a/libc/arch-mips/syscalls/__mmap2.S b/libc/arch-mips/syscalls/__mmap2.S
index 723e80ef..5372817 100644
--- a/libc/arch-mips/syscalls/__mmap2.S
+++ b/libc/arch-mips/syscalls/__mmap2.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __mmap2
-    .align 4
-    .ent __mmap2
+#include <private/bionic_asm.h>
 
-__mmap2:
+ENTRY(__mmap2)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_mmap2
+    .cpload t9
+    li v0, __NR_mmap2
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __mmap2
+END(__mmap2)
diff --git a/libc/arch-mips/syscalls/__openat.S b/libc/arch-mips/syscalls/__openat.S
index e55e71d..f833dd8 100644
--- a/libc/arch-mips/syscalls/__openat.S
+++ b/libc/arch-mips/syscalls/__openat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __openat
-    .align 4
-    .ent __openat
+#include <private/bionic_asm.h>
 
-__openat:
+ENTRY(__openat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_openat
+    .cpload t9
+    li v0, __NR_openat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __openat
+END(__openat)
diff --git a/libc/arch-mips/syscalls/__ppoll.S b/libc/arch-mips/syscalls/__ppoll.S
index ef6d343..a5711d9 100644
--- a/libc/arch-mips/syscalls/__ppoll.S
+++ b/libc/arch-mips/syscalls/__ppoll.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __ppoll
-    .align 4
-    .ent __ppoll
+#include <private/bionic_asm.h>
 
-__ppoll:
+ENTRY(__ppoll)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_ppoll
+    .cpload t9
+    li v0, __NR_ppoll
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __ppoll
+END(__ppoll)
diff --git a/libc/arch-mips/syscalls/__pselect6.S b/libc/arch-mips/syscalls/__pselect6.S
index 26af92a..4c0a0a5 100644
--- a/libc/arch-mips/syscalls/__pselect6.S
+++ b/libc/arch-mips/syscalls/__pselect6.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __pselect6
-    .align 4
-    .ent __pselect6
+#include <private/bionic_asm.h>
 
-__pselect6:
+ENTRY(__pselect6)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_pselect6
+    .cpload t9
+    li v0, __NR_pselect6
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __pselect6
+END(__pselect6)
diff --git a/libc/arch-mips/syscalls/__ptrace.S b/libc/arch-mips/syscalls/__ptrace.S
index f2ea8c7..fcbe529 100644
--- a/libc/arch-mips/syscalls/__ptrace.S
+++ b/libc/arch-mips/syscalls/__ptrace.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __ptrace
-    .align 4
-    .ent __ptrace
+#include <private/bionic_asm.h>
 
-__ptrace:
+ENTRY(__ptrace)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_ptrace
+    .cpload t9
+    li v0, __NR_ptrace
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __ptrace
+END(__ptrace)
diff --git a/libc/arch-mips/syscalls/__reboot.S b/libc/arch-mips/syscalls/__reboot.S
index 95ba5d8..4aa0e7a 100644
--- a/libc/arch-mips/syscalls/__reboot.S
+++ b/libc/arch-mips/syscalls/__reboot.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __reboot
-    .align 4
-    .ent __reboot
+#include <private/bionic_asm.h>
 
-__reboot:
+ENTRY(__reboot)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_reboot
+    .cpload t9
+    li v0, __NR_reboot
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __reboot
+END(__reboot)
diff --git a/libc/arch-mips/syscalls/__rt_sigaction.S b/libc/arch-mips/syscalls/__rt_sigaction.S
index 73253d6..6c5bc37 100644
--- a/libc/arch-mips/syscalls/__rt_sigaction.S
+++ b/libc/arch-mips/syscalls/__rt_sigaction.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __rt_sigaction
-    .align 4
-    .ent __rt_sigaction
+#include <private/bionic_asm.h>
 
-__rt_sigaction:
+ENTRY(__rt_sigaction)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_rt_sigaction
+    .cpload t9
+    li v0, __NR_rt_sigaction
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __rt_sigaction
+END(__rt_sigaction)
diff --git a/libc/arch-mips/syscalls/__rt_sigpending.S b/libc/arch-mips/syscalls/__rt_sigpending.S
index 90357b3..e62f079 100644
--- a/libc/arch-mips/syscalls/__rt_sigpending.S
+++ b/libc/arch-mips/syscalls/__rt_sigpending.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __rt_sigpending
-    .align 4
-    .ent __rt_sigpending
+#include <private/bionic_asm.h>
 
-__rt_sigpending:
+ENTRY(__rt_sigpending)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_rt_sigpending
+    .cpload t9
+    li v0, __NR_rt_sigpending
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __rt_sigpending
+END(__rt_sigpending)
diff --git a/libc/arch-mips/syscalls/__rt_sigprocmask.S b/libc/arch-mips/syscalls/__rt_sigprocmask.S
index 0d34e37..94ef493 100644
--- a/libc/arch-mips/syscalls/__rt_sigprocmask.S
+++ b/libc/arch-mips/syscalls/__rt_sigprocmask.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __rt_sigprocmask
-    .align 4
-    .ent __rt_sigprocmask
+#include <private/bionic_asm.h>
 
-__rt_sigprocmask:
+ENTRY(__rt_sigprocmask)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_rt_sigprocmask
+    .cpload t9
+    li v0, __NR_rt_sigprocmask
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __rt_sigprocmask
+END(__rt_sigprocmask)
diff --git a/libc/arch-mips/syscalls/__rt_sigsuspend.S b/libc/arch-mips/syscalls/__rt_sigsuspend.S
index 3ff4723..077746f 100644
--- a/libc/arch-mips/syscalls/__rt_sigsuspend.S
+++ b/libc/arch-mips/syscalls/__rt_sigsuspend.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __rt_sigsuspend
-    .align 4
-    .ent __rt_sigsuspend
+#include <private/bionic_asm.h>
 
-__rt_sigsuspend:
+ENTRY(__rt_sigsuspend)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_rt_sigsuspend
+    .cpload t9
+    li v0, __NR_rt_sigsuspend
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __rt_sigsuspend
+END(__rt_sigsuspend)
diff --git a/libc/arch-mips/syscalls/__rt_sigtimedwait.S b/libc/arch-mips/syscalls/__rt_sigtimedwait.S
index 19a5ce9..404eab7 100644
--- a/libc/arch-mips/syscalls/__rt_sigtimedwait.S
+++ b/libc/arch-mips/syscalls/__rt_sigtimedwait.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __rt_sigtimedwait
-    .align 4
-    .ent __rt_sigtimedwait
+#include <private/bionic_asm.h>
 
-__rt_sigtimedwait:
+ENTRY(__rt_sigtimedwait)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_rt_sigtimedwait
+    .cpload t9
+    li v0, __NR_rt_sigtimedwait
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __rt_sigtimedwait
+END(__rt_sigtimedwait)
diff --git a/libc/arch-mips/syscalls/__sched_getaffinity.S b/libc/arch-mips/syscalls/__sched_getaffinity.S
index 0038ff9..da71709 100644
--- a/libc/arch-mips/syscalls/__sched_getaffinity.S
+++ b/libc/arch-mips/syscalls/__sched_getaffinity.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __sched_getaffinity
-    .align 4
-    .ent __sched_getaffinity
+#include <private/bionic_asm.h>
 
-__sched_getaffinity:
+ENTRY(__sched_getaffinity)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sched_getaffinity
+    .cpload t9
+    li v0, __NR_sched_getaffinity
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __sched_getaffinity
+END(__sched_getaffinity)
diff --git a/libc/arch-mips/syscalls/__set_thread_area.S b/libc/arch-mips/syscalls/__set_thread_area.S
index 69383e9..f83249e 100644
--- a/libc/arch-mips/syscalls/__set_thread_area.S
+++ b/libc/arch-mips/syscalls/__set_thread_area.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __set_thread_area
-    .align 4
-    .ent __set_thread_area
+#include <private/bionic_asm.h>
 
-__set_thread_area:
+ENTRY(__set_thread_area)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_set_thread_area
+    .cpload t9
+    li v0, __NR_set_thread_area
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __set_thread_area
+END(__set_thread_area)
diff --git a/libc/arch-mips/syscalls/__set_tid_address.S b/libc/arch-mips/syscalls/__set_tid_address.S
index 4fcc82a..146cd0d 100644
--- a/libc/arch-mips/syscalls/__set_tid_address.S
+++ b/libc/arch-mips/syscalls/__set_tid_address.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __set_tid_address
-    .align 4
-    .ent __set_tid_address
+#include <private/bionic_asm.h>
 
-__set_tid_address:
+ENTRY(__set_tid_address)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_set_tid_address
+    .cpload t9
+    li v0, __NR_set_tid_address
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __set_tid_address
+END(__set_tid_address)
diff --git a/libc/arch-mips/syscalls/__sigaction.S b/libc/arch-mips/syscalls/__sigaction.S
index cc53ab4..03dd9da 100644
--- a/libc/arch-mips/syscalls/__sigaction.S
+++ b/libc/arch-mips/syscalls/__sigaction.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __sigaction
-    .align 4
-    .ent __sigaction
+#include <private/bionic_asm.h>
 
-__sigaction:
+ENTRY(__sigaction)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sigaction
+    .cpload t9
+    li v0, __NR_sigaction
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __sigaction
+END(__sigaction)
diff --git a/libc/arch-mips/syscalls/__statfs64.S b/libc/arch-mips/syscalls/__statfs64.S
index 4b3351c..9f94e6a 100644
--- a/libc/arch-mips/syscalls/__statfs64.S
+++ b/libc/arch-mips/syscalls/__statfs64.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __statfs64
-    .align 4
-    .ent __statfs64
+#include <private/bionic_asm.h>
 
-__statfs64:
+ENTRY(__statfs64)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_statfs64
+    .cpload t9
+    li v0, __NR_statfs64
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __statfs64
+END(__statfs64)
diff --git a/libc/arch-mips/syscalls/__syslog.S b/libc/arch-mips/syscalls/__syslog.S
index 61a3242..ace69c7 100644
--- a/libc/arch-mips/syscalls/__syslog.S
+++ b/libc/arch-mips/syscalls/__syslog.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __syslog
-    .align 4
-    .ent __syslog
+#include <private/bionic_asm.h>
 
-__syslog:
+ENTRY(__syslog)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_syslog
+    .cpload t9
+    li v0, __NR_syslog
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __syslog
+END(__syslog)
diff --git a/libc/arch-mips/syscalls/__timer_create.S b/libc/arch-mips/syscalls/__timer_create.S
index 054c1b9..449bd28 100644
--- a/libc/arch-mips/syscalls/__timer_create.S
+++ b/libc/arch-mips/syscalls/__timer_create.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __timer_create
-    .align 4
-    .ent __timer_create
+#include <private/bionic_asm.h>
 
-__timer_create:
+ENTRY(__timer_create)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_timer_create
+    .cpload t9
+    li v0, __NR_timer_create
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __timer_create
+END(__timer_create)
diff --git a/libc/arch-mips/syscalls/__timer_delete.S b/libc/arch-mips/syscalls/__timer_delete.S
index 2fa6e50..7bc5e05 100644
--- a/libc/arch-mips/syscalls/__timer_delete.S
+++ b/libc/arch-mips/syscalls/__timer_delete.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __timer_delete
-    .align 4
-    .ent __timer_delete
+#include <private/bionic_asm.h>
 
-__timer_delete:
+ENTRY(__timer_delete)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_timer_delete
+    .cpload t9
+    li v0, __NR_timer_delete
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __timer_delete
+END(__timer_delete)
diff --git a/libc/arch-mips/syscalls/__timer_getoverrun.S b/libc/arch-mips/syscalls/__timer_getoverrun.S
index 269ac4d..7382c91 100644
--- a/libc/arch-mips/syscalls/__timer_getoverrun.S
+++ b/libc/arch-mips/syscalls/__timer_getoverrun.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __timer_getoverrun
-    .align 4
-    .ent __timer_getoverrun
+#include <private/bionic_asm.h>
 
-__timer_getoverrun:
+ENTRY(__timer_getoverrun)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_timer_getoverrun
+    .cpload t9
+    li v0, __NR_timer_getoverrun
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __timer_getoverrun
+END(__timer_getoverrun)
diff --git a/libc/arch-mips/syscalls/__timer_gettime.S b/libc/arch-mips/syscalls/__timer_gettime.S
index 3a18e3d..d6195b9 100644
--- a/libc/arch-mips/syscalls/__timer_gettime.S
+++ b/libc/arch-mips/syscalls/__timer_gettime.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __timer_gettime
-    .align 4
-    .ent __timer_gettime
+#include <private/bionic_asm.h>
 
-__timer_gettime:
+ENTRY(__timer_gettime)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_timer_gettime
+    .cpload t9
+    li v0, __NR_timer_gettime
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __timer_gettime
+END(__timer_gettime)
diff --git a/libc/arch-mips/syscalls/__timer_settime.S b/libc/arch-mips/syscalls/__timer_settime.S
index daf671f..9fbab86 100644
--- a/libc/arch-mips/syscalls/__timer_settime.S
+++ b/libc/arch-mips/syscalls/__timer_settime.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __timer_settime
-    .align 4
-    .ent __timer_settime
+#include <private/bionic_asm.h>
 
-__timer_settime:
+ENTRY(__timer_settime)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_timer_settime
+    .cpload t9
+    li v0, __NR_timer_settime
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __timer_settime
+END(__timer_settime)
diff --git a/libc/arch-mips/syscalls/__waitid.S b/libc/arch-mips/syscalls/__waitid.S
index 9442ca6..4c9142e 100644
--- a/libc/arch-mips/syscalls/__waitid.S
+++ b/libc/arch-mips/syscalls/__waitid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl __waitid
-    .align 4
-    .ent __waitid
+#include <private/bionic_asm.h>
 
-__waitid:
+ENTRY(__waitid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_waitid
+    .cpload t9
+    li v0, __NR_waitid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end __waitid
+END(__waitid)
diff --git a/libc/arch-mips/syscalls/_exit.S b/libc/arch-mips/syscalls/_exit.S
index 220876a..5a0877d 100644
--- a/libc/arch-mips/syscalls/_exit.S
+++ b/libc/arch-mips/syscalls/_exit.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl _exit
-    .align 4
-    .ent _exit
+#include <private/bionic_asm.h>
 
-_exit:
+ENTRY(_exit)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_exit_group
+    .cpload t9
+    li v0, __NR_exit_group
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end _exit
+END(_exit)
diff --git a/libc/arch-mips/syscalls/_flush_cache.S b/libc/arch-mips/syscalls/_flush_cache.S
index 0ac2576..64967fe 100644
--- a/libc/arch-mips/syscalls/_flush_cache.S
+++ b/libc/arch-mips/syscalls/_flush_cache.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl _flush_cache
-    .align 4
-    .ent _flush_cache
+#include <private/bionic_asm.h>
 
-_flush_cache:
+ENTRY(_flush_cache)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_cacheflush
+    .cpload t9
+    li v0, __NR_cacheflush
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end _flush_cache
+END(_flush_cache)
diff --git a/libc/arch-mips/syscalls/accept.S b/libc/arch-mips/syscalls/accept.S
index f4da4d8..09496ab 100644
--- a/libc/arch-mips/syscalls/accept.S
+++ b/libc/arch-mips/syscalls/accept.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl accept
-    .align 4
-    .ent accept
+#include <private/bionic_asm.h>
 
-accept:
+ENTRY(accept)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_accept
+    .cpload t9
+    li v0, __NR_accept
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end accept
+END(accept)
diff --git a/libc/arch-mips/syscalls/acct.S b/libc/arch-mips/syscalls/acct.S
index c641b9c..6e4a4f2 100644
--- a/libc/arch-mips/syscalls/acct.S
+++ b/libc/arch-mips/syscalls/acct.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl acct
-    .align 4
-    .ent acct
+#include <private/bionic_asm.h>
 
-acct:
+ENTRY(acct)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_acct
+    .cpload t9
+    li v0, __NR_acct
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end acct
+END(acct)
diff --git a/libc/arch-mips/syscalls/bind.S b/libc/arch-mips/syscalls/bind.S
index 912b161..9119aa8 100644
--- a/libc/arch-mips/syscalls/bind.S
+++ b/libc/arch-mips/syscalls/bind.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl bind
-    .align 4
-    .ent bind
+#include <private/bionic_asm.h>
 
-bind:
+ENTRY(bind)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_bind
+    .cpload t9
+    li v0, __NR_bind
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end bind
+END(bind)
diff --git a/libc/arch-mips/syscalls/capget.S b/libc/arch-mips/syscalls/capget.S
index 48f7be3..549dc76 100644
--- a/libc/arch-mips/syscalls/capget.S
+++ b/libc/arch-mips/syscalls/capget.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl capget
-    .align 4
-    .ent capget
+#include <private/bionic_asm.h>
 
-capget:
+ENTRY(capget)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_capget
+    .cpload t9
+    li v0, __NR_capget
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end capget
+END(capget)
diff --git a/libc/arch-mips/syscalls/capset.S b/libc/arch-mips/syscalls/capset.S
index 40223c2..637ac37 100644
--- a/libc/arch-mips/syscalls/capset.S
+++ b/libc/arch-mips/syscalls/capset.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl capset
-    .align 4
-    .ent capset
+#include <private/bionic_asm.h>
 
-capset:
+ENTRY(capset)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_capset
+    .cpload t9
+    li v0, __NR_capset
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end capset
+END(capset)
diff --git a/libc/arch-mips/syscalls/chdir.S b/libc/arch-mips/syscalls/chdir.S
index 4f427a1..752e4e7 100644
--- a/libc/arch-mips/syscalls/chdir.S
+++ b/libc/arch-mips/syscalls/chdir.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl chdir
-    .align 4
-    .ent chdir
+#include <private/bionic_asm.h>
 
-chdir:
+ENTRY(chdir)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_chdir
+    .cpload t9
+    li v0, __NR_chdir
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end chdir
+END(chdir)
diff --git a/libc/arch-mips/syscalls/chroot.S b/libc/arch-mips/syscalls/chroot.S
index a501459..d1ffc97 100644
--- a/libc/arch-mips/syscalls/chroot.S
+++ b/libc/arch-mips/syscalls/chroot.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl chroot
-    .align 4
-    .ent chroot
+#include <private/bionic_asm.h>
 
-chroot:
+ENTRY(chroot)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_chroot
+    .cpload t9
+    li v0, __NR_chroot
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end chroot
+END(chroot)
diff --git a/libc/arch-mips/syscalls/clock_getres.S b/libc/arch-mips/syscalls/clock_getres.S
index d3986fc..49d9bba 100644
--- a/libc/arch-mips/syscalls/clock_getres.S
+++ b/libc/arch-mips/syscalls/clock_getres.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl clock_getres
-    .align 4
-    .ent clock_getres
+#include <private/bionic_asm.h>
 
-clock_getres:
+ENTRY(clock_getres)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_clock_getres
+    .cpload t9
+    li v0, __NR_clock_getres
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end clock_getres
+END(clock_getres)
diff --git a/libc/arch-mips/syscalls/clock_gettime.S b/libc/arch-mips/syscalls/clock_gettime.S
index fa02309..42929e8 100644
--- a/libc/arch-mips/syscalls/clock_gettime.S
+++ b/libc/arch-mips/syscalls/clock_gettime.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl clock_gettime
-    .align 4
-    .ent clock_gettime
+#include <private/bionic_asm.h>
 
-clock_gettime:
+ENTRY(clock_gettime)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_clock_gettime
+    .cpload t9
+    li v0, __NR_clock_gettime
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end clock_gettime
+END(clock_gettime)
diff --git a/libc/arch-mips/syscalls/clock_nanosleep.S b/libc/arch-mips/syscalls/clock_nanosleep.S
index 91a1418..e7c25ce 100644
--- a/libc/arch-mips/syscalls/clock_nanosleep.S
+++ b/libc/arch-mips/syscalls/clock_nanosleep.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl clock_nanosleep
-    .align 4
-    .ent clock_nanosleep
+#include <private/bionic_asm.h>
 
-clock_nanosleep:
+ENTRY(clock_nanosleep)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_clock_nanosleep
+    .cpload t9
+    li v0, __NR_clock_nanosleep
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end clock_nanosleep
+END(clock_nanosleep)
diff --git a/libc/arch-mips/syscalls/clock_settime.S b/libc/arch-mips/syscalls/clock_settime.S
index d8eb8f1..e7dda91 100644
--- a/libc/arch-mips/syscalls/clock_settime.S
+++ b/libc/arch-mips/syscalls/clock_settime.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl clock_settime
-    .align 4
-    .ent clock_settime
+#include <private/bionic_asm.h>
 
-clock_settime:
+ENTRY(clock_settime)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_clock_settime
+    .cpload t9
+    li v0, __NR_clock_settime
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end clock_settime
+END(clock_settime)
diff --git a/libc/arch-mips/syscalls/close.S b/libc/arch-mips/syscalls/close.S
index 098fdd2..bc2c325 100644
--- a/libc/arch-mips/syscalls/close.S
+++ b/libc/arch-mips/syscalls/close.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl close
-    .align 4
-    .ent close
+#include <private/bionic_asm.h>
 
-close:
+ENTRY(close)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_close
+    .cpload t9
+    li v0, __NR_close
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end close
+END(close)
diff --git a/libc/arch-mips/syscalls/connect.S b/libc/arch-mips/syscalls/connect.S
index d3b0cea..6f10652 100644
--- a/libc/arch-mips/syscalls/connect.S
+++ b/libc/arch-mips/syscalls/connect.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl connect
-    .align 4
-    .ent connect
+#include <private/bionic_asm.h>
 
-connect:
+ENTRY(connect)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_connect
+    .cpload t9
+    li v0, __NR_connect
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end connect
+END(connect)
diff --git a/libc/arch-mips/syscalls/delete_module.S b/libc/arch-mips/syscalls/delete_module.S
index ae47697..9247f5a 100644
--- a/libc/arch-mips/syscalls/delete_module.S
+++ b/libc/arch-mips/syscalls/delete_module.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl delete_module
-    .align 4
-    .ent delete_module
+#include <private/bionic_asm.h>
 
-delete_module:
+ENTRY(delete_module)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_delete_module
+    .cpload t9
+    li v0, __NR_delete_module
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end delete_module
+END(delete_module)
diff --git a/libc/arch-mips/syscalls/dup.S b/libc/arch-mips/syscalls/dup.S
index 6cb924f..61b1c03 100644
--- a/libc/arch-mips/syscalls/dup.S
+++ b/libc/arch-mips/syscalls/dup.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl dup
-    .align 4
-    .ent dup
+#include <private/bionic_asm.h>
 
-dup:
+ENTRY(dup)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_dup
+    .cpload t9
+    li v0, __NR_dup
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end dup
+END(dup)
diff --git a/libc/arch-mips/syscalls/dup3.S b/libc/arch-mips/syscalls/dup3.S
index 6a3752c..d0694e8 100644
--- a/libc/arch-mips/syscalls/dup3.S
+++ b/libc/arch-mips/syscalls/dup3.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl dup3
-    .align 4
-    .ent dup3
+#include <private/bionic_asm.h>
 
-dup3:
+ENTRY(dup3)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_dup3
+    .cpload t9
+    li v0, __NR_dup3
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end dup3
+END(dup3)
diff --git a/libc/arch-mips/syscalls/epoll_create1.S b/libc/arch-mips/syscalls/epoll_create1.S
index 0abaeda..2043f39 100644
--- a/libc/arch-mips/syscalls/epoll_create1.S
+++ b/libc/arch-mips/syscalls/epoll_create1.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl epoll_create1
-    .align 4
-    .ent epoll_create1
+#include <private/bionic_asm.h>
 
-epoll_create1:
+ENTRY(epoll_create1)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_epoll_create1
+    .cpload t9
+    li v0, __NR_epoll_create1
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end epoll_create1
+END(epoll_create1)
diff --git a/libc/arch-mips/syscalls/epoll_ctl.S b/libc/arch-mips/syscalls/epoll_ctl.S
index 20d4367..9474d3a 100644
--- a/libc/arch-mips/syscalls/epoll_ctl.S
+++ b/libc/arch-mips/syscalls/epoll_ctl.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl epoll_ctl
-    .align 4
-    .ent epoll_ctl
+#include <private/bionic_asm.h>
 
-epoll_ctl:
+ENTRY(epoll_ctl)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_epoll_ctl
+    .cpload t9
+    li v0, __NR_epoll_ctl
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end epoll_ctl
+END(epoll_ctl)
diff --git a/libc/arch-mips/syscalls/eventfd.S b/libc/arch-mips/syscalls/eventfd.S
index f12bc7d..5282a91 100644
--- a/libc/arch-mips/syscalls/eventfd.S
+++ b/libc/arch-mips/syscalls/eventfd.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl eventfd
-    .align 4
-    .ent eventfd
+#include <private/bionic_asm.h>
 
-eventfd:
+ENTRY(eventfd)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_eventfd2
+    .cpload t9
+    li v0, __NR_eventfd2
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end eventfd
+END(eventfd)
diff --git a/libc/arch-mips/syscalls/execve.S b/libc/arch-mips/syscalls/execve.S
index 750b402..fcaec0a 100644
--- a/libc/arch-mips/syscalls/execve.S
+++ b/libc/arch-mips/syscalls/execve.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl execve
-    .align 4
-    .ent execve
+#include <private/bionic_asm.h>
 
-execve:
+ENTRY(execve)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_execve
+    .cpload t9
+    li v0, __NR_execve
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end execve
+END(execve)
diff --git a/libc/arch-mips/syscalls/faccessat.S b/libc/arch-mips/syscalls/faccessat.S
index ffa4f42..e7afe2a 100644
--- a/libc/arch-mips/syscalls/faccessat.S
+++ b/libc/arch-mips/syscalls/faccessat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl faccessat
-    .align 4
-    .ent faccessat
+#include <private/bionic_asm.h>
 
-faccessat:
+ENTRY(faccessat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_faccessat
+    .cpload t9
+    li v0, __NR_faccessat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end faccessat
+END(faccessat)
diff --git a/libc/arch-mips/syscalls/fallocate64.S b/libc/arch-mips/syscalls/fallocate64.S
index e844d16..d814606 100644
--- a/libc/arch-mips/syscalls/fallocate64.S
+++ b/libc/arch-mips/syscalls/fallocate64.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fallocate64
-    .align 4
-    .ent fallocate64
+#include <private/bionic_asm.h>
 
-fallocate64:
+ENTRY(fallocate64)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fallocate
+    .cpload t9
+    li v0, __NR_fallocate
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end fallocate64
+END(fallocate64)
diff --git a/libc/arch-mips/syscalls/fchdir.S b/libc/arch-mips/syscalls/fchdir.S
index ae0b883..daac0f5 100644
--- a/libc/arch-mips/syscalls/fchdir.S
+++ b/libc/arch-mips/syscalls/fchdir.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fchdir
-    .align 4
-    .ent fchdir
+#include <private/bionic_asm.h>
 
-fchdir:
+ENTRY(fchdir)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fchdir
+    .cpload t9
+    li v0, __NR_fchdir
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end fchdir
+END(fchdir)
diff --git a/libc/arch-mips/syscalls/fchmod.S b/libc/arch-mips/syscalls/fchmod.S
index 272964e..e947e41 100644
--- a/libc/arch-mips/syscalls/fchmod.S
+++ b/libc/arch-mips/syscalls/fchmod.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fchmod
-    .align 4
-    .ent fchmod
+#include <private/bionic_asm.h>
 
-fchmod:
+ENTRY(fchmod)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fchmod
+    .cpload t9
+    li v0, __NR_fchmod
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end fchmod
+END(fchmod)
diff --git a/libc/arch-mips/syscalls/fchmodat.S b/libc/arch-mips/syscalls/fchmodat.S
index 388d221..4d2a7d3 100644
--- a/libc/arch-mips/syscalls/fchmodat.S
+++ b/libc/arch-mips/syscalls/fchmodat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fchmodat
-    .align 4
-    .ent fchmodat
+#include <private/bionic_asm.h>
 
-fchmodat:
+ENTRY(fchmodat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fchmodat
+    .cpload t9
+    li v0, __NR_fchmodat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end fchmodat
+END(fchmodat)
diff --git a/libc/arch-mips/syscalls/fchown.S b/libc/arch-mips/syscalls/fchown.S
index 52d6e59..f59c0f4 100644
--- a/libc/arch-mips/syscalls/fchown.S
+++ b/libc/arch-mips/syscalls/fchown.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fchown
-    .align 4
-    .ent fchown
+#include <private/bionic_asm.h>
 
-fchown:
+ENTRY(fchown)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fchown
+    .cpload t9
+    li v0, __NR_fchown
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end fchown
+END(fchown)
diff --git a/libc/arch-mips/syscalls/fchownat.S b/libc/arch-mips/syscalls/fchownat.S
index 6913d6c..af44cbc 100644
--- a/libc/arch-mips/syscalls/fchownat.S
+++ b/libc/arch-mips/syscalls/fchownat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fchownat
-    .align 4
-    .ent fchownat
+#include <private/bionic_asm.h>
 
-fchownat:
+ENTRY(fchownat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fchownat
+    .cpload t9
+    li v0, __NR_fchownat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end fchownat
+END(fchownat)
diff --git a/libc/arch-mips/syscalls/fdatasync.S b/libc/arch-mips/syscalls/fdatasync.S
index a1d4056..07e3592 100644
--- a/libc/arch-mips/syscalls/fdatasync.S
+++ b/libc/arch-mips/syscalls/fdatasync.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fdatasync
-    .align 4
-    .ent fdatasync
+#include <private/bionic_asm.h>
 
-fdatasync:
+ENTRY(fdatasync)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fdatasync
+    .cpload t9
+    li v0, __NR_fdatasync
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end fdatasync
+END(fdatasync)
diff --git a/libc/arch-mips/syscalls/fgetxattr.S b/libc/arch-mips/syscalls/fgetxattr.S
index 1d645a5..035e71c 100644
--- a/libc/arch-mips/syscalls/fgetxattr.S
+++ b/libc/arch-mips/syscalls/fgetxattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fgetxattr
-    .align 4
-    .ent fgetxattr
+#include <private/bionic_asm.h>
 
-fgetxattr:
+ENTRY(fgetxattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fgetxattr
+    .cpload t9
+    li v0, __NR_fgetxattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end fgetxattr
+END(fgetxattr)
diff --git a/libc/arch-mips/syscalls/flistxattr.S b/libc/arch-mips/syscalls/flistxattr.S
index 2cb53c5..500cd97 100644
--- a/libc/arch-mips/syscalls/flistxattr.S
+++ b/libc/arch-mips/syscalls/flistxattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl flistxattr
-    .align 4
-    .ent flistxattr
+#include <private/bionic_asm.h>
 
-flistxattr:
+ENTRY(flistxattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_flistxattr
+    .cpload t9
+    li v0, __NR_flistxattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end flistxattr
+END(flistxattr)
diff --git a/libc/arch-mips/syscalls/flock.S b/libc/arch-mips/syscalls/flock.S
index c1723a1..7d843ab 100644
--- a/libc/arch-mips/syscalls/flock.S
+++ b/libc/arch-mips/syscalls/flock.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl flock
-    .align 4
-    .ent flock
+#include <private/bionic_asm.h>
 
-flock:
+ENTRY(flock)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_flock
+    .cpload t9
+    li v0, __NR_flock
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end flock
+END(flock)
diff --git a/libc/arch-mips/syscalls/fremovexattr.S b/libc/arch-mips/syscalls/fremovexattr.S
index 2526ae0..9f16186 100644
--- a/libc/arch-mips/syscalls/fremovexattr.S
+++ b/libc/arch-mips/syscalls/fremovexattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fremovexattr
-    .align 4
-    .ent fremovexattr
+#include <private/bionic_asm.h>
 
-fremovexattr:
+ENTRY(fremovexattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fremovexattr
+    .cpload t9
+    li v0, __NR_fremovexattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end fremovexattr
+END(fremovexattr)
diff --git a/libc/arch-mips/syscalls/fsetxattr.S b/libc/arch-mips/syscalls/fsetxattr.S
index 4552b07..0347128 100644
--- a/libc/arch-mips/syscalls/fsetxattr.S
+++ b/libc/arch-mips/syscalls/fsetxattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fsetxattr
-    .align 4
-    .ent fsetxattr
+#include <private/bionic_asm.h>
 
-fsetxattr:
+ENTRY(fsetxattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fsetxattr
+    .cpload t9
+    li v0, __NR_fsetxattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end fsetxattr
+END(fsetxattr)
diff --git a/libc/arch-mips/syscalls/fstat64.S b/libc/arch-mips/syscalls/fstat64.S
index 904ce86..7228541 100644
--- a/libc/arch-mips/syscalls/fstat64.S
+++ b/libc/arch-mips/syscalls/fstat64.S
@@ -1,26 +1,22 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fstat64
-    .align 4
-    .ent fstat64
+#include <private/bionic_asm.h>
 
-fstat64:
+ENTRY(fstat64)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fstat64
+    .cpload t9
+    li v0, __NR_fstat64
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end fstat64
+END(fstat64)
 
     .globl fstat
     .equ fstat, fstat64
diff --git a/libc/arch-mips/syscalls/fstatat64.S b/libc/arch-mips/syscalls/fstatat64.S
index 8c81a9f..b2903f2 100644
--- a/libc/arch-mips/syscalls/fstatat64.S
+++ b/libc/arch-mips/syscalls/fstatat64.S
@@ -1,26 +1,22 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fstatat64
-    .align 4
-    .ent fstatat64
+#include <private/bionic_asm.h>
 
-fstatat64:
+ENTRY(fstatat64)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fstatat64
+    .cpload t9
+    li v0, __NR_fstatat64
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end fstatat64
+END(fstatat64)
 
     .globl fstatat
     .equ fstatat, fstatat64
diff --git a/libc/arch-mips/syscalls/fsync.S b/libc/arch-mips/syscalls/fsync.S
index 383bd0c..96b417d 100644
--- a/libc/arch-mips/syscalls/fsync.S
+++ b/libc/arch-mips/syscalls/fsync.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl fsync
-    .align 4
-    .ent fsync
+#include <private/bionic_asm.h>
 
-fsync:
+ENTRY(fsync)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_fsync
+    .cpload t9
+    li v0, __NR_fsync
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end fsync
+END(fsync)
diff --git a/libc/arch-mips/syscalls/ftruncate.S b/libc/arch-mips/syscalls/ftruncate.S
index 797d239..bd428fb 100644
--- a/libc/arch-mips/syscalls/ftruncate.S
+++ b/libc/arch-mips/syscalls/ftruncate.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl ftruncate
-    .align 4
-    .ent ftruncate
+#include <private/bionic_asm.h>
 
-ftruncate:
+ENTRY(ftruncate)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_ftruncate
+    .cpload t9
+    li v0, __NR_ftruncate
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end ftruncate
+END(ftruncate)
diff --git a/libc/arch-mips/syscalls/ftruncate64.S b/libc/arch-mips/syscalls/ftruncate64.S
index e7f7f81..357e9a5 100644
--- a/libc/arch-mips/syscalls/ftruncate64.S
+++ b/libc/arch-mips/syscalls/ftruncate64.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl ftruncate64
-    .align 4
-    .ent ftruncate64
+#include <private/bionic_asm.h>
 
-ftruncate64:
+ENTRY(ftruncate64)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_ftruncate64
+    .cpload t9
+    li v0, __NR_ftruncate64
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end ftruncate64
+END(ftruncate64)
diff --git a/libc/arch-mips/syscalls/futex.S b/libc/arch-mips/syscalls/futex.S
index 25c88c8..a865fea 100644
--- a/libc/arch-mips/syscalls/futex.S
+++ b/libc/arch-mips/syscalls/futex.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl futex
-    .align 4
-    .ent futex
+#include <private/bionic_asm.h>
 
-futex:
+ENTRY(futex)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_futex
+    .cpload t9
+    li v0, __NR_futex
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end futex
+END(futex)
diff --git a/libc/arch-mips/syscalls/getdents.S b/libc/arch-mips/syscalls/getdents.S
index 7b8006a..ce92886 100644
--- a/libc/arch-mips/syscalls/getdents.S
+++ b/libc/arch-mips/syscalls/getdents.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getdents
-    .align 4
-    .ent getdents
+#include <private/bionic_asm.h>
 
-getdents:
+ENTRY(getdents)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getdents64
+    .cpload t9
+    li v0, __NR_getdents64
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end getdents
+END(getdents)
diff --git a/libc/arch-mips/syscalls/getegid.S b/libc/arch-mips/syscalls/getegid.S
index 5d75420..c3a3ac0 100644
--- a/libc/arch-mips/syscalls/getegid.S
+++ b/libc/arch-mips/syscalls/getegid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getegid
-    .align 4
-    .ent getegid
+#include <private/bionic_asm.h>
 
-getegid:
+ENTRY(getegid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getegid
+    .cpload t9
+    li v0, __NR_getegid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end getegid
+END(getegid)
diff --git a/libc/arch-mips/syscalls/geteuid.S b/libc/arch-mips/syscalls/geteuid.S
index f878ea7..66e6d4f 100644
--- a/libc/arch-mips/syscalls/geteuid.S
+++ b/libc/arch-mips/syscalls/geteuid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl geteuid
-    .align 4
-    .ent geteuid
+#include <private/bionic_asm.h>
 
-geteuid:
+ENTRY(geteuid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_geteuid
+    .cpload t9
+    li v0, __NR_geteuid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end geteuid
+END(geteuid)
diff --git a/libc/arch-mips/syscalls/getgid.S b/libc/arch-mips/syscalls/getgid.S
index 207d1a1..674d527 100644
--- a/libc/arch-mips/syscalls/getgid.S
+++ b/libc/arch-mips/syscalls/getgid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getgid
-    .align 4
-    .ent getgid
+#include <private/bionic_asm.h>
 
-getgid:
+ENTRY(getgid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getgid
+    .cpload t9
+    li v0, __NR_getgid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end getgid
+END(getgid)
diff --git a/libc/arch-mips/syscalls/getgroups.S b/libc/arch-mips/syscalls/getgroups.S
index d0a10a3..caa031b 100644
--- a/libc/arch-mips/syscalls/getgroups.S
+++ b/libc/arch-mips/syscalls/getgroups.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getgroups
-    .align 4
-    .ent getgroups
+#include <private/bionic_asm.h>
 
-getgroups:
+ENTRY(getgroups)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getgroups
+    .cpload t9
+    li v0, __NR_getgroups
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end getgroups
+END(getgroups)
diff --git a/libc/arch-mips/syscalls/getitimer.S b/libc/arch-mips/syscalls/getitimer.S
index 40f90f2..e7a655a 100644
--- a/libc/arch-mips/syscalls/getitimer.S
+++ b/libc/arch-mips/syscalls/getitimer.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getitimer
-    .align 4
-    .ent getitimer
+#include <private/bionic_asm.h>
 
-getitimer:
+ENTRY(getitimer)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getitimer
+    .cpload t9
+    li v0, __NR_getitimer
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end getitimer
+END(getitimer)
diff --git a/libc/arch-mips/syscalls/getpeername.S b/libc/arch-mips/syscalls/getpeername.S
index 6d491de..31df8ad 100644
--- a/libc/arch-mips/syscalls/getpeername.S
+++ b/libc/arch-mips/syscalls/getpeername.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getpeername
-    .align 4
-    .ent getpeername
+#include <private/bionic_asm.h>
 
-getpeername:
+ENTRY(getpeername)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getpeername
+    .cpload t9
+    li v0, __NR_getpeername
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end getpeername
+END(getpeername)
diff --git a/libc/arch-mips/syscalls/getpgid.S b/libc/arch-mips/syscalls/getpgid.S
index dc6ec96..7e3e439 100644
--- a/libc/arch-mips/syscalls/getpgid.S
+++ b/libc/arch-mips/syscalls/getpgid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getpgid
-    .align 4
-    .ent getpgid
+#include <private/bionic_asm.h>
 
-getpgid:
+ENTRY(getpgid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getpgid
+    .cpload t9
+    li v0, __NR_getpgid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end getpgid
+END(getpgid)
diff --git a/libc/arch-mips/syscalls/getpid.S b/libc/arch-mips/syscalls/getpid.S
index 244d256..a053f5b 100644
--- a/libc/arch-mips/syscalls/getpid.S
+++ b/libc/arch-mips/syscalls/getpid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getpid
-    .align 4
-    .ent getpid
+#include <private/bionic_asm.h>
 
-getpid:
+ENTRY(getpid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getpid
+    .cpload t9
+    li v0, __NR_getpid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end getpid
+END(getpid)
diff --git a/libc/arch-mips/syscalls/getppid.S b/libc/arch-mips/syscalls/getppid.S
index 1973424..3d76fc2 100644
--- a/libc/arch-mips/syscalls/getppid.S
+++ b/libc/arch-mips/syscalls/getppid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getppid
-    .align 4
-    .ent getppid
+#include <private/bionic_asm.h>
 
-getppid:
+ENTRY(getppid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getppid
+    .cpload t9
+    li v0, __NR_getppid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end getppid
+END(getppid)
diff --git a/libc/arch-mips/syscalls/getresgid.S b/libc/arch-mips/syscalls/getresgid.S
index b78e90c..235902a 100644
--- a/libc/arch-mips/syscalls/getresgid.S
+++ b/libc/arch-mips/syscalls/getresgid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getresgid
-    .align 4
-    .ent getresgid
+#include <private/bionic_asm.h>
 
-getresgid:
+ENTRY(getresgid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getresgid
+    .cpload t9
+    li v0, __NR_getresgid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end getresgid
+END(getresgid)
diff --git a/libc/arch-mips/syscalls/getresuid.S b/libc/arch-mips/syscalls/getresuid.S
index 336c049..c6c4c13 100644
--- a/libc/arch-mips/syscalls/getresuid.S
+++ b/libc/arch-mips/syscalls/getresuid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getresuid
-    .align 4
-    .ent getresuid
+#include <private/bionic_asm.h>
 
-getresuid:
+ENTRY(getresuid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getresuid
+    .cpload t9
+    li v0, __NR_getresuid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end getresuid
+END(getresuid)
diff --git a/libc/arch-mips/syscalls/getrlimit.S b/libc/arch-mips/syscalls/getrlimit.S
index 557c2c1..ef4ae89 100644
--- a/libc/arch-mips/syscalls/getrlimit.S
+++ b/libc/arch-mips/syscalls/getrlimit.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getrlimit
-    .align 4
-    .ent getrlimit
+#include <private/bionic_asm.h>
 
-getrlimit:
+ENTRY(getrlimit)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getrlimit
+    .cpload t9
+    li v0, __NR_getrlimit
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end getrlimit
+END(getrlimit)
diff --git a/libc/arch-mips/syscalls/getrusage.S b/libc/arch-mips/syscalls/getrusage.S
index c2750f9..21cabfa 100644
--- a/libc/arch-mips/syscalls/getrusage.S
+++ b/libc/arch-mips/syscalls/getrusage.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getrusage
-    .align 4
-    .ent getrusage
+#include <private/bionic_asm.h>
 
-getrusage:
+ENTRY(getrusage)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getrusage
+    .cpload t9
+    li v0, __NR_getrusage
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end getrusage
+END(getrusage)
diff --git a/libc/arch-mips/syscalls/getsid.S b/libc/arch-mips/syscalls/getsid.S
index 9ceb65d..b0b21a0 100644
--- a/libc/arch-mips/syscalls/getsid.S
+++ b/libc/arch-mips/syscalls/getsid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getsid
-    .align 4
-    .ent getsid
+#include <private/bionic_asm.h>
 
-getsid:
+ENTRY(getsid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getsid
+    .cpload t9
+    li v0, __NR_getsid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end getsid
+END(getsid)
diff --git a/libc/arch-mips/syscalls/getsockname.S b/libc/arch-mips/syscalls/getsockname.S
index 43b28c2..82d0b83 100644
--- a/libc/arch-mips/syscalls/getsockname.S
+++ b/libc/arch-mips/syscalls/getsockname.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getsockname
-    .align 4
-    .ent getsockname
+#include <private/bionic_asm.h>
 
-getsockname:
+ENTRY(getsockname)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getsockname
+    .cpload t9
+    li v0, __NR_getsockname
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end getsockname
+END(getsockname)
diff --git a/libc/arch-mips/syscalls/getsockopt.S b/libc/arch-mips/syscalls/getsockopt.S
index affe539..ad360e3 100644
--- a/libc/arch-mips/syscalls/getsockopt.S
+++ b/libc/arch-mips/syscalls/getsockopt.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getsockopt
-    .align 4
-    .ent getsockopt
+#include <private/bionic_asm.h>
 
-getsockopt:
+ENTRY(getsockopt)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getsockopt
+    .cpload t9
+    li v0, __NR_getsockopt
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end getsockopt
+END(getsockopt)
diff --git a/libc/arch-mips/syscalls/gettid.S b/libc/arch-mips/syscalls/gettid.S
index d258ef2..cfdc57b 100644
--- a/libc/arch-mips/syscalls/gettid.S
+++ b/libc/arch-mips/syscalls/gettid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl gettid
-    .align 4
-    .ent gettid
+#include <private/bionic_asm.h>
 
-gettid:
+ENTRY(gettid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_gettid
+    .cpload t9
+    li v0, __NR_gettid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end gettid
+END(gettid)
diff --git a/libc/arch-mips/syscalls/gettimeofday.S b/libc/arch-mips/syscalls/gettimeofday.S
index 006752e..e66fd77 100644
--- a/libc/arch-mips/syscalls/gettimeofday.S
+++ b/libc/arch-mips/syscalls/gettimeofday.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl gettimeofday
-    .align 4
-    .ent gettimeofday
+#include <private/bionic_asm.h>
 
-gettimeofday:
+ENTRY(gettimeofday)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_gettimeofday
+    .cpload t9
+    li v0, __NR_gettimeofday
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end gettimeofday
+END(gettimeofday)
diff --git a/libc/arch-mips/syscalls/getuid.S b/libc/arch-mips/syscalls/getuid.S
index 747318a..345af71 100644
--- a/libc/arch-mips/syscalls/getuid.S
+++ b/libc/arch-mips/syscalls/getuid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getuid
-    .align 4
-    .ent getuid
+#include <private/bionic_asm.h>
 
-getuid:
+ENTRY(getuid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getuid
+    .cpload t9
+    li v0, __NR_getuid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end getuid
+END(getuid)
diff --git a/libc/arch-mips/syscalls/getxattr.S b/libc/arch-mips/syscalls/getxattr.S
index 2f82c4c..c7e215e 100644
--- a/libc/arch-mips/syscalls/getxattr.S
+++ b/libc/arch-mips/syscalls/getxattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl getxattr
-    .align 4
-    .ent getxattr
+#include <private/bionic_asm.h>
 
-getxattr:
+ENTRY(getxattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_getxattr
+    .cpload t9
+    li v0, __NR_getxattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end getxattr
+END(getxattr)
diff --git a/libc/arch-mips/syscalls/init_module.S b/libc/arch-mips/syscalls/init_module.S
index ee644b3..21ba5b1 100644
--- a/libc/arch-mips/syscalls/init_module.S
+++ b/libc/arch-mips/syscalls/init_module.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl init_module
-    .align 4
-    .ent init_module
+#include <private/bionic_asm.h>
 
-init_module:
+ENTRY(init_module)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_init_module
+    .cpload t9
+    li v0, __NR_init_module
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end init_module
+END(init_module)
diff --git a/libc/arch-mips/syscalls/inotify_add_watch.S b/libc/arch-mips/syscalls/inotify_add_watch.S
index f1c4d92..beb70ec 100644
--- a/libc/arch-mips/syscalls/inotify_add_watch.S
+++ b/libc/arch-mips/syscalls/inotify_add_watch.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl inotify_add_watch
-    .align 4
-    .ent inotify_add_watch
+#include <private/bionic_asm.h>
 
-inotify_add_watch:
+ENTRY(inotify_add_watch)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_inotify_add_watch
+    .cpload t9
+    li v0, __NR_inotify_add_watch
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end inotify_add_watch
+END(inotify_add_watch)
diff --git a/libc/arch-mips/syscalls/inotify_init1.S b/libc/arch-mips/syscalls/inotify_init1.S
index c3fcf48..6c825c6 100644
--- a/libc/arch-mips/syscalls/inotify_init1.S
+++ b/libc/arch-mips/syscalls/inotify_init1.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl inotify_init1
-    .align 4
-    .ent inotify_init1
+#include <private/bionic_asm.h>
 
-inotify_init1:
+ENTRY(inotify_init1)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_inotify_init1
+    .cpload t9
+    li v0, __NR_inotify_init1
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end inotify_init1
+END(inotify_init1)
diff --git a/libc/arch-mips/syscalls/inotify_rm_watch.S b/libc/arch-mips/syscalls/inotify_rm_watch.S
index 13191af..280f2b4 100644
--- a/libc/arch-mips/syscalls/inotify_rm_watch.S
+++ b/libc/arch-mips/syscalls/inotify_rm_watch.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl inotify_rm_watch
-    .align 4
-    .ent inotify_rm_watch
+#include <private/bionic_asm.h>
 
-inotify_rm_watch:
+ENTRY(inotify_rm_watch)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_inotify_rm_watch
+    .cpload t9
+    li v0, __NR_inotify_rm_watch
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end inotify_rm_watch
+END(inotify_rm_watch)
diff --git a/libc/arch-mips/syscalls/ioprio_get.S b/libc/arch-mips/syscalls/ioprio_get.S
index b8bd1d3..fbc8b17 100644
--- a/libc/arch-mips/syscalls/ioprio_get.S
+++ b/libc/arch-mips/syscalls/ioprio_get.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl ioprio_get
-    .align 4
-    .ent ioprio_get
+#include <private/bionic_asm.h>
 
-ioprio_get:
+ENTRY(ioprio_get)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_ioprio_get
+    .cpload t9
+    li v0, __NR_ioprio_get
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end ioprio_get
+END(ioprio_get)
diff --git a/libc/arch-mips/syscalls/ioprio_set.S b/libc/arch-mips/syscalls/ioprio_set.S
index c5b3bdc..d0320ed 100644
--- a/libc/arch-mips/syscalls/ioprio_set.S
+++ b/libc/arch-mips/syscalls/ioprio_set.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl ioprio_set
-    .align 4
-    .ent ioprio_set
+#include <private/bionic_asm.h>
 
-ioprio_set:
+ENTRY(ioprio_set)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_ioprio_set
+    .cpload t9
+    li v0, __NR_ioprio_set
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end ioprio_set
+END(ioprio_set)
diff --git a/libc/arch-mips/syscalls/kill.S b/libc/arch-mips/syscalls/kill.S
index 20a484e..0941717 100644
--- a/libc/arch-mips/syscalls/kill.S
+++ b/libc/arch-mips/syscalls/kill.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl kill
-    .align 4
-    .ent kill
+#include <private/bionic_asm.h>
 
-kill:
+ENTRY(kill)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_kill
+    .cpload t9
+    li v0, __NR_kill
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end kill
+END(kill)
diff --git a/libc/arch-mips/syscalls/klogctl.S b/libc/arch-mips/syscalls/klogctl.S
index 5d30db2..ebc8837 100644
--- a/libc/arch-mips/syscalls/klogctl.S
+++ b/libc/arch-mips/syscalls/klogctl.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl klogctl
-    .align 4
-    .ent klogctl
+#include <private/bionic_asm.h>
 
-klogctl:
+ENTRY(klogctl)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_syslog
+    .cpload t9
+    li v0, __NR_syslog
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end klogctl
+END(klogctl)
diff --git a/libc/arch-mips/syscalls/lgetxattr.S b/libc/arch-mips/syscalls/lgetxattr.S
index 6266aaf..8c4a252 100644
--- a/libc/arch-mips/syscalls/lgetxattr.S
+++ b/libc/arch-mips/syscalls/lgetxattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl lgetxattr
-    .align 4
-    .ent lgetxattr
+#include <private/bionic_asm.h>
 
-lgetxattr:
+ENTRY(lgetxattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_lgetxattr
+    .cpload t9
+    li v0, __NR_lgetxattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end lgetxattr
+END(lgetxattr)
diff --git a/libc/arch-mips/syscalls/linkat.S b/libc/arch-mips/syscalls/linkat.S
index dae07dd..cc7278d 100644
--- a/libc/arch-mips/syscalls/linkat.S
+++ b/libc/arch-mips/syscalls/linkat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl linkat
-    .align 4
-    .ent linkat
+#include <private/bionic_asm.h>
 
-linkat:
+ENTRY(linkat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_linkat
+    .cpload t9
+    li v0, __NR_linkat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end linkat
+END(linkat)
diff --git a/libc/arch-mips/syscalls/listen.S b/libc/arch-mips/syscalls/listen.S
index f2e6083..68eba52 100644
--- a/libc/arch-mips/syscalls/listen.S
+++ b/libc/arch-mips/syscalls/listen.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl listen
-    .align 4
-    .ent listen
+#include <private/bionic_asm.h>
 
-listen:
+ENTRY(listen)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_listen
+    .cpload t9
+    li v0, __NR_listen
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end listen
+END(listen)
diff --git a/libc/arch-mips/syscalls/listxattr.S b/libc/arch-mips/syscalls/listxattr.S
index e752340..006bfce 100644
--- a/libc/arch-mips/syscalls/listxattr.S
+++ b/libc/arch-mips/syscalls/listxattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl listxattr
-    .align 4
-    .ent listxattr
+#include <private/bionic_asm.h>
 
-listxattr:
+ENTRY(listxattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_listxattr
+    .cpload t9
+    li v0, __NR_listxattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end listxattr
+END(listxattr)
diff --git a/libc/arch-mips/syscalls/llistxattr.S b/libc/arch-mips/syscalls/llistxattr.S
index 9dc868e..7f833ad 100644
--- a/libc/arch-mips/syscalls/llistxattr.S
+++ b/libc/arch-mips/syscalls/llistxattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl llistxattr
-    .align 4
-    .ent llistxattr
+#include <private/bionic_asm.h>
 
-llistxattr:
+ENTRY(llistxattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_llistxattr
+    .cpload t9
+    li v0, __NR_llistxattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end llistxattr
+END(llistxattr)
diff --git a/libc/arch-mips/syscalls/lremovexattr.S b/libc/arch-mips/syscalls/lremovexattr.S
index d7e6609..21d00ea 100644
--- a/libc/arch-mips/syscalls/lremovexattr.S
+++ b/libc/arch-mips/syscalls/lremovexattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl lremovexattr
-    .align 4
-    .ent lremovexattr
+#include <private/bionic_asm.h>
 
-lremovexattr:
+ENTRY(lremovexattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_lremovexattr
+    .cpload t9
+    li v0, __NR_lremovexattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end lremovexattr
+END(lremovexattr)
diff --git a/libc/arch-mips/syscalls/lseek.S b/libc/arch-mips/syscalls/lseek.S
index 269cc95..82c2776 100644
--- a/libc/arch-mips/syscalls/lseek.S
+++ b/libc/arch-mips/syscalls/lseek.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl lseek
-    .align 4
-    .ent lseek
+#include <private/bionic_asm.h>
 
-lseek:
+ENTRY(lseek)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_lseek
+    .cpload t9
+    li v0, __NR_lseek
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end lseek
+END(lseek)
diff --git a/libc/arch-mips/syscalls/lsetxattr.S b/libc/arch-mips/syscalls/lsetxattr.S
index 2dfd24a..d54ec69 100644
--- a/libc/arch-mips/syscalls/lsetxattr.S
+++ b/libc/arch-mips/syscalls/lsetxattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl lsetxattr
-    .align 4
-    .ent lsetxattr
+#include <private/bionic_asm.h>
 
-lsetxattr:
+ENTRY(lsetxattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_lsetxattr
+    .cpload t9
+    li v0, __NR_lsetxattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end lsetxattr
+END(lsetxattr)
diff --git a/libc/arch-mips/syscalls/madvise.S b/libc/arch-mips/syscalls/madvise.S
index 8318272..9aa2815 100644
--- a/libc/arch-mips/syscalls/madvise.S
+++ b/libc/arch-mips/syscalls/madvise.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl madvise
-    .align 4
-    .ent madvise
+#include <private/bionic_asm.h>
 
-madvise:
+ENTRY(madvise)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_madvise
+    .cpload t9
+    li v0, __NR_madvise
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end madvise
+END(madvise)
diff --git a/libc/arch-mips/syscalls/mincore.S b/libc/arch-mips/syscalls/mincore.S
index 629a468..0db4313 100644
--- a/libc/arch-mips/syscalls/mincore.S
+++ b/libc/arch-mips/syscalls/mincore.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl mincore
-    .align 4
-    .ent mincore
+#include <private/bionic_asm.h>
 
-mincore:
+ENTRY(mincore)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_mincore
+    .cpload t9
+    li v0, __NR_mincore
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end mincore
+END(mincore)
diff --git a/libc/arch-mips/syscalls/mkdirat.S b/libc/arch-mips/syscalls/mkdirat.S
index 3f8bc19..0ac98d4 100644
--- a/libc/arch-mips/syscalls/mkdirat.S
+++ b/libc/arch-mips/syscalls/mkdirat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl mkdirat
-    .align 4
-    .ent mkdirat
+#include <private/bionic_asm.h>
 
-mkdirat:
+ENTRY(mkdirat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_mkdirat
+    .cpload t9
+    li v0, __NR_mkdirat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end mkdirat
+END(mkdirat)
diff --git a/libc/arch-mips/syscalls/mknodat.S b/libc/arch-mips/syscalls/mknodat.S
index fc05bb3..b85d8bf 100644
--- a/libc/arch-mips/syscalls/mknodat.S
+++ b/libc/arch-mips/syscalls/mknodat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl mknodat
-    .align 4
-    .ent mknodat
+#include <private/bionic_asm.h>
 
-mknodat:
+ENTRY(mknodat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_mknodat
+    .cpload t9
+    li v0, __NR_mknodat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end mknodat
+END(mknodat)
diff --git a/libc/arch-mips/syscalls/mlock.S b/libc/arch-mips/syscalls/mlock.S
index 20cacda..0ba2bca 100644
--- a/libc/arch-mips/syscalls/mlock.S
+++ b/libc/arch-mips/syscalls/mlock.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl mlock
-    .align 4
-    .ent mlock
+#include <private/bionic_asm.h>
 
-mlock:
+ENTRY(mlock)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_mlock
+    .cpload t9
+    li v0, __NR_mlock
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end mlock
+END(mlock)
diff --git a/libc/arch-mips/syscalls/mlockall.S b/libc/arch-mips/syscalls/mlockall.S
index 0aac087..642c6e2 100644
--- a/libc/arch-mips/syscalls/mlockall.S
+++ b/libc/arch-mips/syscalls/mlockall.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl mlockall
-    .align 4
-    .ent mlockall
+#include <private/bionic_asm.h>
 
-mlockall:
+ENTRY(mlockall)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_mlockall
+    .cpload t9
+    li v0, __NR_mlockall
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end mlockall
+END(mlockall)
diff --git a/libc/arch-mips/syscalls/mount.S b/libc/arch-mips/syscalls/mount.S
index 1f951ce..f0c5f6b 100644
--- a/libc/arch-mips/syscalls/mount.S
+++ b/libc/arch-mips/syscalls/mount.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl mount
-    .align 4
-    .ent mount
+#include <private/bionic_asm.h>
 
-mount:
+ENTRY(mount)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_mount
+    .cpload t9
+    li v0, __NR_mount
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end mount
+END(mount)
diff --git a/libc/arch-mips/syscalls/mprotect.S b/libc/arch-mips/syscalls/mprotect.S
index 7d9e784..c0ce988 100644
--- a/libc/arch-mips/syscalls/mprotect.S
+++ b/libc/arch-mips/syscalls/mprotect.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl mprotect
-    .align 4
-    .ent mprotect
+#include <private/bionic_asm.h>
 
-mprotect:
+ENTRY(mprotect)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_mprotect
+    .cpload t9
+    li v0, __NR_mprotect
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end mprotect
+END(mprotect)
diff --git a/libc/arch-mips/syscalls/mremap.S b/libc/arch-mips/syscalls/mremap.S
index 22ddda9..bd4c385 100644
--- a/libc/arch-mips/syscalls/mremap.S
+++ b/libc/arch-mips/syscalls/mremap.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl mremap
-    .align 4
-    .ent mremap
+#include <private/bionic_asm.h>
 
-mremap:
+ENTRY(mremap)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_mremap
+    .cpload t9
+    li v0, __NR_mremap
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end mremap
+END(mremap)
diff --git a/libc/arch-mips/syscalls/msync.S b/libc/arch-mips/syscalls/msync.S
index 4969433..e8ecb2a 100644
--- a/libc/arch-mips/syscalls/msync.S
+++ b/libc/arch-mips/syscalls/msync.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl msync
-    .align 4
-    .ent msync
+#include <private/bionic_asm.h>
 
-msync:
+ENTRY(msync)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_msync
+    .cpload t9
+    li v0, __NR_msync
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end msync
+END(msync)
diff --git a/libc/arch-mips/syscalls/munlock.S b/libc/arch-mips/syscalls/munlock.S
index 59f1d44..f8ddc3a 100644
--- a/libc/arch-mips/syscalls/munlock.S
+++ b/libc/arch-mips/syscalls/munlock.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl munlock
-    .align 4
-    .ent munlock
+#include <private/bionic_asm.h>
 
-munlock:
+ENTRY(munlock)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_munlock
+    .cpload t9
+    li v0, __NR_munlock
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end munlock
+END(munlock)
diff --git a/libc/arch-mips/syscalls/munlockall.S b/libc/arch-mips/syscalls/munlockall.S
index d0a8e9f..5ced5c6 100644
--- a/libc/arch-mips/syscalls/munlockall.S
+++ b/libc/arch-mips/syscalls/munlockall.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl munlockall
-    .align 4
-    .ent munlockall
+#include <private/bionic_asm.h>
 
-munlockall:
+ENTRY(munlockall)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_munlockall
+    .cpload t9
+    li v0, __NR_munlockall
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end munlockall
+END(munlockall)
diff --git a/libc/arch-mips/syscalls/munmap.S b/libc/arch-mips/syscalls/munmap.S
index d4c1057..527825c 100644
--- a/libc/arch-mips/syscalls/munmap.S
+++ b/libc/arch-mips/syscalls/munmap.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl munmap
-    .align 4
-    .ent munmap
+#include <private/bionic_asm.h>
 
-munmap:
+ENTRY(munmap)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_munmap
+    .cpload t9
+    li v0, __NR_munmap
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end munmap
+END(munmap)
diff --git a/libc/arch-mips/syscalls/nanosleep.S b/libc/arch-mips/syscalls/nanosleep.S
index ad3b0f9..8dc816a 100644
--- a/libc/arch-mips/syscalls/nanosleep.S
+++ b/libc/arch-mips/syscalls/nanosleep.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl nanosleep
-    .align 4
-    .ent nanosleep
+#include <private/bionic_asm.h>
 
-nanosleep:
+ENTRY(nanosleep)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_nanosleep
+    .cpload t9
+    li v0, __NR_nanosleep
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end nanosleep
+END(nanosleep)
diff --git a/libc/arch-mips/syscalls/perf_event_open.S b/libc/arch-mips/syscalls/perf_event_open.S
index edd8b85..a0e4416 100644
--- a/libc/arch-mips/syscalls/perf_event_open.S
+++ b/libc/arch-mips/syscalls/perf_event_open.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl perf_event_open
-    .align 4
-    .ent perf_event_open
+#include <private/bionic_asm.h>
 
-perf_event_open:
+ENTRY(perf_event_open)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_perf_event_open
+    .cpload t9
+    li v0, __NR_perf_event_open
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end perf_event_open
+END(perf_event_open)
diff --git a/libc/arch-mips/syscalls/personality.S b/libc/arch-mips/syscalls/personality.S
index 59aaeac..e8449a7 100644
--- a/libc/arch-mips/syscalls/personality.S
+++ b/libc/arch-mips/syscalls/personality.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl personality
-    .align 4
-    .ent personality
+#include <private/bionic_asm.h>
 
-personality:
+ENTRY(personality)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_personality
+    .cpload t9
+    li v0, __NR_personality
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end personality
+END(personality)
diff --git a/libc/arch-mips/syscalls/pipe2.S b/libc/arch-mips/syscalls/pipe2.S
index 798bd7b..478d364 100644
--- a/libc/arch-mips/syscalls/pipe2.S
+++ b/libc/arch-mips/syscalls/pipe2.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl pipe2
-    .align 4
-    .ent pipe2
+#include <private/bionic_asm.h>
 
-pipe2:
+ENTRY(pipe2)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_pipe2
+    .cpload t9
+    li v0, __NR_pipe2
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end pipe2
+END(pipe2)
diff --git a/libc/arch-mips/syscalls/prctl.S b/libc/arch-mips/syscalls/prctl.S
index 5e9a28d..e9aff3c 100644
--- a/libc/arch-mips/syscalls/prctl.S
+++ b/libc/arch-mips/syscalls/prctl.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl prctl
-    .align 4
-    .ent prctl
+#include <private/bionic_asm.h>
 
-prctl:
+ENTRY(prctl)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_prctl
+    .cpload t9
+    li v0, __NR_prctl
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end prctl
+END(prctl)
diff --git a/libc/arch-mips/syscalls/pread64.S b/libc/arch-mips/syscalls/pread64.S
index 870b138..55a54c6 100644
--- a/libc/arch-mips/syscalls/pread64.S
+++ b/libc/arch-mips/syscalls/pread64.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl pread64
-    .align 4
-    .ent pread64
+#include <private/bionic_asm.h>
 
-pread64:
+ENTRY(pread64)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_pread64
+    .cpload t9
+    li v0, __NR_pread64
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end pread64
+END(pread64)
diff --git a/libc/arch-mips/syscalls/prlimit64.S b/libc/arch-mips/syscalls/prlimit64.S
index 17e9157..c695d18 100644
--- a/libc/arch-mips/syscalls/prlimit64.S
+++ b/libc/arch-mips/syscalls/prlimit64.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl prlimit64
-    .align 4
-    .ent prlimit64
+#include <private/bionic_asm.h>
 
-prlimit64:
+ENTRY(prlimit64)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_prlimit64
+    .cpload t9
+    li v0, __NR_prlimit64
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end prlimit64
+END(prlimit64)
diff --git a/libc/arch-mips/syscalls/pwrite64.S b/libc/arch-mips/syscalls/pwrite64.S
index 1e808ff..64d3ee1 100644
--- a/libc/arch-mips/syscalls/pwrite64.S
+++ b/libc/arch-mips/syscalls/pwrite64.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl pwrite64
-    .align 4
-    .ent pwrite64
+#include <private/bionic_asm.h>
 
-pwrite64:
+ENTRY(pwrite64)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_pwrite64
+    .cpload t9
+    li v0, __NR_pwrite64
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end pwrite64
+END(pwrite64)
diff --git a/libc/arch-mips/syscalls/read.S b/libc/arch-mips/syscalls/read.S
index c649837..ff548ab 100644
--- a/libc/arch-mips/syscalls/read.S
+++ b/libc/arch-mips/syscalls/read.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl read
-    .align 4
-    .ent read
+#include <private/bionic_asm.h>
 
-read:
+ENTRY(read)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_read
+    .cpload t9
+    li v0, __NR_read
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end read
+END(read)
diff --git a/libc/arch-mips/syscalls/readahead.S b/libc/arch-mips/syscalls/readahead.S
index 09eab9e..674286a 100644
--- a/libc/arch-mips/syscalls/readahead.S
+++ b/libc/arch-mips/syscalls/readahead.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl readahead
-    .align 4
-    .ent readahead
+#include <private/bionic_asm.h>
 
-readahead:
+ENTRY(readahead)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_readahead
+    .cpload t9
+    li v0, __NR_readahead
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end readahead
+END(readahead)
diff --git a/libc/arch-mips/syscalls/readlinkat.S b/libc/arch-mips/syscalls/readlinkat.S
index 3e5d72f..a1c7d6b 100644
--- a/libc/arch-mips/syscalls/readlinkat.S
+++ b/libc/arch-mips/syscalls/readlinkat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl readlinkat
-    .align 4
-    .ent readlinkat
+#include <private/bionic_asm.h>
 
-readlinkat:
+ENTRY(readlinkat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_readlinkat
+    .cpload t9
+    li v0, __NR_readlinkat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end readlinkat
+END(readlinkat)
diff --git a/libc/arch-mips/syscalls/readv.S b/libc/arch-mips/syscalls/readv.S
index 1f367be..af5a4cb 100644
--- a/libc/arch-mips/syscalls/readv.S
+++ b/libc/arch-mips/syscalls/readv.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl readv
-    .align 4
-    .ent readv
+#include <private/bionic_asm.h>
 
-readv:
+ENTRY(readv)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_readv
+    .cpload t9
+    li v0, __NR_readv
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end readv
+END(readv)
diff --git a/libc/arch-mips/syscalls/recvfrom.S b/libc/arch-mips/syscalls/recvfrom.S
index 3c2303c..04b04f6 100644
--- a/libc/arch-mips/syscalls/recvfrom.S
+++ b/libc/arch-mips/syscalls/recvfrom.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl recvfrom
-    .align 4
-    .ent recvfrom
+#include <private/bionic_asm.h>
 
-recvfrom:
+ENTRY(recvfrom)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_recvfrom
+    .cpload t9
+    li v0, __NR_recvfrom
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end recvfrom
+END(recvfrom)
diff --git a/libc/arch-mips/syscalls/recvmsg.S b/libc/arch-mips/syscalls/recvmsg.S
index aaf022f..a0a3a3f 100644
--- a/libc/arch-mips/syscalls/recvmsg.S
+++ b/libc/arch-mips/syscalls/recvmsg.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl recvmsg
-    .align 4
-    .ent recvmsg
+#include <private/bionic_asm.h>
 
-recvmsg:
+ENTRY(recvmsg)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_recvmsg
+    .cpload t9
+    li v0, __NR_recvmsg
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end recvmsg
+END(recvmsg)
diff --git a/libc/arch-mips/syscalls/removexattr.S b/libc/arch-mips/syscalls/removexattr.S
index 29df5d2..0f72ebf 100644
--- a/libc/arch-mips/syscalls/removexattr.S
+++ b/libc/arch-mips/syscalls/removexattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl removexattr
-    .align 4
-    .ent removexattr
+#include <private/bionic_asm.h>
 
-removexattr:
+ENTRY(removexattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_removexattr
+    .cpload t9
+    li v0, __NR_removexattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end removexattr
+END(removexattr)
diff --git a/libc/arch-mips/syscalls/renameat.S b/libc/arch-mips/syscalls/renameat.S
index b7c210e..210b439 100644
--- a/libc/arch-mips/syscalls/renameat.S
+++ b/libc/arch-mips/syscalls/renameat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl renameat
-    .align 4
-    .ent renameat
+#include <private/bionic_asm.h>
 
-renameat:
+ENTRY(renameat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_renameat
+    .cpload t9
+    li v0, __NR_renameat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end renameat
+END(renameat)
diff --git a/libc/arch-mips/syscalls/sched_get_priority_max.S b/libc/arch-mips/syscalls/sched_get_priority_max.S
index 6d63fec..d15a868 100644
--- a/libc/arch-mips/syscalls/sched_get_priority_max.S
+++ b/libc/arch-mips/syscalls/sched_get_priority_max.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sched_get_priority_max
-    .align 4
-    .ent sched_get_priority_max
+#include <private/bionic_asm.h>
 
-sched_get_priority_max:
+ENTRY(sched_get_priority_max)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sched_get_priority_max
+    .cpload t9
+    li v0, __NR_sched_get_priority_max
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end sched_get_priority_max
+END(sched_get_priority_max)
diff --git a/libc/arch-mips/syscalls/sched_get_priority_min.S b/libc/arch-mips/syscalls/sched_get_priority_min.S
index de88b3e..5ff21c6 100644
--- a/libc/arch-mips/syscalls/sched_get_priority_min.S
+++ b/libc/arch-mips/syscalls/sched_get_priority_min.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sched_get_priority_min
-    .align 4
-    .ent sched_get_priority_min
+#include <private/bionic_asm.h>
 
-sched_get_priority_min:
+ENTRY(sched_get_priority_min)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sched_get_priority_min
+    .cpload t9
+    li v0, __NR_sched_get_priority_min
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end sched_get_priority_min
+END(sched_get_priority_min)
diff --git a/libc/arch-mips/syscalls/sched_getparam.S b/libc/arch-mips/syscalls/sched_getparam.S
index ae261db..1cbe720 100644
--- a/libc/arch-mips/syscalls/sched_getparam.S
+++ b/libc/arch-mips/syscalls/sched_getparam.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sched_getparam
-    .align 4
-    .ent sched_getparam
+#include <private/bionic_asm.h>
 
-sched_getparam:
+ENTRY(sched_getparam)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sched_getparam
+    .cpload t9
+    li v0, __NR_sched_getparam
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end sched_getparam
+END(sched_getparam)
diff --git a/libc/arch-mips/syscalls/sched_getscheduler.S b/libc/arch-mips/syscalls/sched_getscheduler.S
index 6a4e6f6..88b16e0 100644
--- a/libc/arch-mips/syscalls/sched_getscheduler.S
+++ b/libc/arch-mips/syscalls/sched_getscheduler.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sched_getscheduler
-    .align 4
-    .ent sched_getscheduler
+#include <private/bionic_asm.h>
 
-sched_getscheduler:
+ENTRY(sched_getscheduler)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sched_getscheduler
+    .cpload t9
+    li v0, __NR_sched_getscheduler
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end sched_getscheduler
+END(sched_getscheduler)
diff --git a/libc/arch-mips/syscalls/sched_rr_get_interval.S b/libc/arch-mips/syscalls/sched_rr_get_interval.S
index 436f8b3..647ee3c 100644
--- a/libc/arch-mips/syscalls/sched_rr_get_interval.S
+++ b/libc/arch-mips/syscalls/sched_rr_get_interval.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sched_rr_get_interval
-    .align 4
-    .ent sched_rr_get_interval
+#include <private/bionic_asm.h>
 
-sched_rr_get_interval:
+ENTRY(sched_rr_get_interval)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sched_rr_get_interval
+    .cpload t9
+    li v0, __NR_sched_rr_get_interval
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end sched_rr_get_interval
+END(sched_rr_get_interval)
diff --git a/libc/arch-mips/syscalls/sched_setaffinity.S b/libc/arch-mips/syscalls/sched_setaffinity.S
index 98bf458..1184766 100644
--- a/libc/arch-mips/syscalls/sched_setaffinity.S
+++ b/libc/arch-mips/syscalls/sched_setaffinity.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sched_setaffinity
-    .align 4
-    .ent sched_setaffinity
+#include <private/bionic_asm.h>
 
-sched_setaffinity:
+ENTRY(sched_setaffinity)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sched_setaffinity
+    .cpload t9
+    li v0, __NR_sched_setaffinity
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end sched_setaffinity
+END(sched_setaffinity)
diff --git a/libc/arch-mips/syscalls/sched_setparam.S b/libc/arch-mips/syscalls/sched_setparam.S
index 2c03e93..1811c74 100644
--- a/libc/arch-mips/syscalls/sched_setparam.S
+++ b/libc/arch-mips/syscalls/sched_setparam.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sched_setparam
-    .align 4
-    .ent sched_setparam
+#include <private/bionic_asm.h>
 
-sched_setparam:
+ENTRY(sched_setparam)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sched_setparam
+    .cpload t9
+    li v0, __NR_sched_setparam
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end sched_setparam
+END(sched_setparam)
diff --git a/libc/arch-mips/syscalls/sched_setscheduler.S b/libc/arch-mips/syscalls/sched_setscheduler.S
index adb1f14..8921d30 100644
--- a/libc/arch-mips/syscalls/sched_setscheduler.S
+++ b/libc/arch-mips/syscalls/sched_setscheduler.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sched_setscheduler
-    .align 4
-    .ent sched_setscheduler
+#include <private/bionic_asm.h>
 
-sched_setscheduler:
+ENTRY(sched_setscheduler)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sched_setscheduler
+    .cpload t9
+    li v0, __NR_sched_setscheduler
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end sched_setscheduler
+END(sched_setscheduler)
diff --git a/libc/arch-mips/syscalls/sched_yield.S b/libc/arch-mips/syscalls/sched_yield.S
index cbe799c..37f09be 100644
--- a/libc/arch-mips/syscalls/sched_yield.S
+++ b/libc/arch-mips/syscalls/sched_yield.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sched_yield
-    .align 4
-    .ent sched_yield
+#include <private/bionic_asm.h>
 
-sched_yield:
+ENTRY(sched_yield)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sched_yield
+    .cpload t9
+    li v0, __NR_sched_yield
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end sched_yield
+END(sched_yield)
diff --git a/libc/arch-mips/syscalls/sendfile.S b/libc/arch-mips/syscalls/sendfile.S
index 219a311..84466b9 100644
--- a/libc/arch-mips/syscalls/sendfile.S
+++ b/libc/arch-mips/syscalls/sendfile.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sendfile
-    .align 4
-    .ent sendfile
+#include <private/bionic_asm.h>
 
-sendfile:
+ENTRY(sendfile)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sendfile
+    .cpload t9
+    li v0, __NR_sendfile
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end sendfile
+END(sendfile)
diff --git a/libc/arch-mips/syscalls/sendfile64.S b/libc/arch-mips/syscalls/sendfile64.S
index 7669973..d9733f6 100644
--- a/libc/arch-mips/syscalls/sendfile64.S
+++ b/libc/arch-mips/syscalls/sendfile64.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sendfile64
-    .align 4
-    .ent sendfile64
+#include <private/bionic_asm.h>
 
-sendfile64:
+ENTRY(sendfile64)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sendfile64
+    .cpload t9
+    li v0, __NR_sendfile64
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end sendfile64
+END(sendfile64)
diff --git a/libc/arch-mips/syscalls/sendmsg.S b/libc/arch-mips/syscalls/sendmsg.S
index faa4cf3..5c37c62 100644
--- a/libc/arch-mips/syscalls/sendmsg.S
+++ b/libc/arch-mips/syscalls/sendmsg.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sendmsg
-    .align 4
-    .ent sendmsg
+#include <private/bionic_asm.h>
 
-sendmsg:
+ENTRY(sendmsg)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sendmsg
+    .cpload t9
+    li v0, __NR_sendmsg
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end sendmsg
+END(sendmsg)
diff --git a/libc/arch-mips/syscalls/sendto.S b/libc/arch-mips/syscalls/sendto.S
index 80a6110..580d142 100644
--- a/libc/arch-mips/syscalls/sendto.S
+++ b/libc/arch-mips/syscalls/sendto.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sendto
-    .align 4
-    .ent sendto
+#include <private/bionic_asm.h>
 
-sendto:
+ENTRY(sendto)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sendto
+    .cpload t9
+    li v0, __NR_sendto
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end sendto
+END(sendto)
diff --git a/libc/arch-mips/syscalls/setgid.S b/libc/arch-mips/syscalls/setgid.S
index 7e460b8..8fa188e 100644
--- a/libc/arch-mips/syscalls/setgid.S
+++ b/libc/arch-mips/syscalls/setgid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setgid
-    .align 4
-    .ent setgid
+#include <private/bionic_asm.h>
 
-setgid:
+ENTRY(setgid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setgid
+    .cpload t9
+    li v0, __NR_setgid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end setgid
+END(setgid)
diff --git a/libc/arch-mips/syscalls/setgroups.S b/libc/arch-mips/syscalls/setgroups.S
index f89a4a4..f2d271c 100644
--- a/libc/arch-mips/syscalls/setgroups.S
+++ b/libc/arch-mips/syscalls/setgroups.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setgroups
-    .align 4
-    .ent setgroups
+#include <private/bionic_asm.h>
 
-setgroups:
+ENTRY(setgroups)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setgroups
+    .cpload t9
+    li v0, __NR_setgroups
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end setgroups
+END(setgroups)
diff --git a/libc/arch-mips/syscalls/setitimer.S b/libc/arch-mips/syscalls/setitimer.S
index 5a1850a..a2eea84 100644
--- a/libc/arch-mips/syscalls/setitimer.S
+++ b/libc/arch-mips/syscalls/setitimer.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setitimer
-    .align 4
-    .ent setitimer
+#include <private/bionic_asm.h>
 
-setitimer:
+ENTRY(setitimer)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setitimer
+    .cpload t9
+    li v0, __NR_setitimer
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end setitimer
+END(setitimer)
diff --git a/libc/arch-mips/syscalls/setns.S b/libc/arch-mips/syscalls/setns.S
index fd4529e..8a4f674 100644
--- a/libc/arch-mips/syscalls/setns.S
+++ b/libc/arch-mips/syscalls/setns.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setns
-    .align 4
-    .ent setns
+#include <private/bionic_asm.h>
 
-setns:
+ENTRY(setns)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setns
+    .cpload t9
+    li v0, __NR_setns
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end setns
+END(setns)
diff --git a/libc/arch-mips/syscalls/setpgid.S b/libc/arch-mips/syscalls/setpgid.S
index d41e01c..c68f9a6 100644
--- a/libc/arch-mips/syscalls/setpgid.S
+++ b/libc/arch-mips/syscalls/setpgid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setpgid
-    .align 4
-    .ent setpgid
+#include <private/bionic_asm.h>
 
-setpgid:
+ENTRY(setpgid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setpgid
+    .cpload t9
+    li v0, __NR_setpgid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end setpgid
+END(setpgid)
diff --git a/libc/arch-mips/syscalls/setpriority.S b/libc/arch-mips/syscalls/setpriority.S
index 443d017..2bf9f47 100644
--- a/libc/arch-mips/syscalls/setpriority.S
+++ b/libc/arch-mips/syscalls/setpriority.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setpriority
-    .align 4
-    .ent setpriority
+#include <private/bionic_asm.h>
 
-setpriority:
+ENTRY(setpriority)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setpriority
+    .cpload t9
+    li v0, __NR_setpriority
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end setpriority
+END(setpriority)
diff --git a/libc/arch-mips/syscalls/setregid.S b/libc/arch-mips/syscalls/setregid.S
index a91e21b..de77e39 100644
--- a/libc/arch-mips/syscalls/setregid.S
+++ b/libc/arch-mips/syscalls/setregid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setregid
-    .align 4
-    .ent setregid
+#include <private/bionic_asm.h>
 
-setregid:
+ENTRY(setregid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setregid
+    .cpload t9
+    li v0, __NR_setregid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end setregid
+END(setregid)
diff --git a/libc/arch-mips/syscalls/setresgid.S b/libc/arch-mips/syscalls/setresgid.S
index dd8a330..b2fd85f 100644
--- a/libc/arch-mips/syscalls/setresgid.S
+++ b/libc/arch-mips/syscalls/setresgid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setresgid
-    .align 4
-    .ent setresgid
+#include <private/bionic_asm.h>
 
-setresgid:
+ENTRY(setresgid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setresgid
+    .cpload t9
+    li v0, __NR_setresgid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end setresgid
+END(setresgid)
diff --git a/libc/arch-mips/syscalls/setresuid.S b/libc/arch-mips/syscalls/setresuid.S
index 1319e2c..ad9ea9b 100644
--- a/libc/arch-mips/syscalls/setresuid.S
+++ b/libc/arch-mips/syscalls/setresuid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setresuid
-    .align 4
-    .ent setresuid
+#include <private/bionic_asm.h>
 
-setresuid:
+ENTRY(setresuid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setresuid
+    .cpload t9
+    li v0, __NR_setresuid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end setresuid
+END(setresuid)
diff --git a/libc/arch-mips/syscalls/setreuid.S b/libc/arch-mips/syscalls/setreuid.S
index e25f2d9..888d219 100644
--- a/libc/arch-mips/syscalls/setreuid.S
+++ b/libc/arch-mips/syscalls/setreuid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setreuid
-    .align 4
-    .ent setreuid
+#include <private/bionic_asm.h>
 
-setreuid:
+ENTRY(setreuid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setreuid
+    .cpload t9
+    li v0, __NR_setreuid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end setreuid
+END(setreuid)
diff --git a/libc/arch-mips/syscalls/setrlimit.S b/libc/arch-mips/syscalls/setrlimit.S
index 65b1cd8..71b49ac 100644
--- a/libc/arch-mips/syscalls/setrlimit.S
+++ b/libc/arch-mips/syscalls/setrlimit.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setrlimit
-    .align 4
-    .ent setrlimit
+#include <private/bionic_asm.h>
 
-setrlimit:
+ENTRY(setrlimit)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setrlimit
+    .cpload t9
+    li v0, __NR_setrlimit
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end setrlimit
+END(setrlimit)
diff --git a/libc/arch-mips/syscalls/setsid.S b/libc/arch-mips/syscalls/setsid.S
index a0bad2b..9467a08 100644
--- a/libc/arch-mips/syscalls/setsid.S
+++ b/libc/arch-mips/syscalls/setsid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setsid
-    .align 4
-    .ent setsid
+#include <private/bionic_asm.h>
 
-setsid:
+ENTRY(setsid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setsid
+    .cpload t9
+    li v0, __NR_setsid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end setsid
+END(setsid)
diff --git a/libc/arch-mips/syscalls/setsockopt.S b/libc/arch-mips/syscalls/setsockopt.S
index 3192d93..e8dd3f6 100644
--- a/libc/arch-mips/syscalls/setsockopt.S
+++ b/libc/arch-mips/syscalls/setsockopt.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setsockopt
-    .align 4
-    .ent setsockopt
+#include <private/bionic_asm.h>
 
-setsockopt:
+ENTRY(setsockopt)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setsockopt
+    .cpload t9
+    li v0, __NR_setsockopt
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end setsockopt
+END(setsockopt)
diff --git a/libc/arch-mips/syscalls/settimeofday.S b/libc/arch-mips/syscalls/settimeofday.S
index 673b7fd..b9b588f 100644
--- a/libc/arch-mips/syscalls/settimeofday.S
+++ b/libc/arch-mips/syscalls/settimeofday.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl settimeofday
-    .align 4
-    .ent settimeofday
+#include <private/bionic_asm.h>
 
-settimeofday:
+ENTRY(settimeofday)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_settimeofday
+    .cpload t9
+    li v0, __NR_settimeofday
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end settimeofday
+END(settimeofday)
diff --git a/libc/arch-mips/syscalls/setuid.S b/libc/arch-mips/syscalls/setuid.S
index abfdafb..55c75c1 100644
--- a/libc/arch-mips/syscalls/setuid.S
+++ b/libc/arch-mips/syscalls/setuid.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setuid
-    .align 4
-    .ent setuid
+#include <private/bionic_asm.h>
 
-setuid:
+ENTRY(setuid)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setuid
+    .cpload t9
+    li v0, __NR_setuid
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end setuid
+END(setuid)
diff --git a/libc/arch-mips/syscalls/setxattr.S b/libc/arch-mips/syscalls/setxattr.S
index b9c1aaa..0cca64c 100644
--- a/libc/arch-mips/syscalls/setxattr.S
+++ b/libc/arch-mips/syscalls/setxattr.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl setxattr
-    .align 4
-    .ent setxattr
+#include <private/bionic_asm.h>
 
-setxattr:
+ENTRY(setxattr)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_setxattr
+    .cpload t9
+    li v0, __NR_setxattr
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end setxattr
+END(setxattr)
diff --git a/libc/arch-mips/syscalls/shutdown.S b/libc/arch-mips/syscalls/shutdown.S
index 0f2208f..f6e9979 100644
--- a/libc/arch-mips/syscalls/shutdown.S
+++ b/libc/arch-mips/syscalls/shutdown.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl shutdown
-    .align 4
-    .ent shutdown
+#include <private/bionic_asm.h>
 
-shutdown:
+ENTRY(shutdown)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_shutdown
+    .cpload t9
+    li v0, __NR_shutdown
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end shutdown
+END(shutdown)
diff --git a/libc/arch-mips/syscalls/sigaltstack.S b/libc/arch-mips/syscalls/sigaltstack.S
index ec1d8a1..6632164 100644
--- a/libc/arch-mips/syscalls/sigaltstack.S
+++ b/libc/arch-mips/syscalls/sigaltstack.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sigaltstack
-    .align 4
-    .ent sigaltstack
+#include <private/bionic_asm.h>
 
-sigaltstack:
+ENTRY(sigaltstack)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sigaltstack
+    .cpload t9
+    li v0, __NR_sigaltstack
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end sigaltstack
+END(sigaltstack)
diff --git a/libc/arch-mips/syscalls/signalfd4.S b/libc/arch-mips/syscalls/signalfd4.S
index 74e6168..e2c2a30 100644
--- a/libc/arch-mips/syscalls/signalfd4.S
+++ b/libc/arch-mips/syscalls/signalfd4.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl signalfd4
-    .align 4
-    .ent signalfd4
+#include <private/bionic_asm.h>
 
-signalfd4:
+ENTRY(signalfd4)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_signalfd4
+    .cpload t9
+    li v0, __NR_signalfd4
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end signalfd4
+END(signalfd4)
diff --git a/libc/arch-mips/syscalls/socket.S b/libc/arch-mips/syscalls/socket.S
index c67404e..2056bcd 100644
--- a/libc/arch-mips/syscalls/socket.S
+++ b/libc/arch-mips/syscalls/socket.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl socket
-    .align 4
-    .ent socket
+#include <private/bionic_asm.h>
 
-socket:
+ENTRY(socket)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_socket
+    .cpload t9
+    li v0, __NR_socket
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end socket
+END(socket)
diff --git a/libc/arch-mips/syscalls/socketpair.S b/libc/arch-mips/syscalls/socketpair.S
index c0f41e2..6257327 100644
--- a/libc/arch-mips/syscalls/socketpair.S
+++ b/libc/arch-mips/syscalls/socketpair.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl socketpair
-    .align 4
-    .ent socketpair
+#include <private/bionic_asm.h>
 
-socketpair:
+ENTRY(socketpair)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_socketpair
+    .cpload t9
+    li v0, __NR_socketpair
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end socketpair
+END(socketpair)
diff --git a/libc/arch-mips/syscalls/swapoff.S b/libc/arch-mips/syscalls/swapoff.S
index 1ed5083..04b5b70 100644
--- a/libc/arch-mips/syscalls/swapoff.S
+++ b/libc/arch-mips/syscalls/swapoff.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl swapoff
-    .align 4
-    .ent swapoff
+#include <private/bionic_asm.h>
 
-swapoff:
+ENTRY(swapoff)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_swapoff
+    .cpload t9
+    li v0, __NR_swapoff
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end swapoff
+END(swapoff)
diff --git a/libc/arch-mips/syscalls/swapon.S b/libc/arch-mips/syscalls/swapon.S
index 08a85b0..1fe3698 100644
--- a/libc/arch-mips/syscalls/swapon.S
+++ b/libc/arch-mips/syscalls/swapon.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl swapon
-    .align 4
-    .ent swapon
+#include <private/bionic_asm.h>
 
-swapon:
+ENTRY(swapon)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_swapon
+    .cpload t9
+    li v0, __NR_swapon
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end swapon
+END(swapon)
diff --git a/libc/arch-mips/syscalls/symlinkat.S b/libc/arch-mips/syscalls/symlinkat.S
index 9c43241..5bd6e6c 100644
--- a/libc/arch-mips/syscalls/symlinkat.S
+++ b/libc/arch-mips/syscalls/symlinkat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl symlinkat
-    .align 4
-    .ent symlinkat
+#include <private/bionic_asm.h>
 
-symlinkat:
+ENTRY(symlinkat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_symlinkat
+    .cpload t9
+    li v0, __NR_symlinkat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end symlinkat
+END(symlinkat)
diff --git a/libc/arch-mips/syscalls/sync.S b/libc/arch-mips/syscalls/sync.S
index 0e0ee1f..eb788f0 100644
--- a/libc/arch-mips/syscalls/sync.S
+++ b/libc/arch-mips/syscalls/sync.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sync
-    .align 4
-    .ent sync
+#include <private/bionic_asm.h>
 
-sync:
+ENTRY(sync)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sync
+    .cpload t9
+    li v0, __NR_sync
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end sync
+END(sync)
diff --git a/libc/arch-mips/syscalls/sysinfo.S b/libc/arch-mips/syscalls/sysinfo.S
index 3acfbf7..7cdccb9 100644
--- a/libc/arch-mips/syscalls/sysinfo.S
+++ b/libc/arch-mips/syscalls/sysinfo.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl sysinfo
-    .align 4
-    .ent sysinfo
+#include <private/bionic_asm.h>
 
-sysinfo:
+ENTRY(sysinfo)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_sysinfo
+    .cpload t9
+    li v0, __NR_sysinfo
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end sysinfo
+END(sysinfo)
diff --git a/libc/arch-mips/syscalls/tgkill.S b/libc/arch-mips/syscalls/tgkill.S
index 5de33d0..9938843 100644
--- a/libc/arch-mips/syscalls/tgkill.S
+++ b/libc/arch-mips/syscalls/tgkill.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl tgkill
-    .align 4
-    .ent tgkill
+#include <private/bionic_asm.h>
 
-tgkill:
+ENTRY(tgkill)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_tgkill
+    .cpload t9
+    li v0, __NR_tgkill
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end tgkill
+END(tgkill)
diff --git a/libc/arch-mips/syscalls/timerfd_create.S b/libc/arch-mips/syscalls/timerfd_create.S
index 2528355..c42f4e1 100644
--- a/libc/arch-mips/syscalls/timerfd_create.S
+++ b/libc/arch-mips/syscalls/timerfd_create.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl timerfd_create
-    .align 4
-    .ent timerfd_create
+#include <private/bionic_asm.h>
 
-timerfd_create:
+ENTRY(timerfd_create)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_timerfd_create
+    .cpload t9
+    li v0, __NR_timerfd_create
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end timerfd_create
+END(timerfd_create)
diff --git a/libc/arch-mips/syscalls/timerfd_gettime.S b/libc/arch-mips/syscalls/timerfd_gettime.S
index b38c2d4..469d174 100644
--- a/libc/arch-mips/syscalls/timerfd_gettime.S
+++ b/libc/arch-mips/syscalls/timerfd_gettime.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl timerfd_gettime
-    .align 4
-    .ent timerfd_gettime
+#include <private/bionic_asm.h>
 
-timerfd_gettime:
+ENTRY(timerfd_gettime)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_timerfd_gettime
+    .cpload t9
+    li v0, __NR_timerfd_gettime
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end timerfd_gettime
+END(timerfd_gettime)
diff --git a/libc/arch-mips/syscalls/timerfd_settime.S b/libc/arch-mips/syscalls/timerfd_settime.S
index 11dc61b..c7c6f47 100644
--- a/libc/arch-mips/syscalls/timerfd_settime.S
+++ b/libc/arch-mips/syscalls/timerfd_settime.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl timerfd_settime
-    .align 4
-    .ent timerfd_settime
+#include <private/bionic_asm.h>
 
-timerfd_settime:
+ENTRY(timerfd_settime)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_timerfd_settime
+    .cpload t9
+    li v0, __NR_timerfd_settime
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end timerfd_settime
+END(timerfd_settime)
diff --git a/libc/arch-mips/syscalls/times.S b/libc/arch-mips/syscalls/times.S
index 248a23f..157b34c 100644
--- a/libc/arch-mips/syscalls/times.S
+++ b/libc/arch-mips/syscalls/times.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl times
-    .align 4
-    .ent times
+#include <private/bionic_asm.h>
 
-times:
+ENTRY(times)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_times
+    .cpload t9
+    li v0, __NR_times
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end times
+END(times)
diff --git a/libc/arch-mips/syscalls/tkill.S b/libc/arch-mips/syscalls/tkill.S
index a80b506..c1ecb61 100644
--- a/libc/arch-mips/syscalls/tkill.S
+++ b/libc/arch-mips/syscalls/tkill.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl tkill
-    .align 4
-    .ent tkill
+#include <private/bionic_asm.h>
 
-tkill:
+ENTRY(tkill)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_tkill
+    .cpload t9
+    li v0, __NR_tkill
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end tkill
+END(tkill)
diff --git a/libc/arch-mips/syscalls/truncate.S b/libc/arch-mips/syscalls/truncate.S
index a4256dc..7fe4a0f 100644
--- a/libc/arch-mips/syscalls/truncate.S
+++ b/libc/arch-mips/syscalls/truncate.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl truncate
-    .align 4
-    .ent truncate
+#include <private/bionic_asm.h>
 
-truncate:
+ENTRY(truncate)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_truncate
+    .cpload t9
+    li v0, __NR_truncate
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end truncate
+END(truncate)
diff --git a/libc/arch-mips/syscalls/truncate64.S b/libc/arch-mips/syscalls/truncate64.S
index 9f48da0..0911f5f 100644
--- a/libc/arch-mips/syscalls/truncate64.S
+++ b/libc/arch-mips/syscalls/truncate64.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl truncate64
-    .align 4
-    .ent truncate64
+#include <private/bionic_asm.h>
 
-truncate64:
+ENTRY(truncate64)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_truncate64
+    .cpload t9
+    li v0, __NR_truncate64
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end truncate64
+END(truncate64)
diff --git a/libc/arch-mips/syscalls/umask.S b/libc/arch-mips/syscalls/umask.S
index d74cf90..57a6aed 100644
--- a/libc/arch-mips/syscalls/umask.S
+++ b/libc/arch-mips/syscalls/umask.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl umask
-    .align 4
-    .ent umask
+#include <private/bionic_asm.h>
 
-umask:
+ENTRY(umask)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_umask
+    .cpload t9
+    li v0, __NR_umask
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end umask
+END(umask)
diff --git a/libc/arch-mips/syscalls/umount2.S b/libc/arch-mips/syscalls/umount2.S
index 6164f76..bf8267d 100644
--- a/libc/arch-mips/syscalls/umount2.S
+++ b/libc/arch-mips/syscalls/umount2.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl umount2
-    .align 4
-    .ent umount2
+#include <private/bionic_asm.h>
 
-umount2:
+ENTRY(umount2)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_umount2
+    .cpload t9
+    li v0, __NR_umount2
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end umount2
+END(umount2)
diff --git a/libc/arch-mips/syscalls/uname.S b/libc/arch-mips/syscalls/uname.S
index a1051a2..ce77bd5 100644
--- a/libc/arch-mips/syscalls/uname.S
+++ b/libc/arch-mips/syscalls/uname.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl uname
-    .align 4
-    .ent uname
+#include <private/bionic_asm.h>
 
-uname:
+ENTRY(uname)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_uname
+    .cpload t9
+    li v0, __NR_uname
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end uname
+END(uname)
diff --git a/libc/arch-mips/syscalls/unlinkat.S b/libc/arch-mips/syscalls/unlinkat.S
index 0ca77fe..82e584b 100644
--- a/libc/arch-mips/syscalls/unlinkat.S
+++ b/libc/arch-mips/syscalls/unlinkat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl unlinkat
-    .align 4
-    .ent unlinkat
+#include <private/bionic_asm.h>
 
-unlinkat:
+ENTRY(unlinkat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_unlinkat
+    .cpload t9
+    li v0, __NR_unlinkat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end unlinkat
+END(unlinkat)
diff --git a/libc/arch-mips/syscalls/unshare.S b/libc/arch-mips/syscalls/unshare.S
index 592cc61..0521f30 100644
--- a/libc/arch-mips/syscalls/unshare.S
+++ b/libc/arch-mips/syscalls/unshare.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl unshare
-    .align 4
-    .ent unshare
+#include <private/bionic_asm.h>
 
-unshare:
+ENTRY(unshare)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_unshare
+    .cpload t9
+    li v0, __NR_unshare
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end unshare
+END(unshare)
diff --git a/libc/arch-mips/syscalls/utimensat.S b/libc/arch-mips/syscalls/utimensat.S
index 42fe4f9..208ef58 100644
--- a/libc/arch-mips/syscalls/utimensat.S
+++ b/libc/arch-mips/syscalls/utimensat.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl utimensat
-    .align 4
-    .ent utimensat
+#include <private/bionic_asm.h>
 
-utimensat:
+ENTRY(utimensat)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_utimensat
+    .cpload t9
+    li v0, __NR_utimensat
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end utimensat
+END(utimensat)
diff --git a/libc/arch-mips/syscalls/wait4.S b/libc/arch-mips/syscalls/wait4.S
index 8c53eca..ec6bd84 100644
--- a/libc/arch-mips/syscalls/wait4.S
+++ b/libc/arch-mips/syscalls/wait4.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl wait4
-    .align 4
-    .ent wait4
+#include <private/bionic_asm.h>
 
-wait4:
+ENTRY(wait4)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_wait4
+    .cpload t9
+    li v0, __NR_wait4
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end wait4
+END(wait4)
diff --git a/libc/arch-mips/syscalls/write.S b/libc/arch-mips/syscalls/write.S
index 85fe4d0..d10e55a 100644
--- a/libc/arch-mips/syscalls/write.S
+++ b/libc/arch-mips/syscalls/write.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl write
-    .align 4
-    .ent write
+#include <private/bionic_asm.h>
 
-write:
+ENTRY(write)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_write
+    .cpload t9
+    li v0, __NR_write
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end write
+END(write)
diff --git a/libc/arch-mips/syscalls/writev.S b/libc/arch-mips/syscalls/writev.S
index 4e23049..0a2c033 100644
--- a/libc/arch-mips/syscalls/writev.S
+++ b/libc/arch-mips/syscalls/writev.S
@@ -1,23 +1,19 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-    .text
-    .globl writev
-    .align 4
-    .ent writev
+#include <private/bionic_asm.h>
 
-writev:
+ENTRY(writev)
     .set noreorder
-    .cpload $t9
-    li $v0, __NR_writev
+    .cpload t9
+    li v0, __NR_writev
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end writev
+END(writev)
diff --git a/libc/arch-mips64/bionic/__bionic_clone.S b/libc/arch-mips64/bionic/__bionic_clone.S
index 2a9a2b0..e1ade30 100644
--- a/libc/arch-mips64/bionic/__bionic_clone.S
+++ b/libc/arch-mips64/bionic/__bionic_clone.S
@@ -26,8 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
-#include <asm/unistd.h>
+#include <private/bionic_asm.h>
 #include <linux/errno.h>
 #include <linux/sched.h>
 
@@ -43,8 +42,7 @@
 #endif
 
 // pid_t __bionic_clone(int flags, void* child_stack, pid_t* parent_tid, void* tls, pid_t* child_tid, int (*fn)(void*), void* arg);
-	.text
-LEAF(__bionic_clone,FRAMESZ)
+LEAF(__bionic_clone, FRAMESZ)
 	PTR_SUBU sp, FRAMESZ			# allocate stack frame
 	SETUP_GP64(FRAME_GP,__bionic_clone)
 	SAVE_GP(FRAME_GP)
diff --git a/libc/arch-mips64/bionic/__get_sp.S b/libc/arch-mips64/bionic/__get_sp.S
index 834c89d..8488102 100644
--- a/libc/arch-mips64/bionic/__get_sp.S
+++ b/libc/arch-mips64/bionic/__get_sp.S
@@ -25,15 +25,10 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-	.text
 
-/* void *__get_sp(void) */
+#include <private/bionic_asm.h>
 
-	.type	__get_sp, @function
-	.global	__get_sp
-	.align	4
-	.ent	__get_sp
-__get_sp:
-	move	$v0, $sp
-	j	$ra
-	.end	__get_sp
+ENTRY(__get_sp)
+  move v0, sp
+  j ra
+END(__get_sp)
diff --git a/libc/arch-mips64/bionic/_exit_with_stack_teardown.S b/libc/arch-mips64/bionic/_exit_with_stack_teardown.S
index 8f624c3..3b537eb 100644
--- a/libc/arch-mips64/bionic/_exit_with_stack_teardown.S
+++ b/libc/arch-mips64/bionic/_exit_with_stack_teardown.S
@@ -26,23 +26,16 @@
  * SUCH DAMAGE.
  */
 
-#include <asm/unistd.h>
-
-	.text
+#include <private/bionic_asm.h>
 
 // void _exit_with_stack_teardown(void* stackBase, size_t stackSize)
+ENTRY(_exit_with_stack_teardown)
+  li	v0, __NR_munmap
+  syscall
+  // If munmap failed, we ignore the failure and exit anyway.
 
-	.type	_exit_with_stack_teardown, @function
-	.global	_exit_with_stack_teardown
-	.align	4
-	.ent	_exit_with_stack_teardown
-_exit_with_stack_teardown:
-	li	$v0, __NR_munmap
-	syscall
-	// If munmap failed, we ignore the failure and exit anyway.
-
-	li	$a0, 0
-	li	$v0, __NR_exit
-	syscall
-        // The exit syscall does not return.
-	.end	_exit_with_stack_teardown
+  li	a0, 0
+  li	v0, __NR_exit
+  syscall
+  // The exit syscall does not return.
+END(_exit_with_stack_teardown)
diff --git a/libc/arch-mips64/bionic/_setjmp.S b/libc/arch-mips64/bionic/_setjmp.S
index e7083ae..4465cd2 100644
--- a/libc/arch-mips64/bionic/_setjmp.S
+++ b/libc/arch-mips64/bionic/_setjmp.S
@@ -2,7 +2,7 @@
 
 /*
  * Copyright (c) 2002 Opsycon AB  (www.opsycon.se / www.opsycon.com)
- * 
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -29,7 +29,7 @@
  *
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/regnum.h>
 #include <machine/signal.h>
 
@@ -48,13 +48,13 @@
         swc1    FPR, OFF(BASE)  ;       \
         mfhc1   t0, FPR         ;       \
         sw      t0, OFF+4(BASE) ;
-        
+
 #define FPREG64_L(FPR, OFF, BASE)       \
         lw      t0, OFF+4(BASE) ;       \
         lw      t1, OFF(BASE)   ;       \
         mtc1    t1, FPR         ;       \
         mthc1   t0, FPR         ;       \
-        
+
 LEAF(_setjmp, FRAMESZ)
 	PTR_SUBU sp, FRAMESZ
 	SETUP_GP64(GPOFF, _setjmp)
@@ -185,4 +185,3 @@
 	RESTORE_GP64
 	PTR_ADDU sp, FRAMESZ
 END(_longjmp)
-
diff --git a/libc/arch-mips64/bionic/bzero.S b/libc/arch-mips64/bionic/bzero.S
index d0b5c84..76c6bc2 100644
--- a/libc/arch-mips64/bionic/bzero.S
+++ b/libc/arch-mips64/bionic/bzero.S
@@ -25,9 +25,8 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-	.text
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 /*
  * void bzero(void *s, size_t n);
@@ -40,4 +39,3 @@
 	RESTORE_GP64
 	j	t9
 END(bzero)
-
diff --git a/libc/arch-mips64/bionic/futex_mips.S b/libc/arch-mips64/bionic/futex_mips.S
index 1a249a7..81f2f22 100644
--- a/libc/arch-mips64/bionic/futex_mips.S
+++ b/libc/arch-mips64/bionic/futex_mips.S
@@ -26,7 +26,6 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
 #include <private/bionic_asm.h>
 
 #define FUTEX_WAIT 0
diff --git a/libc/arch-mips64/bionic/memcmp16.S b/libc/arch-mips64/bionic/memcmp16.S
index b70c078..1c58c1b 100644
--- a/libc/arch-mips64/bionic/memcmp16.S
+++ b/libc/arch-mips64/bionic/memcmp16.S
@@ -27,7 +27,7 @@
  */
 	.text
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 /*
  * u4 __memcmp16(const u2* s0, const u2* s1, size_t count);
diff --git a/libc/arch-mips64/bionic/setjmp.S b/libc/arch-mips64/bionic/setjmp.S
index 7c21195..2af1fbd 100644
--- a/libc/arch-mips64/bionic/setjmp.S
+++ b/libc/arch-mips64/bionic/setjmp.S
@@ -29,7 +29,7 @@
  *
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/regnum.h>
 #include <machine/signal.h>
 
@@ -49,13 +49,13 @@
         swc1    FPR, OFF(BASE)  ;       \
         mfhc1   t0, FPR         ;       \
         sw      t0, OFF+4(BASE) ;
-        
+
 #define FPREG64_L(FPR, OFF, BASE)       \
         lw      t0, OFF+4(BASE) ;       \
         lw      t1, OFF(BASE)   ;       \
         mtc1    t1, FPR         ;       \
         mthc1   t0, FPR         ;       \
-        
+
 NON_LEAF(setjmp, FRAMESZ, ra)
 	.mask	0x80000000, RAOFF
 	PTR_SUBU sp, FRAMESZ			# allocate stack frame
@@ -154,7 +154,7 @@
 	lw	a0, A0OFF(sp)
 	lw	a1, A1OFF(sp)
 
-	.set	noreorder	
+	.set	noreorder
 	REG_L	v0, SC_REGS+ZERO*REGSZ(a0)
 	bne	v0, 0xACEDBADE, botch		# jump if error
 	REG_L	ra, SC_PC(a0)
@@ -169,9 +169,9 @@
 	REG_L	s8, SC_REGS+S8*REGSZ(a0)
 	REG_L	gp, SC_REGS+GP*REGSZ(a0)
 	REG_L	sp, SC_REGS+SP*REGSZ(a0)
-	
+
 #if !defined(SOFTFLOAT)
-	REG_L	v0, SC_FPREGS+((FSR-F0)*REGSZ)(a0)	
+	REG_L	v0, SC_FPREGS+((FSR-F0)*REGSZ)(a0)
 	ctc1	v0, $31
 #if _MIPS_FPSET == 32
         FPREG64_L($f20, SC_FPREGS+((F20-F0)*REGSZ_FP), a0)
diff --git a/libc/arch-mips64/bionic/sigsetjmp.S b/libc/arch-mips64/bionic/sigsetjmp.S
index b05454c..9d2e5ea 100644
--- a/libc/arch-mips64/bionic/sigsetjmp.S
+++ b/libc/arch-mips64/bionic/sigsetjmp.S
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/regnum.h>
 #include <machine/setjmp.h>
 
diff --git a/libc/arch-mips64/bionic/syscall.S b/libc/arch-mips64/bionic/syscall.S
index 08aa705..c4fd009 100644
--- a/libc/arch-mips64/bionic/syscall.S
+++ b/libc/arch-mips64/bionic/syscall.S
@@ -26,8 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
-#include <asm/unistd.h>
+#include <private/bionic_asm.h>
 
 #if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
 FRAMESZ		=	MKFSIZ(6,0)
diff --git a/libc/arch-mips64/bionic/vfork.S b/libc/arch-mips64/bionic/vfork.S
index c936945..911a264 100644
--- a/libc/arch-mips64/bionic/vfork.S
+++ b/libc/arch-mips64/bionic/vfork.S
@@ -26,8 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
-#include <asm/unistd.h>
+#include <private/bionic_asm.h>
 #include <linux/sched.h>
 
 // TODO: mips' uapi signal.h is missing #ifndef __ASSEMBLY__.
@@ -46,7 +45,7 @@
 #if FRAMESZ!=0
 	PTR_SUBU sp, FRAMESZ
 #endif
-	SETUP_GP64(a5,vfork)
+	SETUP_GP64(a5, vfork)
 	LI	a0, (CLONE_VM | CLONE_VFORK | SIGCHLD)
 	move	a1, $0
 	move	a2, $0
diff --git a/libc/arch-mips64/include/machine/asm.h b/libc/arch-mips64/include/machine/asm.h
index eabb1bf..5eacde3 100644
--- a/libc/arch-mips64/include/machine/asm.h
+++ b/libc/arch-mips64/include/machine/asm.h
@@ -28,25 +28,24 @@
 #ifndef _MIPS64_ASM_H
 #define _MIPS64_ASM_H
 
-#include <machine/regdef.h>
-
-#ifdef NEED_OLD_RM7KFIX
-#define ITLBNOPFIX      nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;
-#else
-#define ITLBNOPFIX      nop;nop;nop;nop
+#ifndef _ALIGN_TEXT
+# define _ALIGN_TEXT .align 4
 #endif
 
+#undef __bionic_asm_custom_entry
+#undef __bionic_asm_custom_end
+#define __bionic_asm_custom_entry(f) .ent f
+#define __bionic_asm_custom_end(f) .end f
+
+#include <machine/regdef.h>
+
 #define	_MIPS_ISA_MIPS1	1	/* R2000/R3000 */
 #define	_MIPS_ISA_MIPS2	2	/* R4000/R6000 */
 #define	_MIPS_ISA_MIPS3	3	/* R4000 */
 #define	_MIPS_ISA_MIPS4	4	/* TFP (R1x000) */
-#ifdef __linux__
 #define	_MIPS_ISA_MIPS5 5
 #define	_MIPS_ISA_MIPS32 6
 #define	_MIPS_ISA_MIPS64 7
-#else
-#define	_MIPS_ISA_MIPS32 32	/* MIPS32 */
-#endif
 
 #if !defined(ABICALLS) && !defined(_NO_ABICALLS)
 #define	ABICALLS	.abicalls
@@ -56,8 +55,6 @@
 	ABICALLS
 #endif
 
-#define _C_LABEL(x) x		/* XXX Obsolete but keep for a while */
-
 #if !defined(__MIPSEL__) && !defined(__MIPSEB__)
 #error "__MIPSEL__ or __MIPSEB__ must be defined"
 #endif
@@ -90,15 +87,6 @@
  */
 #if defined(ABICALLS) && !defined(_KERNEL) && !defined(_STANDALONE)
 
-#ifndef _MIPS_SIM
-#define _MIPS_SIM 1
-#define _ABIO32	1
-#endif
-#ifndef _MIPS_ISA
-#define _MIPS_ISA 2
-#define _MIPS_ISA_MIPS2 2
-#endif
-
 #if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
 #define NARGSAVE	4
 
@@ -190,28 +178,6 @@
 #endif
 
 /*
- * Define -pg profile entry code.
- */
-#if defined(XGPROF) || defined(XPROF)
-#define	MCOUNT			\
-	PTR_SUBU sp, sp, 64;	\
-	SAVE_GP(16);		\
-	sd	ra, 56(sp);	\
-	sd	gp, 48(sp);	\
-	.set	noat;		\
-	.set	noreorder;	\
-	move	AT, ra;		\
-	jal	_mcount;	\
-	PTR_SUBU sp, sp, 16;	\
-	ld	ra, 56(sp);	\
-	PTR_ADDU sp, sp, 64;	\
-	.set reorder;		\
-	.set	at;
-#else
-#define	MCOUNT
-#endif
-
-/*
  * LEAF(x, fsize)
  *
  *	Declare a leaf routine.
@@ -221,26 +187,9 @@
 	.globl x;		\
 	.ent x, 0;		\
 x: ;				\
+	.cfi_startproc; \
 	.frame sp, fsize, ra;	\
 	SETUP_GP		\
-	MCOUNT
-
-#define	ALEAF(x)		\
-	.globl	x;		\
-x:
-
-/*
- * NLEAF(x)
- *
- *	Declare a non-profiled leaf routine.
- */
-#define NLEAF(x, fsize)		\
-	.align	3;		\
-	.globl x;		\
-	.ent x, 0;		\
-x: ;				\
-	.frame sp, fsize, ra;	\
-	SETUP_GP
 
 /*
  * NON_LEAF(x)
@@ -252,54 +201,8 @@
 	.globl x;		\
 	.ent x, 0;		\
 x: ;				\
+	.cfi_startproc; \
 	.frame sp, fsize, retpc; \
 	SETUP_GP		\
-	MCOUNT
-
-/*
- * NNON_LEAF(x)
- *
- *	Declare a non-profiled non-leaf routine
- *	(a routine that makes other C calls).
- */
-#define NNON_LEAF(x, fsize, retpc) \
-	.align	3;		\
-	.globl x;		\
-	.ent x, 0;		\
-x: ;				\
-	.frame sp, fsize, retpc	\
-	SETUP_GP
-
-/*
- * END(x)
- *
- *	Mark end of a procedure.
- */
-#define END(x) \
-	.end x
-
-/*
- * Macros to panic and printf from assembly language.
- */
-#define PANIC(msg) \
-	LA	a0, 9f; \
-	jal	panic;	\
-	nop	;	\
-	MSG(msg)
-
-#define	PRINTF(msg) \
-	LA	a0, 9f; \
-	jal	printf; \
-	nop	;	\
-	MSG(msg)
-
-#define	MSG(msg) \
-	.rdata; \
-9:	.asciiz	msg; \
-	.text
-
-#define ASMSTR(str) \
-	.asciiz str; \
-	.align	3
 
 #endif /* !_MIPS_ASM_H */
diff --git a/libc/arch-mips64/include/machine/signal.h b/libc/arch-mips64/include/machine/signal.h
index f02ec0d..b31715c 100644
--- a/libc/arch-mips64/include/machine/signal.h
+++ b/libc/arch-mips64/include/machine/signal.h
@@ -37,8 +37,6 @@
 #ifndef _MIPS_SIGNAL_H_
 #define _MIPS_SIGNAL_H_
 
-#include <machine/asm.h>
-
 #define	SC_REGMASK	(0*REGSZ)
 #define	SC_STATUS	(1*REGSZ)
 #define	SC_PC		(2*REGSZ)
diff --git a/libc/arch-mips64/mips64.mk b/libc/arch-mips64/mips64.mk
index 6977d6a..11ceb40 100644
--- a/libc/arch-mips64/mips64.mk
+++ b/libc/arch-mips64/mips64.mk
@@ -59,18 +59,13 @@
 libc_bionic_src_files_mips64 += bionic/memset.c
 libc_bionic_src_files_mips64 += string/strlen.c
 
-libc_arch_static_src_files_mips64 :=
 
-libc_arch_dynamic_src_files_mips64 :=
-
-##########################################
-# crt-related
 libc_crt_target_cflags_mips64 := \
     $($(my_2nd_arch_prefix)TARGET_GLOBAL_CFLAGS) \
-    -I$(LOCAL_PATH)/arch-mips/include
+    -I$(LOCAL_PATH)/arch-mips64/include
 
 libc_crt_target_crtbegin_file_mips64 := \
-    $(LOCAL_PATH)/arch-mips/bionic/crtbegin.c
+    $(LOCAL_PATH)/arch-mips64/bionic/crtbegin.c
 
 libc_crt_target_crtbegin_so_file_mips64 := \
     $(LOCAL_PATH)/arch-common/bionic/crtbegin_so.c
diff --git a/libc/arch-mips64/string/memcpy.S b/libc/arch-mips64/string/memcpy.S
index aabdfcf..dc91096 100644
--- a/libc/arch-mips64/string/memcpy.S
+++ b/libc/arch-mips64/string/memcpy.S
@@ -39,13 +39,13 @@
  *  Include files
  ************************************************************************/
 
-#include "machine/asm.h"
+#include <private/bionic_asm.h>
 
 
-/* 
+/*
  * This routine could be optimized for MIPS64. The current code only
  * uses MIPS32 instructions.
- */	
+ */
 #if defined(__MIPSEB__)
 #  define LWHI	lwl		/* high part is left in big-endian	*/
 #  define SWHI	swl		/* high part is left in big-endian	*/
diff --git a/libc/arch-mips64/string/memset.S b/libc/arch-mips64/string/memset.S
index a1c5055..3e630ca 100644
--- a/libc/arch-mips64/string/memset.S
+++ b/libc/arch-mips64/string/memset.S
@@ -39,12 +39,12 @@
  *  Include files
  ************************************************************************/
 
-#include "machine/asm.h"
+#include <private/bionic_asm.h>
 
-/* 
+/*
  * This routine could be optimized for MIPS64. The current code only
  * uses MIPS32 instructions.
- */	
+ */
 
 #if defined(__MIPSEB__)
 #  define SWHI	swl		/* high part is left in big-endian	*/
@@ -220,7 +220,7 @@
 	sw	a1,-36(a0)
 	nop
 	nop			# the extra nop instructions help to balance
-	nop			# cycles needed for "store" + "fill" + "evict" 
+	nop			# cycles needed for "store" + "fill" + "evict"
 	nop			# For 64byte store there are needed 8 fill
 	nop			# and 8 evict cycles, i.e. at least 32 instr.
 	nop
@@ -320,4 +320,3 @@
 /************************************************************************
  *  Implementation : Static functions
  ************************************************************************/
-
diff --git a/libc/arch-mips64/syscalls/__brk.S b/libc/arch-mips64/syscalls/__brk.S
index 1e3939a..99a108a 100644
--- a/libc/arch-mips64/syscalls/__brk.S
+++ b/libc/arch-mips64/syscalls/__brk.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __brk
-    .align 4
-    .ent __brk
+#include <private/bionic_asm.h>
 
-__brk:
+ENTRY(__brk)
     .set push
     .set noreorder
     li v0, __NR_brk
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __brk
-.hidden _C_LABEL(__brk)
+END(__brk)
+.hidden __brk
diff --git a/libc/arch-mips64/syscalls/__epoll_pwait.S b/libc/arch-mips64/syscalls/__epoll_pwait.S
index 6167f48..fc3867a 100644
--- a/libc/arch-mips64/syscalls/__epoll_pwait.S
+++ b/libc/arch-mips64/syscalls/__epoll_pwait.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __epoll_pwait
-    .align 4
-    .ent __epoll_pwait
+#include <private/bionic_asm.h>
 
-__epoll_pwait:
+ENTRY(__epoll_pwait)
     .set push
     .set noreorder
     li v0, __NR_epoll_pwait
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __epoll_pwait
-.hidden _C_LABEL(__epoll_pwait)
+END(__epoll_pwait)
+.hidden __epoll_pwait
diff --git a/libc/arch-mips64/syscalls/__exit.S b/libc/arch-mips64/syscalls/__exit.S
index 0297a68..dac53b9 100644
--- a/libc/arch-mips64/syscalls/__exit.S
+++ b/libc/arch-mips64/syscalls/__exit.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __exit
-    .align 4
-    .ent __exit
+#include <private/bionic_asm.h>
 
-__exit:
+ENTRY(__exit)
     .set push
     .set noreorder
     li v0, __NR_exit
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __exit
-.hidden _C_LABEL(__exit)
+END(__exit)
+.hidden __exit
diff --git a/libc/arch-mips64/syscalls/__getcpu.S b/libc/arch-mips64/syscalls/__getcpu.S
index d20369e..9c08710 100644
--- a/libc/arch-mips64/syscalls/__getcpu.S
+++ b/libc/arch-mips64/syscalls/__getcpu.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __getcpu
-    .align 4
-    .ent __getcpu
+#include <private/bionic_asm.h>
 
-__getcpu:
+ENTRY(__getcpu)
     .set push
     .set noreorder
     li v0, __NR_getcpu
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __getcpu
-.hidden _C_LABEL(__getcpu)
+END(__getcpu)
+.hidden __getcpu
diff --git a/libc/arch-mips64/syscalls/__getcwd.S b/libc/arch-mips64/syscalls/__getcwd.S
index 47a32df..79fbca3 100644
--- a/libc/arch-mips64/syscalls/__getcwd.S
+++ b/libc/arch-mips64/syscalls/__getcwd.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __getcwd
-    .align 4
-    .ent __getcwd
+#include <private/bionic_asm.h>
 
-__getcwd:
+ENTRY(__getcwd)
     .set push
     .set noreorder
     li v0, __NR_getcwd
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __getcwd
-.hidden _C_LABEL(__getcwd)
+END(__getcwd)
+.hidden __getcwd
diff --git a/libc/arch-mips64/syscalls/__getdents.S b/libc/arch-mips64/syscalls/__getdents.S
index 3b89c8c..0a70a72 100644
--- a/libc/arch-mips64/syscalls/__getdents.S
+++ b/libc/arch-mips64/syscalls/__getdents.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __getdents
-    .align 4
-    .ent __getdents
+#include <private/bionic_asm.h>
 
-__getdents:
+ENTRY(__getdents)
     .set push
     .set noreorder
     li v0, __NR_getdents
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __getdents
-.hidden _C_LABEL(__getdents)
+END(__getdents)
+.hidden __getdents
diff --git a/libc/arch-mips64/syscalls/__getdents64.S b/libc/arch-mips64/syscalls/__getdents64.S
index eac06aa..6df556a 100644
--- a/libc/arch-mips64/syscalls/__getdents64.S
+++ b/libc/arch-mips64/syscalls/__getdents64.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __getdents64
-    .align 4
-    .ent __getdents64
+#include <private/bionic_asm.h>
 
-__getdents64:
+ENTRY(__getdents64)
     .set push
     .set noreorder
     li v0, __NR_getdents64
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __getdents64
-.hidden _C_LABEL(__getdents64)
+END(__getdents64)
+.hidden __getdents64
diff --git a/libc/arch-mips64/syscalls/__getpriority.S b/libc/arch-mips64/syscalls/__getpriority.S
index e3cd90e..6ca2e1f 100644
--- a/libc/arch-mips64/syscalls/__getpriority.S
+++ b/libc/arch-mips64/syscalls/__getpriority.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __getpriority
-    .align 4
-    .ent __getpriority
+#include <private/bionic_asm.h>
 
-__getpriority:
+ENTRY(__getpriority)
     .set push
     .set noreorder
     li v0, __NR_getpriority
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __getpriority
-.hidden _C_LABEL(__getpriority)
+END(__getpriority)
+.hidden __getpriority
diff --git a/libc/arch-mips64/syscalls/__ioctl.S b/libc/arch-mips64/syscalls/__ioctl.S
index c3bd575..013ce18 100644
--- a/libc/arch-mips64/syscalls/__ioctl.S
+++ b/libc/arch-mips64/syscalls/__ioctl.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __ioctl
-    .align 4
-    .ent __ioctl
+#include <private/bionic_asm.h>
 
-__ioctl:
+ENTRY(__ioctl)
     .set push
     .set noreorder
     li v0, __NR_ioctl
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __ioctl
-.hidden _C_LABEL(__ioctl)
+END(__ioctl)
+.hidden __ioctl
diff --git a/libc/arch-mips64/syscalls/__openat.S b/libc/arch-mips64/syscalls/__openat.S
index 0f14454..1d46ef6 100644
--- a/libc/arch-mips64/syscalls/__openat.S
+++ b/libc/arch-mips64/syscalls/__openat.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __openat
-    .align 4
-    .ent __openat
+#include <private/bionic_asm.h>
 
-__openat:
+ENTRY(__openat)
     .set push
     .set noreorder
     li v0, __NR_openat
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __openat
-.hidden _C_LABEL(__openat)
+END(__openat)
+.hidden __openat
diff --git a/libc/arch-mips64/syscalls/__ppoll.S b/libc/arch-mips64/syscalls/__ppoll.S
index ac7acb9..fb0e19a 100644
--- a/libc/arch-mips64/syscalls/__ppoll.S
+++ b/libc/arch-mips64/syscalls/__ppoll.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __ppoll
-    .align 4
-    .ent __ppoll
+#include <private/bionic_asm.h>
 
-__ppoll:
+ENTRY(__ppoll)
     .set push
     .set noreorder
     li v0, __NR_ppoll
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __ppoll
-.hidden _C_LABEL(__ppoll)
+END(__ppoll)
+.hidden __ppoll
diff --git a/libc/arch-mips64/syscalls/__pselect6.S b/libc/arch-mips64/syscalls/__pselect6.S
index 1e5ac2f..3055b31 100644
--- a/libc/arch-mips64/syscalls/__pselect6.S
+++ b/libc/arch-mips64/syscalls/__pselect6.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __pselect6
-    .align 4
-    .ent __pselect6
+#include <private/bionic_asm.h>
 
-__pselect6:
+ENTRY(__pselect6)
     .set push
     .set noreorder
     li v0, __NR_pselect6
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __pselect6
-.hidden _C_LABEL(__pselect6)
+END(__pselect6)
+.hidden __pselect6
diff --git a/libc/arch-mips64/syscalls/__ptrace.S b/libc/arch-mips64/syscalls/__ptrace.S
index 79b75b2..bae7733 100644
--- a/libc/arch-mips64/syscalls/__ptrace.S
+++ b/libc/arch-mips64/syscalls/__ptrace.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __ptrace
-    .align 4
-    .ent __ptrace
+#include <private/bionic_asm.h>
 
-__ptrace:
+ENTRY(__ptrace)
     .set push
     .set noreorder
     li v0, __NR_ptrace
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __ptrace
-.hidden _C_LABEL(__ptrace)
+END(__ptrace)
+.hidden __ptrace
diff --git a/libc/arch-mips64/syscalls/__reboot.S b/libc/arch-mips64/syscalls/__reboot.S
index 31ae824..31a97e3 100644
--- a/libc/arch-mips64/syscalls/__reboot.S
+++ b/libc/arch-mips64/syscalls/__reboot.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __reboot
-    .align 4
-    .ent __reboot
+#include <private/bionic_asm.h>
 
-__reboot:
+ENTRY(__reboot)
     .set push
     .set noreorder
     li v0, __NR_reboot
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __reboot
-.hidden _C_LABEL(__reboot)
+END(__reboot)
+.hidden __reboot
diff --git a/libc/arch-mips64/syscalls/__rt_sigaction.S b/libc/arch-mips64/syscalls/__rt_sigaction.S
index ef537a4..3728c58 100644
--- a/libc/arch-mips64/syscalls/__rt_sigaction.S
+++ b/libc/arch-mips64/syscalls/__rt_sigaction.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __rt_sigaction
-    .align 4
-    .ent __rt_sigaction
+#include <private/bionic_asm.h>
 
-__rt_sigaction:
+ENTRY(__rt_sigaction)
     .set push
     .set noreorder
     li v0, __NR_rt_sigaction
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __rt_sigaction
-.hidden _C_LABEL(__rt_sigaction)
+END(__rt_sigaction)
+.hidden __rt_sigaction
diff --git a/libc/arch-mips64/syscalls/__rt_sigpending.S b/libc/arch-mips64/syscalls/__rt_sigpending.S
index 2dc1bf6..e0d40cc 100644
--- a/libc/arch-mips64/syscalls/__rt_sigpending.S
+++ b/libc/arch-mips64/syscalls/__rt_sigpending.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __rt_sigpending
-    .align 4
-    .ent __rt_sigpending
+#include <private/bionic_asm.h>
 
-__rt_sigpending:
+ENTRY(__rt_sigpending)
     .set push
     .set noreorder
     li v0, __NR_rt_sigpending
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __rt_sigpending
-.hidden _C_LABEL(__rt_sigpending)
+END(__rt_sigpending)
+.hidden __rt_sigpending
diff --git a/libc/arch-mips64/syscalls/__rt_sigprocmask.S b/libc/arch-mips64/syscalls/__rt_sigprocmask.S
index 2814d66..d34a34b 100644
--- a/libc/arch-mips64/syscalls/__rt_sigprocmask.S
+++ b/libc/arch-mips64/syscalls/__rt_sigprocmask.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __rt_sigprocmask
-    .align 4
-    .ent __rt_sigprocmask
+#include <private/bionic_asm.h>
 
-__rt_sigprocmask:
+ENTRY(__rt_sigprocmask)
     .set push
     .set noreorder
     li v0, __NR_rt_sigprocmask
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __rt_sigprocmask
-.hidden _C_LABEL(__rt_sigprocmask)
+END(__rt_sigprocmask)
+.hidden __rt_sigprocmask
diff --git a/libc/arch-mips64/syscalls/__rt_sigsuspend.S b/libc/arch-mips64/syscalls/__rt_sigsuspend.S
index 83c1990..f36e1c3 100644
--- a/libc/arch-mips64/syscalls/__rt_sigsuspend.S
+++ b/libc/arch-mips64/syscalls/__rt_sigsuspend.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __rt_sigsuspend
-    .align 4
-    .ent __rt_sigsuspend
+#include <private/bionic_asm.h>
 
-__rt_sigsuspend:
+ENTRY(__rt_sigsuspend)
     .set push
     .set noreorder
     li v0, __NR_rt_sigsuspend
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __rt_sigsuspend
-.hidden _C_LABEL(__rt_sigsuspend)
+END(__rt_sigsuspend)
+.hidden __rt_sigsuspend
diff --git a/libc/arch-mips64/syscalls/__rt_sigtimedwait.S b/libc/arch-mips64/syscalls/__rt_sigtimedwait.S
index 48daea8..798d6f8 100644
--- a/libc/arch-mips64/syscalls/__rt_sigtimedwait.S
+++ b/libc/arch-mips64/syscalls/__rt_sigtimedwait.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __rt_sigtimedwait
-    .align 4
-    .ent __rt_sigtimedwait
+#include <private/bionic_asm.h>
 
-__rt_sigtimedwait:
+ENTRY(__rt_sigtimedwait)
     .set push
     .set noreorder
     li v0, __NR_rt_sigtimedwait
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __rt_sigtimedwait
-.hidden _C_LABEL(__rt_sigtimedwait)
+END(__rt_sigtimedwait)
+.hidden __rt_sigtimedwait
diff --git a/libc/arch-mips64/syscalls/__sched_getaffinity.S b/libc/arch-mips64/syscalls/__sched_getaffinity.S
index 006e395..a287815 100644
--- a/libc/arch-mips64/syscalls/__sched_getaffinity.S
+++ b/libc/arch-mips64/syscalls/__sched_getaffinity.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __sched_getaffinity
-    .align 4
-    .ent __sched_getaffinity
+#include <private/bionic_asm.h>
 
-__sched_getaffinity:
+ENTRY(__sched_getaffinity)
     .set push
     .set noreorder
     li v0, __NR_sched_getaffinity
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __sched_getaffinity
-.hidden _C_LABEL(__sched_getaffinity)
+END(__sched_getaffinity)
+.hidden __sched_getaffinity
diff --git a/libc/arch-mips64/syscalls/__set_thread_area.S b/libc/arch-mips64/syscalls/__set_thread_area.S
index 009d004..c28ee4a 100644
--- a/libc/arch-mips64/syscalls/__set_thread_area.S
+++ b/libc/arch-mips64/syscalls/__set_thread_area.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __set_thread_area
-    .align 4
-    .ent __set_thread_area
+#include <private/bionic_asm.h>
 
-__set_thread_area:
+ENTRY(__set_thread_area)
     .set push
     .set noreorder
     li v0, __NR_set_thread_area
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __set_thread_area
-.hidden _C_LABEL(__set_thread_area)
+END(__set_thread_area)
+.hidden __set_thread_area
diff --git a/libc/arch-mips64/syscalls/__set_tid_address.S b/libc/arch-mips64/syscalls/__set_tid_address.S
index 4c1f97d..8757001 100644
--- a/libc/arch-mips64/syscalls/__set_tid_address.S
+++ b/libc/arch-mips64/syscalls/__set_tid_address.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __set_tid_address
-    .align 4
-    .ent __set_tid_address
+#include <private/bionic_asm.h>
 
-__set_tid_address:
+ENTRY(__set_tid_address)
     .set push
     .set noreorder
     li v0, __NR_set_tid_address
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __set_tid_address
-.hidden _C_LABEL(__set_tid_address)
+END(__set_tid_address)
+.hidden __set_tid_address
diff --git a/libc/arch-mips64/syscalls/__syslog.S b/libc/arch-mips64/syscalls/__syslog.S
index 2291401..70eed3a 100644
--- a/libc/arch-mips64/syscalls/__syslog.S
+++ b/libc/arch-mips64/syscalls/__syslog.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __syslog
-    .align 4
-    .ent __syslog
+#include <private/bionic_asm.h>
 
-__syslog:
+ENTRY(__syslog)
     .set push
     .set noreorder
     li v0, __NR_syslog
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __syslog
-.hidden _C_LABEL(__syslog)
+END(__syslog)
+.hidden __syslog
diff --git a/libc/arch-mips64/syscalls/__timer_create.S b/libc/arch-mips64/syscalls/__timer_create.S
index aa024b7..5a4daac 100644
--- a/libc/arch-mips64/syscalls/__timer_create.S
+++ b/libc/arch-mips64/syscalls/__timer_create.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __timer_create
-    .align 4
-    .ent __timer_create
+#include <private/bionic_asm.h>
 
-__timer_create:
+ENTRY(__timer_create)
     .set push
     .set noreorder
     li v0, __NR_timer_create
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __timer_create
-.hidden _C_LABEL(__timer_create)
+END(__timer_create)
+.hidden __timer_create
diff --git a/libc/arch-mips64/syscalls/__timer_delete.S b/libc/arch-mips64/syscalls/__timer_delete.S
index 024f0c4..8bbbdb7 100644
--- a/libc/arch-mips64/syscalls/__timer_delete.S
+++ b/libc/arch-mips64/syscalls/__timer_delete.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __timer_delete
-    .align 4
-    .ent __timer_delete
+#include <private/bionic_asm.h>
 
-__timer_delete:
+ENTRY(__timer_delete)
     .set push
     .set noreorder
     li v0, __NR_timer_delete
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __timer_delete
-.hidden _C_LABEL(__timer_delete)
+END(__timer_delete)
+.hidden __timer_delete
diff --git a/libc/arch-mips64/syscalls/__timer_getoverrun.S b/libc/arch-mips64/syscalls/__timer_getoverrun.S
index 0931111..3bf06cc 100644
--- a/libc/arch-mips64/syscalls/__timer_getoverrun.S
+++ b/libc/arch-mips64/syscalls/__timer_getoverrun.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __timer_getoverrun
-    .align 4
-    .ent __timer_getoverrun
+#include <private/bionic_asm.h>
 
-__timer_getoverrun:
+ENTRY(__timer_getoverrun)
     .set push
     .set noreorder
     li v0, __NR_timer_getoverrun
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __timer_getoverrun
-.hidden _C_LABEL(__timer_getoverrun)
+END(__timer_getoverrun)
+.hidden __timer_getoverrun
diff --git a/libc/arch-mips64/syscalls/__timer_gettime.S b/libc/arch-mips64/syscalls/__timer_gettime.S
index 4eb5f71..a15ec17 100644
--- a/libc/arch-mips64/syscalls/__timer_gettime.S
+++ b/libc/arch-mips64/syscalls/__timer_gettime.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __timer_gettime
-    .align 4
-    .ent __timer_gettime
+#include <private/bionic_asm.h>
 
-__timer_gettime:
+ENTRY(__timer_gettime)
     .set push
     .set noreorder
     li v0, __NR_timer_gettime
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __timer_gettime
-.hidden _C_LABEL(__timer_gettime)
+END(__timer_gettime)
+.hidden __timer_gettime
diff --git a/libc/arch-mips64/syscalls/__timer_settime.S b/libc/arch-mips64/syscalls/__timer_settime.S
index ecac0c5..10e2ca8 100644
--- a/libc/arch-mips64/syscalls/__timer_settime.S
+++ b/libc/arch-mips64/syscalls/__timer_settime.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __timer_settime
-    .align 4
-    .ent __timer_settime
+#include <private/bionic_asm.h>
 
-__timer_settime:
+ENTRY(__timer_settime)
     .set push
     .set noreorder
     li v0, __NR_timer_settime
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __timer_settime
-.hidden _C_LABEL(__timer_settime)
+END(__timer_settime)
+.hidden __timer_settime
diff --git a/libc/arch-mips64/syscalls/__waitid.S b/libc/arch-mips64/syscalls/__waitid.S
index caba21e..4d971e6 100644
--- a/libc/arch-mips64/syscalls/__waitid.S
+++ b/libc/arch-mips64/syscalls/__waitid.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl __waitid
-    .align 4
-    .ent __waitid
+#include <private/bionic_asm.h>
 
-__waitid:
+ENTRY(__waitid)
     .set push
     .set noreorder
     li v0, __NR_waitid
@@ -28,5 +22,5 @@
     j t9
     move ra, t0
     .set pop
-    .end __waitid
-.hidden _C_LABEL(__waitid)
+END(__waitid)
+.hidden __waitid
diff --git a/libc/arch-mips64/syscalls/_exit.S b/libc/arch-mips64/syscalls/_exit.S
index 87aff94..9b108a6 100644
--- a/libc/arch-mips64/syscalls/_exit.S
+++ b/libc/arch-mips64/syscalls/_exit.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl _exit
-    .align 4
-    .ent _exit
+#include <private/bionic_asm.h>
 
-_exit:
+ENTRY(_exit)
     .set push
     .set noreorder
     li v0, __NR_exit_group
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end _exit
+END(_exit)
diff --git a/libc/arch-mips64/syscalls/_flush_cache.S b/libc/arch-mips64/syscalls/_flush_cache.S
index c2f8cd6..132fd4e 100644
--- a/libc/arch-mips64/syscalls/_flush_cache.S
+++ b/libc/arch-mips64/syscalls/_flush_cache.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl _flush_cache
-    .align 4
-    .ent _flush_cache
+#include <private/bionic_asm.h>
 
-_flush_cache:
+ENTRY(_flush_cache)
     .set push
     .set noreorder
     li v0, __NR_cacheflush
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end _flush_cache
+END(_flush_cache)
diff --git a/libc/arch-mips64/syscalls/accept.S b/libc/arch-mips64/syscalls/accept.S
index dc9ac59..6c38556 100644
--- a/libc/arch-mips64/syscalls/accept.S
+++ b/libc/arch-mips64/syscalls/accept.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl accept
-    .align 4
-    .ent accept
+#include <private/bionic_asm.h>
 
-accept:
+ENTRY(accept)
     .set push
     .set noreorder
     li v0, __NR_accept
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end accept
+END(accept)
diff --git a/libc/arch-mips64/syscalls/acct.S b/libc/arch-mips64/syscalls/acct.S
index 0b23866..7185877 100644
--- a/libc/arch-mips64/syscalls/acct.S
+++ b/libc/arch-mips64/syscalls/acct.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl acct
-    .align 4
-    .ent acct
+#include <private/bionic_asm.h>
 
-acct:
+ENTRY(acct)
     .set push
     .set noreorder
     li v0, __NR_acct
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end acct
+END(acct)
diff --git a/libc/arch-mips64/syscalls/bind.S b/libc/arch-mips64/syscalls/bind.S
index da81dad..cb28bb4 100644
--- a/libc/arch-mips64/syscalls/bind.S
+++ b/libc/arch-mips64/syscalls/bind.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl bind
-    .align 4
-    .ent bind
+#include <private/bionic_asm.h>
 
-bind:
+ENTRY(bind)
     .set push
     .set noreorder
     li v0, __NR_bind
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end bind
+END(bind)
diff --git a/libc/arch-mips64/syscalls/capget.S b/libc/arch-mips64/syscalls/capget.S
index 26d74b1..068e076 100644
--- a/libc/arch-mips64/syscalls/capget.S
+++ b/libc/arch-mips64/syscalls/capget.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl capget
-    .align 4
-    .ent capget
+#include <private/bionic_asm.h>
 
-capget:
+ENTRY(capget)
     .set push
     .set noreorder
     li v0, __NR_capget
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end capget
+END(capget)
diff --git a/libc/arch-mips64/syscalls/capset.S b/libc/arch-mips64/syscalls/capset.S
index b4b87de..f29501b 100644
--- a/libc/arch-mips64/syscalls/capset.S
+++ b/libc/arch-mips64/syscalls/capset.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl capset
-    .align 4
-    .ent capset
+#include <private/bionic_asm.h>
 
-capset:
+ENTRY(capset)
     .set push
     .set noreorder
     li v0, __NR_capset
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end capset
+END(capset)
diff --git a/libc/arch-mips64/syscalls/chdir.S b/libc/arch-mips64/syscalls/chdir.S
index af3546a..c2753bd 100644
--- a/libc/arch-mips64/syscalls/chdir.S
+++ b/libc/arch-mips64/syscalls/chdir.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl chdir
-    .align 4
-    .ent chdir
+#include <private/bionic_asm.h>
 
-chdir:
+ENTRY(chdir)
     .set push
     .set noreorder
     li v0, __NR_chdir
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end chdir
+END(chdir)
diff --git a/libc/arch-mips64/syscalls/chroot.S b/libc/arch-mips64/syscalls/chroot.S
index b992774..ca1d4a8 100644
--- a/libc/arch-mips64/syscalls/chroot.S
+++ b/libc/arch-mips64/syscalls/chroot.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl chroot
-    .align 4
-    .ent chroot
+#include <private/bionic_asm.h>
 
-chroot:
+ENTRY(chroot)
     .set push
     .set noreorder
     li v0, __NR_chroot
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end chroot
+END(chroot)
diff --git a/libc/arch-mips64/syscalls/clock_getres.S b/libc/arch-mips64/syscalls/clock_getres.S
index f277ab1..e7a8dd3 100644
--- a/libc/arch-mips64/syscalls/clock_getres.S
+++ b/libc/arch-mips64/syscalls/clock_getres.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl clock_getres
-    .align 4
-    .ent clock_getres
+#include <private/bionic_asm.h>
 
-clock_getres:
+ENTRY(clock_getres)
     .set push
     .set noreorder
     li v0, __NR_clock_getres
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end clock_getres
+END(clock_getres)
diff --git a/libc/arch-mips64/syscalls/clock_gettime.S b/libc/arch-mips64/syscalls/clock_gettime.S
index 8200e75..4c92a38 100644
--- a/libc/arch-mips64/syscalls/clock_gettime.S
+++ b/libc/arch-mips64/syscalls/clock_gettime.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl clock_gettime
-    .align 4
-    .ent clock_gettime
+#include <private/bionic_asm.h>
 
-clock_gettime:
+ENTRY(clock_gettime)
     .set push
     .set noreorder
     li v0, __NR_clock_gettime
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end clock_gettime
+END(clock_gettime)
diff --git a/libc/arch-mips64/syscalls/clock_nanosleep.S b/libc/arch-mips64/syscalls/clock_nanosleep.S
index 9ac95fc..2934591 100644
--- a/libc/arch-mips64/syscalls/clock_nanosleep.S
+++ b/libc/arch-mips64/syscalls/clock_nanosleep.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl clock_nanosleep
-    .align 4
-    .ent clock_nanosleep
+#include <private/bionic_asm.h>
 
-clock_nanosleep:
+ENTRY(clock_nanosleep)
     .set push
     .set noreorder
     li v0, __NR_clock_nanosleep
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end clock_nanosleep
+END(clock_nanosleep)
diff --git a/libc/arch-mips64/syscalls/clock_settime.S b/libc/arch-mips64/syscalls/clock_settime.S
index a8cd723..1969cb6 100644
--- a/libc/arch-mips64/syscalls/clock_settime.S
+++ b/libc/arch-mips64/syscalls/clock_settime.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl clock_settime
-    .align 4
-    .ent clock_settime
+#include <private/bionic_asm.h>
 
-clock_settime:
+ENTRY(clock_settime)
     .set push
     .set noreorder
     li v0, __NR_clock_settime
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end clock_settime
+END(clock_settime)
diff --git a/libc/arch-mips64/syscalls/close.S b/libc/arch-mips64/syscalls/close.S
index cfe5c51..f446000 100644
--- a/libc/arch-mips64/syscalls/close.S
+++ b/libc/arch-mips64/syscalls/close.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl close
-    .align 4
-    .ent close
+#include <private/bionic_asm.h>
 
-close:
+ENTRY(close)
     .set push
     .set noreorder
     li v0, __NR_close
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end close
+END(close)
diff --git a/libc/arch-mips64/syscalls/connect.S b/libc/arch-mips64/syscalls/connect.S
index 80600bb..8fe2d56 100644
--- a/libc/arch-mips64/syscalls/connect.S
+++ b/libc/arch-mips64/syscalls/connect.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl connect
-    .align 4
-    .ent connect
+#include <private/bionic_asm.h>
 
-connect:
+ENTRY(connect)
     .set push
     .set noreorder
     li v0, __NR_connect
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end connect
+END(connect)
diff --git a/libc/arch-mips64/syscalls/delete_module.S b/libc/arch-mips64/syscalls/delete_module.S
index cf2579d..d24adf8 100644
--- a/libc/arch-mips64/syscalls/delete_module.S
+++ b/libc/arch-mips64/syscalls/delete_module.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl delete_module
-    .align 4
-    .ent delete_module
+#include <private/bionic_asm.h>
 
-delete_module:
+ENTRY(delete_module)
     .set push
     .set noreorder
     li v0, __NR_delete_module
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end delete_module
+END(delete_module)
diff --git a/libc/arch-mips64/syscalls/dup.S b/libc/arch-mips64/syscalls/dup.S
index 0a92e57..5d2d7de 100644
--- a/libc/arch-mips64/syscalls/dup.S
+++ b/libc/arch-mips64/syscalls/dup.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl dup
-    .align 4
-    .ent dup
+#include <private/bionic_asm.h>
 
-dup:
+ENTRY(dup)
     .set push
     .set noreorder
     li v0, __NR_dup
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end dup
+END(dup)
diff --git a/libc/arch-mips64/syscalls/dup3.S b/libc/arch-mips64/syscalls/dup3.S
index e9fba1e..90f0f89 100644
--- a/libc/arch-mips64/syscalls/dup3.S
+++ b/libc/arch-mips64/syscalls/dup3.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl dup3
-    .align 4
-    .ent dup3
+#include <private/bionic_asm.h>
 
-dup3:
+ENTRY(dup3)
     .set push
     .set noreorder
     li v0, __NR_dup3
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end dup3
+END(dup3)
diff --git a/libc/arch-mips64/syscalls/epoll_create1.S b/libc/arch-mips64/syscalls/epoll_create1.S
index 9c41868..312887f 100644
--- a/libc/arch-mips64/syscalls/epoll_create1.S
+++ b/libc/arch-mips64/syscalls/epoll_create1.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl epoll_create1
-    .align 4
-    .ent epoll_create1
+#include <private/bionic_asm.h>
 
-epoll_create1:
+ENTRY(epoll_create1)
     .set push
     .set noreorder
     li v0, __NR_epoll_create1
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end epoll_create1
+END(epoll_create1)
diff --git a/libc/arch-mips64/syscalls/epoll_ctl.S b/libc/arch-mips64/syscalls/epoll_ctl.S
index 5f18979..461ad7b 100644
--- a/libc/arch-mips64/syscalls/epoll_ctl.S
+++ b/libc/arch-mips64/syscalls/epoll_ctl.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl epoll_ctl
-    .align 4
-    .ent epoll_ctl
+#include <private/bionic_asm.h>
 
-epoll_ctl:
+ENTRY(epoll_ctl)
     .set push
     .set noreorder
     li v0, __NR_epoll_ctl
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end epoll_ctl
+END(epoll_ctl)
diff --git a/libc/arch-mips64/syscalls/eventfd.S b/libc/arch-mips64/syscalls/eventfd.S
index 9cb87ca..da8866e 100644
--- a/libc/arch-mips64/syscalls/eventfd.S
+++ b/libc/arch-mips64/syscalls/eventfd.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl eventfd
-    .align 4
-    .ent eventfd
+#include <private/bionic_asm.h>
 
-eventfd:
+ENTRY(eventfd)
     .set push
     .set noreorder
     li v0, __NR_eventfd2
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end eventfd
+END(eventfd)
diff --git a/libc/arch-mips64/syscalls/execve.S b/libc/arch-mips64/syscalls/execve.S
index 8edfc34..3cb49b6 100644
--- a/libc/arch-mips64/syscalls/execve.S
+++ b/libc/arch-mips64/syscalls/execve.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl execve
-    .align 4
-    .ent execve
+#include <private/bionic_asm.h>
 
-execve:
+ENTRY(execve)
     .set push
     .set noreorder
     li v0, __NR_execve
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end execve
+END(execve)
diff --git a/libc/arch-mips64/syscalls/faccessat.S b/libc/arch-mips64/syscalls/faccessat.S
index 14de073..d06f420 100644
--- a/libc/arch-mips64/syscalls/faccessat.S
+++ b/libc/arch-mips64/syscalls/faccessat.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl faccessat
-    .align 4
-    .ent faccessat
+#include <private/bionic_asm.h>
 
-faccessat:
+ENTRY(faccessat)
     .set push
     .set noreorder
     li v0, __NR_faccessat
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end faccessat
+END(faccessat)
diff --git a/libc/arch-mips64/syscalls/fallocate.S b/libc/arch-mips64/syscalls/fallocate.S
index 347ab1f..d1e64b5 100644
--- a/libc/arch-mips64/syscalls/fallocate.S
+++ b/libc/arch-mips64/syscalls/fallocate.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl fallocate
-    .align 4
-    .ent fallocate
+#include <private/bionic_asm.h>
 
-fallocate:
+ENTRY(fallocate)
     .set push
     .set noreorder
     li v0, __NR_fallocate
@@ -28,7 +22,7 @@
     j t9
     move ra, t0
     .set pop
-    .end fallocate
+END(fallocate)
 
     .globl fallocate64
     .equ fallocate64, fallocate
diff --git a/libc/arch-mips64/syscalls/fchdir.S b/libc/arch-mips64/syscalls/fchdir.S
index 1b5e7cb..0c8ab73 100644
--- a/libc/arch-mips64/syscalls/fchdir.S
+++ b/libc/arch-mips64/syscalls/fchdir.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl fchdir
-    .align 4
-    .ent fchdir
+#include <private/bionic_asm.h>
 
-fchdir:
+ENTRY(fchdir)
     .set push
     .set noreorder
     li v0, __NR_fchdir
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end fchdir
+END(fchdir)
diff --git a/libc/arch-mips64/syscalls/fchmod.S b/libc/arch-mips64/syscalls/fchmod.S
index b9ce347..4ebb796 100644
--- a/libc/arch-mips64/syscalls/fchmod.S
+++ b/libc/arch-mips64/syscalls/fchmod.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl fchmod
-    .align 4
-    .ent fchmod
+#include <private/bionic_asm.h>
 
-fchmod:
+ENTRY(fchmod)
     .set push
     .set noreorder
     li v0, __NR_fchmod
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end fchmod
+END(fchmod)
diff --git a/libc/arch-mips64/syscalls/fchmodat.S b/libc/arch-mips64/syscalls/fchmodat.S
index f21aea7..4887324 100644
--- a/libc/arch-mips64/syscalls/fchmodat.S
+++ b/libc/arch-mips64/syscalls/fchmodat.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl fchmodat
-    .align 4
-    .ent fchmodat
+#include <private/bionic_asm.h>
 
-fchmodat:
+ENTRY(fchmodat)
     .set push
     .set noreorder
     li v0, __NR_fchmodat
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end fchmodat
+END(fchmodat)
diff --git a/libc/arch-mips64/syscalls/fchown.S b/libc/arch-mips64/syscalls/fchown.S
index 2eb7fa4..c21c831 100644
--- a/libc/arch-mips64/syscalls/fchown.S
+++ b/libc/arch-mips64/syscalls/fchown.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl fchown
-    .align 4
-    .ent fchown
+#include <private/bionic_asm.h>
 
-fchown:
+ENTRY(fchown)
     .set push
     .set noreorder
     li v0, __NR_fchown
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end fchown
+END(fchown)
diff --git a/libc/arch-mips64/syscalls/fchownat.S b/libc/arch-mips64/syscalls/fchownat.S
index 896ba43..eba230c 100644
--- a/libc/arch-mips64/syscalls/fchownat.S
+++ b/libc/arch-mips64/syscalls/fchownat.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl fchownat
-    .align 4
-    .ent fchownat
+#include <private/bionic_asm.h>
 
-fchownat:
+ENTRY(fchownat)
     .set push
     .set noreorder
     li v0, __NR_fchownat
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end fchownat
+END(fchownat)
diff --git a/libc/arch-mips64/syscalls/fcntl.S b/libc/arch-mips64/syscalls/fcntl.S
index 755361d..1f54b0e 100644
--- a/libc/arch-mips64/syscalls/fcntl.S
+++ b/libc/arch-mips64/syscalls/fcntl.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl fcntl
-    .align 4
-    .ent fcntl
+#include <private/bionic_asm.h>
 
-fcntl:
+ENTRY(fcntl)
     .set push
     .set noreorder
     li v0, __NR_fcntl
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end fcntl
+END(fcntl)
diff --git a/libc/arch-mips64/syscalls/fdatasync.S b/libc/arch-mips64/syscalls/fdatasync.S
index f036248..ba1eccc 100644
--- a/libc/arch-mips64/syscalls/fdatasync.S
+++ b/libc/arch-mips64/syscalls/fdatasync.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl fdatasync
-    .align 4
-    .ent fdatasync
+#include <private/bionic_asm.h>
 
-fdatasync:
+ENTRY(fdatasync)
     .set push
     .set noreorder
     li v0, __NR_fdatasync
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end fdatasync
+END(fdatasync)
diff --git a/libc/arch-mips64/syscalls/fgetxattr.S b/libc/arch-mips64/syscalls/fgetxattr.S
index 0cd6ad7..5b9c8ed 100644
--- a/libc/arch-mips64/syscalls/fgetxattr.S
+++ b/libc/arch-mips64/syscalls/fgetxattr.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl fgetxattr
-    .align 4
-    .ent fgetxattr
+#include <private/bionic_asm.h>
 
-fgetxattr:
+ENTRY(fgetxattr)
     .set push
     .set noreorder
     li v0, __NR_fgetxattr
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end fgetxattr
+END(fgetxattr)
diff --git a/libc/arch-mips64/syscalls/flistxattr.S b/libc/arch-mips64/syscalls/flistxattr.S
index 2e8961b..c0bf93c 100644
--- a/libc/arch-mips64/syscalls/flistxattr.S
+++ b/libc/arch-mips64/syscalls/flistxattr.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl flistxattr
-    .align 4
-    .ent flistxattr
+#include <private/bionic_asm.h>
 
-flistxattr:
+ENTRY(flistxattr)
     .set push
     .set noreorder
     li v0, __NR_flistxattr
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end flistxattr
+END(flistxattr)
diff --git a/libc/arch-mips64/syscalls/flock.S b/libc/arch-mips64/syscalls/flock.S
index 93051d3..b63f6fc 100644
--- a/libc/arch-mips64/syscalls/flock.S
+++ b/libc/arch-mips64/syscalls/flock.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl flock
-    .align 4
-    .ent flock
+#include <private/bionic_asm.h>
 
-flock:
+ENTRY(flock)
     .set push
     .set noreorder
     li v0, __NR_flock
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end flock
+END(flock)
diff --git a/libc/arch-mips64/syscalls/fremovexattr.S b/libc/arch-mips64/syscalls/fremovexattr.S
index 6ef8c12..be20d00 100644
--- a/libc/arch-mips64/syscalls/fremovexattr.S
+++ b/libc/arch-mips64/syscalls/fremovexattr.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl fremovexattr
-    .align 4
-    .ent fremovexattr
+#include <private/bionic_asm.h>
 
-fremovexattr:
+ENTRY(fremovexattr)
     .set push
     .set noreorder
     li v0, __NR_fremovexattr
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end fremovexattr
+END(fremovexattr)
diff --git a/libc/arch-mips64/syscalls/fsetxattr.S b/libc/arch-mips64/syscalls/fsetxattr.S
index 89e0de7..92198ce 100644
--- a/libc/arch-mips64/syscalls/fsetxattr.S
+++ b/libc/arch-mips64/syscalls/fsetxattr.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl fsetxattr
-    .align 4
-    .ent fsetxattr
+#include <private/bionic_asm.h>
 
-fsetxattr:
+ENTRY(fsetxattr)
     .set push
     .set noreorder
     li v0, __NR_fsetxattr
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end fsetxattr
+END(fsetxattr)
diff --git a/libc/arch-mips64/syscalls/fstat64.S b/libc/arch-mips64/syscalls/fstat64.S
index aad3c21..078e3dd 100644
--- a/libc/arch-mips64/syscalls/fstat64.S
+++ b/libc/arch-mips64/syscalls/fstat64.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl fstat64
-    .align 4
-    .ent fstat64
+#include <private/bionic_asm.h>
 
-fstat64:
+ENTRY(fstat64)
     .set push
     .set noreorder
     li v0, __NR_fstat
@@ -28,7 +22,7 @@
     j t9
     move ra, t0
     .set pop
-    .end fstat64
+END(fstat64)
 
     .globl fstat
     .equ fstat, fstat64
diff --git a/libc/arch-mips64/syscalls/fstatat64.S b/libc/arch-mips64/syscalls/fstatat64.S
index 828439a..cc38de1 100644
--- a/libc/arch-mips64/syscalls/fstatat64.S
+++ b/libc/arch-mips64/syscalls/fstatat64.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl fstatat64
-    .align 4
-    .ent fstatat64
+#include <private/bionic_asm.h>
 
-fstatat64:
+ENTRY(fstatat64)
     .set push
     .set noreorder
     li v0, __NR_newfstatat
@@ -28,7 +22,7 @@
     j t9
     move ra, t0
     .set pop
-    .end fstatat64
+END(fstatat64)
 
     .globl fstatat
     .equ fstatat, fstatat64
diff --git a/libc/arch-mips64/syscalls/fstatfs64.S b/libc/arch-mips64/syscalls/fstatfs64.S
index 09380b2..3474bc2 100644
--- a/libc/arch-mips64/syscalls/fstatfs64.S
+++ b/libc/arch-mips64/syscalls/fstatfs64.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl fstatfs64
-    .align 4
-    .ent fstatfs64
+#include <private/bionic_asm.h>
 
-fstatfs64:
+ENTRY(fstatfs64)
     .set push
     .set noreorder
     li v0, __NR_fstatfs
@@ -28,7 +22,7 @@
     j t9
     move ra, t0
     .set pop
-    .end fstatfs64
+END(fstatfs64)
 
     .globl fstatfs
     .equ fstatfs, fstatfs64
diff --git a/libc/arch-mips64/syscalls/fsync.S b/libc/arch-mips64/syscalls/fsync.S
index 08f77f0..3543fef 100644
--- a/libc/arch-mips64/syscalls/fsync.S
+++ b/libc/arch-mips64/syscalls/fsync.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl fsync
-    .align 4
-    .ent fsync
+#include <private/bionic_asm.h>
 
-fsync:
+ENTRY(fsync)
     .set push
     .set noreorder
     li v0, __NR_fsync
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end fsync
+END(fsync)
diff --git a/libc/arch-mips64/syscalls/ftruncate.S b/libc/arch-mips64/syscalls/ftruncate.S
index 3afe26a..cd97b87 100644
--- a/libc/arch-mips64/syscalls/ftruncate.S
+++ b/libc/arch-mips64/syscalls/ftruncate.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl ftruncate
-    .align 4
-    .ent ftruncate
+#include <private/bionic_asm.h>
 
-ftruncate:
+ENTRY(ftruncate)
     .set push
     .set noreorder
     li v0, __NR_ftruncate
@@ -28,7 +22,7 @@
     j t9
     move ra, t0
     .set pop
-    .end ftruncate
+END(ftruncate)
 
     .globl ftruncate64
     .equ ftruncate64, ftruncate
diff --git a/libc/arch-mips64/syscalls/futex.S b/libc/arch-mips64/syscalls/futex.S
index edbacba..dc7dcc6 100644
--- a/libc/arch-mips64/syscalls/futex.S
+++ b/libc/arch-mips64/syscalls/futex.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl futex
-    .align 4
-    .ent futex
+#include <private/bionic_asm.h>
 
-futex:
+ENTRY(futex)
     .set push
     .set noreorder
     li v0, __NR_futex
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end futex
+END(futex)
diff --git a/libc/arch-mips64/syscalls/getegid.S b/libc/arch-mips64/syscalls/getegid.S
index d014386..d6b3d7f 100644
--- a/libc/arch-mips64/syscalls/getegid.S
+++ b/libc/arch-mips64/syscalls/getegid.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl getegid
-    .align 4
-    .ent getegid
+#include <private/bionic_asm.h>
 
-getegid:
+ENTRY(getegid)
     .set push
     .set noreorder
     li v0, __NR_getegid
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end getegid
+END(getegid)
diff --git a/libc/arch-mips64/syscalls/geteuid.S b/libc/arch-mips64/syscalls/geteuid.S
index ec63f6c..a1d9713 100644
--- a/libc/arch-mips64/syscalls/geteuid.S
+++ b/libc/arch-mips64/syscalls/geteuid.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl geteuid
-    .align 4
-    .ent geteuid
+#include <private/bionic_asm.h>
 
-geteuid:
+ENTRY(geteuid)
     .set push
     .set noreorder
     li v0, __NR_geteuid
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end geteuid
+END(geteuid)
diff --git a/libc/arch-mips64/syscalls/getgid.S b/libc/arch-mips64/syscalls/getgid.S
index 531d364..c89d709 100644
--- a/libc/arch-mips64/syscalls/getgid.S
+++ b/libc/arch-mips64/syscalls/getgid.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl getgid
-    .align 4
-    .ent getgid
+#include <private/bionic_asm.h>
 
-getgid:
+ENTRY(getgid)
     .set push
     .set noreorder
     li v0, __NR_getgid
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end getgid
+END(getgid)
diff --git a/libc/arch-mips64/syscalls/getgroups.S b/libc/arch-mips64/syscalls/getgroups.S
index b7fcef6..8d9cddb 100644
--- a/libc/arch-mips64/syscalls/getgroups.S
+++ b/libc/arch-mips64/syscalls/getgroups.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl getgroups
-    .align 4
-    .ent getgroups
+#include <private/bionic_asm.h>
 
-getgroups:
+ENTRY(getgroups)
     .set push
     .set noreorder
     li v0, __NR_getgroups
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end getgroups
+END(getgroups)
diff --git a/libc/arch-mips64/syscalls/getitimer.S b/libc/arch-mips64/syscalls/getitimer.S
index 4f9bc63..12dad03 100644
--- a/libc/arch-mips64/syscalls/getitimer.S
+++ b/libc/arch-mips64/syscalls/getitimer.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl getitimer
-    .align 4
-    .ent getitimer
+#include <private/bionic_asm.h>
 
-getitimer:
+ENTRY(getitimer)
     .set push
     .set noreorder
     li v0, __NR_getitimer
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end getitimer
+END(getitimer)
diff --git a/libc/arch-mips64/syscalls/getpeername.S b/libc/arch-mips64/syscalls/getpeername.S
index 695fe6a..278428a 100644
--- a/libc/arch-mips64/syscalls/getpeername.S
+++ b/libc/arch-mips64/syscalls/getpeername.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl getpeername
-    .align 4
-    .ent getpeername
+#include <private/bionic_asm.h>
 
-getpeername:
+ENTRY(getpeername)
     .set push
     .set noreorder
     li v0, __NR_getpeername
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end getpeername
+END(getpeername)
diff --git a/libc/arch-mips64/syscalls/getpgid.S b/libc/arch-mips64/syscalls/getpgid.S
index 46787d6..56551ef 100644
--- a/libc/arch-mips64/syscalls/getpgid.S
+++ b/libc/arch-mips64/syscalls/getpgid.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl getpgid
-    .align 4
-    .ent getpgid
+#include <private/bionic_asm.h>
 
-getpgid:
+ENTRY(getpgid)
     .set push
     .set noreorder
     li v0, __NR_getpgid
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end getpgid
+END(getpgid)
diff --git a/libc/arch-mips64/syscalls/getpid.S b/libc/arch-mips64/syscalls/getpid.S
index 4f3f58f..3b457b5 100644
--- a/libc/arch-mips64/syscalls/getpid.S
+++ b/libc/arch-mips64/syscalls/getpid.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl getpid
-    .align 4
-    .ent getpid
+#include <private/bionic_asm.h>
 
-getpid:
+ENTRY(getpid)
     .set push
     .set noreorder
     li v0, __NR_getpid
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end getpid
+END(getpid)
diff --git a/libc/arch-mips64/syscalls/getppid.S b/libc/arch-mips64/syscalls/getppid.S
index 0bcab00..97066f8 100644
--- a/libc/arch-mips64/syscalls/getppid.S
+++ b/libc/arch-mips64/syscalls/getppid.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl getppid
-    .align 4
-    .ent getppid
+#include <private/bionic_asm.h>
 
-getppid:
+ENTRY(getppid)
     .set push
     .set noreorder
     li v0, __NR_getppid
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end getppid
+END(getppid)
diff --git a/libc/arch-mips64/syscalls/getresgid.S b/libc/arch-mips64/syscalls/getresgid.S
index 48e605b..f07fc11 100644
--- a/libc/arch-mips64/syscalls/getresgid.S
+++ b/libc/arch-mips64/syscalls/getresgid.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl getresgid
-    .align 4
-    .ent getresgid
+#include <private/bionic_asm.h>
 
-getresgid:
+ENTRY(getresgid)
     .set push
     .set noreorder
     li v0, __NR_getresgid
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end getresgid
+END(getresgid)
diff --git a/libc/arch-mips64/syscalls/getresuid.S b/libc/arch-mips64/syscalls/getresuid.S
index 79987d6..4f1ba86 100644
--- a/libc/arch-mips64/syscalls/getresuid.S
+++ b/libc/arch-mips64/syscalls/getresuid.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl getresuid
-    .align 4
-    .ent getresuid
+#include <private/bionic_asm.h>
 
-getresuid:
+ENTRY(getresuid)
     .set push
     .set noreorder
     li v0, __NR_getresuid
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end getresuid
+END(getresuid)
diff --git a/libc/arch-mips64/syscalls/getrlimit.S b/libc/arch-mips64/syscalls/getrlimit.S
index d19eaeb..f825db9 100644
--- a/libc/arch-mips64/syscalls/getrlimit.S
+++ b/libc/arch-mips64/syscalls/getrlimit.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl getrlimit
-    .align 4
-    .ent getrlimit
+#include <private/bionic_asm.h>
 
-getrlimit:
+ENTRY(getrlimit)
     .set push
     .set noreorder
     li v0, __NR_getrlimit
@@ -28,7 +22,7 @@
     j t9
     move ra, t0
     .set pop
-    .end getrlimit
+END(getrlimit)
 
     .globl getrlimit64
     .equ getrlimit64, getrlimit
diff --git a/libc/arch-mips64/syscalls/getrusage.S b/libc/arch-mips64/syscalls/getrusage.S
index dd57c38..49f3c42 100644
--- a/libc/arch-mips64/syscalls/getrusage.S
+++ b/libc/arch-mips64/syscalls/getrusage.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl getrusage
-    .align 4
-    .ent getrusage
+#include <private/bionic_asm.h>
 
-getrusage:
+ENTRY(getrusage)
     .set push
     .set noreorder
     li v0, __NR_getrusage
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end getrusage
+END(getrusage)
diff --git a/libc/arch-mips64/syscalls/getsid.S b/libc/arch-mips64/syscalls/getsid.S
index 5fb9e1b..6fa362c 100644
--- a/libc/arch-mips64/syscalls/getsid.S
+++ b/libc/arch-mips64/syscalls/getsid.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl getsid
-    .align 4
-    .ent getsid
+#include <private/bionic_asm.h>
 
-getsid:
+ENTRY(getsid)
     .set push
     .set noreorder
     li v0, __NR_getsid
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end getsid
+END(getsid)
diff --git a/libc/arch-mips64/syscalls/getsockname.S b/libc/arch-mips64/syscalls/getsockname.S
index 44026bf..5e16aff 100644
--- a/libc/arch-mips64/syscalls/getsockname.S
+++ b/libc/arch-mips64/syscalls/getsockname.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl getsockname
-    .align 4
-    .ent getsockname
+#include <private/bionic_asm.h>
 
-getsockname:
+ENTRY(getsockname)
     .set push
     .set noreorder
     li v0, __NR_getsockname
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end getsockname
+END(getsockname)
diff --git a/libc/arch-mips64/syscalls/getsockopt.S b/libc/arch-mips64/syscalls/getsockopt.S
index 8493faa..fab05b1 100644
--- a/libc/arch-mips64/syscalls/getsockopt.S
+++ b/libc/arch-mips64/syscalls/getsockopt.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl getsockopt
-    .align 4
-    .ent getsockopt
+#include <private/bionic_asm.h>
 
-getsockopt:
+ENTRY(getsockopt)
     .set push
     .set noreorder
     li v0, __NR_getsockopt
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end getsockopt
+END(getsockopt)
diff --git a/libc/arch-mips64/syscalls/gettid.S b/libc/arch-mips64/syscalls/gettid.S
index e03bb4e..30c30c8 100644
--- a/libc/arch-mips64/syscalls/gettid.S
+++ b/libc/arch-mips64/syscalls/gettid.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl gettid
-    .align 4
-    .ent gettid
+#include <private/bionic_asm.h>
 
-gettid:
+ENTRY(gettid)
     .set push
     .set noreorder
     li v0, __NR_gettid
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end gettid
+END(gettid)
diff --git a/libc/arch-mips64/syscalls/gettimeofday.S b/libc/arch-mips64/syscalls/gettimeofday.S
index e1e5c04..07407a4 100644
--- a/libc/arch-mips64/syscalls/gettimeofday.S
+++ b/libc/arch-mips64/syscalls/gettimeofday.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl gettimeofday
-    .align 4
-    .ent gettimeofday
+#include <private/bionic_asm.h>
 
-gettimeofday:
+ENTRY(gettimeofday)
     .set push
     .set noreorder
     li v0, __NR_gettimeofday
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end gettimeofday
+END(gettimeofday)
diff --git a/libc/arch-mips64/syscalls/getuid.S b/libc/arch-mips64/syscalls/getuid.S
index e48f4a6..87c16e1 100644
--- a/libc/arch-mips64/syscalls/getuid.S
+++ b/libc/arch-mips64/syscalls/getuid.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl getuid
-    .align 4
-    .ent getuid
+#include <private/bionic_asm.h>
 
-getuid:
+ENTRY(getuid)
     .set push
     .set noreorder
     li v0, __NR_getuid
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end getuid
+END(getuid)
diff --git a/libc/arch-mips64/syscalls/getxattr.S b/libc/arch-mips64/syscalls/getxattr.S
index b46e4d9..b42ca1e 100644
--- a/libc/arch-mips64/syscalls/getxattr.S
+++ b/libc/arch-mips64/syscalls/getxattr.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl getxattr
-    .align 4
-    .ent getxattr
+#include <private/bionic_asm.h>
 
-getxattr:
+ENTRY(getxattr)
     .set push
     .set noreorder
     li v0, __NR_getxattr
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end getxattr
+END(getxattr)
diff --git a/libc/arch-mips64/syscalls/init_module.S b/libc/arch-mips64/syscalls/init_module.S
index c5b2bcf..90fb6b1 100644
--- a/libc/arch-mips64/syscalls/init_module.S
+++ b/libc/arch-mips64/syscalls/init_module.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl init_module
-    .align 4
-    .ent init_module
+#include <private/bionic_asm.h>
 
-init_module:
+ENTRY(init_module)
     .set push
     .set noreorder
     li v0, __NR_init_module
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end init_module
+END(init_module)
diff --git a/libc/arch-mips64/syscalls/inotify_add_watch.S b/libc/arch-mips64/syscalls/inotify_add_watch.S
index c4c8dbf..17db414 100644
--- a/libc/arch-mips64/syscalls/inotify_add_watch.S
+++ b/libc/arch-mips64/syscalls/inotify_add_watch.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl inotify_add_watch
-    .align 4
-    .ent inotify_add_watch
+#include <private/bionic_asm.h>
 
-inotify_add_watch:
+ENTRY(inotify_add_watch)
     .set push
     .set noreorder
     li v0, __NR_inotify_add_watch
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end inotify_add_watch
+END(inotify_add_watch)
diff --git a/libc/arch-mips64/syscalls/inotify_init1.S b/libc/arch-mips64/syscalls/inotify_init1.S
index b0c7dcc..356dd2d 100644
--- a/libc/arch-mips64/syscalls/inotify_init1.S
+++ b/libc/arch-mips64/syscalls/inotify_init1.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl inotify_init1
-    .align 4
-    .ent inotify_init1
+#include <private/bionic_asm.h>
 
-inotify_init1:
+ENTRY(inotify_init1)
     .set push
     .set noreorder
     li v0, __NR_inotify_init1
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end inotify_init1
+END(inotify_init1)
diff --git a/libc/arch-mips64/syscalls/inotify_rm_watch.S b/libc/arch-mips64/syscalls/inotify_rm_watch.S
index 4b6078e..4096ca3 100644
--- a/libc/arch-mips64/syscalls/inotify_rm_watch.S
+++ b/libc/arch-mips64/syscalls/inotify_rm_watch.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl inotify_rm_watch
-    .align 4
-    .ent inotify_rm_watch
+#include <private/bionic_asm.h>
 
-inotify_rm_watch:
+ENTRY(inotify_rm_watch)
     .set push
     .set noreorder
     li v0, __NR_inotify_rm_watch
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end inotify_rm_watch
+END(inotify_rm_watch)
diff --git a/libc/arch-mips64/syscalls/ioprio_get.S b/libc/arch-mips64/syscalls/ioprio_get.S
index ebb4375..711890c 100644
--- a/libc/arch-mips64/syscalls/ioprio_get.S
+++ b/libc/arch-mips64/syscalls/ioprio_get.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl ioprio_get
-    .align 4
-    .ent ioprio_get
+#include <private/bionic_asm.h>
 
-ioprio_get:
+ENTRY(ioprio_get)
     .set push
     .set noreorder
     li v0, __NR_ioprio_get
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end ioprio_get
+END(ioprio_get)
diff --git a/libc/arch-mips64/syscalls/ioprio_set.S b/libc/arch-mips64/syscalls/ioprio_set.S
index 44daba9..738403a 100644
--- a/libc/arch-mips64/syscalls/ioprio_set.S
+++ b/libc/arch-mips64/syscalls/ioprio_set.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl ioprio_set
-    .align 4
-    .ent ioprio_set
+#include <private/bionic_asm.h>
 
-ioprio_set:
+ENTRY(ioprio_set)
     .set push
     .set noreorder
     li v0, __NR_ioprio_set
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end ioprio_set
+END(ioprio_set)
diff --git a/libc/arch-mips64/syscalls/kill.S b/libc/arch-mips64/syscalls/kill.S
index 2e4aa42..2d8b452 100644
--- a/libc/arch-mips64/syscalls/kill.S
+++ b/libc/arch-mips64/syscalls/kill.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl kill
-    .align 4
-    .ent kill
+#include <private/bionic_asm.h>
 
-kill:
+ENTRY(kill)
     .set push
     .set noreorder
     li v0, __NR_kill
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end kill
+END(kill)
diff --git a/libc/arch-mips64/syscalls/klogctl.S b/libc/arch-mips64/syscalls/klogctl.S
index 1c10f95..2f9ca6a 100644
--- a/libc/arch-mips64/syscalls/klogctl.S
+++ b/libc/arch-mips64/syscalls/klogctl.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl klogctl
-    .align 4
-    .ent klogctl
+#include <private/bionic_asm.h>
 
-klogctl:
+ENTRY(klogctl)
     .set push
     .set noreorder
     li v0, __NR_syslog
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end klogctl
+END(klogctl)
diff --git a/libc/arch-mips64/syscalls/lgetxattr.S b/libc/arch-mips64/syscalls/lgetxattr.S
index c402e81..f8e57b3 100644
--- a/libc/arch-mips64/syscalls/lgetxattr.S
+++ b/libc/arch-mips64/syscalls/lgetxattr.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl lgetxattr
-    .align 4
-    .ent lgetxattr
+#include <private/bionic_asm.h>
 
-lgetxattr:
+ENTRY(lgetxattr)
     .set push
     .set noreorder
     li v0, __NR_lgetxattr
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end lgetxattr
+END(lgetxattr)
diff --git a/libc/arch-mips64/syscalls/linkat.S b/libc/arch-mips64/syscalls/linkat.S
index e734144..a866fa6 100644
--- a/libc/arch-mips64/syscalls/linkat.S
+++ b/libc/arch-mips64/syscalls/linkat.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl linkat
-    .align 4
-    .ent linkat
+#include <private/bionic_asm.h>
 
-linkat:
+ENTRY(linkat)
     .set push
     .set noreorder
     li v0, __NR_linkat
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end linkat
+END(linkat)
diff --git a/libc/arch-mips64/syscalls/listen.S b/libc/arch-mips64/syscalls/listen.S
index 93c1d52..0768c72 100644
--- a/libc/arch-mips64/syscalls/listen.S
+++ b/libc/arch-mips64/syscalls/listen.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl listen
-    .align 4
-    .ent listen
+#include <private/bionic_asm.h>
 
-listen:
+ENTRY(listen)
     .set push
     .set noreorder
     li v0, __NR_listen
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end listen
+END(listen)
diff --git a/libc/arch-mips64/syscalls/listxattr.S b/libc/arch-mips64/syscalls/listxattr.S
index f00402f..f2c00f6 100644
--- a/libc/arch-mips64/syscalls/listxattr.S
+++ b/libc/arch-mips64/syscalls/listxattr.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl listxattr
-    .align 4
-    .ent listxattr
+#include <private/bionic_asm.h>
 
-listxattr:
+ENTRY(listxattr)
     .set push
     .set noreorder
     li v0, __NR_listxattr
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end listxattr
+END(listxattr)
diff --git a/libc/arch-mips64/syscalls/llistxattr.S b/libc/arch-mips64/syscalls/llistxattr.S
index 2628185..f324e2c 100644
--- a/libc/arch-mips64/syscalls/llistxattr.S
+++ b/libc/arch-mips64/syscalls/llistxattr.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl llistxattr
-    .align 4
-    .ent llistxattr
+#include <private/bionic_asm.h>
 
-llistxattr:
+ENTRY(llistxattr)
     .set push
     .set noreorder
     li v0, __NR_llistxattr
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end llistxattr
+END(llistxattr)
diff --git a/libc/arch-mips64/syscalls/lremovexattr.S b/libc/arch-mips64/syscalls/lremovexattr.S
index ef486cb..e44c9d0 100644
--- a/libc/arch-mips64/syscalls/lremovexattr.S
+++ b/libc/arch-mips64/syscalls/lremovexattr.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl lremovexattr
-    .align 4
-    .ent lremovexattr
+#include <private/bionic_asm.h>
 
-lremovexattr:
+ENTRY(lremovexattr)
     .set push
     .set noreorder
     li v0, __NR_lremovexattr
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end lremovexattr
+END(lremovexattr)
diff --git a/libc/arch-mips64/syscalls/lseek.S b/libc/arch-mips64/syscalls/lseek.S
index 4385df5..2858aa8 100644
--- a/libc/arch-mips64/syscalls/lseek.S
+++ b/libc/arch-mips64/syscalls/lseek.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl lseek
-    .align 4
-    .ent lseek
+#include <private/bionic_asm.h>
 
-lseek:
+ENTRY(lseek)
     .set push
     .set noreorder
     li v0, __NR_lseek
@@ -28,7 +22,7 @@
     j t9
     move ra, t0
     .set pop
-    .end lseek
+END(lseek)
 
     .globl lseek64
     .equ lseek64, lseek
diff --git a/libc/arch-mips64/syscalls/lsetxattr.S b/libc/arch-mips64/syscalls/lsetxattr.S
index 14a1aae..ed1b4df 100644
--- a/libc/arch-mips64/syscalls/lsetxattr.S
+++ b/libc/arch-mips64/syscalls/lsetxattr.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl lsetxattr
-    .align 4
-    .ent lsetxattr
+#include <private/bionic_asm.h>
 
-lsetxattr:
+ENTRY(lsetxattr)
     .set push
     .set noreorder
     li v0, __NR_lsetxattr
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end lsetxattr
+END(lsetxattr)
diff --git a/libc/arch-mips64/syscalls/madvise.S b/libc/arch-mips64/syscalls/madvise.S
index 8ca4124..fe6a828 100644
--- a/libc/arch-mips64/syscalls/madvise.S
+++ b/libc/arch-mips64/syscalls/madvise.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl madvise
-    .align 4
-    .ent madvise
+#include <private/bionic_asm.h>
 
-madvise:
+ENTRY(madvise)
     .set push
     .set noreorder
     li v0, __NR_madvise
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end madvise
+END(madvise)
diff --git a/libc/arch-mips64/syscalls/mincore.S b/libc/arch-mips64/syscalls/mincore.S
index 9dbd21c..1e0b544 100644
--- a/libc/arch-mips64/syscalls/mincore.S
+++ b/libc/arch-mips64/syscalls/mincore.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl mincore
-    .align 4
-    .ent mincore
+#include <private/bionic_asm.h>
 
-mincore:
+ENTRY(mincore)
     .set push
     .set noreorder
     li v0, __NR_mincore
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end mincore
+END(mincore)
diff --git a/libc/arch-mips64/syscalls/mkdirat.S b/libc/arch-mips64/syscalls/mkdirat.S
index e652b23..b1c94e1 100644
--- a/libc/arch-mips64/syscalls/mkdirat.S
+++ b/libc/arch-mips64/syscalls/mkdirat.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl mkdirat
-    .align 4
-    .ent mkdirat
+#include <private/bionic_asm.h>
 
-mkdirat:
+ENTRY(mkdirat)
     .set push
     .set noreorder
     li v0, __NR_mkdirat
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end mkdirat
+END(mkdirat)
diff --git a/libc/arch-mips64/syscalls/mknodat.S b/libc/arch-mips64/syscalls/mknodat.S
index 1cedbb4..edbd3b6 100644
--- a/libc/arch-mips64/syscalls/mknodat.S
+++ b/libc/arch-mips64/syscalls/mknodat.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl mknodat
-    .align 4
-    .ent mknodat
+#include <private/bionic_asm.h>
 
-mknodat:
+ENTRY(mknodat)
     .set push
     .set noreorder
     li v0, __NR_mknodat
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end mknodat
+END(mknodat)
diff --git a/libc/arch-mips64/syscalls/mlock.S b/libc/arch-mips64/syscalls/mlock.S
index 18ab4ba..ae599cd 100644
--- a/libc/arch-mips64/syscalls/mlock.S
+++ b/libc/arch-mips64/syscalls/mlock.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl mlock
-    .align 4
-    .ent mlock
+#include <private/bionic_asm.h>
 
-mlock:
+ENTRY(mlock)
     .set push
     .set noreorder
     li v0, __NR_mlock
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end mlock
+END(mlock)
diff --git a/libc/arch-mips64/syscalls/mlockall.S b/libc/arch-mips64/syscalls/mlockall.S
index 50fb23c..b214758 100644
--- a/libc/arch-mips64/syscalls/mlockall.S
+++ b/libc/arch-mips64/syscalls/mlockall.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl mlockall
-    .align 4
-    .ent mlockall
+#include <private/bionic_asm.h>
 
-mlockall:
+ENTRY(mlockall)
     .set push
     .set noreorder
     li v0, __NR_mlockall
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end mlockall
+END(mlockall)
diff --git a/libc/arch-mips64/syscalls/mmap.S b/libc/arch-mips64/syscalls/mmap.S
index 682058e..ba6d4fa 100644
--- a/libc/arch-mips64/syscalls/mmap.S
+++ b/libc/arch-mips64/syscalls/mmap.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl mmap
-    .align 4
-    .ent mmap
+#include <private/bionic_asm.h>
 
-mmap:
+ENTRY(mmap)
     .set push
     .set noreorder
     li v0, __NR_mmap
@@ -28,7 +22,7 @@
     j t9
     move ra, t0
     .set pop
-    .end mmap
+END(mmap)
 
     .globl mmap64
     .equ mmap64, mmap
diff --git a/libc/arch-mips64/syscalls/mount.S b/libc/arch-mips64/syscalls/mount.S
index 595585e..71e08a7 100644
--- a/libc/arch-mips64/syscalls/mount.S
+++ b/libc/arch-mips64/syscalls/mount.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl mount
-    .align 4
-    .ent mount
+#include <private/bionic_asm.h>
 
-mount:
+ENTRY(mount)
     .set push
     .set noreorder
     li v0, __NR_mount
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end mount
+END(mount)
diff --git a/libc/arch-mips64/syscalls/mprotect.S b/libc/arch-mips64/syscalls/mprotect.S
index 77d9207..66ffa1a 100644
--- a/libc/arch-mips64/syscalls/mprotect.S
+++ b/libc/arch-mips64/syscalls/mprotect.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl mprotect
-    .align 4
-    .ent mprotect
+#include <private/bionic_asm.h>
 
-mprotect:
+ENTRY(mprotect)
     .set push
     .set noreorder
     li v0, __NR_mprotect
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end mprotect
+END(mprotect)
diff --git a/libc/arch-mips64/syscalls/mremap.S b/libc/arch-mips64/syscalls/mremap.S
index 33be57f..c73320f 100644
--- a/libc/arch-mips64/syscalls/mremap.S
+++ b/libc/arch-mips64/syscalls/mremap.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl mremap
-    .align 4
-    .ent mremap
+#include <private/bionic_asm.h>
 
-mremap:
+ENTRY(mremap)
     .set push
     .set noreorder
     li v0, __NR_mremap
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end mremap
+END(mremap)
diff --git a/libc/arch-mips64/syscalls/msync.S b/libc/arch-mips64/syscalls/msync.S
index a5e29f6..a97cba8 100644
--- a/libc/arch-mips64/syscalls/msync.S
+++ b/libc/arch-mips64/syscalls/msync.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl msync
-    .align 4
-    .ent msync
+#include <private/bionic_asm.h>
 
-msync:
+ENTRY(msync)
     .set push
     .set noreorder
     li v0, __NR_msync
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end msync
+END(msync)
diff --git a/libc/arch-mips64/syscalls/munlock.S b/libc/arch-mips64/syscalls/munlock.S
index 4d9000a..f5919ae 100644
--- a/libc/arch-mips64/syscalls/munlock.S
+++ b/libc/arch-mips64/syscalls/munlock.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl munlock
-    .align 4
-    .ent munlock
+#include <private/bionic_asm.h>
 
-munlock:
+ENTRY(munlock)
     .set push
     .set noreorder
     li v0, __NR_munlock
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end munlock
+END(munlock)
diff --git a/libc/arch-mips64/syscalls/munlockall.S b/libc/arch-mips64/syscalls/munlockall.S
index f8a1ff4..39e717c 100644
--- a/libc/arch-mips64/syscalls/munlockall.S
+++ b/libc/arch-mips64/syscalls/munlockall.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl munlockall
-    .align 4
-    .ent munlockall
+#include <private/bionic_asm.h>
 
-munlockall:
+ENTRY(munlockall)
     .set push
     .set noreorder
     li v0, __NR_munlockall
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end munlockall
+END(munlockall)
diff --git a/libc/arch-mips64/syscalls/munmap.S b/libc/arch-mips64/syscalls/munmap.S
index a7e65a7..c1c9b01 100644
--- a/libc/arch-mips64/syscalls/munmap.S
+++ b/libc/arch-mips64/syscalls/munmap.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl munmap
-    .align 4
-    .ent munmap
+#include <private/bionic_asm.h>
 
-munmap:
+ENTRY(munmap)
     .set push
     .set noreorder
     li v0, __NR_munmap
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end munmap
+END(munmap)
diff --git a/libc/arch-mips64/syscalls/nanosleep.S b/libc/arch-mips64/syscalls/nanosleep.S
index a3838de..6bfd73e 100644
--- a/libc/arch-mips64/syscalls/nanosleep.S
+++ b/libc/arch-mips64/syscalls/nanosleep.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl nanosleep
-    .align 4
-    .ent nanosleep
+#include <private/bionic_asm.h>
 
-nanosleep:
+ENTRY(nanosleep)
     .set push
     .set noreorder
     li v0, __NR_nanosleep
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end nanosleep
+END(nanosleep)
diff --git a/libc/arch-mips64/syscalls/perf_event_open.S b/libc/arch-mips64/syscalls/perf_event_open.S
index 14465fb..d796a16 100644
--- a/libc/arch-mips64/syscalls/perf_event_open.S
+++ b/libc/arch-mips64/syscalls/perf_event_open.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl perf_event_open
-    .align 4
-    .ent perf_event_open
+#include <private/bionic_asm.h>
 
-perf_event_open:
+ENTRY(perf_event_open)
     .set push
     .set noreorder
     li v0, __NR_perf_event_open
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end perf_event_open
+END(perf_event_open)
diff --git a/libc/arch-mips64/syscalls/personality.S b/libc/arch-mips64/syscalls/personality.S
index af39ee6..e234636 100644
--- a/libc/arch-mips64/syscalls/personality.S
+++ b/libc/arch-mips64/syscalls/personality.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl personality
-    .align 4
-    .ent personality
+#include <private/bionic_asm.h>
 
-personality:
+ENTRY(personality)
     .set push
     .set noreorder
     li v0, __NR_personality
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end personality
+END(personality)
diff --git a/libc/arch-mips64/syscalls/pipe2.S b/libc/arch-mips64/syscalls/pipe2.S
index 4e06258..52d5baa 100644
--- a/libc/arch-mips64/syscalls/pipe2.S
+++ b/libc/arch-mips64/syscalls/pipe2.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl pipe2
-    .align 4
-    .ent pipe2
+#include <private/bionic_asm.h>
 
-pipe2:
+ENTRY(pipe2)
     .set push
     .set noreorder
     li v0, __NR_pipe2
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end pipe2
+END(pipe2)
diff --git a/libc/arch-mips64/syscalls/prctl.S b/libc/arch-mips64/syscalls/prctl.S
index 122a28e..01d422e 100644
--- a/libc/arch-mips64/syscalls/prctl.S
+++ b/libc/arch-mips64/syscalls/prctl.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl prctl
-    .align 4
-    .ent prctl
+#include <private/bionic_asm.h>
 
-prctl:
+ENTRY(prctl)
     .set push
     .set noreorder
     li v0, __NR_prctl
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end prctl
+END(prctl)
diff --git a/libc/arch-mips64/syscalls/pread64.S b/libc/arch-mips64/syscalls/pread64.S
index a97a1d4..5ab8389 100644
--- a/libc/arch-mips64/syscalls/pread64.S
+++ b/libc/arch-mips64/syscalls/pread64.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl pread64
-    .align 4
-    .ent pread64
+#include <private/bionic_asm.h>
 
-pread64:
+ENTRY(pread64)
     .set push
     .set noreorder
     li v0, __NR_pread64
@@ -28,7 +22,7 @@
     j t9
     move ra, t0
     .set pop
-    .end pread64
+END(pread64)
 
     .globl pread
     .equ pread, pread64
diff --git a/libc/arch-mips64/syscalls/prlimit64.S b/libc/arch-mips64/syscalls/prlimit64.S
index e611bd0..e52ca92 100644
--- a/libc/arch-mips64/syscalls/prlimit64.S
+++ b/libc/arch-mips64/syscalls/prlimit64.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl prlimit64
-    .align 4
-    .ent prlimit64
+#include <private/bionic_asm.h>
 
-prlimit64:
+ENTRY(prlimit64)
     .set push
     .set noreorder
     li v0, __NR_prlimit64
@@ -28,7 +22,7 @@
     j t9
     move ra, t0
     .set pop
-    .end prlimit64
+END(prlimit64)
 
     .globl prlimit
     .equ prlimit, prlimit64
diff --git a/libc/arch-mips64/syscalls/pwrite64.S b/libc/arch-mips64/syscalls/pwrite64.S
index 08af91b..8d7a8b5 100644
--- a/libc/arch-mips64/syscalls/pwrite64.S
+++ b/libc/arch-mips64/syscalls/pwrite64.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl pwrite64
-    .align 4
-    .ent pwrite64
+#include <private/bionic_asm.h>
 
-pwrite64:
+ENTRY(pwrite64)
     .set push
     .set noreorder
     li v0, __NR_pwrite64
@@ -28,7 +22,7 @@
     j t9
     move ra, t0
     .set pop
-    .end pwrite64
+END(pwrite64)
 
     .globl pwrite
     .equ pwrite, pwrite64
diff --git a/libc/arch-mips64/syscalls/read.S b/libc/arch-mips64/syscalls/read.S
index 4d8c51d..3f805ca 100644
--- a/libc/arch-mips64/syscalls/read.S
+++ b/libc/arch-mips64/syscalls/read.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl read
-    .align 4
-    .ent read
+#include <private/bionic_asm.h>
 
-read:
+ENTRY(read)
     .set push
     .set noreorder
     li v0, __NR_read
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end read
+END(read)
diff --git a/libc/arch-mips64/syscalls/readahead.S b/libc/arch-mips64/syscalls/readahead.S
index 5ab1dcb..8f5c8c6 100644
--- a/libc/arch-mips64/syscalls/readahead.S
+++ b/libc/arch-mips64/syscalls/readahead.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl readahead
-    .align 4
-    .ent readahead
+#include <private/bionic_asm.h>
 
-readahead:
+ENTRY(readahead)
     .set push
     .set noreorder
     li v0, __NR_readahead
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end readahead
+END(readahead)
diff --git a/libc/arch-mips64/syscalls/readlinkat.S b/libc/arch-mips64/syscalls/readlinkat.S
index 8e91dcf..1381c22 100644
--- a/libc/arch-mips64/syscalls/readlinkat.S
+++ b/libc/arch-mips64/syscalls/readlinkat.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl readlinkat
-    .align 4
-    .ent readlinkat
+#include <private/bionic_asm.h>
 
-readlinkat:
+ENTRY(readlinkat)
     .set push
     .set noreorder
     li v0, __NR_readlinkat
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end readlinkat
+END(readlinkat)
diff --git a/libc/arch-mips64/syscalls/readv.S b/libc/arch-mips64/syscalls/readv.S
index e248942..9c7afd5 100644
--- a/libc/arch-mips64/syscalls/readv.S
+++ b/libc/arch-mips64/syscalls/readv.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl readv
-    .align 4
-    .ent readv
+#include <private/bionic_asm.h>
 
-readv:
+ENTRY(readv)
     .set push
     .set noreorder
     li v0, __NR_readv
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end readv
+END(readv)
diff --git a/libc/arch-mips64/syscalls/recvfrom.S b/libc/arch-mips64/syscalls/recvfrom.S
index 818dc8e..d3911c6 100644
--- a/libc/arch-mips64/syscalls/recvfrom.S
+++ b/libc/arch-mips64/syscalls/recvfrom.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl recvfrom
-    .align 4
-    .ent recvfrom
+#include <private/bionic_asm.h>
 
-recvfrom:
+ENTRY(recvfrom)
     .set push
     .set noreorder
     li v0, __NR_recvfrom
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end recvfrom
+END(recvfrom)
diff --git a/libc/arch-mips64/syscalls/recvmsg.S b/libc/arch-mips64/syscalls/recvmsg.S
index 06d8826..21ec51d 100644
--- a/libc/arch-mips64/syscalls/recvmsg.S
+++ b/libc/arch-mips64/syscalls/recvmsg.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl recvmsg
-    .align 4
-    .ent recvmsg
+#include <private/bionic_asm.h>
 
-recvmsg:
+ENTRY(recvmsg)
     .set push
     .set noreorder
     li v0, __NR_recvmsg
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end recvmsg
+END(recvmsg)
diff --git a/libc/arch-mips64/syscalls/removexattr.S b/libc/arch-mips64/syscalls/removexattr.S
index 8b0d056..ea31771 100644
--- a/libc/arch-mips64/syscalls/removexattr.S
+++ b/libc/arch-mips64/syscalls/removexattr.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl removexattr
-    .align 4
-    .ent removexattr
+#include <private/bionic_asm.h>
 
-removexattr:
+ENTRY(removexattr)
     .set push
     .set noreorder
     li v0, __NR_removexattr
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end removexattr
+END(removexattr)
diff --git a/libc/arch-mips64/syscalls/renameat.S b/libc/arch-mips64/syscalls/renameat.S
index fdf24db..074a6a4 100644
--- a/libc/arch-mips64/syscalls/renameat.S
+++ b/libc/arch-mips64/syscalls/renameat.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl renameat
-    .align 4
-    .ent renameat
+#include <private/bionic_asm.h>
 
-renameat:
+ENTRY(renameat)
     .set push
     .set noreorder
     li v0, __NR_renameat
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end renameat
+END(renameat)
diff --git a/libc/arch-mips64/syscalls/sched_get_priority_max.S b/libc/arch-mips64/syscalls/sched_get_priority_max.S
index c84ab98..1b67bbf 100644
--- a/libc/arch-mips64/syscalls/sched_get_priority_max.S
+++ b/libc/arch-mips64/syscalls/sched_get_priority_max.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl sched_get_priority_max
-    .align 4
-    .ent sched_get_priority_max
+#include <private/bionic_asm.h>
 
-sched_get_priority_max:
+ENTRY(sched_get_priority_max)
     .set push
     .set noreorder
     li v0, __NR_sched_get_priority_max
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end sched_get_priority_max
+END(sched_get_priority_max)
diff --git a/libc/arch-mips64/syscalls/sched_get_priority_min.S b/libc/arch-mips64/syscalls/sched_get_priority_min.S
index d9ab4ec..2d68752 100644
--- a/libc/arch-mips64/syscalls/sched_get_priority_min.S
+++ b/libc/arch-mips64/syscalls/sched_get_priority_min.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl sched_get_priority_min
-    .align 4
-    .ent sched_get_priority_min
+#include <private/bionic_asm.h>
 
-sched_get_priority_min:
+ENTRY(sched_get_priority_min)
     .set push
     .set noreorder
     li v0, __NR_sched_get_priority_min
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end sched_get_priority_min
+END(sched_get_priority_min)
diff --git a/libc/arch-mips64/syscalls/sched_getparam.S b/libc/arch-mips64/syscalls/sched_getparam.S
index 9f40fe4..d0b2069 100644
--- a/libc/arch-mips64/syscalls/sched_getparam.S
+++ b/libc/arch-mips64/syscalls/sched_getparam.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl sched_getparam
-    .align 4
-    .ent sched_getparam
+#include <private/bionic_asm.h>
 
-sched_getparam:
+ENTRY(sched_getparam)
     .set push
     .set noreorder
     li v0, __NR_sched_getparam
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end sched_getparam
+END(sched_getparam)
diff --git a/libc/arch-mips64/syscalls/sched_getscheduler.S b/libc/arch-mips64/syscalls/sched_getscheduler.S
index e263f61..f25bde5 100644
--- a/libc/arch-mips64/syscalls/sched_getscheduler.S
+++ b/libc/arch-mips64/syscalls/sched_getscheduler.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl sched_getscheduler
-    .align 4
-    .ent sched_getscheduler
+#include <private/bionic_asm.h>
 
-sched_getscheduler:
+ENTRY(sched_getscheduler)
     .set push
     .set noreorder
     li v0, __NR_sched_getscheduler
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end sched_getscheduler
+END(sched_getscheduler)
diff --git a/libc/arch-mips64/syscalls/sched_rr_get_interval.S b/libc/arch-mips64/syscalls/sched_rr_get_interval.S
index a3bba28..48233f8 100644
--- a/libc/arch-mips64/syscalls/sched_rr_get_interval.S
+++ b/libc/arch-mips64/syscalls/sched_rr_get_interval.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl sched_rr_get_interval
-    .align 4
-    .ent sched_rr_get_interval
+#include <private/bionic_asm.h>
 
-sched_rr_get_interval:
+ENTRY(sched_rr_get_interval)
     .set push
     .set noreorder
     li v0, __NR_sched_rr_get_interval
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end sched_rr_get_interval
+END(sched_rr_get_interval)
diff --git a/libc/arch-mips64/syscalls/sched_setaffinity.S b/libc/arch-mips64/syscalls/sched_setaffinity.S
index 35bfb30..e604863 100644
--- a/libc/arch-mips64/syscalls/sched_setaffinity.S
+++ b/libc/arch-mips64/syscalls/sched_setaffinity.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl sched_setaffinity
-    .align 4
-    .ent sched_setaffinity
+#include <private/bionic_asm.h>
 
-sched_setaffinity:
+ENTRY(sched_setaffinity)
     .set push
     .set noreorder
     li v0, __NR_sched_setaffinity
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end sched_setaffinity
+END(sched_setaffinity)
diff --git a/libc/arch-mips64/syscalls/sched_setparam.S b/libc/arch-mips64/syscalls/sched_setparam.S
index 714fcc9..b02439f 100644
--- a/libc/arch-mips64/syscalls/sched_setparam.S
+++ b/libc/arch-mips64/syscalls/sched_setparam.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl sched_setparam
-    .align 4
-    .ent sched_setparam
+#include <private/bionic_asm.h>
 
-sched_setparam:
+ENTRY(sched_setparam)
     .set push
     .set noreorder
     li v0, __NR_sched_setparam
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end sched_setparam
+END(sched_setparam)
diff --git a/libc/arch-mips64/syscalls/sched_setscheduler.S b/libc/arch-mips64/syscalls/sched_setscheduler.S
index 4fe5783..dda1ce5 100644
--- a/libc/arch-mips64/syscalls/sched_setscheduler.S
+++ b/libc/arch-mips64/syscalls/sched_setscheduler.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl sched_setscheduler
-    .align 4
-    .ent sched_setscheduler
+#include <private/bionic_asm.h>
 
-sched_setscheduler:
+ENTRY(sched_setscheduler)
     .set push
     .set noreorder
     li v0, __NR_sched_setscheduler
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end sched_setscheduler
+END(sched_setscheduler)
diff --git a/libc/arch-mips64/syscalls/sched_yield.S b/libc/arch-mips64/syscalls/sched_yield.S
index b2542a3..509b029 100644
--- a/libc/arch-mips64/syscalls/sched_yield.S
+++ b/libc/arch-mips64/syscalls/sched_yield.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl sched_yield
-    .align 4
-    .ent sched_yield
+#include <private/bionic_asm.h>
 
-sched_yield:
+ENTRY(sched_yield)
     .set push
     .set noreorder
     li v0, __NR_sched_yield
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end sched_yield
+END(sched_yield)
diff --git a/libc/arch-mips64/syscalls/sendfile.S b/libc/arch-mips64/syscalls/sendfile.S
index bce8d58..684a83a 100644
--- a/libc/arch-mips64/syscalls/sendfile.S
+++ b/libc/arch-mips64/syscalls/sendfile.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl sendfile
-    .align 4
-    .ent sendfile
+#include <private/bionic_asm.h>
 
-sendfile:
+ENTRY(sendfile)
     .set push
     .set noreorder
     li v0, __NR_sendfile
@@ -28,7 +22,7 @@
     j t9
     move ra, t0
     .set pop
-    .end sendfile
+END(sendfile)
 
     .globl sendfile64
     .equ sendfile64, sendfile
diff --git a/libc/arch-mips64/syscalls/sendmsg.S b/libc/arch-mips64/syscalls/sendmsg.S
index 72227f7..6983f9a 100644
--- a/libc/arch-mips64/syscalls/sendmsg.S
+++ b/libc/arch-mips64/syscalls/sendmsg.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl sendmsg
-    .align 4
-    .ent sendmsg
+#include <private/bionic_asm.h>
 
-sendmsg:
+ENTRY(sendmsg)
     .set push
     .set noreorder
     li v0, __NR_sendmsg
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end sendmsg
+END(sendmsg)
diff --git a/libc/arch-mips64/syscalls/sendto.S b/libc/arch-mips64/syscalls/sendto.S
index dbb4c56..cfe774d 100644
--- a/libc/arch-mips64/syscalls/sendto.S
+++ b/libc/arch-mips64/syscalls/sendto.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl sendto
-    .align 4
-    .ent sendto
+#include <private/bionic_asm.h>
 
-sendto:
+ENTRY(sendto)
     .set push
     .set noreorder
     li v0, __NR_sendto
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end sendto
+END(sendto)
diff --git a/libc/arch-mips64/syscalls/setgid.S b/libc/arch-mips64/syscalls/setgid.S
index 3d9b5d4..cc8d3ab 100644
--- a/libc/arch-mips64/syscalls/setgid.S
+++ b/libc/arch-mips64/syscalls/setgid.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl setgid
-    .align 4
-    .ent setgid
+#include <private/bionic_asm.h>
 
-setgid:
+ENTRY(setgid)
     .set push
     .set noreorder
     li v0, __NR_setgid
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end setgid
+END(setgid)
diff --git a/libc/arch-mips64/syscalls/setgroups.S b/libc/arch-mips64/syscalls/setgroups.S
index c4dc713..63f2329 100644
--- a/libc/arch-mips64/syscalls/setgroups.S
+++ b/libc/arch-mips64/syscalls/setgroups.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl setgroups
-    .align 4
-    .ent setgroups
+#include <private/bionic_asm.h>
 
-setgroups:
+ENTRY(setgroups)
     .set push
     .set noreorder
     li v0, __NR_setgroups
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end setgroups
+END(setgroups)
diff --git a/libc/arch-mips64/syscalls/setitimer.S b/libc/arch-mips64/syscalls/setitimer.S
index b1969d0..9ee02dc 100644
--- a/libc/arch-mips64/syscalls/setitimer.S
+++ b/libc/arch-mips64/syscalls/setitimer.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl setitimer
-    .align 4
-    .ent setitimer
+#include <private/bionic_asm.h>
 
-setitimer:
+ENTRY(setitimer)
     .set push
     .set noreorder
     li v0, __NR_setitimer
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end setitimer
+END(setitimer)
diff --git a/libc/arch-mips64/syscalls/setns.S b/libc/arch-mips64/syscalls/setns.S
index 3073aad..191a1a0 100644
--- a/libc/arch-mips64/syscalls/setns.S
+++ b/libc/arch-mips64/syscalls/setns.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl setns
-    .align 4
-    .ent setns
+#include <private/bionic_asm.h>
 
-setns:
+ENTRY(setns)
     .set push
     .set noreorder
     li v0, __NR_setns
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end setns
+END(setns)
diff --git a/libc/arch-mips64/syscalls/setpgid.S b/libc/arch-mips64/syscalls/setpgid.S
index 171ed17..8972160 100644
--- a/libc/arch-mips64/syscalls/setpgid.S
+++ b/libc/arch-mips64/syscalls/setpgid.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl setpgid
-    .align 4
-    .ent setpgid
+#include <private/bionic_asm.h>
 
-setpgid:
+ENTRY(setpgid)
     .set push
     .set noreorder
     li v0, __NR_setpgid
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end setpgid
+END(setpgid)
diff --git a/libc/arch-mips64/syscalls/setpriority.S b/libc/arch-mips64/syscalls/setpriority.S
index a73c155..dce3a76 100644
--- a/libc/arch-mips64/syscalls/setpriority.S
+++ b/libc/arch-mips64/syscalls/setpriority.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl setpriority
-    .align 4
-    .ent setpriority
+#include <private/bionic_asm.h>
 
-setpriority:
+ENTRY(setpriority)
     .set push
     .set noreorder
     li v0, __NR_setpriority
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end setpriority
+END(setpriority)
diff --git a/libc/arch-mips64/syscalls/setregid.S b/libc/arch-mips64/syscalls/setregid.S
index 14217ba..d677b32 100644
--- a/libc/arch-mips64/syscalls/setregid.S
+++ b/libc/arch-mips64/syscalls/setregid.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl setregid
-    .align 4
-    .ent setregid
+#include <private/bionic_asm.h>
 
-setregid:
+ENTRY(setregid)
     .set push
     .set noreorder
     li v0, __NR_setregid
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end setregid
+END(setregid)
diff --git a/libc/arch-mips64/syscalls/setresgid.S b/libc/arch-mips64/syscalls/setresgid.S
index 9e35dde..312eb3a 100644
--- a/libc/arch-mips64/syscalls/setresgid.S
+++ b/libc/arch-mips64/syscalls/setresgid.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl setresgid
-    .align 4
-    .ent setresgid
+#include <private/bionic_asm.h>
 
-setresgid:
+ENTRY(setresgid)
     .set push
     .set noreorder
     li v0, __NR_setresgid
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end setresgid
+END(setresgid)
diff --git a/libc/arch-mips64/syscalls/setresuid.S b/libc/arch-mips64/syscalls/setresuid.S
index fdd28a9..4da79d0 100644
--- a/libc/arch-mips64/syscalls/setresuid.S
+++ b/libc/arch-mips64/syscalls/setresuid.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl setresuid
-    .align 4
-    .ent setresuid
+#include <private/bionic_asm.h>
 
-setresuid:
+ENTRY(setresuid)
     .set push
     .set noreorder
     li v0, __NR_setresuid
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end setresuid
+END(setresuid)
diff --git a/libc/arch-mips64/syscalls/setreuid.S b/libc/arch-mips64/syscalls/setreuid.S
index db50c6c..33f6fce 100644
--- a/libc/arch-mips64/syscalls/setreuid.S
+++ b/libc/arch-mips64/syscalls/setreuid.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl setreuid
-    .align 4
-    .ent setreuid
+#include <private/bionic_asm.h>
 
-setreuid:
+ENTRY(setreuid)
     .set push
     .set noreorder
     li v0, __NR_setreuid
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end setreuid
+END(setreuid)
diff --git a/libc/arch-mips64/syscalls/setrlimit.S b/libc/arch-mips64/syscalls/setrlimit.S
index 9ed0024..3060298 100644
--- a/libc/arch-mips64/syscalls/setrlimit.S
+++ b/libc/arch-mips64/syscalls/setrlimit.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl setrlimit
-    .align 4
-    .ent setrlimit
+#include <private/bionic_asm.h>
 
-setrlimit:
+ENTRY(setrlimit)
     .set push
     .set noreorder
     li v0, __NR_setrlimit
@@ -28,7 +22,7 @@
     j t9
     move ra, t0
     .set pop
-    .end setrlimit
+END(setrlimit)
 
     .globl setrlimit64
     .equ setrlimit64, setrlimit
diff --git a/libc/arch-mips64/syscalls/setsid.S b/libc/arch-mips64/syscalls/setsid.S
index b1b340f..c8d1ad5 100644
--- a/libc/arch-mips64/syscalls/setsid.S
+++ b/libc/arch-mips64/syscalls/setsid.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl setsid
-    .align 4
-    .ent setsid
+#include <private/bionic_asm.h>
 
-setsid:
+ENTRY(setsid)
     .set push
     .set noreorder
     li v0, __NR_setsid
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end setsid
+END(setsid)
diff --git a/libc/arch-mips64/syscalls/setsockopt.S b/libc/arch-mips64/syscalls/setsockopt.S
index 55cce5f..b40aad1 100644
--- a/libc/arch-mips64/syscalls/setsockopt.S
+++ b/libc/arch-mips64/syscalls/setsockopt.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl setsockopt
-    .align 4
-    .ent setsockopt
+#include <private/bionic_asm.h>
 
-setsockopt:
+ENTRY(setsockopt)
     .set push
     .set noreorder
     li v0, __NR_setsockopt
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end setsockopt
+END(setsockopt)
diff --git a/libc/arch-mips64/syscalls/settimeofday.S b/libc/arch-mips64/syscalls/settimeofday.S
index 72802e2..2e333f8 100644
--- a/libc/arch-mips64/syscalls/settimeofday.S
+++ b/libc/arch-mips64/syscalls/settimeofday.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl settimeofday
-    .align 4
-    .ent settimeofday
+#include <private/bionic_asm.h>
 
-settimeofday:
+ENTRY(settimeofday)
     .set push
     .set noreorder
     li v0, __NR_settimeofday
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end settimeofday
+END(settimeofday)
diff --git a/libc/arch-mips64/syscalls/setuid.S b/libc/arch-mips64/syscalls/setuid.S
index d8edd22..fb8125e 100644
--- a/libc/arch-mips64/syscalls/setuid.S
+++ b/libc/arch-mips64/syscalls/setuid.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl setuid
-    .align 4
-    .ent setuid
+#include <private/bionic_asm.h>
 
-setuid:
+ENTRY(setuid)
     .set push
     .set noreorder
     li v0, __NR_setuid
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end setuid
+END(setuid)
diff --git a/libc/arch-mips64/syscalls/setxattr.S b/libc/arch-mips64/syscalls/setxattr.S
index 9ccc378..04e746d 100644
--- a/libc/arch-mips64/syscalls/setxattr.S
+++ b/libc/arch-mips64/syscalls/setxattr.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl setxattr
-    .align 4
-    .ent setxattr
+#include <private/bionic_asm.h>
 
-setxattr:
+ENTRY(setxattr)
     .set push
     .set noreorder
     li v0, __NR_setxattr
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end setxattr
+END(setxattr)
diff --git a/libc/arch-mips64/syscalls/shutdown.S b/libc/arch-mips64/syscalls/shutdown.S
index 335ed41..59f437a 100644
--- a/libc/arch-mips64/syscalls/shutdown.S
+++ b/libc/arch-mips64/syscalls/shutdown.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl shutdown
-    .align 4
-    .ent shutdown
+#include <private/bionic_asm.h>
 
-shutdown:
+ENTRY(shutdown)
     .set push
     .set noreorder
     li v0, __NR_shutdown
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end shutdown
+END(shutdown)
diff --git a/libc/arch-mips64/syscalls/sigaltstack.S b/libc/arch-mips64/syscalls/sigaltstack.S
index 3458b11..0fbd3a1 100644
--- a/libc/arch-mips64/syscalls/sigaltstack.S
+++ b/libc/arch-mips64/syscalls/sigaltstack.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl sigaltstack
-    .align 4
-    .ent sigaltstack
+#include <private/bionic_asm.h>
 
-sigaltstack:
+ENTRY(sigaltstack)
     .set push
     .set noreorder
     li v0, __NR_sigaltstack
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end sigaltstack
+END(sigaltstack)
diff --git a/libc/arch-mips64/syscalls/signalfd4.S b/libc/arch-mips64/syscalls/signalfd4.S
index ef1d1e5..594c73d 100644
--- a/libc/arch-mips64/syscalls/signalfd4.S
+++ b/libc/arch-mips64/syscalls/signalfd4.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl signalfd4
-    .align 4
-    .ent signalfd4
+#include <private/bionic_asm.h>
 
-signalfd4:
+ENTRY(signalfd4)
     .set push
     .set noreorder
     li v0, __NR_signalfd4
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end signalfd4
+END(signalfd4)
diff --git a/libc/arch-mips64/syscalls/socket.S b/libc/arch-mips64/syscalls/socket.S
index 6b042c2..2020e2e 100644
--- a/libc/arch-mips64/syscalls/socket.S
+++ b/libc/arch-mips64/syscalls/socket.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl socket
-    .align 4
-    .ent socket
+#include <private/bionic_asm.h>
 
-socket:
+ENTRY(socket)
     .set push
     .set noreorder
     li v0, __NR_socket
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end socket
+END(socket)
diff --git a/libc/arch-mips64/syscalls/socketpair.S b/libc/arch-mips64/syscalls/socketpair.S
index b4ca8f4..fa684d1 100644
--- a/libc/arch-mips64/syscalls/socketpair.S
+++ b/libc/arch-mips64/syscalls/socketpair.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl socketpair
-    .align 4
-    .ent socketpair
+#include <private/bionic_asm.h>
 
-socketpair:
+ENTRY(socketpair)
     .set push
     .set noreorder
     li v0, __NR_socketpair
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end socketpair
+END(socketpair)
diff --git a/libc/arch-mips64/syscalls/statfs64.S b/libc/arch-mips64/syscalls/statfs64.S
index accd715..e835e41 100644
--- a/libc/arch-mips64/syscalls/statfs64.S
+++ b/libc/arch-mips64/syscalls/statfs64.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl statfs64
-    .align 4
-    .ent statfs64
+#include <private/bionic_asm.h>
 
-statfs64:
+ENTRY(statfs64)
     .set push
     .set noreorder
     li v0, __NR_statfs
@@ -28,7 +22,7 @@
     j t9
     move ra, t0
     .set pop
-    .end statfs64
+END(statfs64)
 
     .globl statfs
     .equ statfs, statfs64
diff --git a/libc/arch-mips64/syscalls/swapoff.S b/libc/arch-mips64/syscalls/swapoff.S
index 8041188..dfaf185 100644
--- a/libc/arch-mips64/syscalls/swapoff.S
+++ b/libc/arch-mips64/syscalls/swapoff.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl swapoff
-    .align 4
-    .ent swapoff
+#include <private/bionic_asm.h>
 
-swapoff:
+ENTRY(swapoff)
     .set push
     .set noreorder
     li v0, __NR_swapoff
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end swapoff
+END(swapoff)
diff --git a/libc/arch-mips64/syscalls/swapon.S b/libc/arch-mips64/syscalls/swapon.S
index 5c24d7c..8e844c4 100644
--- a/libc/arch-mips64/syscalls/swapon.S
+++ b/libc/arch-mips64/syscalls/swapon.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl swapon
-    .align 4
-    .ent swapon
+#include <private/bionic_asm.h>
 
-swapon:
+ENTRY(swapon)
     .set push
     .set noreorder
     li v0, __NR_swapon
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end swapon
+END(swapon)
diff --git a/libc/arch-mips64/syscalls/symlinkat.S b/libc/arch-mips64/syscalls/symlinkat.S
index ce86d86..e43d597 100644
--- a/libc/arch-mips64/syscalls/symlinkat.S
+++ b/libc/arch-mips64/syscalls/symlinkat.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl symlinkat
-    .align 4
-    .ent symlinkat
+#include <private/bionic_asm.h>
 
-symlinkat:
+ENTRY(symlinkat)
     .set push
     .set noreorder
     li v0, __NR_symlinkat
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end symlinkat
+END(symlinkat)
diff --git a/libc/arch-mips64/syscalls/sync.S b/libc/arch-mips64/syscalls/sync.S
index e0787bd..ec342a3 100644
--- a/libc/arch-mips64/syscalls/sync.S
+++ b/libc/arch-mips64/syscalls/sync.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl sync
-    .align 4
-    .ent sync
+#include <private/bionic_asm.h>
 
-sync:
+ENTRY(sync)
     .set push
     .set noreorder
     li v0, __NR_sync
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end sync
+END(sync)
diff --git a/libc/arch-mips64/syscalls/sysinfo.S b/libc/arch-mips64/syscalls/sysinfo.S
index 19ad141..16486fd 100644
--- a/libc/arch-mips64/syscalls/sysinfo.S
+++ b/libc/arch-mips64/syscalls/sysinfo.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl sysinfo
-    .align 4
-    .ent sysinfo
+#include <private/bionic_asm.h>
 
-sysinfo:
+ENTRY(sysinfo)
     .set push
     .set noreorder
     li v0, __NR_sysinfo
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end sysinfo
+END(sysinfo)
diff --git a/libc/arch-mips64/syscalls/tgkill.S b/libc/arch-mips64/syscalls/tgkill.S
index 1a8fe79..d98d9ae 100644
--- a/libc/arch-mips64/syscalls/tgkill.S
+++ b/libc/arch-mips64/syscalls/tgkill.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl tgkill
-    .align 4
-    .ent tgkill
+#include <private/bionic_asm.h>
 
-tgkill:
+ENTRY(tgkill)
     .set push
     .set noreorder
     li v0, __NR_tgkill
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end tgkill
+END(tgkill)
diff --git a/libc/arch-mips64/syscalls/timerfd_create.S b/libc/arch-mips64/syscalls/timerfd_create.S
index 63e8b00..ab8e9e0 100644
--- a/libc/arch-mips64/syscalls/timerfd_create.S
+++ b/libc/arch-mips64/syscalls/timerfd_create.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl timerfd_create
-    .align 4
-    .ent timerfd_create
+#include <private/bionic_asm.h>
 
-timerfd_create:
+ENTRY(timerfd_create)
     .set push
     .set noreorder
     li v0, __NR_timerfd_create
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end timerfd_create
+END(timerfd_create)
diff --git a/libc/arch-mips64/syscalls/timerfd_gettime.S b/libc/arch-mips64/syscalls/timerfd_gettime.S
index 2afe6f1..2ec7b9c 100644
--- a/libc/arch-mips64/syscalls/timerfd_gettime.S
+++ b/libc/arch-mips64/syscalls/timerfd_gettime.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl timerfd_gettime
-    .align 4
-    .ent timerfd_gettime
+#include <private/bionic_asm.h>
 
-timerfd_gettime:
+ENTRY(timerfd_gettime)
     .set push
     .set noreorder
     li v0, __NR_timerfd_gettime
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end timerfd_gettime
+END(timerfd_gettime)
diff --git a/libc/arch-mips64/syscalls/timerfd_settime.S b/libc/arch-mips64/syscalls/timerfd_settime.S
index 40ce07d..0aec09f 100644
--- a/libc/arch-mips64/syscalls/timerfd_settime.S
+++ b/libc/arch-mips64/syscalls/timerfd_settime.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl timerfd_settime
-    .align 4
-    .ent timerfd_settime
+#include <private/bionic_asm.h>
 
-timerfd_settime:
+ENTRY(timerfd_settime)
     .set push
     .set noreorder
     li v0, __NR_timerfd_settime
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end timerfd_settime
+END(timerfd_settime)
diff --git a/libc/arch-mips64/syscalls/times.S b/libc/arch-mips64/syscalls/times.S
index ccbdbf4..2457e0c 100644
--- a/libc/arch-mips64/syscalls/times.S
+++ b/libc/arch-mips64/syscalls/times.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl times
-    .align 4
-    .ent times
+#include <private/bionic_asm.h>
 
-times:
+ENTRY(times)
     .set push
     .set noreorder
     li v0, __NR_times
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end times
+END(times)
diff --git a/libc/arch-mips64/syscalls/tkill.S b/libc/arch-mips64/syscalls/tkill.S
index 8caa695..14d6903 100644
--- a/libc/arch-mips64/syscalls/tkill.S
+++ b/libc/arch-mips64/syscalls/tkill.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl tkill
-    .align 4
-    .ent tkill
+#include <private/bionic_asm.h>
 
-tkill:
+ENTRY(tkill)
     .set push
     .set noreorder
     li v0, __NR_tkill
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end tkill
+END(tkill)
diff --git a/libc/arch-mips64/syscalls/truncate.S b/libc/arch-mips64/syscalls/truncate.S
index a79cdcd..a0cbe51 100644
--- a/libc/arch-mips64/syscalls/truncate.S
+++ b/libc/arch-mips64/syscalls/truncate.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl truncate
-    .align 4
-    .ent truncate
+#include <private/bionic_asm.h>
 
-truncate:
+ENTRY(truncate)
     .set push
     .set noreorder
     li v0, __NR_truncate
@@ -28,7 +22,7 @@
     j t9
     move ra, t0
     .set pop
-    .end truncate
+END(truncate)
 
     .globl truncate64
     .equ truncate64, truncate
diff --git a/libc/arch-mips64/syscalls/umask.S b/libc/arch-mips64/syscalls/umask.S
index 168ff9c..33624d2 100644
--- a/libc/arch-mips64/syscalls/umask.S
+++ b/libc/arch-mips64/syscalls/umask.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl umask
-    .align 4
-    .ent umask
+#include <private/bionic_asm.h>
 
-umask:
+ENTRY(umask)
     .set push
     .set noreorder
     li v0, __NR_umask
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end umask
+END(umask)
diff --git a/libc/arch-mips64/syscalls/umount2.S b/libc/arch-mips64/syscalls/umount2.S
index db80fa8..6193459 100644
--- a/libc/arch-mips64/syscalls/umount2.S
+++ b/libc/arch-mips64/syscalls/umount2.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl umount2
-    .align 4
-    .ent umount2
+#include <private/bionic_asm.h>
 
-umount2:
+ENTRY(umount2)
     .set push
     .set noreorder
     li v0, __NR_umount2
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end umount2
+END(umount2)
diff --git a/libc/arch-mips64/syscalls/uname.S b/libc/arch-mips64/syscalls/uname.S
index 417ecb0..df50f45 100644
--- a/libc/arch-mips64/syscalls/uname.S
+++ b/libc/arch-mips64/syscalls/uname.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl uname
-    .align 4
-    .ent uname
+#include <private/bionic_asm.h>
 
-uname:
+ENTRY(uname)
     .set push
     .set noreorder
     li v0, __NR_uname
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end uname
+END(uname)
diff --git a/libc/arch-mips64/syscalls/unlinkat.S b/libc/arch-mips64/syscalls/unlinkat.S
index e533bc3..29d4442 100644
--- a/libc/arch-mips64/syscalls/unlinkat.S
+++ b/libc/arch-mips64/syscalls/unlinkat.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl unlinkat
-    .align 4
-    .ent unlinkat
+#include <private/bionic_asm.h>
 
-unlinkat:
+ENTRY(unlinkat)
     .set push
     .set noreorder
     li v0, __NR_unlinkat
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end unlinkat
+END(unlinkat)
diff --git a/libc/arch-mips64/syscalls/unshare.S b/libc/arch-mips64/syscalls/unshare.S
index 4a19745..6d8fbf3 100644
--- a/libc/arch-mips64/syscalls/unshare.S
+++ b/libc/arch-mips64/syscalls/unshare.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl unshare
-    .align 4
-    .ent unshare
+#include <private/bionic_asm.h>
 
-unshare:
+ENTRY(unshare)
     .set push
     .set noreorder
     li v0, __NR_unshare
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end unshare
+END(unshare)
diff --git a/libc/arch-mips64/syscalls/utimensat.S b/libc/arch-mips64/syscalls/utimensat.S
index 1cde60d..654b8a4 100644
--- a/libc/arch-mips64/syscalls/utimensat.S
+++ b/libc/arch-mips64/syscalls/utimensat.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl utimensat
-    .align 4
-    .ent utimensat
+#include <private/bionic_asm.h>
 
-utimensat:
+ENTRY(utimensat)
     .set push
     .set noreorder
     li v0, __NR_utimensat
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end utimensat
+END(utimensat)
diff --git a/libc/arch-mips64/syscalls/wait4.S b/libc/arch-mips64/syscalls/wait4.S
index 14abeeb..e3755b5 100644
--- a/libc/arch-mips64/syscalls/wait4.S
+++ b/libc/arch-mips64/syscalls/wait4.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl wait4
-    .align 4
-    .ent wait4
+#include <private/bionic_asm.h>
 
-wait4:
+ENTRY(wait4)
     .set push
     .set noreorder
     li v0, __NR_wait4
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end wait4
+END(wait4)
diff --git a/libc/arch-mips64/syscalls/write.S b/libc/arch-mips64/syscalls/write.S
index f58f25d..ce7f702 100644
--- a/libc/arch-mips64/syscalls/write.S
+++ b/libc/arch-mips64/syscalls/write.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl write
-    .align 4
-    .ent write
+#include <private/bionic_asm.h>
 
-write:
+ENTRY(write)
     .set push
     .set noreorder
     li v0, __NR_write
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end write
+END(write)
diff --git a/libc/arch-mips64/syscalls/writev.S b/libc/arch-mips64/syscalls/writev.S
index a716c78..e2c7875 100644
--- a/libc/arch-mips64/syscalls/writev.S
+++ b/libc/arch-mips64/syscalls/writev.S
@@ -1,14 +1,8 @@
 /* Generated by gensyscalls.py. Do not edit. */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl writev
-    .align 4
-    .ent writev
+#include <private/bionic_asm.h>
 
-writev:
+ENTRY(writev)
     .set push
     .set noreorder
     li v0, __NR_writev
@@ -28,4 +22,4 @@
     j t9
     move ra, t0
     .set pop
-    .end writev
+END(writev)
diff --git a/libc/arch-x86/bionic/__bionic_clone.S b/libc/arch-x86/bionic/__bionic_clone.S
index 3823ecc..e6ddaaa 100644
--- a/libc/arch-x86/bionic/__bionic_clone.S
+++ b/libc/arch-x86/bionic/__bionic_clone.S
@@ -1,5 +1,4 @@
-#include <asm/unistd.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 // pid_t __bionic_clone(int flags, void* child_stack, pid_t* parent_tid, void* tls, pid_t* child_tid, int (*fn)(void*), void* arg);
 ENTRY(__bionic_clone)
diff --git a/libc/arch-x86/bionic/__get_sp.S b/libc/arch-x86/bionic/__get_sp.S
index 0739d79..31ec6bc 100644
--- a/libc/arch-x86/bionic/__get_sp.S
+++ b/libc/arch-x86/bionic/__get_sp.S
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 ENTRY(__get_sp)
   mov  %esp, %eax
diff --git a/libc/arch-x86/bionic/_setjmp.S b/libc/arch-x86/bionic/_setjmp.S
index 9221138..0b256a2 100644
--- a/libc/arch-x86/bionic/_setjmp.S
+++ b/libc/arch-x86/bionic/_setjmp.S
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 /*
  * C library -- _setjmp, _longjmp
diff --git a/libc/arch-x86/bionic/setjmp.S b/libc/arch-x86/bionic/setjmp.S
index c0df647..5b94311 100644
--- a/libc/arch-x86/bionic/setjmp.S
+++ b/libc/arch-x86/bionic/setjmp.S
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 /*
  * C library -- setjmp, longjmp
@@ -47,9 +47,9 @@
 	PIC_PROLOGUE
 	pushl	$0
 #ifdef PIC
-	call	PIC_PLT(_C_LABEL(sigblock))
+	call	PIC_PLT(sigblock)
 #else
-	call	_C_LABEL(sigblock)
+	call	sigblock
 #endif
 	addl	$4,%esp
 	PIC_EPILOGUE
@@ -72,9 +72,9 @@
 	PIC_PROLOGUE
 	pushl	24(%edx)
 #ifdef PIC
-	call	PIC_PLT(_C_LABEL(sigsetmask))
+	call	PIC_PLT(sigsetmask)
 #else
-	call	_C_LABEL(sigsetmask)
+	call	sigsetmask
 #endif
 	addl	$4,%esp
 	PIC_EPILOGUE
diff --git a/libc/arch-x86/bionic/sigsetjmp.S b/libc/arch-x86/bionic/sigsetjmp.S
index 70cc6db..7ef732e 100644
--- a/libc/arch-x86/bionic/sigsetjmp.S
+++ b/libc/arch-x86/bionic/sigsetjmp.S
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 ENTRY(sigsetjmp)
 	movl	4(%esp),%ecx
@@ -43,9 +43,9 @@
 	PIC_PROLOGUE
 	pushl	$0
 #ifdef PIC
-	call	PIC_PLT(_C_LABEL(sigblock))
+	call	PIC_PLT(sigblock)
 #else
-	call	_C_LABEL(sigblock)
+	call	sigblock
 #endif
 	addl	$4,%esp
 	PIC_EPILOGUE
@@ -71,9 +71,9 @@
 	PIC_PROLOGUE
 	pushl	24(%edx)
 #ifdef PIC
-	call	PIC_PLT(_C_LABEL(sigsetmask))
+	call	PIC_PLT(sigsetmask)
 #else
-	call	_C_LABEL(sigsetmask)
+	call	sigsetmask
 #endif
 	addl	$4,%esp
 	PIC_EPILOGUE
diff --git a/libc/arch-x86/include/machine/asm.h b/libc/arch-x86/include/machine/asm.h
index 5ccf78f..913e6c8 100644
--- a/libc/arch-x86/include/machine/asm.h
+++ b/libc/arch-x86/include/machine/asm.h
@@ -37,10 +37,6 @@
 #ifndef _I386_ASM_H_
 #define _I386_ASM_H_
 
-#ifdef _KERNEL_OPT
-#include "opt_multiprocessor.h"
-#endif
-
 #ifdef PIC
 #define PIC_PROLOGUE	\
 	pushl	%ebx;	\
@@ -61,27 +57,6 @@
 #define PIC_GOTOFF(x)	x
 #endif
 
-#ifdef __ELF__
-# define _C_LABEL(x)	x
-#else
-# ifdef __STDC__
-#  define _C_LABEL(x)	_ ## x
-# else
-#  define _C_LABEL(x)	_/**/x
-# endif
-#endif
-#define	_ASM_LABEL(x)	x
-
-#define CVAROFF(x, y)		_C_LABEL(x) + y
-
-#ifdef __STDC__
-# define __CONCAT(x,y)	x ## y
-# define __STRING(x)	#x
-#else
-# define __CONCAT(x,y)	x/**/y
-# define __STRING(x)	"x"
-#endif
-
 /* let kernels and others override entrypoint alignment */
 #if !defined(_ALIGN_TEXT) && !defined(_KERNEL)
 # ifdef _STANDALONE
@@ -93,126 +68,4 @@
 # endif
 #endif
 
-#define _ENTRY(x) \
-	.text; _ALIGN_TEXT; .globl x; .type x,@function; x: .cfi_startproc;
-#define _LABEL(x) \
-	.globl x; x:
-
-#ifdef _KERNEL
-
-#define CPUVAR(off) %fs:__CONCAT(CPU_INFO_,off)
-
-/* XXX Can't use __CONCAT() here, as it would be evaluated incorrectly. */
-#ifdef __ELF__
-#ifdef __STDC__
-#define	IDTVEC(name) \
-	ALIGN_TEXT; .globl X ## name; .type X ## name,@function; X ## name:
-#define	IDTVEC_END(name) \
-	.size X ## name, . - X ## name
-#else 
-#define	IDTVEC(name) \
-	ALIGN_TEXT; .globl X/**/name; .type X/**/name,@function; X/**/name:
-#define	IDTVEC_END(name) \
-	.size X/**/name, . - X/**/name
-#endif /* __STDC__ */ 
-#else 
-#ifdef __STDC__
-#define	IDTVEC(name) \
-	ALIGN_TEXT; .globl _X ## name; .type _X ## name,@function; _X ## name: 
-#define	IDTVEC_END(name) \
-	.size _X ## name, . - _X ## name
-#else
-#define	IDTVEC(name) \
-	ALIGN_TEXT; .globl _X/**/name; .type _X/**/name,@function; _X/**/name:
-#define	IDTVEC_END(name) \
-	.size _X/**/name, . - _X/**/name
-#endif /* __STDC__ */
-#endif /* __ELF__ */
-
-#ifdef _STANDALONE
-#define ALIGN_DATA	.align	4
-#define ALIGN_TEXT	.align	4	/* 4-byte boundaries */
-#define SUPERALIGN_TEXT	.align	16	/* 15-byte boundaries */
-#elif defined __ELF__
-#define ALIGN_DATA	.align	4
-#define ALIGN_TEXT	.align	16	/* 16-byte boundaries */
-#define SUPERALIGN_TEXT	.align	16	/* 16-byte boundaries */
-#else
-#define ALIGN_DATA	.align	2
-#define ALIGN_TEXT	.align	4	/* 16-byte boundaries */
-#define SUPERALIGN_TEXT	.align	4	/* 16-byte boundaries */
-#endif /* __ELF__ */
-
-#define _ALIGN_TEXT ALIGN_TEXT
-
-#ifdef GPROF
-#ifdef __ELF__
-#define	MCOUNT_ASM	call	_C_LABEL(__mcount)
-#else /* __ELF__ */
-#define	MCOUNT_ASM	call	_C_LABEL(mcount)
-#endif /* __ELF__ */
-#else /* GPROF */
-#define	MCOUNT_ASM	/* nothing */
-#endif /* GPROF */
-
-#endif /* _KERNEL */
-
-
-
-#ifdef GPROF
-# ifdef __ELF__
-#  define _PROF_PROLOGUE	\
-	pushl %ebp; movl %esp,%ebp; call PIC_PLT(__mcount); popl %ebp
-# else 
-#  define _PROF_PROLOGUE	\
-	pushl %ebp; movl %esp,%ebp; call PIC_PLT(mcount); popl %ebp
-# endif
-#else
-# define _PROF_PROLOGUE
-#endif
-
-#define	ENTRY(y)	_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
-#define	NENTRY(y)	_ENTRY(_C_LABEL(y))
-#define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
-#define	LABEL(y)	_LABEL(_C_LABEL(y))
-#define	END(y)		.cfi_endproc; .size y, . - y
-
-#define	ASMSTR		.asciz
-
-#ifdef __ELF__
-#define RCSID(x)	.pushsection ".ident"; .asciz x; .popsection
-#else
-#define RCSID(x)	.text; .asciz x
-#endif
-
-#ifdef NO_KERNEL_RCSIDS
-#define	__KERNEL_RCSID(_n, _s)	/* nothing */
-#else
-#define	__KERNEL_RCSID(_n, _s)	RCSID(_s)
-#endif
-
-#ifdef __ELF__
-#define	WEAK_ALIAS(alias,sym)						\
-	.weak alias;							\
-	alias = sym
-#endif
-/*
- * STRONG_ALIAS: create a strong alias.
- */
-#define STRONG_ALIAS(alias,sym)						\
-	.globl alias;							\
-	alias = sym
-
-#ifdef __STDC__
-#define	WARN_REFERENCES(sym,msg)					\
-	.pushsection .gnu.warning. ## sym;				\
-	.ascii msg;							\
-	.popsection
-#else
-#define	WARN_REFERENCES(sym,msg)					\
-	.pushsection .gnu.warning./**/sym;				\
-	.ascii msg;							\
-	.popsection
-#endif /* __STDC__ */
-
 #endif /* !_I386_ASM_H_ */
diff --git a/libc/arch-x86/string/bcopy.S b/libc/arch-x86/string/bcopy.S
index 40df1d0..f425c58 100644
--- a/libc/arch-x86/string/bcopy.S
+++ b/libc/arch-x86/string/bcopy.S
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 	/*
 	 * (ov)bcopy (src,dst,cnt)
diff --git a/libc/arch-x86/string/memcmp.S b/libc/arch-x86/string/memcmp.S
index 3b50530..ef36b4f 100644
--- a/libc/arch-x86/string/memcmp.S
+++ b/libc/arch-x86/string/memcmp.S
@@ -4,7 +4,7 @@
  * Public domain.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 ENTRY(memcmp)
 	pushl	%edi
diff --git a/libc/arch-x86/string/strcat.S b/libc/arch-x86/string/strcat.S
index c75f38a..49e8eee 100644
--- a/libc/arch-x86/string/strcat.S
+++ b/libc/arch-x86/string/strcat.S
@@ -4,7 +4,7 @@
  * Public domain.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 #if defined(APIWARN)
 #APP
diff --git a/libc/arch-x86/string/strcmp.S b/libc/arch-x86/string/strcmp.S
index 5d3f4fc..580f4d5 100644
--- a/libc/arch-x86/string/strcmp.S
+++ b/libc/arch-x86/string/strcmp.S
@@ -4,7 +4,7 @@
  * Public domain.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 /*
  * NOTE: I've unrolled the loop eight times: large enough to make a
diff --git a/libc/arch-x86/string/strncmp.S b/libc/arch-x86/string/strncmp.S
index 6649473..9ba83a1 100644
--- a/libc/arch-x86/string/strncmp.S
+++ b/libc/arch-x86/string/strncmp.S
@@ -4,7 +4,7 @@
  * Public domain.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 /*
  * NOTE: I've unrolled the loop eight times: large enough to make a
diff --git a/libc/arch-x86/string/swab.S b/libc/arch-x86/string/swab.S
index 2f6cfb2..b44d134 100644
--- a/libc/arch-x86/string/swab.S
+++ b/libc/arch-x86/string/swab.S
@@ -4,7 +4,7 @@
  * Public domain.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 /*
  * On the i486, this code is negligibly faster than the code generated
diff --git a/libc/arch-x86/x86.mk b/libc/arch-x86/x86.mk
index a39fcf2..b024acb 100644
--- a/libc/arch-x86/x86.mk
+++ b/libc/arch-x86/x86.mk
@@ -84,15 +84,7 @@
     arch-x86/string/sse2-wcslen-atom.S \
     arch-x86/string/sse2-wcscmp-atom.S \
 
-# These are used by the static and dynamic versions of the libc
-# respectively.
-libc_arch_static_src_files_x86 :=
 
-libc_arch_dynamic_src_files_x86 :=
-
-
-##########################################
-# crt-related
 libc_crt_target_cflags_x86 := \
     -m32 \
     -I$(LOCAL_PATH)/arch-x86/include
diff --git a/libc/arch-x86_64/bionic/__bionic_clone.S b/libc/arch-x86_64/bionic/__bionic_clone.S
index 7692013..cf98d76 100644
--- a/libc/arch-x86_64/bionic/__bionic_clone.S
+++ b/libc/arch-x86_64/bionic/__bionic_clone.S
@@ -26,8 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 // pid_t __bionic_clone(int flags, void* child_stack, pid_t* parent_tid, void* tls, pid_t* child_tid, int (*fn)(void*), void* arg);
 ENTRY(__bionic_clone)
diff --git a/libc/arch-x86_64/bionic/__get_sp.S b/libc/arch-x86_64/bionic/__get_sp.S
index 0c693b3..9cc18a9 100644
--- a/libc/arch-x86_64/bionic/__get_sp.S
+++ b/libc/arch-x86_64/bionic/__get_sp.S
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 ENTRY(__get_sp)
   mov  %rsp, %rax
diff --git a/libc/arch-x86_64/bionic/__rt_sigreturn.S b/libc/arch-x86_64/bionic/__rt_sigreturn.S
index e03bb88..eddceb1 100644
--- a/libc/arch-x86_64/bionic/__rt_sigreturn.S
+++ b/libc/arch-x86_64/bionic/__rt_sigreturn.S
@@ -26,11 +26,9 @@
  * SUCH DAMAGE.
  */
 
-#include <asm/unistd.h>
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
-ENTRY(__rt_sigreturn)
-  .hidden _C_LABEL(__rt_sigreturn) // TODO: add an ENTRY_PRIVATE macro for x86_64.
+ENTRY_PRIVATE(__rt_sigreturn)
   movl $__NR_rt_sigreturn, %eax
   syscall
 END(__rt_sigreturn)
diff --git a/libc/arch-x86_64/bionic/_setjmp.S b/libc/arch-x86_64/bionic/_setjmp.S
index e9b8dbb..c617030 100644
--- a/libc/arch-x86_64/bionic/_setjmp.S
+++ b/libc/arch-x86_64/bionic/_setjmp.S
@@ -36,8 +36,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/setjmp.h>
 
 /*
diff --git a/libc/arch-x86_64/bionic/setjmp.S b/libc/arch-x86_64/bionic/setjmp.S
index 4dd9028..c81b573 100644
--- a/libc/arch-x86_64/bionic/setjmp.S
+++ b/libc/arch-x86_64/bionic/setjmp.S
@@ -36,8 +36,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/setjmp.h>
 
 /*
@@ -54,9 +53,9 @@
 	pushq	%rdi
 	xorq	%rdi,%rdi
 #ifdef __PIC__
-	call	PIC_PLT(_C_LABEL(sigblock))
+	call	PIC_PLT(sigblock)
 #else
-	call	_C_LABEL(sigblock)
+	call	sigblock
 #endif
 	popq	%rdi
 	movq	%rax,(_JB_SIGMASK * 8)(%rdi)
@@ -82,9 +81,9 @@
 	movq	(_JB_SIGMASK * 8)(%rdi),%rdi
 	pushq	%r8
 #ifdef __PIC__
-	call	PIC_PLT(_C_LABEL(sigsetmask))
+	call	PIC_PLT(sigsetmask)
 #else
-	call	_C_LABEL(sigsetmask)
+	call	sigsetmask
 #endif
 	popq	%r8
 	movq	(_JB_RBX * 8)(%r12),%rbx
diff --git a/libc/arch-x86_64/bionic/sigsetjmp.S b/libc/arch-x86_64/bionic/sigsetjmp.S
index 842d6ff..718743f 100644
--- a/libc/arch-x86_64/bionic/sigsetjmp.S
+++ b/libc/arch-x86_64/bionic/sigsetjmp.S
@@ -37,7 +37,7 @@
  */
 
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 #include <machine/setjmp.h>
 
 /*
@@ -58,9 +58,9 @@
 	pushq	%rdi
 	xorq	%rdi,%rdi
 #ifdef __PIC__
-	call	PIC_PLT(_C_LABEL(sigblock))
+	call	PIC_PLT(sigblock)
 #else
-	call	_C_LABEL(sigblock)
+	call	sigblock
 #endif
 	popq	%rdi
 	movq	%rax,(_JB_SIGMASK * 8)(%rdi)
@@ -87,9 +87,9 @@
 
 	movq	(_JB_SIGMASK * 8)(%rdi),%rdi
 #ifdef __PIC__
-	call	PIC_PLT(_C_LABEL(sigsetmask))
+	call	PIC_PLT(sigsetmask)
 #else
-	call	_C_LABEL(sigsetmask)
+	call	sigsetmask
 #endif
 2:	popq	%rax
 	movq	(_JB_RBX * 8)(%r12),%rbx
diff --git a/libc/arch-x86_64/include/machine/asm.h b/libc/arch-x86_64/include/machine/asm.h
index 310b230..0af6dae 100644
--- a/libc/arch-x86_64/include/machine/asm.h
+++ b/libc/arch-x86_64/include/machine/asm.h
@@ -37,8 +37,6 @@
 #ifndef _AMD64_ASM_H_
 #define _AMD64_ASM_H_
 
-#ifdef __x86_64__
-
 #ifdef __PIC__
 #define PIC_PLT(x)	x@PLT
 #define PIC_GOT(x)	x@GOTPCREL(%rip)
@@ -47,19 +45,6 @@
 #define PIC_GOT(x)	x
 #endif
 
-# define _C_LABEL(x)	x
-#define	_ASM_LABEL(x)	x
-
-#define CVAROFF(x,y)		(_C_LABEL(x)+y)(%rip)
-
-#ifdef __STDC__
-# define __CONCAT(x,y)	x ## y
-# define __STRING(x)	#x
-#else
-# define __CONCAT(x,y)	x/**/y
-# define __STRING(x)	"x"
-#endif
-
 /* let kernels and others override entrypoint alignment */
 #ifndef _ALIGN_TEXT
 # ifdef _STANDALONE
@@ -69,78 +54,4 @@
 # endif
 #endif
 
-#define _ENTRY(x) \
-	.text; _ALIGN_TEXT; .globl x; .type x,@function; x: .cfi_startproc;
-#define _LABEL(x) \
-	.globl x; x:
-
-#ifdef _KERNEL
-/* XXX Can't use __CONCAT() here, as it would be evaluated incorrectly. */
-#ifdef __STDC__
-#define	IDTVEC(name) \
-	ALIGN_TEXT; .globl X ## name; .type X ## name,@function; X ## name:
-#define	IDTVEC_END(name) \
-	.size X ## name, . - X ## name
-#else 
-#define	IDTVEC(name) \
-	ALIGN_TEXT; .globl X/**/name; .type X/**/name,@function; X/**/name:
-#define	IDTVEC_END(name) \
-	.size X/**/name, . - X/**/name
-#endif /* __STDC__ */ 
-#endif /* _KERNEL */
-
-#ifdef __STDC__
-#define CPUVAR(off)	%gs:CPU_INFO_ ## off
-#else
-#define CPUVAR(off)     %gs:CPU_INFO_/**/off
-#endif
-
-
-#ifdef GPROF
-# define _PROF_PROLOGUE	\
-	pushq %rbp; leaq (%rsp),%rbp; call PIC_PLT(__mcount); popq %rbp
-#else
-# define _PROF_PROLOGUE
-#endif
-
-#define	ENTRY(y)	_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
-#define	NENTRY(y)	_ENTRY(_C_LABEL(y))
-#define	ALTENTRY(x)	NENTRY(x)
-#define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
-#define	LABEL(y)	_LABEL(_C_LABEL(y))
-#define	END(y)		.cfi_endproc; .size y, . - y
-
-#define	ASMSTR		.asciz
-
-#define RCSID(x)	.pushsection ".ident"; .asciz x; .popsection
-
-#define	WEAK_ALIAS(alias,sym)						\
-	.weak alias;							\
-	alias = sym
-
-/*
- * STRONG_ALIAS: create a strong alias.
- */
-#define STRONG_ALIAS(alias,sym)						\
-	.globl alias;							\
-	alias = sym
-
-#ifdef __STDC__
-#define	WARN_REFERENCES(sym,msg)					\
-	.pushsection .gnu.warning. ## sym;				\
-	.ascii msg;							\
-	.popsection
-#else
-#define	WARN_REFERENCES(sym,msg)					\
-	.pushsection .gnu.warning./**/sym;				\
-	.ascii msg;							\
-	.popsection
-#endif /* __STDC__ */
-
-#else	/*	__x86_64__	*/
-
-#include <i386/asm.h>
-
-#endif	/*	__x86_64__	*/
-
 #endif /* !_AMD64_ASM_H_ */
diff --git a/libc/arch-x86_64/syscalls/__arch_prctl.S b/libc/arch-x86_64/syscalls/__arch_prctl.S
index e878679..ac5d96e 100644
--- a/libc/arch-x86_64/syscalls/__arch_prctl.S
+++ b/libc/arch-x86_64/syscalls/__arch_prctl.S
@@ -14,4 +14,4 @@
 1:
     ret
 END(__arch_prctl)
-.hidden _C_LABEL(__arch_prctl)
+.hidden __arch_prctl
diff --git a/libc/arch-x86_64/syscalls/__brk.S b/libc/arch-x86_64/syscalls/__brk.S
index 18c2997..a69f404 100644
--- a/libc/arch-x86_64/syscalls/__brk.S
+++ b/libc/arch-x86_64/syscalls/__brk.S
@@ -14,4 +14,4 @@
 1:
     ret
 END(__brk)
-.hidden _C_LABEL(__brk)
+.hidden __brk
diff --git a/libc/arch-x86_64/syscalls/__epoll_pwait.S b/libc/arch-x86_64/syscalls/__epoll_pwait.S
index ed913b0..306e12e 100644
--- a/libc/arch-x86_64/syscalls/__epoll_pwait.S
+++ b/libc/arch-x86_64/syscalls/__epoll_pwait.S
@@ -15,4 +15,4 @@
 1:
     ret
 END(__epoll_pwait)
-.hidden _C_LABEL(__epoll_pwait)
+.hidden __epoll_pwait
diff --git a/libc/arch-x86_64/syscalls/__exit.S b/libc/arch-x86_64/syscalls/__exit.S
index da1f9f8..af3ada4 100644
--- a/libc/arch-x86_64/syscalls/__exit.S
+++ b/libc/arch-x86_64/syscalls/__exit.S
@@ -14,4 +14,4 @@
 1:
     ret
 END(__exit)
-.hidden _C_LABEL(__exit)
+.hidden __exit
diff --git a/libc/arch-x86_64/syscalls/__getcpu.S b/libc/arch-x86_64/syscalls/__getcpu.S
index 5a18494..8650db4 100644
--- a/libc/arch-x86_64/syscalls/__getcpu.S
+++ b/libc/arch-x86_64/syscalls/__getcpu.S
@@ -14,4 +14,4 @@
 1:
     ret
 END(__getcpu)
-.hidden _C_LABEL(__getcpu)
+.hidden __getcpu
diff --git a/libc/arch-x86_64/syscalls/__getcwd.S b/libc/arch-x86_64/syscalls/__getcwd.S
index c9e9942..c762804 100644
--- a/libc/arch-x86_64/syscalls/__getcwd.S
+++ b/libc/arch-x86_64/syscalls/__getcwd.S
@@ -14,4 +14,4 @@
 1:
     ret
 END(__getcwd)
-.hidden _C_LABEL(__getcwd)
+.hidden __getcwd
diff --git a/libc/arch-x86_64/syscalls/__getpriority.S b/libc/arch-x86_64/syscalls/__getpriority.S
index f5230e1..8aaae8f 100644
--- a/libc/arch-x86_64/syscalls/__getpriority.S
+++ b/libc/arch-x86_64/syscalls/__getpriority.S
@@ -14,4 +14,4 @@
 1:
     ret
 END(__getpriority)
-.hidden _C_LABEL(__getpriority)
+.hidden __getpriority
diff --git a/libc/arch-x86_64/syscalls/__ioctl.S b/libc/arch-x86_64/syscalls/__ioctl.S
index 8f30eb6..646d819 100644
--- a/libc/arch-x86_64/syscalls/__ioctl.S
+++ b/libc/arch-x86_64/syscalls/__ioctl.S
@@ -14,4 +14,4 @@
 1:
     ret
 END(__ioctl)
-.hidden _C_LABEL(__ioctl)
+.hidden __ioctl
diff --git a/libc/arch-x86_64/syscalls/__openat.S b/libc/arch-x86_64/syscalls/__openat.S
index cd6a07f..e065cca 100644
--- a/libc/arch-x86_64/syscalls/__openat.S
+++ b/libc/arch-x86_64/syscalls/__openat.S
@@ -15,4 +15,4 @@
 1:
     ret
 END(__openat)
-.hidden _C_LABEL(__openat)
+.hidden __openat
diff --git a/libc/arch-x86_64/syscalls/__ppoll.S b/libc/arch-x86_64/syscalls/__ppoll.S
index dd639ae..6edaa36 100644
--- a/libc/arch-x86_64/syscalls/__ppoll.S
+++ b/libc/arch-x86_64/syscalls/__ppoll.S
@@ -15,4 +15,4 @@
 1:
     ret
 END(__ppoll)
-.hidden _C_LABEL(__ppoll)
+.hidden __ppoll
diff --git a/libc/arch-x86_64/syscalls/__pselect6.S b/libc/arch-x86_64/syscalls/__pselect6.S
index c37483a..a2aec7a 100644
--- a/libc/arch-x86_64/syscalls/__pselect6.S
+++ b/libc/arch-x86_64/syscalls/__pselect6.S
@@ -15,4 +15,4 @@
 1:
     ret
 END(__pselect6)
-.hidden _C_LABEL(__pselect6)
+.hidden __pselect6
diff --git a/libc/arch-x86_64/syscalls/__ptrace.S b/libc/arch-x86_64/syscalls/__ptrace.S
index be42b91..8ec8ac1 100644
--- a/libc/arch-x86_64/syscalls/__ptrace.S
+++ b/libc/arch-x86_64/syscalls/__ptrace.S
@@ -15,4 +15,4 @@
 1:
     ret
 END(__ptrace)
-.hidden _C_LABEL(__ptrace)
+.hidden __ptrace
diff --git a/libc/arch-x86_64/syscalls/__reboot.S b/libc/arch-x86_64/syscalls/__reboot.S
index fc8e58d..9b8ef70 100644
--- a/libc/arch-x86_64/syscalls/__reboot.S
+++ b/libc/arch-x86_64/syscalls/__reboot.S
@@ -15,4 +15,4 @@
 1:
     ret
 END(__reboot)
-.hidden _C_LABEL(__reboot)
+.hidden __reboot
diff --git a/libc/arch-x86_64/syscalls/__rt_sigaction.S b/libc/arch-x86_64/syscalls/__rt_sigaction.S
index 70602df..b038f6e 100644
--- a/libc/arch-x86_64/syscalls/__rt_sigaction.S
+++ b/libc/arch-x86_64/syscalls/__rt_sigaction.S
@@ -15,4 +15,4 @@
 1:
     ret
 END(__rt_sigaction)
-.hidden _C_LABEL(__rt_sigaction)
+.hidden __rt_sigaction
diff --git a/libc/arch-x86_64/syscalls/__rt_sigpending.S b/libc/arch-x86_64/syscalls/__rt_sigpending.S
index 1caf131..e0c50c1 100644
--- a/libc/arch-x86_64/syscalls/__rt_sigpending.S
+++ b/libc/arch-x86_64/syscalls/__rt_sigpending.S
@@ -14,4 +14,4 @@
 1:
     ret
 END(__rt_sigpending)
-.hidden _C_LABEL(__rt_sigpending)
+.hidden __rt_sigpending
diff --git a/libc/arch-x86_64/syscalls/__rt_sigprocmask.S b/libc/arch-x86_64/syscalls/__rt_sigprocmask.S
index d7e44a7..2a0ab5e 100644
--- a/libc/arch-x86_64/syscalls/__rt_sigprocmask.S
+++ b/libc/arch-x86_64/syscalls/__rt_sigprocmask.S
@@ -15,4 +15,4 @@
 1:
     ret
 END(__rt_sigprocmask)
-.hidden _C_LABEL(__rt_sigprocmask)
+.hidden __rt_sigprocmask
diff --git a/libc/arch-x86_64/syscalls/__rt_sigsuspend.S b/libc/arch-x86_64/syscalls/__rt_sigsuspend.S
index 851b93e..6fa6565 100644
--- a/libc/arch-x86_64/syscalls/__rt_sigsuspend.S
+++ b/libc/arch-x86_64/syscalls/__rt_sigsuspend.S
@@ -14,4 +14,4 @@
 1:
     ret
 END(__rt_sigsuspend)
-.hidden _C_LABEL(__rt_sigsuspend)
+.hidden __rt_sigsuspend
diff --git a/libc/arch-x86_64/syscalls/__rt_sigtimedwait.S b/libc/arch-x86_64/syscalls/__rt_sigtimedwait.S
index 6962d4a..46ee04b 100644
--- a/libc/arch-x86_64/syscalls/__rt_sigtimedwait.S
+++ b/libc/arch-x86_64/syscalls/__rt_sigtimedwait.S
@@ -15,4 +15,4 @@
 1:
     ret
 END(__rt_sigtimedwait)
-.hidden _C_LABEL(__rt_sigtimedwait)
+.hidden __rt_sigtimedwait
diff --git a/libc/arch-x86_64/syscalls/__sched_getaffinity.S b/libc/arch-x86_64/syscalls/__sched_getaffinity.S
index 861f06b..3707226 100644
--- a/libc/arch-x86_64/syscalls/__sched_getaffinity.S
+++ b/libc/arch-x86_64/syscalls/__sched_getaffinity.S
@@ -14,4 +14,4 @@
 1:
     ret
 END(__sched_getaffinity)
-.hidden _C_LABEL(__sched_getaffinity)
+.hidden __sched_getaffinity
diff --git a/libc/arch-x86_64/syscalls/__set_tid_address.S b/libc/arch-x86_64/syscalls/__set_tid_address.S
index fe7260f..4a8f153 100644
--- a/libc/arch-x86_64/syscalls/__set_tid_address.S
+++ b/libc/arch-x86_64/syscalls/__set_tid_address.S
@@ -14,4 +14,4 @@
 1:
     ret
 END(__set_tid_address)
-.hidden _C_LABEL(__set_tid_address)
+.hidden __set_tid_address
diff --git a/libc/arch-x86_64/syscalls/__syslog.S b/libc/arch-x86_64/syscalls/__syslog.S
index 4e41149..f710025 100644
--- a/libc/arch-x86_64/syscalls/__syslog.S
+++ b/libc/arch-x86_64/syscalls/__syslog.S
@@ -14,4 +14,4 @@
 1:
     ret
 END(__syslog)
-.hidden _C_LABEL(__syslog)
+.hidden __syslog
diff --git a/libc/arch-x86_64/syscalls/__timer_create.S b/libc/arch-x86_64/syscalls/__timer_create.S
index 1c5c68e..2f41c88 100644
--- a/libc/arch-x86_64/syscalls/__timer_create.S
+++ b/libc/arch-x86_64/syscalls/__timer_create.S
@@ -14,4 +14,4 @@
 1:
     ret
 END(__timer_create)
-.hidden _C_LABEL(__timer_create)
+.hidden __timer_create
diff --git a/libc/arch-x86_64/syscalls/__timer_delete.S b/libc/arch-x86_64/syscalls/__timer_delete.S
index c826757..2009916 100644
--- a/libc/arch-x86_64/syscalls/__timer_delete.S
+++ b/libc/arch-x86_64/syscalls/__timer_delete.S
@@ -14,4 +14,4 @@
 1:
     ret
 END(__timer_delete)
-.hidden _C_LABEL(__timer_delete)
+.hidden __timer_delete
diff --git a/libc/arch-x86_64/syscalls/__timer_getoverrun.S b/libc/arch-x86_64/syscalls/__timer_getoverrun.S
index 772b05e..fe71efe 100644
--- a/libc/arch-x86_64/syscalls/__timer_getoverrun.S
+++ b/libc/arch-x86_64/syscalls/__timer_getoverrun.S
@@ -14,4 +14,4 @@
 1:
     ret
 END(__timer_getoverrun)
-.hidden _C_LABEL(__timer_getoverrun)
+.hidden __timer_getoverrun
diff --git a/libc/arch-x86_64/syscalls/__timer_gettime.S b/libc/arch-x86_64/syscalls/__timer_gettime.S
index 181069b..44fe2ff 100644
--- a/libc/arch-x86_64/syscalls/__timer_gettime.S
+++ b/libc/arch-x86_64/syscalls/__timer_gettime.S
@@ -14,4 +14,4 @@
 1:
     ret
 END(__timer_gettime)
-.hidden _C_LABEL(__timer_gettime)
+.hidden __timer_gettime
diff --git a/libc/arch-x86_64/syscalls/__timer_settime.S b/libc/arch-x86_64/syscalls/__timer_settime.S
index 11fe04e..1240aa1 100644
--- a/libc/arch-x86_64/syscalls/__timer_settime.S
+++ b/libc/arch-x86_64/syscalls/__timer_settime.S
@@ -15,4 +15,4 @@
 1:
     ret
 END(__timer_settime)
-.hidden _C_LABEL(__timer_settime)
+.hidden __timer_settime
diff --git a/libc/arch-x86_64/syscalls/__waitid.S b/libc/arch-x86_64/syscalls/__waitid.S
index 4317d78..0d4fc58 100644
--- a/libc/arch-x86_64/syscalls/__waitid.S
+++ b/libc/arch-x86_64/syscalls/__waitid.S
@@ -15,4 +15,4 @@
 1:
     ret
 END(__waitid)
-.hidden _C_LABEL(__waitid)
+.hidden __waitid
diff --git a/libc/arch-x86_64/x86_64.mk b/libc/arch-x86_64/x86_64.mk
index 5d2b05b..44831a6 100644
--- a/libc/arch-x86_64/x86_64.mk
+++ b/libc/arch-x86_64/x86_64.mk
@@ -53,14 +53,7 @@
     arch-x86_64/bionic/vfork.S \
     string/memcmp16.c \
 
-# These are used by the static and dynamic versions of the libc
-# respectively.
-libc_arch_static_src_files_x86_64 :=
 
-libc_arch_dynamic_src_files_x86_64 :=
-
-##########################################
-# crt-related
 libc_crt_target_cflags_x86_64 += \
     -m64 \
     -I$(LOCAL_PATH)/arch-x86_64/include
diff --git a/libc/bionic/atoi.c b/libc/bionic/atoi.c
deleted file mode 100644
index 9a65543..0000000
--- a/libc/bionic/atoi.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2008 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 <inttypes.h>
-
-int  atoi(const char*  s)
-{
-    return (int)strtoimax(s, NULL, 10);
-}
diff --git a/libc/bionic/atol.c b/libc/bionic/atol.c
deleted file mode 100644
index 83dc05c..0000000
--- a/libc/bionic/atol.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2008 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 <inttypes.h>
-
-long  atol(const char*  s)
-{
-    return (long)strtoimax(s, NULL, 10);
-}
diff --git a/libc/bionic/atoll.c b/libc/bionic/atoll.c
deleted file mode 100644
index 953878f..0000000
--- a/libc/bionic/atoll.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2008 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 <inttypes.h>
-
-long long atoll(const char*  s)
-{
-    return (long long)strtoimax(s, NULL, 10);
-}
diff --git a/libc/bionic/ftok.c b/libc/bionic/ftok.c
deleted file mode 100644
index 638bd0a..0000000
--- a/libc/bionic/ftok.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2008 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 <unistd.h>
-#include <sys/ipc.h>
-#include <sys/stat.h>
-
-key_t  ftok(const char*  path, int  id)
-{
-    struct stat   st;
-
-    if ( lstat(path, &st) < 0 )
-        return -1;
-
-    return (key_t)( (st.st_ino & 0xffff) | ((st.st_dev & 0xff) << 16) | ((id & 255) << 24) );
-}
diff --git a/libc/bionic/ndk_cruft.cpp b/libc/bionic/ndk_cruft.cpp
index 3637c3e..fc9d9d4 100644
--- a/libc/bionic/ndk_cruft.cpp
+++ b/libc/bionic/ndk_cruft.cpp
@@ -40,7 +40,7 @@
 // getpagesize() and __getpageshift(). Needed for backwards compatibility with old NDK apps.
 extern "C" {
   unsigned int __page_size = PAGE_SIZE;
-  unsigned int __page_shift = PAGE_SHIFT;
+  unsigned int __page_shift = 12;
 }
 
 // TODO: remove this backward compatibility hack (for jb-mr1 strace binaries).
diff --git a/libc/bionic/perror.c b/libc/bionic/perror.c
deleted file mode 100644
index de55f72..0000000
--- a/libc/bionic/perror.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2008 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 <errno.h>
-#include <unistd.h>
-#include <string.h>
-
-void perror(const char *prefix)
-{
-    char   buff[256];
-
-    strerror_r( errno, buff, sizeof(buff) );
-
-    if (prefix) {
-        write( 2, prefix, strlen(prefix) );
-        write( 2, ": ", 2 );
-    }
-    write( 2, buff, strlen(buff) );
-    write( 2, "\n", 1 );
-}
diff --git a/libc/bionic/strndup.c b/libc/bionic/strndup.c
deleted file mode 100644
index 9dca79c..0000000
--- a/libc/bionic/strndup.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2008 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 <string.h>
-#include <stdlib.h>
-
-char*  strndup(const char*  s, size_t n)
-{
-    size_t  slen = (size_t)strlen(s);
-    char*   copy;
-
-    if (slen < n)
-        n = slen;
-    copy = malloc(n+1);
-    if (copy) {
-        memcpy(copy, s, n);
-        copy[n] = 0;
-    }
-    return copy;
-}
diff --git a/libc/bionic/stubs.cpp b/libc/bionic/stubs.cpp
index 707036a..2c2b74b 100644
--- a/libc/bionic/stubs.cpp
+++ b/libc/bionic/stubs.cpp
@@ -480,7 +480,7 @@
   UNIMPLEMENTED;
 }
 
-// Portable code should use sysconf(_SC_PAGESIZE) directly instead.
+// Portable code should use sysconf(_SC_PAGE_SIZE) directly instead.
 int getpagesize() {
-  return sysconf(_SC_PAGESIZE);
+  return sysconf(_SC_PAGE_SIZE);
 }
diff --git a/libc/bionic/sysconf.cpp b/libc/bionic/sysconf.cpp
index db808c2..233e57c 100644
--- a/libc/bionic/sysconf.cpp
+++ b/libc/bionic/sysconf.cpp
@@ -229,8 +229,11 @@
 #endif
     case _SC_ATEXIT_MAX:        return SYSTEM_ATEXIT_MAX;
     case _SC_IOV_MAX:           return SYSTEM_IOV_MAX;
-    case _SC_PAGESIZE:          return PAGE_SIZE;
-    case _SC_PAGE_SIZE:         return PAGE_SIZE;
+
+    case _SC_PAGESIZE:
+    case _SC_PAGE_SIZE:
+        return PAGE_SIZE;
+
 #ifdef _XOPEN_UNIX
     case _SC_XOPEN_UNIX:        return _XOPEN_UNIX;
 #endif
diff --git a/libc/bionic/system_properties.c b/libc/bionic/system_properties.c
deleted file mode 100644
index 825894f..0000000
--- a/libc/bionic/system_properties.c
+++ /dev/null
@@ -1,714 +0,0 @@
-/*
- * Copyright (C) 2008 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 <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stddef.h>
-#include <errno.h>
-#include <poll.h>
-#include <fcntl.h>
-#include <stdbool.h>
-#include <string.h>
-
-#include <sys/mman.h>
-
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <sys/select.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <unistd.h>
-
-#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
-#include <sys/_system_properties.h>
-
-#include <sys/atomics.h>
-
-#include "private/bionic_atomic_inline.h"
-
-#define ALIGN(x, a) (((x) + (a - 1)) & ~(a - 1))
-
-struct prop_area {
-    unsigned bytes_used;
-    unsigned volatile serial;
-    unsigned magic;
-    unsigned version;
-    unsigned reserved[28];
-    char data[0];
-};
-
-typedef struct prop_area prop_area;
-
-struct prop_info {
-    unsigned volatile serial;
-    char value[PROP_VALUE_MAX];
-    char name[0];
-};
-
-typedef struct prop_info prop_info;
-
-/*
- * Properties are stored in a hybrid trie/binary tree structure.
- * Each property's name is delimited at '.' characters, and the tokens are put
- * into a trie structure.  Siblings at each level of the trie are stored in a
- * binary tree.  For instance, "ro.secure"="1" could be stored as follows:
- *
- * +-----+   children    +----+   children    +--------+
- * |     |-------------->| ro |-------------->| secure |
- * +-----+               +----+               +--------+
- *                       /    \                /   |
- *                 left /      \ right   left /    |  prop   +===========+
- *                     v        v            v     +-------->| ro.secure |
- *                  +-----+   +-----+     +-----+            +-----------+
- *                  | net |   | sys |     | com |            |     1     |
- *                  +-----+   +-----+     +-----+            +===========+
- */
-
-typedef volatile uint32_t prop_off_t;
-struct prop_bt {
-    uint8_t namelen;
-    uint8_t reserved[3];
-
-    prop_off_t prop;
-
-    prop_off_t left;
-    prop_off_t right;
-
-    prop_off_t children;
-
-    char name[0];
-};
-
-typedef struct prop_bt prop_bt;
-
-static const char property_service_socket[] = "/dev/socket/" PROP_SERVICE_NAME;
-static char property_filename[PATH_MAX] = PROP_FILENAME;
-static bool compat_mode = false;
-
-prop_area *__system_property_area__ = NULL;
-
-size_t pa_data_size;
-size_t pa_size;
-
-static int get_fd_from_env(void)
-{
-    char *env = getenv("ANDROID_PROPERTY_WORKSPACE");
-
-    if (!env) {
-        return -1;
-    }
-
-    return atoi(env);
-}
-
-static int map_prop_area_rw()
-{
-    prop_area *pa;
-    int fd;
-    int ret;
-
-    /* dev is a tmpfs that we can use to carve a shared workspace
-     * out of, so let's do that...
-     */
-    fd = open(property_filename, O_RDWR | O_CREAT | O_NOFOLLOW | O_CLOEXEC |
-            O_EXCL, 0444);
-    if (fd < 0) {
-        if (errno == EACCES) {
-            /* for consistency with the case where the process has already
-             * mapped the page in and segfaults when trying to write to it
-             */
-            abort();
-        }
-        return -1;
-    }
-
-    ret = fcntl(fd, F_SETFD, FD_CLOEXEC);
-    if (ret < 0)
-        goto out;
-
-    if (ftruncate(fd, PA_SIZE) < 0)
-        goto out;
-
-    pa_size = PA_SIZE;
-    pa_data_size = pa_size - sizeof(prop_area);
-    compat_mode = false;
-
-    pa = mmap(NULL, pa_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
-    if(pa == MAP_FAILED)
-        goto out;
-
-    memset(pa, 0, pa_size);
-    pa->magic = PROP_AREA_MAGIC;
-    pa->version = PROP_AREA_VERSION;
-    /* reserve root node */
-    pa->bytes_used = sizeof(prop_bt);
-
-    /* plug into the lib property services */
-    __system_property_area__ = pa;
-
-    close(fd);
-    return 0;
-
-out:
-    close(fd);
-    return -1;
-}
-
-int __system_property_set_filename(const char *filename)
-{
-    size_t len = strlen(filename);
-    if (len >= sizeof(property_filename))
-        return -1;
-
-    strcpy(property_filename, filename);
-    return 0;
-}
-
-int __system_property_area_init()
-{
-    return map_prop_area_rw();
-}
-
-static int map_prop_area()
-{
-    bool fromFile = true;
-    int result = -1;
-    int fd;
-    int ret;
-
-    fd = open(property_filename, O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
-    if (fd >= 0) {
-        /* For old kernels that don't support O_CLOEXEC */
-        ret = fcntl(fd, F_SETFD, FD_CLOEXEC);
-        if (ret < 0)
-            goto cleanup;
-    }
-
-    if ((fd < 0) && (errno == ENOENT)) {
-        /*
-         * For backwards compatibility, if the file doesn't
-         * exist, we use the environment to get the file descriptor.
-         * For security reasons, we only use this backup if the kernel
-         * returns ENOENT. We don't want to use the backup if the kernel
-         * returns other errors such as ENOMEM or ENFILE, since it
-         * might be possible for an external program to trigger this
-         * condition.
-         */
-        fd = get_fd_from_env();
-        fromFile = false;
-    }
-
-    if (fd < 0) {
-        return -1;
-    }
-
-    struct stat fd_stat;
-    if (fstat(fd, &fd_stat) < 0) {
-        goto cleanup;
-    }
-
-    if ((fd_stat.st_uid != 0)
-            || (fd_stat.st_gid != 0)
-            || ((fd_stat.st_mode & (S_IWGRP | S_IWOTH)) != 0)
-            || (fd_stat.st_size < sizeof(prop_area)) ) {
-        goto cleanup;
-    }
-
-    pa_size = fd_stat.st_size;
-    pa_data_size = pa_size - sizeof(prop_area);
-    prop_area *pa = mmap(NULL, pa_size, PROT_READ, MAP_SHARED, fd, 0);
-
-    if (pa == MAP_FAILED) {
-        goto cleanup;
-    }
-
-    if((pa->magic != PROP_AREA_MAGIC) || (pa->version != PROP_AREA_VERSION &&
-                pa->version != PROP_AREA_VERSION_COMPAT)) {
-        munmap(pa, pa_size);
-        goto cleanup;
-    }
-
-    if (pa->version == PROP_AREA_VERSION_COMPAT) {
-        compat_mode = true;
-    }
-
-    result = 0;
-
-    __system_property_area__ = pa;
-
-cleanup:
-    if (fromFile) {
-        close(fd);
-    }
-
-    return result;
-}
-
-int __system_properties_init()
-{
-    return map_prop_area();
-}
-
-static void *new_prop_obj(size_t size, prop_off_t *off)
-{
-    prop_area *pa = __system_property_area__;
-    size = ALIGN(size, sizeof(uint32_t));
-
-    if (pa->bytes_used + size > pa_data_size)
-        return NULL;
-
-    *off = pa->bytes_used;
-    __system_property_area__->bytes_used += size;
-    return __system_property_area__->data + *off;
-}
-
-static prop_bt *new_prop_bt(const char *name, uint8_t namelen, prop_off_t *off)
-{
-    prop_off_t off_tmp;
-    prop_bt *bt = new_prop_obj(sizeof(prop_bt) + namelen + 1, &off_tmp);
-    if (bt) {
-        memcpy(bt->name, name, namelen);
-        bt->name[namelen] = '\0';
-        bt->namelen = namelen;
-        ANDROID_MEMBAR_FULL();
-        *off = off_tmp;
-    }
-
-    return bt;
-}
-
-static prop_info *new_prop_info(const char *name, uint8_t namelen,
-        const char *value, uint8_t valuelen, prop_off_t *off)
-{
-    prop_off_t off_tmp;
-    prop_info *info = new_prop_obj(sizeof(prop_info) + namelen + 1, &off_tmp);
-    if (info) {
-        memcpy(info->name, name, namelen);
-        info->name[namelen] = '\0';
-        info->serial = (valuelen << 24);
-        memcpy(info->value, value, valuelen);
-        info->value[valuelen] = '\0';
-        ANDROID_MEMBAR_FULL();
-        *off = off_tmp;
-    }
-
-    return info;
-}
-
-static void *to_prop_obj(prop_off_t off)
-{
-    if (off > pa_data_size)
-        return NULL;
-    if (!__system_property_area__)
-        return NULL;
-
-    return __system_property_area__->data + off;
-}
-
-static prop_bt *root_node()
-{
-    return to_prop_obj(0);
-}
-
-static int cmp_prop_name(const char *one, uint8_t one_len, const char *two,
-        uint8_t two_len)
-{
-    if (one_len < two_len)
-        return -1;
-    else if (one_len > two_len)
-        return 1;
-    else
-        return strncmp(one, two, one_len);
-}
-
-static prop_bt *find_prop_bt(prop_bt *bt, const char *name, uint8_t namelen,
-        bool alloc_if_needed)
-{
-    while (true) {
-        int ret;
-        if (!bt)
-            return bt;
-        ret = cmp_prop_name(name, namelen, bt->name, bt->namelen);
-
-        if (ret == 0) {
-            return bt;
-        } else if (ret < 0) {
-            if (bt->left) {
-                bt = to_prop_obj(bt->left);
-            } else {
-                if (!alloc_if_needed)
-                   return NULL;
-
-                bt = new_prop_bt(name, namelen, &bt->left);
-            }
-        } else {
-            if (bt->right) {
-                bt = to_prop_obj(bt->right);
-            } else {
-                if (!alloc_if_needed)
-                   return NULL;
-
-                bt = new_prop_bt(name, namelen, &bt->right);
-            }
-        }
-    }
-}
-
-static const prop_info *find_property(prop_bt *trie, const char *name,
-        uint8_t namelen, const char *value, uint8_t valuelen,
-        bool alloc_if_needed)
-{
-    const char *remaining_name = name;
-
-    if (!trie) return NULL;
-
-    while (true) {
-        char *sep = strchr(remaining_name, '.');
-        bool want_subtree = (sep != NULL);
-        uint8_t substr_size;
-
-        prop_bt *root;
-
-        if (want_subtree) {
-            substr_size = sep - remaining_name;
-        } else {
-            substr_size = strlen(remaining_name);
-        }
-
-        if (!substr_size)
-            return NULL;
-
-        if (trie->children) {
-            root = to_prop_obj(trie->children);
-        } else if (alloc_if_needed) {
-            root = new_prop_bt(remaining_name, substr_size, &trie->children);
-        } else {
-            root = NULL;
-        }
-
-        if (!root)
-            return NULL;
-
-        trie = find_prop_bt(root, remaining_name, substr_size, alloc_if_needed);
-        if (!trie)
-            return NULL;
-
-        if (!want_subtree)
-            break;
-
-        remaining_name = sep + 1;
-    }
-
-    if (trie->prop) {
-        return to_prop_obj(trie->prop);
-    } else if (alloc_if_needed) {
-        return new_prop_info(name, namelen, value, valuelen, &trie->prop);
-    } else {
-        return NULL;
-    }
-}
-
-const prop_info *__system_property_find(const char *name)
-{
-    if (__predict_false(compat_mode)) {
-        return __system_property_find_compat(name);
-    }
-    return find_property(root_node(), name, strlen(name), NULL, 0, false);
-}
-
-int __system_property_read(const prop_info *pi, char *name, char *value)
-{
-    unsigned serial, len;
-
-    if (__predict_false(compat_mode)) {
-        return __system_property_read_compat(pi, name, value);
-    }
-
-    for(;;) {
-        serial = pi->serial;
-        while(SERIAL_DIRTY(serial)) {
-            __futex_wait((volatile void *)&pi->serial, serial, NULL);
-            serial = pi->serial;
-        }
-        len = SERIAL_VALUE_LEN(serial);
-        memcpy(value, pi->value, len + 1);
-        ANDROID_MEMBAR_FULL();
-        if(serial == pi->serial) {
-            if(name != 0) {
-                strcpy(name, pi->name);
-            }
-            return len;
-        }
-    }
-}
-
-int __system_property_get(const char *name, char *value)
-{
-    const prop_info *pi = __system_property_find(name);
-
-    if(pi != 0) {
-        return __system_property_read(pi, 0, value);
-    } else {
-        value[0] = 0;
-        return 0;
-    }
-}
-
-
-static int send_prop_msg(prop_msg *msg)
-{
-    struct pollfd pollfds[1];
-    struct sockaddr_un addr;
-    socklen_t alen;
-    size_t namelen;
-    int s;
-    int r;
-    int result = -1;
-
-    s = socket(AF_LOCAL, SOCK_STREAM, 0);
-    if(s < 0) {
-        return result;
-    }
-
-    memset(&addr, 0, sizeof(addr));
-    namelen = strlen(property_service_socket);
-    strlcpy(addr.sun_path, property_service_socket, sizeof addr.sun_path);
-    addr.sun_family = AF_LOCAL;
-    alen = namelen + offsetof(struct sockaddr_un, sun_path) + 1;
-
-    if(TEMP_FAILURE_RETRY(connect(s, (struct sockaddr *) &addr, alen)) < 0) {
-        close(s);
-        return result;
-    }
-
-    r = TEMP_FAILURE_RETRY(send(s, msg, sizeof(prop_msg), 0));
-
-    if(r == sizeof(prop_msg)) {
-        // We successfully wrote to the property server but now we
-        // wait for the property server to finish its work.  It
-        // acknowledges its completion by closing the socket so we
-        // poll here (on nothing), waiting for the socket to close.
-        // If you 'adb shell setprop foo bar' you'll see the POLLHUP
-        // once the socket closes.  Out of paranoia we cap our poll
-        // at 250 ms.
-        pollfds[0].fd = s;
-        pollfds[0].events = 0;
-        r = TEMP_FAILURE_RETRY(poll(pollfds, 1, 250 /* ms */));
-        if (r == 1 && (pollfds[0].revents & POLLHUP) != 0) {
-            result = 0;
-        } else {
-            // Ignore the timeout and treat it like a success anyway.
-            // The init process is single-threaded and its property
-            // service is sometimes slow to respond (perhaps it's off
-            // starting a child process or something) and thus this
-            // times out and the caller thinks it failed, even though
-            // it's still getting around to it.  So we fake it here,
-            // mostly for ctl.* properties, but we do try and wait 250
-            // ms so callers who do read-after-write can reliably see
-            // what they've written.  Most of the time.
-            // TODO: fix the system properties design.
-            result = 0;
-        }
-    }
-
-    close(s);
-    return result;
-}
-
-int __system_property_set(const char *key, const char *value)
-{
-    int err;
-    prop_msg msg;
-
-    if(key == 0) return -1;
-    if(value == 0) value = "";
-    if(strlen(key) >= PROP_NAME_MAX) return -1;
-    if(strlen(value) >= PROP_VALUE_MAX) return -1;
-
-    memset(&msg, 0, sizeof msg);
-    msg.cmd = PROP_MSG_SETPROP;
-    strlcpy(msg.name, key, sizeof msg.name);
-    strlcpy(msg.value, value, sizeof msg.value);
-
-    err = send_prop_msg(&msg);
-    if(err < 0) {
-        return err;
-    }
-
-    return 0;
-}
-
-int __system_property_wait(const prop_info *pi)
-{
-    unsigned n;
-    if(pi == 0) {
-        prop_area *pa = __system_property_area__;
-        n = pa->serial;
-        do {
-            __futex_wait(&pa->serial, n, NULL);
-        } while(n == pa->serial);
-    } else {
-        n = pi->serial;
-        do {
-            __futex_wait((volatile void *)&pi->serial, n, NULL);
-        } while(n == pi->serial);
-    }
-    return 0;
-}
-
-int __system_property_update(prop_info *pi, const char *value, unsigned int len)
-{
-    prop_area *pa = __system_property_area__;
-
-    if (len >= PROP_VALUE_MAX)
-        return -1;
-
-    pi->serial = pi->serial | 1;
-    ANDROID_MEMBAR_FULL();
-    memcpy(pi->value, value, len + 1);
-    ANDROID_MEMBAR_FULL();
-    pi->serial = (len << 24) | ((pi->serial + 1) & 0xffffff);
-    __futex_wake(&pi->serial, INT32_MAX);
-
-    pa->serial++;
-    __futex_wake(&pa->serial, INT32_MAX);
-
-    return 0;
-}
-
-int __system_property_add(const char *name, unsigned int namelen,
-            const char *value, unsigned int valuelen)
-{
-    prop_area *pa = __system_property_area__;
-    const prop_info *pi;
-
-    if (namelen >= PROP_NAME_MAX)
-        return -1;
-    if (valuelen >= PROP_VALUE_MAX)
-        return -1;
-    if (namelen < 1)
-        return -1;
-
-    pi = find_property(root_node(), name, namelen, value, valuelen, true);
-    if (!pi)
-        return -1;
-
-    pa->serial++;
-    __futex_wake(&pa->serial, INT32_MAX);
-    return 0;
-}
-
-unsigned int __system_property_serial(const prop_info *pi)
-{
-    return pi->serial;
-}
-
-unsigned int __system_property_wait_any(unsigned int serial)
-{
-    prop_area *pa = __system_property_area__;
-
-    do {
-        __futex_wait(&pa->serial, serial, NULL);
-    } while(pa->serial == serial);
-
-    return pa->serial;
-}
-
-struct find_nth_cookie {
-    unsigned count;
-    unsigned n;
-    const prop_info *pi;
-};
-
-static void find_nth_fn(const prop_info *pi, void *ptr)
-{
-    struct find_nth_cookie *cookie = ptr;
-
-    if (cookie->n == cookie->count)
-        cookie->pi = pi;
-
-    cookie->count++;
-}
-
-const prop_info *__system_property_find_nth(unsigned n)
-{
-    struct find_nth_cookie cookie;
-    int err;
-
-    memset(&cookie, 0, sizeof(cookie));
-    cookie.n = n;
-
-    err = __system_property_foreach(find_nth_fn, &cookie);
-    if (err < 0)
-        return NULL;
-
-    return cookie.pi;
-}
-
-static int foreach_property(prop_off_t off,
-        void (*propfn)(const prop_info *pi, void *cookie), void *cookie)
-{
-    prop_bt *trie = to_prop_obj(off);
-    if (!trie)
-        return -1;
-
-    if (trie->left) {
-        int err = foreach_property(trie->left, propfn, cookie);
-        if (err < 0)
-            return -1;
-    }
-    if (trie->prop) {
-        prop_info *info = to_prop_obj(trie->prop);
-        if (!info)
-            return -1;
-        propfn(info, cookie);
-    }
-    if (trie->children) {
-        int err = foreach_property(trie->children, propfn, cookie);
-        if (err < 0)
-            return -1;
-    }
-    if (trie->right) {
-        int err = foreach_property(trie->right, propfn, cookie);
-        if (err < 0)
-            return -1;
-    }
-
-    return 0;
-}
-
-int __system_property_foreach(void (*propfn)(const prop_info *pi, void *cookie),
-        void *cookie)
-{
-    if (__predict_false(compat_mode)) {
-        return __system_property_foreach_compat(propfn, cookie);
-	}
-    return foreach_property(0, propfn, cookie);
-}
diff --git a/libc/bionic/system_properties.cpp b/libc/bionic/system_properties.cpp
new file mode 100644
index 0000000..56f3724
--- /dev/null
+++ b/libc/bionic/system_properties.cpp
@@ -0,0 +1,763 @@
+/*
+ * Copyright (C) 2008 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 <new>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stddef.h>
+#include <errno.h>
+#include <poll.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <string.h>
+
+#include <sys/mman.h>
+
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/select.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <unistd.h>
+
+#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
+#include <sys/_system_properties.h>
+#include <sys/system_properties.h>
+
+#include <sys/atomics.h>
+
+#include "private/bionic_atomic_inline.h"
+
+#define ALIGN(x, a) (((x) + (a - 1)) & ~(a - 1))
+
+
+static const char property_service_socket[] = "/dev/socket/" PROP_SERVICE_NAME;
+
+
+/*
+ * Properties are stored in a hybrid trie/binary tree structure.
+ * Each property's name is delimited at '.' characters, and the tokens are put
+ * into a trie structure.  Siblings at each level of the trie are stored in a
+ * binary tree.  For instance, "ro.secure"="1" could be stored as follows:
+ *
+ * +-----+   children    +----+   children    +--------+
+ * |     |-------------->| ro |-------------->| secure |
+ * +-----+               +----+               +--------+
+ *                       /    \                /   |
+ *                 left /      \ right   left /    |  prop   +===========+
+ *                     v        v            v     +-------->| ro.secure |
+ *                  +-----+   +-----+     +-----+            +-----------+
+ *                  | net |   | sys |     | com |            |     1     |
+ *                  +-----+   +-----+     +-----+            +===========+
+ */
+
+// Represents a node in the trie.
+struct prop_bt {
+    uint8_t namelen;
+    uint8_t reserved[3];
+
+    volatile uint32_t prop;
+
+    volatile uint32_t left;
+    volatile uint32_t right;
+
+    volatile uint32_t children;
+
+    char name[0];
+
+    prop_bt(const char *name, const uint8_t name_length) {
+        this->namelen = name_length;
+        memcpy(this->name, name, name_length);
+        this->name[name_length] = '\0';
+        ANDROID_MEMBAR_FULL();
+    }
+
+private:
+    // Disallow copy and assign.
+    prop_bt(const prop_bt&);
+    prop_bt& operator=(const prop_bt&);
+};
+
+struct prop_area {
+    uint32_t bytes_used;
+    volatile uint32_t serial;
+    uint32_t magic;
+    uint32_t version;
+    uint32_t reserved[28];
+    char data[0];
+
+    prop_area(const uint32_t magic, const uint32_t version) :
+        serial(0), magic(magic), version(version) {
+        memset(reserved, 0, sizeof(reserved));
+        // Allocate enough space for the root node.
+        bytes_used = sizeof(prop_bt);
+    }
+
+private:
+    // Disallow copy and assign.
+    prop_area(const prop_area&);
+    prop_area& operator=(const prop_area&);
+};
+
+struct prop_info {
+    volatile uint32_t serial;
+    char value[PROP_VALUE_MAX];
+    char name[0];
+
+    prop_info(const char *name, const uint8_t namelen, const char *value,
+              const uint8_t valuelen) {
+        memcpy(this->name, name, namelen);
+        this->name[namelen] = '\0';
+        this->serial = (valuelen << 24);
+        memcpy(this->value, value, valuelen);
+        this->value[valuelen] = '\0';
+        ANDROID_MEMBAR_FULL();
+    }
+private:
+    // Disallow copy and assign.
+    prop_info(const prop_info&);
+    prop_info& operator=(const prop_info&);
+};
+
+struct find_nth_cookie {
+    uint32_t count;
+    const uint32_t n;
+    const prop_info *pi;
+
+    find_nth_cookie(uint32_t n) : count(0), n(n), pi(NULL) {
+    }
+};
+
+static char property_filename[PATH_MAX] = PROP_FILENAME;
+static bool compat_mode = false;
+static size_t pa_data_size;
+static size_t pa_size;
+
+// NOTE: This isn't static because system_properties_compat.c
+// requires it.
+prop_area *__system_property_area__ = NULL;
+
+static int get_fd_from_env(void)
+{
+    // This environment variable consistes of two decimal integer
+    // values separated by a ",". The first value is a file descriptor
+    // and the second is the size of the system properties area. The
+    // size is currently unused.
+    char *env = getenv("ANDROID_PROPERTY_WORKSPACE");
+
+    if (!env) {
+        return -1;
+    }
+
+    return atoi(env);
+}
+
+static int map_prop_area_rw()
+{
+    /* dev is a tmpfs that we can use to carve a shared workspace
+     * out of, so let's do that...
+     */
+    const int fd = open(property_filename,
+                        O_RDWR | O_CREAT | O_NOFOLLOW | O_CLOEXEC | O_EXCL, 0444);
+
+    if (fd < 0) {
+        if (errno == EACCES) {
+            /* for consistency with the case where the process has already
+             * mapped the page in and segfaults when trying to write to it
+             */
+            abort();
+        }
+        return -1;
+    }
+
+    // TODO: Is this really required ? Does android run on any kernels that
+    // don't support O_CLOEXEC ?
+    const int ret = fcntl(fd, F_SETFD, FD_CLOEXEC);
+    if (ret < 0) {
+        close(fd);
+        return -1;
+    }
+
+    if (ftruncate(fd, PA_SIZE) < 0) {
+        close(fd);
+        return -1;
+    }
+
+    pa_size = PA_SIZE;
+    pa_data_size = pa_size - sizeof(prop_area);
+    compat_mode = false;
+
+    void *const memory_area = mmap(NULL, pa_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+    if (memory_area == MAP_FAILED) {
+        close(fd);
+        return -1;
+    }
+
+    prop_area *pa = new(memory_area) prop_area(PROP_AREA_MAGIC, PROP_AREA_VERSION);
+
+    /* plug into the lib property services */
+    __system_property_area__ = pa;
+
+    close(fd);
+    return 0;
+}
+
+static int map_fd_ro(const int fd) {
+    struct stat fd_stat;
+    if (fstat(fd, &fd_stat) < 0) {
+        return -1;
+    }
+
+    if ((fd_stat.st_uid != 0)
+            || (fd_stat.st_gid != 0)
+            || ((fd_stat.st_mode & (S_IWGRP | S_IWOTH)) != 0)
+            || (fd_stat.st_size < static_cast<off_t>(sizeof(prop_area))) ) {
+        return -1;
+    }
+
+    pa_size = fd_stat.st_size;
+    pa_data_size = pa_size - sizeof(prop_area);
+
+    void* const map_result = mmap(NULL, pa_size, PROT_READ, MAP_SHARED, fd, 0);
+    if (map_result == MAP_FAILED) {
+        return -1;
+    }
+
+    prop_area* pa = reinterpret_cast<prop_area*>(map_result);
+    if ((pa->magic != PROP_AREA_MAGIC) || (pa->version != PROP_AREA_VERSION &&
+                pa->version != PROP_AREA_VERSION_COMPAT)) {
+        munmap(pa, pa_size);
+        return -1;
+    }
+
+    if (pa->version == PROP_AREA_VERSION_COMPAT) {
+        compat_mode = true;
+    }
+
+    __system_property_area__ = pa;
+    return 0;
+}
+
+static int map_prop_area()
+{
+    int fd(open(property_filename, O_RDONLY | O_NOFOLLOW | O_CLOEXEC));
+    if (fd >= 0) {
+        /* For old kernels that don't support O_CLOEXEC */
+        const int ret = fcntl(fd, F_SETFD, FD_CLOEXEC);
+        if (ret < 0) {
+            close(fd);
+            return -1;
+        }
+    }
+
+    bool close_fd = true;
+    if ((fd < 0) && (errno == ENOENT)) {
+        /*
+         * For backwards compatibility, if the file doesn't
+         * exist, we use the environment to get the file descriptor.
+         * For security reasons, we only use this backup if the kernel
+         * returns ENOENT. We don't want to use the backup if the kernel
+         * returns other errors such as ENOMEM or ENFILE, since it
+         * might be possible for an external program to trigger this
+         * condition.
+         */
+        fd = get_fd_from_env();
+        close_fd = false;
+    }
+
+    if (fd < 0) {
+        return -1;
+    }
+
+    const int map_result = map_fd_ro(fd);
+    if (close_fd) {
+        close(fd);
+    }
+
+    return map_result;
+}
+
+static void *allocate_obj(const size_t size, uint32_t *const off)
+{
+    prop_area *pa = __system_property_area__;
+    const size_t aligned = ALIGN(size, sizeof(uint32_t));
+    if (pa->bytes_used + aligned > pa_data_size) {
+        return NULL;
+    }
+
+    *off = pa->bytes_used;
+    pa->bytes_used += aligned;
+    return pa->data + *off;
+}
+
+static prop_bt *new_prop_bt(const char *name, uint8_t namelen, uint32_t *const off)
+{
+    uint32_t new_offset;
+    void *const offset = allocate_obj(sizeof(prop_bt) + namelen + 1, &new_offset);
+    if (offset) {
+        prop_bt* bt = new(offset) prop_bt(name, namelen);
+        *off = new_offset;
+        return bt;
+    }
+
+    return NULL;
+}
+
+static prop_info *new_prop_info(const char *name, uint8_t namelen,
+        const char *value, uint8_t valuelen, uint32_t *const off)
+{
+    uint32_t off_tmp;
+    void* const offset = allocate_obj(sizeof(prop_info) + namelen + 1, &off_tmp);
+    if (offset) {
+        prop_info* info = new(offset) prop_info(name, namelen, value, valuelen);
+        *off = off_tmp;
+        return info;
+    }
+
+    return NULL;
+}
+
+static void *to_prop_obj(const uint32_t off)
+{
+    if (off > pa_data_size)
+        return NULL;
+    if (!__system_property_area__)
+        return NULL;
+
+    return (__system_property_area__->data + off);
+}
+
+static prop_bt *root_node()
+{
+    return reinterpret_cast<prop_bt*>(to_prop_obj(0));
+}
+
+static int cmp_prop_name(const char *one, uint8_t one_len, const char *two,
+        uint8_t two_len)
+{
+    if (one_len < two_len)
+        return -1;
+    else if (one_len > two_len)
+        return 1;
+    else
+        return strncmp(one, two, one_len);
+}
+
+static prop_bt *find_prop_bt(prop_bt *const bt, const char *name,
+                             uint8_t namelen, bool alloc_if_needed)
+{
+
+    prop_bt* current = bt;
+    while (true) {
+        if (!current) {
+            return NULL;
+        }
+
+        const int ret = cmp_prop_name(name, namelen, current->name, current->namelen);
+        if (ret == 0) {
+            return current;
+        }
+
+        if (ret < 0) {
+            if (current->left) {
+                current = reinterpret_cast<prop_bt*>(to_prop_obj(current->left));
+            } else {
+                if (!alloc_if_needed) {
+                   return NULL;
+                }
+
+                // Note that there isn't a race condition here. "clients" never
+                // reach this code-path since It's only the (single threaded) server
+                // that allocates new nodes. Though "bt->left" is volatile, it can't
+                // have changed since the last value was last read.
+                uint32_t new_offset = 0;
+                prop_bt* new_bt = new_prop_bt(name, namelen, &new_offset);
+                if (new_bt) {
+                    current->left = new_offset;
+                }
+                return new_bt;
+            }
+        } else {
+            if (current->right) {
+                current = reinterpret_cast<prop_bt*>(to_prop_obj(current->right));
+            } else {
+                if (!alloc_if_needed) {
+                   return NULL;
+                }
+
+                uint32_t new_offset;
+                prop_bt* new_bt = new_prop_bt(name, namelen, &new_offset);
+                if (new_bt) {
+                    current->right = new_offset;
+                }
+                return new_bt;
+            }
+        }
+    }
+}
+
+static const prop_info *find_property(prop_bt *const trie, const char *name,
+        uint8_t namelen, const char *value, uint8_t valuelen,
+        bool alloc_if_needed)
+{
+    if (!trie) return NULL;
+
+    const char *remaining_name = name;
+    prop_bt* current = trie;
+    while (true) {
+        const char *sep = strchr(remaining_name, '.');
+        const bool want_subtree = (sep != NULL);
+        const uint8_t substr_size = (want_subtree) ?
+            sep - remaining_name : strlen(remaining_name);
+
+        if (!substr_size) {
+            return NULL;
+        }
+
+        prop_bt* root = NULL;
+        if (current->children) {
+            root = reinterpret_cast<prop_bt*>(to_prop_obj(current->children));
+        } else if (alloc_if_needed) {
+            uint32_t new_bt_offset;
+            root = new_prop_bt(remaining_name, substr_size, &new_bt_offset);
+            if (root) {
+                current->children = new_bt_offset;
+            }
+        }
+
+        if (!root) {
+            return NULL;
+        }
+
+        current = find_prop_bt(root, remaining_name, substr_size, alloc_if_needed);
+        if (!current) {
+            return NULL;
+        }
+
+        if (!want_subtree)
+            break;
+
+        remaining_name = sep + 1;
+    }
+
+    if (current->prop) {
+        return reinterpret_cast<prop_info*>(to_prop_obj(current->prop));
+    } else if (alloc_if_needed) {
+        uint32_t new_info_offset;
+        prop_info* new_info = new_prop_info(name, namelen, value, valuelen, &new_info_offset);
+        if (new_info) {
+            current->prop = new_info_offset;
+        }
+
+        return new_info;
+    } else {
+        return NULL;
+    }
+}
+
+static int send_prop_msg(const prop_msg *msg)
+{
+    const int fd = socket(AF_LOCAL, SOCK_STREAM, 0);
+    if (fd < 0) {
+        return -1;
+    }
+
+    const size_t namelen = strlen(property_service_socket);
+
+    sockaddr_un addr;
+    memset(&addr, 0, sizeof(addr));
+    strlcpy(addr.sun_path, property_service_socket, sizeof(addr.sun_path));
+    addr.sun_family = AF_LOCAL;
+    socklen_t alen = namelen + offsetof(sockaddr_un, sun_path) + 1;
+    if (TEMP_FAILURE_RETRY(connect(fd, reinterpret_cast<sockaddr*>(&addr), alen)) < 0) {
+        close(fd);
+        return -1;
+    }
+
+    const int num_bytes = TEMP_FAILURE_RETRY(send(fd, msg, sizeof(prop_msg), 0));
+
+    int result = -1;
+    if (num_bytes == sizeof(prop_msg)) {
+        // We successfully wrote to the property server but now we
+        // wait for the property server to finish its work.  It
+        // acknowledges its completion by closing the socket so we
+        // poll here (on nothing), waiting for the socket to close.
+        // If you 'adb shell setprop foo bar' you'll see the POLLHUP
+        // once the socket closes.  Out of paranoia we cap our poll
+        // at 250 ms.
+        pollfd pollfds[1];
+        pollfds[0].fd = fd;
+        pollfds[0].events = 0;
+        const int poll_result = TEMP_FAILURE_RETRY(poll(pollfds, 1, 250 /* ms */));
+        if (poll_result == 1 && (pollfds[0].revents & POLLHUP) != 0) {
+            result = 0;
+        } else {
+            // Ignore the timeout and treat it like a success anyway.
+            // The init process is single-threaded and its property
+            // service is sometimes slow to respond (perhaps it's off
+            // starting a child process or something) and thus this
+            // times out and the caller thinks it failed, even though
+            // it's still getting around to it.  So we fake it here,
+            // mostly for ctl.* properties, but we do try and wait 250
+            // ms so callers who do read-after-write can reliably see
+            // what they've written.  Most of the time.
+            // TODO: fix the system properties design.
+            result = 0;
+        }
+    }
+
+    close(fd);
+    return result;
+}
+
+static void find_nth_fn(const prop_info *pi, void *ptr)
+{
+    find_nth_cookie *cookie = reinterpret_cast<find_nth_cookie*>(ptr);
+
+    if (cookie->n == cookie->count)
+        cookie->pi = pi;
+
+    cookie->count++;
+}
+
+static int foreach_property(const uint32_t off,
+        void (*propfn)(const prop_info *pi, void *cookie), void *cookie)
+{
+    prop_bt *trie = reinterpret_cast<prop_bt*>(to_prop_obj(off));
+    if (!trie)
+        return -1;
+
+    if (trie->left) {
+        const int err = foreach_property(trie->left, propfn, cookie);
+        if (err < 0)
+            return -1;
+    }
+    if (trie->prop) {
+        prop_info *info = reinterpret_cast<prop_info*>(to_prop_obj(trie->prop));
+        if (!info)
+            return -1;
+        propfn(info, cookie);
+    }
+    if (trie->children) {
+        const int err = foreach_property(trie->children, propfn, cookie);
+        if (err < 0)
+            return -1;
+    }
+    if (trie->right) {
+        const int err = foreach_property(trie->right, propfn, cookie);
+        if (err < 0)
+            return -1;
+    }
+
+    return 0;
+}
+
+int __system_properties_init()
+{
+    return map_prop_area();
+}
+
+int __system_property_set_filename(const char *filename)
+{
+    size_t len = strlen(filename);
+    if (len >= sizeof(property_filename))
+        return -1;
+
+    strcpy(property_filename, filename);
+    return 0;
+}
+
+int __system_property_area_init()
+{
+    return map_prop_area_rw();
+}
+
+const prop_info *__system_property_find(const char *name)
+{
+    if (__predict_false(compat_mode)) {
+        return __system_property_find_compat(name);
+    }
+    return find_property(root_node(), name, strlen(name), NULL, 0, false);
+}
+
+int __system_property_read(const prop_info *pi, char *name, char *value)
+{
+    unsigned serial, len;
+
+    if (__predict_false(compat_mode)) {
+        return __system_property_read_compat(pi, name, value);
+    }
+
+    for(;;) {
+        serial = pi->serial;
+        while(SERIAL_DIRTY(serial)) {
+            __futex_wait((volatile void *)&pi->serial, serial, NULL);
+            serial = pi->serial;
+        }
+        len = SERIAL_VALUE_LEN(serial);
+        memcpy(value, pi->value, len + 1);
+        ANDROID_MEMBAR_FULL();
+        if(serial == pi->serial) {
+            if(name != 0) {
+                strcpy(name, pi->name);
+            }
+            return len;
+        }
+    }
+}
+
+int __system_property_get(const char *name, char *value)
+{
+    const prop_info *pi = __system_property_find(name);
+
+    if (pi != 0) {
+        return __system_property_read(pi, 0, value);
+    } else {
+        value[0] = 0;
+        return 0;
+    }
+}
+
+int __system_property_set(const char *key, const char *value)
+{
+    if (key == 0) return -1;
+    if (value == 0) value = "";
+    if (strlen(key) >= PROP_NAME_MAX) return -1;
+    if (strlen(value) >= PROP_VALUE_MAX) return -1;
+
+    prop_msg msg;
+    memset(&msg, 0, sizeof msg);
+    msg.cmd = PROP_MSG_SETPROP;
+    strlcpy(msg.name, key, sizeof msg.name);
+    strlcpy(msg.value, value, sizeof msg.value);
+
+    const int err = send_prop_msg(&msg);
+    if (err < 0) {
+        return err;
+    }
+
+    return 0;
+}
+
+int __system_property_wait(const prop_info *pi)
+{
+    if (pi == 0) {
+        prop_area *pa = __system_property_area__;
+        const uint32_t n = pa->serial;
+        do {
+            __futex_wait(&pa->serial, n, NULL);
+        } while (n == pa->serial);
+    } else {
+        const uint32_t n = pi->serial;
+        do {
+            __futex_wait((volatile void *)&pi->serial, n, NULL);
+        } while(n == pi->serial);
+    }
+    return 0;
+}
+
+int __system_property_update(prop_info *pi, const char *value, unsigned int len)
+{
+    prop_area *pa = __system_property_area__;
+
+    if (len >= PROP_VALUE_MAX)
+        return -1;
+
+    pi->serial = pi->serial | 1;
+    ANDROID_MEMBAR_FULL();
+    memcpy(pi->value, value, len + 1);
+    ANDROID_MEMBAR_FULL();
+    pi->serial = (len << 24) | ((pi->serial + 1) & 0xffffff);
+    __futex_wake(&pi->serial, INT32_MAX);
+
+    pa->serial++;
+    __futex_wake(&pa->serial, INT32_MAX);
+
+    return 0;
+}
+int __system_property_add(const char *name, unsigned int namelen,
+            const char *value, unsigned int valuelen)
+{
+    prop_area *pa = __system_property_area__;
+    const prop_info *pi;
+
+    if (namelen >= PROP_NAME_MAX)
+        return -1;
+    if (valuelen >= PROP_VALUE_MAX)
+        return -1;
+    if (namelen < 1)
+        return -1;
+
+    pi = find_property(root_node(), name, namelen, value, valuelen, true);
+    if (!pi)
+        return -1;
+
+    pa->serial++;
+    __futex_wake(&pa->serial, INT32_MAX);
+    return 0;
+}
+
+unsigned int __system_property_serial(const prop_info *pi)
+{
+    return pi->serial;
+}
+
+unsigned int __system_property_wait_any(unsigned int serial)
+{
+    prop_area *pa = __system_property_area__;
+
+    do {
+        __futex_wait(&pa->serial, serial, NULL);
+    } while(pa->serial == serial);
+
+    return pa->serial;
+}
+
+const prop_info *__system_property_find_nth(unsigned n)
+{
+    find_nth_cookie cookie(n);
+
+    const int err = __system_property_foreach(find_nth_fn, &cookie);
+    if (err < 0) {
+        return NULL;
+    }
+
+    return cookie.pi;
+}
+
+int __system_property_foreach(void (*propfn)(const prop_info *pi, void *cookie),
+        void *cookie)
+{
+    if (__predict_false(compat_mode)) {
+        return __system_property_foreach_compat(propfn, cookie);
+    }
+
+    return foreach_property(0, propfn, cookie);
+}
diff --git a/libc/include/limits.h b/libc/include/limits.h
index b9d4354..471d380 100644
--- a/libc/include/limits.h
+++ b/libc/include/limits.h
@@ -105,9 +105,15 @@
 #define ULONG_LONG_MAX  ULLONG_MAX
 #endif
 
+/* New code should use sysconf(_SC_PAGE_SIZE) instead. */
+#ifndef PAGE_SIZE
+#define PAGE_SIZE 4096
+#endif
 #ifndef PAGESIZE
-#include <asm/page.h>
 #define  PAGESIZE  PAGE_SIZE
 #endif
 
+/* glibc's PAGE_MASK is the bitwise negation of BSD's! TODO: remove? */
+#define PAGE_MASK (~(PAGE_SIZE - 1))
+
 #endif /* !_LIMITS_H_ */
diff --git a/libc/include/sys/_system_properties.h b/libc/include/sys/_system_properties.h
index 5eee7f0..5a681df 100644
--- a/libc/include/sys/_system_properties.h
+++ b/libc/include/sys/_system_properties.h
@@ -139,6 +139,14 @@
         void (*propfn)(const prop_info *pi, void *cookie),
         void *cookie);
 
+/* Initialize the system properties area in read only mode.
+ * Should be done by all processes that need to read system
+ * properties.
+ *
+ * Returns 0 on success, -1 otherwise.
+ */
+int __system_properties_init();
+
 __END_DECLS
 
 #endif
diff --git a/libc/include/sys/mman.h b/libc/include/sys/mman.h
index 7c5f8d7..5a8c985 100644
--- a/libc/include/sys/mman.h
+++ b/libc/include/sys/mman.h
@@ -31,7 +31,6 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 #include <asm/mman.h>
-#include <asm/page.h>
 
 __BEGIN_DECLS
 
@@ -44,23 +43,23 @@
 #define MREMAP_MAYMOVE  1
 #define MREMAP_FIXED    2
 
-extern void*  mmap(void *, size_t, int, int, int, off_t);
-extern void*  mmap64(void *, size_t, int, int, int, off64_t);
-extern int    munmap(void *, size_t);
-extern int    msync(const void *, size_t, int);
-extern int    mprotect(const void *, size_t, int);
-extern void*  mremap(void *, size_t, size_t, unsigned long);
+extern void* mmap(void*, size_t, int, int, int, off_t);
+extern void* mmap64(void*, size_t, int, int, int, off64_t);
+extern int munmap(void*, size_t);
+extern int msync(const void*, size_t, int);
+extern int mprotect(const void*, size_t, int);
+extern void* mremap(void*, size_t, size_t, unsigned long);
 
-extern int    mlockall(int);
-extern int    munlockall(void);
-extern int    mlock(const void *, size_t);
-extern int    munlock(const void *, size_t);
-extern int    madvise(const void *, size_t, int);
+extern int mlockall(int);
+extern int munlockall(void);
+extern int mlock(const void*, size_t);
+extern int munlock(const void*, size_t);
+extern int madvise(const void*, size_t, int);
 
-extern int    mlock(const void *addr, size_t len);
-extern int    munlock(const void *addr, size_t len);
+extern int mlock(const void*, size_t);
+extern int munlock(const void*, size_t);
 
-extern int    mincore(void*  start, size_t  length, unsigned char*  vec);
+extern int mincore(void*, size_t, unsigned char*);
 
 __END_DECLS
 
diff --git a/libc/include/sys/user.h b/libc/include/sys/user.h
index 90cce80..e16b1a5 100644
--- a/libc/include/sys/user.h
+++ b/libc/include/sys/user.h
@@ -30,6 +30,7 @@
 #define _SYS_USER_H_
 
 #include <sys/cdefs.h>
+#include <limits.h> /* For PAGE_SIZE. */
 
 __BEGIN_DECLS
 
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index 70cc4c5..d21f23d 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -64,6 +64,7 @@
 
 extern int execv(const char *, char * const *);
 extern int execvp(const char *, char * const *);
+extern int execvpe(const char *, char * const *, char * const *);
 extern int execve(const char *, char * const *, char * const *);
 extern int execl(const char *, const char *, ...);
 extern int execlp(const char *, const char *, ...);
@@ -194,7 +195,6 @@
 extern int   tcsetpgrp(int fd, pid_t _pid);
 
 #if 0 /* MISSING FROM BIONIC */
-extern int execvpe(const char *, char * const *, char * const *);
 extern int execlpe(const char *, const char *, ...);
 extern int getfsuid(uid_t);
 extern int setfsuid(uid_t);
diff --git a/libc/netbsd/resolv/res_compat.c b/libc/netbsd/resolv/res_compat.c
deleted file mode 100644
index 19a1d5f..0000000
--- a/libc/netbsd/resolv/res_compat.c
+++ /dev/null
@@ -1,87 +0,0 @@
-/*	$NetBSD: res_compat.c,v 1.1 2004/06/09 18:07:03 christos Exp $	*/
-
-/*-
- * Copyright (c) 2004 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Christos Zoulas.
- *
- * 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. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *        This product includes software developed by the NetBSD
- *        Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: res_compat.c,v 1.1 2004/06/09 18:07:03 christos Exp $");
-#endif
-
-#include <sys/types.h>
-#include <arpa/inet.h>
-#include "arpa_nameser.h"
-#include <netdb.h>
-#include <string.h>
-#define __OLD_RES_STATE
-#ifdef ANDROID_CHANGES
-#include "resolv_private.h"
-#else
-#include "resolv.h"
-#endif
-
-#undef _res
-
-/*
- * Binary Compatibility; this symbol does not appear in a header file
- * Most userland programs use this to set res_options before res_init()
- * is called. There are hooks to res_init() to consult the data in this
- * structure. The hooks are provided indirectly by the two functions below.
- * We depend on the fact the the first 440 [32 bit machines] bytes are
- * shared between the two structures.
- */
-#ifndef __BIND_NOSTATIC
-struct __res_state _res
-#if defined(__BIND_RES_TEXT)
-	= { RES_TIMEOUT, }      /* Motorola, et al. */
-# endif
-;
-
-void *__res_get_old_state(void);
-void __res_put_old_state(void *);
-
-void *
-__res_get_old_state(void)
-{
-	return &_res;
-}
-
-void
-__res_put_old_state(void *res)
-{
-	(void)memcpy(&_res, res, sizeof(_res));
-}
-#endif
diff --git a/libc/netbsd/resolv/res_random.c b/libc/netbsd/resolv/res_random.c
deleted file mode 100644
index 4570c4f..0000000
--- a/libc/netbsd/resolv/res_random.c
+++ /dev/null
@@ -1,275 +0,0 @@
-/* $OpenBSD: res_random.c,v 1.17 2008/04/13 00:28:35 djm Exp $ */
-
-/*
- * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
- * Copyright 2008 Damien Miller <djm@openbsd.org>
- * Copyright 2008 Android Open Source Project (thread-safety)
- * All rights reserved.
- *
- * Theo de Raadt <deraadt@openbsd.org> came up with the idea of using
- * such a mathematical system to generate more random (yet non-repeating)
- * ids to solve the resolver/named problem.  But Niels designed the
- * actual system based on the constraints.
- *
- * Later modified by Damien Miller to wrap the LCG output in a 15-bit
- * permutation generator based on a Luby-Rackoff block cipher. This
- * ensures the output is non-repeating and preserves the MSB twiddle
- * trick, but makes it more resistant to LCG prediction.
- *
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
- */
-
-/*
- * seed = random 15bit
- * n = prime, g0 = generator to n,
- * j = random so that gcd(j,n-1) == 1
- * g = g0^j mod n will be a generator again.
- *
- * X[0] = random seed.
- * X[n] = a*X[n-1]+b mod m is a Linear Congruential Generator
- * with a = 7^(even random) mod m,
- *      b = random with gcd(b,m) == 1
- *      m = 31104 and a maximal period of m-1.
- *
- * The transaction id is determined by:
- * id[n] = seed xor (g^X[n] mod n)
- *
- * Effectivly the id is restricted to the lower 15 bits, thus
- * yielding two different cycles by toggling the msb on and off.
- * This avoids reuse issues caused by reseeding.
- *
- * The output of this generator is then randomly permuted though a
- * custom 15 bit Luby-Rackoff block cipher.
- */
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <sys/time.h>
-#include "resolv_private.h"
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-
-/* BIONIC-BEGIN */
-static pthread_mutex_t         _res_random_lock = PTHREAD_MUTEX_INITIALIZER;
-#define  _RES_RANDOM_LOCK()    pthread_mutex_lock(&_res_random_lock)
-#define  _RES_RANDOM_UNLOCK()  pthread_mutex_unlock(&_res_random_lock)
-/* BIONIC-END */
-
-#define RU_OUT  	180	/* Time after wich will be reseeded */
-#define RU_MAX		30000	/* Uniq cycle, avoid blackjack prediction */
-#define RU_GEN		2	/* Starting generator */
-#define RU_N		32749	/* RU_N-1 = 2*2*3*2729 */
-#define RU_AGEN		7	/* determine ru_a as RU_AGEN^(2*rand) */
-#define RU_M		31104	/* RU_M = 2^7*3^5 - don't change */
-#define RU_ROUNDS	11	/* Number of rounds for permute (odd) */
-
-struct prf_ctx {
-	/* PRF lookup table for odd rounds (7 bits input to 8 bits output) */
-	u_char prf7[(RU_ROUNDS / 2) * (1 << 7)];
-
-	/* PRF lookup table for even rounds (8 bits input to 7 bits output) */
-	u_char prf8[((RU_ROUNDS + 1) / 2) * (1 << 8)];
-};
-
-#define PFAC_N 3
-const static u_int16_t pfacts[PFAC_N] = {
-	2,
-	3,
-	2729
-};
-
-static u_int16_t ru_x;
-static u_int16_t ru_seed, ru_seed2;
-static u_int16_t ru_a, ru_b;
-static u_int16_t ru_g;
-static u_int16_t ru_counter = 0;
-static u_int16_t ru_msb = 0;
-static struct prf_ctx *ru_prf = NULL;
-static long ru_reseed;
-
-static u_int16_t pmod(u_int16_t, u_int16_t, u_int16_t);
-static void res_initid(void);
-
-/*
- * Do a fast modular exponation, returned value will be in the range
- * of 0 - (mod-1)
- */
-static u_int16_t
-pmod(u_int16_t gen, u_int16_t exp, u_int16_t mod)
-{
-	u_int16_t s, t, u;
-
-	s = 1;
-	t = gen;
-	u = exp;
-
-	while (u) {
-		if (u & 1)
-			s = (s * t) % mod;
-		u >>= 1;
-		t = (t * t) % mod;
-	}
-	return (s);
-}
-
-/*
- * 15-bit permutation based on Luby-Rackoff block cipher
- */
-u_int
-permute15(u_int in)
-{
-	int i;
-	u_int left, right, tmp;
-
-	if (ru_prf == NULL)
-		return in;
-
-	left = (in >> 8) & 0x7f;
-	right = in & 0xff;
-
-	/*
-	 * Each round swaps the width of left and right. Even rounds have
-	 * a 7-bit left, odd rounds have an 8-bit left.	Since this uses an
-	 * odd number of rounds, left is always 8 bits wide at the end.
-	 */
-	for (i = 0; i < RU_ROUNDS; i++) {
-		if ((i & 1) == 0)
-			tmp = ru_prf->prf8[(i << (8 - 1)) | right] & 0x7f;
-		else
-			tmp = ru_prf->prf7[((i - 1) << (7 - 1)) | right];
-		tmp ^= left;
-		left = right;
-		right = tmp;
-	}
-
-	return (right << 8) | left;
-}
-
-/*
- * Initializes the seed and chooses a suitable generator. Also toggles
- * the msb flag. The msb flag is used to generate two distinct
- * cycles of random numbers and thus avoiding reuse of ids.
- *
- * This function is called from res_randomid() when needed, an
- * application does not have to worry about it.
- */
-static void
-res_initid(void)
-{
-	u_int16_t j, i;
-	u_int32_t tmp;
-	int noprime = 1;
-	struct timeval tv;
-
-	ru_x = arc4random_uniform(RU_M);
-
-	/* 15 bits of random seed */
-	tmp = arc4random();
-	ru_seed = (tmp >> 16) & 0x7FFF;
-	ru_seed2 = tmp & 0x7FFF;
-
-	/* Determine the LCG we use */
-	tmp = arc4random();
-	ru_b = (tmp & 0xfffe) | 1;
-	ru_a = pmod(RU_AGEN, (tmp >> 16) & 0xfffe, RU_M);
-	while (ru_b % 3 == 0)
-		ru_b += 2;
-
-	j = arc4random_uniform(RU_N);
-
-	/*
-	 * Do a fast gcd(j,RU_N-1), so we can find a j with
-	 * gcd(j, RU_N-1) == 1, giving a new generator for
-	 * RU_GEN^j mod RU_N
-	 */
-
-	while (noprime) {
-		for (i = 0; i < PFAC_N; i++)
-			if (j % pfacts[i] == 0)
-				break;
-
-		if (i >= PFAC_N)
-			noprime = 0;
-		else
-			j = (j + 1) % RU_N;
-	}
-
-	ru_g = pmod(RU_GEN, j, RU_N);
-	ru_counter = 0;
-
-	/* Initialise PRF for Luby-Rackoff permutation */
-	if (ru_prf == NULL)
-		ru_prf = malloc(sizeof(*ru_prf));
-	if (ru_prf != NULL)
-		arc4random_buf(ru_prf, sizeof(*ru_prf));
-
-	gettimeofday(&tv, NULL);
-	ru_reseed = tv.tv_sec + RU_OUT;
-	ru_msb = ru_msb == 0x8000 ? 0 : 0x8000;
-}
-
-u_int
-res_randomid(void)
-{
-	struct timeval tv;
-        u_int  result;
-
-        _RES_RANDOM_LOCK()
-	gettimeofday(&tv, NULL);
-	if (ru_counter >= RU_MAX || tv.tv_sec > ru_reseed)
-		res_initid();
-
-	/* Linear Congruential Generator */
-	ru_x = (ru_a * ru_x + ru_b) % RU_M;
-	ru_counter++;
-
-	result = permute15(ru_seed ^ pmod(ru_g, ru_seed2 + ru_x, RU_N)) | ru_msb;
-        _RES_RANDOM_UNLOCK()
-        return result;
-}
-
-#if 0
-int
-main(int argc, char **argv)
-{
-	int i, n;
-	u_int16_t wert;
-
-	res_initid();
-
-	printf("Generator: %u\n", ru_g);
-	printf("Seed: %u\n", ru_seed);
-	printf("Reseed at %ld\n", ru_reseed);
-	printf("Ru_X: %u\n", ru_x);
-	printf("Ru_A: %u\n", ru_a);
-	printf("Ru_B: %u\n", ru_b);
-
-	n = argc > 1 ? atoi(argv[1]) : 60001;
-	for (i=0;i<n;i++) {
-		wert = res_randomid();
-		printf("%u\n", wert);
-	}
-	return 0;
-}
-#endif
-
diff --git a/libc/private/bionic_asm.h b/libc/private/bionic_asm.h
index 803ff29..7c2686f 100644
--- a/libc/private/bionic_asm.h
+++ b/libc/private/bionic_asm.h
@@ -29,15 +29,32 @@
 #ifndef _PRIVATE_BIONIC_ASM_H_
 #define _PRIVATE_BIONIC_ASM_H_
 
-#if !defined(__mips__)
-/* <machine/asm.h> causes trouble on mips by including regdefs.h. */
-#include <machine/asm.h>
-#endif
-
 #include <asm/unistd.h> /* For system call numbers. */
 #define MAX_ERRNO 4095  /* For recognizing system call error returns. */
 
-/* TODO: add ENTRY_PRIVATE. */
-/* TODO: add ASM_ALIAS macro. */
+#define __bionic_asm_custom_entry(f)
+#define __bionic_asm_custom_end(f)
+#define __bionic_asm_function_type @function
+
+#include <machine/asm.h>
+
+#define ENTRY(f) \
+    .text; \
+    .globl f; \
+    _ALIGN_TEXT; \
+    .type f, __bionic_asm_function_type; \
+    f: \
+    __bionic_asm_custom_entry(f); \
+    .cfi_startproc \
+
+#define END(f) \
+    .cfi_endproc; \
+    .size f, .-f; \
+    __bionic_asm_custom_end(f) \
+
+/* Like ENTRY, but with hidden visibility. */
+#define ENTRY_PRIVATE(f) \
+    ENTRY(f); \
+    .hidden f \
 
 #endif /* _PRIVATE_BIONIC_ASM_H_ */
diff --git a/libc/stdlib/strtoll.c b/libc/stdlib/strtoll.c
deleted file mode 100644
index 3c75271..0000000
--- a/libc/stdlib/strtoll.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/* $OpenBSD: strtoll.c,v 1.6 2005/11/10 10:00:17 espie Exp $ */
-/*-
- * Copyright (c) 1992 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.
- */
-
-#include <sys/types.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <inttypes.h>
-
-/*
- * Convert a string to a long long.
- *
- * Ignores `locale' stuff.  Assumes that the upper and lower case
- * alphabets and digits are each contiguous.
- */
-long long
-strtoll(const char *nptr, char **endptr, int base)
-{
-    return strtoimax(nptr, endptr, base);
-}
-
diff --git a/libc/stdlib/strtoull.c b/libc/stdlib/strtoull.c
deleted file mode 100644
index 36698ac..0000000
--- a/libc/stdlib/strtoull.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*	$OpenBSD: strtoull.c,v 1.5 2005/08/08 08:05:37 espie Exp $ */
-/*-
- * Copyright (c) 1992 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.
- */
-
-#include <sys/types.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <inttypes.h>
-
-/*
- * Convert a string to an unsigned long long.
- *
- * Ignores `locale' stuff.  Assumes that the upper and lower case
- * alphabets and digits are each contiguous.
- */
-unsigned long long
-strtoull(const char *nptr, char **endptr, int base)
-{
-    return (unsigned long long)strtoumax(nptr, endptr, base);
-}
diff --git a/libc/tools/genlibgcc_compat.py b/libc/tools/genlibgcc_compat.py
new file mode 100755
index 0000000..f2ff7b0
--- /dev/null
+++ b/libc/tools/genlibgcc_compat.py
@@ -0,0 +1,144 @@
+#!/usr/bin/python
+
+'''
+/* This file generates libgcc_compat.c file that contains dummy
+ * references to libgcc.a functions to force the dynamic linker
+ * to copy their definition into the final libc.so binary.
+ *
+ * They are required to ensure backwards binary compatibility with
+ * libc.so provided by the platform and binaries built with the NDK or
+ * different versions/configurations of toolchains.
+ *
+ * Now, for a more elaborate description of the issue:
+ *
+ * libgcc.a is a compiler-specific library containing various helper
+ * functions used to implement certain operations that are not necessarily
+ * supported by the target CPU. For example, integer division doesn't have a
+ * corresponding CPU instruction on ARMv5, and is instead implemented in the
+ * compiler-generated machine code as a call to an __idiv helper function.
+ *
+ * Normally, one has to place libgcc.a in the link command used to generate
+ * target binaries (shared libraries and executables) after all objects and
+ * static libraries, but before dependent shared libraries, i.e. something
+ * like:
+ *         gcc <options> -o libfoo.so  foo.a libgcc.a -lc -lm
+ *
+ * This ensures that any helper function needed by the code in foo.a is copied
+ * into the final libfoo.so. However, doing so will link a bunch of other __cxa
+ * functions from libgcc.a into each .so and executable, causing 4k+ increase
+ * in every binary. Therefore the Android platform build system has been
+ * using this instead:
+ *
+ *         gcc <options> -o libfoo.so foo.a -lc -lm libgcc.a
+ *
+ * The problem with this is that if one helper function needed by foo.a has
+ * already been copied into libc.so or libm.so, then nothing will be copied
+ * into libfoo.so. Instead, a symbol import definition will be added to it
+ * so libfoo.so can directly call the one in libc.so at runtime.
+ *
+ * When refreshing toolchains for new versions or using different architecture
+ * flags, the set of helper functions copied to libc.so may change, which
+ * resulted in some native shared libraries generated with the NDK or prebuilts
+ * from vendors to fail to load properly.
+ *
+ * The NDK has been fixed after 1.6_r1 to use the correct link command, so
+ * any native shared library generated with it should now be safe from that
+ * problem. On the other hand, existing shared libraries distributed with
+ * applications that were generated with a previous version of the NDK
+ * still need all 1.5/1.6 helper functions in libc.so and libm.so
+ *
+ * After 3.2, the toolchain was updated again, adding __aeabi_f2uiz to the
+ * list of requirements. Technically, this is due to mis-linked NDK libraries
+ * but it is easier to add a single function here than asking several app
+ * developers to fix their build.
+ *
+ * The __aeabi_idiv function is added to the list since cortex-a15 supports
+ * HW idiv instructions so the system libc.so doesn't pull in the reference to
+ * __aeabi_idiv but legacy libraries built against cortex-a9 targets still need
+ * it.
+ *
+ * Final note: some of the functions below should really be in libm.so to
+ *             completely reflect the state of 1.5/1.6 system images. However,
+ *             since libm.so depends on libc.so, it's easier to put all of
+ *             these in libc.so instead, since the dynamic linker will always
+ *             search in libc.so before libm.so for dependencies.
+ */
+'''
+
+import os
+import sys
+import subprocess
+import tempfile
+import re
+
+libgcc_compat_header = "/* Generated by genlibgcc_compat.py */\n" + \
+"""
+#define   COMPAT_FUNCTIONS_LIST \\
+"""
+
+libgcc_compat_footer = """
+
+#define  XX(f)    extern void f(void);
+COMPAT_FUNCTIONS_LIST
+#undef XX
+
+void __bionic_libgcc_compat_hooks(void) {
+#define XX(f)    f();
+COMPAT_FUNCTIONS_LIST
+#undef XX
+}
+"""
+
+class Generator:
+    def process(self):
+        android_build_top_path = os.environ["ANDROID_BUILD_TOP"]
+        build_path =  android_build_top_path + "/bionic/libc"
+        file_name = "libgcc_compat.c"
+        file_path = build_path + "/arch-arm/bionic/" + file_name
+
+        print "* ANDROID_BUILD_TOP=" + android_build_top_path
+
+        # Check TARGET_ARCH
+        arch = subprocess.check_output(["CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core make --no-print-directory -f build/core/config.mk dumpvar-TARGET_ARCH"],
+                    cwd=android_build_top_path, shell=True).strip()
+
+        if arch != 'arm':
+            sys.exit("Error: Invalid TARGET_ARCH='" + arch + "' expecting 'arm'")
+
+        build_output_file_path = tempfile.mkstemp()[1]
+
+        p = subprocess.Popen(["ONE_SHOT_MAKEFILE=bionic/libc/Android.mk make -C " + android_build_top_path
+                    + " -f build/core/main.mk all_modules TARGET_LIBGCC= -j20 -B 2>&1 | tee " + build_output_file_path],
+                    cwd=build_path, shell=True)
+        p.wait()
+
+        print "* Build complete, logfile: " + build_output_file_path
+
+        func_set = set()
+        prog=re.compile("(?<=undefined reference to ')\w+")
+        fd = open(build_output_file_path, 'r')
+        for line in fd:
+            m = prog.search(line)
+            if m:
+                func_set.add(m.group(0))
+
+        fd.close()
+
+        func_list = sorted(func_set)
+
+        print "* Found " + repr(len(func_list)) + " referenced functions: " + repr(func_list)
+
+        if 0 == len(func_list):
+            sys.exit("Error: function list is empty, please check the build log: " + build_output_file_path)
+
+        print "* Generating " + file_path
+        fres = open(file_path, 'w')
+        fres.write(libgcc_compat_header)
+        for func_name in func_list:
+            fres.write("    XX("+func_name+") \\\n")
+        fres.write(libgcc_compat_footer)
+        fres.close()
+
+generator = Generator()
+generator.process()
+
diff --git a/libc/tools/gensyscalls.py b/libc/tools/gensyscalls.py
index 6388ee1..8a5f3d2 100755
--- a/libc/tools/gensyscalls.py
+++ b/libc/tools/gensyscalls.py
@@ -118,29 +118,21 @@
 # MIPS assembler templates for each syscall stub
 #
 
-mips_call = "/* " + warning + " */\n" + \
-"""
-#include <asm/unistd.h>
-    .text
-    .globl %(func)s
-    .align 4
-    .ent %(func)s
-
-%(func)s:
+mips_call = syscall_stub_header + """\
     .set noreorder
-    .cpload $t9
-    li $v0, %(__NR_name)s
+    .cpload t9
+    li v0, %(__NR_name)s
     syscall
-    bnez $a3, 1f
-    move $a0, $v0
-    j $ra
+    bnez a3, 1f
+    move a0, v0
+    j ra
     nop
 1:
-    la $t9,__set_errno
-    j $t9
+    la t9,__set_errno
+    j t9
     nop
     .set reorder
-    .end %(func)s
+END(%(func)s)
 """
 
 
@@ -148,17 +140,7 @@
 # MIPS64 assembler templates for each syscall stub
 #
 
-mips64_call = "/* " + warning + " */\n" + \
-"""
-#include <asm/unistd.h>
-#include <machine/asm.h>
-#include <machine/regdef.h>
-    .text
-    .globl %(func)s
-    .align 4
-    .ent %(func)s
-
-%(func)s:
+mips64_call = syscall_stub_header + """\
     .set push
     .set noreorder
     li v0, %(__NR_name)s
@@ -178,7 +160,7 @@
     j t9
     move ra, t0
     .set pop
-    .end %(func)s
+END(%(func)s)
 """
 
 
@@ -306,7 +288,7 @@
 
     # Use hidden visibility for any functions beginning with underscores.
     if pointer_length == 64 and syscall["func"].startswith("__"):
-        stub += '.hidden _C_LABEL(' + syscall["func"] + ')\n'
+        stub += '.hidden ' + syscall["func"] + '\n'
 
     return stub
 
diff --git a/libc/upstream-freebsd/lib/libc/stdio/clrerr.c b/libc/upstream-freebsd/lib/libc/stdio/clrerr.c
deleted file mode 100644
index f161a6e..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/clrerr.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)clrerr.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "libc_private.h"
-
-#undef clearerr
-#undef clearerr_unlocked
-
-void
-clearerr(FILE *fp)
-{
-	FLOCKFILE(fp);
-	__sclearerr(fp);
-	FUNLOCKFILE(fp);
-}
-
-void
-clearerr_unlocked(FILE *fp)
-{
-
-	__sclearerr(fp);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/feof.c b/libc/upstream-freebsd/lib/libc/stdio/feof.c
deleted file mode 100644
index b970248..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/feof.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)feof.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "libc_private.h"
-
-#undef feof
-#undef feof_unlocked
-
-int
-feof(FILE *fp)
-{
-	int	ret;
-
-	FLOCKFILE(fp);
-	ret= __sfeof(fp);
-	FUNLOCKFILE(fp);
-	return (ret);
-}
-
-int
-feof_unlocked(FILE *fp)
-{
-
-	return (__sfeof(fp));
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/ferror.c b/libc/upstream-freebsd/lib/libc/stdio/ferror.c
deleted file mode 100644
index 7e0f8f9..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/ferror.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)ferror.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "libc_private.h"
-
-#undef ferror
-#undef ferror_unlocked
-
-int
-ferror(FILE *fp)
-{
-	int	ret;
-
-	FLOCKFILE(fp);
-	ret = __sferror(fp);
-	FUNLOCKFILE(fp);
-	return (ret);
-}
-
-int
-ferror_unlocked(FILE *fp)
-{
-
-	return (__sferror(fp));
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fgetpos.c b/libc/upstream-freebsd/lib/libc/stdio/fgetpos.c
deleted file mode 100644
index f161f43..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/fgetpos.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fgetpos.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdio.h>
-
-int
-fgetpos(FILE * __restrict fp, fpos_t * __restrict pos)
-{
-	/*
-	 * ftello is thread-safe; no need to lock fp.
-	 */
-	if ((*pos = ftello(fp)) == (fpos_t)-1)
-		return (-1);
-	else
-		return (0);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fileno.c b/libc/upstream-freebsd/lib/libc/stdio/fileno.c
deleted file mode 100644
index 3ac1830..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/fileno.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fileno.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "libc_private.h"
-
-#undef fileno
-#undef fileno_unlocked
-
-int
-fileno(FILE *fp)
-{
-	int fd;
-
-	FLOCKFILE(fp);
-	fd = __sfileno(fp);
-	FUNLOCKFILE(fp);
-
-	return (fd);
-}
-
-int
-fileno_unlocked(FILE *fp)
-{
-
-	return (__sfileno(fp));
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fwalk.c b/libc/upstream-freebsd/lib/libc/stdio/fwalk.c
deleted file mode 100644
index 151837b..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/fwalk.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fwalk.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <stdio.h>
-#include "local.h"
-#include "glue.h"
-
-int
-_fwalk(int (*function)(FILE *))
-{
-	FILE *fp;
-	int n, ret;
-	struct glue *g;
-
-	ret = 0;
-	/*
-	 * It should be safe to walk the list without locking it;
-	 * new nodes are only added to the end and none are ever
-	 * removed.
-	 *
-	 * Avoid locking this list while walking it or else you will
-	 * introduce a potential deadlock in [at least] refill.c.
-	 */
-	for (g = &__sglue; g != NULL; g = g->next)
-		for (fp = g->iobs, n = g->niobs; --n >= 0; fp++)
-			if ((fp->_flags != 0) && ((fp->_flags & __SIGN) == 0))
-				ret |= (*function)(fp);
-	return (ret);
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/getc.c b/libc/upstream-freebsd/lib/libc/stdio/getc.c
deleted file mode 100644
index 4963c8c..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/getc.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getc.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "libc_private.h"
-#include "local.h"
-
-#undef getc
-#undef getc_unlocked
-
-int
-getc(FILE *fp)
-{
-	int retval;
-	FLOCKFILE(fp);
-	/* Orientation set by __sgetc() when buffer is empty. */
-	/* ORIENT(fp, -1); */
-	retval = __sgetc(fp);
-	FUNLOCKFILE(fp);
-	return (retval);
-}
-
-int
-getc_unlocked(FILE *fp)
-{
-
-	return (__sgetc(fp));
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/getchar.c b/libc/upstream-freebsd/lib/libc/stdio/getchar.c
deleted file mode 100644
index 21040bc..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/getchar.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getchar.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/*
- * A subroutine version of the macro getchar.
- */
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "local.h"
-#include "libc_private.h"
-
-#undef getchar
-#undef getchar_unlocked
-
-int
-getchar()
-{
-	int retval;
-	FLOCKFILE(stdin);
-	/* Orientation set by __sgetc() when buffer is empty. */
-	/* ORIENT(stdin, -1); */
-	retval = __sgetc(stdin);
-	FUNLOCKFILE(stdin);
-	return (retval);
-}
-
-int
-getchar_unlocked(void)
-{
-
-	return (__sgetc(stdin));
-}
diff --git a/libc/upstream-freebsd/lib/libc/stdio/putchar.c b/libc/upstream-freebsd/lib/libc/stdio/putchar.c
deleted file mode 100644
index 7561559..0000000
--- a/libc/upstream-freebsd/lib/libc/stdio/putchar.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)putchar.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
-#include <stdio.h>
-#include "un-namespace.h"
-#include "local.h"
-#include "libc_private.h"
-
-#undef putchar
-#undef putchar_unlocked
-
-/*
- * A subroutine version of the macro putchar
- */
-int
-putchar(int c)
-{
-	int retval;
-	FILE *so = stdout;
-
-	FLOCKFILE(so);
-	/* Orientation set by __sputc() when buffer is full. */
-	/* ORIENT(so, -1); */
-	retval = __sputc(c, so);
-	FUNLOCKFILE(so);
-	return (retval);
-}
-
-int
-putchar_unlocked(int ch)
-{
-
-	return (__sputc(ch, stdout));
-}
diff --git a/libc/upstream-netbsd/libc/gen/ftw.c b/libc/upstream-netbsd/lib/libc/gen/ftw.c
similarity index 100%
rename from libc/upstream-netbsd/libc/gen/ftw.c
rename to libc/upstream-netbsd/lib/libc/gen/ftw.c
diff --git a/libc/upstream-netbsd/libc/gen/nftw.c b/libc/upstream-netbsd/lib/libc/gen/nftw.c
similarity index 100%
rename from libc/upstream-netbsd/libc/gen/nftw.c
rename to libc/upstream-netbsd/lib/libc/gen/nftw.c
diff --git a/libc/upstream-netbsd/libc/gen/nice.c b/libc/upstream-netbsd/lib/libc/gen/nice.c
similarity index 100%
rename from libc/upstream-netbsd/libc/gen/nice.c
rename to libc/upstream-netbsd/lib/libc/gen/nice.c
diff --git a/libc/upstream-netbsd/libc/gen/popen.c b/libc/upstream-netbsd/lib/libc/gen/popen.c
similarity index 100%
rename from libc/upstream-netbsd/libc/gen/popen.c
rename to libc/upstream-netbsd/lib/libc/gen/popen.c
diff --git a/libc/upstream-netbsd/libc/gen/psignal.c b/libc/upstream-netbsd/lib/libc/gen/psignal.c
similarity index 100%
rename from libc/upstream-netbsd/libc/gen/psignal.c
rename to libc/upstream-netbsd/lib/libc/gen/psignal.c
diff --git a/libc/upstream-netbsd/libc/gen/setjmperr.c b/libc/upstream-netbsd/lib/libc/gen/setjmperr.c
similarity index 100%
rename from libc/upstream-netbsd/libc/gen/setjmperr.c
rename to libc/upstream-netbsd/lib/libc/gen/setjmperr.c
diff --git a/libc/upstream-netbsd/libc/gen/utime.c b/libc/upstream-netbsd/lib/libc/gen/utime.c
similarity index 100%
rename from libc/upstream-netbsd/libc/gen/utime.c
rename to libc/upstream-netbsd/lib/libc/gen/utime.c
diff --git a/libc/upstream-netbsd/libc/include/isc/assertions.h b/libc/upstream-netbsd/lib/libc/include/isc/assertions.h
similarity index 100%
rename from libc/upstream-netbsd/libc/include/isc/assertions.h
rename to libc/upstream-netbsd/lib/libc/include/isc/assertions.h
diff --git a/libc/upstream-netbsd/libc/include/isc/dst.h b/libc/upstream-netbsd/lib/libc/include/isc/dst.h
similarity index 100%
rename from libc/upstream-netbsd/libc/include/isc/dst.h
rename to libc/upstream-netbsd/lib/libc/include/isc/dst.h
diff --git a/libc/upstream-netbsd/libc/include/isc/eventlib.h b/libc/upstream-netbsd/lib/libc/include/isc/eventlib.h
similarity index 100%
rename from libc/upstream-netbsd/libc/include/isc/eventlib.h
rename to libc/upstream-netbsd/lib/libc/include/isc/eventlib.h
diff --git a/libc/upstream-netbsd/libc/include/isc/heap.h b/libc/upstream-netbsd/lib/libc/include/isc/heap.h
similarity index 100%
rename from libc/upstream-netbsd/libc/include/isc/heap.h
rename to libc/upstream-netbsd/lib/libc/include/isc/heap.h
diff --git a/libc/upstream-netbsd/libc/include/isc/list.h b/libc/upstream-netbsd/lib/libc/include/isc/list.h
similarity index 100%
rename from libc/upstream-netbsd/libc/include/isc/list.h
rename to libc/upstream-netbsd/lib/libc/include/isc/list.h
diff --git a/libc/upstream-netbsd/libc/include/isc/memcluster.h b/libc/upstream-netbsd/lib/libc/include/isc/memcluster.h
similarity index 100%
rename from libc/upstream-netbsd/libc/include/isc/memcluster.h
rename to libc/upstream-netbsd/lib/libc/include/isc/memcluster.h
diff --git a/libc/upstream-netbsd/libc/inet/inet_ntoa.c b/libc/upstream-netbsd/lib/libc/inet/inet_ntoa.c
similarity index 100%
rename from libc/upstream-netbsd/libc/inet/inet_ntoa.c
rename to libc/upstream-netbsd/lib/libc/inet/inet_ntoa.c
diff --git a/libc/upstream-netbsd/libc/inet/inet_ntop.c b/libc/upstream-netbsd/lib/libc/inet/inet_ntop.c
similarity index 100%
rename from libc/upstream-netbsd/libc/inet/inet_ntop.c
rename to libc/upstream-netbsd/lib/libc/inet/inet_ntop.c
diff --git a/libc/upstream-netbsd/libc/inet/inet_pton.c b/libc/upstream-netbsd/lib/libc/inet/inet_pton.c
similarity index 100%
rename from libc/upstream-netbsd/libc/inet/inet_pton.c
rename to libc/upstream-netbsd/lib/libc/inet/inet_pton.c
diff --git a/libc/upstream-netbsd/libc/isc/ev_streams.c b/libc/upstream-netbsd/lib/libc/isc/ev_streams.c
similarity index 100%
rename from libc/upstream-netbsd/libc/isc/ev_streams.c
rename to libc/upstream-netbsd/lib/libc/isc/ev_streams.c
diff --git a/libc/upstream-netbsd/libc/isc/ev_timers.c b/libc/upstream-netbsd/lib/libc/isc/ev_timers.c
similarity index 100%
rename from libc/upstream-netbsd/libc/isc/ev_timers.c
rename to libc/upstream-netbsd/lib/libc/isc/ev_timers.c
diff --git a/libc/upstream-netbsd/libc/isc/eventlib_p.h b/libc/upstream-netbsd/lib/libc/isc/eventlib_p.h
similarity index 100%
rename from libc/upstream-netbsd/libc/isc/eventlib_p.h
rename to libc/upstream-netbsd/lib/libc/isc/eventlib_p.h
diff --git a/libc/upstream-netbsd/libc/regex/cclass.h b/libc/upstream-netbsd/lib/libc/regex/cclass.h
similarity index 100%
rename from libc/upstream-netbsd/libc/regex/cclass.h
rename to libc/upstream-netbsd/lib/libc/regex/cclass.h
diff --git a/libc/upstream-netbsd/libc/regex/cname.h b/libc/upstream-netbsd/lib/libc/regex/cname.h
similarity index 100%
rename from libc/upstream-netbsd/libc/regex/cname.h
rename to libc/upstream-netbsd/lib/libc/regex/cname.h
diff --git a/libc/upstream-netbsd/libc/regex/engine.c b/libc/upstream-netbsd/lib/libc/regex/engine.c
similarity index 100%
rename from libc/upstream-netbsd/libc/regex/engine.c
rename to libc/upstream-netbsd/lib/libc/regex/engine.c
diff --git a/libc/upstream-netbsd/libc/regex/regcomp.c b/libc/upstream-netbsd/lib/libc/regex/regcomp.c
similarity index 100%
rename from libc/upstream-netbsd/libc/regex/regcomp.c
rename to libc/upstream-netbsd/lib/libc/regex/regcomp.c
diff --git a/libc/upstream-netbsd/libc/regex/regerror.c b/libc/upstream-netbsd/lib/libc/regex/regerror.c
similarity index 100%
rename from libc/upstream-netbsd/libc/regex/regerror.c
rename to libc/upstream-netbsd/lib/libc/regex/regerror.c
diff --git a/libc/upstream-netbsd/libc/regex/regex2.h b/libc/upstream-netbsd/lib/libc/regex/regex2.h
similarity index 100%
rename from libc/upstream-netbsd/libc/regex/regex2.h
rename to libc/upstream-netbsd/lib/libc/regex/regex2.h
diff --git a/libc/upstream-netbsd/libc/regex/regexec.c b/libc/upstream-netbsd/lib/libc/regex/regexec.c
similarity index 100%
rename from libc/upstream-netbsd/libc/regex/regexec.c
rename to libc/upstream-netbsd/lib/libc/regex/regexec.c
diff --git a/libc/upstream-netbsd/libc/regex/regfree.c b/libc/upstream-netbsd/lib/libc/regex/regfree.c
similarity index 100%
rename from libc/upstream-netbsd/libc/regex/regfree.c
rename to libc/upstream-netbsd/lib/libc/regex/regfree.c
diff --git a/libc/upstream-netbsd/libc/regex/utils.h b/libc/upstream-netbsd/lib/libc/regex/utils.h
similarity index 100%
rename from libc/upstream-netbsd/libc/regex/utils.h
rename to libc/upstream-netbsd/lib/libc/regex/utils.h
diff --git a/libc/upstream-netbsd/libc/stdlib/_rand48.c b/libc/upstream-netbsd/lib/libc/stdlib/_rand48.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/_rand48.c
rename to libc/upstream-netbsd/lib/libc/stdlib/_rand48.c
diff --git a/libc/upstream-netbsd/libc/stdlib/bsearch.c b/libc/upstream-netbsd/lib/libc/stdlib/bsearch.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/bsearch.c
rename to libc/upstream-netbsd/lib/libc/stdlib/bsearch.c
diff --git a/libc/upstream-netbsd/libc/stdlib/div.c b/libc/upstream-netbsd/lib/libc/stdlib/div.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/div.c
rename to libc/upstream-netbsd/lib/libc/stdlib/div.c
diff --git a/libc/upstream-netbsd/libc/stdlib/drand48.c b/libc/upstream-netbsd/lib/libc/stdlib/drand48.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/drand48.c
rename to libc/upstream-netbsd/lib/libc/stdlib/drand48.c
diff --git a/libc/upstream-netbsd/libc/stdlib/erand48.c b/libc/upstream-netbsd/lib/libc/stdlib/erand48.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/erand48.c
rename to libc/upstream-netbsd/lib/libc/stdlib/erand48.c
diff --git a/libc/upstream-netbsd/libc/stdlib/exit.c b/libc/upstream-netbsd/lib/libc/stdlib/exit.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/exit.c
rename to libc/upstream-netbsd/lib/libc/stdlib/exit.c
diff --git a/libc/upstream-netbsd/libc/stdlib/jrand48.c b/libc/upstream-netbsd/lib/libc/stdlib/jrand48.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/jrand48.c
rename to libc/upstream-netbsd/lib/libc/stdlib/jrand48.c
diff --git a/libc/upstream-netbsd/libc/stdlib/ldiv.c b/libc/upstream-netbsd/lib/libc/stdlib/ldiv.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/ldiv.c
rename to libc/upstream-netbsd/lib/libc/stdlib/ldiv.c
diff --git a/libc/upstream-netbsd/libc/stdlib/lldiv.c b/libc/upstream-netbsd/lib/libc/stdlib/lldiv.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/lldiv.c
rename to libc/upstream-netbsd/lib/libc/stdlib/lldiv.c
diff --git a/libc/upstream-netbsd/libc/stdlib/lrand48.c b/libc/upstream-netbsd/lib/libc/stdlib/lrand48.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/lrand48.c
rename to libc/upstream-netbsd/lib/libc/stdlib/lrand48.c
diff --git a/libc/upstream-netbsd/libc/stdlib/mrand48.c b/libc/upstream-netbsd/lib/libc/stdlib/mrand48.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/mrand48.c
rename to libc/upstream-netbsd/lib/libc/stdlib/mrand48.c
diff --git a/libc/upstream-netbsd/libc/stdlib/nrand48.c b/libc/upstream-netbsd/lib/libc/stdlib/nrand48.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/nrand48.c
rename to libc/upstream-netbsd/lib/libc/stdlib/nrand48.c
diff --git a/libc/upstream-netbsd/libc/stdlib/seed48.c b/libc/upstream-netbsd/lib/libc/stdlib/seed48.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/seed48.c
rename to libc/upstream-netbsd/lib/libc/stdlib/seed48.c
diff --git a/libc/upstream-netbsd/libc/stdlib/srand48.c b/libc/upstream-netbsd/lib/libc/stdlib/srand48.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/srand48.c
rename to libc/upstream-netbsd/lib/libc/stdlib/srand48.c
diff --git a/libc/upstream-netbsd/libc/stdlib/tdelete.c b/libc/upstream-netbsd/lib/libc/stdlib/tdelete.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/tdelete.c
rename to libc/upstream-netbsd/lib/libc/stdlib/tdelete.c
diff --git a/libc/upstream-netbsd/libc/stdlib/tfind.c b/libc/upstream-netbsd/lib/libc/stdlib/tfind.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/tfind.c
rename to libc/upstream-netbsd/lib/libc/stdlib/tfind.c
diff --git a/libc/upstream-netbsd/libc/stdlib/tsearch.c b/libc/upstream-netbsd/lib/libc/stdlib/tsearch.c
similarity index 100%
rename from libc/upstream-netbsd/libc/stdlib/tsearch.c
rename to libc/upstream-netbsd/lib/libc/stdlib/tsearch.c
diff --git a/libc/upstream-netbsd/libc/string/memccpy.c b/libc/upstream-netbsd/lib/libc/string/memccpy.c
similarity index 100%
rename from libc/upstream-netbsd/libc/string/memccpy.c
rename to libc/upstream-netbsd/lib/libc/string/memccpy.c
diff --git a/libc/upstream-netbsd/libc/string/strcasestr.c b/libc/upstream-netbsd/lib/libc/string/strcasestr.c
similarity index 100%
rename from libc/upstream-netbsd/libc/string/strcasestr.c
rename to libc/upstream-netbsd/lib/libc/string/strcasestr.c
diff --git a/libc/upstream-netbsd/libc/string/strcoll.c b/libc/upstream-netbsd/lib/libc/string/strcoll.c
similarity index 100%
rename from libc/upstream-netbsd/libc/string/strcoll.c
rename to libc/upstream-netbsd/lib/libc/string/strcoll.c
diff --git a/libc/upstream-netbsd/libc/string/strxfrm.c b/libc/upstream-netbsd/lib/libc/string/strxfrm.c
similarity index 100%
rename from libc/upstream-netbsd/libc/string/strxfrm.c
rename to libc/upstream-netbsd/lib/libc/string/strxfrm.c
diff --git a/libc/upstream-netbsd/libc/thread-stub/__isthreaded.c b/libc/upstream-netbsd/lib/libc/thread-stub/__isthreaded.c
similarity index 100%
rename from libc/upstream-netbsd/libc/thread-stub/__isthreaded.c
rename to libc/upstream-netbsd/lib/libc/thread-stub/__isthreaded.c
diff --git a/libc/upstream-netbsd/libc/unistd/killpg.c b/libc/upstream-netbsd/lib/libc/unistd/killpg.c
similarity index 100%
rename from libc/upstream-netbsd/libc/unistd/killpg.c
rename to libc/upstream-netbsd/lib/libc/unistd/killpg.c
diff --git a/libc/unistd/charclass.h b/libc/upstream-openbsd/lib/libc/gen/charclass.h
similarity index 100%
rename from libc/unistd/charclass.h
rename to libc/upstream-openbsd/lib/libc/gen/charclass.h
diff --git a/libc/unistd/exec.c b/libc/upstream-openbsd/lib/libc/gen/exec.c
similarity index 89%
rename from libc/unistd/exec.c
rename to libc/upstream-openbsd/lib/libc/gen/exec.c
index 2fe2a4e..1e2f7d9 100644
--- a/libc/unistd/exec.c
+++ b/libc/upstream-openbsd/lib/libc/gen/exec.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: exec.c,v 1.18 2005/08/08 08:05:34 espie Exp $ */
+/*	$OpenBSD: exec.c,v 1.21 2013/09/30 12:02:33 millert Exp $ */
 /*-
  * Copyright (c) 1991, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -28,19 +28,17 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/param.h>
 #include <sys/types.h>
 #include <sys/uio.h>
+
 #include <errno.h>
-#include <unistd.h>
 #include <limits.h>
-#include <stdlib.h>
-#include <string.h>
-#include <strings.h>
-#include <stdio.h>
 #include <paths.h>
 #include <stdarg.h>
-#include <alloca.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 
 extern char **environ;
 
@@ -124,20 +122,21 @@
 }
 
 int
-execv(const char *name, char * const *argv)
+execv(const char *name, char *const *argv)
 {
 	(void)execve(name, argv, environ);
 	return (-1);
 }
 
 int
-execvp(const char *name, char * const *argv)
+execvpe(const char *name, char *const *argv, char *const *envp)
 {
 	char **memp;
-	int cnt, lp, ln, len;
+	int cnt;
+	size_t lp, ln, len;
 	char *p;
 	int eacces = 0;
-	char *bp, *cur, *path, buf[MAXPATHLEN];
+	char *bp, *cur, *path, buf[PATH_MAX];
 
 	/*
 	 * Do not allow null name
@@ -183,7 +182,7 @@
 		 * security issue; given a way to make the path too long
 		 * the user may execute the wrong program.
 		 */
-		if (lp + ln + 2 > (int)sizeof(buf)) {
+		if (lp + ln + 2 > sizeof(buf)) {
 			struct iovec iov[3];
 
 			iov[0].iov_base = "execvp: ";
@@ -195,12 +194,12 @@
 			(void)writev(STDERR_FILENO, iov, 3);
 			continue;
 		}
-		memcpy(buf, p, lp);
+		bcopy(p, buf, lp);
 		buf[lp] = '/';
-		memcpy(buf + lp + 1, name, ln);
+		bcopy(name, buf + lp + 1, ln);
 		buf[lp + ln + 1] = '\0';
 
-retry:		(void)execve(bp, argv, environ);
+retry:		(void)execve(bp, argv, envp);
 		switch(errno) {
 		case E2BIG:
 			goto done;
@@ -217,8 +216,8 @@
 				goto done;
 			memp[0] = "sh";
 			memp[1] = bp;
-			memcpy(memp + 2, argv + 1, cnt * sizeof(char *));
-			(void)execve(_PATH_BSHELL, memp, environ);
+			bcopy(argv + 1, memp + 2, cnt * sizeof(char *));
+			(void)execve(_PATH_BSHELL, memp, envp);
 			goto done;
 		case ENOMEM:
 			goto done;
@@ -243,3 +242,10 @@
 done:
 	return (-1);
 }
+
+int
+execvp(const char *name, char *const *argv)
+{
+    return execvpe(name, argv, environ);
+}
+
diff --git a/libc/unistd/fnmatch.c b/libc/upstream-openbsd/lib/libc/gen/fnmatch.c
similarity index 100%
rename from libc/unistd/fnmatch.c
rename to libc/upstream-openbsd/lib/libc/gen/fnmatch.c
diff --git a/libc/upstream-openbsd/lib/libc/gen/ftok.c b/libc/upstream-openbsd/lib/libc/gen/ftok.c
new file mode 100644
index 0000000..f9d6621
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/gen/ftok.c
@@ -0,0 +1,43 @@
+/*	$OpenBSD: ftok.c,v 1.7 2005/08/08 08:05:34 espie Exp $ */
+/*
+ * Copyright (c) 1994 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
+ * 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. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ipc.h>
+
+key_t
+ftok(const char *path, int id)
+{
+	struct stat st;
+
+	if (stat(path, &st) < 0)
+		return (key_t)-1;
+
+	return (key_t)
+	    ((id & 0xff) << 24 | (st.st_dev & 0xff) << 16 | (st.st_ino & 0xffff));
+}
diff --git a/libc/stdlib/tolower_.c b/libc/upstream-openbsd/lib/libc/gen/tolower_.c
similarity index 100%
rename from libc/stdlib/tolower_.c
rename to libc/upstream-openbsd/lib/libc/gen/tolower_.c
diff --git a/libc/stdlib/toupper_.c b/libc/upstream-openbsd/lib/libc/gen/toupper_.c
similarity index 100%
rename from libc/stdlib/toupper_.c
rename to libc/upstream-openbsd/lib/libc/gen/toupper_.c
diff --git a/libc/stdio/fgetc.c b/libc/upstream-openbsd/lib/libc/stdio/clrerr.c
similarity index 90%
copy from libc/stdio/fgetc.c
copy to libc/upstream-openbsd/lib/libc/stdio/clrerr.c
index 0a6d54e..ac08c72 100644
--- a/libc/stdio/fgetc.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/clrerr.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: fgetc.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
+/*	$OpenBSD: clrerr.c,v 1.9 2009/11/09 00:18:27 kurt Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -32,9 +32,13 @@
  */
 
 #include <stdio.h>
+#include "local.h"
+#undef	clearerr
 
-int
-fgetc(FILE *fp)
+void
+clearerr(FILE *fp)
 {
-	return (getc(fp));
+	FLOCKFILE(fp);
+	__sclearerr(fp);
+	FUNLOCKFILE(fp);
 }
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fdopen.c b/libc/upstream-openbsd/lib/libc/stdio/fdopen.c
similarity index 77%
rename from libc/upstream-freebsd/lib/libc/stdio/fdopen.c
rename to libc/upstream-openbsd/lib/libc/stdio/fdopen.c
index 2e19b9f..3e47f2c 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/fdopen.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/fdopen.c
@@ -1,3 +1,4 @@
+/*	$OpenBSD: fdopen.c,v 1.6 2008/04/21 12:28:35 otto Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -30,20 +31,12 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fdopen.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
 #include <sys/types.h>
 #include <fcntl.h>
+#include <limits.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <errno.h>
-#include <limits.h>
-#include "un-namespace.h"
 #include "local.h"
 
 FILE *
@@ -52,13 +45,7 @@
 	FILE *fp;
 	int flags, oflags, fdflags, tmp;
 
-	/*
-	 * File descriptors are a full int, but _file is only a short.
-	 * If we get a valid file descriptor that is greater than
-	 * SHRT_MAX, then the fd will get sign-extended into an
-	 * invalid file descriptor.  Handle this case by failing the
-	 * open.
-	 */
+	/* _file is only a short */
 	if (fd > SHRT_MAX) {
 		errno = EMFILE;
 		return (NULL);
@@ -68,7 +55,7 @@
 		return (NULL);
 
 	/* Make sure the mode the user wants is a subset of the actual mode. */
-	if ((fdflags = _fcntl(fd, F_GETFL, 0)) < 0)
+	if ((fdflags = fcntl(fd, F_GETFL, 0)) < 0)
 		return (NULL);
 	tmp = fdflags & O_ACCMODE;
 	if (tmp != O_RDWR && (tmp != (oflags & O_ACCMODE))) {
@@ -78,17 +65,11 @@
 
 	if ((fp = __sfp()) == NULL)
 		return (NULL);
-
-	if ((oflags & O_CLOEXEC) && _fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
-		fp->_flags = 0;
-		return (NULL);
-	}
-
 	fp->_flags = flags;
 	/*
 	 * If opened for appending, but underlying descriptor does not have
-	 * O_APPEND bit set, assert __SAPP so that __swrite() caller
-	 * will _sseek() to the end before write.
+	 * O_APPEND bit set, assert __SAPP so that __swrite() will lseek to
+	 * end before each write.
 	 */
 	if ((oflags & O_APPEND) && !(fdflags & O_APPEND))
 		fp->_flags |= __SAPP;
diff --git a/libc/stdio/printf.c b/libc/upstream-openbsd/lib/libc/stdio/feof.c
similarity index 88%
copy from libc/stdio/printf.c
copy to libc/upstream-openbsd/lib/libc/stdio/feof.c
index 614b435..0036bab 100644
--- a/libc/stdio/printf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/feof.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: printf.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
+/*	$OpenBSD: feof.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -32,16 +32,20 @@
  */
 
 #include <stdio.h>
-#include <stdarg.h>
+#include "local.h"
+
+/*
+ * A subroutine version of the macro feof.
+ */
+#undef feof
 
 int
-printf(const char *fmt, ...)
+feof(FILE *fp)
 {
-	int ret;
-	va_list ap;
+	int	ret;
 
-	va_start(ap, fmt);
-	ret = vfprintf(stdout, fmt, ap);
-	va_end(ap);
+	FLOCKFILE(fp);
+	ret = __sfeof(fp);
+	FUNLOCKFILE(fp);
 	return (ret);
 }
diff --git a/libc/stdio/printf.c b/libc/upstream-openbsd/lib/libc/stdio/ferror.c
similarity index 87%
copy from libc/stdio/printf.c
copy to libc/upstream-openbsd/lib/libc/stdio/ferror.c
index 614b435..00b9c8b 100644
--- a/libc/stdio/printf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/ferror.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: printf.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
+/*	$OpenBSD: ferror.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -32,16 +32,20 @@
  */
 
 #include <stdio.h>
-#include <stdarg.h>
+#include "local.h"
+
+/*
+ * A subroutine version of the macro ferror.
+ */
+#undef ferror
 
 int
-printf(const char *fmt, ...)
+ferror(FILE *fp)
 {
-	int ret;
-	va_list ap;
+	int     ret;
 
-	va_start(ap, fmt);
-	ret = vfprintf(stdout, fmt, ap);
-	va_end(ap);
+	FLOCKFILE(fp);
+	ret = __sferror(fp);
+	FUNLOCKFILE(fp);
 	return (ret);
 }
diff --git a/libc/stdio/fflush.c b/libc/upstream-openbsd/lib/libc/stdio/fflush.c
similarity index 96%
rename from libc/stdio/fflush.c
rename to libc/upstream-openbsd/lib/libc/stdio/fflush.c
index e69bdcc..3e30f10 100644
--- a/libc/stdio/fflush.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/fflush.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: fflush.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
+/*	$OpenBSD: fflush.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -39,7 +39,7 @@
 int
 fflush(FILE *fp)
 {
-	int r;
+	int	r;
 
 	if (fp == NULL)
 		return (_fwalk(__sflush_locked));
@@ -88,7 +88,7 @@
 int
 __sflush_locked(FILE *fp)
 {
-	int r;
+	int	r;
 
 	FLOCKFILE(fp);
 	r = __sflush(fp);
diff --git a/libc/stdio/fgetc.c b/libc/upstream-openbsd/lib/libc/stdio/fgetc.c
similarity index 96%
rename from libc/stdio/fgetc.c
rename to libc/upstream-openbsd/lib/libc/stdio/fgetc.c
index 0a6d54e..c5d7dde 100644
--- a/libc/stdio/fgetc.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/fgetc.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: fgetc.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
+/*	$OpenBSD: fgetc.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fgetln.c b/libc/upstream-openbsd/lib/libc/stdio/fgetln.c
similarity index 86%
rename from libc/upstream-freebsd/lib/libc/stdio/fgetln.c
rename to libc/upstream-openbsd/lib/libc/stdio/fgetln.c
index 1779de2..539b3c0 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/fgetln.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/fgetln.c
@@ -1,3 +1,4 @@
+/*	$OpenBSD: fgetln.c,v 1.11 2009/11/21 09:53:44 guenther Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -30,18 +31,9 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fgetln.c	8.2 (Berkeley) 1/2/94";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include "un-namespace.h"
-#include "libc_private.h"
 #include "local.h"
 
 /*
@@ -70,7 +62,7 @@
 
 /*
  * Get an input line.  The returned pointer often (but not always)
- * points into a stdio buffer.  Fgetln does not alter the text of
+ * points into a stdio buffer.  Fgetline does not alter the text of
  * the returned line (which is thus not a C string because it will
  * not necessarily end with '\0'), but does allow callers to modify
  * it if they wish.  Thus, we set __SMOD in case the caller does.
@@ -79,22 +71,19 @@
 fgetln(FILE *fp, size_t *lenp)
 {
 	unsigned char *p;
+	char *ret;
 	size_t len;
 	size_t off;
 
 	FLOCKFILE(fp);
-	ORIENT(fp, -1);
+	_SET_ORIENTATION(fp, -1);
+
 	/* make sure there is input */
-	if (fp->_r <= 0 && __srefill(fp)) {
-		*lenp = 0;
-		FUNLOCKFILE(fp);
-		return (NULL);
-	}
+	if (fp->_r <= 0 && __srefill(fp))
+		goto error;
 
 	/* look for a newline in the input */
-	if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) != NULL) {
-		char *ret;
-
+	if ((p = memchr((void *)fp->_p, '\n', fp->_r)) != NULL) {
 		/*
 		 * Found one.  Flag buffer as modified to keep fseek from
 		 * `optimising' a backward seek, in case the user stomps on
@@ -135,7 +124,7 @@
 		off = len;
 		if (__srefill(fp))
 			break;	/* EOF or error: return partial line */
-		if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) == NULL)
+		if ((p = memchr((void *)fp->_p, '\n', fp->_r)) == NULL)
 			continue;
 
 		/* got it: finish up the line (like code above) */
@@ -151,11 +140,12 @@
 		break;
 	}
 	*lenp = len;
+	ret = (char *)fp->_lb._base;
 #ifdef notdef
-	fp->_lb._base[len] = 0;
+	ret[len] = '\0';
 #endif
 	FUNLOCKFILE(fp);
-	return ((char *)fp->_lb._base);
+	return (ret);
 
 error:
 	*lenp = 0;		/* ??? */
diff --git a/libc/stdio/fgetc.c b/libc/upstream-openbsd/lib/libc/stdio/fgetpos.c
similarity index 90%
copy from libc/stdio/fgetc.c
copy to libc/upstream-openbsd/lib/libc/stdio/fgetpos.c
index 0a6d54e..e6188e5 100644
--- a/libc/stdio/fgetc.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/fgetpos.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: fgetc.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
+/*	$OpenBSD: fgetpos.c,v 1.6 2005/08/08 08:05:36 espie Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -33,8 +33,11 @@
 
 #include <stdio.h>
 
+/*
+ * fgetpos: like ftello.
+ */
 int
-fgetc(FILE *fp)
+fgetpos(FILE *fp, fpos_t *pos)
 {
-	return (getc(fp));
+	return((*pos = ftello(fp)) == (fpos_t)-1);
 }
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fgets.c b/libc/upstream-openbsd/lib/libc/stdio/fgets.c
similarity index 86%
rename from libc/upstream-freebsd/lib/libc/stdio/fgets.c
rename to libc/upstream-openbsd/lib/libc/stdio/fgets.c
index 9abf559..0ba8770 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/fgets.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/fgets.c
@@ -1,3 +1,4 @@
+/*	$OpenBSD: fgets.c,v 1.14 2009/11/09 00:18:27 kurt Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -30,43 +31,38 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fgets.c	8.2 (Berkeley) 12/22/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
+#include <errno.h>
 #include <stdio.h>
 #include <string.h>
-#include "un-namespace.h"
 #include "local.h"
-#include "libc_private.h"
 
 /*
  * Read at most n-1 characters from the given file.
  * Stop when a newline has been read, or the count runs out.
  * Return first argument, or NULL if no characters were read.
+ * Do not return NULL if n == 1.
  */
 char *
-fgets(char * __restrict buf, int n, FILE * __restrict fp)
+fgets(char *buf, int n, FILE *fp)
 {
 	size_t len;
 	char *s;
 	unsigned char *p, *t;
 
-	if (n <= 0)		/* sanity check */
+	if (n <= 0) {		/* sanity check */
+		errno = EINVAL;
 		return (NULL);
+	}
 
 	FLOCKFILE(fp);
-	ORIENT(fp, -1);
+	_SET_ORIENTATION(fp, -1);
 	s = buf;
 	n--;			/* leave space for NUL */
 	while (n != 0) {
 		/*
 		 * If the buffer is empty, refill it.
 		 */
-		if ((len = fp->_r) <= 0) {
+		if (fp->_r <= 0) {
 			if (__srefill(fp)) {
 				/* EOF/error: stop with partial or no line */
 				if (s == buf) {
@@ -75,8 +71,8 @@
 				}
 				break;
 			}
-			len = fp->_r;
 		}
+		len = fp->_r;
 		p = fp->_p;
 
 		/*
@@ -93,7 +89,7 @@
 			fp->_r -= len;
 			fp->_p = t;
 			(void)memcpy((void *)s, (void *)p, len);
-			s[len] = 0;
+			s[len] = '\0';
 			FUNLOCKFILE(fp);
 			return (buf);
 		}
@@ -103,7 +99,7 @@
 		s += len;
 		n -= len;
 	}
-	*s = 0;
+	*s = '\0';
 	FUNLOCKFILE(fp);
 	return (buf);
 }
diff --git a/libc/stdio/printf.c b/libc/upstream-openbsd/lib/libc/stdio/fileno.c
similarity index 87%
copy from libc/stdio/printf.c
copy to libc/upstream-openbsd/lib/libc/stdio/fileno.c
index 614b435..58628da 100644
--- a/libc/stdio/printf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/fileno.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: printf.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
+/*	$OpenBSD: fileno.c,v 1.8 2009/11/09 00:18:27 kurt Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -32,16 +32,20 @@
  */
 
 #include <stdio.h>
-#include <stdarg.h>
+#include "local.h"
+
+/*
+ * A subroutine version of the macro fileno.
+ */
+#undef fileno
 
 int
-printf(const char *fmt, ...)
+fileno(FILE *fp)
 {
-	int ret;
-	va_list ap;
+	int     ret;
 
-	va_start(ap, fmt);
-	ret = vfprintf(stdout, fmt, ap);
-	va_end(ap);
+	FLOCKFILE(fp);
+	ret = __sfileno(fp);
+	FUNLOCKFILE(fp);
 	return (ret);
 }
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fpurge.c b/libc/upstream-openbsd/lib/libc/stdio/fpurge.c
similarity index 80%
rename from libc/upstream-freebsd/lib/libc/stdio/fpurge.c
rename to libc/upstream-openbsd/lib/libc/stdio/fpurge.c
index f205bdf..65bd749 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/fpurge.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/fpurge.c
@@ -1,3 +1,4 @@
+/*	$OpenBSD: fpurge.c,v 1.9 2009/11/09 00:18:27 kurt Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -30,19 +31,10 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fpurge.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include "un-namespace.h"
 #include "local.h"
-#include "libc_private.h"
 
 /*
  * fpurge: like fflush, but without writing anything: leave the
@@ -51,19 +43,19 @@
 int
 fpurge(FILE *fp)
 {
-	int retval;
 	FLOCKFILE(fp);
 	if (!fp->_flags) {
+		FUNLOCKFILE(fp);
 		errno = EBADF;
-		retval = EOF;
-	} else {
-		if (HASUB(fp))
-			FREEUB(fp);
-		fp->_p = fp->_bf._base;
-		fp->_r = 0;
-		fp->_w = fp->_flags & (__SLBF|__SNBF|__SRD) ? 0 : fp->_bf._size;
-		retval = 0;
+		return(EOF);
 	}
+
+	if (HASUB(fp))
+		FREEUB(fp);
+	WCIO_FREE(fp);
+	fp->_p = fp->_bf._base;
+	fp->_r = 0;
+	fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size;
 	FUNLOCKFILE(fp);
-	return (retval);
+	return (0);
 }
diff --git a/libc/stdio/fputc.c b/libc/upstream-openbsd/lib/libc/stdio/fputc.c
similarity index 96%
rename from libc/stdio/fputc.c
rename to libc/upstream-openbsd/lib/libc/stdio/fputc.c
index 90809e2..98e3960 100644
--- a/libc/stdio/fputc.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/fputc.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: fputc.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
+/*	$OpenBSD: fputc.c,v 1.10 2009/11/09 00:18:27 kurt Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fputs.c b/libc/upstream-openbsd/lib/libc/stdio/fputs.c
similarity index 83%
rename from libc/upstream-freebsd/lib/libc/stdio/fputs.c
rename to libc/upstream-openbsd/lib/libc/stdio/fputs.c
index 3b8f2c9..ea8556a 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/fputs.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/fputs.c
@@ -1,3 +1,4 @@
+/*	$OpenBSD: fputs.c,v 1.10 2009/11/09 00:18:27 kurt Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -30,37 +31,28 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fputs.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
 #include <stdio.h>
 #include <string.h>
-#include "un-namespace.h"
-#include "fvwrite.h"
-#include "libc_private.h"
 #include "local.h"
+#include "fvwrite.h"
 
 /*
  * Write the given string to the given file.
  */
 int
-fputs(const char * __restrict s, FILE * __restrict fp)
+fputs(const char *s, FILE *fp)
 {
-	int retval;
 	struct __suio uio;
 	struct __siov iov;
+	int ret;
 
 	iov.iov_base = (void *)s;
 	iov.iov_len = uio.uio_resid = strlen(s);
 	uio.uio_iov = &iov;
 	uio.uio_iovcnt = 1;
 	FLOCKFILE(fp);
-	ORIENT(fp, -1);
-	retval = __sfvwrite(fp, &uio);
+	_SET_ORIENTATION(fp, -1);
+	ret = __sfvwrite(fp, &uio);
 	FUNLOCKFILE(fp);
-	return (retval);
+	return (ret);
 }
diff --git a/libc/stdio/fscanf.c b/libc/upstream-openbsd/lib/libc/stdio/fscanf.c
similarity index 95%
rename from libc/stdio/fscanf.c
rename to libc/upstream-openbsd/lib/libc/stdio/fscanf.c
index 2f3fceb..5fd10d4 100644
--- a/libc/stdio/fscanf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/fscanf.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: fscanf.c,v 1.9 2005/10/10 17:37:44 espie Exp $ */
+/*	$OpenBSD: fscanf.c,v 1.10 2011/05/30 18:48:33 martynas Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -34,6 +34,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 
+/* SCANFLIKE2 */
 int
 fscanf(FILE *fp, const char *fmt, ...)
 {
diff --git a/libc/stdio/fseek.c b/libc/upstream-openbsd/lib/libc/stdio/fseek.c
similarity index 93%
rename from libc/stdio/fseek.c
rename to libc/upstream-openbsd/lib/libc/stdio/fseek.c
index 38697f5..cdd40b6 100644
--- a/libc/stdio/fseek.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/fseek.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: fseek.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
+/*	$OpenBSD: fseek.c,v 1.11 2012/05/21 22:24:19 matthew Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -185,7 +185,7 @@
 	 * skip this; see fgetln.c.)
 	 */
 	if ((fp->_flags & __SMOD) == 0 &&
-	    target >= curoff && target < (fpos_t)(curoff + n)) {
+	    target >= curoff && target < curoff + n) {
 		int o = target - curoff;
 
 		fp->_p = fp->_bf._base + o;
@@ -209,13 +209,13 @@
 	if ((*seekfn)(fp->_cookie, curoff, SEEK_SET) == POS_ERR)
 		goto dumb;
 	fp->_r = 0;
-	fp->_p = fp->_bf._base;
+ 	fp->_p = fp->_bf._base;
 	if (HASUB(fp))
 		FREEUB(fp);
 	fp->_flags &= ~__SEOF;
 	n = target - curoff;
 	if (n) {
-		if (__srefill(fp) || (size_t)fp->_r < n)
+		if (__srefill(fp) || fp->_r < n)
 			goto dumb;
 		fp->_p += n;
 		fp->_r -= n;
@@ -244,17 +244,8 @@
 	return (0);
 }
 
-/*
- * fseek()'s offset is a long and sizeof(off_t) != sizeof(long) on all arches
- */
-#if defined(__alpha__) && defined(__indr_reference)
-__indr_reference(fseeko, fseek);
-#else
 int
 fseek(FILE *fp, long offset, int whence)
 {
-	off_t off = offset;
-
-	return(fseeko(fp, off, whence));
+	return (fseeko(fp, offset, whence));
 }
-#endif
diff --git a/libc/stdio/fgetc.c b/libc/upstream-openbsd/lib/libc/stdio/fsetpos.c
similarity index 89%
copy from libc/stdio/fgetc.c
copy to libc/upstream-openbsd/lib/libc/stdio/fsetpos.c
index 0a6d54e..9624fe5 100644
--- a/libc/stdio/fgetc.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/fsetpos.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: fgetc.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
+/*	$OpenBSD: fsetpos.c,v 1.6 2005/08/08 08:05:36 espie Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -33,8 +33,11 @@
 
 #include <stdio.h>
 
+/*
+ * fsetpos: like fseeko.
+ */
 int
-fgetc(FILE *fp)
+fsetpos(FILE *iop, const fpos_t *pos)
 {
-	return (getc(fp));
+	return (fseeko(iop, (off_t)*pos, SEEK_SET));
 }
diff --git a/libc/stdio/ftell.c b/libc/upstream-openbsd/lib/libc/stdio/ftell.c
similarity index 88%
rename from libc/stdio/ftell.c
rename to libc/upstream-openbsd/lib/libc/stdio/ftell.c
index 9f850ee..0a2016c 100644
--- a/libc/stdio/ftell.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/ftell.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: ftell.c,v 1.6 2005/08/08 08:05:36 espie Exp $ */
+/*	$OpenBSD: ftell.c,v 1.10 2012/05/21 22:24:19 matthew Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -33,6 +33,7 @@
 
 #include <stdio.h>
 #include <errno.h>
+#include <limits.h>
 #include "local.h"
 
 /*
@@ -46,14 +47,14 @@
 	if (fp->_seek == NULL) {
 		errno = ESPIPE;			/* historic practice */
 		pos = -1;
-                goto out;
+		goto out;
 	}
 
 	/*
 	 * Find offset of underlying I/O object, then
 	 * adjust for buffered bytes.
 	 */
-        FLOCKFILE(fp);
+	FLOCKFILE(fp);
 	__sflush(fp);		/* may adjust seek offset on append stream */
 	if (fp->_flags & __SOFF)
 		pos = fp->_offset;
@@ -83,18 +84,13 @@
 	return (pos);
 }
 
-/*
- * ftell() returns a long and sizeof(off_t) != sizeof(long) on all arches
- */
-#if defined(__alpha__) && defined(__indr_reference)
-__indr_reference(ftello, ftell);
-#else
 long
 ftell(FILE *fp)
 {
-	long pos;
-
-	pos = (long)ftello(fp);
-	return(pos);
+	off_t offset = ftello(fp);
+	if (offset > LONG_MAX) {
+		errno = EOVERFLOW;
+		return (-1);
+	}
+	return ((long)offset);
 }
-#endif
diff --git a/libc/upstream-freebsd/lib/libc/stdio/funopen.c b/libc/upstream-openbsd/lib/libc/stdio/funopen.c
similarity index 86%
rename from libc/upstream-freebsd/lib/libc/stdio/funopen.c
rename to libc/upstream-openbsd/lib/libc/stdio/funopen.c
index 983fe50..b85ee96 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/funopen.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/funopen.c
@@ -1,3 +1,4 @@
+/*	$OpenBSD: funopen.c,v 1.8 2005/08/08 08:05:36 espie Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -30,23 +31,14 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)funopen.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <stdio.h>
 #include <errno.h>
-
 #include "local.h"
 
 FILE *
-funopen(const void *cookie,
-	int (*readfn)(void *, char *, int),
+funopen(const void *cookie, int (*readfn)(void *, char *, int),
 	int (*writefn)(void *, const char *, int),
-	fpos_t (*seekfn)(void *, fpos_t, int),
-	int (*closefn)(void *))
+	fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *))
 {
 	FILE *fp;
 	int flags;
@@ -67,7 +59,7 @@
 		return (NULL);
 	fp->_flags = flags;
 	fp->_file = -1;
-	fp->_cookie = (void *)cookie;
+	fp->_cookie = (void *)cookie;		/* SAFE: cookie not modified */
 	fp->_read = readfn;
 	fp->_write = writefn;
 	fp->_seek = seekfn;
diff --git a/libc/upstream-freebsd/lib/libc/stdio/setbuf.c b/libc/upstream-openbsd/lib/libc/stdio/fwalk.c
similarity index 81%
copy from libc/upstream-freebsd/lib/libc/stdio/setbuf.c
copy to libc/upstream-openbsd/lib/libc/stdio/fwalk.c
index 5c65f97..8ac6628 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/setbuf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/fwalk.c
@@ -1,3 +1,4 @@
+/*	$OpenBSD: fwalk.c,v 1.10 2009/11/09 00:18:27 kurt Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -30,17 +31,23 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)setbuf.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
+#include <errno.h>
 #include <stdio.h>
 #include "local.h"
+#include "glue.h"
 
-void
-setbuf(FILE * __restrict fp, char * __restrict buf)
+int
+_fwalk(int (*function)(FILE *))
 {
-	(void) setvbuf(fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
+	FILE *fp;
+	int n, ret;
+	struct glue *g;
+
+	ret = 0;
+	for (g = &__sglue; g != NULL; g = g->next)
+		for (fp = g->iobs, n = g->niobs; --n >= 0; fp++) {
+			if ((fp->_flags != 0) && ((fp->_flags & __SIGN) == 0))
+				ret |= (*function)(fp);
+		}
+	return (ret);
 }
diff --git a/libc/upstream-freebsd/lib/libc/stdio/setbuf.c b/libc/upstream-openbsd/lib/libc/stdio/getc.c
similarity index 82%
copy from libc/upstream-freebsd/lib/libc/stdio/setbuf.c
copy to libc/upstream-openbsd/lib/libc/stdio/getc.c
index 5c65f97..6879cbb 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/setbuf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/getc.c
@@ -1,3 +1,4 @@
+/*	$OpenBSD: getc.c,v 1.9 2009/11/09 00:18:27 kurt Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -30,17 +31,32 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)setbuf.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <stdio.h>
 #include "local.h"
 
-void
-setbuf(FILE * __restrict fp, char * __restrict buf)
+/*
+ * A subroutine version of the macro getc_unlocked.
+ */
+#undef getc_unlocked
+
+int
+getc_unlocked(FILE *fp)
 {
-	(void) setvbuf(fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
+	return (__sgetc(fp));
+}
+
+/*
+ * A subroutine version of the macro getc.
+ */
+#undef getc
+
+int
+getc(FILE *fp)
+{
+	int c;
+
+	FLOCKFILE(fp);
+	c = __sgetc(fp);
+	FUNLOCKFILE(fp);
+	return (c);
 }
diff --git a/libc/upstream-freebsd/lib/libc/stdio/setbuf.c b/libc/upstream-openbsd/lib/libc/stdio/getchar.c
similarity index 83%
rename from libc/upstream-freebsd/lib/libc/stdio/setbuf.c
rename to libc/upstream-openbsd/lib/libc/stdio/getchar.c
index 5c65f97..550817d 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/setbuf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/getchar.c
@@ -1,3 +1,4 @@
+/*	$OpenBSD: getchar.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -30,17 +31,28 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)setbuf.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <stdio.h>
-#include "local.h"
 
-void
-setbuf(FILE * __restrict fp, char * __restrict buf)
+/*
+ * A subroutine version of the macro getchar_unlocked.
+ */
+#undef getchar_unlocked
+
+int
+getchar_unlocked(void)
 {
-	(void) setvbuf(fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
+	return (getc_unlocked(stdin));
+}
+
+
+/*
+ * A subroutine version of the macro getchar.
+ */
+
+#undef getchar
+
+int
+getchar(void)
+{
+	return (getc(stdin));
 }
diff --git a/libc/upstream-netbsd/libc/stdio/getdelim.c b/libc/upstream-openbsd/lib/libc/stdio/getdelim.c
similarity index 88%
rename from libc/upstream-netbsd/libc/stdio/getdelim.c
rename to libc/upstream-openbsd/lib/libc/stdio/getdelim.c
index acce376..dcde0c3 100644
--- a/libc/upstream-netbsd/libc/stdio/getdelim.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/getdelim.c
@@ -1,3 +1,4 @@
+/*	$OpenBSD: getdelim.c,v 1.1 2012/03/21 23:44:35 fgsch Exp $	*/
 /* $NetBSD: getdelim.c,v 1.13 2011/07/22 23:12:30 joerg Exp $ */
 
 /*
@@ -27,41 +28,28 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-__RCSID("$NetBSD: getdelim.c,v 1.13 2011/07/22 23:12:30 joerg Exp $");
-
-#include "namespace.h"
-
-#include <sys/param.h>
-
-#include <assert.h>
 #include <errno.h>
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include "reentrant.h"
 #include "local.h"
 
-#ifdef __weak_alias
-__weak_alias(getdelim, _getdelim)
-#endif
-
 /* Minimum buffer size we create.
  * This should allow config files to fit into our power of 2 buffer growth
  * without the need for a realloc. */
 #define MINBUF	128
 
 ssize_t
-__getdelim(char **__restrict buf, size_t *__restrict buflen,
+getdelim(char **__restrict buf, size_t *__restrict buflen,
     int sep, FILE *__restrict fp)
 {
 	unsigned char *p;
 	size_t len, newlen, off;
 	char *newb;
 
-	_DIAGASSERT(fp != NULL);
+	FLOCKFILE(fp);
 
 	if (buf == NULL || buflen == NULL) {
 		errno = EINVAL;
@@ -100,6 +88,7 @@
 		if (newlen > *buflen) {
 			if (newlen < MINBUF)
 				newlen = MINBUF;
+#define powerof2(x) ((((x)-1)&(x))==0)
 			if (!powerof2(newlen)) {
 				/* Grow the buffer to the next power of 2 */
 				newlen--;
@@ -128,8 +117,10 @@
 		off += len;
 	} while (p == NULL);
 
+	FUNLOCKFILE(fp);
+
 	/* POSIX demands we return -1 on EOF. */
-	if (off == 0) 
+	if (off == 0)
 		return -1;
 
 	if (*buf != NULL)
@@ -138,17 +129,6 @@
 
 error:
 	fp->_flags |= __SERR;
-	return -1;
-}
-
-ssize_t
-getdelim(char **__restrict buf, size_t *__restrict buflen,
-    int sep, FILE *__restrict fp)
-{
-	ssize_t n;
-
-	FLOCKFILE(fp);
-	n = __getdelim(buf, buflen, sep, fp);
 	FUNLOCKFILE(fp);
-	return n;
+	return -1;
 }
diff --git a/libc/upstream-netbsd/libc/stdio/getline.c b/libc/upstream-openbsd/lib/libc/stdio/getline.c
similarity index 90%
rename from libc/upstream-netbsd/libc/stdio/getline.c
rename to libc/upstream-openbsd/lib/libc/stdio/getline.c
index e5d4bab..55ad396 100644
--- a/libc/upstream-netbsd/libc/stdio/getline.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/getline.c
@@ -1,3 +1,4 @@
+/*	$OpenBSD: getline.c,v 1.1 2012/03/21 23:44:35 fgsch Exp $	*/
 /* $NetBSD: getline.c,v 1.3 2009/12/02 08:46:33 roy Exp $ */
 
 /*
@@ -27,17 +28,8 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-__RCSID("$NetBSD: getline.c,v 1.3 2009/12/02 08:46:33 roy Exp $");
-
-#include "namespace.h"
-
 #include <stdio.h>
 
-#ifdef __weak_alias
-__weak_alias(getline, _getline)
-#endif
-
 ssize_t
 getline(char **__restrict buf, size_t *__restrict buflen, FILE *__restrict fp)
 {
diff --git a/libc/stdio/gets.c b/libc/upstream-openbsd/lib/libc/stdio/gets.c
similarity index 96%
rename from libc/stdio/gets.c
rename to libc/upstream-openbsd/lib/libc/stdio/gets.c
index 93e2edd..c2e1b50 100644
--- a/libc/stdio/gets.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/gets.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: gets.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */
+/*	$OpenBSD: gets.c,v 1.12 2009/11/09 00:18:27 kurt Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
diff --git a/libc/upstream-freebsd/lib/libc/stdio/remove.c b/libc/upstream-openbsd/lib/libc/stdio/perror.c
similarity index 72%
copy from libc/upstream-freebsd/lib/libc/stdio/remove.c
copy to libc/upstream-openbsd/lib/libc/stdio/perror.c
index 2e984ba..8728718 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/remove.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/perror.c
@@ -1,10 +1,8 @@
-/*-
- * Copyright (c) 1990, 1993
+/*	$OpenBSD: perror.c,v 1.8 2005/08/08 08:05:36 espie Exp $ */
+/*
+ * Copyright (c) 1988, 1993
  *	The Regents of the University of California.  All rights reserved.
  *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -30,25 +28,35 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)remove.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <sys/types.h>
-#include <sys/stat.h>
+#include <sys/uio.h>
 #include <unistd.h>
+#include <errno.h>
 #include <stdio.h>
+#include <string.h>
+#include <limits.h>
 
-int
-remove(const char *file)
+void
+perror(const char *s)
 {
-	struct stat sb;
+	struct iovec *v;
+	struct iovec iov[4];
+	char buf[NL_TEXTMAX];
 
-	if (lstat(file, &sb) < 0)
-		return (-1);
-	if (S_ISDIR(sb.st_mode))
-		return (rmdir(file));
-	return (unlink(file));
+	v = iov;
+	if (s && *s) {
+		v->iov_base = (char *)s;
+		v->iov_len = strlen(s);
+		v++;
+		v->iov_base = ": ";
+		v->iov_len = 2;
+		v++;
+	}
+	(void)strerror_r(errno, buf, sizeof(buf));
+	v->iov_base = buf;
+	v->iov_len = strlen(v->iov_base);
+	v++;
+	v->iov_base = "\n";
+	v->iov_len = 1;
+	(void)writev(STDERR_FILENO, iov, (v - iov) + 1);
 }
diff --git a/libc/stdio/printf.c b/libc/upstream-openbsd/lib/libc/stdio/printf.c
similarity index 95%
rename from libc/stdio/printf.c
rename to libc/upstream-openbsd/lib/libc/stdio/printf.c
index 614b435..09bb3d7 100644
--- a/libc/stdio/printf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/printf.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: printf.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
+/*	$OpenBSD: printf.c,v 1.8 2011/05/30 18:48:33 martynas Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -34,6 +34,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 
+/* PRINTFLIKE1 */
 int
 printf(const char *fmt, ...)
 {
diff --git a/libc/upstream-freebsd/lib/libc/stdio/putc.c b/libc/upstream-openbsd/lib/libc/stdio/putc.c
similarity index 80%
rename from libc/upstream-freebsd/lib/libc/stdio/putc.c
rename to libc/upstream-openbsd/lib/libc/stdio/putc.c
index aaffece..762fecb 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/putc.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/putc.c
@@ -1,3 +1,4 @@
+/*	$OpenBSD: putc.c,v 1.12 2009/11/21 10:11:54 guenther Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -30,36 +31,38 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)putc.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
 #include <stdio.h>
-#include "un-namespace.h"
+#include <errno.h>
 #include "local.h"
-#include "libc_private.h"
 
-#undef putc
+/*
+ * A subroutine version of the macro putc_unlocked.
+ */
 #undef putc_unlocked
 
 int
+putc_unlocked(int c, FILE *fp)
+{
+	if (cantwrite(fp)) {
+		errno = EBADF;
+		return (EOF);
+	}
+	_SET_ORIENTATION(fp, -1);
+	return (__sputc(c, fp));
+}
+
+/*
+ * A subroutine version of the macro putc.
+ */
+#undef putc
+
+int
 putc(int c, FILE *fp)
 {
-	int retval;
+	int ret;
+
 	FLOCKFILE(fp);
-	/* Orientation set by __sputc() when buffer is full. */
-	/* ORIENT(fp, -1); */
-	retval = __sputc(c, fp);
+	ret = putc_unlocked(c, fp);
 	FUNLOCKFILE(fp);
-	return (retval);
-}
-
-int
-putc_unlocked(int ch, FILE *fp)
-{
-
-	return (__sputc(ch, fp));
+	return (ret);
 }
diff --git a/libc/upstream-freebsd/lib/libc/stdio/fsetpos.c b/libc/upstream-openbsd/lib/libc/stdio/putchar.c
similarity index 82%
rename from libc/upstream-freebsd/lib/libc/stdio/fsetpos.c
rename to libc/upstream-openbsd/lib/libc/stdio/putchar.c
index c6b8b78..233cdfd 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/fsetpos.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/putchar.c
@@ -1,3 +1,4 @@
+/*	$OpenBSD: putchar.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -30,20 +31,29 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fsetpos.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
 #include <stdio.h>
 
+#undef putchar_unlocked
 /*
- * fsetpos: like fseek.
+ * A subrouting version of the macro putchar_unlocked
  */
 int
-fsetpos(FILE *iop, const fpos_t *pos)
+putchar_unlocked(int c)
 {
-	return (fseeko(iop, (off_t)*pos, SEEK_SET));
+	FILE *so = stdout;
+
+	return (putc_unlocked(c,so));
+}
+
+#undef putchar
+
+/*
+ * A subroutine version of the macro putchar
+ */
+int
+putchar(int c)
+{
+	FILE *so = stdout;
+
+	return (putc(c, so));
 }
diff --git a/libc/upstream-freebsd/lib/libc/stdio/puts.c b/libc/upstream-openbsd/lib/libc/stdio/puts.c
similarity index 84%
rename from libc/upstream-freebsd/lib/libc/stdio/puts.c
rename to libc/upstream-openbsd/lib/libc/stdio/puts.c
index 5ee7fc1..655aed7 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/puts.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/puts.c
@@ -1,3 +1,4 @@
+/*	$OpenBSD: puts.c,v 1.11 2009/11/21 09:53:44 guenther Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -30,30 +31,21 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)puts.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "namespace.h"
 #include <stdio.h>
 #include <string.h>
-#include "un-namespace.h"
-#include "fvwrite.h"
-#include "libc_private.h"
 #include "local.h"
+#include "fvwrite.h"
 
 /*
  * Write the given string to stdout, appending a newline.
  */
 int
-puts(char const *s)
+puts(const char *s)
 {
-	int retval;
 	size_t c = strlen(s);
 	struct __suio uio;
 	struct __siov iov[2];
+	int ret;
 
 	iov[0].iov_base = (void *)s;
 	iov[0].iov_len = c;
@@ -63,8 +55,8 @@
 	uio.uio_iov = &iov[0];
 	uio.uio_iovcnt = 2;
 	FLOCKFILE(stdout);
-	ORIENT(stdout, -1);
-	retval = __sfvwrite(stdout, &uio) ? EOF : '\n';
+	_SET_ORIENTATION(stdout, -1);
+	ret = __sfvwrite(stdout, &uio);
 	FUNLOCKFILE(stdout);
-	return (retval);
+	return (ret ? EOF : '\n');
 }
diff --git a/libc/stdio/refill.c b/libc/upstream-openbsd/lib/libc/stdio/refill.c
similarity index 96%
rename from libc/stdio/refill.c
rename to libc/upstream-openbsd/lib/libc/stdio/refill.c
index 7cb6b78..165c72a 100644
--- a/libc/stdio/refill.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/refill.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: refill.c,v 1.8 2005/08/08 08:05:36 espie Exp $ */
+/*	$OpenBSD: refill.c,v 1.11 2009/11/09 00:18:27 kurt Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -40,7 +40,7 @@
 lflush(FILE *fp)
 {
 	if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR))
-		return (__sflush_locked(fp)); /* ignored... */
+		return (__sflush_locked(fp));	/* ignored... */
 	return (0);
 }
 
@@ -110,7 +110,7 @@
 
 		/* Now flush this file without locking it. */
 		if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR))
-		    __sflush(fp);
+			__sflush(fp);
 	}
 	fp->_p = fp->_bf._base;
 	fp->_r = (*fp->_read)(fp->_cookie, (char *)fp->_p, fp->_bf._size);
diff --git a/libc/upstream-freebsd/lib/libc/stdio/remove.c b/libc/upstream-openbsd/lib/libc/stdio/remove.c
similarity index 86%
rename from libc/upstream-freebsd/lib/libc/stdio/remove.c
rename to libc/upstream-openbsd/lib/libc/stdio/remove.c
index 2e984ba..d09d76f 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/remove.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/remove.c
@@ -1,3 +1,5 @@
+/*	$OpenBSD: remove.c,v 1.7 2005/08/08 08:05:36 espie Exp $	*/
+
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -30,25 +32,18 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)remove.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
 #include <stdio.h>
+#include <unistd.h>
+#include <sys/stat.h>
 
 int
 remove(const char *file)
 {
-	struct stat sb;
+	struct stat st;
 
-	if (lstat(file, &sb) < 0)
+	if (lstat(file, &st) < 0)
 		return (-1);
-	if (S_ISDIR(sb.st_mode))
+	if (S_ISDIR(st.st_mode))
 		return (rmdir(file));
 	return (unlink(file));
 }
diff --git a/libc/stdio/rewind.c b/libc/upstream-openbsd/lib/libc/stdio/rewind.c
similarity index 100%
rename from libc/stdio/rewind.c
rename to libc/upstream-openbsd/lib/libc/stdio/rewind.c
diff --git a/libc/upstream-freebsd/lib/libc/stdio/rget.c b/libc/upstream-openbsd/lib/libc/stdio/rget.c
similarity index 91%
rename from libc/upstream-freebsd/lib/libc/stdio/rget.c
rename to libc/upstream-openbsd/lib/libc/stdio/rget.c
index bdc0311..4cd97cb 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/rget.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/rget.c
@@ -1,3 +1,4 @@
+/*	$OpenBSD: rget.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -30,12 +31,6 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)rget.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <stdio.h>
 #include "local.h"
 
@@ -47,6 +42,7 @@
 int
 __srget(FILE *fp)
 {
+	_SET_ORIENTATION(fp, -1);
 	if (__srefill(fp) == 0) {
 		fp->_r--;
 		return (*fp->_p++);
diff --git a/libc/stdio/scanf.c b/libc/upstream-openbsd/lib/libc/stdio/scanf.c
similarity index 95%
rename from libc/stdio/scanf.c
rename to libc/upstream-openbsd/lib/libc/stdio/scanf.c
index 71194d0..90cf12a 100644
--- a/libc/stdio/scanf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/scanf.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: scanf.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */
+/*	$OpenBSD: scanf.c,v 1.10 2011/05/30 18:48:33 martynas Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -34,6 +34,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 
+/* SCANFLIKE1 */
 int
 scanf(const char *fmt, ...)
 {
diff --git a/libc/stdio/fgetc.c b/libc/upstream-openbsd/lib/libc/stdio/setbuf.c
similarity index 90%
copy from libc/stdio/fgetc.c
copy to libc/upstream-openbsd/lib/libc/stdio/setbuf.c
index 0a6d54e..883b895 100644
--- a/libc/stdio/fgetc.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/setbuf.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: fgetc.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
+/*	$OpenBSD: setbuf.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -32,9 +32,10 @@
  */
 
 #include <stdio.h>
+#include "local.h"
 
-int
-fgetc(FILE *fp)
+void
+setbuf(FILE *fp, char *buf)
 {
-	return (getc(fp));
+	(void) setvbuf(fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
 }
diff --git a/libc/upstream-freebsd/lib/libc/stdio/setbuffer.c b/libc/upstream-openbsd/lib/libc/stdio/setbuffer.c
similarity index 88%
rename from libc/upstream-freebsd/lib/libc/stdio/setbuffer.c
rename to libc/upstream-openbsd/lib/libc/stdio/setbuffer.c
index af5eb3c..8725ff7 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/setbuffer.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/setbuffer.c
@@ -1,3 +1,4 @@
+/*	$OpenBSD: setbuffer.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -30,19 +31,13 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)setbuffer.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <stdio.h>
 
 void
 setbuffer(FILE *fp, char *buf, int size)
 {
 
-	(void)setvbuf(fp, buf, buf ? _IOFBF : _IONBF, (size_t)size);
+	(void)setvbuf(fp, buf, buf ? _IOFBF : _IONBF, size);
 }
 
 /*
diff --git a/libc/stdio/stdio.c b/libc/upstream-openbsd/lib/libc/stdio/stdio.c
similarity index 99%
rename from libc/stdio/stdio.c
rename to libc/upstream-openbsd/lib/libc/stdio/stdio.c
index 1596ebf..a4a27b5 100644
--- a/libc/stdio/stdio.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/stdio.c
@@ -45,7 +45,7 @@
 {
 	FILE *fp = cookie;
 	int ret;
-
+	
 	ret = read(fp->_file, buf, n);
 	/* if the read succeeded, update the current offset */
 	if (ret >= 0)
@@ -71,7 +71,7 @@
 {
 	FILE *fp = cookie;
 	off_t ret;
-
+	
 	ret = lseek(fp->_file, (off_t)offset, whence);
 	if (ret == (off_t)-1)
 		fp->_flags &= ~__SOFF;
diff --git a/libc/upstream-freebsd/lib/libc/stdio/tempnam.c b/libc/upstream-openbsd/lib/libc/stdio/tempnam.c
similarity index 71%
rename from libc/upstream-freebsd/lib/libc/stdio/tempnam.c
rename to libc/upstream-openbsd/lib/libc/stdio/tempnam.c
index e15746f..e3f2ab6 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/tempnam.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/tempnam.c
@@ -1,3 +1,4 @@
+/*	$OpenBSD: tempnam.c,v 1.17 2013/09/30 12:02:35 millert Exp $ */
 /*
  * Copyright (c) 1988, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -27,19 +28,13 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)tempnam.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
 #include <errno.h>
+#include <limits.h>
+#include <paths.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <paths.h>
 
 __warn_references(tempnam,
     "warning: tempnam() possibly used unsafely; consider using mkstemp()");
@@ -49,36 +44,53 @@
 char *
 tempnam(const char *dir, const char *pfx)
 {
-	int sverrno;
+	int sverrno, len;
 	char *f, *name;
 
-	if (!(name = malloc(MAXPATHLEN)))
+	if (!(name = malloc(PATH_MAX)))
 		return(NULL);
 
 	if (!pfx)
 		pfx = "tmp.";
 
-	if (issetugid() == 0 && (f = getenv("TMPDIR"))) {
-		(void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f,
-		    *(f + strlen(f) - 1) == '/'? "": "/", pfx);
+	if (issetugid() == 0 && (f = getenv("TMPDIR")) && *f != '\0') {
+		len = snprintf(name, PATH_MAX, "%s%s%sXXXXXXXXXX", f,
+		    f[strlen(f) - 1] == '/' ? "" : "/", pfx);
+		if (len < 0 || len >= PATH_MAX) {
+			errno = ENAMETOOLONG;
+			return(NULL);
+		}
 		if ((f = _mktemp(name)))
 			return(f);
 	}
 
-	if ((f = (char *)dir)) {
-		(void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f,
-		    *(f + strlen(f) - 1) == '/'? "": "/", pfx);
+	if (dir != NULL) {
+		f = *dir ? (char *)dir : ".";
+		len = snprintf(name, PATH_MAX, "%s%s%sXXXXXXXXXX", f,
+		    f[strlen(f) - 1] == '/' ? "" : "/", pfx);
+		if (len < 0 || len >= PATH_MAX) {
+			errno = ENAMETOOLONG;
+			return(NULL);
+		}
 		if ((f = _mktemp(name)))
 			return(f);
 	}
 
 	f = P_tmpdir;
-	(void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx);
+	len = snprintf(name, PATH_MAX, "%s%sXXXXXXXXX", f, pfx);
+	if (len < 0 || len >= PATH_MAX) {
+		errno = ENAMETOOLONG;
+		return(NULL);
+	}
 	if ((f = _mktemp(name)))
 		return(f);
 
 	f = _PATH_TMP;
-	(void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx);
+	len = snprintf(name, PATH_MAX, "%s%sXXXXXXXXX", f, pfx);
+	if (len < 0 || len >= PATH_MAX) {
+		errno = ENAMETOOLONG;
+		return(NULL);
+	}
 	if ((f = _mktemp(name)))
 		return(f);
 
diff --git a/libc/upstream-freebsd/lib/libc/stdio/tmpnam.c b/libc/upstream-openbsd/lib/libc/stdio/tmpnam.c
similarity index 88%
rename from libc/upstream-freebsd/lib/libc/stdio/tmpnam.c
rename to libc/upstream-openbsd/lib/libc/stdio/tmpnam.c
index ce32dcc..32e0a22 100644
--- a/libc/upstream-freebsd/lib/libc/stdio/tmpnam.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/tmpnam.c
@@ -1,3 +1,4 @@
+/*	$OpenBSD: tmpnam.c,v 1.10 2005/08/08 08:05:36 espie Exp $ */
 /*-
  * Copyright (c) 1990, 1993, 1994
  *	The Regents of the University of California.  All rights reserved.
@@ -30,12 +31,6 @@
  * SUCH DAMAGE.
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)tmpnam.c	8.3 (Berkeley) 3/28/94";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 #include <sys/types.h>
 
 #include <stdio.h>
@@ -54,7 +49,7 @@
 
 	if (s == NULL)
 		s = buf;
-	(void)snprintf(s, L_tmpnam, "%stmp.%lu.XXXXXX", P_tmpdir, tmpcount);
+	(void)snprintf(s, L_tmpnam, "%stmp.%lu.XXXXXXXXX", P_tmpdir, tmpcount);
 	++tmpcount;
 	return (_mktemp(s));
 }
diff --git a/libc/stdio/ungetc.c b/libc/upstream-openbsd/lib/libc/stdio/ungetc.c
similarity index 98%
rename from libc/stdio/ungetc.c
rename to libc/upstream-openbsd/lib/libc/stdio/ungetc.c
index b493d21..675733a 100644
--- a/libc/stdio/ungetc.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/ungetc.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: ungetc.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */
+/*	$OpenBSD: ungetc.c,v 1.12 2009/11/09 00:18:27 kurt Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
diff --git a/libc/stdio/vasprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vasprintf.c
similarity index 91%
rename from libc/stdio/vasprintf.c
rename to libc/upstream-openbsd/lib/libc/stdio/vasprintf.c
index 1630ccb..8fe7c5b 100644
--- a/libc/stdio/vasprintf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/vasprintf.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: vasprintf.c,v 1.13 2006/01/06 18:53:04 millert Exp $	*/
+/*	$OpenBSD: vasprintf.c,v 1.16 2009/11/09 00:18:27 kurt Exp $	*/
 
 /*
  * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -48,7 +48,10 @@
 	return (ret);
 
 err:
-	free(f._bf._base);
+	if (f._bf._base) {
+		free(f._bf._base);
+		f._bf._base = NULL;
+	}
 	*str = NULL;
 	errno = ENOMEM;
 	return (-1);
diff --git a/libc/stdio/vprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vprintf.c
similarity index 100%
rename from libc/stdio/vprintf.c
rename to libc/upstream-openbsd/lib/libc/stdio/vprintf.c
diff --git a/libc/stdio/vscanf.c b/libc/upstream-openbsd/lib/libc/stdio/vscanf.c
similarity index 100%
rename from libc/stdio/vscanf.c
rename to libc/upstream-openbsd/lib/libc/stdio/vscanf.c
diff --git a/libc/stdio/vsnprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vsnprintf.c
similarity index 96%
rename from libc/stdio/vsnprintf.c
rename to libc/upstream-openbsd/lib/libc/stdio/vsnprintf.c
index ca30f94..8b1a088 100644
--- a/libc/stdio/vsnprintf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/vsnprintf.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: vsnprintf.c,v 1.12 2006/01/06 18:53:04 millert Exp $ */
+/*	$OpenBSD: vsnprintf.c,v 1.15 2009/11/09 00:18:28 kurt Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
diff --git a/libc/stdio/vsprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vsprintf.c
similarity index 96%
rename from libc/stdio/vsprintf.c
rename to libc/upstream-openbsd/lib/libc/stdio/vsprintf.c
index 846ee8a..308ff37 100644
--- a/libc/stdio/vsprintf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/vsprintf.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: vsprintf.c,v 1.13 2006/01/06 18:53:04 millert Exp $ */
+/*	$OpenBSD: vsprintf.c,v 1.16 2009/11/09 00:18:28 kurt Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
diff --git a/libc/stdio/wbuf.c b/libc/upstream-openbsd/lib/libc/stdio/wbuf.c
similarity index 97%
rename from libc/stdio/wbuf.c
rename to libc/upstream-openbsd/lib/libc/stdio/wbuf.c
index e09ac59..6aa00e1 100644
--- a/libc/stdio/wbuf.c
+++ b/libc/upstream-openbsd/lib/libc/stdio/wbuf.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: wbuf.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */
+/*	$OpenBSD: wbuf.c,v 1.12 2009/11/09 00:18:28 kurt Exp $ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
diff --git a/libc/stdio/fgetc.c b/libc/upstream-openbsd/lib/libc/stdlib/atoi.c
similarity index 82%
copy from libc/stdio/fgetc.c
copy to libc/upstream-openbsd/lib/libc/stdlib/atoi.c
index 0a6d54e..b084267 100644
--- a/libc/stdio/fgetc.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/atoi.c
@@ -1,10 +1,7 @@
-/*	$OpenBSD: fgetc.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
+/*	$OpenBSD: atoi.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
+/*
+ * Copyright (c) 1988 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
@@ -31,10 +28,10 @@
  * SUCH DAMAGE.
  */
 
-#include <stdio.h>
+#include <stdlib.h>
 
 int
-fgetc(FILE *fp)
+atoi(const char *str)
 {
-	return (getc(fp));
+	return((int)strtol(str, (char **)NULL, 10));
 }
diff --git a/libc/stdio/fgetc.c b/libc/upstream-openbsd/lib/libc/stdlib/atol.c
similarity index 82%
copy from libc/stdio/fgetc.c
copy to libc/upstream-openbsd/lib/libc/stdlib/atol.c
index 0a6d54e..1970804 100644
--- a/libc/stdio/fgetc.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/atol.c
@@ -1,10 +1,7 @@
-/*	$OpenBSD: fgetc.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
+/*	$OpenBSD: atol.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
+/*
+ * Copyright (c) 1988 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
@@ -31,10 +28,10 @@
  * SUCH DAMAGE.
  */
 
-#include <stdio.h>
+#include <stdlib.h>
 
-int
-fgetc(FILE *fp)
+long
+atol(const char *str)
 {
-	return (getc(fp));
+	return(strtol(str, (char **)NULL, 10));
 }
diff --git a/libc/stdio/fgetc.c b/libc/upstream-openbsd/lib/libc/stdlib/atoll.c
similarity index 82%
copy from libc/stdio/fgetc.c
copy to libc/upstream-openbsd/lib/libc/stdlib/atoll.c
index 0a6d54e..a65e682 100644
--- a/libc/stdio/fgetc.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/atoll.c
@@ -1,10 +1,7 @@
-/*	$OpenBSD: fgetc.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
+/*	$OpenBSD: atoll.c,v 1.3 2005/08/08 08:05:36 espie Exp $ */
+/*
+ * Copyright (c) 1988 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
@@ -31,10 +28,11 @@
  * SUCH DAMAGE.
  */
 
-#include <stdio.h>
+#include <stdlib.h>
 
-int
-fgetc(FILE *fp)
+long long
+atoll(str)
+	const char *str;
 {
-	return (getc(fp));
+	return(strtoll(str, (char **)NULL, 10));
 }
diff --git a/libc/stdlib/strtoimax.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoimax.c
similarity index 82%
rename from libc/stdlib/strtoimax.c
rename to libc/upstream-openbsd/lib/libc/stdlib/strtoimax.c
index 0b4323d..2c77f41 100644
--- a/libc/stdlib/strtoimax.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoimax.c
@@ -91,40 +91,9 @@
 	 * Set any if any `digits' consumed; make it negative to indicate
 	 * overflow.
 	 */
-
-	/* BIONIC: avoid division and module for common cases */
-#define  CASE_BASE(x) \
-            case x:  \
-	        if (neg) { \
-                    cutlim = INTMAX_MIN % x; \
-		    cutoff = INTMAX_MIN / x; \
-	        } else { \
-		    cutlim = INTMAX_MAX % x; \
-		    cutoff = INTMAX_MAX / x; \
-		 }; \
-		 break
-
-	switch (base) {
-            case 4:
-                if (neg) {
-                    cutlim = (int)(INTMAX_MIN % 4);
-                    cutoff = INTMAX_MIN / 4;
-                } else {
-                    cutlim = (int)(INTMAX_MAX % 4);
-                    cutoff = INTMAX_MAX / 4;
-                }
-                break;
-
-	    CASE_BASE(8);
-	    CASE_BASE(10);
-	    CASE_BASE(16);
-	    default:
-	              cutoff  = neg ? INTMAX_MIN : INTMAX_MAX;
-		      cutlim  = cutoff % base;
-	              cutoff /= base;
-	}
-#undef CASE_BASE
-
+	cutoff = neg ? INTMAX_MIN : INTMAX_MAX;
+	cutlim = cutoff % base;
+	cutoff /= base;
 	if (neg) {
 		if (cutlim > 0) {
 			cutlim -= base;
diff --git a/libc/stdlib/strtol.c b/libc/upstream-openbsd/lib/libc/stdlib/strtol.c
similarity index 93%
rename from libc/stdlib/strtol.c
rename to libc/upstream-openbsd/lib/libc/stdlib/strtol.c
index a3cdbcd..dc2cf88 100644
--- a/libc/stdlib/strtol.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtol.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: strtol.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */
+/*	$OpenBSD: strtol.c,v 1.9 2013/04/17 17:40:35 tedu Exp $ */
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
  * All rights reserved.
@@ -49,6 +49,17 @@
 	int neg, any, cutlim;
 
 	/*
+	 * Ensure that base is between 2 and 36 inclusive, or the special
+	 * value of 0.
+	 */
+	if (base != 0 && (base < 2 || base > 36)) {
+		if (endptr != 0)
+			*endptr = (char *)nptr;
+		errno = EINVAL;
+		return 0;
+	}
+
+	/*
 	 * Skip white space and pick up leading +/- sign if any.
 	 * If base is 0, allow 0x for hex and 0 for octal, else
 	 * assume decimal; if base is already 16, allow 0x.
diff --git a/libc/stdlib/strtol.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoll.c
similarity index 80%
copy from libc/stdlib/strtol.c
copy to libc/upstream-openbsd/lib/libc/stdlib/strtoll.c
index a3cdbcd..4bcc556 100644
--- a/libc/stdlib/strtol.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoll.c
@@ -1,6 +1,6 @@
-/*	$OpenBSD: strtol.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */
+/* $OpenBSD: strtoll.c,v 1.7 2013/03/28 18:09:38 martynas Exp $ */
 /*-
- * Copyright (c) 1990 The Regents of the University of California.
+ * Copyright (c) 1992 The Regents of the University of California.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -28,23 +28,24 @@
  * SUCH DAMAGE.
  */
 
+#include <sys/types.h>
+
 #include <ctype.h>
 #include <errno.h>
 #include <limits.h>
 #include <stdlib.h>
 
-
 /*
- * Convert a string to a long integer.
+ * Convert a string to a long long.
  *
  * Ignores `locale' stuff.  Assumes that the upper and lower case
  * alphabets and digits are each contiguous.
  */
-long
-strtol(const char *nptr, char **endptr, int base)
+long long
+strtoll(const char *nptr, char **endptr, int base)
 {
 	const char *s;
-	long acc, cutoff;
+	long long acc, cutoff;
 	int c;
 	int neg, any, cutlim;
 
@@ -81,17 +82,18 @@
 	 * followed by a legal input character, is too big.  One that
 	 * is equal to this value may be valid or not; the limit
 	 * between valid and invalid numbers is then based on the last
-	 * digit.  For instance, if the range for longs is
-	 * [-2147483648..2147483647] and the input base is 10,
-	 * cutoff will be set to 214748364 and cutlim to either
-	 * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
-	 * a value > 214748364, or equal but the next digit is > 7 (or 8),
-	 * the number is too big, and we will return a range error.
+	 * digit.  For instance, if the range for long longs is
+	 * [-9223372036854775808..9223372036854775807] and the input base
+	 * is 10, cutoff will be set to 922337203685477580 and cutlim to
+	 * either 7 (neg==0) or 8 (neg==1), meaning that if we have
+	 * accumulated a value > 922337203685477580, or equal but the
+	 * next digit is > 7 (or 8), the number is too big, and we will
+	 * return a range error.
 	 *
 	 * Set any if any `digits' consumed; make it negative to indicate
 	 * overflow.
 	 */
-	cutoff = neg ? LONG_MIN : LONG_MAX;
+	cutoff = neg ? LLONG_MIN : LLONG_MAX;
 	cutlim = cutoff % base;
 	cutoff /= base;
 	if (neg) {
@@ -115,7 +117,7 @@
 		if (neg) {
 			if (acc < cutoff || (acc == cutoff && c > cutlim)) {
 				any = -1;
-				acc = LONG_MIN;
+				acc = LLONG_MIN;
 				errno = ERANGE;
 			} else {
 				any = 1;
@@ -125,7 +127,7 @@
 		} else {
 			if (acc > cutoff || (acc == cutoff && c > cutlim)) {
 				any = -1;
-				acc = LONG_MAX;
+				acc = LLONG_MAX;
 				errno = ERANGE;
 			} else {
 				any = 1;
@@ -138,3 +140,5 @@
 		*endptr = (char *) (any ? s - 1 : nptr);
 	return (acc);
 }
+
+__strong_alias(strtoq, strtoll);
diff --git a/libc/stdlib/strtoul.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoul.c
similarity index 97%
rename from libc/stdlib/strtoul.c
rename to libc/upstream-openbsd/lib/libc/stdlib/strtoul.c
index 61dbb6f..a236365 100644
--- a/libc/stdlib/strtoul.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoul.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: strtoul.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */
+/*	$OpenBSD: strtoul.c,v 1.8 2013/04/17 17:40:35 tedu Exp $ */
 /*
  * Copyright (c) 1990 Regents of the University of California.
  * All rights reserved.
diff --git a/libc/stdlib/strtoul.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoull.c
similarity index 81%
copy from libc/stdlib/strtoul.c
copy to libc/upstream-openbsd/lib/libc/stdlib/strtoull.c
index 61dbb6f..28f613a 100644
--- a/libc/stdlib/strtoul.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoull.c
@@ -1,6 +1,6 @@
-/*	$OpenBSD: strtoul.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */
-/*
- * Copyright (c) 1990 Regents of the University of California.
+/*	$OpenBSD: strtoull.c,v 1.6 2013/03/28 18:09:38 martynas Exp $ */
+/*-
+ * Copyright (c) 1992 The Regents of the University of California.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -28,27 +28,29 @@
  * SUCH DAMAGE.
  */
 
+#include <sys/types.h>
+
 #include <ctype.h>
 #include <errno.h>
 #include <limits.h>
 #include <stdlib.h>
 
 /*
- * Convert a string to an unsigned long integer.
+ * Convert a string to an unsigned long long.
  *
  * Ignores `locale' stuff.  Assumes that the upper and lower case
  * alphabets and digits are each contiguous.
  */
-unsigned long
-strtoul(const char *nptr, char **endptr, int base)
+unsigned long long
+strtoull(const char *nptr, char **endptr, int base)
 {
 	const char *s;
-	unsigned long acc, cutoff;
+	unsigned long long acc, cutoff;
 	int c;
 	int neg, any, cutlim;
 
 	/*
-	 * See strtol for comments as to the logic used.
+	 * See strtoq for comments as to the logic used.
 	 */
 	s = nptr;
 	do {
@@ -57,7 +59,7 @@
 	if (c == '-') {
 		neg = 1;
 		c = *s++;
-	} else {
+	} else { 
 		neg = 0;
 		if (c == '+')
 			c = *s++;
@@ -71,8 +73,8 @@
 	if (base == 0)
 		base = c == '0' ? 8 : 10;
 
-	cutoff = ULONG_MAX / (unsigned long)base;
-	cutlim = ULONG_MAX % (unsigned long)base;
+	cutoff = ULLONG_MAX / (unsigned long long)base;
+	cutlim = ULLONG_MAX % (unsigned long long)base;
 	for (acc = 0, any = 0;; c = (unsigned char) *s++) {
 		if (isdigit(c))
 			c -= '0';
@@ -86,11 +88,11 @@
 			continue;
 		if (acc > cutoff || (acc == cutoff && c > cutlim)) {
 			any = -1;
-			acc = ULONG_MAX;
+			acc = ULLONG_MAX;
 			errno = ERANGE;
 		} else {
 			any = 1;
-			acc *= (unsigned long)base;
+			acc *= (unsigned long long)base;
 			acc += c;
 		}
 	}
@@ -100,3 +102,5 @@
 		*endptr = (char *) (any ? s - 1 : nptr);
 	return (acc);
 }
+
+__strong_alias(strtouq, strtoull);
diff --git a/libc/stdlib/strtoumax.c b/libc/upstream-openbsd/lib/libc/stdlib/strtoumax.c
similarity index 87%
rename from libc/stdlib/strtoumax.c
rename to libc/upstream-openbsd/lib/libc/stdlib/strtoumax.c
index e1ff623..ce6e2c0 100644
--- a/libc/stdlib/strtoumax.c
+++ b/libc/upstream-openbsd/lib/libc/stdlib/strtoumax.c
@@ -57,7 +57,7 @@
 	if (c == '-') {
 		neg = 1;
 		c = *s++;
-	} else {
+	} else { 
 		neg = 0;
 		if (c == '+')
 			c = *s++;
@@ -71,21 +71,8 @@
 	if (base == 0)
 		base = c == '0' ? 8 : 10;
 
-        /* BIONIC: avoid division and modulo for common cases */
-#define  CASE_BASE(x)                            \
-            case x: cutoff = UINTMAX_MAX / x;    \
-	            cutlim = UINTMAX_MAX % x;    \
-		    break
-
-        switch (base) {
-        CASE_BASE(8);
-	CASE_BASE(10);
-	CASE_BASE(16);
-	default:
-	    cutoff = UINTMAX_MAX / base;
-	    cutlim = UINTMAX_MAX % base;
-	}
-
+	cutoff = UINTMAX_MAX / (uintmax_t)base;
+	cutlim = UINTMAX_MAX % (uintmax_t)base;
 	for (acc = 0, any = 0;; c = (unsigned char) *s++) {
 		if (isdigit(c))
 			c -= '0';
diff --git a/libc/string/strcasecmp.c b/libc/upstream-openbsd/lib/libc/string/strcasecmp.c
similarity index 100%
rename from libc/string/strcasecmp.c
rename to libc/upstream-openbsd/lib/libc/string/strcasecmp.c
diff --git a/libc/string/strcspn.c b/libc/upstream-openbsd/lib/libc/string/strcspn.c
similarity index 100%
rename from libc/string/strcspn.c
rename to libc/upstream-openbsd/lib/libc/string/strcspn.c
diff --git a/libc/string/strdup.c b/libc/upstream-openbsd/lib/libc/string/strdup.c
similarity index 100%
rename from libc/string/strdup.c
rename to libc/upstream-openbsd/lib/libc/string/strdup.c
diff --git a/libc/upstream-openbsd/lib/libc/string/strndup.c b/libc/upstream-openbsd/lib/libc/string/strndup.c
new file mode 100644
index 0000000..27701ac
--- /dev/null
+++ b/libc/upstream-openbsd/lib/libc/string/strndup.c
@@ -0,0 +1,39 @@
+/*	$OpenBSD: strndup.c,v 1.1 2010/05/18 22:24:55 tedu Exp $	*/
+
+/*
+ * Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+char *
+strndup(const char *str, size_t maxlen)
+{
+	char *copy;
+	size_t len;
+
+	len = strnlen(str, maxlen);
+	copy = malloc(len + 1);
+	if (copy != NULL) {
+		(void)memcpy(copy, str, len);
+		copy[len] = '\0';
+	}
+
+	return copy;
+}
diff --git a/libc/string/strpbrk.c b/libc/upstream-openbsd/lib/libc/string/strpbrk.c
similarity index 100%
rename from libc/string/strpbrk.c
rename to libc/upstream-openbsd/lib/libc/string/strpbrk.c
diff --git a/libc/string/strsep.c b/libc/upstream-openbsd/lib/libc/string/strsep.c
similarity index 97%
rename from libc/string/strsep.c
rename to libc/upstream-openbsd/lib/libc/string/strsep.c
index c44bc5b..bcca681 100644
--- a/libc/string/strsep.c
+++ b/libc/upstream-openbsd/lib/libc/string/strsep.c
@@ -34,7 +34,7 @@
 
 /*
  * Get next token from string *stringp, where tokens are possibly-empty
- * strings separated by characters from delim.
+ * strings separated by characters from delim.  
  *
  * Writes NULs into the string at *stringp to end tokens.
  * delim need not remain constant from call to call.
diff --git a/libc/string/strspn.c b/libc/upstream-openbsd/lib/libc/string/strspn.c
similarity index 100%
rename from libc/string/strspn.c
rename to libc/upstream-openbsd/lib/libc/string/strspn.c
diff --git a/libc/string/strstr.c b/libc/upstream-openbsd/lib/libc/string/strstr.c
similarity index 100%
rename from libc/string/strstr.c
rename to libc/upstream-openbsd/lib/libc/string/strstr.c
diff --git a/libc/string/strtok.c b/libc/upstream-openbsd/lib/libc/string/strtok.c
similarity index 100%
rename from libc/string/strtok.c
rename to libc/upstream-openbsd/lib/libc/string/strtok.c
diff --git a/libc/include/asm/page.h b/libc/upstream-openbsd/openbsd-compat.h
similarity index 69%
rename from libc/include/asm/page.h
rename to libc/upstream-openbsd/openbsd-compat.h
index d401a3f..428156f 100644
--- a/libc/include/asm/page.h
+++ b/libc/upstream-openbsd/openbsd-compat.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 The Android Open Source Project
+ * Copyright (C) 2014 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.
@@ -14,12 +14,9 @@
  * limitations under the License.
  */
 
-#ifndef __ASM_PAGE_H
-#define __ASM_PAGE_H
+#ifndef _BIONIC_OPENBSD_COMPAT_H_included
+#define _BIONIC_OPENBSD_COMPAT_H_included
 
-/* New code should use sysconf(_SC_PAGESIZE) instead. */
-#define PAGE_SHIFT 12
-#define PAGE_SIZE (1ULL << PAGE_SHIFT)
-#define PAGE_MASK (~(PAGE_SIZE - 1))
+#define _GNU_SOURCE
 
 #endif
diff --git a/linker/arch/arm64/begin.S b/linker/arch/arm64/begin.S
index 55618b7..c96ede7 100644
--- a/linker/arch/arm64/begin.S
+++ b/linker/arch/arm64/begin.S
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 ENTRY(_start)
   mov x0, sp
diff --git a/linker/arch/mips64/begin.S b/linker/arch/mips64/begin.S
index 9a85925..9e741c0 100644
--- a/linker/arch/mips64/begin.S
+++ b/linker/arch/mips64/begin.S
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 #if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
 #define ELF_DYNSZ       8
diff --git a/linker/arch/x86_64/begin.S b/linker/arch/x86_64/begin.S
index 9ecad1a..aff4660 100644
--- a/linker/arch/x86_64/begin.S
+++ b/linker/arch/x86_64/begin.S
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 
-#include <machine/asm.h>
+#include <private/bionic_asm.h>
 
 ENTRY(_start)
   /* Pass elfdata to __linker_init. */
diff --git a/linker/linker.cpp b/linker/linker.cpp
index ead9bd4..156864c 100755
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -1744,7 +1744,7 @@
         case DT_MIPS_RLD_MAP:
             // Set the DT_MIPS_RLD_MAP entry to the address of _r_debug for GDB.
             {
-              r_debug** dp = reinterpret_cast<r_debug**>(d->d_un.d_ptr);
+              r_debug** dp = reinterpret_cast<r_debug**>(base + d->d_un.d_ptr);
               *dp = &_r_debug;
             }
             break;
diff --git a/tests/math_test.cpp b/tests/math_test.cpp
index c8974d3..fc561bc 100644
--- a/tests/math_test.cpp
+++ b/tests/math_test.cpp
@@ -16,11 +16,42 @@
 
 #define _DECLARE_C99_LDBL_MATH 1
 
+// This include (and the associated definition of __test_capture_signbit)
+// must be placed before any files that include <cmath> (gtest.h in this case).
+//
+// <math.h> is required to define generic macros signbit, isfinite and
+// several other such functions.
+//
+// <cmath> is required to undef declarations of these macros in the global
+// namespace and make equivalent functions available in namespace std. Our
+// stlport implementation does this only for signbit, isfinite, isinf and
+// isnan.
+//
+// NOTE: We don't write our test using std::signbit because we want to be
+// sure that we're testing the bionic version of signbit. The C++ libraries
+// are free to reimplement signbit or delegate to compiler builtins if they
+// please.
+#include <math.h>
+
+namespace {
+template<typename T> inline int test_capture_signbit(const T in) {
+  return signbit(in);
+}
+template<typename T> inline int test_capture_isfinite(const T in) {
+  return isfinite(in);
+}
+template<typename T> inline int test_capture_isnan(const T in) {
+  return isnan(in);
+}
+template<typename T> inline int test_capture_isinf(const T in) {
+  return isinf(in);
+}
+}
+
 #include <gtest/gtest.h>
 
 #include <fenv.h>
 #include <limits.h>
-#include <math.h>
 #include <stdint.h>
 
 float float_subnormal() {
@@ -59,27 +90,25 @@
   ASSERT_EQ(FP_ZERO, fpclassify(0.0));
 }
 
-/* TODO: stlport breaks the isfinite macro
 TEST(math, isfinite) {
-  ASSERT_TRUE(isfinite(123.0f));
-  ASSERT_TRUE(isfinite(123.0));
-  ASSERT_FALSE(isfinite(HUGE_VALF));
-  ASSERT_FALSE(isfinite(HUGE_VAL));
+  ASSERT_TRUE(test_capture_isfinite(123.0f));
+  ASSERT_TRUE(test_capture_isfinite(123.0));
+  ASSERT_FALSE(test_capture_isfinite(HUGE_VALF));
+  ASSERT_FALSE(test_capture_isfinite(HUGE_VAL));
 }
-*/
 
 TEST(math, isinf) {
-  ASSERT_FALSE(isinf(123.0f));
-  ASSERT_FALSE(isinf(123.0));
-  ASSERT_TRUE(isinf(HUGE_VALF));
-  ASSERT_TRUE(isinf(HUGE_VAL));
+  ASSERT_FALSE(test_capture_isinf(123.0f));
+  ASSERT_FALSE(test_capture_isinf(123.0));
+  ASSERT_TRUE(test_capture_isinf(HUGE_VALF));
+  ASSERT_TRUE(test_capture_isinf(HUGE_VAL));
 }
 
 TEST(math, isnan) {
-  ASSERT_FALSE(isnan(123.0f));
-  ASSERT_FALSE(isnan(123.0));
-  ASSERT_TRUE(isnan(nanf("")));
-  ASSERT_TRUE(isnan(nan("")));
+  ASSERT_FALSE(test_capture_isnan(123.0f));
+  ASSERT_FALSE(test_capture_isnan(123.0));
+  ASSERT_TRUE(test_capture_isnan(nanf("")));
+  ASSERT_TRUE(test_capture_isnan(nan("")));
 }
 
 TEST(math, isnormal) {
@@ -90,19 +119,16 @@
 }
 
 // TODO: isgreater, isgreaterequals, isless, islessequal, islessgreater, isunordered
-
-/* TODO: stlport breaks the signbit macro
 TEST(math, signbit) {
-  ASSERT_EQ(0, signbit(0.0f));
-  ASSERT_EQ(0, signbit(0.0));
+  ASSERT_EQ(0, test_capture_signbit(0.0f));
+  ASSERT_EQ(0, test_capture_signbit(0.0));
 
-  ASSERT_EQ(0, signbit(1.0f));
-  ASSERT_EQ(0, signbit(1.0));
+  ASSERT_EQ(0, test_capture_signbit(1.0f));
+  ASSERT_EQ(0, test_capture_signbit(1.0));
 
-  ASSERT_NE(0, signbit(-1.0f));
-  ASSERT_NE(0, signbit(-1.0));
+  ASSERT_NE(0, test_capture_signbit(-1.0f));
+  ASSERT_NE(0, test_capture_signbit(-1.0));
 }
-*/
 
 TEST(math, __fpclassifyd) {
 #if defined(__BIONIC__)
diff --git a/tests/sys_mman_test.cpp b/tests/sys_mman_test.cpp
index 57067d7..6ac279f 100644
--- a/tests/sys_mman_test.cpp
+++ b/tests/sys_mman_test.cpp
@@ -20,11 +20,11 @@
 #include <unistd.h>
 
 TEST(sys_mman, mmap_negative) {
-  off_t off = -sysconf(_SC_PAGESIZE); // Aligned but negative.
+  off_t off = -sysconf(_SC_PAGE_SIZE); // Aligned but negative.
   ASSERT_EQ(MAP_FAILED, mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, off));
 }
 
 TEST(sys_mman, mmap64_negative) {
-  off64_t off64 = -sysconf(_SC_PAGESIZE); // Aligned but negative.
+  off64_t off64 = -sysconf(_SC_PAGE_SIZE); // Aligned but negative.
   ASSERT_EQ(MAP_FAILED, mmap64(NULL, 4096, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, off64));
 }