[59/61] Add uclibc support

Message ID 20250131171232.1018281-61-aleksandar.rakic@htecgroup.com
State New
Headers
Series Improve Mips target |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply

Commit Message

Aleksandar Rakic Jan. 31, 2025, 5:13 p.m. UTC
  From: Jean Lee <xiaoyur347@sina.com>

Disable stack unwind and fix page size for uclibc on mips target.

Fix "ASan runtime does not come first in initial library list; you
should either link runtime to your application or manually preload it
with LD_PRELOAD."

Disable SANITIZER_INTERCEPT_GLOB.

Resolve libsanitizer build issues for uclibc.

Cherry-picked 94e7806991cf3af0dbaf6147d0010480a7760cc8,
52849bd97f29b6ad17d493ad383d8833473ee6a7,
0dcb2d0c3cc4d7118bd211a24e01d9a991dd72d2,
127b4d28d9bfba10e7006decdcd0f24665e5d5af,
5cd320103ba1248c6925b9843f1139e60d283bed and
af4425414cef0155d6f00ad118417f4908eae756
from https://github.com/MIPS/gcc

Signed-off-by: Jean Lee <xiaoyur347@sina.com>
Signed-off-by: Faraz Shahbazker <fshahbazker@wavecomp.com>
Signed-off-by: Aleksandar Rakic <aleksandar.rakic@htecgroup.com>
---
 libsanitizer/asan/asan_descriptions.cpp       |  5 ++
 libsanitizer/asan/asan_linux.cpp              |  2 +-
 .../interception/interception_linux.cpp       |  6 ++-
 .../interception/interception_linux.h         |  6 ++-
 .../sanitizer_common/sanitizer_common.cpp     | 10 +++-
 .../sanitizer_common/sanitizer_linux.cpp      |  6 ++-
 .../sanitizer_common/sanitizer_platform.h     |  9 ++++
 .../sanitizer_platform_interceptors.h         | 14 ++++--
 .../sanitizer_platform_limits_posix.cpp       | 46 +++++++++++++++----
 .../sanitizer_platform_limits_posix.h         |  9 +++-
 .../sanitizer_unwind_linux_libcdep.cpp        |  2 +
 11 files changed, 93 insertions(+), 22 deletions(-)
  

Patch

diff --git a/libsanitizer/asan/asan_descriptions.cpp b/libsanitizer/asan/asan_descriptions.cpp
index caec79313e2..0b8180bbf0f 100644
--- a/libsanitizer/asan/asan_descriptions.cpp
+++ b/libsanitizer/asan/asan_descriptions.cpp
@@ -175,10 +175,15 @@  bool GetHeapAddressInformation(uptr addr, uptr access_size,
 }
 
 static StackTrace GetStackTraceFromId(u32 id) {
+#if !(defined(__mips__) && SANITIZER_UCLIBC)
   CHECK(id);
   StackTrace res = StackDepotGet(id);
   CHECK(res.trace);
   return res;
+#else
+  StackTrace res;
+  return res;
+#endif
 }
 
 bool DescribeAddressIfHeap(uptr addr, uptr access_size) {
diff --git a/libsanitizer/asan/asan_linux.cpp b/libsanitizer/asan/asan_linux.cpp
index 4cabca388ca..abcfb2467c9 100644
--- a/libsanitizer/asan/asan_linux.cpp
+++ b/libsanitizer/asan/asan_linux.cpp
@@ -107,7 +107,7 @@  void FlushUnneededASanShadowMemory(uptr p, uptr size) {
   ReleaseMemoryPagesToOS(MemToShadow(p), MemToShadow(p + size));
 }
 
-#  if SANITIZER_ANDROID
+#  if SANITIZER_ANDROID || SANITIZER_UCLIBC
 // FIXME: should we do anything for Android?
 void AsanCheckDynamicRTPrereqs() {}
 void AsanCheckIncompatibleRT() {}
diff --git a/libsanitizer/interception/interception_linux.cpp b/libsanitizer/interception/interception_linux.cpp
index ef8136eb4fc..ed8bd3a80b9 100644
--- a/libsanitizer/interception/interception_linux.cpp
+++ b/libsanitizer/interception/interception_linux.cpp
@@ -64,7 +64,8 @@  bool InterceptFunction(const char *name, uptr *ptr_to_real, uptr func,
 }
 
 // dlvsym is a GNU extension supported by some other platforms.
-#if SANITIZER_GLIBC || SANITIZER_FREEBSD || SANITIZER_NETBSD
+#if (SANITIZER_GLIBC || SANITIZER_FREEBSD || SANITIZER_NETBSD) && \
+    !SANITIZER_UCLIBC
 static void *GetFuncAddr(const char *name, const char *ver) {
   return dlvsym(RTLD_NEXT, name, ver);
 }
@@ -75,7 +76,8 @@  bool InterceptFunction(const char *name, const char *ver, uptr *ptr_to_real,
   *ptr_to_real = (uptr)addr;
   return addr && (func == trampoline);
 }
-#  endif  // SANITIZER_GLIBC || SANITIZER_FREEBSD || SANITIZER_NETBSD
+#  endif  // (SANITIZER_GLIBC || SANITIZER_FREEBSD || SANITIZER_NETBSD) &&
+	  // !SANITIZER_UCLIBC
 
 }  // namespace __interception
 
