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

Unified 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, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: tools/relocation_packer/test_data/generate_elf_file_unittest_relocs.py
diff --git a/tools/relocation_packer/test_data/generate_elf_file_unittest_relocs.py b/tools/relocation_packer/test_data/generate_elf_file_unittest_relocs.py
new file mode 100755
index 0000000000000000000000000000000000000000..e71b5cbbdc1681414be208a539f95b673b6e4a20
--- /dev/null
+++ b/tools/relocation_packer/test_data/generate_elf_file_unittest_relocs.py
@@ -0,0 +1,88 @@
+#!/usr/bin/env python
+#
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Build relocation packer unit test data.
+
+Uses a built relocation packer to generate 'golden' reference test data
+files for elf_file_unittests.cc.
+"""
+
+import optparse
+import os
+import shutil
+import subprocess
+import sys
+import tempfile
+
+def PackArmLibraryRelocations(android_pack_relocations,
+ android_objcopy,
+ added_section,
+ input_path,
+ output_path):
+ # Copy and add a 'NULL' .android.rel.dyn section for the packing tool.
+ with tempfile.NamedTemporaryFile() as stream:
+ stream.write('NULL')
+ stream.flush()
+ objcopy_command = [android_objcopy,
+ '--add-section', '%s=%s' % (added_section, stream.name),
+ input_path, output_path]
+ subprocess.check_call(objcopy_command)
+
+ # Pack relocations.
+ pack_command = [android_pack_relocations, output_path]
+ subprocess.check_call(pack_command)
+
+
+def UnpackArmLibraryRelocations(android_pack_relocations,
+ input_path,
+ output_path):
+ shutil.copy(input_path, output_path)
+
+ # Unpack relocations. We leave the .android.rel.dyn or .android.rela.dyn
+ # in place.
+ unpack_command = [android_pack_relocations, '-u', output_path]
+ subprocess.check_call(unpack_command)
+
+
+def main():
+ parser = optparse.OptionParser()
+
+ parser.add_option('--android-pack-relocations',
+ help='Path to the ARM relocations packer binary')
+ parser.add_option('--android-objcopy',
+ help='Path to the toolchain\'s objcopy binary')
+ parser.add_option('--added-section',
+ choices=['.android.rel.dyn', '.android.rela.dyn'],
+ help='Section to add, one of ".android.rel.dyn" or ".android.rela.dyn"')
+ parser.add_option('--test-file',
+ help='Path to the input test file, an unpacked ARM .so')
+ parser.add_option('--unpacked-output',
+ help='Path to the output file for reference unpacked data')
+ parser.add_option('--packed-output',
+ help='Path to the output file for reference packed data')
+
+ options, _ = parser.parse_args()
+
+ for output in [options.unpacked_output, options.packed_output]:
+ directory = os.path.dirname(output)
+ if not os.path.exists(directory):
+ os.makedirs(directory)
+
+ PackArmLibraryRelocations(options.android_pack_relocations,
+ options.android_objcopy,
+ options.added_section,
+ options.test_file,
+ options.packed_output)
+
+ UnpackArmLibraryRelocations(options.android_pack_relocations,
+ options.packed_output,
+ options.unpacked_output)
+
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main())

Powered by Google App Engine
This is Rietveld 408576698