Skip to content

Conversation

tlaurion
Copy link
Collaborator

@tlaurion tlaurion commented Jul 30, 2025

WiP : bump musl-cross-make to latest commit, bump gcc 9.4.0 -> 15.1.0; rename/bump kexec-tools to latest version + gcc 15.10, switch/patch modules to switch from -Os to -Oz

TLDR: 1.44% space reduction (115kb gain)

Stats from global to specifics:

coreboot final stiching stats diff

"/home/user/heads/build/x86/coreboot-24.12/EOL_x230-hotp-maximized/cbfstool" "/home/user/heads/build/x86/coreboot-24.12/EOL_x230-hotp-maximized/coreboot.rom" print
FMAP REGION: COREBOOT
Name                           Offset     Type           Size   Comp
cbfs_master_header             0x0        cbfs header        32 none
cpu_microcode_blob.bin         0x80       microcode       26624 none
fallback/romstage              0x68c0     stage          107512 none
fallback/ramstage              0x20d40    stage          149993 LZMA (324488 decompressed)
config                         0x45780    raw              3521 LZMA (11135 decompressed)
revision                       0x46580    raw               724 none
build_info                     0x46880    raw               101 none
bootsplash.jpg                 0x46940    bootsplash      43282 none
fallback/dsdt.aml              0x51280    raw             14748 none
vbt.bin                        0x54c80    raw              1433 LZMA (4281 decompressed)
cmos_layout.bin                0x55280    cmos_layout      2012 none
fallback/postcar               0x55ac0    stage           40156 none
fallback/payload               0x5f800    simple elf    7908858 none
(empty)                        0x7ea640   null          4048740 none
bootblock                      0xbc6dc0   bootblock       36864 none

Master:

Jul 28 03:19:40 EOL_x230-hotp-maximized/util/cbfstool/cbfstool EOL_x230-hotp-maximized/coreboot.rom print -r COREBOOT
Jul 28 03:19:40 FMAP REGION: COREBOOT
Jul 28 03:19:40 Name                           Offset     Type           Size   Comp
Jul 28 03:19:40 cbfs_master_header             0x0        cbfs header        32 none
Jul 28 03:19:40 cpu_microcode_blob.bin         0x80       microcode       26624 none
Jul 28 03:19:40 fallback/romstage              0x68c0     stage          107512 none
Jul 28 03:19:40 fallback/ramstage              0x20d40    stage          149982 LZMA (324488 decompressed)
Jul 28 03:19:40 config                         0x45780    raw              3521 LZMA (11135 decompressed)
Jul 28 03:19:40 revision                       0x46580    raw               724 none
Jul 28 03:19:40 build_info                     0x46880    raw               101 none
Jul 28 03:19:40 bootsplash.jpg                 0x46940    bootsplash      43282 none
Jul 28 03:19:40 fallback/dsdt.aml              0x51280    raw             14748 none
Jul 28 03:19:40 vbt.bin                        0x54c80    raw              1433 LZMA (4281 decompressed)
Jul 28 03:19:40 cmos_layout.bin                0x55280    cmos_layout      2012 none
Jul 28 03:19:40 fallback/postcar               0x55ac0    stage           40156 none
Jul 28 03:19:40 fallback/payload               0x5f800    simple elf    8024362 none
Jul 28 03:19:40 (empty)                        0x806980   null          3933220 none
Jul 28 03:19:40 bootblock                      0xbc6dc0   bootblock       36864 none

Analysis:

  • gain (emtpy comparison) = 4048740 - 3933220 = 115520 bytes

sizes.txt comparison (diff -u master pr)

--- /tmp/master_sizes.txt       2025-07-27 23:19:45.000000000 -0400
+++ build/x86/EOL_x230-hotp-maximized/sizes.txt 2025-07-30 12:22:53.607423022 -0400
-2025-07-28 03:11:34+00:00 652eff3d831aaf195825e55903cbc4fab67d4a56 clean
- 2822912:/root/heads/build/x86/EOL_x230-hotp-maximized/bzImage
-  930816:/root/heads/build/x86/EOL_x230-hotp-maximized/modules.cpio
+2025-07-30 16:19:56+00:00 b5a94d5488287500316e4de1072a6fba41d593b9 clean
+ 2798032:/home/user/heads/build/x86/EOL_x230-hotp-maximized/bzImage
+  928256:/home/user/heads/build/x86/EOL_x230-hotp-maximized/modules.cpio
[...]
-13865984:/root/heads/build/x86/EOL_x230-hotp-maximized/tools.cpio
+13262336:/home/user/heads/build/x86/EOL_x230-hotp-maximized/tools.cpio
[...]
-  434176:/root/heads/build/x86/EOL_x230-hotp-maximized/heads.cpio
+  434176:/home/user/heads/build/x86/EOL_x230-hotp-maximized/heads.cpio
[...]
- 2508800:/root/heads/build/x86/EOL_x230-hotp-maximized/data.cpio
+ 2508800:/home/user/heads/build/x86/EOL_x230-hotp-maximized/data.cpio
[...]
- 5212160:build/x86/EOL_x230-hotp-maximized/initrd.cpio.xz
+ 5121536:build/x86/EOL_x230-hotp-maximized/initrd.cpio.xz

