Skip to content

Commit

Permalink
WiP: have modules built to be optimized for space (-Os)
Browse files Browse the repository at this point in the history
Adresses @easrentai suggestion to pass modules build optimization for space here: linuxboot#590 (comment)

Uniformized module's $(CROSS_TOOLS) being passed as environment variable, prior of ./configure call

Limitations:
- busybox don't seem to take Os into consideration when applied, no change to module yet.
- kexec applies both O2 and Os, no change to module yet.
- Kernel is already optimized for size (CONFIG_CC_OPTIMIZE_FOR_SIZE as Kconfig option), and kernel modules stripped prior of inserted in initrd, compressed with xz. Nothing else can be done here unless lto

Next steps:
- Go LTO for kernel and modules? But, I was not successful going that way in the past, maybe musl-cross-make has changed.
- Not sure if I read correctly, but -Oz may have happened under GCC 12.1, but not sure if apple relative or FSS GCC. Opened an issue over musl-cross-make, but the project is conservative on used GCC version.

Attempt to contribute to linuxboot#590 by reducing payload's footprint
  • Loading branch information
tlaurion committed Feb 18, 2023
1 parent 9676c79 commit efad24f
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion modules/cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ cairo_url := https://www.cairographics.org/releases/$(cairo_tar)
cairo_hash := 8c90f00c500b2299c0a323dd9beead2a00353752b2092ead558139bd67f7bf16

cairo_configure := \
CFLAGS="-DCAIRO_NO_MUTEX=1 -Os" \
$(CROSS_TOOLS) \
CFLAGS="-DCAIRO_NO_MUTEX=1 -O3" \
./configure \
--host $(MUSL_ARCH)-elf-linux \
--prefix="/" \
Expand Down
4 changes: 3 additions & 1 deletion modules/cryptsetup
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ cryptsetup_hash := af2b04e8475cf40b8d9ffd97a1acfa73aa787c890430afd89804fb544d6ad

# Use an empty prefix so that the executables will not include the
# build path.
cryptsetup_configure := ./configure \
cryptsetup_configure := \
$(CROSS_TOOLS) \
CFLAGS="-Os" \
./configure \
--host $(MUSL_ARCH)-elf-linux \
--prefix "/" \
--disable-gcrypt-pbkdf2 \
Expand Down
4 changes: 3 additions & 1 deletion modules/cryptsetup2
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ cryptsetup2_hash := 3bca4ffe39e2f94cef50f6ea65acb873a6dbce5db34fc6bcefe38b6d095e

# Use an empty prefix so that the executables will not include the
# build path.
cryptsetup2_configure := ./configure \
cryptsetup2_configure := \
$(CROSS_TOOLS) \
CFLAGS="-Os" \
./configure \
--host $(MUSL_ARCH)-elf-linux \
--prefix "/" \
--disable-rpath \
Expand Down
4 changes: 3 additions & 1 deletion modules/gpg
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ gpg_hash := 6b47a3100c857dcab3c60e6152e56a997f2c7862c1b8b2b25adf3884a1ae2276
# Force a different host/build setting so that it detects a cross compile.
# Otherwise it wil try to run tests.
#
gpg_configure := ./configure \
gpg_configure := \
CFLAGS="-Os" \
$(CROSS_TOOLS) \
./configure \
--build $(MUSL_ARCH)-elf-linux \
--host $(MUSL_ARCH)-linux-musl \
--with-libusb="$(INSTALL)" \
Expand Down
4 changes: 3 additions & 1 deletion modules/gpg2
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ gpg2_hash := 61e83278fb5fa7336658a8b73ab26f379d41275bb1c7c6e694dd9f9a6e8e76ec
# be generated with the correct paths, but then re-write them when
# we use the install target so that they will be copied to the correct
# location.
gpg2_configure := ./configure \
gpg2_configure := \
$(CROSS_TOOLS) \
CFLAGS="-Os" \
./configure \
CPPFLAGS="-I$(INSTALL)/include/libusb-1.0" \
--host $(MUSL_ARCH)-linux-musl \
--with-libusb="$(INSTALL)" \
Expand Down
4 changes: 3 additions & 1 deletion modules/libassuan
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ libassuan_tar := libassuan-$(libassuan_version).tar.bz2
libassuan_url := https://gnupg.org/ftp/gcrypt/libassuan/$(libassuan_tar)
libassuan_hash := 91bcb0403866b4e7c4bc1cc52ed4c364a9b5414b3994f718c70303f7f765e702

libassuan_configure := ./configure \
libassuan_configure := \
CFLAGS="-Os" \
$(CROSS_TOOLS) \
./configure \
--host $(MUSL_ARCH)-linux-musl \
--prefix "/" \
--disable-static \
Expand Down
4 changes: 3 additions & 1 deletion modules/libgcrypt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ libgcrypt_tar := libgcrypt-$(libgcrypt_version).tar.bz2
libgcrypt_url := https://gnupg.org/ftp/gcrypt/libgcrypt/$(libgcrypt_tar)
libgcrypt_hash := 0cba2700617b99fc33864a0c16b1fa7fdf9781d9ed3509f5d767178e5fd7b975

