xref: /aosp_15_r20/external/executorch/scripts/strip_binary.py (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1#!/usr/bin/env python3
2# Copyright (c) Meta Platforms, Inc. and affiliates.
3# All rights reserved.
4#
5# This source code is licensed under the BSD-style license found in the
6# LICENSE file in the root directory of this source tree.
7
8# pyre-strict
9
10"""
11Strip a binary file using the ELF `strip` tool specified by a Skycastle workflow.
12
13Usage:
14    strip_binary.py input_path output_path
15
16    Strip the ELF binary given by `input_path`, outputting the stripped
17    binary to `output_path`.
18"""
19
20import subprocess
21import sys
22from pathlib import Path
23
24
25def main():
26    if len(sys.argv) != 3:
27        print("Must specify input and output file paths")
28        sys.exit(1)
29
30    input_file = Path(sys.argv[1])
31    output_file = Path(sys.argv[2])
32
33    # Assumes `strip` tool is in the path (should be specified by Skycastle workflow).
34    # GNU `strip`, or equivalent, should work for x86 and ARM ELF binaries. This might
35    # not be appropriate for more exotic, non-ELF toolchains.
36    completed = subprocess.run(["strip", "--strip-all", input_file, "-o", output_file])
37    sys.exit(completed.returncode)
38
39
40if __name__ == "__main__":
41    main()
42