From c8cfa685ec55aedfacab257cb191b2ebb64bb4f6 Mon Sep 17 00:00:00 2001 From: Michael Mikovsky <77305074+Astatin3@users.noreply.github.com> Date: Sat, 20 Dec 2025 14:08:17 -0700 Subject: [PATCH] Mess with build parameters to make component binary smaller --- core-modules/client/.Cargo.toml.kate-swp | Bin 271 -> 0 bytes core-modules/client/.cargo/config.toml | 3 +++ core-modules/client/Cargo.toml | 4 ++-- core-modules/client/build.sh | 24 +++++++++++++++++++ core-modules/client/src/lib.rs | 7 +++--- core-modules/server/.cargo/config.toml | 3 +++ core-modules/server/Cargo.toml | 4 ++-- core-modules/server/build.sh | 29 ++++++++++++++++++----- unshell-lib/Cargo.lock | 4 ++-- unshell-lib/Cargo.toml | 1 + unshell-lib/src/announcement.rs | 9 ++++--- unshell-lib/src/config/mod.rs | 2 +- unshell-payload/Cargo.lock | 2 ++ unshell-payload/build.sh | 3 ++- unshell-payload/src/main.rs | 4 +++- 15 files changed, 76 insertions(+), 23 deletions(-) delete mode 100644 core-modules/client/.Cargo.toml.kate-swp create mode 100644 core-modules/client/.cargo/config.toml create mode 100755 core-modules/client/build.sh create mode 100644 core-modules/server/.cargo/config.toml diff --git a/core-modules/client/.Cargo.toml.kate-swp b/core-modules/client/.Cargo.toml.kate-swp deleted file mode 100644 index 3d6407b7d14dd1001e43cc1cc20c2105b9ba3c2e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 271 zcmZQzU=Z?7EJ;-eE>A2_aLdd|RWQ;sU|?VndGutlVFcF+M}}v&Zs&Ese9{}eDrjxq>_$8N@`kSX-Q#5>&p diff --git a/core-modules/client/.cargo/config.toml b/core-modules/client/.cargo/config.toml new file mode 100644 index 0000000..043187d --- /dev/null +++ b/core-modules/client/.cargo/config.toml @@ -0,0 +1,3 @@ +[unstable] +build-std = ["core", "std"] +build-std-features = ["optimize_for_size"] diff --git a/core-modules/client/Cargo.toml b/core-modules/client/Cargo.toml index e2e4a33..8604d92 100644 --- a/core-modules/client/Cargo.toml +++ b/core-modules/client/Cargo.toml @@ -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" diff --git a/core-modules/client/build.sh b/core-modules/client/build.sh new file mode 100755 index 0000000..a450f26 --- /dev/null +++ b/core-modules/client/build.sh @@ -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 diff --git a/core-modules/client/src/lib.rs b/core-modules/client/src/lib.rs index 68214cb..2526bcf 100644 --- a/core-modules/client/src/lib.rs +++ b/core-modules/client/src/lib.rs @@ -58,10 +58,11 @@ fn start_runtime(config: &'static RuntimeConfig) -> Result NamedComponent { - NamedComponent { +#[unsafe(no_mangle)] +pub fn get_components() -> Vec { + vec![NamedComponent { name: MODULE_NAME, get_interface: &get_interface, start_runtime: &start_runtime, - } + }] } diff --git a/core-modules/server/.cargo/config.toml b/core-modules/server/.cargo/config.toml new file mode 100644 index 0000000..043187d --- /dev/null +++ b/core-modules/server/.cargo/config.toml @@ -0,0 +1,3 @@ +[unstable] +build-std = ["core", "std"] +build-std-features = ["optimize_for_size"] diff --git a/core-modules/server/Cargo.toml b/core-modules/server/Cargo.toml index d9c8315..41cf995 100644 --- a/core-modules/server/Cargo.toml +++ b/core-modules/server/Cargo.toml @@ -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" diff --git a/core-modules/server/build.sh b/core-modules/server/build.sh index e2ce7ee..b9d1572 100755 --- a/core-modules/server/build.sh +++ b/core-modules/server/build.sh @@ -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 diff --git a/unshell-lib/Cargo.lock b/unshell-lib/Cargo.lock index 00c8031..45426bf 100644 --- a/unshell-lib/Cargo.lock +++ b/unshell-lib/Cargo.lock @@ -494,9 +494,9 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "ryu" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" +checksum = "62049b2877bf12821e8f9ad256ee38fdc31db7387ec2d3b3f403024de2034aea" [[package]] name = "scopeguard" diff --git a/unshell-lib/Cargo.toml b/unshell-lib/Cargo.toml index 699521f..f2879cf 100644 --- a/unshell-lib/Cargo.toml +++ b/unshell-lib/Cargo.toml @@ -23,6 +23,7 @@ chrono = "0.4.42" serde = { version = "1.0.228", features = ["derive"] } serde_json = "1.0.145" + libc = "0.2.177" rand = "0.9.2" crossbeam-channel = "0.5.15" diff --git a/unshell-lib/src/announcement.rs b/unshell-lib/src/announcement.rs index f09713b..d8d328f 100644 --- a/unshell-lib/src/announcement.rs +++ b/unshell-lib/src/announcement.rs @@ -6,12 +6,11 @@ use crate::config::RuntimeConfig; #[derive(Clone, Debug, Encode, Decode)] pub enum Announcement { TestAnnouncement(String), + // GetRuntimes, + // GetRuntimesAck(usize), - GetRuntimes, - GetRuntimesAck(usize), - - StartRuntime(RuntimeConfig), - StartRuntimeAck(bool), + // StartRuntime(RuntimeConfig), + // StartRuntimeAck(bool), } const BINCODE_CONFIG: bincode::config::Configuration = bincode::config::standard(); diff --git a/unshell-lib/src/config/mod.rs b/unshell-lib/src/config/mod.rs index b283ba5..49f068d 100644 --- a/unshell-lib/src/config/mod.rs +++ b/unshell-lib/src/config/mod.rs @@ -21,7 +21,7 @@ pub struct PayloadConfig { pub runtime_config: Vec, } -#[derive(Debug, Clone, Encode, Decode)] +#[derive(Debug, Clone)] pub struct RuntimeConfig { pub parent_component: String, pub name: String, diff --git a/unshell-payload/Cargo.lock b/unshell-payload/Cargo.lock index af5acca..a63574b 100644 --- a/unshell-payload/Cargo.lock +++ b/unshell-payload/Cargo.lock @@ -667,6 +667,8 @@ version = "0.0.0" dependencies = [ "proc-macro2", "quote", + "rand", + "static_init", "syn 2.0.109", "unshell-crypt", ] diff --git a/unshell-payload/build.sh b/unshell-payload/build.sh index 0792954..176567c 100755 --- a/unshell-payload/build.sh +++ b/unshell-payload/build.sh @@ -7,4 +7,5 @@ RUSTFLAGS="-Zlocation-detail=none -Zfmt-debug=none" \ cargo +nightly build \ -Z build-std=std,panic_abort \ -Z build-std-features="optimize_for_size" \ - --profile release $@ + $@ \ + --profile release diff --git a/unshell-payload/src/main.rs b/unshell-payload/src/main.rs index 40bcf07..bca8354 100644 --- a/unshell-payload/src/main.rs +++ b/unshell-payload/src/main.rs @@ -16,7 +16,7 @@ extern crate unshell_lib; #[dynamic] static PAYLOAD_CONFIG: PayloadConfig = PayloadConfig { id: symbol!("Test ID"), - components: unshell_lib::get_components(), + components: Vec::new(), runtime_config: vec![RuntimeConfig { parent_component: symbol!("client").to_string(), name: symbol!("client runtime").to_string(), @@ -52,6 +52,8 @@ fn main() { // // modules.push(Module::new(&arg)?) // } + // let modules = vec + // Run the manager, this is blocking. let manager = Manager::start(&PAYLOAD_CONFIG, Vec::new());