Skip to content

Commit 5358b92

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 5358b92

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
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

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)