Analysis:

  • initrd.cpio.xz (concatenated+compressed cpio) reduced by 90,624 bytes (compression gains maybe suboptimal?)
    • modules.cpio (kernel modules) reduced by 2,560 bytes
    • tools.cpio (compiled libs/bins) reduced by 603,648 bytes
  • bzImage (kernel) reduced by 24,880 bytes

TLDR:

  • Master Heads payload: 8,035,072 bytes (7.66 MB)
  • PR Heads payload: 7,919,568 bytes (7.55 MB)
    Total Savings: 115,504 bytes (1.44% reduction)

Continues #590

@tlaurion tlaurion changed the title Agressive optimization for space (-Os -> -Oz): musl-cross-make-> bump to gcc 15.1.0 & related changes Further optimization for space (-Os -> -Oz): musl-cross-make-> bump to gcc 15.1.0 & related changes Aug 9, 2025
@tlaurion tlaurion marked this pull request as draft August 14, 2025 16:26
tlaurion and others added 15 commits August 19, 2025 16:12
….1.0 (in the goal of using gcc 12+ -Oz instead of -Os for more agressive optimization for space)

Signed-off-by: Thierry Laurion <[email protected]>
… (purgatory cannot be built with i386; do 2.0.31(latest) + missing patch)

Signed-off-by: Thierry Laurion <[email protected]>
…ility fixes

This commit upgrades the cross-compilation toolchain from GCC 9.4.0 to GCC 15.1.0
and implements systematic compatibility fixes across the codebase.

**Core Changes:**
- modules/musl-cross-make: Update to commit 3635262e (GCC 15.1.0 toolchain)
- Systematic conversion from -Os to -Oz optimization across 33+ modules
- Added comprehensive C23 compatibility fixes for affected modules

**C23 Standard Compatibility Fixes:**
- modules/linux: Added -std=gnu11 to resolve bool/false keyword conflicts
- modules/gpg2: Added -std=gnu11 to resolve true keyword conflicts
- modules/bash: Added -std=gnu11 + patched tparam.c for unistd.h include
- modules/e2fsprogs: Added -std=gnu11 to resolve bool typedef conflicts

**Header Include Fixes:**
- patches/lvm2-2.03.23.patch: Added libgen.h include for basename() function
- patches/bash-5.1.16.patch: Added unistd.h include for write() function

**Compiler Flag Adjustments:**
- modules/cairo: Added -Wno-inline and -Wno-incompatible-pointer-types for -Oz
- Makefile: Added -Wno-unterminated-string-initialization for cbmem utility

**Optimization Improvements:**
- Converted CFLAGS from -Os to -Oz in 33+ modules for better size optimization
- All modules: cryptsetup, flashrom, gpg, libgcrypt, ncurses, util-linux, etc.

**Documentation & Future Maintenance:**
- Added unified TODO_GCC_15_* comments across all modified modules
- Created doc/GCC_15_UPGRADE_SUMMARY.md for tracking changes
- Created doc/GCC_15_COMPATIBILITY_TEMPLATE.md for future upgrades
- All compatibility fixes documented with removal conditions

**Build Validation:**
- Full build testing completed successfully
- All modules compile cleanly with GCC 15.1.0
- Cross-compiler toolchain verified functional
- Systematic C23 compatibility approach established

This upgrade enables modern GCC optimizations while maintaining compatibility
with current module versions. All changes include TODO comments for easy
removal when modules are updated to support C23 natively.

Co-authored-by: GitHub Copilot <[email protected]>
Signed-off-by: Thierry Laurion <[email protected]>
…being added to cpio then initrd.cpio.xz

Signed-off-by: Thierry Laurion <[email protected]>
…e fixes to comply with gcc 15.1+

Signed-off-by: Thierry Laurion <[email protected]>
….patch individual patch files

Signed-off-by: Thierry Laurion <[email protected]>
• Upgrade from 2016.74 to 2025.88 for GCC 15.1.0 compatibility
• Apply extensive configure optimizations to minimize feature set:
  --disable-lastlog, --disable-syslog, --disable-utmp, --disable-utmpx,
  --disable-wtmp, --disable-wtmpx, --disable-loginfunc, --disable-pututline,
  --disable-pututxline, --disable-openpty, --disable-shadow
• Restore critical security patch for Heads embedded environment:
  Comment out fatal user/group change errors that legitimately fail in firmware
• Organize patches under patches/dropbear-2025.88/ directory structure
• Size impact: +89KB (185KB→274KB dropbear, 23KB→27KB scp)
  Trade-off necessary for security updates and compiler compatibility

Signed-off-by: Thierry Laurion <[email protected]>
…c algorithms

Reduce OpenSSL libcrypto.so.3 size by 103KB (3.1%) through aggressive
algorithm disabling via configure flags. Removed unused cryptographic
algorithms while maintaining compatibility with TPM2-TSS requirements.

Disabled algorithms:
- Legacy ciphers: DES, RC2/RC4, IDEA, Blowfish, CAST
- Hash functions: MD2/MD4/MD5, RIPEMD160, Whirlpool
- Modern algorithms: ChaCha20, Poly1305, ARIA, Camellia
- Elliptic curves: EC2M curves, SM2/SM4 Chinese algorithms
- Key exchange: DH, DSA, SRP, GOST
- Protocol versions: SSL 3.0, TLS 1.0/1.1
- Advanced features: OCB, SIV, CMAC, BLAKE2, engines

Size impact:
- libcrypto.so.3: 3,280,536 → 3,177,880 bytes (-103KB, -3.1%)
- tools.cpio total: ~621KB cumulative savings vs master

Maintains required algorithms for TPM2 operations (SHA, AES, SM3).

Signed-off-by: Thierry Laurion <[email protected]>
…tion

Further optimize LVM2 by disabling unused features:
- --with-snapshots=none: Disable snapshot support
- --with-mirrors=none: Disable mirror support
- --disable-udev_rules: Disable udev integration
- --disable-pkgconfig: Disable pkgconfig support
- --disable-nls: Disable internationalization

Results (stripped binary sizes):
- lvm: 2,140,888 → 2,132,376 bytes (-8,512 bytes)
- dmsetup: 110,936 bytes (unchanged)
- Total LVM2 optimization: 51,976 bytes saved

These flags safely remove functionality not needed by Heads
while maintaining essential device-mapper capabilities required
by cryptsetup for disk encryption support.

Signed-off-by: Thierry Laurion <[email protected]>
…tion

Algorithm-specific optimization targeting only required cryptographic functions:
- Ciphers: aes des chacha20 (for GPG2 and factory reset)
- Public key: rsa ecc (RSA keys and ECDSA/ECDH nistp256)
- Digests: sha1 sha256 sha512 blake2 (essential hash functions)

Space reduction:
- Baseline (stripped): 814,928 bytes
- Optimized (stripped): 497,504 bytes
- Space saved: 317,424 bytes (310KB)
- Reduction: 38.9%

Excluded unused algorithms:
- Symmetric: arcfour blowfish cast5 twofish serpent rfc2268 seed camellia idea salsa20 gost28147 sm4
- Digests: crc gostr3411-94 md4 md5 rmd160 sha3 tiger whirlpool stribog sm3
- Public key: dsa elgamal

Hardware acceleration preserved for optimal performance.
Maintains full functionality for GPG2 operations and factory reset key generation.

Signed-off-by: GitHub Copilot <[email protected]>
Signed-off-by: Thierry Laurion <[email protected]>
Optimized libgcrypt with -Oz optimization:
- Stripped size: 564,192 bytes (551KB)
- Significant improvement over master baseline
- All algorithms enabled for full compatibility

Baseline measurements:
- Master baseline: 1,198,224 bytes (1.17MB)
- Current (-Oz): 564,192 bytes (551KB)
- Space saved: 634,032 bytes (619KB) - 53% reduction!
- Previous attempt: 497,504 bytes (restricted algorithms, GPG broken)

This provides a solid optimized baseline for further systematic algorithm
optimization while maintaining full functionality for GPG2, factory reset,
and cryptsetup2. The -Oz flag alone provides massive space savings.

Signed-off-by: GitHub Copilot <[email protected]>
Signed-off-by: Thierry Laurion <[email protected]>
…-gcc15.patch: function pointers need proper signatures to match their actual usage

modules/powerpc-utils contains docs traces in regard of gcc15 requirements

Signed-off-by: Thierry Laurion <[email protected]>
…atch_fix_for_newer_gcc_from_musl_125.patch: add patches needed for skiboot to be compiled in little-endian by heads boostrapped gcc15.1 compiler

Signed-off-by: Thierry Laurion <[email protected]>
@tlaurion tlaurion force-pushed the musl-cross-make_gcc_15.1.0-Optimized_for_space-Oz branch from 69ab1d1 to c19ab15 Compare August 19, 2025 20:14
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.

1 participant