summaryrefslogtreecommitdiff
path: root/lto-plugin
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2022-03-22 11:02:31 +0100
committerJakub Jelinek <jakub@redhat.com>2022-03-22 11:03:54 +0100
commit6ee5892638526366fc3d8a1f4426f3cc278ea061 (patch)
tree6c9ae9cdf8cb260c5167a58cc453279962ef491d /lto-plugin
parent919fbffef0755562cd3b686c838069c20bc7878f (diff)
downloadgcc-6ee5892638526366fc3d8a1f4426f3cc278ea061.tar.gz
lto-plugin: Use GNU ld or Solaris ld version script in preference to -export-symbols-regex [PR102426]
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. 2022-03-22 Jakub Jelinek <jakub@redhat.com> PR lto/102426 lto-plugin/ * 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.
Diffstat (limited to 'lto-plugin')
-rw-r--r--lto-plugin/Makefile.am18
-rw-r--r--lto-plugin/Makefile.in13
-rwxr-xr-xlto-plugin/configure116
-rw-r--r--lto-plugin/configure.ac37
-rw-r--r--lto-plugin/lto-plugin.map3
5 files changed, 179 insertions, 8 deletions
diff --git a/lto-plugin/Makefile.am b/lto-plugin/Makefile.am
index 988d7a78294..a96acc87ee2 100644
--- a/lto-plugin/Makefile.am
+++ b/lto-plugin/Makefile.am
@@ -18,11 +18,24 @@ libexecsub_LTLIBRARIES = liblto_plugin.la
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) \
diff --git a/lto-plugin/Makefile.in b/lto-plugin/Makefile.in
index f8df31bb1e8..5debcb21b66 100644
--- a/lto-plugin/Makefile.in
+++ b/lto-plugin/Makefile.in
@@ -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) \
diff --git a/lto-plugin/configure b/lto-plugin/configure
index 26aad9dd699..b820accfd65 100755
--- a/lto-plugin/configure
+++ b/lto-plugin/configure
@@ -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}" && test -z "${am__fastdepCC_FALSE}"; then
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
diff --git a/lto-plugin/configure.ac b/lto-plugin/configure.ac
index 7e6f729e9dc..bc5b618a495 100644
--- a/lto-plugin/configure.ac
+++ b/lto-plugin/configure.ac
@@ -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)
diff --git a/lto-plugin/lto-plugin.map b/lto-plugin/lto-plugin.map
new file mode 100644
index 00000000000..3d60e71cc2d
--- /dev/null
+++ b/lto-plugin/lto-plugin.map
@@ -0,0 +1,3 @@
+{
+ global: onload; local: *;
+};