-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathdumpdeps.pm
90 lines (75 loc) · 2.15 KB
/
dumpdeps.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Dump the dependencies of a perl program, both Perl and shared libraries for
# modules and the interpreter.
package dumpdeps;
use v5.20;
use constant LIB_IS_SYMLINK => -l "/lib";
# This is the sign of the hacks this involves, LWP for example does a lot of
# require on demand. Various other tools don't fully load things either. In
# general things fail pretty obviously with module not found errors.
my %additional_requires = (
"LWP/UserAgent.pm" => [qw(HTTP::Headers::Util LWP::Authen::Basic HTTP::Request::Common HTML::HeadParser HTTP::Config File::Temp Encode Encode::Locale LWP::Protocol::http LWP::Protocol::https)],
"URI.pm" => [qw(URI/_foreign.pm URI::data URI::file URI::http URI::https)],
"Plack/Runner.pm" => [qw(Getopt::Long Getopt::Long::Parser Plack::Loader Socket POSIX Carp)],
);
our $x;
sub new {
return bless {}, shift;
}
sub DESTROY {
say $0;
for my $module (keys %::INC) {
if (exists $additional_requires{$module}) {
eval "require $_" for @{$additional_requires{$module}};
}
}
for (values %::INC) {
say if -f;
}
my %seen;
# loaded shared libraries + mmaped data, etc.
{
open my $fh, "<", "/proc/self/maps" or die $!;
while(<$fh>) {
if (m{ (/.*?)$}) {
say $1 unless $seen{$1}++;
}
}
}
# ldd deps (will in most cases pick up symlinks, which we try to also resolve below).
{
open my $fh, "-|", "ldd", $^X or die $!;
while(<$fh>) {
if (m{\s(/.*?) \(}) {
my $l = $1;
$l =~ s{^/lib}{/usr/lib} if LIB_IS_SYMLINK;
say $l unless $seen{$l}++;
}
}
}
for (keys %seen) {
if (LIB_IS_SYMLINK) {
if (m{^(/usr?)/lib/}) {
say "/lib" unless $seen{"/lib"}++;
} elsif (m{^(/usr)?/lib64/}) {
say "/lib64" unless $seen{"/lib64"}++;
}
}
if (m{^(.*\.so)\.([0-9.]+)$}) {
my $l = $1;
my $v = $2;
if ($v =~ /\./) {
my @parts = split /\./, $v;
for my $i (1 .. @parts) {
my $solib = "$l." . join(".", @parts[0 .. $i-1]);
if (-e $solib) {
say $solib unless $seen{$solib}++;
}
}
}
}
}
}
BEGIN {
$x = __PACKAGE__->new;
}
1;