summaryrefslogtreecommitdiff
path: root/usr.bin/libtool/LT
diff options
context:
space:
mode:
authorVadim Zhukov <zhuk@cvs.openbsd.org>2014-04-27 18:08:36 +0000
committerVadim Zhukov <zhuk@cvs.openbsd.org>2014-04-27 18:08:36 +0000
commita3d82ae85f68ae70732722cefdbfe336a0448433 (patch)
tree661edf7cc7663b119eb46571e24e0de7e29eebf4 /usr.bin/libtool/LT
parent5850cbb766de0c7fb98b6c86613f3cf698b22b91 (diff)
Fix library search order in our libtool.
Before, libtool first searched all directories for .la files, and if search failed, switched to actual libraries (.so/.a). But the correct way is to check each directory first for .la, then for .so/.a. The problem was reported by ajacoutot@ who verified that the patch fixes his case and okay'ed the initial diff. And jasper@'s bulk uncovered a bug which is fixed now (verified by another bulk).
Diffstat (limited to 'usr.bin/libtool/LT')
-rw-r--r--usr.bin/libtool/LT/LaFile.pm23
-rw-r--r--usr.bin/libtool/LT/Mode/Link.pm55
2 files changed, 55 insertions, 23 deletions
diff --git a/usr.bin/libtool/LT/LaFile.pm b/usr.bin/libtool/LT/LaFile.pm
index 90f11b5117f..641cb650c74 100644
--- a/usr.bin/libtool/LT/LaFile.pm
+++ b/usr.bin/libtool/LT/LaFile.pm
@@ -1,4 +1,4 @@
-# $OpenBSD: LaFile.pm,v 1.21 2014/04/16 10:31:27 zhuk Exp $
+# $OpenBSD: LaFile.pm,v 1.22 2014/04/27 18:08:35 zhuk Exp $
# Copyright (c) 2007-2010 Steven Mestdagh <steven@openbsd.org>
# Copyright (c) 2012 Marc Espie <espie@openbsd.org>
@@ -126,22 +126,17 @@ sub write_shared_libs_log
# XXX pick the right one if multiple are found!
sub find
{
- my ($self, $l, $dirs) = @_;
-
- # search in cwd as well
- unshift @$dirs, '.';
- tsay {"searching .la for $l"};
- tsay {"search path= ", join(':', @$dirs)};
- foreach my $d (@$dirs) {
- foreach my $la_candidate ("$d/lib$l.la", "$d/$l.la") {
- if (-f $la_candidate) {
- tsay {"found $la_candidate"};
- return $la_candidate;
- }
+ my ($self, $l, $sd) = @_;
+
+ tsay {"searching .la for $l in $sd"};
+ foreach my $la_candidate ("$sd/lib$l.la", "$sd/$l.la") {
+ if (-f $la_candidate) {
+ tsay {"found $la_candidate"};
+ return $la_candidate;
}
}
tsay {".la for $l not found!"};
- return 0;
+ return undef;
}
sub install
diff --git a/usr.bin/libtool/LT/Mode/Link.pm b/usr.bin/libtool/LT/Mode/Link.pm
index 6f38e5fd978..bb7c13b0348 100644
--- a/usr.bin/libtool/LT/Mode/Link.pm
+++ b/usr.bin/libtool/LT/Mode/Link.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Link.pm,v 1.28 2014/04/20 17:34:26 zhuk Exp $
+# $OpenBSD: Link.pm,v 1.29 2014/04/27 18:08:35 zhuk Exp $
#
# Copyright (c) 2007-2010 Steven Mestdagh <steven@openbsd.org>
# Copyright (c) 2012 Marc Espie <espie@openbsd.org>
@@ -510,6 +510,37 @@ sub resolve_la
$self->{args} = $o->{result};
}
+# Find first library or .la file for given library name.
+# Returns pair of (type, file path), or empty list on error.
+sub find_first_lib
+{
+ my ($self, $lib, $dirs, $gp) = @_;
+
+ my $name = $lib->{key};
+ require LT::LaFile;
+
+ push(@$dirs, $gp->libsearchdirs) if $gp;
+ for my $sd(".", @$dirs) {
+ my $file = LT::LaFile->find($name, $sd);
+ tsay {" LT::LaFile->find($name, $sd) returned \"$file\""} if defined $file;
+ return ('LT::LaFile', $file) if defined $file;
+
+ $file = $lib->findbest($sd, $name);
+ if (defined $file) {
+ tsay {"found $name in $sd"};
+ return ('LT::Library', $file);
+ } else {
+ # XXX find static library instead?
+ $file = "$sd/lib$name.a";
+ if (-f $file) {
+ tsay {"found static $name in $sd"};
+ return ('LT::Library', $file);
+ }
+ }
+ }
+ return ();
+}
+
# parse link flags and arguments
# eliminate all -L and -l flags in the argument string and add the
# corresponding directories and library names to the dirs/libs hashes.
@@ -562,25 +593,31 @@ sub internal_parse_linkargs1
my $key = $1;
if (!exists $libs->{$key}) {
$libs->create($key);
- require LT::LaFile;
- my $lafile = LT::LaFile->find($key, $dirs);
- if ($lafile) {
- $libs->{$key}->{lafile} = $lafile;
- my $absla = abs_path($lafile);
+ my ($type, $file) = $self->find_first_lib($libs->{$key}, $dirs, $gp);
+ if (!defined $type) {
+ say "warning: could not find a $key library";
+ next;
+ } elsif ($type eq 'LT::LaFile') {
+ my $absla = abs_path($file);
+ $libs->{$key}->{lafile} = $absla;
tsay {" adding $absla to deplibs"}
if $level == 0;
push(@$deplibs, $absla);
- push(@$result, $lafile);
+ push(@$result, $file);
next;
- } else {
- $libs->{$key}->resolve_library($dirs, 1, 0, 'notyet', $gp);
+ } elsif ($type eq 'LT::Library') {
+ $libs->{$key}->{fullpath} = $file;
my @deps = $libs->{$key}->inspect;
foreach my $d (@deps) {
my $k = basename($d);
+ # XXX will fail for (_pic)?\.a$
$k =~ s/^(\S+)\.so.*$/$1/;
$k =~ s/^lib//;
push(@largs, "-l$k");
}
+ } else {
+ die "internal error: unsupported" .
+ " library type \"$type\"";
}
}
tsay {" adding $arg to deplibs"} if $level == 0;