Toolchain: Yocto Linux with poky-tiny
Host platform: openSUSE 15.3 x86_64
Target platform: arm-poky-linux-musleabi (armv7, 32 bit)
When I try to compile libkcapi [1] [2] with current
Yocto/Openembedded master branch, I get the following compiler error:
| ../git/lib/kcapi-kernel-if.c: In function '_kcapi_common_send_meta':
| ../git/lib/kcapi-kernel-if.c:193:26: error: unsigned conversion from 'long int' to 'long unsigned int' changes value from '-4' to '4294967292' [-Werror=sign-conversion]
| 193 | header = CMSG_NXTHDR(&msg, header);
| | ^~~~~~~~~~~
| ../git/lib/kcapi-kernel-if.c:193:26: error: unsigned conversion from 'long int' to 'long unsigned int' changes value from '-4' to '4294967292' [-Werror=sign-conversion]
| ../git/lib/kcapi-kernel-if.c:213:26: error: unsigned conversion from 'long int' to 'long unsigned int' changes value from '-4' to '4294967292' [-Werror=sign-conversion]
| 213 | header = CMSG_NXTHDR(&msg, header);
| | ^~~~~~~~~~~
| ../git/lib/kcapi-kernel-if.c:213:26: error: unsigned conversion from 'long int' to 'long unsigned int' changes value from '-4' to '4294967292' [-Werror=sign-conversion]
Note: libcapi uses the '-Werror' and '-Wconversion' flags.
For testing, I created a minimal code snipset (cmsg.c):
#include <stddef.h>
#include <sys/socket.h>
void foo(void)
{
struct msghdr msg = {0};
struct cmsghdr *header = NULL;
header = CMSG_FIRSTHDR(&msg);
header = CMSG_NXTHDR(&msg, header);
}
# arm-poky-linux-musleabi-gcc --sysroot=<...> -Werror -Wconversion -c -o cmsg.o cmsg.c
cmsg.c: In function 'foo':
cmsg.c:10:18: error: unsigned conversion from 'long int' to 'long unsigned int' changes value from '-4' to '4294967292' [-Werror=sign-conversion]
10 | header = CMSG_NXTHDR(&msg, header);
| ^~~~~~~~~~~
cmsg.c:10:18: error: unsigned conversion from 'long int' to 'long unsigned int' changes value from '-4' to '4294967292' [-Werror=sign-conversion]
When replace CMSG_NXTHDR() by the expanded macro code, I get the following errors:
cmsg.c: In function 'foo':
cmsg.c:12:46: error: unsigned conversion from 'long int' to 'long unsigned int' changes value from '-4' to '4294967292' [-Werror=sign-conversion]
12 | (((header)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1)) + sizeof(struct cmsghdr) >= ((unsigned char *)(&msg)->msg_control + (&msg)->msg_controllen) - (unsigned char *)(header) \
| ^
cmsg.c:13:99: error: unsigned conversion from 'long int' to 'long unsigned int' changes value from '-4' to '4294967292' [-Werror=sign-conversion]
13 | ? 0 : (struct cmsghdr *)((unsigned char *)(header) + (((header)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1))));
| ^