Re: [PATCH] Improve location for new statements in match-and-simplify phiopt

2021-12-18 Thread Richard Biener via Gcc-patches
On December 18, 2021 11:56:48 PM GMT+01:00, apinski--- via Gcc-patches 
 wrote:
>From: Andrew Pinski 
>
>Before match-and-simplify was used in phiot, the location of the
>new stamtents were all of that of the conditional, this adds that
>back as I did not realize gimple_simplify didn't do that for you.
>
>OK? Bootstrapped and tested on x86_64 with no regressions.

OK. 

Richard. 

>gcc/ChangeLog:
>
>   * tree-ssa-phiopt.c (gimple_simplify_phiopt): Annotate the
>   new sequence with the location of the conditional statement.
>---
> gcc/tree-ssa-phiopt.c | 4 
> 1 file changed, 4 insertions(+)
>
>diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
>index 3eac9b1ce46..714deab005a 100644
>--- a/gcc/tree-ssa-phiopt.c
>+++ b/gcc/tree-ssa-phiopt.c
>@@ -900,6 +900,8 @@ gimple_simplify_phiopt (bool early_p, tree type, gimple 
>*comp_stmt,
> result = maybe_push_res_to_seq (, );
> if (result)
>   {
>+if (loc != UNKNOWN_LOCATION)
>+  annotate_all_with_location (seq1, loc);
> gimple_seq_add_seq_without_update (seq, seq1);
> return result;
>   }
>@@ -929,6 +931,8 @@ gimple_simplify_phiopt (bool early_p, tree type, gimple 
>*comp_stmt,
> result = maybe_push_res_to_seq (, );
> if (result)
>   {
>+if (loc != UNKNOWN_LOCATION)
>+  annotate_all_with_location (seq1, loc);
> gimple_seq_add_seq_without_update (seq, seq1);
> return result;
>   }



Re: [PATCH v3 06/12] LoongArch Port: Builtin macros.

2021-12-18 Thread Paul Hua via Gcc-patches
Hi Ruoyao,
Thank you for your attention.

> GCC 12 development cycle is at stage 3 (general bugfixing) now.  So a
> new port have to wait until stage 1 of GCC 13 begins (in mid 2022, I
> guess).
I know it is stage3, but we are a new target, it's ok for GCC 12.


Re: [PATCH] c++: Avoid narrowing in make_char_string_pack

2021-12-18 Thread Eric Gallager via Gcc-patches
On Fri, Dec 17, 2021 at 5:59 PM Marek Polacek via Gcc-patches
 wrote:
>
> This fixes
>
> gcc/cp/parser.c:4618:41: warning: narrowing conversion of '(char)(*(str + 
> ((sizetype)i)))' from 'char' to 'unsigned char' [-Wnarrowing]
>  4618 |   unsigned char s[3] = { '\'', str[i], '\'' };
>   |~^
>
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
>

Hi, I thought that GCC was built with -Wno-narrowing; has that changed
since I last checked? I'd support a move to officially switch from
disabling -Wnarrowing to enabling it instead if that's possible and
hasn't been done yet. Also the '(char)(*(str + ((sizetype)i)))' looks
like some implementation details leaking; is there a bug against
-Wnarrowing (or the diagnostics system in general) open about that?

