Index: compiler-rt/lib/asan/asan_linux.cpp =================================================================== --- compiler-rt/lib/asan/asan_linux.cpp +++ compiler-rt/lib/asan/asan_linux.cpp @@ -45,7 +45,11 @@ #include #endif -#if SANITIZER_ANDROID || SANITIZER_FREEBSD || SANITIZER_SOLARIS +#if SANITIZER_LINUX && !SANITIZER_GNU +#include +#endif + +#if !SANITIZER_GNU && !SANITIZER_NETBSD #include extern "C" void* _DYNAMIC; #elif SANITIZER_NETBSD Index: compiler-rt/lib/interception/interception_linux.cpp =================================================================== --- compiler-rt/lib/interception/interception_linux.cpp +++ compiler-rt/lib/interception/interception_linux.cpp @@ -63,8 +63,8 @@ return addr && (func == wrapper); } -// Android and Solaris do not have dlvsym -#if !SANITIZER_ANDROID && !SANITIZER_SOLARIS +// dlvsym is GNU extension, FreeBSD has support for it +#if SANITIZER_GNU || SANITIZER_FREEBSD static void *GetFuncAddr(const char *name, const char *ver) { return dlvsym(RTLD_NEXT, name, ver); } @@ -75,7 +75,7 @@ *ptr_to_real = (uptr)addr; return addr && (func == wrapper); } -#endif // !SANITIZER_ANDROID +#endif // SANITIZER_GNU || SANITIZER_FREEBSD } // namespace __interception Index: compiler-rt/lib/sanitizer_common/sanitizer_platform.h =================================================================== --- compiler-rt/lib/sanitizer_common/sanitizer_platform.h +++ compiler-rt/lib/sanitizer_common/sanitizer_platform.h @@ -25,6 +25,12 @@ # define SANITIZER_LINUX 0 #endif +#if defined(__GLIBC__) +#define SANITIZER_GNU 1 +#else +#define SANITIZER_GNU 0 +#endif + #if defined(__FreeBSD__) # define SANITIZER_FREEBSD 1 #else Index: compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp =================================================================== --- compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp +++ compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp @@ -57,8 +57,10 @@ #include #endif -#if !SANITIZER_ANDROID +#if SANITIZER_GNU #include +#endif +#if !SANITIZER_ANDROID #include #include #include @@ -110,7 +112,7 @@ #include #endif -#if SANITIZER_LINUX && !SANITIZER_ANDROID +#if SANITIZER_GNU #include #include #include @@ -141,21 +143,36 @@ #include #include #include -#include -#endif // SANITIZER_LINUX && !SANITIZER_ANDROID +#endif // SANITIZER_GNU -#if SANITIZER_ANDROID +#if SANITIZER_LINUX && !SANITIZER_GNU #include #include #include #include +#if !SANITIZER_ANDROID +#include +#include +#include +// #include doesn't have the required mtconfiginfo +// #include doesn't have the required nr_parms_struct +#include +#include +#include +#include +#include +#include +#include +#include #endif +#endif // SANITIZER_LINUX && !SANITIZER_GNU #if SANITIZER_LINUX +#include #include -#include -#include #include +#include +#include #endif // SANITIZER_LINUX #if SANITIZER_MAC @@ -202,12 +219,12 @@ unsigned struct_statfs64_sz = sizeof(struct statfs64); #endif // (SANITIZER_MAC && !TARGET_CPU_ARM64) && !SANITIZER_IOS -#if !SANITIZER_ANDROID +#if SANITIZER_GNU unsigned struct_fstab_sz = sizeof(struct fstab); unsigned struct_statfs_sz = sizeof(struct statfs); unsigned struct_sockaddr_sz = sizeof(struct sockaddr); unsigned ucontext_t_sz = sizeof(ucontext_t); -#endif // !SANITIZER_ANDROID +#endif // SANITIZER_GNU #if SANITIZER_LINUX unsigned struct_epoll_event_sz = sizeof(struct epoll_event); @@ -246,12 +263,12 @@ unsigned struct_crypt_data_sz = sizeof(struct crypt_data); #endif // SANITIZER_LINUX && !SANITIZER_ANDROID -#if SANITIZER_LINUX && !SANITIZER_ANDROID +#if SANITIZER_GNU unsigned struct_timex_sz = sizeof(struct timex); unsigned struct_msqid_ds_sz = sizeof(struct msqid_ds); unsigned struct_mq_attr_sz = sizeof(struct mq_attr); unsigned struct_statvfs_sz = sizeof(struct statvfs); -#endif // SANITIZER_LINUX && !SANITIZER_ANDROID +#endif // SANITIZER_GNU const uptr sig_ign = (uptr)SIG_IGN; const uptr sig_dfl = (uptr)SIG_DFL; @@ -262,8 +279,7 @@ int e_tabsz = (int)E_TABSZ; #endif - -#if SANITIZER_LINUX && !SANITIZER_ANDROID +#if SANITIZER_GNU unsigned struct_shminfo_sz = sizeof(struct shminfo); unsigned struct_shm_info_sz = sizeof(struct shm_info); int shmctl_ipc_stat = (int)IPC_STAT; @@ -299,12 +315,12 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); #endif -#if SANITIZER_LINUX && !SANITIZER_ANDROID - int glob_nomatch = GLOB_NOMATCH; - int glob_altdirfunc = GLOB_ALTDIRFUNC; +#if SANITIZER_GNU +int glob_nomatch = GLOB_NOMATCH; +int glob_altdirfunc = GLOB_ALTDIRFUNC; #endif -#if SANITIZER_LINUX && !SANITIZER_ANDROID && \ +#if SANITIZER_GNU && \ (defined(__i386) || defined(__x86_64) || defined(__mips64) || \ defined(__powerpc64__) || defined(__aarch64__) || defined(__arm__) || \ defined(__s390__) || SANITIZER_RISCV64) @@ -422,7 +438,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 SANITIZER_GNU 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); @@ -448,7 +466,9 @@ #endif // SANITIZER_LINUX #if SANITIZER_LINUX && !SANITIZER_ANDROID +#if SANITIZER_GNU 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); @@ -460,13 +480,17 @@ unsigned struct_kbentry_sz = sizeof(struct kbentry); unsigned struct_kbkeycode_sz = sizeof(struct kbkeycode); unsigned struct_kbsentry_sz = sizeof(struct kbsentry); +#if SANITIZER_GNU unsigned struct_mtconfiginfo_sz = sizeof(struct mtconfiginfo); 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); +#if SANITIZER_GNU unsigned struct_serial_multiport_struct_sz = sizeof(struct serial_multiport_struct); unsigned struct_serial_struct_sz = sizeof(struct serial_struct); +#endif unsigned struct_sockaddr_ax25_sz = sizeof(struct sockaddr_ax25); unsigned struct_unimapdesc_sz = sizeof(struct unimapdesc); unsigned struct_unimapinit_sz = sizeof(struct unimapinit); @@ -482,7 +506,11 @@ 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 = 4096; +#endif const unsigned IOCTL_NOT_PRESENT = 0; @@ -874,31 +902,41 @@ unsigned IOCTL_LPSETIRQ = LPSETIRQ; unsigned IOCTL_LPTIME = LPTIME; unsigned IOCTL_LPWAIT = LPWAIT; +#if SANITIZER_GNU unsigned IOCTL_MTIOCGETCONFIG = MTIOCGETCONFIG; unsigned IOCTL_MTIOCSETCONFIG = MTIOCSETCONFIG; +#endif unsigned IOCTL_PIO_CMAP = PIO_CMAP; unsigned IOCTL_PIO_FONT = PIO_FONT; unsigned IOCTL_PIO_UNIMAP = PIO_UNIMAP; unsigned IOCTL_PIO_UNIMAPCLR = PIO_UNIMAPCLR; unsigned IOCTL_PIO_UNISCRNMAP = PIO_UNISCRNMAP; +#if SANITIZER_GNU unsigned IOCTL_SCSI_IOCTL_GET_IDLUN = SCSI_IOCTL_GET_IDLUN; 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; +#endif unsigned IOCTL_SIOCAIPXITFCRT = SIOCAIPXITFCRT; unsigned IOCTL_SIOCAIPXPRISLT = SIOCAIPXPRISLT; unsigned IOCTL_SIOCAX25ADDUID = SIOCAX25ADDUID; unsigned IOCTL_SIOCAX25DELUID = SIOCAX25DELUID; +#if SANITIZER_GNU unsigned IOCTL_SIOCAX25GETPARMS = SIOCAX25GETPARMS; +#endif unsigned IOCTL_SIOCAX25GETUID = SIOCAX25GETUID; unsigned IOCTL_SIOCAX25NOUID = SIOCAX25NOUID; +#if SANITIZER_GNU unsigned IOCTL_SIOCAX25SETPARMS = SIOCAX25SETPARMS; +#endif unsigned IOCTL_SIOCDEVPLIP = SIOCDEVPLIP; unsigned IOCTL_SIOCIPXCFGDATA = SIOCIPXCFGDATA; unsigned IOCTL_SIOCNRDECOBS = SIOCNRDECOBS; +#if SANITIZER_GNU 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; @@ -969,7 +1007,7 @@ CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phnum); #endif // SANITIZER_LINUX || SANITIZER_FREEBSD -#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID +#if (SANITIZER_GNU || SANITIZER_FREEBSD) CHECK_TYPE_SIZE(glob_t); CHECK_SIZE_AND_OFFSET(glob_t, gl_pathc); CHECK_SIZE_AND_OFFSET(glob_t, gl_pathv); @@ -1003,6 +1041,7 @@ CHECK_SIZE_AND_OFFSET(iovec, iov_base); CHECK_SIZE_AND_OFFSET(iovec, iov_len); +#if SANITIZER_GNU || SANITIZER_ANDROID CHECK_TYPE_SIZE(msghdr); CHECK_SIZE_AND_OFFSET(msghdr, msg_name); CHECK_SIZE_AND_OFFSET(msghdr, msg_namelen); @@ -1016,6 +1055,11 @@ CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_len); CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_level); CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_type); +#endif + +#ifndef __GLIBC_PREREQ +#define __GLIBC_PREREQ(x, y) 0 +#endif #if SANITIZER_LINUX && (__ANDROID_API__ >= 21 || __GLIBC_PREREQ (2, 14)) CHECK_TYPE_SIZE(mmsghdr); @@ -1121,7 +1165,7 @@ CHECK_TYPE_SIZE(ether_addr); -#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID +#if SANITIZER_GNU || SANITIZER_FREEBSD CHECK_TYPE_SIZE(ipc_perm); # if SANITIZER_FREEBSD CHECK_SIZE_AND_OFFSET(ipc_perm, key); @@ -1183,7 +1227,8 @@ CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_data); #endif -#if SANITIZER_LINUX +// mallinfo is annoying, cause it's SVID instead of POSIX or C standard... +#if SANITIZER_GNU COMPILER_CHECK(sizeof(__sanitizer_struct_mallinfo) == sizeof(struct mallinfo)); #endif @@ -1233,7 +1278,8 @@ COMPILER_CHECK(__sanitizer_XDR_FREE == XDR_FREE); #endif -#if SANITIZER_LINUX && !SANITIZER_ANDROID +// #if SANITIZER_LINUX && !SANITIZER_ANDROID +#if SANITIZER_GNU COMPILER_CHECK(sizeof(__sanitizer_FILE) <= sizeof(FILE)); CHECK_SIZE_AND_OFFSET(FILE, _flags); CHECK_SIZE_AND_OFFSET(FILE, _IO_read_ptr); @@ -1252,7 +1298,7 @@ CHECK_SIZE_AND_OFFSET(FILE, _fileno); #endif -#if SANITIZER_LINUX && !SANITIZER_ANDROID +#if SANITIZER_GNU COMPILER_CHECK(sizeof(__sanitizer__obstack_chunk) <= sizeof(_obstack_chunk)); CHECK_SIZE_AND_OFFSET(_obstack_chunk, limit); CHECK_SIZE_AND_OFFSET(_obstack_chunk, prev);