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

Backports: 3fc723ec2cf1965aa4eec8883957fbbe1b2e7027 (#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 60b10f56319e62415c61e69c67f9c713ed81172e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?De=C3=A1k=20Lajos?=
 <36414743+deakla...@users.noreply.github.com>
Date: Tue, 22 Jul 2025 20:31:28 +0200
Subject: [PATCH] [compiler-rt][sanitizer] fix msghdr for musl (#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`.
---
 .../sanitizer_platform_limits_posix.h         | 24 +++++++++++++++++++
 1 file changed, 24 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 f118d53f0df80..24966523f3a02 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -478,6 +478,30 @@ 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;
+  int msg_iovlen;
+#    if SANITIZER_WORDSIZE == 64
+  int __pad1;
+#    endif
+  void *msg_control;
+  unsigned msg_controllen;
+#    if SANITIZER_WORDSIZE == 64
+  int __pad2;
+#    endif
+  int msg_flags;
+};
+struct __sanitizer_cmsghdr {
+  unsigned cmsg_len;
+#    if SANITIZER_WORDSIZE == 64
+  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.

_______________________________________________
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to