-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.sh
executable file
·32 lines (23 loc) · 929 Bytes
/
check.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#! /bin/bash
# Install nightly toolchain
# rustup toolchain install nightly-x86_64-unknown-linux-gnu
# rustup component add rust-src --toolchain nightly
RUSTFLAGS="-Ctarget-cpu=native -Clink-args=-nostartfiles -Ctarget-feature=+crt-static -C relocation-model=static -Clink-args=-Wl,-n,-N,--no-dynamic-linker,--no-pie,-build-id=none " cargo +nightly b --release
# Processing
# Copy to root
cp ./target/release/smallest-hello hello
# Remove unnecesary sectors
objcopy -R .shstrtab -R .comment hello hello.tmp
mv hello.tmp hello
# Remove everything after Hello Rust!\n\x00, mainly the section header
# Ideally you would use something like https://github.com/blackle/Section-Header-Stripper
#python truncate.py
# Or sstrip from https://github.com/BR903/ELFkickers, highly recommend that
sstrip -z hello
# Custom header
python3 header.py
echo
echo "Final binary size:"
/bin/ls -l hello | awk '{print $5}'
file hello
./hello