summaryrefslogtreecommitdiff
path: root/usr.bin/libtool/LT
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2012-11-09 10:55:02 +0000
committerMarc Espie <espie@cvs.openbsd.org>2012-11-09 10:55:02 +0000
commit135b5eff57ee95cea68b13c919d7fae2a881bbb8 (patch)
tree5a223f1e9726043e0d324cb97f7f448f6a0d1ff0 /usr.bin/libtool/LT
parentff1f0b7a67c7c04921cfbf3b9b99994a564fdaef (diff)
*really* filter symbols on elf systems: introduce a new "export_symbols"
method that does all the work to produce the right options (one option, so that the *.ver file contains all useful information). Have to cater to regexp: in particular, make sure to nm on every object and static library we might need, so we don't lose anything. Allow for the result to be empty (since some projects use -export-symbols-regex everywhere, *including on binaries with empty symbol lists*) should now be clean portswise. As usual, a non working option means lots of weird fuck-ups to fix first... thx to millert@ for the hint, aja,jasper,landry for comments and testing.
Diffstat (limited to 'usr.bin/libtool/LT')
-rw-r--r--usr.bin/libtool/LT/Mode/Link.pm42
-rw-r--r--usr.bin/libtool/LT/Mode/Link/Library.pm15
-rw-r--r--usr.bin/libtool/LT/Mode/Link/Program.pm18
3 files changed, 52 insertions, 23 deletions
diff --git a/usr.bin/libtool/LT/Mode/Link.pm b/usr.bin/libtool/LT/Mode/Link.pm
index 6e5ad1f225a..5b34eb45004 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.22 2012/08/27 11:00:27 espie Exp $
+# $OpenBSD: Link.pm,v 1.23 2012/11/09 10:55:01 espie Exp $
#
# Copyright (c) 2007-2010 Steven Mestdagh <steven@openbsd.org>
# Copyright (c) 2012 Marc Espie <espie@openbsd.org>
@@ -802,5 +802,45 @@ sub infer_libparameter
return "-l$lib";
}
+sub export_symbols
+{
+ my ($self, $ltconfig, $base, $gp, @o) = @_;
+ my $symbolsfile;
+ my $comment;
+ if ($gp->export_symbols) {
+ $symbolsfile = $gp->export_symbols;
+ $comment = "/* version script derived from $symbolsfile */\n\n";
+ } elsif ($gp->export_symbols_regex) {
+ ($symbolsfile = $base) =~ s/\.la$/.exp/;
+ LT::Archive->get_symbollist($symbolsfile, $gp->export_symbols_regex, \@o);
+ $comment = "/* version script generated from\n * ".join(' ', @o)."\n * using regexp ".$gp->export_symbols_regex. " */\n\n";
+ } else {
+ return ();
+ }
+ my $scriptfile;
+ ($scriptfile = $base) =~ s/(\.la)?$/.ver/;
+ if ($ltconfig->{elf}) {
+ open my $fh, ">", $scriptfile or die;
+ open my $fh2, '<', $symbolsfile or die;
+ print $fh $comment;
+ print $fh "{\n";
+ my $first = 1;
+ while (<$fh2>) {
+ chomp;
+ if ($first) {
+ print $fh "\tglobal:\n";
+ $first = 0;
+ }
+ print $fh "\t\t$_;\n";
+ }
+ print $fh "\tlocal:\n\t\t\*;\n};\n";
+ close($fh);
+ close($fh2);
+ return ("--version-script", $scriptfile);
+ } else {
+ return ("-retain-symbols-file", $symbolsfile);
+ }
+}
+
1;
diff --git a/usr.bin/libtool/LT/Mode/Link/Library.pm b/usr.bin/libtool/LT/Mode/Link/Library.pm
index 62a32a49c6b..8a18d059010 100644
--- a/usr.bin/libtool/LT/Mode/Link/Library.pm
+++ b/usr.bin/libtool/LT/Mode/Link/Library.pm
@@ -1,4 +1,4 @@
-# $OpenBSD: Library.pm,v 1.1 2012/07/13 11:56:13 espie Exp $
+# $OpenBSD: Library.pm,v 1.2 2012/11/09 10:55:01 espie Exp $
# Copyright (c) 2007-2010 Steven Mestdagh <steven@openbsd.org>
# Copyright (c) 2012 Marc Espie <espie@openbsd.org>
@@ -99,14 +99,6 @@ sub link
return;
}
- # dynamic linking
- my $symbolsfile;
- if ($gp->export_symbols) {
- $symbolsfile = $gp->export_symbols;
- } elsif ($gp->export_symbols_regex) {
- ($symbolsfile = "$odir/$ltdir/$la") =~ s/\.la$/.exp/;
- LT::Archive->get_symbollist($symbolsfile, $gp->export_symbols_regex, $objs);
- }
my $tmp = [];
while (my $k = shift @$finalorderedlibs) {
my $l = $libs->{$k};
@@ -155,7 +147,10 @@ sub link
push @cmd, '-Wl,-whole-archive', @$staticlibs, '-Wl,-no-whole-archive'
if @$staticlibs;
push @cmd, "-L$symlinkdir", @libflags if @libflags;
- push @cmd, "-Wl,-retain-symbols-file,$symbolsfile" if $symbolsfile;
+
+ my @e = $linker->export_symbols($ltconfig,
+ "$odir/$ltdir/$la", $gp, @$objs, @$staticlibs);
+ push(@cmd, join(',', "-Wl", @e)) if @e;
LT::Exec->link(@cmd);
}
diff --git a/usr.bin/libtool/LT/Mode/Link/Program.pm b/usr.bin/libtool/LT/Mode/Link/Program.pm
index 30c8aa95d38..e9e57f7e932 100644
--- a/usr.bin/libtool/LT/Mode/Link/Program.pm
+++ b/usr.bin/libtool/LT/Mode/Link/Program.pm
@@ -1,4 +1,4 @@
-# $OpenBSD: Program.pm,v 1.2 2012/08/27 11:02:46 espie Exp $
+# $OpenBSD: Program.pm,v 1.3 2012/11/09 10:55:01 espie Exp $
# Copyright (c) 2007-2010 Steven Mestdagh <steven@openbsd.org>
# Copyright (c) 2012 Marc Espie <espie@openbsd.org>
@@ -68,13 +68,6 @@ sub link
$dst = ($odir eq '.') ? $fname : "$odir/$fname";
}
- my $symbolsfile;
- if ($gp->export_symbols) {
- $symbolsfile = $gp->export_symbols;
- } elsif ($gp->export_symbols_regex) {
- ($symbolsfile = "$odir/$ltdir/$fname") =~ s/\.la$/.exp/;
- LT::Archive->get_symbollist($symbolsfile, $gp->export_symbols_regex, $self->{objlist});
- }
$libdirs = reverse_zap_duplicates_ref($libdirs);
my $rpath_link = {};
# add libdirs to rpath if they are not in standard lib path
@@ -118,9 +111,10 @@ sub link
push(@linkeropts, '-rpath-link', $d);
}
}
- if ($symbolsfile) {
- push(@linkeropts, '-retain-symbols-file', $symbolsfile);
- }
+
+ push(@linkeropts, $linker->export_symbols($ltconfig,
+ "$odir/$ltdir/$fname", $gp, @{$self->{objlist}}, @$staticlibs));
+
@cmd = @$ltprog;
push @cmd, '-o', $dst;
push @cmd, '-pthread' if $parser->{pthread};
@@ -128,7 +122,7 @@ sub link
push @cmd, @{$self->{objlist}} if @{$self->{objlist}};
push @cmd, @$staticlibs if @$staticlibs;
push @cmd, "-L$symlinkdir", @libflags if @libflags;
- push @cmd, '-Wl,'. join(',', @linkeropts) if @linkeropts;
+ push @cmd, join(',', '-Wl', @linkeropts) if @linkeropts;
LT::Exec->link(@cmd);
}
1;