diff mbox series

lto-plugin: Use GNU ld or Solaris ld version script in preference to -export-symbols-regex [PR102426]

Message ID YjmUJam2HTHZuUTX@tucnak
State New
Headers show
Series lto-plugin: Use GNU ld or Solaris ld version script in preference to -export-symbols-regex [PR102426] | expand

Commit Message

Jakub Jelinek March 22, 2022, 9:17 a.m. UTC
Hi!

As reported, libtool -export-symbols-regex doesn't work on Solaris
when using GNU ld instead of Sun ld, libtool just always assumes Sun ld.
As I'm unsure what is the maintainance status of libtool right now,
this patch solves it on the lto-plugin side instead, tests at configure time
similar way how libssp and other target libraries test for symbol versioning
(except omitting the symbol version because we just want one GLOBAL symbol
and rest of them LOCAL), and will use the current way of
-export-symbols-regex onload as fallback when this doesn't work.

Bootstrapped/regtested on x86_64-linux and i686-linux (where it now uses
the GNU versioning instead of -export-symbols-regex onload).
Ok for trunk if it works for Rainer too (both Sun and GNU ld)?

2022-03-22  Jakub Jelinek  <jakub@redhat.com>

	PR lto/102426
	* configure.ac (LTO_PLUGIN_USE_SYMVER, LTO_PLUGIN_USE_SYMVER_GNU,
	LTO_PLUGIN_USE_SYMVER_SUN): New test for symbol versioning support.
	* Makefile.am (version_arg, version_dep): Set conditionally based
	on LTO_PLUGIN_USE_SYMVER*.
	(liblto_plugin_la_LDFLAGS): Use $(version_arg) instead of
	-export-symbols-regex onload.
	(liblto_plugin_la_DEPENDENCIES): Depend on $(version_dep).
	* lto-plugin.map: New file.
	* configure: Regenerated.
	* Makefile.in: Regenerated.


	Jakub

Comments

Rainer Orth March 22, 2022, 9:28 a.m. UTC | #1
Hi Jakub,

> As reported, libtool -export-symbols-regex doesn't work on Solaris
> when using GNU ld instead of Sun ld, libtool just always assumes Sun ld.
> As I'm unsure what is the maintainance status of libtool right now,

as it happens, libtool 2.4.7 has just been released on 2022-03-16 after
a hiatus of more than 5 years.  Whatever that means for future
maintenance...

> this patch solves it on the lto-plugin side instead, tests at configure time
> similar way how libssp and other target libraries test for symbol versioning
> (except omitting the symbol version because we just want one GLOBAL symbol
> and rest of them LOCAL), and will use the current way of
> -export-symbols-regex onload as fallback when this doesn't work.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux (where it now uses
> the GNU versioning instead of -export-symbols-regex onload).
> Ok for trunk if it works for Rainer too (both Sun and GNU ld)?

It did without any issues: tested on i386-pc-solaris2.11 (gas/ld and
gas/gld) and sparc-sun-solaris2.11 (gas/ld).

	Rainer
Richard Biener March 22, 2022, 9:33 a.m. UTC | #2
> Am 22.03.2022 um 10:28 schrieb Rainer Orth <ro@cebitec.uni-bielefeld.de>:
> 
> Hi Jakub,
> 
>> As reported, libtool -export-symbols-regex doesn't work on Solaris
>> when using GNU ld instead of Sun ld, libtool just always assumes Sun ld.
>> As I'm unsure what is the maintainance status of libtool right now,
> 
> as it happens, libtool 2.4.7 has just been released on 2022-03-16 after
> a hiatus of more than 5 years.  Whatever that means for future
> maintenance...
> 
>> this patch solves it on the lto-plugin side instead, tests at configure time
>> similar way how libssp and other target libraries test for symbol versioning
>> (except omitting the symbol version because we just want one GLOBAL symbol
>> and rest of them LOCAL), and will use the current way of
>> -export-symbols-regex onload as fallback when this doesn't work.
>> 
>> Bootstrapped/regtested on x86_64-linux and i686-linux (where it now uses
>> the GNU versioning instead of -export-symbols-regex onload).
>> Ok for trunk if it works for Rainer too (both Sun and GNU ld)?
> 
> It did without any issues: tested on i386-pc-solaris2.11 (gas/ld and
> gas/gld) and sparc-sun-solaris2.11 (gas/ld).

