Skip to content

Commit f4fce84

Browse files
author
Iulian Barbu
committed
devtool: added strip command
Added `devtool strip` command. This command can strip binaries out of DWARF debug sections. The command can be parameterized by `--target-libc (musl|gnu)`, which sets the libc used by a specific toolchain (e.g. x86_64-uknown-linux-${libc_flavor}). Signed-off-by: Iulian Barbu <[email protected]>
1 parent e630dfc commit f4fce84

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
snapshot.
2626
- Added a new API call, `PUT /snapshot/load`, for loading a snapshot.
2727
- Added metrics for the vsock device.
28+
- Added devtool strip command to strip release binaries out of DWARF sections.
2829

2930
### Fixed
3031

tests/host_tools/cargo_build.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,15 @@ def get_firecracker_binaries():
6969
fc_bin_path = "{}/{}".format(out_dir, FC_BINARY_NAME)
7070
jailer_bin_path = "{}/{}".format(out_dir, JAILER_BINARY_NAME)
7171

72+
cmd = "strip --strip-debug {} {}".format(fc_bin_path, jailer_bin_path)
73+
utils.run_cmd(cmd)
74+
7275
return fc_bin_path, jailer_bin_path
7376

7477

7578
def get_rustflags():
7679
"""Get the relevant rustflags for building/unit testing."""
7780
rustflags = "-D warnings"
7881
if platform.machine() == "aarch64":
79-
rustflags += " -C link-arg=-lgcc -C link-arg=-lfdt "
82+
rustflags += " -C link-args=-lgcc -lfdt "
8083
return rustflags

tests/integration_tests/build/test_binary_size.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
MACHINE = platform.machine()
1212
""" Platform definition used to select the correct size target"""
1313

14-
FC_BINARY_SIZE_TARGET = 3200000 if MACHINE == "x86_64" else 3251464
14+
FC_BINARY_SIZE_TARGET = 1955168 if MACHINE == "x86_64" else 1531384
1515
"""Firecracker target binary size in bytes"""
1616

17-
FC_BINARY_SIZE_LIMIT = 3500000 if MACHINE == "x86_64" else 3400000
17+
FC_BINARY_SIZE_LIMIT = 2052927 if MACHINE == "x86_64" else 1607953
1818
"""Firecracker maximum binary size in bytes"""
1919

20-
JAILER_BINARY_SIZE_TARGET = 2568384 if MACHINE == "x86_64" else 2792688
20+
JAILER_BINARY_SIZE_TARGET = 1439512 if MACHINE == "x86_64" else 1338312
2121
"""Jailer target binary size in bytes"""
2222

23-
JAILER_BINARY_SIZE_LIMIT = 3000000
23+
JAILER_BINARY_SIZE_LIMIT = 1511488
2424
"""Jailer maximum binary size in bytes"""
2525

2626
BINARY_SIZE_TOLERANCE = 0.05

tools/devtool

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,15 @@ cmd_help() {
385385
echo " -l, --libc musl|gnu Choose the libc flavor against which Firecracker will"
386386
echo " be linked. Default is musl."
387387
echo ""
388+
echo " strip [--target-libc musl|gnu]"
389+
echo " Strip from debug symbols the Firecracker binaries."
390+
echo ""
391+
echo " --target-libc musl|gnu Choose the target libc flavor which determines the"
392+
echo " toolchain used to build Firecracker release binaries."
393+
echo " Stripping will occur only for the Firecracker release"
394+
echo " binaries corresponding to the inferred toolchain. Default"
395+
echo " is musl."
396+
echo ""
388397
echo " fmt"
389398
echo " Auto-format all Rust source files, to match the Firecracker requirements."
390399
echo " This should be used as the last step in every commit, to ensure that the"
@@ -500,6 +509,54 @@ cmd_build() {
500509
return $ret
501510
}
502511

512+
cmd_strip() {
513+
profile="release"
514+
libc="musl"
515+
target="$(uname -m)-unknown-linux-${libc}"
516+
517+
# Parse any command line args.
518+
while [ $# -gt 0 ]; do
519+
case "$1" in
520+
"-h"|"--help") { cmd_help; exit 1; } ;;
521+
"--target-libc")
522+
shift
523+
[[ "$1" =~ ^(musl|gnu)$ ]] || \
524+
die "Invalid libc: $1. Valid options are \"musl\" and \"gnu\"."
525+
libc="$1"
526+
target="$(uname -m)-unknown-linux-${libc}"
527+
;;
528+
*)
529+
die "Unknown argument: $1. Please use --help for help."
530+
;;
531+
esac
532+
shift
533+
done
534+
535+
# Check prerequisites
536+
ensure_devctr
537+
ensure_build_dir
538+
539+
say "Starting stripping the debug symbols for $profile binaries built against $target target."
540+
strip_flags="--strip-debug"
541+
say "Strip flags: $strip_flags."
542+
543+
run_devctr \
544+
--user "$(id -u):$(id -g)" \
545+
-- \
546+
strip $strip_flags\
547+
"$CTR_CARGO_TARGET_DIR/$target/$profile/firecracker" \
548+
"$CTR_CARGO_TARGET_DIR/$target/$profile/jailer"
549+
ret=$?
550+
551+
[ $ret -eq 0 ] && {
552+
cargo_bin_dir="$CARGO_TARGET_DIR/$target/$profile"
553+
say "Stripping was successful."
554+
say "Stripped binaries placed under $cargo_bin_dir."
555+
}
556+
557+
return $?
558+
}
559+
503560
# `$0 test` - run integration tests
504561
# Please see `$0 help` for more information.
505562
#

0 commit comments

Comments
 (0)