Chromium Code Reviews| Index: components/cronet/tools/hide_symbols.py |
| diff --git a/components/cronet/tools/hide_symbols.py b/components/cronet/tools/hide_symbols.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..7a21652d58fb361419da5d94e81ba462e4d523fc |
| --- /dev/null |
| +++ b/components/cronet/tools/hide_symbols.py |
| @@ -0,0 +1,88 @@ |
| +#!/usr/bin/env python |
| + |
| +# Copyright 2017 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. |
| + |
| +# Create a static library which exposes only symbols which are explicitly marked |
| +# as visible e.g., by __attribute__((visibility("default"))). |
| +# |
| +# See BUILD.gn in this directory for usage example. |
| +# |
| +# This way, we can reduce risk of symbol conflict when linking it into apps |
| +# by exposing internal symbols, especially in third-party libraries. |
| + |
| +import optparse |
| +import os |
| +import subprocess |
| + |
| + |
| +# Mapping from GN's target_cpu attribute to ld's -arch parameter. |
| +# Taken from the definition of config("compiler") in: |
| +# //build/config/mac/BUILD.gn |
| +GN_CPU_TO_LD_ARCH = { |
| + 'x64': 'x86_64', |
| + 'x86': 'i386', |
| + 'armv7': 'armv7', |
| + 'arm': 'armv7', |
| + 'arm64': 'arm64', |
| +} |
| + |
| + |
| +def main(): |
| + parser = optparse.OptionParser() |
| + parser.add_option( |
| + '--input_libs', |
| + help='Comma-separated paths to input .a files which contain symbols ' |
| + 'which must be always linked.') |
| + parser.add_option( |
| + '--deps_lib', |
| + help='The path to a complete static library (.a file) which contains all ' |
| + 'dependencies of --input_libs. .o files in this library are also ' |
| + 'added to the output library, but only if they are referred from ' |
| + '--input_libs.') |
| + parser.add_option( |
| + '--output_obj', |
| + help='Outputs the generated .o file here. This is an intermediate file.') |
| + parser.add_option( |
| + '--output_lib', |
| + help='Outputs the generated .a file here.') |
| + parser.add_option( |
| + '--current_cpu', |
| + help='The current processor architecture in the format of the target_cpu ' |
| + 'attribute in GN.') |
| + (options, args) = parser.parse_args() |
| + assert not args |
| + |
| + # ld -r concatenates multiple .o files and .a files into a single .o file, |
| + # while "hiding" symbols not marked as visible. |
| + command = [ |
| + 'xcrun', 'ld', |
| + '-arch', GN_CPU_TO_LD_ARCH[options.current_cpu], |
|
mef
2017/04/11 21:05:09
This gets an error in debug simulator build:
ld:
Hiroshi Ichikawa
2017/04/12 04:35:25
Does it happen only on trybot, or does it happen o
mef
2017/04/12 15:57:50
It happens locally, but only for one configuration
|
| + '-r', |
| + ] |
| + for input_lib in options.input_libs.split(','): |
| + # By default, ld only pulls .o files out of a static library if needed to |
| + # resolve some symbol reference. We apply -force_load option to input_lib |
| + # (but not to deps_lib) to force pulling all .o files. |
| + command += ['-force_load', input_lib] |
| + command += [ |
| + options.deps_lib, |
| + '-o', options.output_obj |
| + ] |
| + subprocess.check_call(command) |
| + |
| + if os.path.exists(options.output_lib): |
| + os.remove(options.output_lib) |
| + |
| + # Creates a .a file which contains a single .o file. |
| + command = [ |
| + 'xcrun', 'ar', '-r', |
| + options.output_lib, |
| + options.output_obj, |
| + ] |
| + subprocess.check_call(command) |
| + |
| + |
| +if __name__ == "__main__": |
| + main() |