Ok.

>    Rainer
> 
> -- 
> -----------------------------------------------------------------------------
> Rainer Orth, Center for Biotechnology, Bielefeld University
diff mbox series

Patch

--- lto-plugin/configure.ac.jj	2020-04-27 09:11:14.431603556 +0200
+++ lto-plugin/configure.ac	2022-03-21 14:42:05.913555824 +0100
@@ -50,6 +50,43 @@  AC_SUBST(real_target_noncanonical)
 # Determine what GCC version number to use in filesystem paths.
 GCC_BASE_VER
 
+AC_MSG_CHECKING([whether symbol versioning is supported])
+lto_plugin_use_symver=no
+if test x$gcc_no_link = xyes; then
+  # If we cannot link, we cannot build shared libraries, so do not use
+  # symbol versioning.
+  lto_plugin_use_symver=no
+else
+  save_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS -fPIC -shared -Wl,--version-script,./conftest.map"
+  cat > conftest.map <<EOF
+{
+  global: *foo*; bar; local: *;
+};
+EOF
+  AC_TRY_LINK([int foo;],[],[lto_plugin_use_symver=gnu],[lto_plugin_use_symver=no])
+  if test x$lto_plugin_use_symver = xno; then
+    case "$target_os" in
+      solaris2*)
+	LDFLAGS="$save_LDFLAGS"
+	LDFLAGS="$LDFLAGS -fPIC -shared -Wl,-M,./conftest.map"
+	# Sun ld cannot handle wildcards and treats all entries as undefined.
+	cat > conftest.map <<EOF
+{
+  global: foo; local: *;
+};
+EOF
+	AC_TRY_LINK([int foo;],[],[lto_plugin_use_symver=sun],[lto_plugin_use_symver=no])
+	  ;;
+    esac
+  fi
+  LDFLAGS="$save_LDFLAGS"
+fi
+AC_MSG_RESULT($lto_plugin_use_symver)
+AM_CONDITIONAL(LTO_PLUGIN_USE_SYMVER, [test "x$lto_plugin_use_symver" != xno])
+AM_CONDITIONAL(LTO_PLUGIN_USE_SYMVER_GNU, [test "x$lto_plugin_use_symver" = xgnu])
+AM_CONDITIONAL(LTO_PLUGIN_USE_SYMVER_SUN, [test "x$lto_plugin_use_symver" = xsun])
+
 AM_PROG_LIBTOOL
 ACX_LT_HOST_FLAGS
 AC_SUBST(target_noncanonical)
--- lto-plugin/Makefile.am.jj	2021-12-30 15:12:44.466133110 +0100
+++ lto-plugin/Makefile.am	2022-03-21 14:53:47.084888889 +0100
@@ -18,11 +18,24 @@  libexecsub_LTLIBRARIES = liblto_plugin.l
 gcc_build_dir = @gcc_build_dir@
 in_gcc_libs = $(foreach lib, $(libexecsub_LTLIBRARIES), $(gcc_build_dir)/$(lib))
 
+if LTO_PLUGIN_USE_SYMVER
+if LTO_PLUGIN_USE_SYMVER_GNU
+version_arg = -Wl,--version-script=$(srcdir)/lto-plugin.map
+endif
+if LTO_PLUGIN_USE_SYMVER_SUN
+version_arg = -Wl,-M,$(srcdir)/lto-plugin.map
+endif
+version_dep = $(srcdir)/lto-plugin.map
+else
+version_arg = -export-symbols-regex onload
+version_dep =
+endif
+
 liblto_plugin_la_SOURCES = lto-plugin.c
 # Note that we intentionally override the bindir supplied by ACX_LT_HOST_FLAGS.
 liblto_plugin_la_LDFLAGS = $(AM_LDFLAGS) \
 	$(lt_host_flags) -module -avoid-version -bindir $(libexecsubdir) \
-	-export-symbols-regex onload
+	$(version_arg)
 # Can be simplified when libiberty becomes a normal convenience library.
 libiberty = $(with_libiberty)/libiberty.a
 libiberty_noasan = $(with_libiberty)/noasan/libiberty.a
