Hash :
92b16ea2
Author :
Date :
2018-12-12T17:06:47
Re-land: Compress symbols for libraries Reintroduce commit ffda3e2985f18f4ff6e3778af8b9715109b21ad0. 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. Fix https://crbug.com/916751 introduced by Compress symbol support CL ffda3e2985f18f4ff6e3778af8b9715109b21ad0. Bug: angleproject:2981 Change-Id: I8d3ef8e9f0ed44bdd24290f6cd56ba674b79f98c Reviewed-on: https://chromium-review.googlesource.com/c/1387344 Reviewed-by: Yuly Novikov <ynovikov@chromium.org> Commit-Queue: Courtney Goeltzenleuchter <courtneygo@google.com>
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 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())