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

-Wdeprecated-non-prototype warning in musl's dlstart.c with zig cc main.c -target aarch64-linux-musl #13385

Closed
alexrp opened this issue Nov 1, 2022 · 8 comments · Fixed by #20921
Labels
bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. upstream An issue with a third party project that Zig uses.
Milestone

Comments

@alexrp
Copy link
Member

alexrp commented Nov 1, 2022

Zig Version

0.10.0

Steps to Reproduce and Observed Behavior

$ cat main.c
#include <stdio.h>

int main()
{
    printf("Hello World\n");
}
$ zig cc main.c -target aarch64-linux-musl
In file included from /home/alexrp/sysroot/lib/zig/lib/libc/musl/crt/rcrt1.c:3:
/home/alexrp/sysroot/lib/zig/lib/libc/musl/crt/../ldso/dlstart.c:146:20: warning: a function declaration without a prototype is deprecated in all versions of C and is treated as a zero-parameter prototype in C2x, conflicting with a subsequent definition [-Wdeprecated-non-prototype]
        GETFUNCSYM(&dls2, __dls2, base+dyn[DT_PLTGOT]);
                          ^
/home/alexrp/sysroot/lib/zig/lib/libc/musl/crt/rcrt1.c:11:13: note: conflicting prototype is here
hidden void __dls2(unsigned char *base, size_t *sp)
            ^
1 warning generated.

Also happens for arm-linux-musleabihf.

This did not occur in 0.9.1.

Expected Behavior

No warning.

@alexrp alexrp added the bug Observed behavior contradicts documented or intended behavior label Nov 1, 2022
@ehaas
Copy link
Contributor

ehaas commented Nov 1, 2022

This is due to the switch to clang 15 for Zig 0.10.0, since support for old-style (K&R) function declarations is being removed: https://discourse.llvm.org/t/rfc-enabling-wstrict-prototypes-by-default-in-c/60521

You can manually disable it with -Wno-deprecated-non-prototype, otherwise it will have to be fixed upstream in musl.

@Vexu Vexu added the upstream An issue with a third party project that Zig uses. label Nov 1, 2022
@Vexu Vexu added this to the 0.11.0 milestone Nov 1, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.10.1 Nov 2, 2022
@andrewrk andrewrk added the contributor friendly This issue is limited in scope and/or knowledge of Zig internals. label Nov 2, 2022
@sylr
Copy link

sylr commented Nov 9, 2022

Got the same thing using zig as CC for a golang crossbuild:

CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC="zig cc -target aarch64-linux" CXX="zig c++ -target aarch64-linux" /opt/homebrew/bin/go build -tags ,crossbuild -trimpath -ldflags '-s -w -X sylr.dev/fix/cmd.Version=c3ca56c-dirty -extldflags ""' -o dist/fix-c3ca56c-dirty-linux-arm64
# sylr.dev/fix
In file included from /opt/homebrew/Cellar/zig/0.10.0/lib/zig/libc/musl/crt/rcrt1.c:3:
/opt/homebrew/Cellar/zig/0.10.0/lib/zig/libc/musl/crt/../ldso/dlstart.c:146:20: warning: a function declaration without a prototype is deprecated in all versions of C and is treated as a zero-parameter prototype in C2x, conflicting with a subsequent definition [-Wdeprecated-non-prototype]
        GETFUNCSYM(&dls2, __dls2, base+dyn[DT_PLTGOT]);
                          ^
/opt/homebrew/Cellar/zig/0.10.0/lib/zig/libc/musl/crt/rcrt1.c:11:13: note: conflicting prototype is here
hidden void __dls2(unsigned char *base, size_t *sp)
            ^
1 warning generated.

Reproducing steps:

mkdir -p ~/git && (cd ~/git && git clone https://github.com/sylr/fix)
cd git/fix
make crossbuild

@markus-oberhumer
Copy link
Contributor

Would this issue get fixed by upgrading to musl 1.2.5 ?

@alexrp
Copy link
Member Author

alexrp commented Jun 17, 2024

Would this issue get fixed by upgrading to musl 1.2.5 ?

Doesn't seem to be the case. This will need an upstream patch.

@alexrp
Copy link
Member Author

alexrp commented Jun 17, 2024

That said, it's not actually obvious to me what the patch should be.

https://git.musl-libc.org/cgit/musl/tree/ldso/dlstart.c?id=6f3ead0ae16deb9f0004b275e29a276c9712ee3c#n14

This GETFUNCSYM definition is a fallback for when an architecture doesn't provide a definition with inline assembly. Short of passing the whole function signature into the macro, I'm not sure how else it could be written to avoid that warning. Suppressing the warning is probably not desirable (there seems to be no precedent for this in musl).

@alexrp
Copy link
Member Author

alexrp commented Jul 28, 2024

For whatever reason, I'm just completely unable to reproduce this outside the context of Zig's own musl build logic:

$ zig cc --version
clang version 18.1.6
$ ./configure --target=aarch64-linux-gnu CC="zig cc" CFLAGS="-target aarch64-linux -Wall -Wextra -Werror"
$ make -j
$ make clean
$ clang --version
Ubuntu clang version 16.0.6
$ ./configure --target=aarch64-linux-gnu CC=clang CFLAGS="--target=aarch64-linux-gnu -Wall -Wextra -Werror"
$ make -j
$ make clean
$ /opt/llvm/bin/clang --version
clang version 18.1.8
$ ./configure --target=aarch64-linux-gnu CC=/opt/llvm/bin/clang CFLAGS="--target=aarch64-linux-gnu -Wall -Wextra -Werror"
$ make -j

They all build successfully. At this point, I strongly suspect the bug is actually on the Zig side somehow.

@markus-oberhumer
Copy link
Contributor

@alexrp

This is might be because musl configure disables warnings with -w when building with clang.

Try the diff below and run something like CC="clang" CFLAGS="-std=c17 -Werror=deprecated-non-prototype" ../../musl-1.2.5/configure. This should now fail.

$ git diff
diff --git a/configure b/configure
index bc9fbe48..c0fdeffe 100755
--- a/configure
+++ b/configure
@@ -534,7 +534,7 @@ fi
 # to start from a clean slate. So use -w if building with clang. Also
 # turn off a common on-by-default cast warning regardless of compiler.
 #
-test "$cc_family" = clang && tryflag CFLAGS_AUTO -w
+#### test "$cc_family" = clang && tryflag CFLAGS_AUTO -w

 tryflag CFLAGS_AUTO -Wno-pointer-to-int-cast

@alexrp
Copy link
Member Author

alexrp commented Aug 3, 2024

@markus-oberhumer thank you, that's super helpful! I hadn't spotted that. This means we just need to adjust our CFLAGS when building musl to use the same warning settings as upstream. So it was indeed on the Zig side. 🙂

alexrp added a commit to alexrp/zig that referenced this issue Aug 3, 2024
This is what upstream's configure does.

Previously, we only disabled warnings in some musl compilations, with `rcrt1.o`
notably being one for which we didn't. This resulted in a warning in `dlstart.c`
which is included in `rcrt1.c`. So let's just be consistent and disable warnings
for all musl code.

Closes ziglang#13385.
igor84 pushed a commit to igor84/zig that referenced this issue Aug 11, 2024
This is what upstream's configure does.

Previously, we only disabled warnings in some musl compilations, with `rcrt1.o`
notably being one for which we didn't. This resulted in a warning in `dlstart.c`
which is included in `rcrt1.c`. So let's just be consistent and disable warnings
for all musl code.

Closes ziglang#13385.
SammyJames pushed a commit to SammyJames/zig that referenced this issue Aug 13, 2024
This is what upstream's configure does.

Previously, we only disabled warnings in some musl compilations, with `rcrt1.o`
notably being one for which we didn't. This resulted in a warning in `dlstart.c`
which is included in `rcrt1.c`. So let's just be consistent and disable warnings
for all musl code.

Closes ziglang#13385.
Rexicon226 pushed a commit to Rexicon226/zig that referenced this issue Aug 13, 2024
This is what upstream's configure does.

Previously, we only disabled warnings in some musl compilations, with `rcrt1.o`
notably being one for which we didn't. This resulted in a warning in `dlstart.c`
which is included in `rcrt1.c`. So let's just be consistent and disable warnings
for all musl code.

Closes ziglang#13385.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. upstream An issue with a third party project that Zig uses.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants