Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -45,6 +45,11 @@ mark_as_advanced(COMPILER_RT_BUILD_PROFILE) option(COMPILER_RT_BUILD_XRAY_NO_PREINIT "Build xray with no preinit patching" OFF) mark_as_advanced(COMPILER_RT_BUILD_XRAY_NO_PREINIT) +option(COMPILER_RT_BUILD_WITH_MUSL "Build with musl libc" OFF) +mark_as_advanced(COMPILER_RT_BUILD_WITH_MUSL) +if (COMPILER_RT_BUILD_WITH_MUSL) + add_compile_definitions(__MUSL__) +endif() set(COMPILER_RT_ASAN_SHADOW_SCALE "" CACHE STRING "Override the shadow scale to be used in ASan runtime") Index: lib/asan/asan_linux.cc =================================================================== --- lib/asan/asan_linux.cc +++ lib/asan/asan_linux.cc @@ -55,6 +55,9 @@ #else #include #include +# if defined(__MUSL__) && __MUSL__ +extern "C" void* _DYNAMIC; +# endif #endif // x86-64 FreeBSD 9.2 and older define 'ucontext_t' incorrectly in Index: lib/interception/interception_linux.cc =================================================================== --- lib/interception/interception_linux.cc +++ lib/interception/interception_linux.cc @@ -59,7 +59,7 @@ } // Android and Solaris do not have dlvsym -#if !SANITIZER_ANDROID && !SANITIZER_SOLARIS && !SANITIZER_OPENBSD +#if (!SANITIZER_ANDROID && !SANITIZER_SOLARIS && !SANITIZER_OPENBSD) && (!SANITIZER_LINUX || (SANITIZER_LINUX && (!defined(__MUSL__) || !__MUSL__))) static void *GetFuncAddr(const char *name, const char *ver) { return dlvsym(RTLD_NEXT, name, ver); } Index: lib/msan/msan_linux.cc =================================================================== --- lib/msan/msan_linux.cc +++ lib/msan/msan_linux.cc @@ -26,7 +26,9 @@ #include #include #include +#if !defined(__MUSL__) || !__MUSL__ #include +#endif #include #include Index: lib/sanitizer_common/sanitizer_common_interceptors.inc =================================================================== --- lib/sanitizer_common/sanitizer_common_interceptors.inc +++ lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -2302,6 +2302,7 @@ COMMON_INTERCEPTOR_READ_STRING(ctx, pattern, 0); __sanitizer_glob_t glob_copy; internal_memcpy(&glob_copy, &kGlobCopy, sizeof(glob_copy)); +#if !defined(__MUSL__) || !__MUSL__ if (flags & glob_altdirfunc) { Swap(pglob->gl_closedir, glob_copy.gl_closedir); Swap(pglob->gl_readdir, glob_copy.gl_readdir); @@ -2310,7 +2311,9 @@ Swap(pglob->gl_stat, glob_copy.gl_stat); pglob_copy = &glob_copy; } +#endif int res = REAL(glob)(pattern, flags, errfunc, pglob); +#if !defined(__MUSL__) || !__MUSL__ if (flags & glob_altdirfunc) { Swap(pglob->gl_closedir, glob_copy.gl_closedir); Swap(pglob->gl_readdir, glob_copy.gl_readdir); @@ -2318,6 +2321,7 @@ Swap(pglob->gl_lstat, glob_copy.gl_lstat); Swap(pglob->gl_stat, glob_copy.gl_stat); } +#endif pglob_copy = 0; if ((!res || res == glob_nomatch) && pglob) unpoison_glob_t(ctx, pglob); return res; @@ -2338,6 +2342,7 @@ COMMON_INTERCEPTOR_READ_STRING(ctx, pattern, 0); __sanitizer_glob_t glob_copy; internal_memcpy(&glob_copy, &kGlobCopy, sizeof(glob_copy)); +#if !defined(__MUSL__) || !__MUSL__ if (flags & glob_altdirfunc) { Swap(pglob->gl_closedir, glob_copy.gl_closedir); Swap(pglob->gl_readdir, glob_copy.gl_readdir); @@ -2346,7 +2351,9 @@ Swap(pglob->gl_stat, glob_copy.gl_stat); pglob_copy = &glob_copy; } +#endif int res = REAL(glob64)(pattern, flags, errfunc, pglob); +#if !defined(__MUSL__) || !__MUSL__ if (flags & glob_altdirfunc) { Swap(pglob->gl_closedir, glob_copy.gl_closedir); Swap(pglob->gl_readdir, glob_copy.gl_readdir); @@ -2354,6 +2361,7 @@ Swap(pglob->gl_lstat, glob_copy.gl_lstat); Swap(pglob->gl_stat, glob_copy.gl_stat); } +#endif pglob_copy = 0; if ((!res || res == glob_nomatch) && pglob) unpoison_glob_t(ctx, pglob); return res; Index: lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc =================================================================== --- lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc +++ lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc @@ -330,13 +330,17 @@ _(SOUND_PCM_WRITE_CHANNELS, WRITE, sizeof(int)); _(SOUND_PCM_WRITE_FILTER, WRITE, sizeof(int)); _(TCFLSH, NONE, 0); +#if !defined(__MUSL__) || !__MUSL__ _(TCGETA, WRITE, struct_termio_sz); +#endif _(TCGETS, WRITE, struct_termios_sz); _(TCSBRK, NONE, 0); _(TCSBRKP, NONE, 0); +#if !defined(__MUSL__) || !__MUSL__ _(TCSETA, READ, struct_termio_sz); _(TCSETAF, READ, struct_termio_sz); _(TCSETAW, READ, struct_termio_sz); +#endif _(TCSETS, READ, struct_termios_sz); _(TCSETSF, READ, struct_termios_sz); _(TCSETSW, READ, struct_termios_sz); Index: lib/sanitizer_common/sanitizer_linux.cc =================================================================== --- lib/sanitizer_common/sanitizer_linux.cc +++ lib/sanitizer_common/sanitizer_linux.cc @@ -27,8 +27,10 @@ #include "sanitizer_procmaps.h" #if SANITIZER_LINUX +#if !defined(__MUSL__) || !__MUSL__ #include #endif +#endif // For mips64, syscall(__NR_stat) fills the buffer in the 'struct kernel_stat' // format. Struct kernel_stat is defined as 'struct stat' in asm/stat.h. To @@ -1057,7 +1059,11 @@ #if !SANITIZER_ANDROID uptr GetPageSize() { #if SANITIZER_LINUX && (defined(__x86_64__) || defined(__i386__)) +#if defined(PAGESIZE) + return PAGESIZE; +#else return EXEC_PAGESIZE; +#endif #elif SANITIZER_USE_GETAUXVAL return getauxval(AT_PAGESZ); #elif SANITIZER_FREEBSD || SANITIZER_NETBSD Index: lib/sanitizer_common/sanitizer_linux_libcdep.cc =================================================================== --- lib/sanitizer_common/sanitizer_linux_libcdep.cc +++ lib/sanitizer_common/sanitizer_linux_libcdep.cc @@ -184,7 +184,8 @@ } #if !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_GO && \ - !SANITIZER_NETBSD && !SANITIZER_OPENBSD && !SANITIZER_SOLARIS + !SANITIZER_NETBSD && !SANITIZER_OPENBSD && !SANITIZER_SOLARIS && \ + (!defined(__MUSL__) || !__MUSL__) static uptr g_tls_size; #ifdef __i386__ @@ -431,13 +432,13 @@ #if !SANITIZER_GO static void GetTls(uptr *addr, uptr *size) { -#if SANITIZER_LINUX && !SANITIZER_ANDROID +#if SANITIZER_LINUX && !SANITIZER_ANDROID && (!defined(__MUSL__) || !__MUSL__) # if defined(__x86_64__) || defined(__i386__) || defined(__s390__) *addr = ThreadSelf(); *size = GetTlsSize(); *addr -= *size; *addr += ThreadDescriptorSize(); -# elif defined(__mips__) || defined(__aarch64__) || defined(__powerpc64__) \ +# elif (defined(__mips__) || defined(__aarch64__) || defined(__powerpc64__) \ || defined(__arm__) *addr = ThreadSelf(); *size = GetTlsSize(); @@ -445,6 +446,9 @@ *addr = 0; *size = 0; # endif +#elif SANITIZER_LINUX && !SANITIZER_ANDROID && defined(__MUSL__) && __MUSL__ + *addr = 0; + *size = 0; #elif SANITIZER_FREEBSD void** segbase = ThreadSelfSegbase(); *addr = 0; @@ -491,7 +495,7 @@ #if !SANITIZER_GO uptr GetTlsSize() { #if SANITIZER_FREEBSD || SANITIZER_ANDROID || SANITIZER_NETBSD || \ - SANITIZER_OPENBSD || SANITIZER_SOLARIS + SANITIZER_OPENBSD || SANITIZER_SOLARIS || (defined(__MUSL__) && __MUSL__) uptr addr, size; GetTls(&addr, &size); return size; Index: lib/sanitizer_common/sanitizer_platform_limits_posix.h =================================================================== --- lib/sanitizer_common/sanitizer_platform_limits_posix.h +++ lib/sanitizer_common/sanitizer_platform_limits_posix.h @@ -192,7 +192,11 @@ extern unsigned struct_statvfs64_sz; struct __sanitizer_ipc_perm { +#if defined(__MUSL__) && __MUSL__ + int __ipc_perm_key; +#else int __key; +#endif int uid; int gid; int cuid; @@ -221,16 +225,25 @@ unsigned long __unused1; unsigned long __unused2; #else +# if defined(__MUSL__) && __MUSL__ + unsigned mode; + int __ipc_perm_seq; + long __pad1; + long __pad2; +# else unsigned short mode; unsigned short __pad1; unsigned short __seq; unsigned short __pad2; +# endif #if defined(__x86_64__) && !defined(_LP64) u64 __unused1; u64 __unused2; #else +# if !defined(__MUSL__) || !__MUSL__ unsigned long __unused1; unsigned long __unused2; +# endif #endif #endif }; @@ -454,13 +467,39 @@ void *msg_name; unsigned msg_namelen; struct __sanitizer_iovec *msg_iov; +#if defined(__GLIBC__) uptr msg_iovlen; +#else +#if defined(__DEFINED_socklen_t) + socklen_t msg_iovlen, __pad1; +#else + unsigned msg_iovlen, __pad1; +#endif +#endif void *msg_control; +#if defined(__GLIBC__) uptr msg_controllen; +#else +#if defined(__DEFINED_socklen_t) + socklen_t msg_controllen, __pad2; +#else + unsigned msg_controllen, __pad2; +#endif +#endif int msg_flags; }; struct __sanitizer_cmsghdr { +#if defined(__GLIBC__) uptr cmsg_len; +#else +#if defined(__DEFINED_socklen_t) + socklen_t cmsg_len; + int __pad1; +#else + unsigned cmsg_len; + int __pad1; +#endif +#endif int cmsg_level; int cmsg_type; }; @@ -960,7 +999,9 @@ extern unsigned struct_input_absinfo_sz; extern unsigned struct_input_id_sz; extern unsigned struct_mtpos_sz; +#if !defined(__MUSL__) || !__MUSL__ extern unsigned struct_termio_sz; +#endif extern unsigned struct_vt_consize_sz; extern unsigned struct_vt_sizes_sz; extern unsigned struct_vt_stat_sz; Index: lib/sanitizer_common/sanitizer_platform_limits_posix.cc =================================================================== --- lib/sanitizer_common/sanitizer_platform_limits_posix.cc +++ lib/sanitizer_common/sanitizer_platform_limits_posix.cc @@ -54,7 +54,9 @@ #endif #if !SANITIZER_ANDROID +#if !defined(__MUSL__) || !__MUSL__ #include +#endif #include #include #include @@ -107,12 +109,16 @@ #if SANITIZER_LINUX && !SANITIZER_ANDROID #include +#if !defined(__MUSL__) || !__MUSL__ #include +#endif #include +#if !defined(__MUSL__) || !__MUSL__ #include #include #include #include +#endif #if HAVE_RPC_XDR_H # include #endif @@ -196,7 +202,9 @@ #endif // SANITIZER_MAC && !SANITIZER_IOS #if !SANITIZER_ANDROID +#if !defined(__MUSL__) || !__MUSL__ unsigned struct_fstab_sz = sizeof(struct fstab); +#endif unsigned struct_statfs_sz = sizeof(struct statfs); unsigned struct_sockaddr_sz = sizeof(struct sockaddr); unsigned ucontext_t_sz = sizeof(ucontext_t); @@ -293,8 +301,10 @@ #if SANITIZER_LINUX && !SANITIZER_ANDROID int glob_nomatch = GLOB_NOMATCH; +#if !defined(__MUSL__) || !__MUSL__ int glob_altdirfunc = GLOB_ALTDIRFUNC; #endif +#endif #if SANITIZER_LINUX && !SANITIZER_ANDROID && \ (defined(__i386) || defined(__x86_64) || defined(__mips64) || \ @@ -410,7 +420,9 @@ unsigned struct_input_id_sz = sizeof(struct input_id); unsigned struct_mtpos_sz = sizeof(struct mtpos); unsigned struct_rtentry_sz = sizeof(struct rtentry); +#if !defined(__MUSL__) || !__MUSL__ unsigned struct_termio_sz = sizeof(struct termio); +#endif unsigned struct_vt_consize_sz = sizeof(struct vt_consize); unsigned struct_vt_sizes_sz = sizeof(struct vt_sizes); unsigned struct_vt_stat_sz = sizeof(struct vt_stat); @@ -436,41 +448,54 @@ #endif // SANITIZER_LINUX #if SANITIZER_LINUX && !SANITIZER_ANDROID +#if !defined(__MUSL__) || !__MUSL__ unsigned struct_ax25_parms_struct_sz = sizeof(struct ax25_parms_struct); +#endif unsigned struct_cyclades_monitor_sz = sizeof(struct cyclades_monitor); #if EV_VERSION > (0x010000) unsigned struct_input_keymap_entry_sz = sizeof(struct input_keymap_entry); #else unsigned struct_input_keymap_entry_sz = 0; #endif +#if !defined(__MUSL__) || !__MUSL__ unsigned struct_ipx_config_data_sz = sizeof(struct ipx_config_data); +#endif unsigned struct_kbdiacrs_sz = sizeof(struct kbdiacrs); unsigned struct_kbentry_sz = sizeof(struct kbentry); unsigned struct_kbkeycode_sz = sizeof(struct kbkeycode); unsigned struct_kbsentry_sz = sizeof(struct kbsentry); unsigned struct_mtconfiginfo_sz = sizeof(struct mtconfiginfo); +#if !defined(__MUSL__) || !__MUSL__ unsigned struct_nr_parms_struct_sz = sizeof(struct nr_parms_struct); +#endif unsigned struct_scc_modem_sz = sizeof(struct scc_modem); unsigned struct_scc_stat_sz = sizeof(struct scc_stat); unsigned struct_serial_multiport_struct_sz = sizeof(struct serial_multiport_struct); unsigned struct_serial_struct_sz = sizeof(struct serial_struct); +#if !defined(__MUSL__) || !__MUSL__ unsigned struct_sockaddr_ax25_sz = sizeof(struct sockaddr_ax25); +#endif unsigned struct_unimapdesc_sz = sizeof(struct unimapdesc); unsigned struct_unimapinit_sz = sizeof(struct unimapinit); #endif // SANITIZER_LINUX && !SANITIZER_ANDROID #if SANITIZER_LINUX && !SANITIZER_ANDROID unsigned struct_audio_buf_info_sz = sizeof(struct audio_buf_info); +#if !defined(__MUSL__) || !__MUSL__ unsigned struct_ppp_stats_sz = sizeof(struct ppp_stats); +#endif #endif // (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID #if !SANITIZER_ANDROID && !SANITIZER_MAC unsigned struct_sioc_sg_req_sz = sizeof(struct sioc_sg_req); unsigned struct_sioc_vif_req_sz = sizeof(struct sioc_vif_req); #endif - +#if defined(BUFSIZ) const unsigned long __sanitizer_bufsiz = BUFSIZ; +#else + const unsigned long __sanitizer_bufsiz = 8192; +#endif const unsigned IOCTL_NOT_PRESENT = 0; @@ -614,6 +639,19 @@ unsigned IOCTL_HDIO_SET_NOWERR = HDIO_SET_NOWERR; unsigned IOCTL_HDIO_SET_UNMASKINTR = HDIO_SET_UNMASKINTR; unsigned IOCTL_MTIOCPOS = MTIOCPOS; +#if defined(__MUSL__) && __MUSL__ + unsigned IOCTL_PPPIOCGASYNCMAP = IOCTL_NOT_PRESENT; + unsigned IOCTL_PPPIOCGDEBUG = IOCTL_NOT_PRESENT; + unsigned IOCTL_PPPIOCGFLAGS = IOCTL_NOT_PRESENT; + unsigned IOCTL_PPPIOCGUNIT = IOCTL_NOT_PRESENT; + unsigned IOCTL_PPPIOCGXASYNCMAP = IOCTL_NOT_PRESENT; + unsigned IOCTL_PPPIOCSASYNCMAP = IOCTL_NOT_PRESENT; + unsigned IOCTL_PPPIOCSDEBUG = IOCTL_NOT_PRESENT; + unsigned IOCTL_PPPIOCSFLAGS = IOCTL_NOT_PRESENT; + unsigned IOCTL_PPPIOCSMAXCID = IOCTL_NOT_PRESENT; + unsigned IOCTL_PPPIOCSMRU = IOCTL_NOT_PRESENT; + unsigned IOCTL_PPPIOCSXASYNCMAP = IOCTL_NOT_PRESENT; +#else unsigned IOCTL_PPPIOCGASYNCMAP = PPPIOCGASYNCMAP; unsigned IOCTL_PPPIOCGDEBUG = PPPIOCGDEBUG; unsigned IOCTL_PPPIOCGFLAGS = PPPIOCGFLAGS; @@ -625,6 +663,7 @@ unsigned IOCTL_PPPIOCSMAXCID = PPPIOCSMAXCID; unsigned IOCTL_PPPIOCSMRU = PPPIOCSMRU; unsigned IOCTL_PPPIOCSXASYNCMAP = PPPIOCSXASYNCMAP; +#endif unsigned IOCTL_SIOCADDRT = SIOCADDRT; unsigned IOCTL_SIOCDARP = SIOCDARP; unsigned IOCTL_SIOCDELRT = SIOCDELRT; @@ -873,6 +912,7 @@ unsigned IOCTL_SCSI_IOCTL_PROBE_HOST = SCSI_IOCTL_PROBE_HOST; unsigned IOCTL_SCSI_IOCTL_TAGGED_DISABLE = SCSI_IOCTL_TAGGED_DISABLE; unsigned IOCTL_SCSI_IOCTL_TAGGED_ENABLE = SCSI_IOCTL_TAGGED_ENABLE; +#if !defined(__MUSL__) || !__MUSL__ unsigned IOCTL_SIOCAIPXITFCRT = SIOCAIPXITFCRT; unsigned IOCTL_SIOCAIPXPRISLT = SIOCAIPXPRISLT; unsigned IOCTL_SIOCAX25ADDUID = SIOCAX25ADDUID; @@ -881,12 +921,15 @@ unsigned IOCTL_SIOCAX25GETUID = SIOCAX25GETUID; unsigned IOCTL_SIOCAX25NOUID = SIOCAX25NOUID; unsigned IOCTL_SIOCAX25SETPARMS = SIOCAX25SETPARMS; +#endif unsigned IOCTL_SIOCDEVPLIP = SIOCDEVPLIP; +#if !defined(__MUSL__) || !__MUSL__ unsigned IOCTL_SIOCIPXCFGDATA = SIOCIPXCFGDATA; unsigned IOCTL_SIOCNRDECOBS = SIOCNRDECOBS; unsigned IOCTL_SIOCNRGETPARMS = SIOCNRGETPARMS; unsigned IOCTL_SIOCNRRTCTL = SIOCNRRTCTL; unsigned IOCTL_SIOCNRSETPARMS = SIOCNRSETPARMS; +#endif unsigned IOCTL_TIOCGSERIAL = TIOCGSERIAL; unsigned IOCTL_TIOCSERGETMULTI = TIOCSERGETMULTI; unsigned IOCTL_TIOCSERSETMULTI = TIOCSERSETMULTI; @@ -957,7 +1000,7 @@ CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phnum); #endif // SANITIZER_LINUX || SANITIZER_FREEBSD -#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID +#if ((SANITIZER_LINUX && (!defined(__MUSL__) || !__MUSL__)) || SANITIZER_FREEBSD) && !SANITIZER_ANDROID CHECK_TYPE_SIZE(glob_t); CHECK_SIZE_AND_OFFSET(glob_t, gl_pathc); CHECK_SIZE_AND_OFFSET(glob_t, gl_pathv); @@ -1119,8 +1162,12 @@ CHECK_SIZE_AND_OFFSET(ipc_perm, key); CHECK_SIZE_AND_OFFSET(ipc_perm, seq); # else +# if defined(__MUSL__) && __MUSL__ +CHECK_SIZE_AND_OFFSET(ipc_perm, __ipc_perm_key); +# else CHECK_SIZE_AND_OFFSET(ipc_perm, __key); CHECK_SIZE_AND_OFFSET(ipc_perm, __seq); +# endif # endif CHECK_SIZE_AND_OFFSET(ipc_perm, uid); CHECK_SIZE_AND_OFFSET(ipc_perm, gid); @@ -1174,7 +1221,7 @@ CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_data); #endif -#if SANITIZER_LINUX +#if SANITIZER_LINUX && (!defined(__MUSL__) || !__MUSL__) COMPILER_CHECK(sizeof(__sanitizer_struct_mallinfo) == sizeof(struct mallinfo)); #endif @@ -1224,7 +1271,7 @@ COMPILER_CHECK(__sanitizer_XDR_FREE == XDR_FREE); #endif -#if SANITIZER_LINUX && !SANITIZER_ANDROID +#if SANITIZER_LINUX && !SANITIZER_ANDROID && (!defined(__MUSL__) || !__MUSL__) COMPILER_CHECK(sizeof(__sanitizer_FILE) <= sizeof(FILE)); CHECK_SIZE_AND_OFFSET(FILE, _flags); CHECK_SIZE_AND_OFFSET(FILE, _IO_read_ptr); @@ -1243,7 +1290,7 @@ CHECK_SIZE_AND_OFFSET(FILE, _fileno); #endif -#if SANITIZER_LINUX && !SANITIZER_ANDROID +#if SANITIZER_LINUX && !SANITIZER_ANDROID && (!defined(__MUSL__) || !__MUSL__) COMPILER_CHECK(sizeof(__sanitizer__obstack_chunk) <= sizeof(_obstack_chunk)); CHECK_SIZE_AND_OFFSET(_obstack_chunk, limit); CHECK_SIZE_AND_OFFSET(_obstack_chunk, prev);