mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] musl CMSG_NXTHDR() triggers a -Wsign-compare from Clang
@ 2024-03-29 16:50 Denis Ovsienko
  2024-03-30  2:06 ` Rich Felker
  0 siblings, 1 reply; 3+ messages in thread
From: Denis Ovsienko @ 2024-03-29 16:50 UTC (permalink / raw)
  To: musl

Hello all.

To see how well libpcap compiles with musl libc, I used Alpine Linux
3.19 and noticed that one of the musl headers triggers warnings in
libpcap source, which in development environments tends to use -Werror
because normally it produces no compiler warnings.  The warning in musl
libc <sys/socket.h> becomes a warning in libpcap pcap-bt-linux.c and
fails the build.  The workaround is not difficult, but fixing it in
upstream would make more sense from my point of view.  The problem
reproduces using Clang only.

$ /usr/lib/libc.so
musl libc (x86_64)
Version 1.2.4_git20230717
Dynamic Program Loader
Usage: /usr/lib/libc.so [options] [--] pathname [args]

$ clang --version
Alpine clang version 17.0.5
Target: x86_64-alpine-linux-musl
Thread model: posix
InstalledDir: /usr/bin
Configuration file: /etc/clang17/x86_64-alpine-linux-musl.cfg

$ clang
-fvisibility=hidden -W
-Wall -Wcomma
-Wdocumentation
-Wformat-nonliteral -Wmissing-noreturn -Wmissing-prototypes
-Wmissing-variable-declarations -Wnull-pointer-subtraction
-Wpointer-arith -Wpointer-sign -Wshadow -Wshorten-64-to-32
-Wsign-compare -Wstrict-prototypes -Wundef -Wunreachable-code
-Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-parameter
-Wused-but-marked-unused  -fpic -I.  -I/usr/include/libnl3
-I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include -DBUILDING_PCAP
-Dpcap_EXPORTS -DHAVE_CONFIG_H  -Werror -c ./pcap-bt-linux.c

./pcap-bt-linux.c:373:10: error: comparison of integers of different signs: 'unsigned long' and 'long' [-Werror,-Wsign-compare]
  373 |                 cmsg = CMSG_NXTHDR(&msg, cmsg);
      |                        ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/sys/socket.h:358:44: note: expanded from macro 'CMSG_NXTHDR'
  358 |         __CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= __MHDR_END(mhdr) - (unsigned char *)(cmsg) \
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [Makefile:87: pcap-bt-linux.o] Error 1

-- 
    Denis Ovsienko

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [musl] musl CMSG_NXTHDR() triggers a -Wsign-compare from Clang
  2024-03-29 16:50 [musl] musl CMSG_NXTHDR() triggers a -Wsign-compare from Clang Denis Ovsienko
@ 2024-03-30  2:06 ` Rich Felker
  2024-04-01 15:39   ` James Y Knight
  0 siblings, 1 reply; 3+ messages in thread
From: Rich Felker @ 2024-03-30  2:06 UTC (permalink / raw)
  To: Denis Ovsienko; +Cc: musl

On Fri, Mar 29, 2024 at 04:50:47PM +0000, Denis Ovsienko wrote:
> Hello all.
> 
> To see how well libpcap compiles with musl libc, I used Alpine Linux
> 3.19 and noticed that one of the musl headers triggers warnings in
> libpcap source, which in development environments tends to use -Werror
> because normally it produces no compiler warnings.  The warning in musl
> libc <sys/socket.h> becomes a warning in libpcap pcap-bt-linux.c and
> fails the build.  The workaround is not difficult, but fixing it in
> upstream would make more sense from my point of view.  The problem
> reproduces using Clang only.
> 
> $ /usr/lib/libc.so
> musl libc (x86_64)
> Version 1.2.4_git20230717
> Dynamic Program Loader
> Usage: /usr/lib/libc.so [options] [--] pathname [args]
> 
> $ clang --version
> Alpine clang version 17.0.5
> Target: x86_64-alpine-linux-musl
> Thread model: posix
> InstalledDir: /usr/bin
> Configuration file: /etc/clang17/x86_64-alpine-linux-musl.cfg
> 
> $ clang
> -fvisibility=hidden -W
> -Wall -Wcomma
> -Wdocumentation
> -Wformat-nonliteral -Wmissing-noreturn -Wmissing-prototypes
> -Wmissing-variable-declarations -Wnull-pointer-subtraction
> -Wpointer-arith -Wpointer-sign -Wshadow -Wshorten-64-to-32
> -Wsign-compare -Wstrict-prototypes -Wundef -Wunreachable-code
> -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-parameter
> -Wused-but-marked-unused  -fpic -I.  -I/usr/include/libnl3
> -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include -DBUILDING_PCAP
> -Dpcap_EXPORTS -DHAVE_CONFIG_H  -Werror -c ./pcap-bt-linux.c
> 
> ../pcap-bt-linux.c:373:10: error: comparison of integers of different signs: 'unsigned long' and 'long' [-Werror,-Wsign-compare]
>   373 |                 cmsg = CMSG_NXTHDR(&msg, cmsg);
>       |                        ^~~~~~~~~~~~~~~~~~~~~~~
> /usr/include/sys/socket.h:358:44: note: expanded from macro 'CMSG_NXTHDR'
>   358 |         __CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= __MHDR_END(mhdr) - (unsigned char *)(cmsg) \
>       |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 1 error generated.
> make: *** [Makefile:87: pcap-bt-linux.o] Error 1

This issue has come up serveral times. It's not clear to me why clang
(ang gcc?) fail to suppress this as coming from -isystem. Clearly they
now where the macro was expanded from; it's even in the above message.
If there's no path forward on getting compilers not to do this, maybe
we should look into working around the warning this one time? :/

Rich

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [musl] musl CMSG_NXTHDR() triggers a -Wsign-compare from Clang
  2024-03-30  2:06 ` Rich Felker
@ 2024-04-01 15:39   ` James Y Knight
  0 siblings, 0 replies; 3+ messages in thread
From: James Y Knight @ 2024-04-01 15:39 UTC (permalink / raw)
  To: musl; +Cc: Denis Ovsienko

[-- Attachment #1: Type: text/plain, Size: 1041 bytes --]

On Fri, Mar 29, 2024 at 10:08 PM Rich Felker <dalias@libc.org> wrote:

> It's not clear to me why clang
> (ang gcc?) fail to suppress this as coming from -isystem. Clearly they
> now where the macro was expanded from; it's even in the above message.
>
>
Clang and GCC suppress diagnostics in system headers, but as a general
rule, do not suppress diagnostics arising from expanding macros which were
defined in system headers. There are special cases for some diagnostics,
but this is not one of them in Clang.

As an example with a different diagnostic, the following triggers
-Wincompatible-pointer-types for the definition of "z", but not "y", in
both GCC and Clang:

// System header "test.h"
int yy;
float *y = &yy;
#define FOO float *z = &yy;

// User file "test.c"
#include <test.h>
FOO

If there's no path forward on getting compilers not to do this, maybe
> we should look into working around the warning this one time? :/


 Inserting an explicit cast in the musl macro would seem appropriate here.

[-- Attachment #2: Type: text/html, Size: 1675 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-01 15:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-29 16:50 [musl] musl CMSG_NXTHDR() triggers a -Wsign-compare from Clang Denis Ovsienko
2024-03-30  2:06 ` Rich Felker
2024-04-01 15:39   ` James Y Knight

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).