Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: tools/relocation_packer/test_data/generate_elf_file_unittest_relocs.py

Issue 670183003: Update from chromium 62675d9fb31fb8cedc40f68e78e8445a74f362e7 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # Copyright 2014 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 """Build relocation packer unit test data.
8
9 Uses a built relocation packer to generate 'golden' reference test data
10 files for elf_file_unittests.cc.
11 """
12
13 import optparse
14 import os
15 import shutil
16 import subprocess
17 import sys
18 import tempfile
19
20 def PackArmLibraryRelocations(android_pack_relocations,
21 android_objcopy,
22 added_section,
23 input_path,
24 output_path):
25 # Copy and add a 'NULL' .android.rel.dyn section for the packing tool.
26 with tempfile.NamedTemporaryFile() as stream:
27 stream.write('NULL')
28 stream.flush()
29 objcopy_command = [android_objcopy,
30 '--add-section', '%s=%s' % (added_section, stream.name),
31 input_path, output_path]
32 subprocess.check_call(objcopy_command)
33
34 # Pack relocations.
35 pack_command = [android_pack_relocations, output_path]
36 subprocess.check_call(pack_command)
37
38
39 def UnpackArmLibraryRelocations(android_pack_relocations,
40 input_path,
41 output_path):
42 shutil.copy(input_path, output_path)
43
44 # Unpack relocations. We leave the .android.rel.dyn or .android.rela.dyn
45 # in place.
46 unpack_command = [android_pack_relocations, '-u', output_path]
47 subprocess.check_call(unpack_command)
48
49
50 def main():
51 parser = optparse.OptionParser()
52
53 parser.add_option('--android-pack-relocations',
54 help='Path to the ARM relocations packer binary')
55 parser.add_option('--android-objcopy',
56 help='Path to the toolchain\'s objcopy binary')
57 parser.add_option('--added-section',
58 choices=['.android.rel.dyn', '.android.rela.dyn'],
59 help='Section to add, one of ".android.rel.dyn" or ".android.rela.dyn"')
60 parser.add_option('--test-file',
61 help='Path to the input test file, an unpacked ARM .so')
62 parser.add_option('--unpacked-output',
63 help='Path to the output file for reference unpacked data')
64 parser.add_option('--packed-output',
65 help='Path to the output file for reference packed data')
66
67 options, _ = parser.parse_args()
68
69 for output in [options.unpacked_output, options.packed_output]:
70 directory = os.path.dirname(output)
71 if not os.path.exists(directory):
72 os.makedirs(directory)
73
74 PackArmLibraryRelocations(options.android_pack_relocations,
75 options.android_objcopy,
76 options.added_section,
77 options.test_file,
78 options.packed_output)
79
80 UnpackArmLibraryRelocations(options.android_pack_relocations,
81 options.packed_output,
82 options.unpacked_output)
83
84 return 0
85
86
87 if __name__ == '__main__':
88 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698