Created
June 1, 2016 12:59
-
-
Save pwaller/2337f3290f12634cad3e3730cff0a6c1 to your computer and use it in GitHub Desktop.
Make clang sanitizers work under musl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/asan/asan_linux.cc b/lib/asan/asan_linux.cc | |
index e26b400..9618933 100644 | |
--- a/lib/asan/asan_linux.cc | |
+++ b/lib/asan/asan_linux.cc | |
@@ -39,7 +39,7 @@ | |
#include <sys/link_elf.h> | |
#endif | |
-#if SANITIZER_ANDROID || SANITIZER_FREEBSD | |
+#if SANITIZER_ANDROID || SANITIZER_FREEBSD || SANITIZER_NONGNU | |
#include <ucontext.h> | |
extern "C" void* _DYNAMIC; | |
#else | |
@@ -75,7 +75,7 @@ void *AsanDoesNotSupportStaticLinkage() { | |
return &_DYNAMIC; // defined in link.h | |
} | |
-#if SANITIZER_ANDROID | |
+#if SANITIZER_ANDROID || SANITIZER_NONGNU | |
// FIXME: should we do anything for Android? | |
void AsanCheckDynamicRTPrereqs() {} | |
void AsanCheckIncompatibleRT() {} | |
diff --git a/lib/interception/interception_linux.cc b/lib/interception/interception_linux.cc | |
index 6e908ac..76c1688 100644 | |
--- a/lib/interception/interception_linux.cc | |
+++ b/lib/interception/interception_linux.cc | |
@@ -24,7 +24,7 @@ bool GetRealFunctionAddress(const char *func_name, uptr *func_addr, | |
return real == wrapper; | |
} | |
-#if !defined(__ANDROID__) // android does not have dlvsym | |
+#if !defined(__ANDROID__) && defined(__GLIBC__) // android does not have dlvsym | |
void *GetFuncAddrVer(const char *func_name, const char *ver) { | |
return dlvsym(RTLD_NEXT, func_name, ver); | |
} | |
diff --git a/lib/msan/msan_linux.cc b/lib/msan/msan_linux.cc | |
index ab3be91..6656416 100644 | |
--- a/lib/msan/msan_linux.cc | |
+++ b/lib/msan/msan_linux.cc | |
@@ -13,7 +13,7 @@ | |
//===----------------------------------------------------------------------===// | |
#include "sanitizer_common/sanitizer_platform.h" | |
-#if SANITIZER_FREEBSD || SANITIZER_LINUX | |
+#if SANITIZER_FREEBSD || SANITIZER_LINUX && !SANITIZER_NONGNU | |
#include "msan.h" | |
#include "msan_thread.h" | |
diff --git a/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc b/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc | |
index fcd0a3d..b40befd 100644 | |
--- a/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc | |
+++ b/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc | |
@@ -97,7 +97,7 @@ static void ioctl_table_fill() { | |
_(SIOCGETVIFCNT, WRITE, struct_sioc_vif_req_sz); | |
#endif | |
-#if SANITIZER_LINUX | |
+#if SANITIZER_LINUX && !SANITIZER_NONGNU | |
// Conflicting request ids. | |
// _(CDROMAUDIOBUFSIZ, NONE, 0); | |
// _(SNDCTL_TMR_CONTINUE, NONE, 0); | |
@@ -358,7 +358,7 @@ static void ioctl_table_fill() { | |
_(VT_WAITACTIVE, NONE, 0); | |
#endif | |
-#if SANITIZER_LINUX && !SANITIZER_ANDROID | |
+#if SANITIZER_LINUX && !SANITIZER_ANDROID && !SANITIZER_NONGNU | |
// _(SIOCDEVPLIP, WRITE, struct_ifreq_sz); // the same as EQL_ENSLAVE | |
_(CYGETDEFTHRESH, WRITE, sizeof(int)); | |
_(CYGETDEFTIMEOUT, WRITE, sizeof(int)); | |
diff --git a/lib/sanitizer_common/sanitizer_common_syscalls.inc b/lib/sanitizer_common/sanitizer_common_syscalls.inc | |
index 008e577..5883a97 100644 | |
--- a/lib/sanitizer_common/sanitizer_common_syscalls.inc | |
+++ b/lib/sanitizer_common/sanitizer_common_syscalls.inc | |
@@ -2042,7 +2042,7 @@ POST_SYSCALL(setrlimit)(long res, long resource, void *rlim) { | |
} | |
} | |
-#if !SANITIZER_ANDROID | |
+#if !SANITIZER_ANDROID && !SANITIZER_NONGNU | |
PRE_SYSCALL(prlimit64)(long pid, long resource, const void *new_rlim, | |
void *old_rlim) { | |
if (new_rlim) PRE_READ(new_rlim, struct_rlimit64_sz); | |
diff --git a/lib/sanitizer_common/sanitizer_linux_libcdep.cc b/lib/sanitizer_common/sanitizer_linux_libcdep.cc | |
index 04031d2..a95fe51 100644 | |
--- a/lib/sanitizer_common/sanitizer_linux_libcdep.cc | |
+++ b/lib/sanitizer_common/sanitizer_linux_libcdep.cc | |
@@ -26,7 +26,7 @@ | |
#include "sanitizer_procmaps.h" | |
#include "sanitizer_stacktrace.h" | |
-#if SANITIZER_ANDROID || SANITIZER_FREEBSD | |
+#if SANITIZER_ANDROID || SANITIZER_FREEBSD || SANITIZER_NONGNU | |
#include <dlfcn.h> // for dlsym() | |
#endif | |
@@ -156,7 +156,7 @@ bool SanitizerGetThreadName(char *name, int max_len) { | |
#endif | |
} | |
-#if !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_GO | |
+#if !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_GO && !SANITIZER_NONGNU | |
static uptr g_tls_size; | |
#endif | |
@@ -185,7 +185,7 @@ static uptr TlsPreTcbSize() { | |
#endif | |
void InitTlsSize() { | |
-#if !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_GO | |
+#if !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_GO && !SANITIZER_NONGNU | |
// all current supported platforms have 16 bytes stack alignment | |
const size_t kStackAlign = 16; | |
typedef void (*get_tls_func)(size_t*, size_t*) DL_INTERNAL_FUNCTION; | |
@@ -201,12 +201,12 @@ void InitTlsSize() { | |
if (tls_align < kStackAlign) | |
tls_align = kStackAlign; | |
g_tls_size = RoundUpTo(tls_size, tls_align); | |
-#endif // !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_GO | |
+#endif // !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_GO && !SANITIZER_NONGNU | |
} | |
#if (defined(__x86_64__) || defined(__i386__) || defined(__mips__) \ | |
|| defined(__aarch64__) || defined(__powerpc64__)) \ | |
- && SANITIZER_LINUX && !SANITIZER_ANDROID | |
+ && SANITIZER_LINUX && !SANITIZER_ANDROID && !SANITIZER_NONGNU | |
// sizeof(struct pthread) from glibc. | |
static atomic_uintptr_t kThreadDescriptorSize; | |
@@ -336,7 +336,7 @@ uptr ThreadSelf() { | |
#if !SANITIZER_GO | |
static void GetTls(uptr *addr, uptr *size) { | |
-#if SANITIZER_LINUX && !SANITIZER_ANDROID | |
+#if SANITIZER_LINUX && !SANITIZER_ANDROID && !SANITIZER_NONGNU | |
# if defined(__x86_64__) || defined(__i386__) | |
*addr = ThreadSelf(); | |
*size = GetTlsSize(); | |
@@ -362,7 +362,7 @@ static void GetTls(uptr *addr, uptr *size) { | |
*addr = (uptr) dtv[2]; | |
*size = (*addr == 0) ? 0 : ((uptr) segbase[0] - (uptr) dtv[2]); | |
} | |
-#elif SANITIZER_ANDROID | |
+#elif SANITIZER_ANDROID || SANITIZER_NONGNU | |
*addr = 0; | |
*size = 0; | |
#else | |
@@ -373,7 +373,7 @@ static void GetTls(uptr *addr, uptr *size) { | |
#if !SANITIZER_GO | |
uptr GetTlsSize() { | |
-#if SANITIZER_FREEBSD || SANITIZER_ANDROID | |
+#if SANITIZER_FREEBSD || SANITIZER_ANDROID || SANITIZER_NONGNU | |
uptr addr, size; | |
GetTls(&addr, &size); | |
return size; | |
diff --git a/lib/sanitizer_common/sanitizer_platform.h b/lib/sanitizer_common/sanitizer_platform.h | |
index 841cceb..542aa9a 100644 | |
--- a/lib/sanitizer_common/sanitizer_platform.h | |
+++ b/lib/sanitizer_common/sanitizer_platform.h | |
@@ -81,6 +81,13 @@ | |
# define SANITIZER_X32 0 | |
#endif | |
+ | |
+#if defined(__linux__) && !defined(__GLIBC__) | |
+# define SANITIZER_NONGNU 1 | |
+#else | |
+# define SANITIZER_NONGNU 0 | |
+#endif | |
+ | |
// By default we allow to use SizeClassAllocator64 on 64-bit platform. | |
// But in some cases (e.g. AArch64's 39-bit address space) SizeClassAllocator64 | |
// does not work well and we need to fallback to SizeClassAllocator32. | |
diff --git a/lib/sanitizer_common/sanitizer_platform_interceptors.h b/lib/sanitizer_common/sanitizer_platform_interceptors.h | |
index 430ad48..728693b 100644 | |
--- a/lib/sanitizer_common/sanitizer_platform_interceptors.h | |
+++ b/lib/sanitizer_common/sanitizer_platform_interceptors.h | |
@@ -23,7 +23,7 @@ | |
# define SI_NOT_WINDOWS 0 | |
#endif | |
-#if SANITIZER_LINUX && !SANITIZER_ANDROID | |
+#if SANITIZER_LINUX && !SANITIZER_ANDROID && !SANITIZER_NONGNU | |
# define SI_LINUX_NOT_ANDROID 1 | |
#else | |
# define SI_LINUX_NOT_ANDROID 0 | |
diff --git a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc | |
index b642cba..e5eb853 100644 | |
--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc | |
+++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc | |
@@ -140,12 +140,14 @@ typedef struct user_fpregs elf_fpregset_t; | |
#if SANITIZER_LINUX && !SANITIZER_ANDROID | |
#include <glob.h> | |
-#include <obstack.h> | |
+# if !SANITIZER_NONGNU | |
+# include <obstack.h> | |
+# endif | |
#include <mqueue.h> | |
-#include <net/if_ppp.h> | |
-#include <netax25/ax25.h> | |
-#include <netipx/ipx.h> | |
-#include <netrom/netrom.h> | |
+#include <linux/if_ppp.h> | |
+#include <linux/ax25.h> | |
+#include <linux/ipx.h> | |
+#include <linux/netrom.h> | |
#if HAVE_RPC_XDR_H | |
# include <rpc/xdr.h> | |
#elif HAVE_TIRPC_RPC_XDR_H | |
@@ -161,7 +163,8 @@ typedef struct user_fpregs elf_fpregset_t; | |
# include <sys/procfs.h> | |
#endif | |
#include <sys/user.h> | |
-#include <sys/ustat.h> | |
+// #include <sys/ustat.h> | |
+#include <sys/statfs.h> | |
#include <linux/cyclades.h> | |
#include <linux/if_eql.h> | |
#include <linux/if_plip.h> | |
@@ -253,7 +256,7 @@ namespace __sanitizer { | |
unsigned struct_itimerspec_sz = sizeof(struct itimerspec); | |
#endif // SANITIZER_LINUX || SANITIZER_FREEBSD | |
-#if SANITIZER_LINUX && !SANITIZER_ANDROID | |
+#if SANITIZER_LINUX && !SANITIZER_ANDROID && !SANITIZER_NONGNU | |
unsigned struct_ustat_sz = sizeof(struct ustat); | |
unsigned struct_rlimit64_sz = sizeof(struct rlimit64); | |
unsigned struct_statvfs64_sz = sizeof(struct statvfs64); | |
@@ -304,7 +307,7 @@ unsigned struct_ElfW_Phdr_sz = sizeof(ElfW(Phdr)); | |
unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); | |
#endif | |
-#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID | |
+#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID && !SANITIZER_NONGNU | |
int glob_nomatch = GLOB_NOMATCH; | |
int glob_altdirfunc = GLOB_ALTDIRFUNC; | |
#endif | |
@@ -393,7 +396,7 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); | |
unsigned struct_termios_sz = sizeof(struct termios); | |
unsigned struct_winsize_sz = sizeof(struct winsize); | |
-#if SANITIZER_LINUX | |
+#if SANITIZER_LINUX && !SANITIZER_NONGNU | |
unsigned struct_arpreq_sz = sizeof(struct arpreq); | |
unsigned struct_cdrom_msf_sz = sizeof(struct cdrom_msf); | |
unsigned struct_cdrom_multisession_sz = sizeof(struct cdrom_multisession); | |
@@ -443,7 +446,7 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); | |
unsigned struct_vt_mode_sz = sizeof(struct vt_mode); | |
#endif // SANITIZER_LINUX || SANITIZER_FREEBSD | |
-#if SANITIZER_LINUX && !SANITIZER_ANDROID | |
+#if SANITIZER_LINUX && !SANITIZER_ANDROID && !SANITIZER_NONGNU | |
unsigned struct_ax25_parms_struct_sz = sizeof(struct ax25_parms_struct); | |
unsigned struct_cyclades_monitor_sz = sizeof(struct cyclades_monitor); | |
#if EV_VERSION > (0x010000) | |
@@ -811,7 +814,7 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); | |
unsigned IOCTL_VT_WAITACTIVE = VT_WAITACTIVE; | |
#endif // SANITIZER_LINUX || SANITIZER_FREEBSD | |
-#if SANITIZER_LINUX && !SANITIZER_ANDROID | |
+#if SANITIZER_LINUX && !SANITIZER_ANDROID && !SANITIZER_NONGNU | |
unsigned IOCTL_CYGETDEFTHRESH = CYGETDEFTHRESH; | |
unsigned IOCTL_CYGETDEFTIMEOUT = CYGETDEFTIMEOUT; | |
unsigned IOCTL_CYGETMON = CYGETMON; | |
@@ -972,7 +975,7 @@ CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phdr); | |
CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phnum); | |
#endif // SANITIZER_LINUX || SANITIZER_FREEBSD | |
-#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID | |
+#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID && !SANITIZER_NONGNU | |
CHECK_TYPE_SIZE(glob_t); | |
CHECK_SIZE_AND_OFFSET(glob_t, gl_pathc); | |
CHECK_SIZE_AND_OFFSET(glob_t, gl_pathv); | |
@@ -1006,6 +1009,7 @@ CHECK_TYPE_SIZE(iovec); | |
CHECK_SIZE_AND_OFFSET(iovec, iov_base); | |
CHECK_SIZE_AND_OFFSET(iovec, iov_len); | |
+#if !SANITIZER_NONGNU | |
CHECK_TYPE_SIZE(msghdr); | |
CHECK_SIZE_AND_OFFSET(msghdr, msg_name); | |
CHECK_SIZE_AND_OFFSET(msghdr, msg_namelen); | |
@@ -1019,6 +1023,7 @@ CHECK_TYPE_SIZE(cmsghdr); | |
CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_len); | |
CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_level); | |
CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_type); | |
+#endif | |
COMPILER_CHECK(sizeof(__sanitizer_dirent) <= sizeof(dirent)); | |
CHECK_SIZE_AND_OFFSET(dirent, d_ino); | |
@@ -1114,7 +1119,7 @@ CHECK_SIZE_AND_OFFSET(mntent, mnt_passno); | |
CHECK_TYPE_SIZE(ether_addr); | |
-#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID | |
+#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID && !SANITIZER_NONGNU | |
CHECK_TYPE_SIZE(ipc_perm); | |
# if SANITIZER_FREEBSD | |
CHECK_SIZE_AND_OFFSET(ipc_perm, key); | |
@@ -1178,7 +1183,7 @@ CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_dstaddr); | |
CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_data); | |
#endif | |
-#if SANITIZER_LINUX | |
+#if SANITIZER_LINUX && !SANITIZER_NONGNU | |
COMPILER_CHECK(sizeof(__sanitizer_mallinfo) == sizeof(struct mallinfo)); | |
#endif | |
@@ -1228,7 +1233,7 @@ COMPILER_CHECK(__sanitizer_XDR_DECODE == XDR_DECODE); | |
COMPILER_CHECK(__sanitizer_XDR_FREE == XDR_FREE); | |
#endif | |
-#if SANITIZER_LINUX && !SANITIZER_ANDROID | |
+#if SANITIZER_LINUX && !SANITIZER_ANDROID && !SANITIZER_NONGNU | |
COMPILER_CHECK(sizeof(__sanitizer_FILE) <= sizeof(FILE)); | |
CHECK_SIZE_AND_OFFSET(FILE, _flags); | |
CHECK_SIZE_AND_OFFSET(FILE, _IO_read_ptr); | |
@@ -1247,7 +1252,7 @@ CHECK_SIZE_AND_OFFSET(FILE, _chain); | |
CHECK_SIZE_AND_OFFSET(FILE, _fileno); | |
#endif | |
-#if SANITIZER_LINUX && !SANITIZER_ANDROID | |
+#if SANITIZER_LINUX && !SANITIZER_ANDROID && !SANITIZER_NONGNU | |
COMPILER_CHECK(sizeof(__sanitizer__obstack_chunk) <= sizeof(_obstack_chunk)); | |
CHECK_SIZE_AND_OFFSET(_obstack_chunk, limit); | |
CHECK_SIZE_AND_OFFSET(_obstack_chunk, prev); | |
diff --git a/lib/tsan/rtl/tsan_platform_linux.cc b/lib/tsan/rtl/tsan_platform_linux.cc | |
index 6602561..2c4d59b 100644 | |
--- a/lib/tsan/rtl/tsan_platform_linux.cc | |
+++ b/lib/tsan/rtl/tsan_platform_linux.cc | |
@@ -309,7 +309,7 @@ bool IsGlobalVar(uptr addr) { | |
// This is required to properly "close" the fds, because we do not see internal | |
// closes within glibc. The code is a pure hack. | |
int ExtractResolvFDs(void *state, int *fds, int nfd) { | |
-#if SANITIZER_LINUX && !SANITIZER_ANDROID | |
+#if SANITIZER_LINUX && !SANITIZER_ANDROID && !SANITIZER_NONGNU | |
int cnt = 0; | |
__res_state *statp = (__res_state*)state; | |
for (int i = 0; i < MAXNS && cnt < nfd; i++) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment