Skip to content

flake.nix: compile zlibLto with -nostdlib#58

Merged
CyberShadow merged 1 commit into
CyberShadow:masterfrom
hmenke:errno
May 6, 2026
Merged

flake.nix: compile zlibLto with -nostdlib#58
CyberShadow merged 1 commit into
CyberShadow:masterfrom
hmenke:errno

Conversation

@hmenke
Copy link
Copy Markdown
Contributor

@hmenke hmenke commented Mar 11, 2026

This has suddently started failing when building on NixOS 25.11.

gzread.c:24:5: error: use of undeclared identifier 'errno'
   24 |     errno = 0;
      |     ^~~~~
gzread.c:36:13: error: use of undeclared identifier 'errno'
   36 |         if (errno == EAGAIN || errno == EWOULDBLOCK) {
      |             ^~~~~
gzread.c:36:22: error: use of undeclared identifier 'EAGAIN'
   36 |         if (errno == EAGAIN || errno == EWOULDBLOCK) {
      |                      ^~~~~~
gzread.c:36:32: error: use of undeclared identifier 'errno'
   36 |         if (errno == EAGAIN || errno == EWOULDBLOCK) {
      |                                ^~~~~
gzread.c:36:41: error: use of undeclared identifier 'EWOULDBLOCK'
   36 |         if (errno == EAGAIN || errno == EWOULDBLOCK) {
      |                                         ^~~~~~~~~~~
5 errors generated.

@CyberShadow
Copy link
Copy Markdown
Owner

started failing

I don't understand how this can be possible. We pin our Flake inputs..?

Do you mean if you update the Flake inputs to use the latest nixpkgs?

@hmenke
Copy link
Copy Markdown
Contributor Author

hmenke commented Mar 11, 2026

Sorry, I guess I should have mentioned that I override the flake input like so

nix build .#btdu-static-x86_64 --override-input nixpkgs "github:NixOS/nixpkgs/nixos-25.11"

@CyberShadow
Copy link
Copy Markdown
Owner

Thanks. This seems like an upstream bug, have you checked if it has been reported to zlib? Do other projects apply similar patches?

@hmenke
Copy link
Copy Markdown
Contributor Author

hmenke commented Mar 11, 2026

zlib blames the builder (madler/zlib#1126) and indeed I can see a build failure in configure.log

=== ztest30.c ===
#include <string.h>
#include <errno.h>
int main() { return strlen(strerror(errno)); }
===
/nix/store/zq0z7g2s1jnks1995nmp8ii6lp0xh6wq-clang-21.1.7/bin/clang --target=x86_64-unknown-linux-musl -isystem /nix/store/4vdrxsxq45rw02pmxizrzqpl67kjfl4v-musl-static-x86_64-unknown-linux-musl-1.2.5-dev/include -flto=thin -O2 -U_FORTIFY_SOURCE -w -fPIC -D_LARGEFILE64_SOURCE=1 -fuse-ld=lld -L/nix/store/6z8maf3yjcz2cm5m0fvrj15h3gn14i1x-musl-static-x86_64-unknown-linux-musl-1.2.5/lib -o ztest30 ztest30.c
ld.lld: error: cannot open Scrt1.o: No such file or directory
ld.lld: error: cannot open crti.o: No such file or directory
ld.lld: error: cannot open crtbeginS.o: No such file or directory
ld.lld: error: unable to find library -lgcc
ld.lld: error: unable to find library -lgcc_s
ld.lld: error: unable to find library -lgcc
ld.lld: error: unable to find library -lgcc_s
ld.lld: error: cannot open crtendS.o: No such file or directory
ld.lld: error: cannot open crtn.o: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
(exit code 1)
Checking for strerror... No.

@hmenke
Copy link
Copy Markdown
Contributor Author

hmenke commented Mar 11, 2026

Okay, the actual problem is that the compiler as it's configured currently cannot compile any executable. Attempting to compile a file with just an empty main in the Nix sandbox

echo "int main() {}" > test.c
$CC $CFLAGS -o test test.c $LDFLAGS

fails with

ld.lld: error: cannot open Scrt1.o: No such file or directory
ld.lld: error: cannot open crti.o: No such file or directory
ld.lld: error: cannot open crtbeginS.o: No such file or directory
ld.lld: error: unable to find library -lgcc
ld.lld: error: unable to find library -lgcc_s
ld.lld: error: unable to find library -lgcc
ld.lld: error: unable to find library -lgcc_s
ld.lld: error: cannot open crtendS.o: No such file or directory
ld.lld: error: cannot open crtn.o: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)

@CyberShadow
Copy link
Copy Markdown
Owner

Makes sense, the setup is pretty much only to support the specific cross build we need, so regular program compilation might be broken, but maybe we should fix that to make configure happy.

@hmenke
Copy link
Copy Markdown
Contributor Author

hmenke commented Mar 11, 2026

This seems to work.

diff --git a/flake.nix b/flake.nix
index 7c7eb1b..406509e 100644
--- a/flake.nix
+++ b/flake.nix
@@ -144,7 +144,7 @@
               configurePhase = ''
                 # Use musl headers and disable glibc's FORTIFY_SOURCE
                 # Note: -w suppresses all warnings, needed because zlib's configure checks for any stderr output
-                export CC="${pkgs.llvmPackages.clang-unwrapped}/bin/clang --target=${targetTriple}"
+                export CC="${pkgs.llvmPackages.clang-unwrapped}/bin/clang --target=${targetTriple} -nostdlib"
                 export AR="${pkgs.llvmPackages.bintools-unwrapped}/bin/llvm-ar"
                 export RANLIB="${pkgs.llvmPackages.bintools-unwrapped}/bin/llvm-ranlib"
                 export CFLAGS="-isystem ${muslLibc.dev}/include -flto=thin -O2 -U_FORTIFY_SOURCE -w"

@hmenke hmenke changed the title Inject missing #include <errno.h> into zlib flake.nix: compile zlibLto with -nostdlib May 6, 2026
@hmenke
Copy link
Copy Markdown
Contributor Author

hmenke commented May 6, 2026

I have now updated this Pull Request to use the change that I have proposed above to make configure happy.

@CyberShadow CyberShadow merged commit 8b6e9b0 into CyberShadow:master May 6, 2026
4 checks passed
@hmenke hmenke deleted the errno branch May 6, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants