Mess with build parameters to make component binary smaller

This commit is contained in:
Michael Mikovsky
2025-12-20 14:08:17 -07:00
parent 514dd5c87b
commit c8cfa685ec
15 changed files with 76 additions and 23 deletions
Binary file not shown.
+3
View File
@@ -0,0 +1,3 @@
[unstable]
build-std = ["core", "std"]
build-std-features = ["optimize_for_size"]
+2 -2
View File
@@ -1,4 +1,4 @@
cargo-features = ["trim-paths"]
cargo-features = ["trim-paths", "panic-immediate-abort"]
[package]
name = "client"
@@ -21,6 +21,6 @@ strip = true # Strip symbols from the binary
opt-level = "s" # Optimize for size
lto = true
codegen-units = 1
panic = "abort"
panic = "immediate-abort"
debug = false
trim-paths = "all"
+24
View File
@@ -0,0 +1,24 @@
OBFUSCATION_KEY=abc123abc \
cargo build --release
export BINARY=./target/release/libclient.so
declare -a headers=(
".gnu_debuglink" # - Debug information link
".comment" #- Compiler version info
".shstrtab" #- Section header string table (only needed by tools like readelf)
".note.gnu.bu" ".note.gnu.build-id" # - Build ID note
".eh_frame" ".eh_frame_hdr" # Exception handling info (can break C++ exceptions if removed)
".gnu.version" ".gnu.version_r" # Symbol versioning (may be needed for some shared libraries)
".gnu.hash" # Hash table for symbol lookup optimization
)
# TODO: Implement FAKE section header comments and information
# Shuffle order of headers??
for section in "${headers[@]}"
do
strip --remove-section="$section" $BINARY
echo "Removed section header $section"
done
+4 -3
View File
@@ -58,10 +58,11 @@ fn start_runtime(config: &'static RuntimeConfig) -> Result<Box<dyn ModuleRuntime
Ok(Box::new(ClientRuntime::new(config)?))
}
pub const fn get_named_component() -> NamedComponent {
NamedComponent {
#[unsafe(no_mangle)]
pub fn get_components() -> Vec<NamedComponent> {
vec![NamedComponent {
name: MODULE_NAME,
get_interface: &get_interface,
start_runtime: &start_runtime,
}
}]
}
+3
View File
@@ -0,0 +1,3 @@
[unstable]
build-std = ["core", "std"]
build-std-features = ["optimize_for_size"]
+2 -2
View File
@@ -1,4 +1,4 @@
cargo-features = ["trim-paths"]
cargo-features = ["trim-paths", "panic-immediate-abort"]
[package]
name = "server"
@@ -20,6 +20,6 @@ strip = true # Strip symbols from the binary
opt-level = "s" # Optimize for size
lto = true
codegen-units = 1
panic = "abort"
panic = "immediate-abort"
debug = false
trim-paths = "all"
+23 -6
View File
@@ -1,7 +1,24 @@
OBFUSCATION_KEY=abc123abc \
RUSTFLAGS="-Zlocation-detail=none -Zfmt-debug=none" \
cargo +nightly bloat \
-Z build-std=std,panic_abort \
-Z build-std-features="optimize_for_size" \
$@ \
--profile release
cargo build --release
export BINARY=./target/release/libserver.so
declare -a headers=(
".gnu_debuglink" # - Debug information link
".comment" #- Compiler version info
".shstrtab" #- Section header string table (only needed by tools like readelf)
".note.gnu.bu" ".note.gnu.build-id" # - Build ID note
".eh_frame" ".eh_frame_hdr" # Exception handling info (can break C++ exceptions if removed)
".gnu.version" ".gnu.version_r" # Symbol versioning (may be needed for some shared libraries)
".gnu.hash" # Hash table for symbol lookup optimization
)
// TODO: Implement FAKE section header comments and information
// Shuffle order of headers??
for section in "${headers[@]}"
do
strip --remove-section="$section" $BINARY
echo "Removed section header $section"
done