Fixed some bugs.
[llvm/zpu.git] / utils / findsym.pl
blob92346572fe01670167297427bafdee003e38af4d
1 #!/usr/bin/perl -w
3 # Program: findsym.pl
5 # Synopsis: Generate a list of the libraries in which a symbol is defined or
6 # referenced.
8 # Syntax: findsym.pl <directory_with_libraries_in_it> <symbol>
11 # Give first option a name.
12 my $Directory = $ARGV[0];
13 my $Symbol = $ARGV[1];
15 # Open the directory and read its contents, sorting by name and differentiating
16 # by whether its a library (.a) or an object file (.o)
17 opendir DIR,$Directory;
18 my @files = readdir DIR;
19 closedir DIR;
20 @objects = grep(/l?i?b?LLVM.*\.[oa]$/,sort(@files));
22 # Gather definitions from the libraries
23 foreach $lib (@objects) {
24 my $head = 0;
25 open SYMS,
26 "nm $Directory/$lib | grep '$Symbol' | sort --key=3 | uniq |";
27 while (<SYMS>) {
28 if (!$head) { print "$lib:\n"; $head = 1; }
29 chomp($_);
30 print " $_\n";
32 close SYMS;