blob: df84550be0c4dac770515da0d657cb3687ddc0be [file] [log] [blame]
Patrick Williams58776372022-04-13 09:07:35 -05001From: Stefan Schmidt <stefan.schmidt@huawei.com>
2Subject: Turn off sign compare for musl libc
3
4When building with musl and clang the usage of CMSG_NXTHDR results in
5sign-compare error. Disable the check only in this specific part of the
6code with a #pragma.
7
8| /home/stefan/huawei/yocto-upstream/yoe/workspace/sources/ot-br-posix/third_party/openthread/repo/src/posix/platform/udp.cpp:147:28: fatal error: comparison of integers of different signs: 'unsigned long' and 'long' [-Wsign-compare]
9| cmsg = CMSG_NXTHDR(&msg, cmsg);
10| ^~~~~~~~~~~~~~~~~~~~~~~
11| /home/stefan/huawei/yocto-upstream/yoe/build/tmp/work/cortexa57-yoe-linux-musl/ot-br-posix/0.3.0+git999-r0/recipe-sysroot/usr/include/sys/socket.h:358:44: note: expanded from macro 'CMSG_NXTHDR'
12| __CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= __MHDR_END(mhdr) - (unsigned char *)(cmsg) \
13| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14| 1 error generated.
15
16Idea and fix taken from
17recipes-devtools/breakpad/breakpad/0001-Turn-off-sign-compare-for-musl-libc.patch
18by Khem Raj.
19
20Upstream-Status: Inappropriate [OE specific]
21
22Signed-off-by: Stefan Schmidt <stefan.schmidt@huawei.com>
23
24diff --git a/src/backbone_router/nd_proxy.cpp b/src/backbone_router/nd_proxy.cpp
25index 7136878c3d..8a223c95c7 100644
26--- a/src/backbone_router/nd_proxy.cpp
27+++ b/src/backbone_router/nd_proxy.cpp
28@@ -185,9 +185,18 @@ void NdProxyManager::ProcessMulticastNeighborSolicition()
29 VerifyOrExit(icmp6header->icmp6_type == ND_NEIGHBOR_SOLICIT, error = OTBR_ERROR_PARSE);
30
31 otbrLogDebug("NdProxyManager: Received ND-NS from %s", src.ToString().c_str());
32-
33+#ifndef __GLIBC__
34+ // In musl-libc, CMSG_NXTHDR typecasts char* to cmsghdr* which causes
35+ // clang to throw sign-compare warning. This is to suppress the warning
36+ // inline.
37+ #pragma clang diagnostic push
38+ #pragma clang diagnostic ignored "-Wsign-compare"
39+#endif
40 for (cmsghdr = CMSG_FIRSTHDR(&msghdr); cmsghdr; cmsghdr = CMSG_NXTHDR(&msghdr, cmsghdr))
41- {
42+#ifndef __GLIBC__
43+ #pragma clang diagnostic pop
44+#endif
45+ {
46 if (cmsghdr->cmsg_level != IPPROTO_IPV6)
47 {
48 continue;
49Submodule third_party/openthread/repo contains modified content
50diff --git a/third_party/openthread/repo/src/posix/platform/infra_if.cpp b/third_party/openthread/repo/src/posix/platform/infra_if.cpp
51index 9f93d2b1c..1ed40fe50 100644
52--- a/third_party/openthread/repo/src/posix/platform/infra_if.cpp
53+++ b/third_party/openthread/repo/src/posix/platform/infra_if.cpp
54@@ -228,7 +228,17 @@ otError InfraNetif::SendIcmp6Nd(uint32_t aInfraIfIndex,
55 packetInfo->ipi6_ifindex = mInfraIfIndex;
56
57 // Per section 6.1.2 of RFC 4861, we need to send the ICMPv6 message with IP Hop Limit 255.
58+#ifndef __GLIBC__
59+ // In musl-libc, CMSG_NXTHDR typecasts char* to cmsghdr* which causes
60+ // clang to throw sign-compare warning. This is to suppress the warning
61+ // inline.
62+ #pragma clang diagnostic push
63+ #pragma clang diagnostic ignored "-Wsign-compare"
64+#endif
65 cmsgPointer = CMSG_NXTHDR(&msgHeader, cmsgPointer);
66+#ifndef __GLIBC__
67+ #pragma clang diagnostic pop
68+#endif
69 cmsgPointer->cmsg_level = IPPROTO_IPV6;
70 cmsgPointer->cmsg_type = IPV6_HOPLIMIT;
71 cmsgPointer->cmsg_len = CMSG_LEN(sizeof(hopLimit));
72@@ -481,7 +491,17 @@ void InfraNetif::ReceiveIcmp6Message(void)
73
74 bufferLength = static_cast<uint16_t>(rval);
75
76+#ifndef __GLIBC__
77+ // In musl-libc, CMSG_NXTHDR typecasts char* to cmsghdr* which causes
78+ // clang to throw sign-compare warning. This is to suppress the warning
79+ // inline.
80+ #pragma clang diagnostic push
81+ #pragma clang diagnostic ignored "-Wsign-compare"
82+#endif
83 for (cmh = CMSG_FIRSTHDR(&msg); cmh; cmh = CMSG_NXTHDR(&msg, cmh))
84+#ifndef __GLIBC__
85+ #pragma clang diagnostic pop
86+#endif
87 {
88 if (cmh->cmsg_level == IPPROTO_IPV6 && cmh->cmsg_type == IPV6_PKTINFO &&
89 cmh->cmsg_len == CMSG_LEN(sizeof(struct in6_pktinfo)))
90diff --git a/third_party/openthread/repo/src/posix/platform/udp.cpp b/third_party/openthread/repo/src/posix/platform/udp.cpp
91index b7aacc5fa..a814fea70 100644
92--- a/third_party/openthread/repo/src/posix/platform/udp.cpp
93+++ b/third_party/openthread/repo/src/posix/platform/udp.cpp
94@@ -144,8 +144,18 @@ otError transmitPacket(int aFd, uint8_t *aPayload, uint16_t aLength, const otMes
95 {
96 struct in6_pktinfo pktinfo;
97
98+#ifndef __GLIBC__
99+ // In musl-libc, CMSG_NXTHDR typecasts char* to cmsghdr* which causes
100+ // clang to throw sign-compare warning. This is to suppress the warning
101+ // inline.
102+ #pragma clang diagnostic push
103+ #pragma clang diagnostic ignored "-Wsign-compare"
104+#endif
105 cmsg = CMSG_NXTHDR(&msg, cmsg);
106- cmsg->cmsg_level = IPPROTO_IPV6;
107+#ifndef __GLIBC__
108+ #pragma clang diagnostic pop
109+#endif
110+ cmsg->cmsg_level = IPPROTO_IPV6;
111 cmsg->cmsg_type = IPV6_PKTINFO;
112 cmsg->cmsg_len = CMSG_LEN(sizeof(pktinfo));
113
114@@ -200,7 +210,17 @@ otError receivePacket(int aFd, uint8_t *aPayload, uint16_t &aLength, otMessageIn
115 VerifyOrExit(rval > 0, perror("recvmsg"));
116 aLength = static_cast<uint16_t>(rval);
117
118+#ifndef __GLIBC__
119+ // In musl-libc, CMSG_NXTHDR typecasts char* to cmsghdr* which causes
120+ // clang to throw sign-compare warning. This is to suppress the warning
121+ // inline.
122+ #pragma clang diagnostic push
123+ #pragma clang diagnostic ignored "-Wsign-compare"
124+#endif
125 for (struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg); cmsg != nullptr; cmsg = CMSG_NXTHDR(&msg, cmsg))
126+#ifndef __GLIBC__
127+ #pragma clang diagnostic pop
128+#endif
129 {
130 if (cmsg->cmsg_level == IPPROTO_IPV6)
131 {