File: ldd.pl

package info (click to toggle)
libpar-packer-perl 1.064-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,388 kB
  • sloc: perl: 12,774; ansic: 1,474; makefile: 30; sh: 5
file content (63 lines) | stat: -rw-r--r-- 1,502 bytes parent folder | download | duplicates (4)
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
#!perl

use strict;
use warnings;

sub is_system_lib;

sub find_files_to_embed
{
    my ($par, $libperl) = @_;

    if ($^O =~ /cygwin/i)
    {
        chomp(my $system_root = qx( cygpath --unix '$ENV{SYSTEMROOT}' ));
        print STDERR "### SystemRoot (as Unix path) = $system_root\n";
        *is_system_lib = sub { shift =~ m{^/usr/bin/(?!cygcrypt\b)|^\Q$system_root\E/}i }; 
        # NOTE: cygcrypt-0.dll is not (anymore) in the set of default Cygwin packages
    }
    else
    {
        *is_system_lib = sub { shift =~ m{^(?:/usr)?/lib(?:32|64)?/} };
    }

    my $dlls = ldd($par); 

    # weed out system libs (but exclude the shared perl lib)
    foreach my $name (keys %$dlls)
    {
        delete $dlls->{$name} if is_system_lib($dlls->{$name}) && $name !~ /perl/;
    }

    return $dlls;
}

sub ldd
{
    my ($file) = @_;

    my $out = qx(ldd $file);
    die qq["ldd $file" failed\n] unless $? == 0;

    # NOTE: On older Linux/glibc (e.g. seen on Linux 3.2.0/glibc 2.13)
    # ldd prints a line like
    #    linux-vdso.so.1 =>  (0x00007fffd2ff2000)
    # (without a pathname between "=>" and the address)
    # while newer versions omit "=>" in this case.
    my %dlls = $out =~ /^ \s* (\S+) \s* => \s* ( \/ \S+ ) /gmx;

    foreach my $name (keys %dlls)
    {
        my $path = $dlls{$name};
        unless (-e $path)
        {
            warn qq[# ldd reported strange path: $path\n];
            delete $dlls{$name};
            next;
        }
    }

    return \%dlls;
}

1;