@@ -36,7 +49,8 @@  liblto_plugin_la_LDFLAGS += \
 	$(if $(wildcard $(libiberty_pic)),,-Wc,$(libiberty)))
 liblto_plugin_la_DEPENDENCIES = \
 	$(if $(wildcard $(libiberty_noasan)),$(libiberty_noasan), \
-	$(if $(wildcard $(libiberty_pic)),$(libiberty_pic),))
+	$(if $(wildcard $(libiberty_pic)),$(libiberty_pic),)) \
+	$(version_dep)
 LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS))
 liblto_plugin_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
 	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
--- lto-plugin/lto-plugin.map.jj	2022-03-21 14:44:17.558740855 +0100
+++ lto-plugin/lto-plugin.map	2022-03-21 14:45:26.915784640 +0100
@@ -0,0 +1,3 @@ 
+{
+  global: onload; local: *;
+};
--- lto-plugin/configure.jj	2021-05-04 11:01:35.372865350 +0200
+++ lto-plugin/configure	2022-03-21 14:42:13.743447879 +0100
@@ -650,6 +650,12 @@  LD
 FGREP
 SED
 LIBTOOL
+LTO_PLUGIN_USE_SYMVER_SUN_FALSE
+LTO_PLUGIN_USE_SYMVER_SUN_TRUE
+LTO_PLUGIN_USE_SYMVER_GNU_FALSE
+LTO_PLUGIN_USE_SYMVER_GNU_TRUE
+LTO_PLUGIN_USE_SYMVER_FALSE
+LTO_PLUGIN_USE_SYMVER_TRUE
 get_gcc_base_ver
 real_target_noncanonical
 accel_dir_suffix
