--- 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) \
