Hi, all. The patch below makes libtool remove -lstdc++ when -lestdc++ exists. This is needed to fix another poppler linking issue, and likely some other ports that get both -lstdc++ and -lestdc++ linked in (which is bad by definition).
A side effect of this patch could/should be some stdc++ entries in WANTLIB becoming extra ones. So, in theory, this _is_ a package contents change. But PLIST_DB doesn't register checksums of files, so this doesn't affect bulk builds themselves. aja@ kindly put this in a bulk build, and there were no regressions. So... okay? To be honest, the patch won't help when either -lstdc++ or -lestdc++ is implied by the compiler. There are some crazy ideas, like: * Pass LIBTOOL_CXXLIB=estdc++ from ports framework when "estdc++" is found in any of WANTLIB* entries; * Patch ld(1) instead of libtool; * Ask David Blaine for a special magic; and so on, discussion is open. :) -- WBR, Vadim Zhukov Index: LT/UList.pm =================================================================== RCS file: /cvs/src/usr.bin/libtool/LT/UList.pm,v retrieving revision 1.2 diff -u -p -r1.2 UList.pm --- LT/UList.pm 20 Apr 2014 17:34:26 -0000 1.2 +++ LT/UList.pm 19 Dec 2016 08:34:15 -0000 @@ -63,6 +63,8 @@ sub TIEARRAY { # returned by tie() or tied() instead. sub exists { return exists $_[0]->[0]->{$_[1]}; } +sub indexof { return exists($_[0]->[0]->{$_[1]}) ? ($_[0]->[0]->{$_[1]} - 1) : undef; } + sub FETCHSIZE { return scalar(@{$_[0]}) - 1; } # not needed @@ -144,8 +146,30 @@ sub SPLICE $length = $maxrm; } - # do not ever dream of adding items here - my @ret = splice(@$self, $offset, $length); + my $i = @$self; + + # make sure no duplicates get added + @_ = grep { !exists $self->[0] or + $self->[0]->{$_} >= $offset && + $self->[0]->{$_} < $offset + $length } @_; + + for (@_) { + # set up index + $self->[0]->{$_} = $i++; + } + + # + # Renumber (in advance) trailing items, in case something gets added + # and number of added and removed items differs. + # + my $delta = scalar(@_) - $length; + if (scalar(@_) and $delta) { + for $i ($offset + $length .. scalar(@$self)) { + $self->[0]->{$self->[$i]} += $delta; + } + } + + my @ret = splice(@$self, $offset, $length, @_); for (@ret) { delete $self->[0]->{$_}; Index: LT/Mode/Link.pm =================================================================== RCS file: /cvs/src/usr.bin/libtool/LT/Mode/Link.pm,v retrieving revision 1.33 diff -u -p -r1.33 Link.pm --- LT/Mode/Link.pm 3 Nov 2016 10:23:01 -0000 1.33 +++ LT/Mode/Link.pm 19 Dec 2016 08:34:15 -0000 @@ -822,6 +822,20 @@ sub common1 my $staticlibs = []; my $args = $parser->parse_linkargs2($gp, $orderedlibs, $staticlibs, $dirs, $libs); + my $tiedlibs = tied(@$orderedlibs); + my $ie = $tiedlibs->indexof("estdc++"); + my $is = $tiedlibs->indexof("stdc++"); + if (defined($ie) and defined($is)) { + tsay {"stripping stdc++ from orderedlibs due to having estdc++ already; ie=$ie, is=$is"}; + # check what library comes later + if ($ie < $is) { + splice(@$orderedlibs, $ie, 1); + splice(@$orderedlibs, $is, 1, "estdc++"); + $ie = $is; + } else { + splice(@$orderedlibs, $is, 1); + } + } tsay {"staticlibs = \n", join("\n", @$staticlibs)}; tsay {"orderedlibs = @$orderedlibs"}; return ($staticlibs, $orderedlibs, $args);