> gcc/cp/ChangeLog:
>
> * parser.c (make_char_string_pack): Add a cast to const unsigned
> char *.
> ---
>  gcc/cp/parser.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
> index 44eed7ea638..56232ab029f 100644
> --- a/gcc/cp/parser.c
> +++ b/gcc/cp/parser.c
> @@ -4607,7 +4607,8 @@ make_char_string_pack (tree value)
>  {
>tree charvec;
>tree argpack = make_node (NONTYPE_ARGUMENT_PACK);
> -  const char *str = TREE_STRING_POINTER (value);
> +  const unsigned char *str
> += (const unsigned char *) TREE_STRING_POINTER (value);
>int i, len = TREE_STRING_LENGTH (value) - 1;
>tree argvec = make_tree_vec (1);
>
>
> base-commit: d7ca2a79b82c6500ead6ab983d14c609e2124eee
> --
> 2.33.1
>


[PATCH] Improve location for new statements in match-and-simplify phiopt

2021-12-18 Thread apinski--- via Gcc-patches
From: Andrew Pinski 

Before match-and-simplify was used in phiot, the location of the
new stamtents were all of that of the conditional, this adds that
back as I did not realize gimple_simplify didn't do that for you.

OK? Bootstrapped and tested on x86_64 with no regressions.

gcc/ChangeLog:

* tree-ssa-phiopt.c (gimple_simplify_phiopt): Annotate the
new sequence with the location of the conditional statement.
---
 gcc/tree-ssa-phiopt.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
index 3eac9b1ce46..714deab005a 100644
--- a/gcc/tree-ssa-phiopt.c
+++ b/gcc/tree-ssa-phiopt.c
@@ -900,6 +900,8 @@ gimple_simplify_phiopt (bool early_p, tree type, gimple 
*comp_stmt,
  result = maybe_push_res_to_seq (, );
  if (result)
{
+ if (loc != UNKNOWN_LOCATION)
+   annotate_all_with_location (seq1, loc);
  gimple_seq_add_seq_without_update (seq, seq1);
  return result;
}
@@ -929,6 +931,8 @@ gimple_simplify_phiopt (bool early_p, tree type, gimple 
*comp_stmt,
  result = maybe_push_res_to_seq (, );
  if (result)
{
+ if (loc != UNKNOWN_LOCATION)
+   annotate_all_with_location (seq1, loc);
  gimple_seq_add_seq_without_update (seq, seq1);
  return result;
}
-- 
2.17.1



[PATCH, committed] PR fortran/103412 - [10/11/12 Regression] ICE: Invalid expression in gfc_element_size since r10-2083-g8dc63166e0b85954

2021-12-18 Thread Harald Anlauf via Gcc-patches
Dear all,

committed as obvious after discussion with Steve: SIZEOF() cannot
accept a BOZ argument which has no defined type.

Regtested on x86_64-pc-linux-gnu.

Thanks,
Harald

From fd74a2ee40456a1d1621e88738f8e57536194080 Mon Sep 17 00:00:00 2001
From: Harald Anlauf 
Date: Sat, 18 Dec 2021 23:21:35 +0100
Subject: [PATCH] Fortran: reject BOZ type argument to SIZEOF().

gcc/fortran/ChangeLog:

	PR fortran/103412
	* check.c (gfc_check_sizeof): Reject BOZ type argument.

gcc/testsuite/ChangeLog:

	PR fortran/103412
	* gfortran.dg/illegal_boz_arg_2.f90: New test.
---
 gcc/fortran/check.c | 3 +++
 gcc/testsuite/gfortran.dg/illegal_boz_arg_2.f90 | 6 ++
 2 files changed, 9 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/illegal_boz_arg_2.f90

diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index 3934336df2e..625473c90d1 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -5135,6 +5135,9 @@ gfc_check_sizeof (gfc_expr *arg)
   return false;
 }

+  if (illegal_boz_arg (arg))
+return false;
+
   /* TYPE(*) is acceptable if and only if it uses an array descriptor.  */
   if (arg->ts.type == BT_ASSUMED
   && (arg->symtree->n.sym->as == NULL
diff --git a/gcc/testsuite/gfortran.dg/illegal_boz_arg_2.f90 b/gcc/testsuite/gfortran.dg/illegal_boz_arg_2.f90
new file mode 100644
index 000..3e5f6b6d1d4
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/illegal_boz_arg_2.f90
@@ -0,0 +1,6 @@
+! { dg-do compile }
+! PR fortran/103412
+
+program p
+  integer, parameter :: a = sizeof(z'1') ! { dg-error "cannot be an actual" }
+end
--
2.26.2



Re: [PATCH] config: Add check whether D compiler works (PR103528)

2021-12-18 Thread Segher Boessenkool
On Fri, Dec 17, 2021 at 12:12:28AM +0100, Iain Buclaw wrote:
> Hi,
> 
> This patch extends AC_PROG_GDC so that as well as checking for the
> existence of a GDC compiler, also validate that it has also been built
> with libphobos, otherwise warn or fail with the message that GDC is
> required to build d.
> 
> Tested on a system running powerpcle-linux both without a D compiler,
> and with a D compiler configured with --disable-libphobos.
> 
> This would also help with Solaris and Darwin ports, where support for
> both D and runtime isn't present across all current releases. 
> 
> OK for mainline?

This fixes PR103739 by not building D at all anymore.  That is also a
regression of course, but at least it doesn't break bootstrap anymore :-)

Thanks,


Segher


Re: [PATCH, rs6000] Implement mffscrni pattern

2021-12-18 Thread Segher Boessenkool
On Fri, Dec 17, 2021 at 10:33:12PM -0500, David Edelsohn wrote:
> On Thu, Dec 16, 2021 at 9:43 PM HAO CHEN GUI  wrote:
> > +(define_insn "rs6000_mffscrni"
> > +  [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
> > +   (unspec_volatile:DF [(match_operand:DF 1 "u2bit_cint_operand" "n")]
> 
> Why is this input operand 1 DFmode?  This is a 2 bit integer value.
> This pattern is called from rs6000_set_fpscr_rn with an SImode
> operand, and it seems that this should be SImode as well.

Yup.  This predicate will only allow const_int, and matching a const_int
ignores the mode, so most (or all?) things will work whatever mode you
give here.  But only MODE_INT modes make sense (and possibly VOIDmode,
but VOIDmode in machine descriptions means anything is allowed, also not
what you want here).


Segher


Re: [PATCH] config.gcc: Obsolete m32c-rtems target

2021-12-18 Thread Joel Sherrill
On Sat, Dec 18, 2021 at 10:13 AM Joel Sherrill  wrote:
>
>
>
> On Fri, Dec 17, 2021, 9:57 PM Jeff Law  wrote:
>>
>>
>>
>> On 12/17/2021 9:10 AM, Joel Sherrill wrote:
>> > ---
>> >   gcc/config.gcc | 1 +
>> >   1 file changed, 1 insertion(+)
>> >
>> > diff --git a/gcc/config.gcc b/gcc/config.gcc
>> > index c8824367b13..fe93a72a16c 100644
>> > --- a/gcc/config.gcc
>> > +++ b/gcc/config.gcc
>> > @@ -252,6 +252,7 @@ case ${target} in
>> >| cr16-*-* \
>> >| hppa[12]*-*-hpux10*  \
>> >| hppa[12]*-*-hpux11*  \
>> > + | m32c-*-rtems* \
>> >)
>> >   if test "x$enable_obsolete" != xyes; then
>> > echo "*** Configuration ${target} is obsolete." >&2
>> OK.  Given that last time I tried, I couldn't even get m32c to build
>> newlib, I'm not terribly surprised you're deprecating it from rtems.
>
>
> We removed it over a while back. The last release branch with it was using 
> gcc 7 or 8.
>
> We had no indication there were any users and it led to removing some 
> alternative implementations optimised for 16 bit CPUs.
>
>>
>> I would support deprecation of m32c-*.
>
>
> No complaint here.

Can I commit the gcc and wwwdocs patch for m32c-rtems and let Jeff or
someone follow up completely eliminating m32c?

Thanks.

--joel

>
> --joel
>>
>>
>> jeff


Re: [PATCH v3 04/12] LoongArch Port: Machine description C files and .h files.

2021-12-18 Thread Xi Ruoyao via Gcc-patches
On Fri, 2021-12-10 at 15:43 +0800, Chenghua Xu wrote:

> +#undef TARGET_ASM_CODE_END
> +#define TARGET_ASM_CODE_END loongarch_code_end

/* snip */

> +static void
> +loongarch_code_end (void)
> +{
> +  if (NEED_INDICATE_EXEC_STACK)
> +/* Add .note.GNU-stack.  */
> +file_end_indicate_exec_stack ();
> +}
> +

Hi Chenghua,

I think this should be put into TARGET_ASM_FILE_END (like how MIPS and
ARM port do this) instead of TARGET_ASM_CODE_END.

Consider compiling a "hello world" program with -flto -g:

$ loongarch64-linux-gnu-gcc hw.c -flto -g

During the LTO pass, a file containing debug info named "a-
hw.o.debug.temp.o" is created.  This file does not contain any code. 
But .note.GNU-stack should still be emitted into it, or when it's linked
into a.out, a.out will have executable stack which is bad for security.

Now I get 650 files in /usr/bin with executable stack in my 5th Linux
>From Scratch build on LoongArch!  Will start over and do 6th.
-- 
Xi Ruoyao 
School of Aerospace Science and Technology, Xidian University


Re: [PATCH] config.gcc: Obsolete m32c-rtems target

2021-12-18 Thread Joel Sherrill
On Fri, Dec 17, 2021, 9:57 PM Jeff Law  wrote:

>
>
> On 12/17/2021 9:10 AM, Joel Sherrill wrote:
> > ---
> >   gcc/config.gcc | 1 +
> >   1 file changed, 1 insertion(+)
> >
> > diff --git a/gcc/config.gcc b/gcc/config.gcc
> > index c8824367b13..fe93a72a16c 100644
> > --- a/gcc/config.gcc
> > +++ b/gcc/config.gcc
> > @@ -252,6 +252,7 @@ case ${target} in
> >| cr16-*-* \
> >| hppa[12]*-*-hpux10*  \
> >| hppa[12]*-*-hpux11*  \
> > + | m32c-*-rtems* \
> >)
> >   if test "x$enable_obsolete" != xyes; then
> > echo "*** Configuration ${target} is obsolete." >&2
> OK.  Given that last time I tried, I couldn't even get m32c to build
> newlib, I'm not terribly surprised you're deprecating it from rtems.
>

We removed it over a while back. The last release branch with it was using
gcc 7 or 8.

We had no indication there were any users and it led to removing some
alternative implementations optimised for 16 bit CPUs.


> I would support deprecation of m32c-*.
>

No complaint here.

--joel

>
> jeff
>


[PATCH v5 4/4] tree-object-size: Dynamic sizes for ADDR_EXPR

2021-12-18 Thread Siddhesh Poyarekar
Allow returning dynamic expressions from ADDR_EXPR for
__builtin_dynamic_object_size and also allow offsets to be dynamic.

gcc/ChangeLog:

* tree-object-size.c (size_valid_p): New function.
(size_for_offset): Remove OFFSET constness assertion.
(addr_object_size): Build dynamic expressions for object
sizes and use size_valid_p to decide if it is valid for the
given OBJECT_SIZE_TYPE.
(compute_builtin_object_size): Allow dynamic offsets when
computing size at O0.
(call_object_size): Call size_valid_p.
(plus_stmt_object_size): Allow non-constant offset and use
size_valid_p to decide if it is valid for the given
OBJECT_SIZE_TYPE.

gcc/testsuite/ChangeLog:

* gcc.dg/builtin-dynamic-object-size-0.c: Add new tests.
* gcc.dg/builtin-object-size-1.c (test1)
[__builtin_object_size]: Adjust expected output for dynamic
object sizes.
* gcc.dg/builtin-object-size-2.c (test1)
[__builtin_object_size]: Likewise.
* gcc.dg/builtin-object-size-3.c (test1)
[__builtin_object_size]: Likewise.
* gcc.dg/builtin-object-size-4.c (test1)
[__builtin_object_size]: Likewise.

Signed-off-by: Siddhesh Poyarekar 
---
 .../gcc.dg/builtin-dynamic-object-size-0.c| 158 ++
 gcc/testsuite/gcc.dg/builtin-object-size-1.c  |  30 +++-
 gcc/testsuite/gcc.dg/builtin-object-size-2.c  |  43 -
 gcc/testsuite/gcc.dg/builtin-object-size-3.c  |  25 ++-
 gcc/testsuite/gcc.dg/builtin-object-size-4.c  |  17 +-
 gcc/tree-object-size.c|  91 +-
 6 files changed, 300 insertions(+), 64 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c 
b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
index d67cf4a3c07..ba710f47f1c 100644
--- a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
+++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
@@ -250,6 +250,79 @@ test_deploop (size_t sz, size_t cond)
   return __builtin_dynamic_object_size (bin, 0);
 }
 
+/* Address expressions.  */
+
+struct dynarray_struct
+{
+  long a;
+  char c[16];
+  int b;
+};
+
+size_t
+__attribute__ ((noinline))
+test_dynarray_struct (size_t sz, size_t off)
+{
+  struct dynarray_struct bin[sz];
+
+  return __builtin_dynamic_object_size ([off].c, 0);
+}
+
+size_t
+__attribute__ ((noinline))
+test_dynarray_struct_subobj (size_t sz, size_t off)
+{
+  struct dynarray_struct bin[sz];
+
+  return __builtin_dynamic_object_size ([off].c[4], 1);
+}
+
+size_t
+__attribute__ ((noinline))
+test_dynarray_struct_subobj2 (size_t sz, size_t off, size_t *objsz)
+{
+  struct dynarray_struct2
+{
+  long a;
+  int b;
+  char c[sz];
+};
+
+  struct dynarray_struct2 bin;
+
+  *objsz = sizeof (bin);
+
+  return __builtin_dynamic_object_size ([off], 1);
+}
+
+size_t
+__attribute__ ((noinline))
+test_substring (size_t sz, size_t off)
+{
+  char str[sz];
+
+  return __builtin_dynamic_object_size ([off], 0);
+}
+
+size_t
+__attribute__ ((noinline))
+test_substring_ptrplus (size_t sz, size_t off)
+{
+  int str[sz];
+
+  return __builtin_dynamic_object_size (str + off, 0);
+}
+
+size_t
+__attribute__ ((noinline))
+test_substring_ptrplus2 (size_t sz, size_t off, size_t off2)
+{
+  int str[sz];
+  int *ptr = [off];
+
+  return __builtin_dynamic_object_size (ptr + off2, 0);
+}
+
 size_t
 __attribute__ ((access (__read_write__, 1, 2)))
 __attribute__ ((noinline))
@@ -258,6 +331,40 @@ test_parmsz_simple (void *obj, size_t sz)
   return __builtin_dynamic_object_size (obj, 0);
 }
 
+size_t
+__attribute__ ((noinline))
+__attribute__ ((access (__read_write__, 1, 2)))
+test_parmsz (void *obj, size_t sz, size_t off)
+{
+  return __builtin_dynamic_object_size (obj + off, 0);
+}
+
+size_t
+__attribute__ ((noinline))
+__attribute__ ((access (__read_write__, 1, 2)))
+test_parmsz_scale (int *obj, size_t sz, size_t off)
+{
+  return __builtin_dynamic_object_size (obj + off, 0);
+}
+
+size_t
+__attribute__ ((noinline))
+__attribute__ ((access (__read_write__, 1, 2)))
+test_loop (int *obj, size_t sz, size_t start, size_t end, int incr)
+{
+  int *ptr = obj + start;
+
+  for (int i = start; i != end; i = i + incr)
+{
+  ptr = ptr + incr;
+  if (__builtin_dynamic_object_size (ptr, 0) == 0)
+   return 0;
+}
+
+  return __builtin_dynamic_object_size (ptr, 0);
+}
+
+
 unsigned nfails = 0;
 
 #define FAIL() ({ \
@@ -318,6 +425,31 @@ main (int argc, char **argv)
 FAIL ();
   if (test_dynarray (__builtin_strlen (argv[0])) != __builtin_strlen (argv[0]))
 FAIL ();
+  if (test_dynarray_struct (42, 4) !=
+  ((42 - 4) * sizeof (struct dynarray_struct)
+   - __builtin_offsetof (struct dynarray_struct, c)))
+FAIL ();
+  if (test_dynarray_struct (42, 48) != 0)
+FAIL ();
+  if (test_substring (128, 4) != 128 - 4)
+FAIL ();
+  if (test_substring (128, 142) != 0)
+FAIL ();
+  if (test_dynarray_struct_subobj (42, 4) != 16 - 4)
+

[PATCH v5 3/4] tree-object-size: Handle GIMPLE_CALL

2021-12-18 Thread Siddhesh Poyarekar
Handle non-constant expressions in GIMPLE_CALL arguments.  Also handle
alloca.

gcc/ChangeLog:

* tree-object-size.c (alloc_object_size): Make and return
non-constant size expression.
(call_object_size): Return expression or unknown based on
whether dynamic object size is requested.

gcc/testsuite/ChangeLog:

* gcc.dg/builtin-dynamic-object-size-0.c: Add new tests.
* gcc.dg/builtin-object-size-1.c (test1)
[__builtin_object_size]: Alter expected result for dynamic
object size.
* gcc.dg/builtin-object-size-2.c (test1)
[__builtin_object_size]: Likewise.
* gcc.dg/builtin-object-size-3.c (test1)
[__builtin_object_size]: Likewise.
* gcc.dg/builtin-object-size-4.c (test1)
[__builtin_object_size]: Likewise.

Signed-off-by: Siddhesh Poyarekar 
---
Changes since v4:
- Free allocations in tests.

 .../gcc.dg/builtin-dynamic-object-size-0.c| 251 +-
 gcc/testsuite/gcc.dg/builtin-object-size-1.c  |   7 +
 gcc/testsuite/gcc.dg/builtin-object-size-2.c  |  14 +
 gcc/testsuite/gcc.dg/builtin-object-size-3.c  |   7 +
 gcc/testsuite/gcc.dg/builtin-object-size-4.c  |  14 +
 gcc/tree-object-size.c|  22 +-
 6 files changed, 307 insertions(+), 8 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c 
b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
index 7616ffa4cf0..d67cf4a3c07 100644
--- a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
+++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
@@ -4,6 +4,73 @@
 typedef __SIZE_TYPE__ size_t;
 #define abort __builtin_abort
 
+void *
+__attribute__ ((alloc_size (1)))
+__attribute__ ((__nothrow__ , __leaf__))
+__attribute__ ((noinline))
+alloc_func (size_t sz)
+{
+  return __builtin_malloc (sz);
+}
+
+void *
+__attribute__ ((alloc_size (1, 2)))
+__attribute__ ((__nothrow__ , __leaf__))
+__attribute__ ((noinline))
+calloc_func (size_t cnt, size_t sz)
+{
+  return __builtin_calloc (cnt, sz);
+}
+
+void *
+__attribute__ ((noinline))
+unknown_allocator (size_t cnt, size_t sz)
+{
+  return __builtin_calloc (cnt, sz);
+}
+
+size_t
+__attribute__ ((noinline))
+test_unknown (size_t cnt, size_t sz)
+{
+  void *ch = unknown_allocator (cnt, sz);
+  size_t ret = __builtin_dynamic_object_size (ch, 0);
+  __builtin_free (ch);
+  return ret;
+}
+
+/* Malloc-like allocator.  */
+
+size_t
+__attribute__ ((noinline))
+test_malloc (size_t sz)
+{
+  void *ch = alloc_func (sz);
+  size_t ret = __builtin_dynamic_object_size (ch, 0);
+  __builtin_free (ch);
+  return ret;
+}
+
+size_t
+__attribute__ ((noinline))
+test_builtin_malloc (size_t sz)
+{
+  void *ch = __builtin_malloc (sz);
+  size_t ret = __builtin_dynamic_object_size (ch, 0);
+  __builtin_free (ch);
+  return ret;
+}
+
+size_t
+__attribute__ ((noinline))
+test_builtin_malloc_cond (int cond)
+{
+  void *ch = __builtin_malloc (cond ? 32 : 64);
+  size_t ret = __builtin_dynamic_object_size (ch, 0);
+  __builtin_free (ch);
+  return ret;
+}
+
 size_t
 __attribute__ ((noinline))
 test_builtin_malloc_condphi (int cond)
@@ -21,6 +88,95 @@ test_builtin_malloc_condphi (int cond)
   return ret;
 }
 
+size_t
+__attribute__ ((noinline))
+test_builtin_malloc_condphi2 (int cond, size_t in)
+{
+  void *ch;
+
+  if (cond)
+ch = __builtin_malloc (in);
+  else
+ch = __builtin_malloc (64);
+
+  size_t ret = __builtin_dynamic_object_size (ch, 0);
+
+  __builtin_free (ch);
+  return ret;
+}
+
+size_t
+__attribute__ ((noinline))
+test_builtin_malloc_condphi3 (int cond, size_t in, size_t in2)
+{
+  void *ch;
+
+  if (cond)
+ch = __builtin_malloc (in);
+  else
+ch = __builtin_malloc (in2);
+
+  size_t ret = __builtin_dynamic_object_size (ch, 0);
+
+  __builtin_free (ch);
+  return ret;
+}
+
+size_t
+__attribute__ ((noinline))
+test_builtin_malloc_condphi4 (size_t sz, int cond)
+{
+  char *a = __builtin_malloc (sz);
+  char b[sz / 2];
+
+  size_t ret = __builtin_dynamic_object_size (cond ? b : (void *) , 0);
+  __builtin_free (a);
+  return ret;
+}
+
+size_t
+__attribute__ ((noinline))
+test_builtin_malloc_condphi5 (size_t sz, int cond, char *c)
+{
+  char *a = __builtin_malloc (sz);
+
+  size_t ret = __builtin_dynamic_object_size (cond ? c : (void *) , 0);
+  __builtin_free (a);
+  return ret;
+}
+
+/* Calloc-like allocator.  */
+
+size_t
+__attribute__ ((noinline))
+test_calloc (size_t cnt, size_t sz)
+{
+  void *ch = calloc_func (cnt, sz);
+  size_t ret = __builtin_dynamic_object_size (ch, 0);
+  __builtin_free (ch);
+  return ret;
+}
+
+size_t
+__attribute__ ((noinline))
+test_builtin_calloc (size_t cnt, size_t sz)
+{
+  void *ch = __builtin_calloc (cnt, sz);
+  size_t ret = __builtin_dynamic_object_size (ch, 0);
+  __builtin_free (ch);
+  return ret;
+}
+
+size_t
+__attribute__ ((noinline))
+test_builtin_calloc_cond (int cond1, int cond2)
+{
+  void *ch = __builtin_calloc (cond1 ? 32 : 64, cond2 ? 1024 : 16);
+  size_t ret = __builtin_dynamic_object_size 

[PATCH v5 1/4] tree-object-size: Support dynamic sizes in conditions

2021-12-18 Thread Siddhesh Poyarekar
Handle GIMPLE_PHI and conditionals specially for dynamic objects,
returning PHI/conditional expressions instead of just a MIN/MAX
estimate.

This makes the returned object size variable for loops and conditionals,
so tests need to be adjusted to look for precise size in some cases.
builtin-dynamic-object-size-5.c had to be modified to only look for
success in maximum object size case and skip over the minimum object
size tests because the result is no longer a compile time constant.

I also added some simple tests to exercise conditionals with dynamic
object sizes.

gcc/ChangeLog:

* builtins.c (fold_builtin_object_size): Adjust for dynamic size
expressions.
* tree-object-size.c: Include gimplify-me.h.
(struct object_size_info): New member UNKNOWNS.
(size_initval_p, size_usable_p, object_sizes_get_raw): New
functions.
(object_sizes_get): Return suitable gimple variable for
object size.
(bundle_sizes): New function.
(object_sizes_set): Use it and handle dynamic object size
expressions.
(object_sizes_set_temp): New function.
(size_for_offset): Adjust for dynamic size expressions.
(emit_phi_nodes, propagate_unknowns, gimplify_size_expressions):
New functions.
(compute_builtin_object_size): Call gimplify_size_expressions
for OST_DYNAMIC.
(dynamic_object_size): New function.
(cond_expr_object_size): Use it.
(phi_dynamic_object_size): New function.
(collect_object_sizes_for): Call it for OST_DYNAMIC.  Adjust to
accommodate dynamic object sizes.

gcc/testsuite/ChangeLog:

* gcc.dg/builtin-dynamic-object-size-0.c: New tests.
* gcc.dg/builtin-dynamic-object-size-10.c: Add comment.
* gcc.dg/builtin-dynamic-object-size-5-main.c: New file.
* gcc.dg/builtin-dynamic-object-size-5.c: Use it and change test
to dg-do run.
* gcc.dg/builtin-object-size-5.c [!N]: Define N.
(test1, test2, test3, test4) [__builtin_object_size]: Expect
exact result for __builtin_dynamic_object_size.
* gcc.dg/builtin-object-size-1.c [__builtin_object_size]: Expect
exact size expressions for __builtin_dynamic_object_size.
* gcc.dg/builtin-object-size-2.c [__builtin_object_size]:
Likewise.
* gcc.dg/builtin-object-size-3.c [__builtin_object_size]:
Likewise.
* gcc.dg/builtin-object-size-4.c [__builtin_object_size]:
Likewise.
* gcc.dg/builtin-object-size-5.c [__builtin_object_size]:
Likewise.

Signed-off-by: Siddhesh Poyarekar 
---
Changes since v4:

- Propagate sameness of size and wholesize through PHI nodes whenever
  possible.  Check and avoid emitting wholesize if it is the same as
  size.
- Bail out and punt to __builtin_object_size if PHI node has any complex
  edges.  Use insert_seq_on_edge to emit size PHI node edge values.
- Free allocations in tests.

 gcc/builtins.c|   6 +-
 .../gcc.dg/builtin-dynamic-object-size-0.c|  77 +++
 .../gcc.dg/builtin-dynamic-object-size-10.c   |   2 +
 .../builtin-dynamic-object-size-5-main.c  |  32 ++
 .../gcc.dg/builtin-dynamic-object-size-5.c|   7 +-
 gcc/testsuite/gcc.dg/builtin-object-size-1.c  | 119 +++-
 gcc/testsuite/gcc.dg/builtin-object-size-2.c  |  92 
 gcc/testsuite/gcc.dg/builtin-object-size-3.c  | 121 +
 gcc/testsuite/gcc.dg/builtin-object-size-4.c  |  78 +++
 gcc/testsuite/gcc.dg/builtin-object-size-5.c  |  22 +-
 gcc/tree-object-size.c| 509 +-
 11 files changed, 1030 insertions(+), 35 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-dynamic-object-size-5-main.c

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 00f6c5552bf..01c24f42540 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -10285,7 +10285,8 @@ fold_builtin_object_size (tree ptr, tree ost, enum 
built_in_function fcode)
   if (TREE_CODE (ptr) == ADDR_EXPR)
 {
   compute_builtin_object_size (ptr, object_size_type, );
-  if (int_fits_type_p (bytes, size_type_node))
+  if ((object_size_type & OST_DYNAMIC)
+ || int_fits_type_p (bytes, size_type_node))
return fold_convert (size_type_node, bytes);
 }
   else if (TREE_CODE (ptr) == SSA_NAME)
@@ -10294,7 +10295,8 @@ fold_builtin_object_size (tree ptr, tree ost, enum 
built_in_function fcode)
later.  Maybe subsequent passes will help determining
it.  */
   if (compute_builtin_object_size (ptr, object_size_type, )
- && int_fits_type_p (bytes, size_type_node))
+ && ((object_size_type & OST_DYNAMIC)
+ || int_fits_type_p (bytes, size_type_node)))
return fold_convert (size_type_node, bytes);
 }
 
diff --git a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c 

[PATCH v5 2/4] tree-object-size: Handle function parameters

2021-12-18 Thread Siddhesh Poyarekar
Handle hints provided by __attribute__ ((access (...))) to compute
dynamic sizes for objects.

gcc/ChangeLog:

* tree-object-size.c: Include tree-dfa.h.
(parm_object_size): New function.
(collect_object_sizes_for): Call it.

gcc/testsuite/ChangeLog:

* gcc.dg/builtin-dynamic-object-size-0.c (test_parmsz_simple):
New function.
(main): Call it.

Signed-off-by: Siddhesh Poyarekar 
---
 .../gcc.dg/builtin-dynamic-object-size-0.c| 11 
 gcc/tree-object-size.c| 50 ++-
 2 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c 
b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
index 81588cb28a6..7616ffa4cf0 100644
--- a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
+++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
@@ -51,6 +51,14 @@ test_deploop (size_t sz, size_t cond)
   return __builtin_dynamic_object_size (bin, 0);
 }
 
