rust-teeny(opt): optimize size further

This commit is contained in:
2026-06-16 21:38:40 +02:00
parent 74b82edd18
commit 5bc6a32c6a
3 changed files with 15 additions and 3 deletions
+2 -1
View File
@@ -1,4 +1,4 @@
Tiny stripped rust binary (8.6 KiB, x86_64, dynamic libc) that loads and executes a shellcode payload built into it.
Tiny stripped rust binary (8.0 KiB, x86_64, dynamic libc) that loads and executes a shellcode payload built into it.
## Building
@@ -13,3 +13,4 @@ The code is completely correct, checks `mmap` and `mprotect` succeeded, the code
- Memory mapping a RWX page directly, some protected kernel builds require `RW` -> `RX` transition though.
- Assuming mmap and mprotect succeeded, no modern kernel should fail on `mmap` even if out of memory, the mapping is done regardless and memory actually reserved once used. `mprotect` shouldn't fail either if done correctly (man page mentions failures because no memory, which I said shouldn't happen, invalid permission combinations and invalid, which don't happen if you do correct permissions and valid pointers, or rare permission cases).
- `no_std`, this barely needs std, could just hardcode the 3-4 syscalls present and don't use `std` at all. This code also hardcoded `libc` values before so that's not needed either, but I think `libc` has `no_std` support either way.
- 0.1 KiB can be removed if you get rid of `.gnu.hash` and `.gnu.version` sections, but I think those can be required on other machines, not on mine though.
+12 -1
View File
@@ -11,7 +11,7 @@ build:
-Zlocation-detail=none -Zfmt-debug=none \
\
-Clinker=clang -Clink-arg=-fuse-ld=lld \
-Clink-arg=-Wl,--gc-sections -Clink-arg=-Wl,--strip-all \
-Clink-arg=-Wl,--gc-sections -Clink-arg=-Wl,--as-needed -Clink-arg=-Wl,--strip-all -Clink-arg=-Wl,--build-id=none \
\
-Cpanic=immediate-abort --remap-path-prefix=$PWD=[src] \
" cargo \
@@ -21,6 +21,17 @@ build:
\
b -r --target {{ target }}
# Base, does like nothing
strip --strip-all --strip-unneeded target/{{ target }}/release/rust-teeny
# BS, I don't want these
strip -R .comment -R .note.\* target/{{ target }}/release/rust-teeny
# Only OK because we don't do unwinding
strip -R .eh_frame\* target/{{ target }}/release/rust-teeny
# Not sure why .gnu.version and .gnu.hash don't break if I remove them in my machine, but that's very relative and its related to dynamic loading, but they could reduce size by `0.2 KiB`
stat:
stat target/{{ target }}/release/rust-teeny