libgcrypt_configure := ./configure \
libgcrypt_configure := \
$(CROSS_TOOLS) \
CFLAGS="-Os" \
./configure \
--host=$(MUSL_ARCH)-linux-musl \
--prefix "/" \
--disable-static \
Expand Down
4 changes: 3 additions & 1 deletion modules/libgpg-error
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ libgpg-error_tar := libgpg-error-$(libgpg-error_version).tar.bz2
libgpg-error_url := https://gnupg.org/ftp/gcrypt/libgpg-error/$(libgpg-error_tar)
libgpg-error_hash := b32d6ff72a73cf79797f7f2d039e95e9c6f92f0c1450215410840ab62aea9763

libgpg-error_configure := ./configure \
libgpg-error_configure := \
$(CROSS_TOOLS) \
CFLAGS="-Os" \
./configure \
--prefix "/" \
--host=$(MUSL_ARCH)-linux-musl \
--disable-static \
Expand Down
4 changes: 3 additions & 1 deletion modules/libksba
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ libksba_tar := libksba-$(libksba_version).tar.bz2
libksba_url := https://gnupg.org/ftp/gcrypt/libksba/$(libksba_tar)
libksba_hash := bfe6a8e91ff0f54d8a329514db406667000cb207238eded49b599761bfca41b6

libksba_configure := ./configure \
libksba_configure := \
$(CROSS_TOOLS) \
CFLAGS="-Os" \
./configure \
--host $(MUSL_ARCH)-linux-musl \
--prefix "/" \
--disable-static \
Expand Down
1 change: 1 addition & 0 deletions modules/libpng
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ libpng_hash := 574623a4901a9969080ab4a2df9437026c8a87150dfd5c235e28c94b212964a7

libpng_configure := \
$(CROSS_TOOLS) \
CFLAGS="-Os" \
./configure \
--host $(MUSL_ARCH)-elf-linux \
--prefix="/" \
Expand Down
1 change: 1 addition & 0 deletions modules/lvm2
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ lvm2_hash := 23a3d1cddd41b3ef51812ebf83e9fa491f502fe74130d4263be327a91914660d
# so we force it via the configure cache.
lvm2_configure := \
$(CROSS_TOOLS) \
CFLAGS="-Os" \
PKG_CONFIG=/bin/false \
MODPROBE_CMD=/bin/false \
ac_cv_func_malloc_0_nonnull=yes \
Expand Down
1 change: 1 addition & 0 deletions modules/mbedtls
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mbedtls_configure :=

mbedtls_target := \
SHARED=1 \
CFLAGS="-Os" \
DESTDIR=$(INSTALL) \
$(CROSS_TOOLS) \
$(MAKE_JOBS) \
Expand Down
4 changes: 3 additions & 1 deletion modules/pinentry
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ pinentry_hash := 68076686fa724a290ea49cdf0d1c0c1500907d1b759a3bcbfbec0293e8f5657
# be generated with the correct paths, but then re-write them when
# we use the install target so that they will be copied to the correct
# location.
pinentry_configure := ./configure \
pinentry_configure := \
$(CROSS_TOOLS) \
CFLAGS="-Os" \
./configure \
--host $(MUSL_ARCH)-linux-musl \
--prefix "/" \
--enable-pinentry-tty \
Expand Down
1 change: 1 addition & 0 deletions modules/pixman
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pixman_hash := 21b6b249b51c6800dc9553b65106e1e37d0e25df942c90531d4c3997aa20a88e

pixman_configure := \
$(CROSS_TOOLS) \
CFLAGS="-Os" \
./configure \
--host $(MUSL_ARCH)-elf-linux \
--prefix="/" \
Expand Down
2 changes: 1 addition & 1 deletion modules/tpmtotp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ tpmtotp_hash := 1082f2b0e4af833e04220dddedcc21a39eb39ee4dc5668bb010e7bcc795c606c

tpmtotp_target := \
$(CROSS_TOOLS) \
CFLAGS="-I$(INSTALL)/include" \
CFLAGS="-I$(INSTALL)/include -Os" \
LDFLAGS="-L$(INSTALL)/lib" \

tpmtotp_output := \
Expand Down
4 changes: 3 additions & 1 deletion modules/util-linux
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ util-linux_tar := util-linux-$(util-linux_version).tar.xz
util-linux_url := https://www.kernel.org/pub/linux/utils/util-linux/v2.29/$(util-linux_tar)
util-linux_hash := accea4d678209f97f634f40a93b7e9fcad5915d1f4749f6c47bee6bf110fe8e3

util-linux_configure := ./configure \
util-linux_configure := \
$(CROSS_TOOLS) \
CFLAGS="-Os" \
./configure \
--host $(MUSL_ARCH)-elf-linux \
--prefix "/" \
--oldincludedir "$(INSTALL)/include" \
Expand Down
1 change: 1 addition & 0 deletions modules/zlib
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ zlib_hash := c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1

zlib_configure := \
$(CROSS_TOOLS) \
CFLAGS="-Os" \
./configure \
--prefix="/" \

Expand Down

0 comments on commit efad24f

Please sign in to comment.