Merge "Fix the default alignment of the allocations."
diff --git a/libc/Android.mk b/libc/Android.mk
index 42f717e..f2004e1 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -850,7 +850,9 @@
 LOCAL_SRC_FILES := $(libc_upstream_netbsd_src_files)
 LOCAL_CFLAGS := \
     $(libc_common_cflags) \
-    -Wno-sign-compare -Wno-uninitialized \
+    -Wno-sign-compare \
+    -Wno-uninitialized \
+    -Wno-unused-parameter \
     -DPOSIX_MISTAKE \
     -include netbsd-compat.h \
 
diff --git a/libc/upstream-netbsd/android/include/netbsd-compat.h b/libc/upstream-netbsd/android/include/netbsd-compat.h
index 8d1c46b..665d65e 100644
--- a/libc/upstream-netbsd/android/include/netbsd-compat.h
+++ b/libc/upstream-netbsd/android/include/netbsd-compat.h
@@ -20,17 +20,16 @@
 #define _BSD_SOURCE
 #define _GNU_SOURCE
 
-// NetBSD uses _DIAGASSERT to null-check arguments and the like.
-#include <assert.h>
-#define _DIAGASSERT(e) ((e) ? (void) 0 : __assert2(__FILE__, __LINE__, __func__, #e))
-
-// TODO: update our <sys/cdefs.h> to support this properly.
-#define __type_fit(t, a) (0 == 0)
+// NetBSD uses _DIAGASSERT to null-check arguments and the like,
+// but it's clear from the number of mistakes in their assertions
+// that they don't actually test or ship with this.
+#define _DIAGASSERT(e) /* nothing */
 
 // TODO: we don't yet have thread-safe environment variables.
 #define __readlockenv() 0
 #define __unlockenv() 0
 
+#include <sys/cdefs.h>
 #include <stddef.h>
 __LIBC_HIDDEN__ int reallocarr(void*, size_t, size_t);
 
diff --git a/linker/Android.mk b/linker/Android.mk
index 85ac0ca..5bbe172 100644
--- a/linker/Android.mk
+++ b/linker/Android.mk
@@ -1,6 +1,20 @@
 LOCAL_PATH := $(call my-dir)
 
 include $(CLEAR_VARS)
+LOCAL_CLANG := true
+
+LOCAL_MODULE := liblinker_malloc
+
+LOCAL_SRC_FILES := \
+    linker_allocator.cpp \
+    linker_memory.cpp
+
+# We need to access Bionic private headers in the linker.
+LOCAL_CFLAGS += -I$(LOCAL_PATH)/../libc/
+
+include $(BUILD_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
 
 LOCAL_CLANG := true
 
@@ -8,11 +22,9 @@
     debugger.cpp \
     dlfcn.cpp \
     linker.cpp \
-    linker_allocator.cpp \
     linker_block_allocator.cpp \
     linker_libc_support.c \
     linker_mapped_file_fragment.cpp \
-    linker_memory.cpp \
     linker_phdr.cpp \
     linker_sdk_versions.cpp \
     linker_utils.cpp \
@@ -63,7 +75,7 @@
 
 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
 
-LOCAL_STATIC_LIBRARIES := libc_nomalloc libziparchive libutils libbase libz liblog
+LOCAL_STATIC_LIBRARIES := libc_nomalloc liblinker_malloc libziparchive libutils libbase libz liblog
 
 LOCAL_FORCE_STATIC_EXECUTABLE := true
 
diff --git a/linker/tests/Android.mk b/linker/tests/Android.mk
index a061877..e9f43e9 100644
--- a/linker/tests/Android.mk
+++ b/linker/tests/Android.mk
@@ -32,11 +32,12 @@
   linker_block_allocator_test.cpp \
   ../linker_block_allocator.cpp \
   linker_memory_allocator_test.cpp \
-  ../linker_allocator.cpp \
   linker_utils_test.cpp \
   ../linker_utils.cpp
 
 # for __libc_fatal
 LOCAL_SRC_FILES += ../../libc/bionic/libc_logging.cpp
 
+LOCAL_STATIC_LIBRARIES := liblinker_malloc
+
 include $(BUILD_NATIVE_TEST)
diff --git a/tests/regex_test.cpp b/tests/regex_test.cpp
index 4a4409e..0e7f8dd 100644
--- a/tests/regex_test.cpp
+++ b/tests/regex_test.cpp
@@ -46,3 +46,14 @@
   ASSERT_EQ(2, matches[0].rm_eo);
   regfree(&re);
 }
+
+TEST(regex, regerror_NULL_0) {
+  regex_t re;
+  int error = regcomp(&re, "*", REG_EXTENDED);
+  ASSERT_NE(0, error);
+
+  // Passing a null pointer and a size of 0 is a legitimate way to ask
+  // how large a buffer we would need for the error message.
+  int error_length = regerror(error, &re, nullptr, 0);
+  ASSERT_GT(error_length, 0);
+}