+size_t
+__attribute__ ((access (__read_write__, 1, 2)))
+__attribute__ ((noinline))
+test_parmsz_simple (void *obj, size_t sz)
+{
+  return __builtin_dynamic_object_size (obj, 0);
+}
+
 unsigned nfails = 0;
 
 #define FAIL() ({ \
@@ -69,6 +77,9 @@ main (int argc, char **argv)
 FAIL ();
   if (test_deploop (128, 129) != 32)
 FAIL ();
+  if (test_parmsz_simple (argv[0], __builtin_strlen (argv[0]) + 1)
+  != __builtin_strlen (argv[0]) + 1)
+FAIL ();
 
   if (nfails > 0)
 __builtin_abort ();
diff --git a/gcc/tree-object-size.c b/gcc/tree-object-size.c
index 95cb44d9c7e..bf33ac93b93 100644
--- a/gcc/tree-object-size.c
+++ b/gcc/tree-object-size.c
@@ -32,6 +32,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-fold.h"
 #include "gimple-iterator.h"
 #include "tree-cfg.h"
+#include "tree-dfa.h"
 #include "stringpool.h"
 #include "attribs.h"
 #include "builtins.h"
@@ -1440,6 +1441,53 @@ cond_expr_object_size (struct object_size_info *osi, 
tree var, gimple *stmt)
   return reexamine;
 }
 
