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