[PATCH v2] Allow explicitly specifying the thread model for runtime libs

2021-08-21 Thread John Ericson
Previously, they always scraped the thread mode from `$CC -v', now, that
is the default but one may pass `--with-threads=MODEL` to be explicit
instead.

One use-case is bootstraping with a shorter critical path. The
traditionally route was to build an entire "static stage" GCC, build
libc, and then build GCC again supporting dynamic linking,
multithreading, etc. But this is wasteful in that GCC itself is built
twice.

With this change, rather than having to mess with spec files we can just
configure the runtime libraries the way we want directly. In turn, that
opens to just building libgcc twice rather than all of GCC.

Frankly, specs were always a rather indirect approach to coordinate this
during GCC's bootstrap, since GCC itself really doesn't care what the
threading model is, just that the runtime libraries agree among
themselves. Relying on a hard-coded spec for this also keeps us one step
further from the long-term goal of multi-target GCC, for what it's
worth.

For the record, "single stage" builds of GCC have some precedent in
downstream packaging, for example with [1]. That one, as far as I can
tell, builds libgcc once, but with the headers of the libc
implementation provided and then cyclic linking down later. They are
both fine approaches, but I don't think one should have to be forced
into cyclic dependencies if they don't want to. That opens the door to
non-terminating programs due to, e.g., atomics used in a threads
implementation being lowered to threads absent hardware support.

Finally, I understand that such custom bootstrapping is not officially
supported. I don't mean to imply it should be --- a lot more cleanup
work to the build system would be necessary before supporting it
wouldn't be a huge additional maintainer burden --- I just hope to add a
reasonable knob for those comfortable with doing unsupported things
already.

[1]: https://github.com/richfelker/musl-cross-make
---
 config/gthr.m4  | 32 
 libatomic/configure.ac  |  4 +---
 libgcc/configure.ac |  4 +---
 libphobos/m4/druntime/os.m4 |  2 +-
 libstdc++-v3/acinclude.m4   |  8 +++-
 5 files changed, 38 insertions(+), 12 deletions(-)

diff --git a/config/gthr.m4 b/config/gthr.m4
index 4b937306ad0..754e622f159 100644
--- a/config/gthr.m4
+++ b/config/gthr.m4
@@ -5,6 +5,35 @@ dnl Public License, this file may be distributed as part of a 
program
 dnl that contains a configuration script generated by Autoconf, under
 dnl the same distribution terms as the rest of that program.
 
+dnl Define thread model
+
+dnl usage: GCC_AC_THREAD_MODEL
+AC_DEFUN([GCC_AC_THREAD_MODEL],
+[
+# With threads
+# Pass with no value to take from compiler's metadata
+# Pass with a value to specify a thread package
+# 'single' means single threaded -- without threads.
+AC_ARG_WITH(threads,
+[AS_HELP_STRING([[--with-threads=MODEL]],
+   [specify thread model for this GCC
+runtime library])],,
+[with_threads=''])
+
+if test x"$with_threads" = x'yes'; then
+AC_MSG_ERROR([Cannot pass bare --with-threads, must pass explicit 
--with-threads=MODEL])
+elif test x"$with_threads" = x'no'; then
+target_thread_file=single
+elif test x"$with_threads" = x''; then
+AC_MSG_CHECKING([for thread model used by GCC])
+target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
+AC_MSG_RESULT([$target_thread_file])
+else
+target_thread_file=$with_threads
+fi
+])
+
+
 dnl Define header location by thread model
 
 dnl usage: GCC_AC_THREAD_HEADER([thread_model])
@@ -22,6 +51,9 @@ case $1 in
 tpf)   thread_header=config/s390/gthr-tpf.h ;;
 vxworks)   thread_header=config/gthr-vxworks.h ;;
 win32) thread_header=config/i386/gthr-win32.h ;;
+*)
+AC_MSG_ERROR([No known header for threading model '$1'.])
+;;
 esac
 AC_SUBST(thread_header)
 ])
diff --git a/libatomic/configure.ac b/libatomic/configure.ac
index 2a371870c2f..42d2016b7a2 100644
--- a/libatomic/configure.ac
+++ b/libatomic/configure.ac
@@ -161,9 +161,7 @@ libtool_VERSION=3:0:2
 AC_SUBST(libtool_VERSION)
 
 # Check for used threading-model
-AC_MSG_CHECKING([for thread model used by GCC])
-target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
-AC_MSG_RESULT([$target_thread_file])
+GCC_AC_THREAD_MODEL
 
 case "$target" in
  *aarch64*)
diff --git a/libgcc/configure.ac b/libgcc/configure.ac
index 13a80b2551b..1209a0986e0 100644
--- a/libgcc/configure.ac
+++ b/libgcc/configure.ac
@@ -298,9 +298,7 @@ AC_SUBST([use_tm_clone_registry])
 
 AC_LIB_PROG_LD_GNU
 
-AC_MSG_CHECKING([for thread model used by GCC])
-target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
-AC_MSG_RESULT([$target_thread_file]) 
+GCC_AC_THREAD_MODEL
 
 # Check for assembler CFI support.
 AC_CACHE_CHECK([whether assembler supports CFI directives], [libgcc_cv_cfi],
diff --git a/libphobos/m4/druntime/os.m4 b/libphobos/m4/druntime/os.m4
index 351558dbcda..2b44fbca8fc 100644
--- 

[Patch] gcc.c-torture/execute: Fix tmpnam issue on Windows

2021-08-21 Thread Jonathan Yong via Gcc-patches

Attached patch OK?

2021-08-22  Jonathan Yong  <10wa...@gmail.com>

gcc/testsuite/ChangLog:

* gcc.c-torture/execute/gcc_tmpnam.h: Fix tmpnam case on Windows
where it can return a filename with "\" to indicate current
directory.
* gcc.c-torture/execute/fprintf-2.c: Use wrapper.
* gcc.c-torture/execute/printf-2.c: Use wrapper.
* gcc.c-torture/execute/user-printf.c: Use wrapper.

From a42f25168397de2f45e44b05b6e49cc455a5b7a7 Mon Sep 17 00:00:00 2001
From: Jonathan Yong <10wa...@gmail.com>
Date: Sun, 22 Aug 2021 03:05:07 +
Subject: [PATCH] gcc.c-torture/execute: Fix tmpnam issue on Windows

2021-08-22  Jonathan Yong  <10wa...@gmail.com>

gcc/testsuite/ChangLog:

	* gcc.c-torture/execute/gcc_tmpnam.h: Fix tmpnam case on Windows
	where it can return a filename with "\" to indicate current
	directory.
	* gcc.c-torture/execute/fprintf-2.c: Use wrapper.
	* gcc.c-torture/execute/printf-2.c: Use wrapper.
	* gcc.c-torture/execute/user-printf.c: Use wrapper.

Signed-off-by: Jonathan Yong <10wa...@gmail.com>
---
 gcc/testsuite/gcc.c-torture/execute/fprintf-2.c   |  3 ++-
 gcc/testsuite/gcc.c-torture/execute/gcc_tmpnam.h  | 13 +
 gcc/testsuite/gcc.c-torture/execute/printf-2.c|  3 ++-
 gcc/testsuite/gcc.c-torture/execute/user-printf.c |  3 ++-
 4 files changed, 19 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/execute/gcc_tmpnam.h

diff --git a/gcc/testsuite/gcc.c-torture/execute/fprintf-2.c b/gcc/testsuite/gcc.c-torture/execute/fprintf-2.c
index d8e19e7b2f8..00517d1d1ac 100644
--- a/gcc/testsuite/gcc.c-torture/execute/fprintf-2.c
+++ b/gcc/testsuite/gcc.c-torture/execute/fprintf-2.c
@@ -9,10 +9,11 @@
 #include 
 #include 
 #include 
+#include "gcc_tmpnam.h"
 
 int main (void)
 {
-  char *tmpfname = tmpnam (0);
+  char *tmpfname = gcc_tmpnam (0);
   FILE *f = fopen (tmpfname, "w");
   if (!f)
 {
diff --git a/gcc/testsuite/gcc.c-torture/execute/gcc_tmpnam.h b/gcc/testsuite/gcc.c-torture/execute/gcc_tmpnam.h
new file mode 100644
index 000..2136e6eaf13
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/gcc_tmpnam.h
@@ -0,0 +1,13 @@
+#include 
+#ifndef GCC_TMPNAM
+#define GCC_TMPNAM
+static inline char *gcc_tmpnam(char *s)
+{
+  char *ret = tmpnam (s);
+  // Windows sometimes prepends a backslash to denote the current directory,
+  // so swallow that if it occurs
+  if (ret[0] == '\\')
+++ret;
+  return ret;
+}
+#endif
diff --git a/gcc/testsuite/gcc.c-torture/execute/printf-2.c b/gcc/testsuite/gcc.c-torture/execute/printf-2.c
index 4e7d8f7cdfa..2087bba8448 100644
--- a/gcc/testsuite/gcc.c-torture/execute/printf-2.c
+++ b/gcc/testsuite/gcc.c-torture/execute/printf-2.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include "gcc_tmpnam.h"
 
 __attribute__ ((noipa)) void
 write_file (void)
@@ -26,7 +27,7 @@ write_file (void)
 
 int main (void)
 {
-  char *tmpfname = tmpnam (0);
+  char *tmpfname = gcc_tmpnam (0);
   FILE *f = freopen (tmpfname, "w", stdout);
   if (!f)
 {
diff --git a/gcc/testsuite/gcc.c-torture/execute/user-printf.c b/gcc/testsuite/gcc.c-torture/execute/user-printf.c
index 42a3b17f123..bfee0760dd7 100644
--- a/gcc/testsuite/gcc.c-torture/execute/user-printf.c
+++ b/gcc/testsuite/gcc.c-torture/execute/user-printf.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include "gcc_tmpnam.h"
 
 void __attribute__ ((format (printf, 1, 2), noipa))
 user_print (const char *fmt, ...)
@@ -23,7 +24,7 @@ user_print (const char *fmt, ...)
 
 int main (void)
 {
-  char *tmpfname = tmpnam (0);
+  char *tmpfname = gcc_tmpnam (0);
   FILE *f = freopen (tmpfname, "w", stdout);
   if (!f)
 {
-- 
2.33.0



OpenPGP_0x713B5FE29C145D45.asc
Description: OpenPGP public key


OpenPGP_signature
Description: OpenPGP digital signature


Re: [PATCH] libgfortran : Use the libtool macro to determine libm availability.

2021-08-21 Thread Eric Gallager via Gcc-patches
On Fri, Aug 20, 2021 at 3:53 AM Tobias Burnus  wrote:
>
> On 20.08.21 09:34, Richard Biener via Fortran wrote:
>
> > On Thu, Aug 19, 2021 at 10:10 PM Iain Sandoe  wrote:
> >> libm is not needed on Darwin, and should not be added unconditionally
> >> even if that is (mostly) harmless since it is a symlink to libc.
> >>
> >> tested on x86_64, i686-darwin, x86_64-linux,
> >> OK for master?
> > OK.
> > Richard.
>
> Looks also good to me – but for completeness and as background, I also
> want to remark the following.
>
> (At least as I understand it, I did not dig deeper.)
>
> > --- a/libgfortran/configure.ac
> > +++ b/libgfortran/configure.ac
> > ...
> > +AC_CHECK_LIBM
>
> This CHECK_LIBM has a hard-coded list of targets and for some (like
> Darwin) it simply does not set $LIBM.

I thought the proper macro to use was LT_LIB_M ?

>
> >> +++ b/libgfortran/Makefile.am
> >> @@ -42,7 +42,7 @@ libgfortran_la_LINK = $(LINK) $(libgfortran_la_LDFLAGS)
> >>   libgfortran_la_LDFLAGS = -version-info `grep -v '^\#' 
> >> $(srcdir)/libtool-version` \
> >>  $(LTLDFLAGS) $(LIBQUADLIB) ../libbacktrace/libbacktrace.la \
> >>  $(HWCAP_LDFLAGS) \
> >> -   -lm $(extra_ldflags_libgfortran) \
> >> +   $(LIBM) $(extra_ldflags_libgfortran) \
>
> I think usage like this one do not actually link '-lm' as
> gcc/config/darwin.h contains:
>
> #define LINK_SPEC  \
> ...
> %:remove-outfile(-lm) \
>
> However, this spec change comes too early for:
> > --- a/libgfortran/libgfortran.spec.in
> > +++ b/libgfortran/libgfortran.spec.in
> > @@ -5,4 +5,4 @@
> >   #
> >
> >   %rename lib liborig
> > -*lib: @LIBQUADSPEC@ -lm %(libgcc) %(liborig)
> > +*lib: @LIBQUADSPEC@  @LIBM@ %(libgcc) %(liborig)
> NIT: There are two spaces instead of one before @LIBM@.
>
> Thus, it makes sense to the unconditional '-lm' from the .spec file.
>
> Tobias
>
> -
> Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
> München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
> Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
> München, HRB 106955


[COMMITTED] MAINTAINERS: Add myself for write after approval

2021-08-21 Thread Dragan Mladjenovic via Gcc-patches
2021-08-21  Dragan Mladjenovic  

ChangeLog:

* MAINTAINERS: Add myself for write after approval.
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 7b03fc25f4d..b8d5f16f85f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -531,6 +531,7 @@ Bingfeng Mei

 Jim Meyering   
 Martin Michlmayr   
 Lee Millward   
+Dragan Mladjenovic 
 Alan Modra 
 Catherine Moore
 James A. Morrison  
-- 
2.17.1

[committed] hppa: Don't build libgcc_stub.a on hppa[12]*-*-hpux11*

2021-08-21 Thread John David Anglin
libgcc_stub.a is not needed on hppa[12]*-*-hpux11*, so don't build it.

Tested on hppa2.0w-hp-hpux11.11.  Committed to trunk.

Dave
---

Don't build libgcc_stub.a on hppa[12]*-*-hpux11*.

2021-08-21  John David Anglin  

libgcc/ChangeLog:
* config.host: Remove extra_parts from hppa[12]*-*-hpux11* case.

diff --git a/libgcc/config.host b/libgcc/config.host
index 8ca7a00082a..8b636743c63 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -667,7 +667,6 @@ hppa[12]*-*-hpux11*)
tmake_file="$tmake_file pa/t-slibgcc-dwarf-ver"
fi
tmake_file="$tmake_file pa/t-slibgcc-hpux t-slibgcc-hpux"
-   extra_parts="libgcc_stub.a"
md_unwind_header=pa/hpux-unwind.h
;;
 hppa*-*-openbsd*)


RE: [PATCH][MIPS] Remove TARGET_ASM_FUNCTION_RODATA_SECTION

2021-08-21 Thread Dragan Mladjenovic via Gcc-patches


From: Jeff Law [mailto:jeffreya...@gmail.com] 
Sent: 19 August 2021 18:03
To: Dragan Mladjenovic ; 
gcc-patches@gcc.gnu.org
Cc: Andrew Pinski 
Subject: Re: [PATCH][MIPS] Remove TARGET_ASM_FUNCTION_RODATA_SECTION


> On 8/19/2021 6:11 AM, Dragan Mladjenovic wrote:
> > Since 'Remove obsolete IRIX 6.5 support' [1] we only use
> > gp-relative jump-tables for PIC code. We can fall back to
> > default behaviour for asm_function_rodata_section.
> >
> > [1] https://gcc.gnu.org/ml/libstdc++/2012-03/msg00067.html
> >
> > 2018-06-04 Dragan Mladjenovic 
> > gcc/
> >
> > * config/mips/mips.c (mips_function_rodata_section,
> > TARGET_ASM_FUNCTION_RODATA_SECTION): Removed.
> OK
> jeff

Thanks,

Committed as 304ec0d1d9f177e059e695fbe11d93f99f6f14e0.

Dragan


[committed] hppa: Don't warn when alignment of global common data exceeds maximum alignment

2021-08-21 Thread John David Anglin
On 32-bit hppa*-hpux*, global common data is used for one-only support.  The 
warning in
pa_asm_output_aligned_common() causes numerous tests in the libstdc++-v3 to 
fail due to
excess errors.

The only code that requires more alignment is the ldcw semaphore instruction, 
so I believe
we don't need the warning.

Tested on hppa2.0w-hp-hpux11.11 and hppa64-hp-hpux11.11.  Committed to trunk.

Dave
---

Don't warn when alignment of global common data exceeds maximum alignment.

2021-08-21  John David Anglin  

gcc/ChangeLog:
* config/pa/pa.c (pa_asm_output_aligned_common): Remove warning.

diff --git a/gcc/config/pa/pa.c b/gcc/config/pa/pa.c
index 46194ba395d..06143023b46 100644
--- a/gcc/config/pa/pa.c
+++ b/gcc/config/pa/pa.c
@@ -9080,9 +9080,7 @@ pa_asm_output_aligned_common (FILE *stream,
   max_common_align = TARGET_64BIT ? 128 : (size >= 4096 ? 256 : 64);
   if (align > max_common_align)
 {
-  warning (0, "alignment (%u) for %s exceeds maximum alignment "
-  "for global common data.  Using %u",
-  align / BITS_PER_UNIT, name, max_common_align / BITS_PER_UNIT);
+  /* Alignment exceeds maximum alignment for global common data.  */
   align = max_common_align;
 }



[r12-3052 Regression] FAIL: gcc.dg/analyzer/malloc-callbacks.c (test for excess errors) on Linux/x86_64

2021-08-21 Thread sunil.k.pandey via Gcc-patches
On Linux/x86_64,

e92d0ff6b5e6d4b95c04fc3e326d40efeb136086 is the first bad commit
commit e92d0ff6b5e6d4b95c04fc3e326d40efeb136086
Author: Ankur Saini 
Date:   Thu Aug 19 19:54:56 2021 +0530

analyzer: Fix PR analyzer/101980

caused

FAIL: gcc.dg/analyzer/malloc-callbacks.c (test for excess errors)

with GCC configured with



To reproduce:

$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="analyzer.exp=gcc.dg/analyzer/malloc-callbacks.c 
--target_board='unix{-m32}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="analyzer.exp=gcc.dg/analyzer/malloc-callbacks.c 
--target_board='unix{-m32\ -march=cascadelake}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="analyzer.exp=gcc.dg/analyzer/malloc-callbacks.c 
--target_board='unix{-m64}'"
$ cd {build_dir}/gcc && make check 
RUNTESTFLAGS="analyzer.exp=gcc.dg/analyzer/malloc-callbacks.c 
--target_board='unix{-m64\ -march=cascadelake}'"

(Please do not reply to this email, for question about this report, contact me 
at skpgkp2 at gmail dot com)


Re: [PATCH] IPA: MODREF should skip EAF_* flags for indirect calls

2021-08-21 Thread Martin Jambor
Hi,

On Fri, Aug 20 2021, Martin Liška wrote:
> Hello.
>
> As showed in the PR, returning (EAF_NOCLOBBER | EAF_NOESCAPE) for an argument
> that is a function pointer is problematic. Doing such a function call is a 
> clobber.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?
> Thanks,
> Martin
>
>   PR 101949
>
> gcc/ChangeLog:
>
>   * ipa-modref.c (analyze_ssa_name_flags): Do not propagate EAF
> flags arguments for indirect functions.
>
> gcc/testsuite/ChangeLog:
>
>   * gcc.dg/lto/pr101949_0.c: New test.
>   * gcc.dg/lto/pr101949_1.c: New test.
>
> Co-Authored-By: Richard Biener 
> ---
>   gcc/ipa-modref.c  |  3 +++
>   gcc/testsuite/gcc.dg/lto/pr101949_0.c | 20 
>   gcc/testsuite/gcc.dg/lto/pr101949_1.c |  4 
>   3 files changed, 27 insertions(+)
>   create mode 100644 gcc/testsuite/gcc.dg/lto/pr101949_0.c
>   create mode 100644 gcc/testsuite/gcc.dg/lto/pr101949_1.c
>
> diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c
> index fafd804d4ba..380ba6926b9 100644
> --- a/gcc/ipa-modref.c
> +++ b/gcc/ipa-modref.c
> @@ -1715,6 +1715,9 @@ analyze_ssa_name_flags (tree name, vec 
> , int depth,
> else if (callee && !ipa && recursive_call_p (current_function_decl,
> callee))
>   lattice[index].merge (0);
> +   /* Ignore indirect calls (PR101949).  */
> +   else if (callee == NULL_TREE)
> + lattice[index].merge (0);

I just had a quick glance, but wouldn't bailing out only when

  gimple_call_fn (call) == name

suffice here?  Otherwise it seems to trigger also when passing NAME to
an indirectly called function about which we might learn something from
gimple_call_fntype, as the code apparently tries later on.

Martin