Opened 4 years ago

Closed 4 years ago

#2166 closed defect (wontfix)

Nginx-1.20.0 fails to build using clang 12.0.0 public release

Reported by: debohman@… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.19.x
Keywords: Cc: debohman@…
uname -a: Darwin kane.local 16.7.0 Darwin Kernel Version 16.7.0: Tue Jan 30 11:27:06 PST 2018; root:xnu-3789.73.11~1/RELEASE_X86_64 x86_64
nginx -V: nginx version: nginx/1.20.0
built by clang 12.0.0
built with OpenSSL 1.1.1k 25 Mar 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --with-threads --with-http_ssl_module --with-http_v2_module --with-cc-opt='-I /usr/local/include' --with-ld-opt='-L /usr/local/lib'

Description

The issue is the fact that -Werror is turned on, and the following warning is generated by the build:

src/os/unix/ngx_channel.c:26:25: warning: variable length array folded to constant array as an extension [-Wgnu-folding-constant]

char space[CMSG_SPACE(sizeof(int))];


src/os/unix/ngx_channel.c:106:25: warning: variable length array folded to constant array as an extension [-Wgnu-folding-constant]

char space[CMSG_SPACE(sizeof(int))];


Change History (5)

comment:1 by Sergey Kandaurov, 4 years ago

This looks like due to a defective __DARWIN_ALIGN32 macro used to implement CMSG_SPACE in Darwin. It contains some integer to pointer to integer cast magic that pops with -Wgnu-folding-constant.
In contrast, a similar macro in FreeBSD looks less fragile.

This breaks compilation on macOS, coupled with -Wgnu-folding-constant, which seems to be enabled by default in clang 12 though doesn't seem to be reflected in relnotes. The most close review I could find is https://reviews.llvm.org/D89523.
It is similarly broken on macOS if compiled on a previous clang release with -Wgnu-folding-constant.

For the record, a possible way to suppress warnings is to redefine CMSG_SPACE similar to a broken CMSG_DATA macro on FreeBSD 3.x.

comment:2 by debohman@…, 4 years ago

Perhaps -Wno-gnu-folding-constant on Darwin, similar to the existing -Wno-deprecated-declarations?

Version 0, edited 4 years ago by debohman@… (next)

comment:3 by Maxim Dounin, 4 years ago

Given that it is macOS issue which is only triggered by using clang 12.0, which is not the default, I would rather suggest to use ./configure --with-cc-opt="-Wno-gnu-folding-constant" when needed. Likely this will be fixed before clang 12.0 will become the default in macOS.

Last edited 4 years ago by Maxim Dounin (previous) (diff)

comment:4 by Sergey Kandaurov, 4 years ago

For the record, __DARWIN_ALIGN32 definitely seems to be (already) fixed in MacOSX11.1.sdk.

Last edited 4 years ago by Sergey Kandaurov (previous) (diff)

comment:5 by Maxim Dounin, 4 years ago

Resolution: wontfix
Status: newclosed

Just updated my xcode command-line tools, and can confirm that building with most recent MacOSX11.3.sdk works fine, as well as MacOSX11.1.sdk. Provided MacOSX10.15.sdk triggers the warning, but only with -Wgnu-folding-constant, since the clang 12.0.5 provided by Apple does not have this warning enabled by default.

Overall, this looks already fixed by Apple. If you want to use clang 12, consider updating to a newer SDK. Alternatively, use --with-cc-opt="-Wno-gnu-folding-constant" as suggested in comment:3.

Note: See TracTickets for help on using tickets.