@@ -5910,6 +5916,100 @@  fi
 
 
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether symbol versioning is supported" >&5
+$as_echo_n "checking whether symbol versioning is supported... " >&6; }
+lto_plugin_use_symver=no
+if test x$gcc_no_link = xyes; then
+  # If we cannot link, we cannot build shared libraries, so do not use
+  # symbol versioning.
+  lto_plugin_use_symver=no
+else
+  save_LDFLAGS="$LDFLAGS"
+  LDFLAGS="$LDFLAGS -fPIC -shared -Wl,--version-script,./conftest.map"
+  cat > conftest.map <<EOF
+{
+  global: *foo*; bar; local: *;
+};
+EOF
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int foo;
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  lto_plugin_use_symver=gnu
+else
+  lto_plugin_use_symver=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+  if test x$lto_plugin_use_symver = xno; then
+    case "$target_os" in
+      solaris2*)
+	LDFLAGS="$save_LDFLAGS"
+	LDFLAGS="$LDFLAGS -fPIC -shared -Wl,-M,./conftest.map"
+	# Sun ld cannot handle wildcards and treats all entries as undefined.
+	cat > conftest.map <<EOF
+{
+  global: foo; local: *;
+};
+EOF
+	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int foo;
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  lto_plugin_use_symver=sun
+else
+  lto_plugin_use_symver=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+	  ;;
+    esac
+  fi
+  LDFLAGS="$save_LDFLAGS"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lto_plugin_use_symver" >&5
+$as_echo "$lto_plugin_use_symver" >&6; }
+ if test "x$lto_plugin_use_symver" != xno; then
+  LTO_PLUGIN_USE_SYMVER_TRUE=
+  LTO_PLUGIN_USE_SYMVER_FALSE='#'
+else
+  LTO_PLUGIN_USE_SYMVER_TRUE='#'
+  LTO_PLUGIN_USE_SYMVER_FALSE=
+fi
+
+ if test "x$lto_plugin_use_symver" = xgnu; then
+  LTO_PLUGIN_USE_SYMVER_GNU_TRUE=
+  LTO_PLUGIN_USE_SYMVER_GNU_FALSE='#'
+else
+  LTO_PLUGIN_USE_SYMVER_GNU_TRUE='#'
+  LTO_PLUGIN_USE_SYMVER_GNU_FALSE=
+fi
+
+ if test "x$lto_plugin_use_symver" = xsun; then
+  LTO_PLUGIN_USE_SYMVER_SUN_TRUE=
+  LTO_PLUGIN_USE_SYMVER_SUN_FALSE='#'
+else
+  LTO_PLUGIN_USE_SYMVER_SUN_TRUE='#'
+  LTO_PLUGIN_USE_SYMVER_SUN_FALSE=
+fi
+
+
 case `pwd` in
   *\ * | *\	*)
     { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5
@@ -11981,7 +12081,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11984 "configure"
+#line 12084 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12087,7 +12187,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12090 "configure"
+#line 12190 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12558,6 +12658,18 @@  if test -z "${am__fastdepCC_TRUE}" && te
   as_fn_error $? "conditional \"am__fastdepCC\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${LTO_PLUGIN_USE_SYMVER_TRUE}" && test -z "${LTO_PLUGIN_USE_SYMVER_FALSE}"; then
+  as_fn_error $? "conditional \"LTO_PLUGIN_USE_SYMVER\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${LTO_PLUGIN_USE_SYMVER_GNU_TRUE}" && test -z "${LTO_PLUGIN_USE_SYMVER_GNU_FALSE}"; then
+  as_fn_error $? "conditional \"LTO_PLUGIN_USE_SYMVER_GNU\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${LTO_PLUGIN_USE_SYMVER_SUN_TRUE}" && test -z "${LTO_PLUGIN_USE_SYMVER_SUN_FALSE}"; then
+  as_fn_error $? "conditional \"LTO_PLUGIN_USE_SYMVER_SUN\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 
 : "${CONFIG_STATUS=./config.status}"
 ac_write_fail=0
--- lto-plugin/Makefile.in.jj	2022-01-11 23:20:34.347532985 +0100
+++ lto-plugin/Makefile.in	2022-03-21 14:53:49.644853595 +0100
@@ -323,7 +323,6 @@  prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
 real_target_noncanonical = @real_target_noncanonical@
-runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -349,11 +348,16 @@  AM_LDFLAGS = @ac_lto_plugin_ldflags@
 AM_LIBTOOLFLAGS = --tag=disable-static
 libexecsub_LTLIBRARIES = liblto_plugin.la
 in_gcc_libs = $(foreach lib, $(libexecsub_LTLIBRARIES), $(gcc_build_dir)/$(lib))
+@LTO_PLUGIN_USE_SYMVER_FALSE@version_arg = -export-symbols-regex onload
+@LTO_PLUGIN_USE_SYMVER_GNU_TRUE@@LTO_PLUGIN_USE_SYMVER_TRUE@version_arg = -Wl,--version-script=$(srcdir)/lto-plugin.map
+@LTO_PLUGIN_USE_SYMVER_SUN_TRUE@@LTO_PLUGIN_USE_SYMVER_TRUE@version_arg = -Wl,-M,$(srcdir)/lto-plugin.map
+@LTO_PLUGIN_USE_SYMVER_FALSE@version_dep = 
+@LTO_PLUGIN_USE_SYMVER_TRUE@version_dep = $(srcdir)/lto-plugin.map
 liblto_plugin_la_SOURCES = lto-plugin.c
 # Note that we intentionally override the bindir supplied by ACX_LT_HOST_FLAGS.
 liblto_plugin_la_LDFLAGS = $(AM_LDFLAGS) $(lt_host_flags) -module \
-	-avoid-version -bindir $(libexecsubdir) -export-symbols-regex \
-	onload $(if $(wildcard $(libiberty_noasan)),, $(if $(wildcard \
+	-avoid-version -bindir $(libexecsubdir) $(version_arg) $(if \
+	$(wildcard $(libiberty_noasan)),, $(if $(wildcard \
 	$(libiberty_pic)),,-Wc,$(libiberty)))
 # Can be simplified when libiberty becomes a normal convenience library.
 libiberty = $(with_libiberty)/libiberty.a
@@ -366,7 +370,8 @@  liblto_plugin_la_LIBADD = \
 
 liblto_plugin_la_DEPENDENCIES = \
 	$(if $(wildcard $(libiberty_noasan)),$(libiberty_noasan), \
-	$(if $(wildcard $(libiberty_pic)),$(libiberty_pic),))
+	$(if $(wildcard $(libiberty_pic)),$(libiberty_pic),)) \
+	$(version_dep)
 
 LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS))
 liblto_plugin_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \