blob: 156e8830ed4d5801e099aed7aae0981091b119fe [file] [log] [blame]
Eric Fiselierfdea4b42015-03-20 22:09:29 +00001#!/usr/bin/env python
Eric Fiselier120ec472016-01-19 21:58:49 +00002#===----------------------------------------------------------------------===##
3#
Chandler Carruthd2012102019-01-19 10:56:40 +00004# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5# See https://llvm.org/LICENSE.txt for license information.
6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Eric Fiselier120ec472016-01-19 21:58:49 +00007#
8#===----------------------------------------------------------------------===##
Eric Fiselierfdea4b42015-03-20 22:09:29 +00009"""
10sym_extract - Extract and output a list of symbols from a shared library.
11"""
12from argparse import ArgumentParser
Eric Fiselier569ea5b2017-02-09 22:53:14 +000013from libcxx.sym_check import extract, util
Eric Fiselierfdea4b42015-03-20 22:09:29 +000014
15
16def main():
17 parser = ArgumentParser(
18 description='Extract a list of symbols from a shared library.')
19 parser.add_argument('library', metavar='shared-lib', type=str,
20 help='The library to extract symbols from')
21 parser.add_argument('-o', '--output', dest='output',
22 help='The output file. stdout is used if not given',
23 type=str, action='store', default=None)
24 parser.add_argument('--names-only', dest='names_only',
25 help='Output only the name of the symbol',
26 action='store_true', default=False)
Eric Fiselierc10332f2016-11-18 01:40:20 +000027 parser.add_argument('--only-stdlib-symbols', dest='only_stdlib',
28 help="Filter all symbols not related to the stdlib",
29 action='store_true', default=False)
Eric Fiselierfdea4b42015-03-20 22:09:29 +000030 args = parser.parse_args()
31 if args.output is not None:
32 print('Extracting symbols from %s to %s.'
33 % (args.library, args.output))
34 syms = extract.extract_symbols(args.library)
Eric Fiselierc10332f2016-11-18 01:40:20 +000035 if args.only_stdlib:
36 syms, other_syms = util.filter_stdlib_symbols(syms)
Eric Fiselierfdea4b42015-03-20 22:09:29 +000037 util.write_syms(syms, out=args.output, names_only=args.names_only)
38
39
40if __name__ == '__main__':
41 main()