3 Copyright (c) 2011-2013 ARM Limited
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
18 Utility to find which libraries could define a given symbol
20 from argparse import ArgumentParser
21 from os.path import join, splitext
23 from subprocess import Popen, PIPE
26 OBJ_EXT = ['.o', '.a', '.ar']
29 def find_sym_in_lib(sym, obj_path):
30 contain_symbol = False
32 out = Popen(["nm", "-C", obj_path], stdout=PIPE, stderr=PIPE).communicate()[0]
33 for line in out.splitlines():
46 # This object is using this symbol, not defining it
55 def find_sym_in_path(sym, dir_path):
56 for root, _, files in walk(dir_path):
59 _, ext = splitext(file)
60 if ext not in OBJ_EXT: continue
62 path = join(root, file)
63 if find_sym_in_lib(sym, path):
67 if __name__ == '__main__':
68 parser = ArgumentParser(description='Find Symbol')
69 parser.add_argument('-s', '--sym', required=True,
70 help='The symbol to be searched')
71 parser.add_argument('-p', '--path', required=True,
72 help='The path where to search')
73 args = parser.parse_args()
75 find_sym_in_path(args.sym, args.path)