Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

curl using cmake on arm32 systems build error -Werror=cast-align #13035

Closed
heitbaum opened this issue Mar 3, 2024 · 21 comments
Closed

curl using cmake on arm32 systems build error -Werror=cast-align #13035

heitbaum opened this issue Mar 3, 2024 · 21 comments
Labels

Comments

@heitbaum
Copy link

heitbaum commented Mar 3, 2024

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

@bagder bagder added the build label Mar 3, 2024
@icing
Copy link
Contributor

icing commented Mar 4, 2024

This looks like a wrong compiler warning. struct Curl_cwriter is the first member of struct chunked_writer. Afaik, this is legal C.

@heitbaum
Copy link
Author

heitbaum commented Mar 4, 2024

fyi - it is gcc version 13.2.0 (GCC)

@icing
Copy link
Contributor

icing commented Mar 4, 2024

Hmm, is this the only file where you get those errors? We use the same casting in content_encding.c for some time.

@heitbaum
Copy link
Author

heitbaum commented 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
Copy link
Member

bagder commented Mar 4, 2024

Does this patch silence the warnings? (against current master, might not work cleanly on 8.6.0)

diff --git a/lib/http_chunks.c b/lib/http_chunks.c
index 3236c0e47..c1f5e42f5 100644
--- a/lib/http_chunks.c
+++ b/lib/http_chunks.c
@@ -389,10 +389,21 @@ CURLcode Curl_httpchunk_read(struct Curl_easy *data,
 struct chunked_writer {
   struct Curl_cwriter super;
   struct Curl_chunker ch;
 };
 
+#if defined(__GNUC__)
+/* Ignore cast-align warnings (on 32 bit arm):
+
+   error: cast increases required alignment of target type [-Werror=cast-align]
+        |   struct chunked_writer *ctx = (struct chunked_writer *)writer;
+                                         ^
+ */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-align"
+#endif
+
 static CURLcode cw_chunked_init(struct Curl_easy *data,
                                 struct Curl_cwriter *writer)
 {
   struct chunked_writer *ctx = (struct chunked_writer *)writer;
 
@@ -411,10 +422,14 @@ static void cw_chunked_close(struct Curl_easy *data,
 static CURLcode cw_chunked_write(struct Curl_easy *data,
                                  struct Curl_cwriter *writer, int type,
                                  const char *buf, size_t blen)
 {
   struct chunked_writer *ctx = (struct chunked_writer *)writer;
+#if defined(__GNUC__)
+/* Stop ignoring cast-align warnings */
+#pragma GCC diagnostic pop
+#endif
   CURLcode result;
   size_t consumed;
 
   if(!(type & CLIENTWRITE_BODY))
     return Curl_cwriter_write(data, writer->next, type, buf, blen);

@icing
Copy link
Contributor

icing commented 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
Copy link
Author

heitbaum commented Mar 4, 2024

Does this patch silence the warnings? (against current master, might not work cleanly on 8.6.0)

I have run a full build on all of our targets. This addresses the issue. No warnings or errors - 👍.

@heitbaum
Copy link
Author

heitbaum commented 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?

I’ll try.

@heitbaum
Copy link
Author

heitbaum commented 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
Copy link
Contributor

icing commented Mar 4, 2024

Same here. Do not really understand it. Let's go with @bagder 's proposal.

@bagder
Copy link
Member

bagder commented Mar 4, 2024

I'll turn it into a PR in a sec

bagder added a commit that referenced this issue Mar 5, 2024
Using pragma.

Reported by Rudi Heitbaum
Fixes #13035
@bagder
Copy link
Member

bagder commented Mar 5, 2024

the "sec" became 17 hours 😁

@icing
Copy link
Contributor

icing commented Mar 5, 2024

You are just accelerating too fast now and then, time dilation sets in.

@vszakats
Copy link
Member

vszakats commented 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 x64 x86:

./lib/sendf.c:490:27: warning: cast from 'struct Curl_creader *' to 'struct cr_in_ctx *' increases required alignment from 4 to 8 [-Wcast-align]
  490 |   struct cr_in_ctx *ctx = (struct cr_in_ctx *)reader;
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~
./lib/sendf.c:503:27: warning: cast from 'struct Curl_creader *' to 'struct cr_in_ctx *' increases required alignment from 4 to 8 [-Wcast-align]
  503 |   struct cr_in_ctx *ctx = (struct cr_in_ctx *)reader;
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~
./lib/sendf.c:594:27: warning: cast from 'struct Curl_creader *' to 'struct cr_in_ctx *' increases required alignment from 4 to 8 [-Wcast-align]
  594 |   struct cr_in_ctx *ctx = (struct cr_in_ctx *)reader;
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~    
./lib/sendf.c:790:29: warning: cast from 'struct Curl_creader *' to 'struct cr_in_ctx *' increases required alignment from 4 to 8 [-Wcast-align]
  790 |     struct cr_in_ctx *ctx = (struct cr_in_ctx *)r;      
      |                             ^~~~~~~~~~~~~~~~~~~~~       
4 warnings generated.                                           

edit: this is different code, but the same pattern with a reader (instead of writer), and the same warning.

@icing
Copy link
Contributor

icing commented 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_cwriter and struct Curl_creader a member void *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
Copy link
Member

bagder commented Mar 5, 2024

I'll have them merged before EOD!

@icing
Copy link
Contributor

icing commented Mar 5, 2024

Thanks. Then I'll start that change tomorrow.

@icing
Copy link
Contributor

icing commented Mar 5, 2024

My current explanation for this mess: https://chaos.social/@icing/112043038186968686

icing added a commit to icing/curl that referenced this issue Mar 6, 2024
- `struct Curl_cwriter` and `struct Curl_creader` now carry a
  `void *ctx` member that points to the instance as allocated.
- using `r->ctx` and `w->ctx` as pointer to the instance specific
  struct that has been allocated
- intended to fix curl#13035
@icing
Copy link
Contributor

icing commented Mar 6, 2024

Could you verify that #13059 fixes the issue in your builds? Thanks!

@heitbaum
Copy link
Author

heitbaum commented Mar 6, 2024

Could you verify that #13059 fixes the issue in your builds? Thanks!

Just tested master db5c9f4 with #13059 and #12930 - all built successfully across arm32, aarch64, x86_64

@vszakats
Copy link
Member

vszakats commented 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)

@bagder bagder closed this as completed in 9978d40 Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 participants