nginx / unit

NGINX Unit - universal web app server - a lightweight and versatile open source server that simplifies the application stack by natively executing application code across eight different programming language runtimes.
https://unit.nginx.org
Apache License 2.0
5.37k stars 323 forks source link

Missing builtins, attributes & atomics with clang on Alpine Linux on armv[78] and riscv64 #942

Closed ac000 closed 1 year ago

ac000 commented 1 year ago
          @ac000 thank you for patch! it allows to [build](https://gitlab.alpinelinux.org/alpine/aports/-/pipelines/178845) meantime exposed issues on armv7 and armv8 and riscv64
checking for GCC __builtin_expect() ... not found
checking for GCC __builtin_unreachable() ... not found
checking for GCC __builtin_prefetch() ... not found
checking for GCC __builtin_clz() ... not found
checking for GCC __builtin_popcount() ... not found
checking for GCC __attribute__ visibility ... not found
checking for GCC __attribute__ aligned ... not found
checking for GCC __attribute__ malloc ... not found
checking for GCC __attribute__ packed ... not found
checking for GCC __attribute__ unused ... not found
checking for GCC builtin atomic operations ... not found
checking for Solaris builtin atomic operations ... not found
checking for xlC builtin atomic operations ... not found
./configure: error: no atomic operations found.

maybe it's related to clang for this arches but at least "GCC" prefix for atomics is confusing when building with clang

Originally posted by @andypost in https://github.com/nginx/unit/issues/936#issuecomment-1708938752

thresheek commented 1 year ago

FWIW I can not reproduce with the same docker image as used on Alpine pipeline linked in https://github.com/nginx/unit/issues/936#issuecomment-1708938752 - running locally on Ubuntu 22.04 aarch64 host.

Output of build/autoconf.err will help.

ac000 commented 1 year ago

@thresheek

Thanks for trying that. There is definitely something very broken in this case, from one of the failed builds

checking for endianness ... not found
checking for int size ... not found
checking for long size ... not found
checking for long long size ... not found
checking for void * size ... not found
checking for size_t size ... not found
checking for off_t size ... not found
checking for time_t size ... not found
checking for C99 variadic macro ... not found
checking for GCC variadic macro ... not found
checking for GCC __builtin_expect() ... not found
checking for GCC __builtin_unreachable() ... not found
checking for GCC __builtin_prefetch() ... not found
checking for GCC __builtin_clz() ... not found
checking for GCC __builtin_popcount() ... not found
checking for GCC __attribute__ visibility ... not found
checking for GCC __attribute__ aligned ... not found
checking for GCC __attribute__ malloc ... not found
checking for GCC __attribute__ packed ... not found
checking for GCC __attribute__ unused ... not found
checking for GCC builtin atomic operations ... not found
checking for Solaris builtin atomic operations ... not found
checking for xlC builtin atomic operations ... not found

Absolutely nothing worked!

@andypost as @thresheek says, if you could post the build/autoconf.err file from one of the failed builds, that may shed some light on the matter.

However it looks like clang is very broken on these systems.

andypost commented 1 year ago

@ac000 here's full log of build env https://gist.github.com/andypost/bfeb0f21637a0a2463c00151eb429e69

ac000 commented 1 year ago

Thanks.

Heh. What's fix-clang.patch?

But it looks like all the tests are failing due to the unknown -fstack-clash-protection option.

checking for endianness
clang-16: error: argument unused during compilation: '-fstack-clash-protection' [-Werror,-Wunused-command-line-argument]

I don't know where that actually comes from. I can't see it set anywhere in Unit. There are other options like -Os which I can't see set in Unit.

As to fstack-clash-protection it looks like it is only implemented on some platforms currently

https://blog.llvm.org/posts/2021-01-05-stack-clash-protection/ https://reviews.llvm.org/D96007

So we need to find where this is coming from.

ac000 commented 1 year ago

On Alpine Linux, this is the command I'm seeing run for these tests...

clang -pipe -fPIC -fvisibility=hidden -O -W -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -fstrict-aliasing -Wstrict-overflow=5 -Wmissing-prototypes -Werror -g -o build/autotest build/autotest.c
andypost commented 1 year ago

Probably builders/CI configured this way, I found other packages using it and now it pass https://gitlab.alpinelinux.org/alpine/aports/-/pipelines/178897

    case "$CARCH" in
    arm*|aarch64|riscv64)
        export CFLAGS="${CFLAGS/-fstack-clash-protection}"
        ;;
    esac
ac000 commented 1 year ago

OK, cool. I'll go ahead and close this then.