tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

zlib builtin bug workaround on NetBSD



It turns out NetBSD has been shipping with a bug in its zconf.h, part
of zlib, that causes certain inline macros -- and potentially function
prototypes -- to be wrong in a way that breaks the build of certain
packages using autoconf on LP32 platforms.

PR lib/59711: "#define HAVE_UNISTD_H 1" breaks 32-bit libz

Specifically, zconf.h has logic that roughly boils down to:

#ifndef z_off_t
#  ifdef HAVE_UNISTD_H
#    define z_off_t	off_t
#  else
#    define z_off_t	long
#  endif
#endif

and similarly for z_ptrdiff_t.

The system library is built with z_off_t=long (i.e., without
HAVE_UNISTD_H), but if you build a program with autoconf defining
HAVE_UNISTD_H, that program will be built with the wrong definition of
z_off_t in various functions and inline macros in zlib.h.

The wrong definition has different size on LP32 platforms.  On
little-endian LP32 platforms, as long as the structure in question is
padded, using off_t (64-bit) where you should use long (32-bit) may
not cause too much trouble because the placement of numbers below 2^32
coincides, but on big-endian LP32 the low bytes are in the wrong place
so things quickly go awry as in the PR.

Of course we'll fix this in NetBSD so that it ignores HAVE_UNISTD_H
and gives the same z_off_t with or without that macro.  But there will
remain a problem with binary packages built against the x.0 release
with the broken zconf.h.  I expect we can work around it in pkgsrc by
putting the following fragment in devel/zlib/builtin.mk (plus an
explanatory comment with references):

.    if ${OPSYS} == "NetBSD" && ${OPSYS_VERSION} < 110000
CPPFLAGS+=	-Dz_off_t=long -Dz_ptrdiff_t=long
CFLAGS+=	-Dz_off_t=long -Dz_ptrdiff_t=long
.    endif

But this will also require rebuilding any packages that were already
built against the builtin zlib -- those packages need to be revbumped.

Thoughts?
From a311c1ba5fafce6316aec8183454e22f345f3d03 Mon Sep 17 00:00:00 2001
From: Taylor R Campbell <riastradh%NetBSD.org@localhost>
Date: Sun, 19 Oct 2025 22:09:29 +0000
Subject: [PATCH] devel/zlib: Work around zconf.h bug in NetBSD.

Even if the zconf.h bug is fixed in NetBSD release branches, we need
to work around this in pkgsrc for netbsd<11 binary package builds
that are made against the x.0 release which doesn't have the fix.

This will also require a revbump of all packages that potentially use
zlib builtin.mk to guarantee it takes effect in incremental package
builds.

PR lib/59711: "#define HAVE_UNISTD_H 1" breaks 32-bit libz
---
 devel/zlib/builtin.mk | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/devel/zlib/builtin.mk b/devel/zlib/builtin.mk
index bab555bf6c23..0c0e21429e0b 100644
--- a/devel/zlib/builtin.mk
+++ b/devel/zlib/builtin.mk
@@ -86,6 +86,15 @@ CHECK_BUILTIN.zlib?=	no
 .if ${CHECK_BUILTIN.zlib:tl} == no
 .  if ${USE_BUILTIN.zlib:tl} == yes
 
+# Work around PR lib/59711: "#define HAVE_UNISTD_H 1" breaks 32-bit
+# libz.  Must be fixed in pkgsrc for binary package builds against x.0
+# releases (e.g., 9.0) because the system header file is wrong.
+# Practically, this probably only affects big-endian LP32 platforms.
+.    if ${OPSYS} == "NetBSD" && ${OPSYS_VERSION} < 110000
+CPPFLAGS+=	-Dz_off_t=long -Dz_ptrdiff_t=long
+CFLAGS+=	-Dz_off_t=long -Dz_ptrdiff_t=long
+.    endif
+
 BUILDLINK_TARGETS+=	fake-zlib-pc
 
 _FAKE_ZLIB_PC=	${BUILDLINK_DIR}/lib/pkgconfig/zlib.pc


Home | Main Index | Thread Index | Old Index