blob: 4b2f06400bc1e11a92fa2e4eafb6244b8d667e9c [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')
Nelson Billing3ed73012020-08-25 04:39:1533 parser.add_argument('--dwp', help='Path to dwp binary', metavar='FILE')
Christopher Grant3b06acce2019-04-25 18:26:4134 parser.add_argument('input', help='Input file')
35 args = parser.parse_args()
36
37 objcopy_args = [args.objcopy]
38 if args.partition:
Christopher Grantdcbf30132019-05-09 15:39:2339 objcopy_args += ['--extract-partition', args.partition]
Christopher Grant3b06acce2019-04-25 18:26:4140 else:
41 objcopy_args += ['--extract-main-partition']
42 objcopy_args += [args.input, args.unstripped_output]
43 subprocess.check_call(objcopy_args)
44
45 objcopy_args = [
46 args.objcopy, '--strip-all', args.unstripped_output, args.stripped_output
47 ]
48 subprocess.check_call(objcopy_args)
49
Nelson Billing3ed73012020-08-25 04:39:1550 if args.dwp:
51 dwp_args = [
52 args.dwp, '-e', args.unstripped_output, '-o',
Nelson Billingaa05b8662020-09-22 19:11:0753 args.unstripped_output + '.dwp'
Nelson Billing3ed73012020-08-25 04:39:1554 ]
Nelson Billingd30089b2020-11-06 17:45:0955 # Suppress output here because it doesn't seem to be useful. The most
56 # common error is a segfault, which will happen if files are missing.
57 subprocess.check_output(dwp_args, stderr=subprocess.STDOUT)
Nelson Billing3ed73012020-08-25 04:39:1558
Christopher Grant3b06acce2019-04-25 18:26:4159
60if __name__ == '__main__':
61 sys.exit(main())