Opened 8 months ago

Closed 8 months ago

#2534 closed defect (wontfix)

Build error with clang 16 on Alpine

Reported by: kenballus@… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.25.x
Keywords: Cc: kenballus@…
uname -a: Linux 7c234f30133d 6.4.11-arch2-1 #1 SMP PREEMPT_DYNAMIC Sat, 19 Aug 2023 15:38:34 +0000 x86_64 Linux
nginx -V: Does not apply, since the issue is with the build.

If I build with gcc, then the output of nginx -V looks like this:
"""
built by gcc 12.2.1 20220924 (Alpine 12.2.1_git20220924-r10)
configure arguments:
"""

Description (last modified by kenballus@…)

Nginx's current default branch (revision hash 44536076405cf79ebdd82a6a0ab27bb3aed86b04) fails to build with clang on Alpine Linux because of Werror and Wsign-compare.

Steps to reproduce:

  1. Get a fresh Alpine Linux container:

docker run --rm --workdir /repro -it alpine:3.18.0

  1. Get dependencies:

apk add mercurial clang musl-dev pcre-dev zlib-dev make

  1. Clone nginx:

hg clone "https://hg.nginx.org/nginx"

  1. Configure:

cd nginx && ./auto/configure --with-cc=clang

  1. Try to build:

make

  1. Observe the warning->error that halts the build:
    make -f objs/Makefile
    make[1]: Entering directory '/repro/nginx'
    ...
    clang -c -pipe  -O -Wall -Wextra -Wpointer-arith -Wconditional-uninitialized -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/event/quic -I src/os/unix -I objs \
    	-o objs/src/event/ngx_event_udp.o \
    	src/event/ngx_event_udp.c
    src/event/ngx_event_udp.c:143:25: error: comparison of integers of different signs: 'unsigned long' and 'long' [-Werror,-Wsign-compare]
                     cmsg = CMSG_NXTHDR(&msg, cmsg))
                            ^~~~~~~~~~~~~~~~~~~~~~~
    /usr/include/sys/socket.h:358:44: note: expanded from macro 'CMSG_NXTHDR'
            __CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= __MHDR_END(mhdr) - (unsigned char *)(cmsg) \
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1 error generated.
    make[1]: *** [objs/Makefile:641: objs/src/event/ngx_event_udp.o] Error 1
    make[1]: Leaving directory '/repro/nginx'
    make: *** [Makefile:10: build] Error 2
    

The build succeeds with GCC 12.2.1 on Alpine, and with clang 16 on Debian. It's only clang 16 on Alpine that fails.

Change History (2)

comment:1 by kenballus@…, 8 months ago

Description: modified (diff)

comment:2 by Maxim Dounin, 8 months ago

Resolution: wontfix
Status: newclosed

That's a known issue with clang and musl, see here:

https://www.openwall.com/lists/musl/2016/10/10/1

I don't think we can/should try to fix this. This is an obvious issue in the system headers, which a) should be fixed in the system headers, not in nginx, and b) shouldn't be reported by compiler at all.

An obvious workaround on nginx side is to use --with-cc-opt="-Wno-error".

Note: See TracTickets for help on using tickets.