diff --git a/libsanitizer/interception/interception_linux.h b/libsanitizer/interception/interception_linux.h
index 2e01ff44578..897ec677350 100644
--- a/libsanitizer/interception/interception_linux.h
+++ b/libsanitizer/interception/interception_linux.h
@@ -38,7 +38,8 @@  bool InterceptFunction(const char *name, const char *ver, uptr *ptr_to_real,
       (::__interception::uptr) &TRAMPOLINE(func))
 
 // dlvsym is a GNU extension supported by some other platforms.
-#if SANITIZER_GLIBC || SANITIZER_FREEBSD || SANITIZER_NETBSD
+#if (SANITIZER_GLIBC || SANITIZER_FREEBSD || SANITIZER_NETBSD) && \
+    !SANITIZER_UCLIBC
 #define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \
   ::__interception::InterceptFunction(                        \
       #func, symver,                                          \
@@ -48,7 +49,8 @@  bool InterceptFunction(const char *name, const char *ver, uptr *ptr_to_real,
 #else
 #define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \
   INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func)
-#endif  // SANITIZER_GLIBC || SANITIZER_FREEBSD || SANITIZER_NETBSD
+#endif  // (SANITIZER_GLIBC || SANITIZER_FREEBSD || SANITIZER_NETBSD) &&
+	// !SANITIZER_UCLIBC
 
 #endif  // INTERCEPTION_LINUX_H
 #endif  // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD ||
diff --git a/libsanitizer/sanitizer_common/sanitizer_common.cpp b/libsanitizer/sanitizer_common/sanitizer_common.cpp
index 6cd69a53093..812102028ad 100644
--- a/libsanitizer/sanitizer_common/sanitizer_common.cpp
+++ b/libsanitizer/sanitizer_common/sanitizer_common.cpp
@@ -384,7 +384,15 @@  void internal_sleep(unsigned seconds) {
 void SleepForSeconds(unsigned seconds) {
   internal_usleep((u64)seconds * 1000 * 1000);
 }
-void SleepForMillis(unsigned millis) { internal_usleep((u64)millis * 1000); }
+void SleepForMillis (unsigned millis)
+{
+  #if SANITIZER_UCLIBC
+  struct timespec tv = {0, millis * 1000000};
+  nanosleep (&tv, NULL);
+  #else
+  internal_usleep ((u64)millis * 1000);
+  #endif
+}
 
 void WaitForDebugger(unsigned seconds, const char *label) {
   if (seconds) {
diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.cpp b/libsanitizer/sanitizer_common/sanitizer_linux.cpp
index 8b1850f8501..5b326cd4e53 100644
--- a/libsanitizer/sanitizer_common/sanitizer_linux.cpp
+++ b/libsanitizer/sanitizer_common/sanitizer_linux.cpp
@@ -71,7 +71,9 @@ 
 #  include <sys/syscall.h>
 #  include <sys/time.h>
 #  include <sys/types.h>
-#  include <ucontext.h>
+#  if !SANITIZER_UCLIBC
+#    include <ucontext.h>
+#  endif
 #  include <unistd.h>
 
 #  if SANITIZER_LINUX
@@ -1215,6 +1217,8 @@  uptr GetPageSize() {
   return (uptr)pz;
 #    elif SANITIZER_USE_GETAUXVAL
   return getauxval(AT_PAGESZ);
+#    elif defined(__mips__) && SANITIZER_UCLIBC
+  return 4096;
 #    else
   return sysconf(_SC_PAGESIZE);  // EXEC_PAGESIZE may not be trustworthy.
 #    endif
diff --git a/libsanitizer/sanitizer_common/sanitizer_platform.h b/libsanitizer/sanitizer_common/sanitizer_platform.h
index 57966403c92..fd3e8543f91 100644
--- a/libsanitizer/sanitizer_common/sanitizer_platform.h
+++ b/libsanitizer/sanitizer_common/sanitizer_platform.h
@@ -140,6 +140,15 @@ 
   (SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_APPLE || \
    SANITIZER_NETBSD || SANITIZER_SOLARIS)
 
+#include <features.h> //for uclibc
+
+#if defined(__UCLIBC__)
+# define SANITIZER_UCLIBC  1
+#else
+# define SANITIZER_UCLIBC  0
+#endif
+
+
 #if __LP64__ || defined(_WIN64)
 #  define SANITIZER_WORDSIZE 64
 #else
diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_interceptors.h b/libsanitizer/sanitizer_common/sanitizer_platform_interceptors.h
index 3fd6b595ef1..48f28729498 100644
--- a/libsanitizer/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/libsanitizer/sanitizer_common/sanitizer_platform_interceptors.h
@@ -58,6 +58,12 @@ 
 #define SI_ANDROID 0
 #endif
 
+#if SANITIZER_LINUX && !SANITIZER_UCLIBC
+# define SI_LINUX_NOT_UCLIBC 1
+#else
+# define SI_LINUX_NOT_UCLIBC 0
+#endif
+
 #if SANITIZER_FREEBSD
 #define SI_FREEBSD 1
 #else
@@ -258,8 +264,9 @@  SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
   (SI_LINUX || SI_FREEBSD || SI_NETBSD)
 #define SANITIZER_INTERCEPT_GETITIMER SI_POSIX
 #define SANITIZER_INTERCEPT_TIME SI_POSIX
-#define SANITIZER_INTERCEPT_GLOB (SI_GLIBC || SI_SOLARIS)
-#define SANITIZER_INTERCEPT_GLOB64 SI_GLIBC
+#define SANITIZER_INTERCEPT_GLOB \
+  ((SI_GLIBC && SI_LINUX_NOT_UCLIBC) || SI_SOLARIS)
+#define SANITIZER_INTERCEPT_GLOB64 (SI_GLIBC && SI_LINUX_NOT_UCLIBC)
 #define SANITIZER_INTERCEPT___B64_TO SI_LINUX_NOT_ANDROID
 #define SANITIZER_INTERCEPT_DN_COMP_EXPAND SI_LINUX_NOT_ANDROID
 #define SANITIZER_INTERCEPT_POSIX_SPAWN SI_POSIX
@@ -439,7 +446,8 @@  SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SANITIZER_INTERCEPT_GETXATTR SI_LINUX
 #define SANITIZER_INTERCEPT_GETRESID SI_LINUX
 #define SANITIZER_INTERCEPT_GETIFADDRS \
-  (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_MAC || SI_SOLARIS)
+  (SI_FREEBSD || SI_NETBSD || (SI_LINUX_NOT_ANDROID && SI_LINUX_NOT_UCLIBC) \
+   || SI_MAC || SI_SOLARIS)
 #define SANITIZER_INTERCEPT_IF_INDEXTONAME \
   (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_MAC || SI_SOLARIS)
 #define SANITIZER_INTERCEPT_CAPGET SI_LINUX_NOT_ANDROID
diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp
index c87d5ef42c9..2744172cb82 100644
--- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp
+++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp
@@ -35,7 +35,9 @@ 
 #include <net/if.h>
 #include <netdb.h>
 #include <poll.h>
+#if !SANITIZER_UCLIBC
 #include <pthread.h>
+#endif
 #include <pwd.h>
 #include <signal.h>
 #include <stddef.h>
@@ -62,15 +64,19 @@ 
 
 #if !SANITIZER_ANDROID
 #include <sys/mount.h>
+#if !SANITIZER_UCLIBC
 #include <sys/timeb.h>
 #include <utmpx.h>
 #endif
+#endif
 
 #if SANITIZER_LINUX
 #include <malloc.h>
 #include <mntent.h>
 #include <netinet/ether.h>
+#if !SANITIZER_UCLIBC //for redefine
 #include <sys/sysinfo.h>
+#endif
 #include <sys/vt.h>
 #include <linux/cdrom.h>
 #include <linux/fd.h>
@@ -92,7 +98,9 @@ 
 #endif
 
 #if SANITIZER_LINUX
-# include <utime.h>
+# if !SANITIZER_UCLIBC
+#  include <utime.h>
+# endif
 # include <sys/ptrace.h>
 #    if defined(__mips64) || defined(__aarch64__) || defined(__arm__) ||       \
         defined(__hexagon__) || defined(__loongarch__) || SANITIZER_RISCV64 || \
@@ -109,7 +117,7 @@  typedef struct user_fpregs elf_fpregset_t;
 # include <semaphore.h>
 #endif
 
-#if !SANITIZER_ANDROID
+#if !SANITIZER_ANDROID && !SANITIZER_UCLIBC
 #include <ifaddrs.h>
 #include <sys/ucontext.h>
 #include <wordexp.h>
@@ -122,7 +130,9 @@  typedef struct user_fpregs elf_fpregset_t;
 #      include <net/if_ppp.h>
 #      include <netax25/ax25.h>
 #      include <netipx/ipx.h>
-#      include <netrom/netrom.h>
+#      if !SANITIZER_UCLIBC
+#	include <netrom/netrom.h>
+#      endif
 #      include <obstack.h>
 #      if HAVE_RPC_XDR_H
 #        include <rpc/xdr.h>
@@ -200,12 +210,16 @@  namespace __sanitizer {
   unsigned timeval_sz = sizeof(timeval);
   unsigned uid_t_sz = sizeof(uid_t);
   unsigned gid_t_sz = sizeof(gid_t);
+  #if !SANITIZER_UCLIBC
   unsigned mbstate_t_sz = sizeof(mbstate_t);
+  #endif
   unsigned sigset_t_sz = sizeof(sigset_t);
   unsigned struct_timezone_sz = sizeof(struct timezone);
   unsigned struct_tms_sz = sizeof(struct tms);
   unsigned struct_sigevent_sz = sizeof(struct sigevent);
+  #if !SANITIZER_UCLIBC
   unsigned struct_sched_param_sz = sizeof(struct sched_param);
+  #endif
   unsigned struct_regex_sz = sizeof(regex_t);
   unsigned struct_regmatch_sz = sizeof(regmatch_t);
 
@@ -271,7 +285,9 @@  namespace __sanitizer {
 #if SANITIZER_LINUX
   unsigned struct_rlimit_sz = sizeof(struct rlimit);
   unsigned struct_timespec_sz = sizeof(struct timespec);
+  #if !SANITIZER_UCLIBC
   unsigned struct_utimbuf_sz = sizeof(struct utimbuf);
+  #endif
   unsigned struct_itimerspec_sz = sizeof(struct itimerspec);
 #endif // SANITIZER_LINUX
 
@@ -327,7 +343,7 @@  namespace __sanitizer {
 #if !SANITIZER_APPLE && !SANITIZER_FREEBSD
   unsigned struct_utmp_sz = sizeof(struct utmp);
 #endif
-#if !SANITIZER_ANDROID
+#if !SANITIZER_ANDROID && !SANITIZER_UCLIBC
   unsigned struct_utmpx_sz = sizeof(struct utmpx);
 #endif
 
@@ -351,7 +367,7 @@  unsigned struct_ElfW_Phdr_sz = sizeof(ElfW(Phdr));
 unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr);
 #endif
 
-#if SANITIZER_GLIBC
+#if SANITIZER_GLIBC && !SANITIZER_UCLIBC
   int glob_nomatch = GLOB_NOMATCH;
   int glob_altdirfunc = GLOB_ALTDIRFUNC;
 #endif
@@ -525,7 +541,9 @@  unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr);
   unsigned struct_kbkeycode_sz = sizeof(struct kbkeycode);
   unsigned struct_kbsentry_sz = sizeof(struct kbsentry);
   unsigned struct_mtconfiginfo_sz = sizeof(struct mtconfiginfo);
+#if !SANITIZER_UCLIBC
   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
@@ -894,7 +912,11 @@  unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr);
   unsigned IOCTL_EQL_SETSLAVECFG = EQL_SETSLAVECFG;
 #if EV_VERSION > (0x010000)
   unsigned IOCTL_EVIOCGKEYCODE_V2 = EVIOCGKEYCODE_V2;
+#if !SANITIZER_UCLIBC
   unsigned IOCTL_EVIOCGPROP = EVIOCGPROP(0);
+#else
+  unsigned IOCTL_EVIOCGPROP = IOCTL_NOT_PRESENT;
+#endif
   unsigned IOCTL_EVIOCSKEYCODE_V2 = EVIOCSKEYCODE_V2;
 #else
   unsigned IOCTL_EVIOCGKEYCODE_V2 = IOCTL_NOT_PRESENT;
@@ -958,10 +980,12 @@  unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr);
   unsigned IOCTL_SIOCAX25SETPARMS = SIOCAX25SETPARMS;
   unsigned IOCTL_SIOCDEVPLIP = SIOCDEVPLIP;
   unsigned IOCTL_SIOCIPXCFGDATA = SIOCIPXCFGDATA;
+#if !SANITIZER_UCLIBC
   unsigned IOCTL_SIOCNRDECOBS = SIOCNRDECOBS;
   unsigned IOCTL_SIOCNRGETPARMS = SIOCNRGETPARMS;
   unsigned IOCTL_SIOCNRRTCTL = SIOCNRRTCTL;
   unsigned IOCTL_SIOCNRSETPARMS = SIOCNRSETPARMS;
+#endif
 #endif
   unsigned IOCTL_TIOCGSERIAL = TIOCGSERIAL;
   unsigned IOCTL_TIOCSERGETMULTI = TIOCSERGETMULTI;
@@ -1033,7 +1057,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_GLIBC || SANITIZER_FREEBSD
+#if (SANITIZER_GLIBC || SANITIZER_FREEBSD) && !SANITIZER_UCLIBC
 CHECK_TYPE_SIZE(glob_t);
 CHECK_SIZE_AND_OFFSET(glob_t, gl_pathc);
 CHECK_SIZE_AND_OFFSET(glob_t, gl_pathv);
@@ -1172,7 +1196,7 @@  CHECK_TYPE_SIZE(__kernel_loff_t);
 CHECK_TYPE_SIZE(__kernel_fd_set);
 #endif
 
-#if !SANITIZER_ANDROID
+#if !SANITIZER_ANDROID && !SANITIZER_UCLIBC
 CHECK_TYPE_SIZE(wordexp_t);
 CHECK_SIZE_AND_OFFSET(wordexp_t, we_wordc);
 CHECK_SIZE_AND_OFFSET(wordexp_t, we_wordv);
@@ -1240,7 +1264,7 @@  CHECK_TYPE_SIZE(clock_t);
 CHECK_TYPE_SIZE(clockid_t);
 #endif
 
-#if !SANITIZER_ANDROID
+#if !SANITIZER_ANDROID && !SANITIZER_UCLIBC
 CHECK_TYPE_SIZE(ifaddrs);
 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_next);
 CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_name);
@@ -1270,7 +1294,7 @@  CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_data);
 COMPILER_CHECK(sizeof(__sanitizer_struct_mallinfo) == sizeof(struct mallinfo));
 #endif
 
-#if !SANITIZER_ANDROID
+#if !SANITIZER_ANDROID && !SANITIZER_UCLIBC
 CHECK_TYPE_SIZE(timeb);
 CHECK_SIZE_AND_OFFSET(timeb, time);
 CHECK_SIZE_AND_OFFSET(timeb, millitm);
@@ -1316,7 +1340,7 @@  COMPILER_CHECK(__sanitizer_XDR_DECODE == XDR_DECODE);
 COMPILER_CHECK(__sanitizer_XDR_FREE == XDR_FREE);
 #endif
 
-#if SANITIZER_GLIBC
+#if SANITIZER_GLIBC && !SANITIZER_UCLIBC
 COMPILER_CHECK(sizeof(__sanitizer_FILE) <= sizeof(FILE));
 CHECK_SIZE_AND_OFFSET(FILE, _flags);
 CHECK_SIZE_AND_OFFSET(FILE, _IO_read_ptr);
@@ -1334,6 +1358,7 @@  CHECK_SIZE_AND_OFFSET(FILE, _markers);
 CHECK_SIZE_AND_OFFSET(FILE, _chain);
 CHECK_SIZE_AND_OFFSET(FILE, _fileno);
 
+#if !SANITIZER_UCLIBC
 COMPILER_CHECK(sizeof(__sanitizer__obstack_chunk) <= sizeof(_obstack_chunk));
 CHECK_SIZE_AND_OFFSET(_obstack_chunk, limit);
 CHECK_SIZE_AND_OFFSET(_obstack_chunk, prev);
@@ -1348,6 +1373,7 @@  CHECK_SIZE_AND_OFFSET(cookie_io_functions_t, read);
 CHECK_SIZE_AND_OFFSET(cookie_io_functions_t, write);
 CHECK_SIZE_AND_OFFSET(cookie_io_functions_t, seek);
 CHECK_SIZE_AND_OFFSET(cookie_io_functions_t, close);
+#endif
 #endif  // SANITIZER_GLIBC
 
 #if SANITIZER_LINUX || SANITIZER_FREEBSD
diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
index e8c81aa8e28..e2ac31a5fb3 100644
--- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -316,7 +316,7 @@  struct __sanitizer_iovec {
   uptr iov_len;
 };
 
-#if !SANITIZER_ANDROID
+#if !SANITIZER_ANDROID && !SANITIZER_UCLIBC
 struct __sanitizer_ifaddrs {
   struct __sanitizer_ifaddrs *ifa_next;
   char *ifa_name;
@@ -570,6 +570,11 @@  typedef unsigned long __sanitizer_sigset_t;
 # endif
 #elif SANITIZER_APPLE
 typedef unsigned __sanitizer_sigset_t;
+#elif SANITIZER_UCLIBC
+  struct __sanitizer_sigset_t {
+    // The size is determined by looking at sizeof of real sigset_t on linux.
+    uptr val[128 / (sizeof (unsigned long) * 8)];
+  };
 #elif SANITIZER_LINUX
 struct __sanitizer_sigset_t {
   // The size is determined by looking at sizeof of real sigset_t on linux.
@@ -681,7 +686,7 @@  struct __sanitizer_sigaction {
 #if SANITIZER_LINUX
   void (*sa_restorer)();
 #endif
-#if defined(__mips__) && (SANITIZER_WORDSIZE == 32)
+#if defined(__mips__) && (SANITIZER_WORDSIZE == 32) && !SANITIZER_UCLIBC
   int sa_resv[1];
 #endif
 #if defined(__s390x__)
diff --git a/libsanitizer/sanitizer_common/sanitizer_unwind_linux_libcdep.cpp b/libsanitizer/sanitizer_common/sanitizer_unwind_linux_libcdep.cpp
index 6a8e82e2e21..d678ebacb2a 100644
--- a/libsanitizer/sanitizer_common/sanitizer_unwind_linux_libcdep.cpp
+++ b/libsanitizer/sanitizer_common/sanitizer_unwind_linux_libcdep.cpp
@@ -126,6 +126,7 @@  void SanitizerInitializeUnwinder() {
 void BufferedStackTrace::UnwindSlow(uptr pc, u32 max_depth) {
   CHECK_GE(max_depth, 2);
   size = 0;
+#if !(defined(__mips__) && SANITIZER_UCLIBC)
   UnwindTraceArg arg = {this, Min(max_depth + 1, kStackTraceMax)};
   _Unwind_Backtrace(Unwind_Trace, &arg);
   // We need to pop a few frames so that pc is on top.
@@ -140,6 +141,7 @@  void BufferedStackTrace::UnwindSlow(uptr pc, u32 max_depth) {
     to_pop = 1;
   PopStackFrames(to_pop);
   trace_buffer[0] = pc;
+#endif
 }
 
 void BufferedStackTrace::UnwindSlow(uptr pc, void *context, u32 max_depth) {