1*58b9f456SAndroid Build Coastguard Worker#!/usr/bin/env python 2*58b9f456SAndroid Build Coastguard Worker#===----------------------------------------------------------------------===## 3*58b9f456SAndroid Build Coastguard Worker# 4*58b9f456SAndroid Build Coastguard Worker# The LLVM Compiler Infrastructure 5*58b9f456SAndroid Build Coastguard Worker# 6*58b9f456SAndroid Build Coastguard Worker# This file is dual licensed under the MIT and the University of Illinois Open 7*58b9f456SAndroid Build Coastguard Worker# Source Licenses. See LICENSE.TXT for details. 8*58b9f456SAndroid Build Coastguard Worker# 9*58b9f456SAndroid Build Coastguard Worker#===----------------------------------------------------------------------===## 10*58b9f456SAndroid Build Coastguard Worker""" 11*58b9f456SAndroid Build Coastguard Workersym_extract - Extract and output a list of symbols from a shared library. 12*58b9f456SAndroid Build Coastguard Worker""" 13*58b9f456SAndroid Build Coastguard Workerfrom argparse import ArgumentParser 14*58b9f456SAndroid Build Coastguard Workerfrom libcxx.sym_check import extract, util 15*58b9f456SAndroid Build Coastguard Worker 16*58b9f456SAndroid Build Coastguard Worker 17*58b9f456SAndroid Build Coastguard Workerdef main(): 18*58b9f456SAndroid Build Coastguard Worker parser = ArgumentParser( 19*58b9f456SAndroid Build Coastguard Worker description='Extract a list of symbols from a shared library.') 20*58b9f456SAndroid Build Coastguard Worker parser.add_argument('library', metavar='shared-lib', type=str, 21*58b9f456SAndroid Build Coastguard Worker help='The library to extract symbols from') 22*58b9f456SAndroid Build Coastguard Worker parser.add_argument('-o', '--output', dest='output', 23*58b9f456SAndroid Build Coastguard Worker help='The output file. stdout is used if not given', 24*58b9f456SAndroid Build Coastguard Worker type=str, action='store', default=None) 25*58b9f456SAndroid Build Coastguard Worker parser.add_argument('--names-only', dest='names_only', 26*58b9f456SAndroid Build Coastguard Worker help='Output only the name of the symbol', 27*58b9f456SAndroid Build Coastguard Worker action='store_true', default=False) 28*58b9f456SAndroid Build Coastguard Worker parser.add_argument('--only-stdlib-symbols', dest='only_stdlib', 29*58b9f456SAndroid Build Coastguard Worker help="Filter all symbols not related to the stdlib", 30*58b9f456SAndroid Build Coastguard Worker action='store_true', default=False) 31*58b9f456SAndroid Build Coastguard Worker args = parser.parse_args() 32*58b9f456SAndroid Build Coastguard Worker if args.output is not None: 33*58b9f456SAndroid Build Coastguard Worker print('Extracting symbols from %s to %s.' 34*58b9f456SAndroid Build Coastguard Worker % (args.library, args.output)) 35*58b9f456SAndroid Build Coastguard Worker syms = extract.extract_symbols(args.library) 36*58b9f456SAndroid Build Coastguard Worker if args.only_stdlib: 37*58b9f456SAndroid Build Coastguard Worker syms, other_syms = util.filter_stdlib_symbols(syms) 38*58b9f456SAndroid Build Coastguard Worker util.write_syms(syms, out=args.output, names_only=args.names_only) 39*58b9f456SAndroid Build Coastguard Worker 40*58b9f456SAndroid Build Coastguard Worker 41*58b9f456SAndroid Build Coastguard Workerif __name__ == '__main__': 42*58b9f456SAndroid Build Coastguard Worker main() 43