blob: 52607c85b76bdbc131d21ec5e4a36f6e021da16f [file] [log] [blame]
Christopher Grant3b06acce2019-04-25 18:26:411#!/usr/bin/env python
2# Copyright 2019 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5"""Extracts an LLD partition from an ELF file."""
6
7import argparse
8import subprocess
9import sys
10
11
12def main():
13 parser = argparse.ArgumentParser(description=__doc__)
14 parser.add_argument(
15 '--partition',
16 help='Name of partition if not the main partition',
17 metavar='PART')
18 parser.add_argument(
19 '--objcopy',
20 required=True,
21 help='Path to llvm-objcopy binary',
22 metavar='FILE')
23 parser.add_argument(
24 '--unstripped-output',
25 required=True,
26 help='Unstripped output file',
27 metavar='FILE')
28 parser.add_argument(
29 '--stripped-output',
30 required=True,
31 help='Stripped output file',
32 metavar='FILE')
33 parser.add_argument('input', help='Input file')
34 args = parser.parse_args()
35
36 objcopy_args = [args.objcopy]
37 if args.partition:
Christopher Grantdcbf30132019-05-09 15:39:2338 objcopy_args += ['--extract-partition', args.partition]
Christopher Grant3b06acce2019-04-25 18:26:4139 else:
40 objcopy_args += ['--extract-main-partition']
41 objcopy_args += [args.input, args.unstripped_output]
42 subprocess.check_call(objcopy_args)
43
44 objcopy_args = [
45 args.objcopy, '--strip-all', args.unstripped_output, args.stripped_output
46 ]
47 subprocess.check_call(objcopy_args)
48
Christopher Grant3b06acce2019-04-25 18:26:4149
50if __name__ == '__main__':
51 sys.exit(main())