Support compiling libjemalloc5 against musl
Musl in the Android platform is configured to use libjemalloc5 by
default as the built-in malloc causes a segfault when running aprotoc.
Fix a build error that assumes pthread_t is an unsigned long when
initializing it to zero.
Adjust the host configuration to work with musl.
Bug: 190084016
Test: m out/soong/host/linux-x86/bin/aprotoc && out/soong/host/linux-x86/bin/aprotoc
Change-Id: I5b5d5226744817b8705d58f6b71cf6c62b128eee
diff --git a/Android.bp b/Android.bp
index 80eede9..15f7d63 100644
--- a/Android.bp
+++ b/Android.bp
@@ -201,6 +201,11 @@
system_shared_libs: [],
header_libs: ["libc_headers"],
},
+ musl: {
+ // Linking against musl uses libjemalloc5 by default, list only
+ // libc_musl here to avoid a circular dependency.
+ system_shared_libs: ["libc_musl"],
+ },
},
}
diff --git a/include/jemalloc/internal/jemalloc_internal_defs_host.h b/include/jemalloc/internal/jemalloc_internal_defs_host.h
index 38f91bc..f4c973b 100644
--- a/include/jemalloc/internal/jemalloc_internal_defs_host.h
+++ b/include/jemalloc/internal/jemalloc_internal_defs_host.h
@@ -376,6 +376,8 @@
/*
* Defined if strerror_r returns char * if _GNU_SOURCE is defined.
*/
+#ifdef __GLIBC__
#define JEMALLOC_STRERROR_R_RETURNS_CHAR_WITH_GNU_SOURCE
+#endif
#endif /* JEMALLOC_INTERNAL_DEFS_H_ */
diff --git a/src/jemalloc.c b/src/jemalloc.c
index 0584362..bf5976b 100644
--- a/src/jemalloc.c
+++ b/src/jemalloc.c
@@ -111,7 +111,7 @@
#ifdef JEMALLOC_THREADED_INIT
/* Used to let the initializing thread recursively allocate. */
-# define NO_INITIALIZER ((unsigned long)0)
+# define NO_INITIALIZER ((pthread_t)0)
# define INITIALIZER pthread_self()
# define IS_INITIALIZER (malloc_initializer == pthread_self())
static pthread_t malloc_initializer = NO_INITIALIZER;