Home | History | Annotate | Download | only in utils
      1 #!/usr/bin/perl -w
      2 #
      3 # Program:  findsym.pl
      4 #
      5 # Synopsis: Generate a list of the libraries in which a symbol is defined or
      6 #           referenced.
      7 #
      8 # Syntax:   findsym.pl <directory_with_libraries_in_it> <symbol>
      9 #
     10 
     11 # Give first option a name.
     12 my $Directory = $ARGV[0];
     13 my $Symbol = $ARGV[1];
     14 
     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));
     21 
     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";
     31   }
     32   close SYMS;
     33 }
     34