findsym.pl 832 B

123456789101112131415161718192021222324252627282930313233
  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. # Give first option a name.
  11. my $Directory = $ARGV[0];
  12. my $Symbol = $ARGV[1];
  13. # Open the directory and read its contents, sorting by name and differentiating
  14. # by whether its a library (.a) or an object file (.o)
  15. opendir DIR,$Directory;
  16. my @files = readdir DIR;
  17. closedir DIR;
  18. @objects = grep(/l?i?b?LLVM.*\.[oa]$/,sort(@files));
  19. # Gather definitions from the libraries
  20. foreach $lib (@objects) {
  21. my $head = 0;
  22. open SYMS,
  23. "nm $Directory/$lib | grep '$Symbol' | sort --key=3 | uniq |";
  24. while (<SYMS>) {
  25. if (!$head) { print "$lib:\n"; $head = 1; }
  26. chomp($_);
  27. print " $_\n";
  28. }
  29. close SYMS;
  30. }