From 0dba86f80d162e3498cbb0f6b9dd2c26d554f5da Mon Sep 17 00:00:00 2001 From: steven Date: Tue, 28 Oct 2008 09:58:55 +0000 Subject: [PATCH] use -whole-archive linker flag when linking a shared library with static libraries --- infrastructure/build/libtool | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/infrastructure/build/libtool b/infrastructure/build/libtool index d974114a281..aa4c294a44d 100755 --- a/infrastructure/build/libtool +++ b/infrastructure/build/libtool @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $OpenBSD: libtool,v 1.27 2008/10/27 10:34:18 steven Exp $ +# $OpenBSD: libtool,v 1.28 2008/10/28 09:58:55 steven Exp $ # Copyright (c) 2007-2008 Steven Mestdagh # @@ -1070,22 +1070,29 @@ sub linkcmds create_symlinks($ltdir, \@libfiles); map { $_ = "$ltdir/". basename $_ } @libfiles; print "symlinks to libfiles used for linking: @libfiles\n" if $D; + my $prev_was_archive = 0; + my $libcounter = 0; foreach my $k (@finalorderedlibs) { my $a = $libs{$k}; if ($a =~ m/\.a$/) { # don't make a -lfoo out of a static library if ($lmode == LIBRARY) { - # extract objects from archive - my $libfile = basename $a; - my $xdir = "$odir/$ltdir/${la}x/$libfile"; - extract_archive($xdir, $a); - my @kobjs = get_objlist_from_archive($a); - map { $_ = "$xdir/$_"; } @kobjs; - push @libflags, @kobjs; - } elsif ($lmode == PROGRAM) { - push @libflags, $a; + if (!$prev_was_archive) { + push @libflags, '-Wl,-whole-archive'; + } } + push @libflags, $a; + if ($lmode == LIBRARY) { + if ($libcounter == @finalorderedlibs - 1) { + push @libflags, '-Wl,-no-whole-archive'; + } + } + $prev_was_archive = 1; } else { + if ($prev_was_archive) { + push @libflags, '-Wl,-no-whole-archive'; + } + $prev_was_archive = 0; my $lib = basename $a; if ($lib =~ m/^lib(.*)\.so(\.\d+){2}/) { $lib = $1; @@ -1095,6 +1102,7 @@ sub linkcmds } push @libflags, "-l$lib"; } + $libcounter++; } $cmd = "$ltprog";