mirror of
https://github.com/clearlinux/swupd-client.git
synced 2026-05-13 18:23:51 +00:00
Fixes #448 Make a number of functions static, and bodge around the extra symbol that gcc adds (__gnu_lto_v1) when compiling with -flto=4 Signed-off-by: Icarus Sparry <icarus.w.sparry@intel.com>
85 lines
2.1 KiB
Perl
85 lines
2.1 KiB
Perl
#!/usr/bin/perl -w
|
|
# find a list of fns and variables in the code that could be static
|
|
# usually called with something like this:
|
|
# findstatic.pl `find . -name "*.o"`
|
|
# Andrew Tridgell <tridge@samba.org>
|
|
|
|
use strict;
|
|
|
|
# use nm to find the symbols
|
|
my($saved_delim) = $/;
|
|
undef $/;
|
|
my($syms) = `nm -o @ARGV`;
|
|
$/ = $saved_delim;
|
|
|
|
my(@lines) = split(/\n/s, $syms);
|
|
|
|
# The design of this code expects there to be one definition
|
|
# for each variable and multiple references. This just doesn't
|
|
# work for "common" variables, which are declared multiple times
|
|
# and lets the linker merge them.
|
|
# In particular gcc creates a common variable __gnu_lto_v1 when invoked
|
|
# with -flto for each file. So we pretend that we have a use for this variable.
|
|
push(@lines, "MAGICRUNTIME: U __gnu_lto_v1");
|
|
push(@lines, "MAGICRUNTIME: U __gnu_lto_slim");
|
|
|
|
my(%def);
|
|
my(%undef);
|
|
my(%stype);
|
|
|
|
my(%typemap) = (
|
|
"T" => "function",
|
|
"C" => "uninitialised variable",
|
|
"D" => "initialised variable"
|
|
);
|
|
|
|
|
|
# parse the symbols into defined and undefined
|
|
for (my($i)=0; $i <= $#lines; $i++) {
|
|
my($line) = $lines[$i];
|
|
if ($line =~ /(.*):[a-f0-9]* ([TCD]) (.*)/) {
|
|
my($fname) = $1;
|
|
my($symbol) = $3;
|
|
push(@{$def{$fname}}, $symbol);
|
|
$stype{$symbol} = $2;
|
|
}
|
|
if ($line =~ /(.*):\s* U (.*)/) {
|
|
my($fname) = $1;
|
|
my($symbol) = $2;
|
|
push(@{$undef{$fname}}, $symbol);
|
|
}
|
|
}
|
|
|
|
# look for defined symbols that are never referenced outside the place they
|
|
# are defined
|
|
foreach my $f (keys %def) {
|
|
print "Checking $f\n";
|
|
my($found_one) = 0;
|
|
foreach my $s (@{$def{$f}}) {
|
|
my($found) = 0;
|
|
foreach my $f2 (keys %undef) {
|
|
if ($f2 ne $f) {
|
|
foreach my $s2 (@{$undef{$f2}}) {
|
|
if ($s2 eq $s) {
|
|
$found = 1;
|
|
$found_one = 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ($found == 0) {
|
|
my($t) = $typemap{$stype{$s}};
|
|
if ($s eq 'main') {
|
|
# special case: main program
|
|
$found_one = 1;
|
|
} else {
|
|
print " '$s' is unique to $f, should be static? ($t)\n";
|
|
}
|
|
}
|
|
}
|
|
if ($found_one == 0) {
|
|
print " all symbols in '$f' are unused (main program?)\n";
|
|
}
|
|
}
|
|
|