* [PATCH] lto-plugin: Add path to libatomic for riscv64
@ 2022-07-04 11:32 Martin Liška
2022-07-04 12:28 ` Richard Biener
0 siblings, 1 reply; 10+ messages in thread
From: Martin Liška @ 2022-07-04 11:32 UTC (permalink / raw)
To: gcc-patches; +Cc: Kito Cheng, jim.wilson.gcc
Similarly to libgo, we need to provide -L for targets where
libpthread does depends on libatomic.
Ready for master?
PR bootstrap/106156
lto-plugin/ChangeLog:
* Makefile.am: Use PTHREAD_CFLAGS.
* Makefile.in: Regenerate.
* configure.ac: Detect if PTHREAD_CFLAGS should contain path
to libatomic.
* configure: Regenerate.
---
lto-plugin/Makefile.am | 2 +-
lto-plugin/Makefile.in | 3 ++-
lto-plugin/configure | 34 ++++++++++++++++++++++++++++++++--
lto-plugin/configure.ac | 17 +++++++++++++++++
4 files changed, 52 insertions(+), 4 deletions(-)
diff --git a/lto-plugin/Makefile.am b/lto-plugin/Makefile.am
index 81362eafc36..64a6bc8c943 100644
--- a/lto-plugin/Makefile.am
+++ b/lto-plugin/Makefile.am
@@ -10,7 +10,7 @@ libexecsubdir := $(libexecdir)/gcc/$(real_target_noncanonical)/$(gcc_version)$(a
AM_CPPFLAGS = -I$(top_srcdir)/../include $(DEFS)
AM_CFLAGS = @ac_lto_plugin_warn_cflags@ $(CET_HOST_FLAGS)
# The plug-in depends on pthreads.
-AM_LDFLAGS = -pthread @ac_lto_plugin_ldflags@
+AM_LDFLAGS = $(PTHREAD_CFLAGS) @ac_lto_plugin_ldflags@
AM_LIBTOOLFLAGS = --tag=disable-static
override CFLAGS := $(filter-out -fsanitize=address -fsanitize=hwaddress,$(CFLAGS))
override LDFLAGS := $(filter-out -fsanitize=address -fsanitize=hwaddress,$(LDFLAGS))
diff --git a/lto-plugin/Makefile.in b/lto-plugin/Makefile.in
index 2033dd9b7c2..de19c8873de 100644
--- a/lto-plugin/Makefile.in
+++ b/lto-plugin/Makefile.in
@@ -264,6 +264,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
+PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
@@ -345,7 +346,7 @@ libexecsubdir := $(libexecdir)/gcc/$(real_target_noncanonical)/$(gcc_version)$(a
AM_CPPFLAGS = -I$(top_srcdir)/../include $(DEFS)
AM_CFLAGS = @ac_lto_plugin_warn_cflags@ $(CET_HOST_FLAGS)
# The plug-in depends on pthreads.
-AM_LDFLAGS = -pthread @ac_lto_plugin_ldflags@
+AM_LDFLAGS = $(PTHREAD_CFLAGS) @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))
diff --git a/lto-plugin/configure b/lto-plugin/configure
index aaa91a63623..aa35bd94b3f 100755
--- a/lto-plugin/configure
+++ b/lto-plugin/configure
@@ -650,6 +650,7 @@ LD
FGREP
SED
LIBTOOL
+PTHREAD_CFLAGS
LTO_PLUGIN_USE_SYMVER_SUN_FALSE
LTO_PLUGIN_USE_SYMVER_SUN_TRUE
LTO_PLUGIN_USE_SYMVER_GNU_FALSE
@@ -6020,6 +6021,35 @@ fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -pthread is supported" >&5
+$as_echo_n "checking whether -pthread is supported... " >&6; }
+if ${lto_plugin_cv_lib_pthread+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ CFLAGS_hold=$CFLAGS
+CFLAGS="$CFLAGS -pthread -L../$build/libatomic/.libs"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ lto_plugin_cv_lib_pthread=yes
+else
+ lto_plugin_cv_lib_pthread=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+CFLAGS=$CFLAGS_hold
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lto_plugin_cv_lib_pthread" >&5
+$as_echo "$lto_plugin_cv_lib_pthread" >&6; }
+PTHREAD_CFLAGS=
+if test "$libgo_cv_lib_pthread" = yes; then
+ # RISC-V apparently adds -latomic when using -pthread.
+ PTHREAD_CFLAGS="-pthread -L../$build/libatomic/.libs"
+fi
+
+
+
case `pwd` in
*\ * | *\ *)
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5
@@ -12091,7 +12121,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 12094 "configure"
+#line 12124 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -12197,7 +12227,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 12200 "configure"
+#line 12230 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
diff --git a/lto-plugin/configure.ac b/lto-plugin/configure.ac
index c2ec512880f..ba34a5d0ca1 100644
--- a/lto-plugin/configure.ac
+++ b/lto-plugin/configure.ac
@@ -91,6 +91,23 @@ AM_CONDITIONAL(LTO_PLUGIN_USE_SYMVER_SUN, [test "x$lto_plugin_use_symver" = xsun
AC_CHECK_HEADER(pthread.h,
[AC_DEFINE(HAVE_PTHREAD_H, 1, [Define to 1 if pthread.h is present.])])
+dnl Test whether the compiler supports the -pthread option.
+AC_CACHE_CHECK([whether -pthread is supported],
+[lto_plugin_cv_lib_pthread],
+[CFLAGS_hold=$CFLAGS
+CFLAGS="$CFLAGS -pthread -L../$build/libatomic/.libs"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])],
+[lto_plugin_cv_lib_pthread=yes],
+[lto_plugin_cv_lib_pthread=no])
+CFLAGS=$CFLAGS_hold])
+PTHREAD_CFLAGS=
+if test "$libgo_cv_lib_pthread" = yes; then
+ # RISC-V apparently adds -latomic when using -pthread.
+ PTHREAD_CFLAGS="-pthread -L../$build/libatomic/.libs"
+fi
+AC_SUBST(PTHREAD_CFLAGS)
+
+
AM_PROG_LIBTOOL
ACX_LT_HOST_FLAGS
AC_SUBST(target_noncanonical)
--
2.36.1
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] lto-plugin: Add path to libatomic for riscv64
2022-07-04 11:32 [PATCH] lto-plugin: Add path to libatomic for riscv64 Martin Liška
@ 2022-07-04 12:28 ` Richard Biener
2022-07-04 12:28 ` Richard Biener
0 siblings, 1 reply; 10+ messages in thread
From: Richard Biener @ 2022-07-04 12:28 UTC (permalink / raw)
To: Martin Liška; +Cc: GCC Patches, Kito Cheng
On Mon, Jul 4, 2022 at 1:32 PM Martin Liška <mliska@suse.cz> wrote:
>
> Similarly to libgo, we need to provide -L for targets where
> libpthread does depends on libatomic.
>
> Ready for master?
OK
> PR bootstrap/106156
>
> lto-plugin/ChangeLog:
>
> * Makefile.am: Use PTHREAD_CFLAGS.
> * Makefile.in: Regenerate.
> * configure.ac: Detect if PTHREAD_CFLAGS should contain path
> to libatomic.
> * configure: Regenerate.
> ---
> lto-plugin/Makefile.am | 2 +-
> lto-plugin/Makefile.in | 3 ++-
> lto-plugin/configure | 34 ++++++++++++++++++++++++++++++++--
> lto-plugin/configure.ac | 17 +++++++++++++++++
> 4 files changed, 52 insertions(+), 4 deletions(-)
>
> diff --git a/lto-plugin/Makefile.am b/lto-plugin/Makefile.am
> index 81362eafc36..64a6bc8c943 100644
> --- a/lto-plugin/Makefile.am
> +++ b/lto-plugin/Makefile.am
> @@ -10,7 +10,7 @@ libexecsubdir := $(libexecdir)/gcc/$(real_target_noncanonical)/$(gcc_version)$(a
> AM_CPPFLAGS = -I$(top_srcdir)/../include $(DEFS)
> AM_CFLAGS = @ac_lto_plugin_warn_cflags@ $(CET_HOST_FLAGS)
> # The plug-in depends on pthreads.
> -AM_LDFLAGS = -pthread @ac_lto_plugin_ldflags@
> +AM_LDFLAGS = $(PTHREAD_CFLAGS) @ac_lto_plugin_ldflags@
> AM_LIBTOOLFLAGS = --tag=disable-static
> override CFLAGS := $(filter-out -fsanitize=address -fsanitize=hwaddress,$(CFLAGS))
> override LDFLAGS := $(filter-out -fsanitize=address -fsanitize=hwaddress,$(LDFLAGS))
> diff --git a/lto-plugin/Makefile.in b/lto-plugin/Makefile.in
> index 2033dd9b7c2..de19c8873de 100644
> --- a/lto-plugin/Makefile.in
> +++ b/lto-plugin/Makefile.in
> @@ -264,6 +264,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
> PACKAGE_URL = @PACKAGE_URL@
> PACKAGE_VERSION = @PACKAGE_VERSION@
> PATH_SEPARATOR = @PATH_SEPARATOR@
> +PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
> RANLIB = @RANLIB@
> SED = @SED@
> SET_MAKE = @SET_MAKE@
> @@ -345,7 +346,7 @@ libexecsubdir := $(libexecdir)/gcc/$(real_target_noncanonical)/$(gcc_version)$(a
> AM_CPPFLAGS = -I$(top_srcdir)/../include $(DEFS)
> AM_CFLAGS = @ac_lto_plugin_warn_cflags@ $(CET_HOST_FLAGS)
> # The plug-in depends on pthreads.
> -AM_LDFLAGS = -pthread @ac_lto_plugin_ldflags@
> +AM_LDFLAGS = $(PTHREAD_CFLAGS) @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))
> diff --git a/lto-plugin/configure b/lto-plugin/configure
> index aaa91a63623..aa35bd94b3f 100755
> --- a/lto-plugin/configure
> +++ b/lto-plugin/configure
> @@ -650,6 +650,7 @@ LD
> FGREP
> SED
> LIBTOOL
> +PTHREAD_CFLAGS
> LTO_PLUGIN_USE_SYMVER_SUN_FALSE
> LTO_PLUGIN_USE_SYMVER_SUN_TRUE
> LTO_PLUGIN_USE_SYMVER_GNU_FALSE
> @@ -6020,6 +6021,35 @@ fi
>
>
>
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -pthread is supported" >&5
> +$as_echo_n "checking whether -pthread is supported... " >&6; }
> +if ${lto_plugin_cv_lib_pthread+:} false; then :
> + $as_echo_n "(cached) " >&6
> +else
> + CFLAGS_hold=$CFLAGS
> +CFLAGS="$CFLAGS -pthread -L../$build/libatomic/.libs"
> +cat confdefs.h - <<_ACEOF >conftest.$ac_ext
> +/* end confdefs.h. */
> +int i;
> +_ACEOF
> +if ac_fn_c_try_compile "$LINENO"; then :
> + lto_plugin_cv_lib_pthread=yes
> +else
> + lto_plugin_cv_lib_pthread=no
> +fi
> +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
> +CFLAGS=$CFLAGS_hold
> +fi
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lto_plugin_cv_lib_pthread" >&5
> +$as_echo "$lto_plugin_cv_lib_pthread" >&6; }
> +PTHREAD_CFLAGS=
> +if test "$libgo_cv_lib_pthread" = yes; then
> + # RISC-V apparently adds -latomic when using -pthread.
> + PTHREAD_CFLAGS="-pthread -L../$build/libatomic/.libs"
> +fi
> +
> +
> +
> case `pwd` in
> *\ * | *\ *)
> { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5
> @@ -12091,7 +12121,7 @@ else
> lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
> lt_status=$lt_dlunknown
> cat > conftest.$ac_ext <<_LT_EOF
> -#line 12094 "configure"
> +#line 12124 "configure"
> #include "confdefs.h"
>
> #if HAVE_DLFCN_H
> @@ -12197,7 +12227,7 @@ else
> lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
> lt_status=$lt_dlunknown
> cat > conftest.$ac_ext <<_LT_EOF
> -#line 12200 "configure"
> +#line 12230 "configure"
> #include "confdefs.h"
>
> #if HAVE_DLFCN_H
> diff --git a/lto-plugin/configure.ac b/lto-plugin/configure.ac
> index c2ec512880f..ba34a5d0ca1 100644
> --- a/lto-plugin/configure.ac
> +++ b/lto-plugin/configure.ac
> @@ -91,6 +91,23 @@ AM_CONDITIONAL(LTO_PLUGIN_USE_SYMVER_SUN, [test "x$lto_plugin_use_symver" = xsun
> AC_CHECK_HEADER(pthread.h,
> [AC_DEFINE(HAVE_PTHREAD_H, 1, [Define to 1 if pthread.h is present.])])
>
> +dnl Test whether the compiler supports the -pthread option.
> +AC_CACHE_CHECK([whether -pthread is supported],
> +[lto_plugin_cv_lib_pthread],
> +[CFLAGS_hold=$CFLAGS
> +CFLAGS="$CFLAGS -pthread -L../$build/libatomic/.libs"
> +AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])],
> +[lto_plugin_cv_lib_pthread=yes],
> +[lto_plugin_cv_lib_pthread=no])
> +CFLAGS=$CFLAGS_hold])
> +PTHREAD_CFLAGS=
> +if test "$libgo_cv_lib_pthread" = yes; then
> + # RISC-V apparently adds -latomic when using -pthread.
> + PTHREAD_CFLAGS="-pthread -L../$build/libatomic/.libs"
> +fi
> +AC_SUBST(PTHREAD_CFLAGS)
> +
> +
> AM_PROG_LIBTOOL
> ACX_LT_HOST_FLAGS
> AC_SUBST(target_noncanonical)
> --
> 2.36.1
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] lto-plugin: Add path to libatomic for riscv64
2022-07-04 12:28 ` Richard Biener
@ 2022-07-04 12:28 ` Richard Biener
2022-07-04 13:09 ` Martin Liška
0 siblings, 1 reply; 10+ messages in thread
From: Richard Biener @ 2022-07-04 12:28 UTC (permalink / raw)
To: Martin Liška; +Cc: GCC Patches, Kito Cheng
On Mon, Jul 4, 2022 at 2:28 PM Richard Biener
<richard.guenther@gmail.com> wrote:
>
> On Mon, Jul 4, 2022 at 1:32 PM Martin Liška <mliska@suse.cz> wrote:
> >
> > Similarly to libgo, we need to provide -L for targets where
> > libpthread does depends on libatomic.
> >
> > Ready for master?
>
> OK
... but ... is libatomic properly built for the host? libgo is a
target library.
>
> > PR bootstrap/106156
> >
> > lto-plugin/ChangeLog:
> >
> > * Makefile.am: Use PTHREAD_CFLAGS.
> > * Makefile.in: Regenerate.
> > * configure.ac: Detect if PTHREAD_CFLAGS should contain path
> > to libatomic.
> > * configure: Regenerate.
> > ---
> > lto-plugin/Makefile.am | 2 +-
> > lto-plugin/Makefile.in | 3 ++-
> > lto-plugin/configure | 34 ++++++++++++++++++++++++++++++++--
> > lto-plugin/configure.ac | 17 +++++++++++++++++
> > 4 files changed, 52 insertions(+), 4 deletions(-)
> >
> > diff --git a/lto-plugin/Makefile.am b/lto-plugin/Makefile.am
> > index 81362eafc36..64a6bc8c943 100644
> > --- a/lto-plugin/Makefile.am
> > +++ b/lto-plugin/Makefile.am
> > @@ -10,7 +10,7 @@ libexecsubdir := $(libexecdir)/gcc/$(real_target_noncanonical)/$(gcc_version)$(a
> > AM_CPPFLAGS = -I$(top_srcdir)/../include $(DEFS)
> > AM_CFLAGS = @ac_lto_plugin_warn_cflags@ $(CET_HOST_FLAGS)
> > # The plug-in depends on pthreads.
> > -AM_LDFLAGS = -pthread @ac_lto_plugin_ldflags@
> > +AM_LDFLAGS = $(PTHREAD_CFLAGS) @ac_lto_plugin_ldflags@
> > AM_LIBTOOLFLAGS = --tag=disable-static
> > override CFLAGS := $(filter-out -fsanitize=address -fsanitize=hwaddress,$(CFLAGS))
> > override LDFLAGS := $(filter-out -fsanitize=address -fsanitize=hwaddress,$(LDFLAGS))
> > diff --git a/lto-plugin/Makefile.in b/lto-plugin/Makefile.in
> > index 2033dd9b7c2..de19c8873de 100644
> > --- a/lto-plugin/Makefile.in
> > +++ b/lto-plugin/Makefile.in
> > @@ -264,6 +264,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
> > PACKAGE_URL = @PACKAGE_URL@
> > PACKAGE_VERSION = @PACKAGE_VERSION@
> > PATH_SEPARATOR = @PATH_SEPARATOR@
> > +PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
> > RANLIB = @RANLIB@
> > SED = @SED@
> > SET_MAKE = @SET_MAKE@
> > @@ -345,7 +346,7 @@ libexecsubdir := $(libexecdir)/gcc/$(real_target_noncanonical)/$(gcc_version)$(a
> > AM_CPPFLAGS = -I$(top_srcdir)/../include $(DEFS)
> > AM_CFLAGS = @ac_lto_plugin_warn_cflags@ $(CET_HOST_FLAGS)
> > # The plug-in depends on pthreads.
> > -AM_LDFLAGS = -pthread @ac_lto_plugin_ldflags@
> > +AM_LDFLAGS = $(PTHREAD_CFLAGS) @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))
> > diff --git a/lto-plugin/configure b/lto-plugin/configure
> > index aaa91a63623..aa35bd94b3f 100755
> > --- a/lto-plugin/configure
> > +++ b/lto-plugin/configure
> > @@ -650,6 +650,7 @@ LD
> > FGREP
> > SED
> > LIBTOOL
> > +PTHREAD_CFLAGS
> > LTO_PLUGIN_USE_SYMVER_SUN_FALSE
> > LTO_PLUGIN_USE_SYMVER_SUN_TRUE
> > LTO_PLUGIN_USE_SYMVER_GNU_FALSE
> > @@ -6020,6 +6021,35 @@ fi
> >
> >
> >
> > +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -pthread is supported" >&5
> > +$as_echo_n "checking whether -pthread is supported... " >&6; }
> > +if ${lto_plugin_cv_lib_pthread+:} false; then :
> > + $as_echo_n "(cached) " >&6
> > +else
> > + CFLAGS_hold=$CFLAGS
> > +CFLAGS="$CFLAGS -pthread -L../$build/libatomic/.libs"
> > +cat confdefs.h - <<_ACEOF >conftest.$ac_ext
> > +/* end confdefs.h. */
> > +int i;
> > +_ACEOF
> > +if ac_fn_c_try_compile "$LINENO"; then :
> > + lto_plugin_cv_lib_pthread=yes
> > +else
> > + lto_plugin_cv_lib_pthread=no
> > +fi
> > +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
> > +CFLAGS=$CFLAGS_hold
> > +fi
> > +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lto_plugin_cv_lib_pthread" >&5
> > +$as_echo "$lto_plugin_cv_lib_pthread" >&6; }
> > +PTHREAD_CFLAGS=
> > +if test "$libgo_cv_lib_pthread" = yes; then
> > + # RISC-V apparently adds -latomic when using -pthread.
> > + PTHREAD_CFLAGS="-pthread -L../$build/libatomic/.libs"
> > +fi
> > +
> > +
> > +
> > case `pwd` in
> > *\ * | *\ *)
> > { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5
> > @@ -12091,7 +12121,7 @@ else
> > lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
> > lt_status=$lt_dlunknown
> > cat > conftest.$ac_ext <<_LT_EOF
> > -#line 12094 "configure"
> > +#line 12124 "configure"
> > #include "confdefs.h"
> >
> > #if HAVE_DLFCN_H
> > @@ -12197,7 +12227,7 @@ else
> > lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
> > lt_status=$lt_dlunknown
> > cat > conftest.$ac_ext <<_LT_EOF
> > -#line 12200 "configure"
> > +#line 12230 "configure"
> > #include "confdefs.h"
> >
> > #if HAVE_DLFCN_H
> > diff --git a/lto-plugin/configure.ac b/lto-plugin/configure.ac
> > index c2ec512880f..ba34a5d0ca1 100644
> > --- a/lto-plugin/configure.ac
> > +++ b/lto-plugin/configure.ac
> > @@ -91,6 +91,23 @@ AM_CONDITIONAL(LTO_PLUGIN_USE_SYMVER_SUN, [test "x$lto_plugin_use_symver" = xsun
> > AC_CHECK_HEADER(pthread.h,
> > [AC_DEFINE(HAVE_PTHREAD_H, 1, [Define to 1 if pthread.h is present.])])
> >
> > +dnl Test whether the compiler supports the -pthread option.
> > +AC_CACHE_CHECK([whether -pthread is supported],
> > +[lto_plugin_cv_lib_pthread],
> > +[CFLAGS_hold=$CFLAGS
> > +CFLAGS="$CFLAGS -pthread -L../$build/libatomic/.libs"
> > +AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])],
> > +[lto_plugin_cv_lib_pthread=yes],
> > +[lto_plugin_cv_lib_pthread=no])
> > +CFLAGS=$CFLAGS_hold])
> > +PTHREAD_CFLAGS=
> > +if test "$libgo_cv_lib_pthread" = yes; then
> > + # RISC-V apparently adds -latomic when using -pthread.
> > + PTHREAD_CFLAGS="-pthread -L../$build/libatomic/.libs"
> > +fi
> > +AC_SUBST(PTHREAD_CFLAGS)
> > +
> > +
> > AM_PROG_LIBTOOL
> > ACX_LT_HOST_FLAGS
> > AC_SUBST(target_noncanonical)
> > --
> > 2.36.1
> >
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] lto-plugin: Add path to libatomic for riscv64
2022-07-04 12:28 ` Richard Biener
@ 2022-07-04 13:09 ` Martin Liška
2022-07-05 7:27 ` Richard Biener
0 siblings, 1 reply; 10+ messages in thread
From: Martin Liška @ 2022-07-04 13:09 UTC (permalink / raw)
To: Richard Biener; +Cc: GCC Patches, Kito Cheng
On 7/4/22 14:28, Richard Biener wrote:
> ... but ... is libatomic properly built for the host? libgo is a
> target library.
You're correct.
Well, so the host library should be taken, which works for stage1 lto-plugin:
[ 668s] libtool: link: gcc -shared -fPIC -DPIC .libs/lto-plugin.o -pthread -static-libgcc -Wl,--version-script=../../lto-plugin/lto-plugin.map -static-libstdc++ -static-libgcc ../libiberty/pic/libiberty.a -pthread -Wl,-soname -Wl,liblto_plugin.so -o .libs/liblto_p
while it fails in stage2:
[ 7129s] libtool: link: /home/abuild/rpmbuild/BUILD/gcc-13.0.0+git194120/obj-riscv64-suse-linux/./prev-gcc/xgcc -B/home/abuild/rpmbuild/BUILD/gcc-13.0.0+git194120/obj-riscv64-suse-linux/./prev-gcc/ -B/usr/riscv64-suse-linux/bin/ -B/usr/riscv64-suse-linux/bin/ -B/usr/riscv64-suse-linux/lib/ -isystem /usr/riscv64-suse-linux/include -isystem /usr/riscv64-suse-linux/sys-include -fno-checking -shared -fPIC -DPIC .libs/lto-plugin.o -pthread -static-libgcc -Wl,--version-script=../../lto-plugin/lto-plugin.map -static-libstdc++ -static-libgcc ../libiberty/pic/libiberty.a -pthread -Wl,-soname -Wl,liblto_plugin.so -o .libs/liblto_plugin.so
Where the system compiler takes the library from:
/usr/lib/gcc/riscv64-linux-gnu/11/libatomic.so
that points to system library location:
ls -l /usr/lib/gcc/riscv64-linux-gnu/11/libatomic.so
lrwxrwxrwx 1 root root 41 Mar 24 14:22 /usr/lib/gcc/riscv64-linux-gnu/11/libatomic.so -> ../../../riscv64-linux-gnu/libatomic.so.1
So the question is how to fix that?
Martin
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] lto-plugin: Add path to libatomic for riscv64
2022-07-04 13:09 ` Martin Liška
@ 2022-07-05 7:27 ` Richard Biener
2022-07-07 11:43 ` [PATCH] lto-plugin: use locking only for selected targets Martin Liška
0 siblings, 1 reply; 10+ messages in thread
From: Richard Biener @ 2022-07-05 7:27 UTC (permalink / raw)
To: Martin Liška; +Cc: GCC Patches, Kito Cheng
On Mon, Jul 4, 2022 at 3:09 PM Martin Liška <mliska@suse.cz> wrote:
>
> On 7/4/22 14:28, Richard Biener wrote:
> > ... but ... is libatomic properly built for the host? libgo is a
> > target library.
>
> You're correct.
>
> Well, so the host library should be taken, which works for stage1 lto-plugin:
>
> [ 668s] libtool: link: gcc -shared -fPIC -DPIC .libs/lto-plugin.o -pthread -static-libgcc -Wl,--version-script=../../lto-plugin/lto-plugin.map -static-libstdc++ -static-libgcc ../libiberty/pic/libiberty.a -pthread -Wl,-soname -Wl,liblto_plugin.so -o .libs/liblto_p
>
> while it fails in stage2:
>
> [ 7129s] libtool: link: /home/abuild/rpmbuild/BUILD/gcc-13.0.0+git194120/obj-riscv64-suse-linux/./prev-gcc/xgcc -B/home/abuild/rpmbuild/BUILD/gcc-13.0.0+git194120/obj-riscv64-suse-linux/./prev-gcc/ -B/usr/riscv64-suse-linux/bin/ -B/usr/riscv64-suse-linux/bin/ -B/usr/riscv64-suse-linux/lib/ -isystem /usr/riscv64-suse-linux/include -isystem /usr/riscv64-suse-linux/sys-include -fno-checking -shared -fPIC -DPIC .libs/lto-plugin.o -pthread -static-libgcc -Wl,--version-script=../../lto-plugin/lto-plugin.map -static-libstdc++ -static-libgcc ../libiberty/pic/libiberty.a -pthread -Wl,-soname -Wl,liblto_plugin.so -o .libs/liblto_plugin.so
>
> Where the system compiler takes the library from:
> /usr/lib/gcc/riscv64-linux-gnu/11/libatomic.so
>
> that points to system library location:
> ls -l /usr/lib/gcc/riscv64-linux-gnu/11/libatomic.so
> lrwxrwxrwx 1 root root 41 Mar 24 14:22 /usr/lib/gcc/riscv64-linux-gnu/11/libatomic.so -> ../../../riscv64-linux-gnu/libatomic.so.1
>
> So the question is how to fix that?
We'd need to add libatomic as host_module in Makefile.def and also
bootstrap that (since lto-plugin is bootstrapped), plus adding
the required dependency. At least for the targets that need this.
Or give up and use better means of serialization or use a whitelist
for now (via lto-plugin configury) and leave
all not covered targets not thread-safe (see also the mingw bugreport).
Richard.
>
> Martin
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH] lto-plugin: use locking only for selected targets
2022-07-05 7:27 ` Richard Biener
@ 2022-07-07 11:43 ` Martin Liška
2022-07-07 11:46 ` Richard Biener
0 siblings, 1 reply; 10+ messages in thread
From: Martin Liška @ 2022-07-07 11:43 UTC (permalink / raw)
To: gcc-patches
For now, support locking only for linux targets that are different from
riscv* where the target depends on libatomic (and fails during
bootstrap).
Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Ready to be installed?
Thanks,
Martin
PR lto/106170
lto-plugin/ChangeLog:
* configure.ac: Configure HAVE_PTHREAD_LOCKING.
* lto-plugin.c (LOCK_SECTION): New.
(UNLOCK_SECTION): New.
(claim_file_handler): Use the newly added macros.
(onload): Likewise.
* config.h.in: Regenerate.
* configure: Regenerate.
---
lto-plugin/config.h.in | 4 ++--
lto-plugin/configure | 20 ++++++++++++++------
lto-plugin/configure.ac | 17 +++++++++++++++--
lto-plugin/lto-plugin.c | 30 ++++++++++++++++++++----------
4 files changed, 51 insertions(+), 20 deletions(-)
diff --git a/lto-plugin/config.h.in b/lto-plugin/config.h.in
index 029e782f1ee..bf269f000d2 100644
--- a/lto-plugin/config.h.in
+++ b/lto-plugin/config.h.in
@@ -9,8 +9,8 @@
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
-/* Define to 1 if pthread.h is present. */
-#undef HAVE_PTHREAD_H
+/* Define if the system-provided pthread locking mechanism. */
+#undef HAVE_PTHREAD_LOCKING
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
diff --git a/lto-plugin/configure b/lto-plugin/configure
index aaa91a63623..7ea54e6008f 100755
--- a/lto-plugin/configure
+++ b/lto-plugin/configure
@@ -6011,14 +6011,22 @@ fi
# Check for thread headers.
-ac_fn_c_check_header_mongrel "$LINENO" "pthread.h" "ac_cv_header_pthread_h" "$ac_includes_default"
-if test "x$ac_cv_header_pthread_h" = xyes; then :
+use_locking=no
-$as_echo "#define HAVE_PTHREAD_H 1" >>confdefs.h
+case $target in
+ riscv*)
+ # do not use locking as pthread depends on libatomic
+ ;;
+ *-linux*)
+ use_locking=yes
+ ;;
+esac
-fi
+if test x$use_locking = xyes; then
+$as_echo "#define HAVE_PTHREAD_LOCKING 1" >>confdefs.h
+fi
case `pwd` in
*\ * | *\ *)
@@ -12091,7 +12099,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 12094 "configure"
+#line 12102 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -12197,7 +12205,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 12200 "configure"
+#line 12208 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
diff --git a/lto-plugin/configure.ac b/lto-plugin/configure.ac
index c2ec512880f..69bc5139193 100644
--- a/lto-plugin/configure.ac
+++ b/lto-plugin/configure.ac
@@ -88,8 +88,21 @@ 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])
# Check for thread headers.
-AC_CHECK_HEADER(pthread.h,
- [AC_DEFINE(HAVE_PTHREAD_H, 1, [Define to 1 if pthread.h is present.])])
+use_locking=no
+
+case $target in
+ riscv*)
+ # do not use locking as pthread depends on libatomic
+ ;;
+ *-linux*)
+ use_locking=yes
+ ;;
+esac
+
+if test x$use_locking = xyes; then
+ AC_DEFINE(HAVE_PTHREAD_LOCKING, 1,
+ [Define if the system-provided pthread locking mechanism.])
+fi
AM_PROG_LIBTOOL
ACX_LT_HOST_FLAGS
diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index 635e126946b..cba58f5999b 100644
--- a/lto-plugin/lto-plugin.c
+++ b/lto-plugin/lto-plugin.c
@@ -40,11 +40,7 @@ along with this program; see the file COPYING3. If not see
#ifdef HAVE_CONFIG_H
#include "config.h"
-#if !HAVE_PTHREAD_H
-#error POSIX threads are mandatory dependency
#endif
-#endif
-
#if HAVE_STDINT_H
#include <stdint.h>
#endif
@@ -59,7 +55,9 @@ along with this program; see the file COPYING3. If not see
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
+#if HAVE_PTHREAD_LOCKING
#include <pthread.h>
+#endif
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
@@ -162,9 +160,18 @@ enum symbol_style
ss_uscore, /* Underscore prefix all symbols. */
};
+#if HAVE_PTHREAD_LOCKING
/* Plug-in mutex. */
static pthread_mutex_t plugin_lock;
+#define LOCK_SECTION pthread_mutex_lock (&plugin_lock)
+#define UNLOCK_SECTION pthread_mutex_unlock (&plugin_lock)
+#else
+
+#define LOCK_SECTION
+#define UNLOCK_SECTION
+#endif
+
static char *arguments_file_name;
static ld_plugin_register_claim_file register_claim_file;
static ld_plugin_register_all_symbols_read register_all_symbols_read;
@@ -1270,18 +1277,18 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed)
lto_file.symtab.syms);
check (status == LDPS_OK, LDPL_FATAL, "could not add symbols");
- pthread_mutex_lock (&plugin_lock);
+ LOCK_SECTION;
num_claimed_files++;
claimed_files =
xrealloc (claimed_files,
num_claimed_files * sizeof (struct plugin_file_info));
claimed_files[num_claimed_files - 1] = lto_file;
- pthread_mutex_unlock (&plugin_lock);
+ UNLOCK_SECTION;
*claimed = 1;
}
- pthread_mutex_lock (&plugin_lock);
+ LOCK_SECTION;
if (offload_files == NULL)
{
/* Add dummy item to the start of the list. */
@@ -1344,14 +1351,15 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed)
offload_files_last_lto = ofld;
num_offload_files++;
}
- pthread_mutex_unlock (&plugin_lock);
+
+ UNLOCK_SECTION;
goto cleanup;
err:
- pthread_mutex_lock (&plugin_lock);
+ LOCK_SECTION;
non_claimed_files++;
- pthread_mutex_unlock (&plugin_lock);
+ UNLOCK_SECTION;
free (lto_file.name);
cleanup:
@@ -1429,11 +1437,13 @@ onload (struct ld_plugin_tv *tv)
struct ld_plugin_tv *p;
enum ld_plugin_status status;
+#if HAVE_PTHREAD_LOCKING
if (pthread_mutex_init (&plugin_lock, NULL) != 0)
{
fprintf (stderr, "mutex init failed\n");
abort ();
}
+#endif
p = tv;
while (p->tv_tag)
--
2.36.1
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] lto-plugin: use locking only for selected targets
2022-07-07 11:43 ` [PATCH] lto-plugin: use locking only for selected targets Martin Liška
@ 2022-07-07 11:46 ` Richard Biener
2022-07-07 11:52 ` Rainer Orth
2022-07-07 13:18 ` Martin Liška
0 siblings, 2 replies; 10+ messages in thread
From: Richard Biener @ 2022-07-07 11:46 UTC (permalink / raw)
To: Martin Liška; +Cc: GCC Patches
On Thu, Jul 7, 2022 at 1:43 PM Martin Liška <mliska@suse.cz> wrote:
>
> For now, support locking only for linux targets that are different from
> riscv* where the target depends on libatomic (and fails during
> bootstrap).
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?
OK - that also resolves the mingw issue, correct? I suppose we need
to be careful to not advertise v1 API (which includes threadsafeness)
when not HAVE_PTHREAD_LOCKING.
Thanks,
Richard.
> Thanks,
> Martin
>
> PR lto/106170
>
> lto-plugin/ChangeLog:
>
> * configure.ac: Configure HAVE_PTHREAD_LOCKING.
> * lto-plugin.c (LOCK_SECTION): New.
> (UNLOCK_SECTION): New.
> (claim_file_handler): Use the newly added macros.
> (onload): Likewise.
> * config.h.in: Regenerate.
> * configure: Regenerate.
> ---
> lto-plugin/config.h.in | 4 ++--
> lto-plugin/configure | 20 ++++++++++++++------
> lto-plugin/configure.ac | 17 +++++++++++++++--
> lto-plugin/lto-plugin.c | 30 ++++++++++++++++++++----------
> 4 files changed, 51 insertions(+), 20 deletions(-)
>
> diff --git a/lto-plugin/config.h.in b/lto-plugin/config.h.in
> index 029e782f1ee..bf269f000d2 100644
> --- a/lto-plugin/config.h.in
> +++ b/lto-plugin/config.h.in
> @@ -9,8 +9,8 @@
> /* Define to 1 if you have the <memory.h> header file. */
> #undef HAVE_MEMORY_H
>
> -/* Define to 1 if pthread.h is present. */
> -#undef HAVE_PTHREAD_H
> +/* Define if the system-provided pthread locking mechanism. */
> +#undef HAVE_PTHREAD_LOCKING
>
> /* Define to 1 if you have the <stdint.h> header file. */
> #undef HAVE_STDINT_H
> diff --git a/lto-plugin/configure b/lto-plugin/configure
> index aaa91a63623..7ea54e6008f 100755
> --- a/lto-plugin/configure
> +++ b/lto-plugin/configure
> @@ -6011,14 +6011,22 @@ fi
>
>
> # Check for thread headers.
> -ac_fn_c_check_header_mongrel "$LINENO" "pthread.h" "ac_cv_header_pthread_h" "$ac_includes_default"
> -if test "x$ac_cv_header_pthread_h" = xyes; then :
> +use_locking=no
>
> -$as_echo "#define HAVE_PTHREAD_H 1" >>confdefs.h
> +case $target in
> + riscv*)
> + # do not use locking as pthread depends on libatomic
> + ;;
> + *-linux*)
> + use_locking=yes
> + ;;
> +esac
>
> -fi
> +if test x$use_locking = xyes; then
>
> +$as_echo "#define HAVE_PTHREAD_LOCKING 1" >>confdefs.h
>
> +fi
>
> case `pwd` in
> *\ * | *\ *)
> @@ -12091,7 +12099,7 @@ else
> lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
> lt_status=$lt_dlunknown
> cat > conftest.$ac_ext <<_LT_EOF
> -#line 12094 "configure"
> +#line 12102 "configure"
> #include "confdefs.h"
>
> #if HAVE_DLFCN_H
> @@ -12197,7 +12205,7 @@ else
> lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
> lt_status=$lt_dlunknown
> cat > conftest.$ac_ext <<_LT_EOF
> -#line 12200 "configure"
> +#line 12208 "configure"
> #include "confdefs.h"
>
> #if HAVE_DLFCN_H
> diff --git a/lto-plugin/configure.ac b/lto-plugin/configure.ac
> index c2ec512880f..69bc5139193 100644
> --- a/lto-plugin/configure.ac
> +++ b/lto-plugin/configure.ac
> @@ -88,8 +88,21 @@ 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])
>
> # Check for thread headers.
> -AC_CHECK_HEADER(pthread.h,
> - [AC_DEFINE(HAVE_PTHREAD_H, 1, [Define to 1 if pthread.h is present.])])
> +use_locking=no
> +
> +case $target in
> + riscv*)
> + # do not use locking as pthread depends on libatomic
> + ;;
> + *-linux*)
> + use_locking=yes
> + ;;
> +esac
> +
> +if test x$use_locking = xyes; then
> + AC_DEFINE(HAVE_PTHREAD_LOCKING, 1,
> + [Define if the system-provided pthread locking mechanism.])
> +fi
>
> AM_PROG_LIBTOOL
> ACX_LT_HOST_FLAGS
> diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
> index 635e126946b..cba58f5999b 100644
> --- a/lto-plugin/lto-plugin.c
> +++ b/lto-plugin/lto-plugin.c
> @@ -40,11 +40,7 @@ along with this program; see the file COPYING3. If not see
>
> #ifdef HAVE_CONFIG_H
> #include "config.h"
> -#if !HAVE_PTHREAD_H
> -#error POSIX threads are mandatory dependency
> #endif
> -#endif
> -
> #if HAVE_STDINT_H
> #include <stdint.h>
> #endif
> @@ -59,7 +55,9 @@ along with this program; see the file COPYING3. If not see
> #include <unistd.h>
> #include <fcntl.h>
> #include <sys/types.h>
> +#if HAVE_PTHREAD_LOCKING
> #include <pthread.h>
> +#endif
> #ifdef HAVE_SYS_WAIT_H
> #include <sys/wait.h>
> #endif
> @@ -162,9 +160,18 @@ enum symbol_style
> ss_uscore, /* Underscore prefix all symbols. */
> };
>
> +#if HAVE_PTHREAD_LOCKING
> /* Plug-in mutex. */
> static pthread_mutex_t plugin_lock;
>
> +#define LOCK_SECTION pthread_mutex_lock (&plugin_lock)
> +#define UNLOCK_SECTION pthread_mutex_unlock (&plugin_lock)
> +#else
> +
> +#define LOCK_SECTION
> +#define UNLOCK_SECTION
> +#endif
> +
> static char *arguments_file_name;
> static ld_plugin_register_claim_file register_claim_file;
> static ld_plugin_register_all_symbols_read register_all_symbols_read;
> @@ -1270,18 +1277,18 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed)
> lto_file.symtab.syms);
> check (status == LDPS_OK, LDPL_FATAL, "could not add symbols");
>
> - pthread_mutex_lock (&plugin_lock);
> + LOCK_SECTION;
> num_claimed_files++;
> claimed_files =
> xrealloc (claimed_files,
> num_claimed_files * sizeof (struct plugin_file_info));
> claimed_files[num_claimed_files - 1] = lto_file;
> - pthread_mutex_unlock (&plugin_lock);
> + UNLOCK_SECTION;
>
> *claimed = 1;
> }
>
> - pthread_mutex_lock (&plugin_lock);
> + LOCK_SECTION;
> if (offload_files == NULL)
> {
> /* Add dummy item to the start of the list. */
> @@ -1344,14 +1351,15 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed)
> offload_files_last_lto = ofld;
> num_offload_files++;
> }
> - pthread_mutex_unlock (&plugin_lock);
> +
> + UNLOCK_SECTION;
>
> goto cleanup;
>
> err:
> - pthread_mutex_lock (&plugin_lock);
> + LOCK_SECTION;
> non_claimed_files++;
> - pthread_mutex_unlock (&plugin_lock);
> + UNLOCK_SECTION;
> free (lto_file.name);
>
> cleanup:
> @@ -1429,11 +1437,13 @@ onload (struct ld_plugin_tv *tv)
> struct ld_plugin_tv *p;
> enum ld_plugin_status status;
>
> +#if HAVE_PTHREAD_LOCKING
> if (pthread_mutex_init (&plugin_lock, NULL) != 0)
> {
> fprintf (stderr, "mutex init failed\n");
> abort ();
> }
> +#endif
>
> p = tv;
> while (p->tv_tag)
> --
> 2.36.1
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] lto-plugin: use locking only for selected targets
2022-07-07 11:46 ` Richard Biener
@ 2022-07-07 11:52 ` Rainer Orth
2022-07-07 13:18 ` Martin Liška
2022-07-07 13:18 ` Martin Liška
1 sibling, 1 reply; 10+ messages in thread
From: Rainer Orth @ 2022-07-07 11:52 UTC (permalink / raw)
To: Richard Biener via Gcc-patches
Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> writes:
>> +if test x$use_locking = xyes; then
>> + AC_DEFINE(HAVE_PTHREAD_LOCKING, 1,
>> + [Define if the system-provided pthread locking mechanism.])
This isn't even a sentence. At least I cannot parse it. Besides, it
seems to be misnamed since the test doesn't check if pthread_mutex_lock
and friends are present on the target, but if they should be used.
Rainer
--
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] lto-plugin: use locking only for selected targets
2022-07-07 11:52 ` Rainer Orth
@ 2022-07-07 13:18 ` Martin Liška
0 siblings, 0 replies; 10+ messages in thread
From: Martin Liška @ 2022-07-07 13:18 UTC (permalink / raw)
To: Rainer Orth, Richard Biener via Gcc-patches
[-- Attachment #1: Type: text/plain, Size: 536 bytes --]
On 7/7/22 13:52, Rainer Orth wrote:
> Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> writes:
>
>>> +if test x$use_locking = xyes; then
>>> + AC_DEFINE(HAVE_PTHREAD_LOCKING, 1,
>>> + [Define if the system-provided pthread locking mechanism.])
>
> This isn't even a sentence. At least I cannot parse it. Besides, it
> seems to be misnamed since the test doesn't check if pthread_mutex_lock
> and friends are present on the target, but if they should be used.
You are right, fixed in v2.
Martin
>
> Rainer
>
[-- Attachment #2: 0001-lto-plugin-use-locking-only-for-selected-targets.patch --]
[-- Type: text/x-patch, Size: 6208 bytes --]
From 0c3380e64dc769b4bc00568395468bdf02e74f6f Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Thu, 7 Jul 2022 12:15:28 +0200
Subject: [PATCH] lto-plugin: use locking only for selected targets
For now, support locking only for linux targets that are different from
riscv* where the target depends on libatomic (and fails during
bootstrap).
PR lto/106170
lto-plugin/ChangeLog:
* configure.ac: Configure HAVE_PTHREAD_LOCKING.
* lto-plugin.c (LOCK_SECTION): New.
(UNLOCK_SECTION): New.
(claim_file_handler): Use the newly added macros.
(onload): Likewise.
* config.h.in: Regenerate.
* configure: Regenerate.
---
lto-plugin/config.h.in | 4 ++--
lto-plugin/configure | 21 +++++++++++++++++----
lto-plugin/configure.ac | 17 +++++++++++++++--
lto-plugin/lto-plugin.c | 29 +++++++++++++++++++----------
4 files changed, 53 insertions(+), 18 deletions(-)
diff --git a/lto-plugin/config.h.in b/lto-plugin/config.h.in
index 029e782f1ee..8eb9c8aa47d 100644
--- a/lto-plugin/config.h.in
+++ b/lto-plugin/config.h.in
@@ -9,8 +9,8 @@
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
-/* Define to 1 if pthread.h is present. */
-#undef HAVE_PTHREAD_H
+/* Define if the system provides pthread locking mechanism. */
+#undef HAVE_PTHREAD_LOCKING
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
diff --git a/lto-plugin/configure b/lto-plugin/configure
index aaa91a63623..870e49b2e62 100755
--- a/lto-plugin/configure
+++ b/lto-plugin/configure
@@ -6011,14 +6011,27 @@ fi
# Check for thread headers.
-ac_fn_c_check_header_mongrel "$LINENO" "pthread.h" "ac_cv_header_pthread_h" "$ac_includes_default"
+use_locking=no
+
+case $target in
+ riscv*)
+ # do not use locking as pthread depends on libatomic
+ ;;
+ *-linux*)
+ use_locking=yes
+ ;;
+esac
+
+if test x$use_locking = xyes; then
+ ac_fn_c_check_header_mongrel "$LINENO" "pthread.h" "ac_cv_header_pthread_h" "$ac_includes_default"
if test "x$ac_cv_header_pthread_h" = xyes; then :
-$as_echo "#define HAVE_PTHREAD_H 1" >>confdefs.h
+$as_echo "#define HAVE_PTHREAD_LOCKING 1" >>confdefs.h
fi
+fi
case `pwd` in
*\ * | *\ *)
@@ -12091,7 +12104,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 12094 "configure"
+#line 12107 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -12197,7 +12210,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 12200 "configure"
+#line 12213 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
diff --git a/lto-plugin/configure.ac b/lto-plugin/configure.ac
index c2ec512880f..18eb4f60b0a 100644
--- a/lto-plugin/configure.ac
+++ b/lto-plugin/configure.ac
@@ -88,8 +88,21 @@ 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])
# Check for thread headers.
-AC_CHECK_HEADER(pthread.h,
- [AC_DEFINE(HAVE_PTHREAD_H, 1, [Define to 1 if pthread.h is present.])])
+use_locking=no
+
+case $target in
+ riscv*)
+ # do not use locking as pthread depends on libatomic
+ ;;
+ *-linux*)
+ use_locking=yes
+ ;;
+esac
+
+if test x$use_locking = xyes; then
+ AC_CHECK_HEADER(pthread.h,
+ [AC_DEFINE(HAVE_PTHREAD_LOCKING, 1, [Define if the system provides pthread locking mechanism.])])
+fi
AM_PROG_LIBTOOL
ACX_LT_HOST_FLAGS
diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index 635e126946b..7927dca60a4 100644
--- a/lto-plugin/lto-plugin.c
+++ b/lto-plugin/lto-plugin.c
@@ -40,11 +40,7 @@ along with this program; see the file COPYING3. If not see
#ifdef HAVE_CONFIG_H
#include "config.h"
-#if !HAVE_PTHREAD_H
-#error POSIX threads are mandatory dependency
#endif
-#endif
-
#if HAVE_STDINT_H
#include <stdint.h>
#endif
@@ -59,7 +55,9 @@ along with this program; see the file COPYING3. If not see
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
+#if HAVE_PTHREAD_LOCKING
#include <pthread.h>
+#endif
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
@@ -162,9 +160,17 @@ enum symbol_style
ss_uscore, /* Underscore prefix all symbols. */
};
+#if HAVE_PTHREAD_LOCKING
/* Plug-in mutex. */
static pthread_mutex_t plugin_lock;
+#define LOCK_SECTION pthread_mutex_lock (&plugin_lock)
+#define UNLOCK_SECTION pthread_mutex_unlock (&plugin_lock)
+#else
+#define LOCK_SECTION
+#define UNLOCK_SECTION
+#endif
+
static char *arguments_file_name;
static ld_plugin_register_claim_file register_claim_file;
static ld_plugin_register_all_symbols_read register_all_symbols_read;
@@ -1270,18 +1276,18 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed)
lto_file.symtab.syms);
check (status == LDPS_OK, LDPL_FATAL, "could not add symbols");
- pthread_mutex_lock (&plugin_lock);
+ LOCK_SECTION;
num_claimed_files++;
claimed_files =
xrealloc (claimed_files,
num_claimed_files * sizeof (struct plugin_file_info));
claimed_files[num_claimed_files - 1] = lto_file;
- pthread_mutex_unlock (&plugin_lock);
+ UNLOCK_SECTION;
*claimed = 1;
}
- pthread_mutex_lock (&plugin_lock);
+ LOCK_SECTION;
if (offload_files == NULL)
{
/* Add dummy item to the start of the list. */
@@ -1344,14 +1350,15 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed)
offload_files_last_lto = ofld;
num_offload_files++;
}
- pthread_mutex_unlock (&plugin_lock);
+
+ UNLOCK_SECTION;
goto cleanup;
err:
- pthread_mutex_lock (&plugin_lock);
+ LOCK_SECTION;
non_claimed_files++;
- pthread_mutex_unlock (&plugin_lock);
+ UNLOCK_SECTION;
free (lto_file.name);
cleanup:
@@ -1429,11 +1436,13 @@ onload (struct ld_plugin_tv *tv)
struct ld_plugin_tv *p;
enum ld_plugin_status status;
+#if HAVE_PTHREAD_LOCKING
if (pthread_mutex_init (&plugin_lock, NULL) != 0)
{
fprintf (stderr, "mutex init failed\n");
abort ();
}
+#endif
p = tv;
while (p->tv_tag)
--
2.36.1
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] lto-plugin: use locking only for selected targets
2022-07-07 11:46 ` Richard Biener
2022-07-07 11:52 ` Rainer Orth
@ 2022-07-07 13:18 ` Martin Liška
1 sibling, 0 replies; 10+ messages in thread
From: Martin Liška @ 2022-07-07 13:18 UTC (permalink / raw)
To: Richard Biener; +Cc: GCC Patches
On 7/7/22 13:46, Richard Biener wrote:
> OK - that also resolves the mingw issue, correct? I suppose we need
Yes.
> to be careful to not advertise v1 API (which includes threadsafeness)
> when not HAVE_PTHREAD_LOCKING.
Will reflect that in the patch.
I'm going to push it now.
Martin
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-07-07 13:18 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-04 11:32 [PATCH] lto-plugin: Add path to libatomic for riscv64 Martin Liška
2022-07-04 12:28 ` Richard Biener
2022-07-04 12:28 ` Richard Biener
2022-07-04 13:09 ` Martin Liška
2022-07-05 7:27 ` Richard Biener
2022-07-07 11:43 ` [PATCH] lto-plugin: use locking only for selected targets Martin Liška
2022-07-07 11:46 ` Richard Biener
2022-07-07 11:52 ` Rainer Orth
2022-07-07 13:18 ` Martin Liška
2022-07-07 13:18 ` Martin Liška
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).