[compiler-rt] [compiler-rt][sanitizer] fix msghdr for musl (PR #136195)

Deák Lajos via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 17 13:38:46 PDT 2025


https://github.com/deaklajos created https://github.com/llvm/llvm-project/pull/136195

Ran into the issue on Alpine when building with TSAN that `__sanitizer_msghdr` and the `msghdr` provided by musl did not match.
This caused lots of tsan reports and an eventual termination of the application by the oom during a `sendmsg`.

>From 3ffdd1ea76b4fbf45b8905210fd0be809499c474 Mon Sep 17 00:00:00 2001
From: Lajos Deak <lajos.deak at evosoft.com>
Date: Thu, 17 Apr 2025 20:01:05 +0000
Subject: [PATCH] [compiler-rt][sanitizer] fix msghdr for musl

---
 .../sanitizer_platform_limits_posix.h         | 33 +++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
index 348bb4f27aec3..899bd22bbd309 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -476,6 +476,39 @@ struct __sanitizer_cmsghdr {
   int cmsg_level;
   int cmsg_type;
 };
+#elif SANITIZER_MUSL
+struct __sanitizer_msghdr {
+  void *msg_name;
+  unsigned msg_namelen;
+  struct __sanitizer_iovec *msg_iov;
+#  if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN
+  int __pad1;
+#  endif
+  int msg_iovlen;
+#  if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN
+  int __pad1;
+#  endif
+  void *msg_control;
+#  if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN
+  int __pad2;
+#  endif
+  unsigned msg_controllen;
+#  if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN
+  int __pad2;
+#  endif
+  int msg_flags;
+};
+struct __sanitizer_cmsghdr {
+#  if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN
+  int __pad1;
+#  endif
+  unsigned cmsg_len;
+#  if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN
+  int __pad1;
+#  endif
+  int cmsg_level;
+  int cmsg_type;
+};
 #else
 // In POSIX, int msg_iovlen; socklen_t msg_controllen; socklen_t cmsg_len; but
 // many implementations don't conform to the standard.



More information about the llvm-commits mailing list