Apply the fix for Linux from fb5e6cda96bd9dcae9e4f62ec8b6b3e572a32743
to the non-Linux cases.

-export-symbols was implemented using --retain-symbols-file. For
non-exported symbols this flag tries to remove symbol information
altogether which it can only do if a symbol isn't referenced
anywhere. So, often this flag doesn't do anything. With a version
script non-exported symbols can be marked local instead of removed.

* m4/libtool.m4: Fix -export-symbols for GNU ld on non-Linux.
---
 m4/libtool.m4 | 35 ++++++++++++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 5 deletions(-)

diff --git a/m4/libtool.m4 b/m4/libtool.m4
index 20527f83..5e6a283b 100644
--- a/m4/libtool.m4
+++ b/m4/libtool.m4
@@ -5192,7 +5192,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~
+         $SED "s/.*/_&;/" $export_symbols >> $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)
@@ -5280,7 +5285,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~
+           $SED "s/$/;/" $export_symbols >> $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
       ;;
 
@@ -5299,7 +5309,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~
+           $SED "s/$/;/" $export_symbols >> $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
@@ -5328,7 +5343,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~
+               $SED "s/$/;/" $export_symbols >> $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
@@ -5346,7 +5366,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~
+           $SED "s/$/;/" $export_symbols >> $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
-- 
2.43.0

Reply via email to