forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
objcopy.py
executable file
·58 lines (48 loc) · 1.3 KB
/
objcopy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import argparse
import os
import subprocess
import sys
# BFD architecture names recognized by objcopy.
BFD_ARCH = {
'arm': 'arm',
'arm64': 'aarch64',
'x86': 'i386',
'x64': 'i386:x86-64',
}
# BFD target names recognized by objcopy.
BFD_TARGET = {
'arm': 'elf32-littlearm',
'arm64': 'elf64-littleaarch64',
'x86': 'elf32-i386',
'x64': 'elf64-x86-64',
}
def main():
parser = argparse.ArgumentParser(
description='Convert a data file to an object file'
)
parser.add_argument('--objcopy', type=str, required=True)
parser.add_argument('--input', type=str, required=True)
parser.add_argument('--output', type=str, required=True)
parser.add_argument('--arch', type=str, required=True)
args = parser.parse_args()
input_dir, input_file = os.path.split(args.input)
output_path = os.path.abspath(args.output)
subprocess.check_call([
args.objcopy,
'-I',
'binary',
'-O',
BFD_TARGET[args.arch],
'-B',
BFD_ARCH[args.arch],
input_file,
output_path,
],
cwd=input_dir)
if __name__ == '__main__':
sys.exit(main())