The experiment to consolidate some crypto functions, shared between zfs/geli.
Needs ReviewPublic

Authored by tsoome on Aug 22 2016, 10:09 PM.

Details

Reviewers
jmg
allanjude
imp
Summary

The goal is to reduce code duplication in loader by creating a separate
instance of crypto library, which can be linked if either zfs or geli
is needed. Incidentally it also resulted in some related changes, such as
geli + zfsboot (totally untested however). Also there is still some
confusion about _STAND and _STANDALONE defines, which probably will need
some attention. Also there seems to be some confusion about bsd.stand.mk
use cases.

The resulting zfsloader binary is only slightly reduced in size:
-r-xr-xr-x 1 root wheel 446464 Aug 19 08:46 zfsloader
-rw-r--r-- 1 root wheel 438272 Aug 23 00:30 zfsloader.b

in this sample, the zfsloader.b is built based on this work. Since only
sha256/sha512-256 code was duplicated, the result is quite good, I think.

There also seems to be some sort of issue preventing removal of unused
symbols from resulting binaries, the specific case was observed regarding
SHA* functions, eventually I just used preprocessor to exclude unused ones.

Most likely I have missed some related parts, only tested x86 build.

Test Plan

Tested with sha256/sha512 checksum set on zfs datasets.

The current best size for zfsloader with -Os is:
-rw-r--r-- 1 root wheel 380928 Aug 23 19:55 zfsloader

Diff Detail

Repository
rS FreeBSD src repository
Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 5777
Build 6081: arc lint + arc unit
tsoome retitled this revision from to The experiment to consolidate some crypto functions, shared between zfs/geli..Aug 22 2016, 10:09 PM
tsoome updated this object.
tsoome edited the test plan for this revision. (Show Details)
tsoome added subscribers: allanjude, imp.
emaste added a subscriber: emaste.Aug 23 2016, 4:15 PM
tsoome updated this revision to Diff 19589.Aug 23 2016, 4:53 PM

I hope I got most makefiles right now, bsd.stand.mk defaults to use -Os,
-Oz did break ficl (i think).
Updated to revision 304689.

tsoome edited the test plan for this revision. (Show Details)Aug 23 2016, 4:57 PM
avg added a subscriber: avg.Aug 23 2016, 5:24 PM
tsoome updated this revision to Diff 19614.Aug 24 2016, 6:40 AM
tsoome edited the test plan for this revision. (Show Details)

zfsboot has leftover libbootcrypto reference in Makefile

allanjude removed a subscriber: allanjude.
tsoome updated this revision to Diff 21122.EditedOct 6 2016, 6:21 PM

Updated to revision 306775.

resulting file sizes:
tsoome@freebsd:/usr/obj/usr/src/sys/boot % ls -l i386/zfsloader/zfsloader efi/boot1/boot1.efi efi/loader/loader.efi userboot/userboot/userboot.so
-rwxr-xr-x 1 root wheel 117248 Oct 6 21:10 efi/boot1/boot1.efi
-rwxr-xr-x 1 root wheel 414720 Oct 6 21:10 efi/loader/loader.efi
-rw-r--r-- 1 root wheel 380928 Oct 6 21:11 i386/zfsloader/zfsloader
-rwxr-xr-x 1 root wheel 376128 Oct 6 21:11 userboot/userboot/userboot.so
tsoome@freebsd:/usr/obj/usr/src/sys/boot %

tsoome updated this revision to Diff 21857.Oct 31 2016, 10:41 PM

Updated to revision 308153.

If you have time, could you refresh this, I'd like to look at it again.

share/mk/bsd.stand.mk
8

could we maybe also do CFLAGS.clang+= -Oz