blob: 0d9d2eeb8e5ae4bc0a934176f62917d19e521a68 [file] [log] [blame]
Eric Fiselier2d9feb52015-03-20 22:09:29 +00001#!/usr/bin/env python
Eric Fiseliera9e91f32016-01-19 21:58:49 +00002#===----------------------------------------------------------------------===##
3#
4# The LLVM Compiler Infrastructure
5#
6# This file is dual licensed under the MIT and the University of Illinois Open
7# Source Licenses. See LICENSE.TXT for details.
8#
9#===----------------------------------------------------------------------===##
Eric Fiselier2d9feb52015-03-20 22:09:29 +000010"""
11sym_extract - Extract and output a list of symbols from a shared library.
12"""
13from argparse import ArgumentParser
Eric Fiselier11477532017-02-09 22:53:14 +000014from libcxx.sym_check import extract, util
Eric Fiselier2d9feb52015-03-20 22:09:29 +000015
16
17def main():
18 parser = ArgumentParser(
19 description='Extract a list of symbols from a shared library.')
20 parser.add_argument('library', metavar='shared-lib', type=str,
21 help='The library to extract symbols from')
22 parser.add_argument('-o', '--output', dest='output',
23 help='The output file. stdout is used if not given',
24 type=str, action='store', default=None)
25 parser.add_argument('--names-only', dest='names_only',
26 help='Output only the name of the symbol',
27 action='store_true', default=False)
Eric Fiselier0d694182016-11-18 01:40:20 +000028 parser.add_argument('--only-stdlib-symbols', dest='only_stdlib',
29 help="Filter all symbols not related to the stdlib",
30 action='store_true', default=False)
Eric Fiselier2d9feb52015-03-20 22:09:29 +000031 args = parser.parse_args()
32 if args.output is not None:
33 print('Extracting symbols from %s to %s.'
34 % (args.library, args.output))
35 syms = extract.extract_symbols(args.library)
Eric Fiselier0d694182016-11-18 01:40:20 +000036 if args.only_stdlib:
37 syms, other_syms = util.filter_stdlib_symbols(syms)
Eric Fiselier2d9feb52015-03-20 22:09:29 +000038 util.write_syms(syms, out=args.output, names_only=args.names_only)
39
40
41if __name__ == '__main__':
42 main()