+/* Find size of an object passed as a parameter to the function.  */
+
+static void
+parm_object_size (struct object_size_info *osi, tree var)
+{
+  int object_size_type = osi->object_size_type;
+  tree parm = SSA_NAME_VAR (var);
+
+  if (!(object_size_type & OST_DYNAMIC) || !POINTER_TYPE_P (TREE_TYPE (parm)))
+expr_object_size (osi, var, parm);
+
+  /* Look for access attribute.  */
+  rdwr_map rdwr_idx;
+
+  tree fndecl = cfun->decl;
+  const attr_access *access = get_parm_access (rdwr_idx, parm, fndecl);
+  tree typesize = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (parm)));
+  tree sz = NULL_TREE;
+
+  if (access && access->sizarg != UINT_MAX)
+{
+  tree fnargs = DECL_ARGUMENTS (fndecl);
+  tree arg = NULL_TREE;
+  unsigned argpos = 0;
+
+  /* Walk through the parameters to pick the size parameter and safely
+scale it by the type size.  */
+  for (arg = fnargs; argpos != access->sizarg && arg;
+  arg = TREE_CHAIN (arg), ++argpos);
+
+  if (arg != NULL_TREE && INTEGRAL_TYPE_P (TREE_TYPE (arg)))
+   {
+ sz = get_or_create_ssa_default_def (cfun, arg);
+ if (sz != NULL_TREE)
+   {
+ sz = fold_convert (sizetype, sz);
+ if (typesize)
+   sz = size_binop (MULT_EXPR, sz, typesize);
+   }
+   }
+}
+  if (!sz)
+sz = size_unknown (object_size_type);
+
+  object_sizes_set (osi, SSA_NAME_VERSION (var), sz, sz);
+}
+
 /* Compute an object size expression for VAR, which is the result of a PHI
node.  */
 
