Skip to content

Instantly share code, notes, and snippets.

@milkey-mouse
Forked from jstraarup/nongnu.patch
Last active April 8, 2018 05:28
Show Gist options
  • Save milkey-mouse/f14e8d4f185bdd517124832ac0c2b8d2 to your computer and use it in GitHub Desktop.
Save milkey-mouse/f14e8d4f185bdd517124832ac0c2b8d2 to your computer and use it in GitHub Desktop.
Make clang sanitizers ( sys-libs/compiler-rt-sanitizers-6.0.0 ) compile with musl
diff -ruN compiler-rt-6.0.0.src/lib/asan/asan_linux.cc compiler-rt-6.0.0.src-musl/lib/asan/asan_linux.cc
--- compiler-rt-6.0.0.src/lib/asan/asan_linux.cc 2018-02-07 20:51:13.000000000 +0100
+++ compiler-rt-6.0.0.src-musl/lib/asan/asan_linux.cc 2018-03-20 11:57:12.381740075 +0100
@@ -46,7 +46,7 @@
#include <link.h>
#endif
-#if SANITIZER_ANDROID || SANITIZER_FREEBSD || SANITIZER_SOLARIS
+#if SANITIZER_ANDROID || SANITIZER_FREEBSD || SANITIZER_SOLARIS || SANITIZER_NONGNU
#include <ucontext.h>
extern "C" void* _DYNAMIC;
#elif SANITIZER_NETBSD
@@ -139,7 +139,7 @@
UNIMPLEMENTED();
}
-#if SANITIZER_ANDROID
+#if SANITIZER_ANDROID || SANITIZER_NONGNU
// FIXME: should we do anything for Android?
void AsanCheckDynamicRTPrereqs() {}
void AsanCheckIncompatibleRT() {}
diff -ruN compiler-rt-6.0.0.src/lib/interception/interception_linux.cc compiler-rt-6.0.0.src-musl/lib/interception/interception_linux.cc
--- compiler-rt-6.0.0.src/lib/interception/interception_linux.cc 2017-12-14 21:14:29.000000000 +0100
+++ compiler-rt-6.0.0.src-musl/lib/interception/interception_linux.cc 2018-03-20 11:50:05.798412046 +0100
@@ -43,7 +43,7 @@
}
// Android and Solaris do not have dlvsym
-#if !SANITIZER_ANDROID && !SANITIZER_SOLARIS
+#if !SANITIZER_ANDROID && !SANITIZER_SOLARIS && defined(__GLIBC__)
void *GetFuncAddrVer(const char *func_name, const char *ver) {
return dlvsym(RTLD_NEXT, func_name, ver);
}
diff -ruN compiler-rt-6.0.0.src/lib/msan/msan_interceptors.cc compiler-rt-6.0.0.src-musl/lib/msan/msan_interceptors.cc
--- compiler-rt-6.0.0.src/lib/msan/msan_interceptors.cc 2017-12-14 02:20:16.000000000 +0100
+++ compiler-rt-6.0.0.src-musl/lib/msan/msan_interceptors.cc 2018-03-20 13:18:05.831679710 +0100
@@ -1438,6 +1438,7 @@
return cbdata->callback(info, size, cbdata->data);
}
+/* does not compile with musl
INTERCEPTOR(void *, shmat, int shmid, const void *shmaddr, int shmflg) {
ENSURE_MSAN_INITED();
void *p = REAL(shmat)(shmid, shmaddr, shmflg);
@@ -1450,6 +1451,7 @@
}
return p;
}
+*/
INTERCEPTOR(int, dl_iterate_phdr, dl_iterate_phdr_cb callback, void *data) {
void *ctx;
@@ -1668,7 +1670,7 @@
INTERCEPT_FUNCTION(pthread_join);
INTERCEPT_FUNCTION(tzset);
INTERCEPT_FUNCTION(__cxa_atexit);
- INTERCEPT_FUNCTION(shmat);
+ // INTERCEPT_FUNCTION(shmat); // does not compile with musl
INTERCEPT_FUNCTION(fork);
INTERCEPT_FUNCTION(openpty);
INTERCEPT_FUNCTION(forkpty);
diff -ruN compiler-rt-6.0.0.src/lib/msan/msan_linux.cc compiler-rt-6.0.0.src-musl/lib/msan/msan_linux.cc
--- compiler-rt-6.0.0.src/lib/msan/msan_linux.cc 2017-11-08 00:51:22.000000000 +0100
+++ compiler-rt-6.0.0.src-musl/lib/msan/msan_linux.cc 2018-03-20 12:37:58.201709654 +0100
@@ -13,7 +13,7 @@
//===----------------------------------------------------------------------===//
#include "sanitizer_common/sanitizer_platform.h"
-#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
+#if SANITIZER_FREEBSD || SANITIZER_LINUX && !SANITIZER_NONGNU || SANITIZER_NETBSD
#include "msan.h"
#include "msan_thread.h"
diff -ruN compiler-rt-6.0.0.src/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc compiler-rt-6.0.0.src-musl/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
--- compiler-rt-6.0.0.src/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc 2017-12-14 21:14:29.000000000 +0100
+++ compiler-rt-6.0.0.src-musl/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc 2018-03-20 12:09:13.391731107 +0100
@@ -102,7 +102,7 @@
_(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);
@@ -363,7 +363,7 @@
_(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 -ruN compiler-rt-6.0.0.src/lib/sanitizer_common/sanitizer_common_syscalls.inc compiler-rt-6.0.0.src-musl/lib/sanitizer_common/sanitizer_common_syscalls.inc
--- compiler-rt-6.0.0.src/lib/sanitizer_common/sanitizer_common_syscalls.inc 2016-06-25 01:09:44.000000000 +0200
+++ compiler-rt-6.0.0.src-musl/lib/sanitizer_common/sanitizer_common_syscalls.inc 2018-03-20 12:32:49.228380164 +0100
@@ -2038,7 +2038,7 @@
}
}
-#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);
Binary files compiler-rt-6.0.0.src/lib/sanitizer_common/.sanitizer_linux_libcdep.cc.kate-swp and compiler-rt-6.0.0.src-musl/lib/sanitizer_common/.sanitizer_linux_libcdep.cc.kate-swp differ
diff -ruN compiler-rt-6.0.0.src/lib/sanitizer_common/sanitizer_platform.h compiler-rt-6.0.0.src-musl/lib/sanitizer_common/sanitizer_platform.h
--- compiler-rt-6.0.0.src/lib/sanitizer_common/sanitizer_platform.h 2017-12-14 21:14:29.000000000 +0100
+++ compiler-rt-6.0.0.src-musl/lib/sanitizer_common/sanitizer_platform.h 2018-03-20 11:27:50.371761989 +0100
@@ -24,6 +24,12 @@
#else
# define SANITIZER_LINUX 0
#endif
+
+#if defined(__linux__) && !defined(__GLIBC__)
+# define SANITIZER_NONGNU 1
+#else
+# define SANITIZER_NONGNU 0
+#endif
#if defined(__FreeBSD__)
# define SANITIZER_FREEBSD 1
diff -ruN compiler-rt-6.0.0.src/lib/sanitizer_common/sanitizer_platform_interceptors.h compiler-rt-6.0.0.src-musl/lib/sanitizer_common/sanitizer_platform_interceptors.h
--- compiler-rt-6.0.0.src/lib/sanitizer_common/sanitizer_platform_interceptors.h 2017-12-29 00:06:51.000000000 +0100
+++ compiler-rt-6.0.0.src-musl/lib/sanitizer_common/sanitizer_platform_interceptors.h 2018-03-20 11:30:21.908426772 +0100
@@ -38,7 +38,7 @@
# include "sanitizer_platform_limits_solaris.h"
#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 -ruN compiler-rt-6.0.0.src/lib/sanitizer_common/sanitizer_platform_limits_posix.cc compiler-rt-6.0.0.src-musl/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
--- compiler-rt-6.0.0.src/lib/sanitizer_common/sanitizer_platform_limits_posix.cc 2017-11-21 10:36:07.000000000 +0100
+++ compiler-rt-6.0.0.src-musl/lib/sanitizer_common/sanitizer_platform_limits_posix.cc 2018-03-20 13:37:42.438331742 +0100
@@ -140,10 +140,10 @@
#include <glob.h>
#include <obstack.h>
#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
@@ -159,7 +159,7 @@
# include <sys/procfs.h>
#endif
#include <sys/user.h>
-#include <sys/ustat.h>
+/* #include <sys/ustat.h> // is in glibc, but not in musl */
#include <linux/cyclades.h>
#include <linux/if_eql.h>
#include <linux/if_plip.h>
@@ -252,8 +252,8 @@
unsigned struct_itimerspec_sz = sizeof(struct itimerspec);
#endif // SANITIZER_LINUX || SANITIZER_FREEBSD
-#if SANITIZER_LINUX && !SANITIZER_ANDROID
- unsigned struct_ustat_sz = sizeof(struct ustat);
+#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);
#endif // SANITIZER_LINUX && !SANITIZER_ANDROID
@@ -275,9 +275,9 @@
#endif
-#if (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
+#if (SANITIZER_LINUX && !SANITIZER_NONGNU || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
unsigned struct_shminfo_sz = sizeof(struct shminfo);
- unsigned struct_shm_info_sz = sizeof(struct shm_info);
+ unsigned struct_shm_info_sz = sizeof(nstruct shm_info);
int shmctl_ipc_stat = (int)IPC_STAT;
int shmctl_ipc_info = (int)IPC_INFO;
int shmctl_shm_info = (int)SHM_INFO;
@@ -311,7 +311,7 @@
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
@@ -405,7 +405,7 @@
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);
@@ -455,7 +455,7 @@
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)
@@ -823,7 +823,7 @@
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;
@@ -978,7 +978,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 || 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);
@@ -1012,6 +1012,7 @@
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);
@@ -1025,6 +1026,7 @@
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);
@@ -1127,7 +1129,7 @@
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);
@@ -1188,7 +1190,7 @@
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
@@ -1238,7 +1240,7 @@
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);
@@ -1257,7 +1259,7 @@
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 -ruN compiler-rt-6.0.0.src/lib/tsan/rtl/tsan_platform_linux.cc compiler-rt-6.0.0.src-musl/lib/tsan/rtl/tsan_platforMake clang sanitizers ( sys-libs/compiler-rt-sanitizers-6.0.0 ) compile with muslm_linux.cc
--- compiler-rt-6.0.0.src/lib/tsan/rtl/tsan_platform_linux.cc 2017-11-28 17:28:54.000000000 +0100
+++ compiler-rt-6.0.0.src-musl/lib/tsan/rtl/tsan_platform_linux.cc 2018-03-20 12:02:39.218402676 +0100
@@ -285,7 +285,7 @@
// 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;
struct __res_state *statp = (struct __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