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.
This commit is contained in:
Jakub Jelinek 2022-03-22 11:02:31 +01:00
parent 919fbffef0
commit 6ee5892638
5 changed files with 179 additions and 8 deletions

View File

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

View File

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

116
lto-plugin/configure vendored
View File

@ -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

View File

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

View File

@ -0,0 +1,3 @@
{
global: onload; local: *;
};