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