[PATCH] D21034: [sanitizer] Fix build for new GLIBC msghdr/cmsghdr definition
Adhemerval Zanella via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 6 12:19:35 PDT 2016
zatrazz created this revision.
zatrazz added reviewers: samsonov, eugenis, pcc, dvyukov.
zatrazz added subscribers: rengolin, llvm-commits.
zatrazz set the repository for this revision to rL LLVM.
zatrazz added a project: Sanitizers.
Herald added a subscriber: kubabrecka.
GLIBC now follows POSIX [1] for both msghdr and cmsghdr definitions,
which means that msg_iovlen, msg_controllen, and cmsg_len are no
longer size_t but sockelen_t for 64-bits architectures. The final struct
size does not change, since paddings were added.
This patch fixes the build issue against GLIBC 2.24 socket.h header by
using the same definition for internal __sanitizer_msghdr and
__sanitizer_cmsghdr.
[1] http://pubs.opengroup.org/onlinepubs/9699919799/
Repository:
rL LLVM
http://reviews.llvm.org/D21034
Files:
lib/sanitizer_common/sanitizer_platform_limits_posix.cc
lib/sanitizer_common/sanitizer_platform_limits_posix.h
Index: lib/sanitizer_common/sanitizer_platform_limits_posix.h
===================================================================
--- lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -419,13 +419,48 @@
void *msg_name;
unsigned msg_namelen;
struct __sanitizer_iovec *msg_iov;
+#ifndef __GLIBC_PREREQ
+#define __GLIBC_PREREQ(x, y) 0
+#endif
+// GLIBC 2.24 follows msghdr and cmsghdr POSIX definition for internal
+// member size and adds padding where required.
+#if __GLIBC_PREREQ (2, 24) && __WORDSIZE == 64
+# if __BYTE_ORDER == __BIG_ENDIAN
+ int __padding1;
+ unsigned msg_iovlen;
+# else
+ unsigned msg_iovlen;
+ int __padding1;
+# endif
+# else
uptr msg_iovlen;
+# endif
void *msg_control;
+#if __GLIBC_PREREQ (2, 24) && __WORDSIZE == 64
+# if __BYTE_ORDER == __BIG_ENDIAN
+ int __padding2;
+ unsigned msg_controllen;
+# else
+ unsigned msg_controllen;
+ int __padding2;
+# endif
+#else
uptr msg_controllen;
+#endif
int msg_flags;
};
struct __sanitizer_cmsghdr {
+#if __GLIBC_PREREQ (2, 24) && __WORDSIZE == 64
+# if __BYTE_ORDER == __BIG_ENDIAN
+ int __padding1;
+ unsigned cmsg_len;
+# else
+ unsigned cmsg_len;
+ int __padding1;
+# endif
+#else
uptr cmsg_len;
+#endif
int cmsg_level;
int cmsg_type;
};
Index: lib/sanitizer_common/sanitizer_platform_limits_posix.cc
===================================================================
--- lib/sanitizer_common/sanitizer_platform_limits_posix.cc
+++ lib/sanitizer_common/sanitizer_platform_limits_posix.cc
@@ -1011,17 +1011,32 @@
CHECK_SIZE_AND_OFFSET(iovec, iov_base);
CHECK_SIZE_AND_OFFSET(iovec, iov_len);
+#define CHECK_SENDMSG_MEMBER 1
+#if SANITIZER_LINUX
+# if __GLIBC_PREREQ == 0
+# undef CHECK_SENDMSG_MEMBER
+# endif
+#endif
+
CHECK_TYPE_SIZE(msghdr);
CHECK_SIZE_AND_OFFSET(msghdr, msg_name);
+#if CHECK_SENDMSG_MEMBER
CHECK_SIZE_AND_OFFSET(msghdr, msg_namelen);
+#endif
CHECK_SIZE_AND_OFFSET(msghdr, msg_iov);
+#if CHECK_SENDMSG_MEMBER
CHECK_SIZE_AND_OFFSET(msghdr, msg_iovlen);
+#endif
CHECK_SIZE_AND_OFFSET(msghdr, msg_control);
+#if CHECK_SENDMSG_MEMBER
CHECK_SIZE_AND_OFFSET(msghdr, msg_controllen);
+#endif
CHECK_SIZE_AND_OFFSET(msghdr, msg_flags);
CHECK_TYPE_SIZE(cmsghdr);
+#if CHECK_SENDMSG_MEMBER
CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_len);
+#endif
CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_level);
CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_type);
@@ -1060,9 +1075,6 @@
// Can't write checks for sa_handler and sa_sigaction due to them being
// preprocessor macros.
CHECK_STRUCT_SIZE_AND_OFFSET(sigaction, sa_mask);
-#ifndef __GLIBC_PREREQ
-#define __GLIBC_PREREQ(x, y) 0
-#endif
#if !defined(__s390x__) || __GLIBC_PREREQ (2, 20)
// On s390x glibc 2.19 and earlier sa_flags was unsigned long, and sa_resv
// didn't exist.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21034.59760.patch
Type: text/x-patch
Size: 2873 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160606/ad862db3/attachment.bin>
More information about the llvm-commits
mailing list