| 1 | # Copyright © 2007, 2016 Raphaël Hertzog <hertzog@debian.org> | ||||||||||||||||||||||||||||
| 2 | # Copyright © 2007-2008, 2012-2015 Guillem Jover <guillem@debian.org> | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 5 | # it under the terms of the GNU General Public License as published by | ||||||||||||||||||||||||||||
| 6 | # the Free Software Foundation; either version 2 of the License, or | ||||||||||||||||||||||||||||
| 7 | # (at your option) any later version. | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||||||||||
| 12 | # GNU General Public License for more details. | ||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||
| 14 | # You should have received a copy of the GNU General Public License | ||||||||||||||||||||||||||||
| 15 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =encoding utf8 | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head1 NAME | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | Dpkg::Shlibs - shared library location handling | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | This module provides functions to locate shared libraries. | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | B<Note>: This is a private module, its API can change at any time. | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =cut | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | package Dpkg::Shlibs 0.03; | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 2 | ▶ | use v5.36; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 2 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 36 | blank_library_paths | ||||||||||||||||||||||||||||
| 37 | setup_library_paths | ||||||||||||||||||||||||||||
| 38 | get_library_paths | ||||||||||||||||||||||||||||
| 39 | add_library_dir | ||||||||||||||||||||||||||||
| 40 | find_library | ||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 2 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 2 | ▶ | use Dpkg::Gettext; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 47 | 2 | ▶ | use Dpkg::ErrorHandling; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 48 | 2 | ▶ | use Dpkg::Shlibs::Objdump; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | 2 | ▶ | use Dpkg::BuildAPI qw(get_build_api); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 50 | 2 | ▶ | use Dpkg::Path qw(resolve_symlink canonpath); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | 2 | ▶ | use Dpkg::Arch qw(get_build_arch get_host_arch :mappers); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 2 | ▶ | use constant DEFAULT_LIBRARY_PATH => | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | 2 | qw(/lib /usr/lib); | |||||||||||||||||||||||||||
| 55 | # XXX: Deprecated multilib paths. | ||||||||||||||||||||||||||||
| 56 | 2 | ▶ | use constant DEFAULT_MULTILIB_PATH => | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 57 | 2 | qw(/lib32 /usr/lib32 /lib64 /usr/lib64); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # Library paths set by the user. | ||||||||||||||||||||||||||||
| 60 | 2 | my @custom_librarypaths; | |||||||||||||||||||||||||||
| 61 | # Library paths from the system. | ||||||||||||||||||||||||||||
| 62 | my @system_librarypaths; | ||||||||||||||||||||||||||||
| 63 | 2 | my $librarypaths_init; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 16 | ▶ | sub parse_ldso_conf { | ||||||||||||||||||||||||||
|
Subroutine
parse_ldso_conf: called CC=10 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 66 | 16 | my $file = shift; | |||||||||||||||||||||||||||
| 67 | 16 | state %visited; | |||||||||||||||||||||||||||
| 68 | 16 | local $_; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | my %librarypath = map { | ||||||||||||||||||||||||||||
| 71 | 16 | $_ => 1 | |||||||||||||||||||||||||||
| 72 | } (@custom_librarypaths, @system_librarypaths); | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 16 | ▶ | open my $fh, '<', $file or syserr(g_('cannot open %s'), $file); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 16 | $visited{$file}++; | |||||||||||||||||||||||||||
| 76 | 16 | ▶ | while (<$fh>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 42 | ▶ | next if /^\s*$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 34 | chomp; | |||||||||||||||||||||||||||
| 79 | 34 | s{/+$}{}; | |||||||||||||||||||||||||||
| 80 | 34 | ▶ | if (/^include\s+(\S.*\S)\s*$/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 81 | 2 | ▶ | foreach my $include (glob($1)) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 82 | parse_ldso_conf($include) if -e $include | ||||||||||||||||||||||||||||
| 83 | 14 | ▶ | && ! $visited{$include}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-e $include and not $visited{$include}
MC/DC50%1/2
-e $include and not $visited{$include}
-e $include
not $visited{$include}
Truth table66%2/3
A and not(B)
A= -e $includeB= not $visited{$include}
| |||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | } elsif (m{^\s*/}) { | ||||||||||||||||||||||||||||
| 86 | 16 | my $libdir = s/^\s+//r; | |||||||||||||||||||||||||||
| 87 | 16 | ▶ | if (not exists $librarypath{$libdir}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 16 | $librarypath{$libdir} = 1; | |||||||||||||||||||||||||||
| 89 | 16 | push @system_librarypaths, $libdir; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 16 | close $fh; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 2 | ▶ | sub blank_library_paths { | ||||||||||||||||||||||||||
|
Subroutine
blank_library_paths: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 97 | 2 | @custom_librarypaths = (); | |||||||||||||||||||||||||||
| 98 | 2 | @system_librarypaths = (); | |||||||||||||||||||||||||||
| 99 | 2 | $librarypaths_init = 1; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 2 | ▶ | sub setup_library_paths { | ||||||||||||||||||||||||||
|
Subroutine
setup_library_paths: called CC=9 SCAR=25.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 103 | 2 | @custom_librarypaths = (); | |||||||||||||||||||||||||||
| 104 | 2 | @system_librarypaths = (); | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | # XXX: Deprecated. Update library paths with LD_LIBRARY_PATH. | ||||||||||||||||||||||||||||
| 107 | 2 | ▶ | if ($ENV{LD_LIBRARY_PATH}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 2 | require Cwd; | |||||||||||||||||||||||||||
| 109 | 2 | my $cwd = Cwd::getcwd; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 2 | foreach my $path (split /:/, $ENV{LD_LIBRARY_PATH}) { | |||||||||||||||||||||||||||
| 112 | 2 | $path =~ s{/+$}{}; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 2 | my $realpath = Cwd::realpath($path); | |||||||||||||||||||||||||||
| 115 | 2 | ▶ | next unless defined $realpath; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 2 | ▶ | if ($realpath =~ m/^\Q$cwd\E/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if (get_build_api() >= 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 0 | error(g_('use -l option instead of LD_LIBRARY_PATH')); | |||||||||||||||||||||||||||
| 119 | } else { | ||||||||||||||||||||||||||||
| 120 | 0 | warning(g_('deprecated use of LD_LIBRARY_PATH with private ' . | |||||||||||||||||||||||||||
| 121 | 'library directory which interferes with ' . | ||||||||||||||||||||||||||||
| 122 | 'cross-building, use -l option instead')); | ||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 2 | ▶ | next if get_build_api() >= 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | # XXX: This should be added to @custom_librarypaths, but as this | ||||||||||||||||||||||||||||
| 129 | # is deprecated we do not care as the code will go away. | ||||||||||||||||||||||||||||
| 130 | 2 | push @system_librarypaths, $path; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | # Adjust set of directories to consider during cross builds. | ||||||||||||||||||||||||||||
| 135 | 2 | ▶ | if (get_build_arch() ne get_host_arch()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 0 | my $multiarch = debarch_to_multiarch(get_host_arch()); | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 0 | push @system_librarypaths, "/lib/$multiarch", "/usr/lib/$multiarch"; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 2 | push @system_librarypaths, DEFAULT_LIBRARY_PATH; | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | # Update library paths with ld.so config. | ||||||||||||||||||||||||||||
| 144 | 2 | ▶ | parse_ldso_conf('/etc/ld.so.conf') if -e '/etc/ld.so.conf'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 2 | push @system_librarypaths, DEFAULT_MULTILIB_PATH; | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 2 | $librarypaths_init = 1; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 4 | ▶ | sub add_library_dir { | ||||||||||||||||||||||||||
|
Subroutine
add_library_dir: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 152 | 4 | my $dir = shift; | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 4 | ▶ | setup_library_paths() if not $librarypaths_init; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 4 | push @custom_librarypaths, $dir; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 6 | ▶ | sub get_library_paths { | ||||||||||||||||||||||||||
|
Subroutine
get_library_paths: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 160 | 6 | ▶ | setup_library_paths() if not $librarypaths_init; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 6 | return (@custom_librarypaths, @system_librarypaths); | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | # find_library ($soname, \@rpath, $format, $root) | ||||||||||||||||||||||||||||
| 166 | 0 | ▶ | sub find_library { | ||||||||||||||||||||||||||
|
Subroutine
find_library: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 167 | 0 | my ($lib, $rpath, $format, $root) = @_; | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | setup_library_paths() if not $librarypaths_init; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | my @librarypaths = ( | ||||||||||||||||||||||||||||
| 172 | 0 | @{$rpath}, | |||||||||||||||||||||||||||
| 173 | @custom_librarypaths, | ||||||||||||||||||||||||||||
| 174 | @system_librarypaths, | ||||||||||||||||||||||||||||
| 175 | ); | ||||||||||||||||||||||||||||
| 176 | 0 | my @libs; | |||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 0 | ▶ | $root //= ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$root //= ""
MC/DC0%0/1
$root //= ""
$root
Truth table0%0/2
A
A= $root
| |||||||||||||||||||||||||||||
| 179 | 0 | $root =~ s{/+$}{}; | |||||||||||||||||||||||||||
| 180 | 0 | foreach my $dir (@librarypaths) { | |||||||||||||||||||||||||||
| 181 | 0 | my $checkdir = "$root$dir"; | |||||||||||||||||||||||||||
| 182 | 0 | ▶ | if (-e "$checkdir/$lib") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 0 | my $libformat = Dpkg::Shlibs::Objdump::get_format("$checkdir/$lib"); | |||||||||||||||||||||||||||
| 184 | 0 | ▶ | if (not defined $libformat) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 185 | 0 | warning(g_("unknown executable format in file '%s'"), "$checkdir/$lib"); | |||||||||||||||||||||||||||
| 186 | } elsif ($format eq $libformat) { | ||||||||||||||||||||||||||||
| 187 | 0 | push @libs, canonpath("$checkdir/$lib"); | |||||||||||||||||||||||||||
| 188 | } else { | ||||||||||||||||||||||||||||
| 189 | 0 | debug(1, "Skipping lib $checkdir/$lib, libabi=<%s> != objabi=<%s>", | |||||||||||||||||||||||||||
| 190 | $libformat, $format); | ||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | 0 | return @libs; | |||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | =head1 CHANGES | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | =head2 Version 0.xx | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | This is a private module. | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | =cut | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 2 | 1; | |||||||||||||||||||||||||||