crazy linker: convert relocation unpacking to Android style.

Replace relocation unpacking code with functions that understand
the packing format generated by the Android relocation packer.

Switch to using the Android relocation packer when packing during
build.

BUG=385553

Review URL: https://codereview.chromium.org/1072533002

Cr-Original-Commit-Position: refs/heads/master@{#333293}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: e5acfbccce659364606758b687b90488e2f44be2
This commit is contained in:
simonb 2015-06-08 11:11:26 -07:00 коммит произвёл Commit bot
Родитель 3f274ff1ab
Коммит 30992e0da3
4 изменённых файлов: 19 добавлений и 61 удалений

Просмотреть файл

@ -95,8 +95,8 @@
}],
['target_arch == "arm" or target_arch == "arm64"', {
'dependencies': [
# The relocation packer only works on ARM or ARM64.
'../tools/relocation_packer/relocation_packer.gyp:relocation_packer_unittests#host',
# The relocation packer is currently used only for ARM or ARM64.
'../third_party/android_platform/relocation_packer.gyp:android_relocation_packer_unittests#host',
],
}],
],

Просмотреть файл

@ -4,17 +4,14 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Pack ARM relative relocations in a library (or copy unchanged).
"""Pack relocations in a library (or copy unchanged).
If --enable-packing and --configuration-name=='Release', invoke the
relocation_packer tool to pack the .rel.dyn or .rela.dyn section in the given
library files. This step is inserted after the libraries are stripped.
Packing adds a new .android.rel.dyn or .android.rela.dyn section to the file
and reduces the size of .rel.dyn or .rela.dyn accordingly.
Currently packing only understands ARM32 shared libraries. For all other
architectures --enable-packing should be set to zero. In this case the
script copies files verbatim, with no attempt to pack relative relocations.
If --enable-packing is zero, the script copies files verbatim, with no
attempt to pack relocations.
Any library listed in --exclude-packing-list is also copied verbatim,
irrespective of any --enable-packing setting. Typically this would be
@ -30,32 +27,13 @@ import tempfile
from util import build_utils
def PackArmLibraryRelocations(android_pack_relocations,
android_objcopy,
has_relocations_with_addends,
library_path,
output_path):
# Select an appropriate name for the section we add.
if has_relocations_with_addends:
new_section = '.android.rela.dyn'
else:
new_section = '.android.rel.dyn'
# Copy and add a 'NULL' packed relocations section for the packing tool.
with tempfile.NamedTemporaryFile() as stream:
stream.write('NULL')
stream.flush()
objcopy_command = [android_objcopy,
'--add-section', '%s=%s' % (new_section, stream.name),
library_path, output_path]
build_utils.CheckOutput(objcopy_command)
# Pack R_ARM_RELATIVE relocations.
def PackLibraryRelocations(android_pack_relocations, library_path, output_path):
shutil.copy(library_path, output_path)
pack_command = [android_pack_relocations, output_path]
build_utils.CheckOutput(pack_command)
def CopyArmLibraryUnchanged(library_path, output_path):
def CopyLibraryUnchanged(library_path, output_path):
shutil.copy(library_path, output_path)
@ -75,16 +53,11 @@ def main(args):
choices=['0', '1'],
help=('Pack relocations if 1 and configuration name is \'Release\','
' otherwise plain file copy'))
parser.add_option('--has-relocations-with-addends',
choices=['0', '1'],
help=('Pack into \'.android.rela.dyn\' if 1, else \'.android.rel.dyn\''))
parser.add_option('--exclude-packing-list',
default='',
help='Names of any libraries explicitly not packed')
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')
help='Path to the relocations packer binary')
parser.add_option('--stripped-libraries-dir',
help='Directory for stripped libraries')
parser.add_option('--packed-libraries-dir',
@ -96,7 +69,6 @@ def main(args):
options, _ = parser.parse_args(args)
enable_packing = (options.enable_packing == '1' and
options.configuration_name == 'Release')
has_relocations_with_addends = (options.has_relocations_with_addends == '1')
exclude_packing_set = set(shlex.split(options.exclude_packing_list))
libraries = []
@ -114,13 +86,11 @@ def main(args):
options.packed_libraries_dir, os.path.basename(library))
if enable_packing and library not in exclude_packing_set:
PackArmLibraryRelocations(options.android_pack_relocations,
options.android_objcopy,
has_relocations_with_addends,
PackLibraryRelocations(options.android_pack_relocations,
library_path,
output_path)
else:
CopyArmLibraryUnchanged(library_path, output_path)
CopyLibraryUnchanged(library_path, output_path)
if options.depfile:
build_utils.WriteDepfile(

Просмотреть файл

@ -3,7 +3,7 @@
# found in the LICENSE file.
# This file is meant to be included into an action to provide a rule that
# packs ARM relative relocations in Release builds of native libraries.
# packs relocations in Release builds of native libraries.
#
# To use this, create a gyp target with the following form:
# {
@ -25,13 +25,6 @@
{
'variables': {
'input_paths': [],
'conditions': [
['target_arch == "arm64"', {
'has_relocations_with_addends': 1,
}, {
'has_relocations_with_addends': 0,
}],
],
},
'inputs': [
'<(DEPTH)/build/android/gyp/util/build_utils.py',
@ -44,21 +37,19 @@
],
'conditions': [
['enable_packing == 1', {
'message': 'Packing ARM relative relocations for <(_target_name)',
'message': 'Packing relocations for <(_target_name)',
'dependencies': [
'<(DEPTH)/tools/relocation_packer/relocation_packer.gyp:relocation_packer#host',
'<(DEPTH)/third_party/android_platform/relocation_packer.gyp:android_relocation_packer#host',
],
'inputs': [
'<(PRODUCT_DIR)/relocation_packer',
'<(PRODUCT_DIR)/android_relocation_packer',
],
'action': [
'python', '<(DEPTH)/build/android/gyp/pack_arm_relocations.py',
'--configuration-name=<(CONFIGURATION_NAME)',
'--enable-packing=1',
'--has-relocations-with-addends=<(has_relocations_with_addends)',
'--exclude-packing-list=<@(exclude_packing_list)',
'--android-pack-relocations=<(PRODUCT_DIR)/relocation_packer',
'--android-objcopy=<(android_objcopy)',
'--android-pack-relocations=<(PRODUCT_DIR)/android_relocation_packer',
'--stripped-libraries-dir=<(stripped_libraries_dir)',
'--packed-libraries-dir=<(packed_libraries_dir)',
'--libraries=@FileArg(<(ordered_libraries_file):libraries)',

Просмотреть файл

@ -5,8 +5,8 @@
import("//base/android/linker/config.gni")
import("//build/config/android/config.gni")
import("//build/config/android/internal_rules.gni")
import("//third_party/android_platform/config.gni")
import("//tools/grit/grit_rule.gni")
import("//tools/relocation_packer/config.gni")
assert(is_android)
@ -1572,12 +1572,9 @@ template("android_apk") {
"--depfile",
rebase_path(depfile, root_build_dir),
"--enable-packing=$enable_packing_arg",
"--has-relocations-with-addends=$relocations_have_addends",
"--exclude-packing-list=$skip_packing_list",
"--android-pack-relocations",
rebase_path(relocation_packer_exe, root_build_dir),
"--android-objcopy",
rebase_path(android_objcopy, root_build_dir),
"--stripped-libraries-dir",
rebase_path(root_build_dir, root_build_dir),
"--packed-libraries-dir",