Repository navigation
curl using cmake on arm32 systems build error -Werror=cast-align #13035
Copy link
Copy link
Closed
Labels
Description
I did this
build curl using cmake on arm32 systems errors due to http_chunks.c:399:32: error: cast increases required alignment of target type [-Werror=cast-align]. Build on aarch64 and x86_64 build correctly
BUILD curl (target)
TOOLCHAIN cmake (auto-detect)
Executing (target): cmake -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE=/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/toolchain/etc/cmake-armv7ve-libreelec-linux-gnueabihf.conf -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=MinSizeRel -DENABLE_DEBUG=OFF -DCURL_LTO=ON -DCURL_WERROR=ON -DENABLE_CURLDEBUG=OFF -DENABLE_ARES=OFF -DCURL_DISABLE_HTTP=OFF -DCURL_DISABLE_FTP=OFF -DCURL_DISABLE_FILE=OFF -DCURL_DISABLE_LDAP=ON -DCURL_DISABLE_LDAPS=ON -DCURL_DISABLE_RTSP=OFF -DCURL_DISABLE_PROXY=OFF -DCURL_DISABLE_DICT=ON -DCURL_DISABLE_TELNET=ON -DCURL_DISABLE_TFTP=ON -DCURL_DISABLE_POP3=ON -DCURL_DISABLE_IMAP=ON -DCURL_DISABLE_SMB=ON -DCURL_DISABLE_SMTP=ON -DCURL_DISABLE_GOPHER=ON -DCURL_DISABLE_MQTT=ON -DENABLE_MANUAL=OFF -DENABLE_IPV6=ON -DENABLE_THREADED_RESOLVER=ON -DCURL_DISABLE_VERBOSE_STRINGS=OFF -DCURL_WINDOWS_SSPI=OFF -DCURL_DISABLE_COOKIES=OFF -DCURL_HIDDEN_SYMBOLS=ON -DCURL_USE_GSSAPI=OFF -DUSE_ZLIB=ON -DCURL_BROTLI=OFF -DCURL_ZSTD=OFF -DRANDOM_FILE=/dev/urandom -DCURL_USE_GNUTLS=OFF -DCURL_ENABLE_SSL=ON -DCURL_USE_MBEDTLS=OFF -DCURL_CA_BUNDLE=/run/libreelec/cacert.pem -DCURL_CA_PATH=none -DCURL_USE_LIBPSL=OFF -DCURL_USE_LIBSSH2=OFF -DUSE_LIBRTMP=ON -DUSE_LIBIDN2=ON -DUSE_NGHTTP2=ON /var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/curl-8.6.0
-- Using CMake version 3.28.3
-- curl version=[8.6.0]
-- Picky compiler options: -pedantic-errors -W -Wall -pedantic -Wbad-function-cast -Wconversion -Winline -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wno-long-long -Wno-multichar -Wpointer-arith -Wshadow -Wsign-compare -Wundef -Wunused -Wwrite-strings -Waddress -Wattributes -Wcast-align -Wdeclaration-after-statement -Wdiv-by-zero -Wempty-body -Wendif-labels -Wfloat-equal -Wformat-security -Wignored-qualifiers -Wmissing-field-initializers -Wmissing-noreturn -Wno-format-nonliteral -Wno-system-headers -Wold-style-definition -Wredundant-decls -Wsign-conversion -Wno-error=sign-conversion -Wstrict-prototypes -Wtype-limits -Wunreachable-code -Wunused-parameter -Wvla -Wclobbered -Wmissing-parameter-type -Wold-style-declaration -Wstrict-aliasing=3 -Wtrampolines -Wformat=2 -Warray-bounds=2 -ftree-vrp -Wduplicated-cond -Wnull-dereference -fdelete-null-pointer-checks -Wshift-negative-value -Wshift-overflow=2 -Walloc-zero -Wduplicated-branches -Wformat-overflow=2 -Wformat-truncation=2 -Wimplicit-fallthrough -Wrestrict -Warith-conversion -Wdouble-promotion -Wenum-conversion -Wpragmas -Wunused-const-variable
CMake Warning at CMake/Macros.cmake:96 (message):
Found no *nroff program
Call Stack (most recent call first):
CMakeLists.txt:315 (curl_nroff_check)
CMake Warning at CMakeLists.txt:321 (message):
Perl not found, or nroff not useful. Will not build manuals.
-- LTO supported and enabled
-- Enabled features: SSL IPv6 UnixSockets libz AsynchDNS IDN Largefile alt-svc HSTS NTLM TLS-SRP HTTP2 HTTPS-proxy threadsafe
-- Enabled protocols: FILE FTP FTPS HTTP HTTPS IPFS IPNS RTMP RTSP
-- Enabled SSL backends: OpenSSL
-- Configuring done (0.1s)
-- Generating done (0.2s)
-- Build files have been written to: /var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/curl-8.6.0/.armv7ve-libreelec-linux-gnueabihf
Executing (target): ninja
[25/80] Building C object lib/CMakeFiles/libcurl_shared.dir/http_chunks.c.o
FAILED: lib/CMakeFiles/libcurl_shared.dir/http_chunks.c.o
/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/toolchain/bin/armv7ve-libreelec-linux-gnueabihf-gcc -DBUILDING_LIBCURL -DCURL_HIDDEN_SYMBOLS -DHAVE_CONFIG_H -Dlibcurl_shared_EXPORTS -I/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/curl-8.6.0/include -I/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/curl-8.6.0/.armv7ve-libreelec-linux-gnueabihf/lib/../include -I/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/curl-8.6.0/lib/.. -I/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/curl-8.6.0/lib/../include -I/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/curl-8.6.0/.armv7ve-libreelec-linux-gnueabihf/lib/.. -I/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/curl-8.6.0/lib -I/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/curl-8.6.0/.armv7ve-libreelec-linux-gnueabihf/lib -march=armv7ve -mtune=cortex-a7 -mabi=aapcs-linux -Wno-psabi -Wa,-mno-warn-deprecated -mfloat-abi=hard -mfpu=neon-vfpv4 -Wall -pipe -O2 -fomit-frame-pointer -DNDEBUG -pedantic-errors -W -Wall -pedantic -Wbad-function-cast -Wconversion -Winline -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wno-long-long -Wno-multichar -Wpointer-arith -Wshadow -Wsign-compare -Wundef -Wunused -Wwrite-strings -Waddress -Wattributes -Wcast-align -Wdeclaration-after-statement -Wdiv-by-zero -Wempty-body -Wendif-labels -Wfloat-equal -Wformat-security -Wignored-qualifiers -Wmissing-field-initializers -Wmissing-noreturn -Wno-format-nonliteral -Wno-system-headers -Wold-style-definition -Wredundant-decls -Wsign-conversion -Wno-error=sign-conversion -Wstrict-prototypes -Wtype-limits -Wunreachable-code -Wunused-parameter -Wvla -Wclobbered -Wmissing-parameter-type -Wold-style-declaration -Wstrict-aliasing=3 -Wtrampolines -Wformat=2 -Warray-bounds=2 -ftree-vrp -Wduplicated-cond -Wnull-dereference -fdelete-null-pointer-checks -Wshift-negative-value -Wshift-overflow=2 -Walloc-zero -Wduplicated-branches -Wformat-overflow=2 -Wformat-truncation=2 -Wimplicit-fallthrough -Wrestrict -Warith-conversion -Wdouble-promotion -Wenum-conversion -Wpragmas -Wunused-const-variable -Werror -DDUMMYOPT -fPIC -fvisibility=hidden -MD -MT lib/CMakeFiles/libcurl_shared.dir/http_chunks.c.o -MF lib/CMakeFiles/libcurl_shared.dir/http_chunks.c.o.d -o lib/CMakeFiles/libcurl_shared.dir/http_chunks.c.o -c /var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/curl-8.6.0/lib/http_chunks.c
/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/curl-8.6.0/lib/http_chunks.c: In function 'cw_chunked_init':
/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/curl-8.6.0/lib/http_chunks.c:389:32: error: cast increases required alignment of target type [-Werror=cast-align]
389 | struct chunked_writer *ctx = (struct chunked_writer *)writer;
| ^
/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/curl-8.6.0/lib/http_chunks.c: In function 'cw_chunked_close':
/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/curl-8.6.0/lib/http_chunks.c:399:32: error: cast increases required alignment of target type [-Werror=cast-align]
399 | struct chunked_writer *ctx = (struct chunked_writer *)writer;
| ^
/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/curl-8.6.0/lib/http_chunks.c: In function 'cw_chunked_write':
/var/media/DATA/home-rudi/LibreELEC.kernel11/build.LibreELEC-RPi2.arm-12.0-devel/build/curl-8.6.0/lib/http_chunks.c:407:32: error: cast increases required alignment of target type [-Werror=cast-align]
407 | struct chunked_writer *ctx = (struct chunked_writer *)writer;
| ^
cc1: all warnings being treated as errors
[40/80] Building C object lib/CMakeFiles/libcurl_shared.dir/vtls/openssl.c.o
ninja: build stopped: subcommand failed.
I expected the following
Successful compile
curl/libcurl version
curl 8.6.0
operating system
LibreELEC HEAD
Reactions are currently unavailable
Activity
icing commentedon Mar 4, 2024
This looks like a wrong compiler warning.
struct Curl_cwriteris the first member ofstruct chunked_writer. Afaik, this is legal C.heitbaum commentedon Mar 4, 2024
fyi - it is
gcc version 13.2.0 (GCC)icing commentedon Mar 4, 2024
Hmm, is this the only file where you get those errors? We use the same casting in
content_encding.cfor some time.heitbaum commentedon Mar 4, 2024
I just tested with
CFLAGS+=" -Wno-error=cast-align"and it is only those 3 lines that error/warn. And the errors only happen on the arm32 bit build. The aarch64 and x86_64 builds are clean with no errors.bagder commentedon Mar 4, 2024
Does this patch silence the warnings? (against current master, might not work cleanly on 8.6.0)
icing commentedon Mar 4, 2024
We could reorder the struct to move the
char *'s to later, should that help. But I am unable to verify this.@heitbaum could you test if it helps to reshuffle the members in
struct Curl_cwriter?heitbaum commentedon Mar 4, 2024
I have run a full build on all of our targets. This addresses the issue. No warnings or errors - 👍.
heitbaum commentedon Mar 4, 2024
I’ll try.
heitbaum commentedon Mar 4, 2024
I’ve had a look, and don’t think it is the struct itself? I tried with char align[] with no success.. Might be wrong. Is it the pointer? The pointer is 4 bytes on arm32 and 8 on aarch64/x86_64.
Curl_cwriter is 12 bytes on arm32 and 24 or x86_64
chunked_writer would be 12+(16+28) or 24+(28+36) I think..
I’m not sure I understand fully the passing in the pointer to Curl_cwriter and casting it to the chunked_writer pointer.
im a bit confused now.
icing commentedon Mar 4, 2024
Same here. Do not really understand it. Let's go with @bagder 's proposal.
bagder commentedon Mar 4, 2024
I'll turn it into a PR in a sec
http_chunks: disable a cast-align gcc warning on 32 bit arm
bagder commentedon Mar 5, 2024
the "sec" became 17 hours 😁
icing commentedon Mar 5, 2024
You are just accelerating too fast now and then, time dilation sets in.
vszakats commentedon Mar 5, 2024
This isn't limited to gcc or arm32. llvm/clang 17.0.6 also complains, e.g. in this case for Windows
x64x86:edit: this is different code, but the same pattern with a reader (instead of writer), and the same warning.
icing commentedon Mar 5, 2024
Ok, it's time to rethink this way of casting. We started this in content_encoding.c ages ago, but modern compilers and arch do not seem to like that.
I will make a PR to change that, given
struct Curl_cwriterandstruct Curl_creadera membervoid *ctx, similar to what we use in connection filters.@bagder any intent to merge #13026 and #13039 soon? I'd like to do the rework on top of that to avoid rebasing.
bagder commentedon Mar 5, 2024
I'll have them merged before EOD!
icing commentedon Mar 5, 2024
Thanks. Then I'll start that change tomorrow.
icing commentedon Mar 5, 2024
My current explanation for this mess: https://chaos.social/@icing/112043038186968686
client reader/writer, ctx casting
icing commentedon Mar 6, 2024
Could you verify that #13059 fixes the issue in your builds? Thanks!
heitbaum commentedon Mar 6, 2024
Just tested master db5c9f4 with #13059 and #12930 - all built successfully across arm32, aarch64, x86_64
vszakats commentedon Mar 6, 2024
#13059 fixed my build case. (it wasn't x64, but x86, just noticed it now, but Windows and llvm/clang 17 it is)
lib: add `void *ctx` to reader/writer instances