Page MenuHomeFreeBSD

Allow Kernel to link in both legacy libkern/zlib and new sys/contrib/zlib.

Authored by delphij on Mar 26 2019, 2:43 AM.



The 1st large review have been separated into multiple pieces based on modules and functionalities.

This change-set updates the kernel to link both old and new ZLIB versions so that we can migrate one component at a time.

I created sys/dev/zlib directory to have some std compatible header files, also place kernel module C file, and kernel versions memory allocation functions like zcalloc, zcfree and few others.

Test Plan

% make buildkernel

Diff Detail

rS FreeBSD src repository
Lint OK
No Unit Test Coverage
Build Status
Buildable 25628
Build 24222: arc lint + arc unit

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes

Added sys/contrib/zlib/crc32.c to zlib kernel module.

delphij requested changes to this revision.Jul 1 2019, 4:40 PM
delphij added inline comments.

The two additional -D's are only specified for zutil.c for sys/modules/zlib ( version of ZLIB_CFLAGS don't have these). Since the sys/conf/files already have them, should they be removed here?

1 ↗(On Diff #59136)

I still prefer a way to not use these "fake" headers (I can't really work on this until mid-July but will take a look as soon as I can).


I think the probes needs to match their definitions? (Also, is there some specific reason not to convert this to use new zlib?)

This revision now requires changes to proceed.Jul 1 2019, 4:40 PM

The extra flags will be changed for Z_SOLO.

1 ↗(On Diff #59136)

We can delay this action by using -DZ_SOLO. ZFS needs non Z_SOLO zlib and we can revisit that time.


The probes need to be matching ABI, the binary symbol.
I can put cryptodefate changes together.
One of suggestion was break one large changeset into smaller ones; this one looks better be a part of this one to avoid changing probe names.

Use -DZ_SOLO to avoid standard C header files.
ZFS requires Non-Z_SOLO ZLIB and we will revisit when we work on ZFS.
Combined opencrypto conversion to avoid dtrace probe name changes.

Drop -DMY_ZCALLOC as no use under -DZ_SOLO.

Drop -DMY_ZCALLOC from but put zcfree() back.

Missed zcallc.h/c files from last update.

I had missed zcalloc.c in sys/modules/Makefile, too.

Drop NO_GZIP compile option changes in zlib as these aren't necessary at this stage.

Thanks! This looks mostly good to me. I intend to commit this version with some minor tweaks after some testing in a day or two, so please yell if you don't agree with some change proposals (commented inline).


This seems to be my bad (rS206708 derived from vendor 7147f24cd7b27dd95f6e841851a111cb311a9c07).

Initially, in rS205306, we #if 0'ed Z_HAVE_UNISTD_H, which used to determine if we would include sys/types.h. Later, the upstream have decided to include it for all platforms, and sys/types.h was included again, so when upgrading zlib I have decided to just take it and removed the include below, right before our hardcoded configuration.

May I ask a favor that we revert the change here to vendor version, and instead, add a block of:

#ifdef Z_SOLO
#  include <sys/types.h>      /* for off_t */

under "This is hard-configured for FreeBSD." so we keep the local changes together? Potentially, that would make it easier for future upgrades.


the new line before crypto_zalloc() is not necessary.


[OPTIONAL] Personally I'd remove the variable names in prototype definition. Alternatively, you can move these functions' bodies here because these are static functions.


[OPTIONAL] I wonder if we can make deflate_copyright and inflate_copyright in sys/libkern/zlib.c static instead?

delphij accepted this revision.Jul 8 2019, 9:25 PM



I will move implementations here.


It appeared that these 2 variables are not used at all. Converting to static variable resulted in error.

Adjusted sys/type.h include to FreeBSD section and also moved crypto_z* function implementations to top of file.

Disable broken gzipped aout executable support and rename zlib in ZFS to avoid filename conflicts.

gzipped aout supports has been broken for more than few years now. Disable it to avoid inflate() ABI conflict. I'm interested in reimplementing it with zlib but it will be one of the last zlib update processes.

Add opensolaris_ prefix to zlib files in ZFS to avoid object filename conflicts. Zlib in ZFS is compiled with different options and they are not ABI compatible.
This will also address

These changes address link errors found by LINT:
% make buildLINT
% make buildkernel KERNCONF=LINT

Actually, this file rename doesn't fix
I don't think it is worth addressing this bug report here as removing the zlib in zfs also fixes this issue and we are aiming for this serious of changes.

D21072, "Remove support for kernel.tramp and kernel.tramp.gz", precedes this revision. This removes obsolete use of legacy zlib version.

D21099 removed gzip'ed a.out support. Rebased and adjusted.

delphij updated this revision to Diff 60318.Jul 31 2019, 5:44 AM

Add license plate for sys/dev/zlib/zlib_mod.c.

delphij added a subscriber: markm.

+@markm (Please confirm if the license is Okay for sys/dev/zlib/zlib_mod.c, the file is largely based on your change rS130799 in 2004 for sys/net/zlib.c).


A license plate should be added.


A license plate should be added.

delphij added subscribers: mmacy, avg.

+@mav @avg @mmacy for ZFS portion of change as a FYI (sys/cddl/contrib/opensolaris/uts/common/zmod). TL;DR: the bundled zlib (1.2.3) was removed in favor of new zlib; alloc/free functions merged from zmod_subr.c into zmod.c.

markm accepted this revision.Jul 31 2019, 7:20 AM

LGTM otherwise.


This file is 99.999% boilerplate; I'm happy for the copyright to revert to FreeBSD Foundation without mentioning me.

delphij updated this revision to Diff 60319.Jul 31 2019, 7:43 AM

Modified zlib_mod.c to use standard FreeBSD Foundation license.

It looks ZFS changes, dropping zlib files in zfs, are melded into this one.
I recall needing to add -DGZIP and/or -DGUNZIP option for zfs compression=gzip to properly uncompress gzipped zfs devices with older version; there was gzip header regression...

I'd like to test to ensure I can read zfs with compresssion=gzip from 12-RELEASE.


Please use
/* This file is in the public domain. */

It is a clone of multiple copies of same functions.


Please use
/* This file is in the public domain. */

It is a clone of multiple copies of same functions.

I tested reads and writes on gzipped ZFS between 12.0-RELEASE and 13-CURRENT with this changes.
The test result was good.

Do we need to bump kernel version for this change like we did for gzip'ed a.out support removal?

delphij updated this revision to Diff 60351.Aug 1 2019, 6:26 AM

Update license for zcalloc;

Fix tinderbox build (needs upstream).

delphij accepted this revision.Aug 1 2019, 6:36 AM
delphij commandeered this revision.Aug 1 2019, 6:43 AM
delphij accepted this revision.
delphij edited reviewers, added:; removed: delphij.

Submitted as rS350496. accepted this revision.Aug 3 2019, 2:27 PM
This revision was not accepted when it landed; it landed in state Needs Review.Aug 6 2019, 1:32 PM
This revision was automatically updated to reflect the committed changes.