Compress symbols for libraries

Android requires system libraries to include symbols to aid
debugging. This CL will compress and attach the symbols from the
unstripped .so and add it to the stripped .so that goes in the apk
when building a release build.

Bug: angleproject:2981
Change-Id: I51c315627b9183e49b509c27df506bf99bf45f30
Reviewed-on: https://chromium-review.googlesource.com/c/1376270
Commit-Queue: Courtney Goeltzenleuchter <courtneygo@google.com>
Reviewed-by: Yuly Novikov <ynovikov@chromium.org>
This commit is contained in:
Courtney Goeltzenleuchter 2018-12-12 17:06:47 -07:00 коммит произвёл Commit Bot
Родитель 4638dc9def
Коммит ffda3e2985
3 изменённых файлов: 210 добавлений и 14 удалений

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

@ -10,6 +10,7 @@ import("//testing/libfuzzer/fuzzer_test.gni")
import("gni/angle.gni")
if (is_android) {
# android/rules.gni can only be imported for Android targets
import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")
import("android/angle_apk.gni")
}
@ -805,6 +806,46 @@ source_set("libEGL_egl_loader") {
]
}
if (is_android && symbol_level != 0) {
action_foreach("compressed_symbols") {
sources = [
"${root_out_dir}/libEGL${angle_libs_suffix}.so",
"${root_out_dir}/libGLESv1_CM${angle_libs_suffix}.so",
"${root_out_dir}/libGLESv2${angle_libs_suffix}.so",
"${root_out_dir}/libfeature_support${angle_libs_suffix}.so",
]
script = rebase_path("${root_build_dir}/android/compress_symbols.py",
root_build_dir)
deps = [
"//third_party/angle:libEGL${angle_libs_suffix}",
"//third_party/angle:libGLESv1_CM${angle_libs_suffix}",
"//third_party/angle:libGLESv2${angle_libs_suffix}",
"//third_party/angle:libfeature_support${angle_libs_suffix}",
]
outputs = [
"$root_out_dir/lib.compressed/{{source_file_part}}",
]
android_nm = "${android_tool_prefix}nm"
args = [
"--objcopy",
rebase_path(android_objcopy, root_build_dir),
"--nm",
rebase_path(android_nm, root_build_dir),
"--sofile",
"{{source}}",
"--unstrippedsofile",
"{{source_dir}}/lib.unstripped/{{source_file_part}}",
"--output",
"{{source_dir}}/lib.compressed/{{source_file_part}}",
]
}
}
shared_library("libEGL${angle_libs_suffix}") {
sources = libegl_sources
@ -1036,7 +1077,7 @@ shared_library("libfeature_support${angle_libs_suffix}") {
]
}
if (is_android) {
if (is_android && current_toolchain == default_toolchain) {
# Package ANGLE libraries for pre-installed system image
angle_apk("aosp_apk") {
package_name = "com.android.angle"

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

@ -43,25 +43,52 @@ template("angle_apk") {
"//third_party/android_deps:android_support_v14_preference_java",
"//third_party/android_deps:android_support_v7_preference_java",
]
if (symbol_level != 0) {
deps += [ ":compressed_symbols" ]
if (build_apk_secondary_abi && android_64bit_target_cpu) {
deps += [ ":compressed_symbols($android_secondary_abi_toolchain)" ]
}
}
uncompress_shared_libraries = true
if (build_apk_secondary_abi && android_64bit_target_cpu) {
secondary_abi_shared_libraries = [
"//third_party/angle:libEGL${angle_libs_suffix}($android_secondary_abi_toolchain)",
"//third_party/angle:libGLESv1_CM${angle_libs_suffix}($android_secondary_abi_toolchain)",
"//third_party/angle:libGLESv2${angle_libs_suffix}($android_secondary_abi_toolchain)",
"//third_party/angle:libfeature_support${angle_libs_suffix}" +
"($android_secondary_abi_toolchain)",
]
if (symbol_level == 0) {
secondary_abi_shared_libraries = [
"//third_party/angle:libEGL${angle_libs_suffix}($android_secondary_abi_toolchain)",
"//third_party/angle:libGLESv1_CM${angle_libs_suffix}($android_secondary_abi_toolchain)",
"//third_party/angle:libGLESv2${angle_libs_suffix}($android_secondary_abi_toolchain)",
"//third_party/angle:libfeature_support${angle_libs_suffix}" +
"($android_secondary_abi_toolchain)",
]
} else {
_secondary_out_dir = get_label_info(
":compressed_symbols($android_secondary_abi_toolchain)",
"root_out_dir")
secondary_abi_loadable_modules = [
"$_secondary_out_dir/lib.compressed/libEGL${angle_libs_suffix}.so",
"$_secondary_out_dir/lib.compressed/libGLESv1_CM${angle_libs_suffix}.so",
"$_secondary_out_dir/lib.compressed/libGLESv2${angle_libs_suffix}.so",
"$_secondary_out_dir/lib.compressed/libfeature_support${angle_libs_suffix}.so",
]
}
}
shared_libraries = [
"//third_party/angle:libEGL${angle_libs_suffix}",
"//third_party/angle:libGLESv1_CM${angle_libs_suffix}",
"//third_party/angle:libGLESv2${angle_libs_suffix}",
"//third_party/angle:libfeature_support${angle_libs_suffix}",
]
if (symbol_level == 0) {
shared_libraries = [
"//third_party/angle:libEGL${angle_libs_suffix}",
"//third_party/angle:libGLESv1_CM${angle_libs_suffix}",
"//third_party/angle:libGLESv2${angle_libs_suffix}",
"//third_party/angle:libfeature_support${angle_libs_suffix}",
]
} else {
loadable_modules = [
"$root_out_dir/lib.compressed/libEGL${angle_libs_suffix}.so",
"$root_out_dir/lib.compressed/libGLESv1_CM${angle_libs_suffix}.so",
"$root_out_dir/lib.compressed/libGLESv2${angle_libs_suffix}.so",
"$root_out_dir/lib.compressed/libfeature_support${angle_libs_suffix}.so",
]
}
# Common files required by all builds
java_files = [

128
android/compress_symbols.py Executable file
Просмотреть файл

@ -0,0 +1,128 @@
#!/usr/bin/env python
# Copyright 2018 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Generate library file with compressed symbols per Android build
# process.
#
import argparse
import os
import subprocess
import sys
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
'--objcopy',
required=True,
help='The objcopy binary to run',
metavar='PATH')
parser.add_argument(
'--nm', required=True, help='The nm binary to run', metavar='PATH')
parser.add_argument(
'--sofile',
required=True,
help='Shared object file produced by linking command',
metavar='FILE')
parser.add_argument(
'--output',
required=True,
help='Final output shared object file',
metavar='FILE')
parser.add_argument(
'--unstrippedsofile',
required=True,
help='Unstripped shared object file produced by linking command',
metavar='FILE')
args = parser.parse_args()
copy_cmd = ["cp", args.sofile, args.output]
result = subprocess.call(copy_cmd)
objcopy_cmd = [args.objcopy]
objcopy_cmd.append('--only-keep-debug')
objcopy_cmd.append(args.unstrippedsofile)
objcopy_cmd.append(args.output + '.debug')
result = subprocess.call(objcopy_cmd)
nm_cmd = subprocess.Popen(
[args.nm, args.unstrippedsofile, '--format=posix', '--defined-only'],
stdout=subprocess.PIPE)
awk_cmd = subprocess.Popen(['awk', '{ print $1}'],
stdin=nm_cmd.stdout,
stdout=subprocess.PIPE)
dynsym_out = open(args.output + '.dynsyms', 'w')
sort_cmd = subprocess.Popen(['sort'], stdin=awk_cmd.stdout, stdout=dynsym_out)
dynsym_out.close()
nm_cmd = subprocess.Popen(
[args.nm, args.unstrippedsofile, '--format=posix', '--defined-only'],
stdout=subprocess.PIPE)
awk_cmd = subprocess.Popen(
['awk', '{ if ($2 == "T" || $2 == "t" ||' + ' $2 == "D") print $1 }'],
stdin=nm_cmd.stdout,
stdout=subprocess.PIPE)
funcsyms_out = open(args.output + '.funcsyms', 'w')
sort_cmd = subprocess.Popen(['sort'],
stdin=awk_cmd.stdout,
stdout=funcsyms_out)
funcsyms_out.close()
keep_symbols = open(args.output + '.keep_symbols', 'w')
sort_cmd = subprocess.Popen(
['comm', '-13', args.output + '.dynsyms', args.output + '.funcsyms'],
stdin=awk_cmd.stdout,
stdout=keep_symbols)
# Ensure that the keep_symbols file is not empty.
keep_symbols.write("\n")
keep_symbols.close()
objcopy_cmd = [
args.objcopy, '--rename-section', '.debug_frame=saved_debug_frame',
args.output + '.debug', args.output + ".mini_debuginfo"
]
subprocess.check_call(objcopy_cmd)
objcopy_cmd = [
args.objcopy, '-S', '--remove-section', '.gdb_index', '--remove-section',
'.comment', '--keep-symbols=' + args.output + '.keep_symbols',
args.output + '.mini_debuginfo'
]
subprocess.check_call(objcopy_cmd)
objcopy_cmd = [
args.objcopy, '--rename-section', '.saved_debug_frame=.debug_frame',
args.output + ".mini_debuginfo"
]
subprocess.check_call(objcopy_cmd)
xz_cmd = ['xz', args.output + '.mini_debuginfo']
subprocess.check_call(xz_cmd)
objcopy_cmd = [
args.objcopy, '--add-section',
'.gnu_debugdata=' + args.output + '.mini_debuginfo.xz', args.output
]
subprocess.check_call(objcopy_cmd)
# Clean out scratch files
rm_cmd = [
'rm', '-f', args.output + '.dynsyms', args.output + '.funcsyms',
args.output + '.keep_symbols', args.output + '.debug',
args.output + '.mini_debuginfo', args.output + '.mini_debuginfo.xz'
]
result = subprocess.call(rm_cmd)
return result
if __name__ == "__main__":
sys.exit(main())