To implement -export-symbols(-regex) on non-Linux systems with GNU
ld(1) libtool currently uses the linker flag --retain-symbols-file
but this is more like a fine-grained strip(1) (.symtab table) and
does not affect what symbols are exported (.dynsym table).  On Linux
libtool uses --version-script instead.  The patch copies this to
other systems.

Libtool still uses --retain-symbols-file with other languages than
C, but also on Linux so the patch does not change any of that.

This has been tested on the FreeBSD package building cluster.  It
reduced the number of exported symbols in several libraries.  The
-export-symbols(-regex) test cases also work on FreeBSD now.
diff --git a/m4/libtool.m4 b/m4/libtool.m4
index 2e8c3cf..9192b22 100644
--- a/m4/libtool.m4
+++ b/m4/libtool.m4
@@ -5183,7 +5183,12 @@ _LT_EOF
       # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
       # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
       _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
-      _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      if test yes = "$supports_anon_versioning"; then
+	_LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
+	  cat $export_symbols | sed -e "s/\(.*\)/_\1;/" >> $output_objdir/$libname.ver~
+	  echo "local: *; };" >> $output_objdir/$libname.ver~
+	  $CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--version-script,$output_objdir/$libname.ver $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      fi
       ;;
 
     gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu)
@@ -5271,7 +5276,12 @@ _LT_EOF
 	wlarc=
       else
 	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib'
-	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib'
+	if test yes = "$supports_anon_versioning"; then
+	  _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
+	    cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+	    echo "local: *; };" >> $output_objdir/$libname.ver~
+	    $CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl--version-script $wl$output_objdir/$libname.ver -o $lib'
+	fi
       fi
       ;;
 
@@ -5290,7 +5300,12 @@ _LT_EOF
 _LT_EOF
       elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
 	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib'
-	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib'
+	if test yes = "$supports_anon_versioning"; then
+	  _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
+	    cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+	    echo "local: *; };" >> $output_objdir/$libname.ver~
+	    $CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl--version-script $wl$output_objdir/$libname.ver -o $lib'
+	fi
       else
 	_LT_TAGVAR(ld_shlibs, $1)=no
       fi
@@ -5319,7 +5334,12 @@ _LT_EOF
 	  if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
 	    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir'
 	    _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib'
-	    _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib'
+	    if test yes = "$supports_anon_versioning"; then
+	      _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
+		cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+		echo "local: *; };" >> $output_objdir/$libname.ver~
+		$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl--version-script $wl$output_objdir/$libname.ver -o $lib'
+	    fi
 	  else
 	    _LT_TAGVAR(ld_shlibs, $1)=no
 	  fi
@@ -5337,7 +5357,12 @@ _LT_EOF
     *)
       if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
 	_LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib'
-	_LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib'
+	if test yes = "$supports_anon_versioning"; then
+	  _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
+	    cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+	    echo "local: *; };" >> $output_objdir/$libname.ver~
+	    $CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl--version-script $wl$output_objdir/$libname.ver -o $lib'
+	fi
       else
 	_LT_TAGVAR(ld_shlibs, $1)=no
       fi

Reply via email to