@@ -1610,7 +1658,7 @@ collect_object_sizes_for (struct object_size_info *osi, 
tree var)
 case GIMPLE_NOP:
   if (SSA_NAME_VAR (var)
  && TREE_CODE (SSA_NAME_VAR (var)) == PARM_DECL)
-   expr_object_size (osi, var, SSA_NAME_VAR (var));
+   parm_object_size (osi, var);
   else
/* Uninitialized SSA names point nowhere.  */
unknown_object_size (osi, var);
-- 
2.31.1



[PATCH v5 0/4] __builtin_dynamic_object_size

2021-12-18 Thread Siddhesh Poyarekar
This patchset enhances the __builtin_dynamic_object_size builtin to
produce dynamic expressions for object sizes to improve coverage of
_FORTIFY_SOURCE.

Testing:


This series has been tested with build and test for i686, bootstrap with
ubsan and full bootstrap and test with x86_64.  I also tested the
toolchain with a glibc build and testsuite run for x86_64 and i686 with
_FORTIFY_SOURCE=3 enabled for gcc12.

Additional testing plans (i.e. I've already started to do some of this):

- Build packages to compare values returned by __builtin_object_size
  with the older pass and this new one.  Also compare with
  __builtin_dynamic_object_size.

- Expand the list of packages to get more coverage metrics.

- Explore performance impact on applications on building with
  _FORTIFY_SOURCE=3.

Siddhesh Poyarekar (4):
  tree-object-size: Support dynamic sizes in conditions
  tree-object-size: Handle function parameters
  tree-object-size: Handle GIMPLE_CALL
  tree-object-size: Dynamic sizes for ADDR_EXPR

 gcc/builtins.c|   6 +-
 .../gcc.dg/builtin-dynamic-object-size-0.c| 495 +
 .../gcc.dg/builtin-dynamic-object-size-10.c   |   2 +
 .../builtin-dynamic-object-size-5-main.c  |  32 +
 .../gcc.dg/builtin-dynamic-object-size-5.c|   7 +-
 gcc/testsuite/gcc.dg/builtin-object-size-1.c  | 154 +++-
 gcc/testsuite/gcc.dg/builtin-object-size-2.c  | 133 
 gcc/testsuite/gcc.dg/builtin-object-size-3.c  | 151 
 gcc/testsuite/gcc.dg/builtin-object-size-4.c  |  93 +++
 gcc/testsuite/gcc.dg/builtin-object-size-5.c  |  22 +-
 gcc/tree-object-size.c| 670 +++---
 11 files changed, 1677 insertions(+), 88 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
 create mode 100644 gcc/testsuite/gcc.dg/builtin-dynamic-object-size-5-main.c

-- 
2.31.1



Re: [patch] Future-proof and homogenise handling of darwin versions

2021-12-18 Thread FX via Gcc-patches
> Yes, but please put this ^^ explanation into the git commit log, and prepend 
> the title line with Darwin:

Thanks, committed.

FX

[PATCH v2] Disable -fsplit-stack support on non-glibc targets

2021-12-18 Thread soeren--- via Gcc-patches
From: Sören Tempel 

The -fsplit-stack option requires the pthread_t TCB definition in the
libc to provide certain struct fields at specific hardcoded offsets. As
far as I know, only glibc provides these fields at the required offsets.
Most notably, musl libc does not have these fields. However, since gcc
accesses the fields using a fixed offset, this does not cause a
compile-time error, but instead results in a silent memory corruption at
run-time with musl libc. For example, on s390x libgcc's
__stack_split_initialize CTOR will overwrite the cancel field in the
pthread_t TCB on musl.

The -fsplit-stack option is used within the gcc code base itself by
gcc-go (if available). On musl-based systems with split-stack support
(i.e. s390x or x86) this causes Go programs compiled with gcc-go to
misbehave at run-time.

This patch fixes gcc-go on musl by disabling -fsplit-stack in gcc itself
since it is not supported on non-glibc targets anyhow. This is achieved
by checking if gcc targets a glibc-based system. This check has been
added for x86 and s390x, the rs6000 config already checks for
TARGET_GLIBC_MAJOR. Other architectures do not have split-stack
support. With this patch applied, the gcc-go configure script will
detect that -fsplit-stack support is not available and will not use it.

See https://www.openwall.com/lists/musl/2012/10/16/12

This patch was written under the assumption that glibc is the only libc
implementation which supports the required fields at the required
offsets in the pthread_t TCB. The patch has been tested on Alpine Linux
Edge on the s390x and x86 architectures by bootstrapping Google's Go
implementation with gcc-go.

Signed-off-by: Sören Tempel 

gcc/ChangeLog:

* common/config/s390/s390-common.c (s390_supports_split_stack):
Only support split-stack on glibc targets.
* config/i386/gnu-user-common.h (STACK_CHECK_STATIC_BUILTIN): Ditto.
* config/i386/gnu.h (defined): Ditto.
---
This version of the patch addresses feedback by Andrew Pinski and uses
OPTION_GLIBC as well as opts->x_linux_libc == LIBC_GLIBC to detect glibc
targets (instead of relying on TARGET_GLIBC_MAJOR).

 gcc/common/config/s390/s390-common.c | 11 +--
 gcc/config/i386/gnu-user-common.h|  5 +++--
 gcc/config/i386/gnu.h|  6 +-
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/gcc/common/config/s390/s390-common.c 
b/gcc/common/config/s390/s390-common.c
index b6bc8501742..fc86e0bc5e7 100644
--- a/gcc/common/config/s390/s390-common.c
+++ b/gcc/common/config/s390/s390-common.c
@@ -116,13 +116,20 @@ s390_handle_option (struct gcc_options *opts 
ATTRIBUTE_UNUSED,
 
 /* -fsplit-stack uses a field in the TCB, available with glibc-2.23.
We don't verify it, since earlier versions just have padding at
-   its place, which works just as well.  */
+   its place, which works just as well. For other libc implementations
+   we disable the feature entirely to avoid corrupting the TCB.  */
 
 static bool
 s390_supports_split_stack (bool report ATTRIBUTE_UNUSED,
   struct gcc_options *opts ATTRIBUTE_UNUSED)
 {
-  return true;
+  if (opts->x_linux_libc == LIBC_GLIBC) {
+return true;
+  } else {
+if (report)
+  error("%<-fsplit-stack%> currently only supported on GNU/Linux");
+return false;
+  }
 }
 
 #undef TARGET_DEFAULT_TARGET_FLAGS
diff --git a/gcc/config/i386/gnu-user-common.h 
b/gcc/config/i386/gnu-user-common.h
index 00226f5a455..6e13315b5a3 100644
--- a/gcc/config/i386/gnu-user-common.h
+++ b/gcc/config/i386/gnu-user-common.h
@@ -66,7 +66,8 @@ along with GCC; see the file COPYING3.  If not see
 #define STACK_CHECK_STATIC_BUILTIN 1
 
 /* We only build the -fsplit-stack support in libgcc if the
-   assembler has full support for the CFI directives.  */
-#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE
+   assembler has full support for the CFI directives and
+   targets glibc.  */
+#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE && OPTION_GLIBC
 #define TARGET_CAN_SPLIT_STACK
 #endif
diff --git a/gcc/config/i386/gnu.h b/gcc/config/i386/gnu.h
index 25fbc07f58c..adfe817201e 100644
--- a/gcc/config/i386/gnu.h
+++ b/gcc/config/i386/gnu.h
@@ -35,7 +35,11 @@ along with GCC.  If not, see .
crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"
 #endif
 
-#ifdef TARGET_LIBC_PROVIDES_SSP
+/* -fsplit-stack uses a field in the TCB at a fixed offset. This
+   field is only available for glibc. Disable -fsplit-stack for
+   other libc implementation to avoid silent TCB corruptions.  */
+
+#if defined (TARGET_LIBC_PROVIDES_SSP) && OPTION_GLIBC
 
 /* i386 glibc provides __stack_chk_guard in %gs:0x14.  */
 #define TARGET_THREAD_SSP_OFFSET0x14


Re: [PATCH] Disable -fsplit-stack support on non-glibc targets

2021-12-18 Thread Andrew Pinski via Gcc-patches
On Sat, Dec 18, 2021 at 3:13 AM Sören Tempel  wrote:
>
> Andrew Pinski  wrote:
> > I think it should check OPTION_MUSL at runtime instead of
> > TARGET_GLIBC_MAJOR at compile time.
> > or rather opts->x_linux_libc == LIBC_MUSL
> > The others should be done similarly too.
>
> Thanks for pointing this out, I wasn't aware of OPTION_MUSL and
> OPTION_GLIBC. However, I am wondering if isn't more useful to whitelist
> this feature on glibc instead of blacklisting it on musl? I was
> operating on the assumption that other libc implementations (uclibc,
> bionic, dietlibc, …) do also not support the required pthread_t fields,
> i.e. that glibc is the only libc where this feature actually works.

yes checking OPTION_GLIBC is better really. Saying glibc only is
better than saying it does not work on musl in this case.
Though I think opts->x_linux_libc == LIBC_GLIBC is the more correct
fix for this function as we are passed down the opts struction and
all.

Thanks,
Andrew Pinski

>
> Greetings,
> Sören


Re: [PATCH] Disable -fsplit-stack support on non-glibc targets

2021-12-18 Thread Sören Tempel via Gcc-patches
Andrew Pinski  wrote:
> I think it should check OPTION_MUSL at runtime instead of
> TARGET_GLIBC_MAJOR at compile time.
> or rather opts->x_linux_libc == LIBC_MUSL
> The others should be done similarly too.

Thanks for pointing this out, I wasn't aware of OPTION_MUSL and
OPTION_GLIBC. However, I am wondering if isn't more useful to whitelist
this feature on glibc instead of blacklisting it on musl? I was
operating on the assumption that other libc implementations (uclibc,
bionic, dietlibc, …) do also not support the required pthread_t fields,
i.e. that glibc is the only libc where this feature actually works.

Greetings,
Sören


Re: [PATCH] Disable -fsplit-stack support on non-glibc targets

2021-12-18 Thread Andrew Pinski via Gcc-patches
On Sat, Dec 18, 2021 at 2:44 AM soeren--- via Gcc-patches
 wrote:
>
> From: Sören Tempel 
>
> The -fsplit-stack option requires the pthread_t TCB definition in the
> libc to provide certain struct fields at specific hardcoded offsets. As
> far as I know, only glibc provides these fields at the required offsets.
> Most notably, musl libc does not have these fields. However, since gcc
> accesses the fields using a fixed offset, this does not cause a
> compile-time error, but instead results in a silent memory corruption at
> run-time with musl libc. For example, on s390x libgcc's
> __stack_split_initialize CTOR will overwrite the cancel field in the
> pthread_t TCB on musl.
>
> The -fsplit-stack option is used within the gcc code base itself by
> gcc-go (if available). On musl-based systems with split-stack support
> (i.e. s390x or x86) this causes Go programs compiled with gcc-go to
> misbehave at run-time.
>
> This patch fixes gcc-go on musl by disabling -fsplit-stack in gcc itself
> since it is not supported on non-glibc targets anyhow. This is achieved
> by checking if TARGET_GLIBC_MAJOR is defined to a non-zero value (it
> defaults to zero on non-glibc systems). The check has been added for x86
> and s390x, the rs6000 config already checks for TARGET_GLIBC_MAJOR.
> Other architectures do not have split-stack support. With this patch
> applied, the gcc-go configure script will detect that -fsplit-stack
> support is not available and will not use it.
>
> See https://www.openwall.com/lists/musl/2012/10/16/12
>
> This patch has been tested on Alpine Linux Edge on the s390x and x86
> architectures by bootstrapping Google's Go implementation with gcc-go.
>
> Signed-off-by: Sören Tempel 
>
> gcc/ChangeLog:
>
> * common/config/s390/s390-common.c (s390_supports_split_stack):
> Only support split-stack on glibc targets.
> * config/i386/gnu-user-common.h (STACK_CHECK_STATIC_BUILTIN): Ditto.
> * config/i386/gnu.h (defined): Ditto.
> ---
>  gcc/common/config/s390/s390-common.c | 9 -
>  gcc/config/i386/gnu-user-common.h| 5 +++--
>  gcc/config/i386/gnu.h| 6 +-
>  3 files changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/gcc/common/config/s390/s390-common.c 
> b/gcc/common/config/s390/s390-common.c
> index b6bc8501742..afbd8d3fe66 100644
> --- a/gcc/common/config/s390/s390-common.c
> +++ b/gcc/common/config/s390/s390-common.c
> @@ -116,13 +116,20 @@ s390_handle_option (struct gcc_options *opts 
> ATTRIBUTE_UNUSED,
>
>  /* -fsplit-stack uses a field in the TCB, available with glibc-2.23.
> We don't verify it, since earlier versions just have padding at
> -   its place, which works just as well.  */
> +   its place, which works just as well. For other libc implementations
> +   we disable the feature entirely to avoid corrupting the TCB.  */
>
>  static bool
>  s390_supports_split_stack (bool report ATTRIBUTE_UNUSED,
>struct gcc_options *opts ATTRIBUTE_UNUSED)
>  {
> +#if TARGET_GLIBC_MAJOR
>return true;
> +#else
> +  if (report)
> +error("%<-fsplit-stack%> currently only supported on GNU/Linux");
> +  return false;
> +#endif
>  }

I think it should check OPTION_MUSL at runtime instead of
TARGET_GLIBC_MAJOR at compile time.
or rather opts->x_linux_libc == LIBC_MUSL
The others should be done similarly too.

Thanks,
Andrew


>
>  #undef TARGET_DEFAULT_TARGET_FLAGS
> diff --git a/gcc/config/i386/gnu-user-common.h 
> b/gcc/config/i386/gnu-user-common.h
> index 00226f5a455..69f2d7415ad 100644
> --- a/gcc/config/i386/gnu-user-common.h
> +++ b/gcc/config/i386/gnu-user-common.h
> @@ -66,7 +66,8 @@ along with GCC; see the file COPYING3.  If not see
>  #define STACK_CHECK_STATIC_BUILTIN 1
>
>  /* We only build the -fsplit-stack support in libgcc if the
> -   assembler has full support for the CFI directives.  */
> -#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE
> +   assembler has full support for the CFI directives and
> +   targets glibc.  */
> +#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE && TARGET_GLIBC_MAJOR
>  #define TARGET_CAN_SPLIT_STACK
>  #endif
> diff --git a/gcc/config/i386/gnu.h b/gcc/config/i386/gnu.h
> index 25fbc07f58c..895a7369816 100644
> --- a/gcc/config/i386/gnu.h
> +++ b/gcc/config/i386/gnu.h
> @@ -35,7 +35,11 @@ along with GCC.  If not, see 
> .
> crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"
>  #endif
>
> -#ifdef TARGET_LIBC_PROVIDES_SSP
> +/* -fsplit-stack uses a field in the TCB at a fixed offset. This
> +   field is only available for glibc. Disable -fsplit-stack for
> +   other libc implementation to avoid silent TCB corruptions.  */
> +
> +#if defined (TARGET_LIBC_PROVIDES_SSP) && TARGET_GLIBC_MAJOR
>
>  /* i386 glibc provides __stack_chk_guard in %gs:0x14.  */
>  #define TARGET_THREAD_SSP_OFFSET0x14


[PATCH] Disable -fsplit-stack support on non-glibc targets

2021-12-18 Thread soeren--- via Gcc-patches
From: Sören Tempel 

The -fsplit-stack option requires the pthread_t TCB definition in the
libc to provide certain struct fields at specific hardcoded offsets. As
far as I know, only glibc provides these fields at the required offsets.
Most notably, musl libc does not have these fields. However, since gcc
accesses the fields using a fixed offset, this does not cause a
compile-time error, but instead results in a silent memory corruption at
run-time with musl libc. For example, on s390x libgcc's
__stack_split_initialize CTOR will overwrite the cancel field in the
pthread_t TCB on musl.

The -fsplit-stack option is used within the gcc code base itself by
gcc-go (if available). On musl-based systems with split-stack support
(i.e. s390x or x86) this causes Go programs compiled with gcc-go to
misbehave at run-time.

This patch fixes gcc-go on musl by disabling -fsplit-stack in gcc itself
since it is not supported on non-glibc targets anyhow. This is achieved
by checking if TARGET_GLIBC_MAJOR is defined to a non-zero value (it
defaults to zero on non-glibc systems). The check has been added for x86
and s390x, the rs6000 config already checks for TARGET_GLIBC_MAJOR.
Other architectures do not have split-stack support. With this patch
applied, the gcc-go configure script will detect that -fsplit-stack
support is not available and will not use it.

See https://www.openwall.com/lists/musl/2012/10/16/12

This patch has been tested on Alpine Linux Edge on the s390x and x86
architectures by bootstrapping Google's Go implementation with gcc-go.

Signed-off-by: Sören Tempel 

gcc/ChangeLog:

* common/config/s390/s390-common.c (s390_supports_split_stack):
Only support split-stack on glibc targets.
* config/i386/gnu-user-common.h (STACK_CHECK_STATIC_BUILTIN): Ditto.
* config/i386/gnu.h (defined): Ditto.
---
 gcc/common/config/s390/s390-common.c | 9 -
 gcc/config/i386/gnu-user-common.h| 5 +++--
 gcc/config/i386/gnu.h| 6 +-
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/gcc/common/config/s390/s390-common.c 
b/gcc/common/config/s390/s390-common.c
index b6bc8501742..afbd8d3fe66 100644
--- a/gcc/common/config/s390/s390-common.c
+++ b/gcc/common/config/s390/s390-common.c
@@ -116,13 +116,20 @@ s390_handle_option (struct gcc_options *opts 
ATTRIBUTE_UNUSED,
 
 /* -fsplit-stack uses a field in the TCB, available with glibc-2.23.
We don't verify it, since earlier versions just have padding at
-   its place, which works just as well.  */
+   its place, which works just as well. For other libc implementations
+   we disable the feature entirely to avoid corrupting the TCB.  */
 
 static bool
 s390_supports_split_stack (bool report ATTRIBUTE_UNUSED,
   struct gcc_options *opts ATTRIBUTE_UNUSED)
 {
+#if TARGET_GLIBC_MAJOR
   return true;
+#else
+  if (report)
+error("%<-fsplit-stack%> currently only supported on GNU/Linux");
+  return false;
+#endif
 }
 
 #undef TARGET_DEFAULT_TARGET_FLAGS
diff --git a/gcc/config/i386/gnu-user-common.h 
b/gcc/config/i386/gnu-user-common.h
index 00226f5a455..69f2d7415ad 100644
--- a/gcc/config/i386/gnu-user-common.h
+++ b/gcc/config/i386/gnu-user-common.h
@@ -66,7 +66,8 @@ along with GCC; see the file COPYING3.  If not see
 #define STACK_CHECK_STATIC_BUILTIN 1
 
 /* We only build the -fsplit-stack support in libgcc if the
-   assembler has full support for the CFI directives.  */
-#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE
+   assembler has full support for the CFI directives and
+   targets glibc.  */
+#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE && TARGET_GLIBC_MAJOR
 #define TARGET_CAN_SPLIT_STACK
 #endif
diff --git a/gcc/config/i386/gnu.h b/gcc/config/i386/gnu.h
index 25fbc07f58c..895a7369816 100644
--- a/gcc/config/i386/gnu.h
+++ b/gcc/config/i386/gnu.h
@@ -35,7 +35,11 @@ along with GCC.  If not, see .
crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"
 #endif
 
-#ifdef TARGET_LIBC_PROVIDES_SSP
+/* -fsplit-stack uses a field in the TCB at a fixed offset. This
+   field is only available for glibc. Disable -fsplit-stack for
+   other libc implementation to avoid silent TCB corruptions.  */
+
+#if defined (TARGET_LIBC_PROVIDES_SSP) && TARGET_GLIBC_MAJOR
 
 /* i386 glibc provides __stack_chk_guard in %gs:0x14.  */
 #define TARGET_THREAD_SSP_OFFSET0x14


Re: [PATCH v3 06/12] LoongArch Port: Builtin macros.

2021-12-18 Thread Xi Ruoyao via Gcc-patches
On Fri, 2021-12-17 at 15:45 +0800, Paul Hua via Gcc-patches wrote:
> Hi Joseph,
> 
> Thanks for your suggestion, Those macros can be removed, we will send
> the v4 version soon.
> 
> Are there any problems in this series of patches?

I'm not a compiler expert, but I'll bootstrap it once my 5th Linux From
Scratch build on LoongArch finishes and give a feedback.

> In other words, What conditions are required for LoongArch back-end
> merged?

GCC 12 development cycle is at stage 3 (general bugfixing) now.  So a
new port have to wait until stage 1 of GCC 13 begins (in mid 2022, I
guess).

In the meantime you need to get someone applied by the SC as the
maintainer of the new port.  Joseph is a SC member but I guess you'd
like to discuss this off-list.

> By the way, We are preparing the LoongArch machine to send to Cfarm
> for testing.
-- 
Xi Ruoyao 
School of Aerospace Science and Technology, Xidian University


Re: [PATCH v3] tree-optimization/103759: Use sizetype everywhere for object sizes

2021-12-18 Thread Jakub Jelinek via Gcc-patches
On Sat, Dec 18, 2021 at 12:24:48PM +0530, Siddhesh Poyarekar wrote:
> Since all computations in tree-object-size are now done in sizetype and
> not HOST_WIDE_INT, comparisons with HOST_WIDE_INT based unknown and
> initval would be incorrect.  Instead, use the sizetype trees directly to
> generate and evaluate initval and unknown size values.
> 
> gcc/ChangeLog:
> 
>   PR tree-optimization/103759
>   * tree-object-size (unknown, initval): Remove functions.
>   (size_unknown, size_initval, size_unknown_p): Operate directly
>   on trees.
> 
> Signed-off-by: Siddhesh Poyarekar 
> ---
> Tested a full bootstrap on x86_64, config=ubsan-bootstrap and i686.

Ok.

Jakub



New Spanish PO file for 'cpplib' (version 11.1-b20210207)

2021-12-18 Thread Translation Project Robot
Hello, gentle maintainer.

This is a message from the Translation Project robot.

A revised PO file for textual domain 'cpplib' has been submitted
by the Spanish team of translators.  The file is available at:

https://translationproject.org/latest/cpplib/es.po

(This file, 'cpplib-11.1-b20210207.es.po', has just now been sent to you in
a separate email.)

All other PO files for your package are available in:

https://translationproject.org/latest/cpplib/

Please consider including all of these in your next release, whether
official or a pretest.

Whenever you have a new distribution with a new version number ready,
containing a newer POT file, please send the URL of that distribution
tarball to the address below.  The tarball may be just a pretest or a
snapshot, it does not even have to compile.  It is just used by the
translators when they need some extra translation context.

The following HTML page has been updated:

https://translationproject.org/domain/cpplib.html

If any question arises, please contact the translation coordinator.

Thank you for all your work,

The Translation Project robot, in the
name of your translation coordinator.




Contents of PO file 'cpplib-11.1-b20210207.es.po'

2021-12-18 Thread Translation Project Robot


cpplib-11.1-b20210207.es.po.gz
Description: Binary data
The Translation Project robot, in the
name of your translation coordinator.