1#!/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: 38 objcopy_args += ['--extract-partition', args.partition] 39 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 49 50if __name__ == '__main__': 51 sys.exit(main()) 52