Re: RFA: libiberty: avoid UBSAN complaint in cplus-dem.c

2018-07-27 Thread Ian Lance Taylor via gcc-patches
On Fri, Jul 27, 2018 at 10:12 AM, Tom Tromey  wrote:
> I built gdb with -fsanitize=undefined, and there was a complaint coming
> from cplus-dem.c.  remember_Btype can call memcpy with a NULL pointer,
> which is undefined behavior according to the C standard.
>
> This patch fixes the problem for me.  I tested this by rebuilding gdb
> (with -fsanitize=undefined) and re-running the test suite.
>
> Ok?
>
> Tom
>
> 2018-07-27  Tom Tromey  
>
> * cplus-dem.c (remember_Btype): Don't call memcpy with LEN==0.

This is OK.

Thanks.

Ian


Re: [PATCH] libbacktrace: Move define of HAVE_ZLIB into check for -lz

2018-07-31 Thread Ian Lance Taylor via gcc-patches
On Sun, Jul 29, 2018 at 7:50 AM, Iain Buclaw  wrote:
>
> This is really to suppress the default action-if-found for
> AC_CHECK_LIBS.  Zlib is not a dependency of libbacktrace, and so it
> shouldn't be added to LIBS.  When looking at the check, saw that could
> remove the test for ac_cv_lib_z_compress also.

Thanks, but this doesn't seem like quite the right approach, as seen
by the fact that HAVE_ZLIB_H was dropped from config.h.in.  I think
you need to keep the AC_DEFINE out of the AC_CHECK_LIB.  I would guess
that it would work to just change the default case of AC_CHECK_LIB to
[;] or something similarly innocuous.

Ian


Re: [PATCH] libbacktrace: Move define of HAVE_ZLIB into check for -lz

2018-07-31 Thread Ian Lance Taylor via gcc-patches
On Tue, Jul 31, 2018 at 8:10 AM, Iain Buclaw  wrote:
> On 31 July 2018 at 16:33, Ian Lance Taylor  wrote:
>> On Sun, Jul 29, 2018 at 7:50 AM, Iain Buclaw  wrote:
>>>
>>> This is really to suppress the default action-if-found for
>>> AC_CHECK_LIBS.  Zlib is not a dependency of libbacktrace, and so it
>>> shouldn't be added to LIBS.  When looking at the check, saw that could
>>> remove the test for ac_cv_lib_z_compress also.
>>
>> Thanks, but this doesn't seem like quite the right approach, as seen
>> by the fact that HAVE_ZLIB_H was dropped from config.h.in.  I think
>> you need to keep the AC_DEFINE out of the AC_CHECK_LIB.  I would guess
>> that it would work to just change the default case of AC_CHECK_LIB to
>> [;] or something similarly innocuous.
>>
>> Ian
>
> May I ask you to look at the patch again?  There's two similarly named
> variables here, HAVE_LIBZ and HAVE_ZLIB.
>
> Only the unused HAVE_LIBZ has been dropped from config.h.in.  The one
> that matters has been left alone, or at least I'm pretty sure of.

Ah, got it.  Sorry about that.  The patch is OK with a ChangeLog entry.  Thanks.

Ian


Re: [PATCH 01/11] Add __builtin_speculation_safe_value

2018-07-31 Thread Ian Lance Taylor via gcc-patches
On Tue, Jul 31, 2018 at 12:25 PM, H.J. Lu  wrote:
> On Mon, Jul 30, 2018 at 6:16 AM, Richard Biener  wrote:
>> On Fri, 27 Jul 2018, Richard Earnshaw wrote:
>>
>>>
>>> This patch defines a new intrinsic function
>>> __builtin_speculation_safe_value.  A generic default implementation is
>>> defined which will attempt to use the backend pattern
>>> "speculation_safe_barrier".  If this pattern is not defined, or if it
>>> is not available, then the compiler will emit a warning, but
>>> compilation will continue.
>>>
>>> Note that the test spec-barrier-1.c will currently fail on all
>>> targets.  This is deliberate, the failure will go away when
>>> appropriate action is taken for each target backend.
>>
>> OK.
>>
>> Thanks,
>> Richard.
>>
>>> gcc:
>>>   * builtin-types.def (BT_FN_PTR_PTR_VAR): New function type.
>>>   (BT_FN_I1_I1_VAR, BT_FN_I2_I2_VAR, BT_FN_I4_I4_VAR): Likewise.
>>>   (BT_FN_I8_I8_VAR, BT_FN_I16_I16_VAR): Likewise.
>>>   * builtin-attrs.def (ATTR_NOVOPS_NOTHROW_LEAF_LIST): New attribute
>>>   list.
>>>   * builtins.def (BUILT_IN_SPECULATION_SAFE_VALUE_N): New builtin.
>>>   (BUILT_IN_SPECULATION_SAFE_VALUE_PTR): New internal builtin.
>>>   (BUILT_IN_SPECULATION_SAFE_VALUE_1): Likewise.
>>>   (BUILT_IN_SPECULATION_SAFE_VALUE_2): Likewise.
>>>   (BUILT_IN_SPECULATION_SAFE_VALUE_4): Likewise.
>>>   (BUILT_IN_SPECULATION_SAFE_VALUE_8): Likewise.
>>>   (BUILT_IN_SPECULATION_SAFE_VALUE_16): Likewise.
>>>   * builtins.c (expand_speculation_safe_value): New function.
>>>   (expand_builtin): Call it.
>>>   * doc/cpp.texi: Document predefine __HAVE_SPECULATION_SAFE_VALUE.
>>>   * doc/extend.texi: Document __builtin_speculation_safe_value.
>>>   * doc/md.texi: Document "speculation_barrier" pattern.
>>>   * doc/tm.texi.in: Pull in TARGET_SPECULATION_SAFE_VALUE and
>>>   TARGET_HAVE_SPECULATION_SAFE_VALUE.
>>>   * doc/tm.texi: Regenerated.
>>>   * target.def (have_speculation_safe_value, speculation_safe_value): 
>>> New
>>>   hooks.
>>>   * targhooks.c (default_have_speculation_safe_value): New function.
>>>   (default_speculation_safe_value): New function.
>>>   * targhooks.h (default_have_speculation_safe_value): Add prototype.
>>>   (default_speculation_safe_value): Add prototype.
>>>
>
> I got
>
> ../../src-trunk/gcc/targhooks.c: In function ‘bool
> default_have_speculation_safe_value(bool)’:
> ../../src-trunk/gcc/targhooks.c:2319:43: error: unused parameter
> ‘active’ [-Werror=unused-parameter]
>  default_have_speculation_safe_value (bool active)
>   ~^~


Me too.

Committed this patch as obvious.

Ian


2018-07-31  Ian Lance Taylor  

* targhooks.c (default_have_speculation_safe_value): Add
ATTRIBUTE_UNUSED.
Index: gcc/targhooks.c
===
--- gcc/targhooks.c (revision 263179)
+++ gcc/targhooks.c (working copy)
@@ -2316,7 +2316,7 @@ default_preferred_else_value (unsigned,
 
 /* Default implementation of TARGET_HAVE_SPECULATION_SAFE_VALUE.  */
 bool
-default_have_speculation_safe_value (bool active)
+default_have_speculation_safe_value (bool active ATTRIBUTE_UNUSED)
 {
 #ifdef HAVE_speculation_barrier
   return active ? HAVE_speculation_barrier : true;


Re: [PATCH] libgcc: Use initarray section type for .init_stack

2023-05-31 Thread Ian Lance Taylor via Gcc-patches
On Wed, May 31, 2023 at 12:41 AM Kewen.Lin via Gcc-patches
 wrote:
>
> >> libgcc/ChangeLog:
> >>
> >>  * config/i386/morestack.S: Use @init_array rather than
> >>  @progbits for section type of section .init_array.
> >>  * config/rs6000/morestack.S: Likewise.
> >>  * config/s390/morestack.S: Likewise.
> >
> > s390 parts are ok. I did run a bootstrap and regression. Looks all good. 
> > Thanks!
>
> Thanks for testing this on s390, really appreciate!
>
> Hi Ian & Uros,
>
> Do you have any concerns on this, or does it look good to you?

This is OK.

Thanks.

Ian


libgo patch committet: Don't collect package CGOLDFLAGS

2023-07-20 Thread Ian Lance Taylor via Gcc-patches
This libgo patch to the go command sources stops collecting package
CGOLDFLAGS when using gccgo.  The flags are already collected via
cmd/cgo.

The gccgo_link_c test is tweaked to do real linking as with this
change the cgo ldflags are not fully reflected in go build -n output,
since they now only come from the built archive.

This is a backport of https://go.dev/cl/497117 from the main repo.

This is for https://go.dev/issue/60287.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
d2437e29edbe2673867d0e965d6431aff5cec941
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index c44cdc2baac..83ab3e2d64c 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-92152c88ea8e2dd9e8c67e91bf4ae5e3edf1b506
+d04b024021bb7dbaa434a6d902bd12beb08e315f
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/go/cmd/go/internal/work/gccgo.go 
b/libgo/go/cmd/go/internal/work/gccgo.go
index 1e8250002ee..c1026c71e01 100644
--- a/libgo/go/cmd/go/internal/work/gccgo.go
+++ b/libgo/go/cmd/go/internal/work/gccgo.go
@@ -413,16 +413,9 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, 
out, importcfg string
}
 
for _, a := range allactions {
-   // Gather CgoLDFLAGS, but not from standard packages.
-   // The go tool can dig up runtime/cgo from GOROOT and
-   // think that it should use its CgoLDFLAGS, but gccgo
-   // doesn't use runtime/cgo.
if a.Package == nil {
continue
}
-   if !a.Package.Standard {
-   cgoldflags = append(cgoldflags, a.Package.CgoLDFLAGS...)
-   }
if len(a.Package.CgoFiles) > 0 {
usesCgo = true
}
@@ -452,9 +445,6 @@ func (tools gccgoToolchain) link(b *Builder, root *Action, 
out, importcfg string
 
ldflags = append(ldflags, cgoldflags...)
ldflags = append(ldflags, envList("CGO_LDFLAGS", "")...)
-   if root.Package != nil {
-   ldflags = append(ldflags, root.Package.CgoLDFLAGS...)
-   }
if cfg.Goos != "aix" {
ldflags = str.StringList("-Wl,-(", ldflags, "-Wl,-)")
}
diff --git a/libgo/go/cmd/go/testdata/script/gccgo_link_c.txt 
b/libgo/go/cmd/go/testdata/script/gccgo_link_c.txt
index db2a29128b2..8d67ae2bc7e 100644
--- a/libgo/go/cmd/go/testdata/script/gccgo_link_c.txt
+++ b/libgo/go/cmd/go/testdata/script/gccgo_link_c.txt
@@ -4,8 +4,9 @@
 [!cgo] skip
 [!exec:gccgo] skip
 
-go build -n -compiler gccgo cgoref
+! go build -x -compiler gccgo cgoref
 stderr 'gccgo.*\-L [^ ]*alibpath \-lalib' # make sure that Go-inline "#cgo 
LDFLAGS:" ("-L alibpath -lalib") passed to gccgo linking stage
+! stderr 'gccgo.*-lalib.*-lalib' # make sure -lalib is only passed once
 
 -- cgoref/cgoref.go --
 package main


libbacktrace patch committed

2023-07-31 Thread Ian Lance Taylor via Gcc-patches
This libbacktrace patch, based on one by Andres Freund, uses the
_pgmptr variable declared on Windows to find the executable file name
if none is specified.  Bootstrapped and ran libbacktrace testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian

Patch from Andres Freund:
* configure.ac: Check for _pgmptr declaration.
* fileline.c (fileline_initialize): Check for _pgmfptr before
/proc/self/exec.
* configure, config.h.in: Regenerate.
a349ba16f18b66b70c7a1bdb1ab5c5b6247676da
diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac
index 39e6bf41e35..72ff2b30053 100644
--- a/libbacktrace/configure.ac
+++ b/libbacktrace/configure.ac
@@ -407,6 +407,9 @@ if test "$have_getexecname" = "yes"; then
   AC_DEFINE(HAVE_GETEXECNAME, 1, [Define if getexecname is available.])
 fi
 
+# Check for _pgmptr variable, contains the executable filename on windows
+AC_CHECK_DECLS([_pgmptr])
+
 # Check for sysctl definitions.
 
 AC_CACHE_CHECK([for KERN_PROC],
diff --git a/libbacktrace/fileline.c b/libbacktrace/fileline.c
index 674bf33cdcf..0e560b44e7a 100644
--- a/libbacktrace/fileline.c
+++ b/libbacktrace/fileline.c
@@ -155,6 +155,16 @@ macho_get_executable_path (struct backtrace_state *state,
 
 #endif /* !defined (HAVE_MACH_O_DYLD_H) */
 
+#if HAVE_DECL__PGMPTR
+
+#define windows_executable_filename() _pgmptr
+
+#else /* !HAVE_DECL__PGMPTR */
+
+#define windows_executable_filename() NULL
+
+#endif /* !HAVE_DECL__PGMPTR */
+
 /* Initialize the fileline information from the executable.  Returns 1
on success, 0 on failure.  */
 
@@ -192,7 +202,7 @@ fileline_initialize (struct backtrace_state *state,
 
   descriptor = -1;
   called_error_callback = 0;
-  for (pass = 0; pass < 8; ++pass)
+  for (pass = 0; pass < 9; ++pass)
 {
   int does_not_exist;
 
@@ -205,23 +215,28 @@ fileline_initialize (struct backtrace_state *state,
  filename = getexecname ();
  break;
case 2:
- filename = "/proc/self/exe";
+ /* Test this before /proc/self/exe, as the latter exists but points
+to the wine binary (and thus doesn't work).  */
+ filename = windows_executable_filename ();
  break;
case 3:
- filename = "/proc/curproc/file";
+ filename = "/proc/self/exe";
  break;
case 4:
+ filename = "/proc/curproc/file";
+ break;
+   case 5:
  snprintf (buf, sizeof (buf), "/proc/%ld/object/a.out",
(long) getpid ());
  filename = buf;
  break;
-   case 5:
+   case 6:
  filename = sysctl_exec_name1 (state, error_callback, data);
  break;
-   case 6:
+   case 7:
  filename = sysctl_exec_name2 (state, error_callback, data);
  break;
-   case 7:
+   case 8:
  filename = macho_get_executable_path (state, error_callback, data);
  break;
default:


Re: [PATCH] mksysinfo: add support for musl libc

2022-06-30 Thread Ian Lance Taylor via Gcc-patches
On Thu, Jun 30, 2022 at 9:59 AM Sören Tempel  wrote:
>
> Ian Lance Taylor  wrote:
> > Thanks for the info.  Does this patch work?  It tweaks the handling of
> > SYS_SECCOMP to be specific to that constant.
>
> Yes, your patch works for me too on Alpine Linux Edge.

Thanks.  Committed to mainline.

Ian


Go patch committed: Avoid C++20 keyword requires

2022-07-01 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend renames "requires" to "needs" to avoid
the C++20 keyword.  Bootstrapped on x86_64-pc-linux-gnu.  Committed to
mainline.

Ian
9d44418664ec8c3e59365901e3ec02e488d9e01c
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 0d49e9e70c6..65f64e0fbfb 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-548720bca6bff21ebc9aba22249d9ce45bbd90c7
+ac438edc5335f69c95df9342f43712ad2f61ad66
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc
index e13df0da22b..67b91fab4ca 100644
--- a/gcc/go/gofrontend/gogo.cc
+++ b/gcc/go/gofrontend/gogo.cc
@@ -5302,16 +5302,16 @@ Gogo::write_c_header()
   Named_object* no = types.front();
   types.pop_front();
 
-  std::vector requires;
+  std::vector needs;
   std::vector declare;
-  if (!no->type_value()->struct_type()->can_write_to_c_header(&requires,
+  if (!no->type_value()->struct_type()->can_write_to_c_header(&needs,
  &declare))
continue;
 
   bool ok = true;
   for (std::vector::const_iterator pr
-= requires.begin();
-  pr != requires.end() && ok;
+= needs.begin();
+  pr != needs.end() && ok;
   ++pr)
{
  for (std::list::const_iterator pt = types.begin();
@@ -5342,10 +5342,10 @@ Gogo::write_c_header()
  if (*pd == no)
continue;
 
- std::vector drequires;
+ std::vector dneeds;
  std::vector ddeclare;
  if (!(*pd)->type_value()->struct_type()->
- can_write_to_c_header(&drequires, &ddeclare))
+ can_write_to_c_header(&dneeds, &ddeclare))
continue;
 
  bool done = false;
diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc
index e82be6840aa..4995283bb60 100644
--- a/gcc/go/gofrontend/types.cc
+++ b/gcc/go/gofrontend/types.cc
@@ -6967,7 +6967,7 @@ Struct_type::do_import(Import* imp)
 
 bool
 Struct_type::can_write_to_c_header(
-std::vector* requires,
+std::vector* needs,
 std::vector* declare) const
 {
   const Struct_field_list* fields = this->fields_;
@@ -6978,7 +6978,7 @@ Struct_type::can_write_to_c_header(
p != fields->end();
++p)
 {
-  if (!this->can_write_type_to_c_header(p->type(), requires, declare))
+  if (!this->can_write_type_to_c_header(p->type(), needs, declare))
return false;
   if (Gogo::message_name(p->field_name()) == "_")
sinks++;
@@ -6993,7 +6993,7 @@ Struct_type::can_write_to_c_header(
 bool
 Struct_type::can_write_type_to_c_header(
 const Type* t,
-std::vector* requires,
+std::vector* needs,
 std::vector* declare) const
 {
   t = t->forwarded();
@@ -7027,13 +7027,13 @@ Struct_type::can_write_type_to_c_header(
   return true;
 
 case TYPE_STRUCT:
-  return t->struct_type()->can_write_to_c_header(requires, declare);
+  return t->struct_type()->can_write_to_c_header(needs, declare);
 
 case TYPE_ARRAY:
   if (t->is_slice_type())
return true;
   return this->can_write_type_to_c_header(t->array_type()->element_type(),
- requires, declare);
+ needs, declare);
 
 case TYPE_NAMED:
   {
@@ -7049,10 +7049,10 @@ Struct_type::can_write_type_to_c_header(
// We will accept empty struct fields, but not print them.
if (t->struct_type()->total_field_count() == 0)
  return true;
-   requires->push_back(no);
-   return t->struct_type()->can_write_to_c_header(requires, declare);
+   needs->push_back(no);
+   return t->struct_type()->can_write_to_c_header(needs, declare);
  }
-   return this->can_write_type_to_c_header(t->base(), requires, declare);
+   return this->can_write_type_to_c_header(t->base(), needs, declare);
   }
 
 case TYPE_CALL_MULTIPLE_RESULT:
@@ -7150,9 +7150,9 @@ Struct_type::write_field_to_c_header(std::ostream& os, 
const std::string& name,
 
 case TYPE_POINTER:
   {
-   std::vector requires;
+   std::vector needs;
std::vector declare;
-   if (!this->can_write_type_to_c_header(t->points_to(), &requires,
+   if (!this->can_write_type_to_c_header(t->points_to(), &needs,
  &declare))
  os << "void*";
else


DSE patch RFA: Don't delete trapping insn

2022-07-01 Thread Ian Lance Taylor via Gcc-patches
The DSE pass can delete a dead store even if the instruction can trap.
That is incorrect when using -fnon-call-exceptions
-fno-delete-dead-exceptions.  This led to a bug report against gccgo:
https://go.dev/issue/53012.  However, the bug is not specific to Go.

This patch fixes the problem in a simple way, and includes a C++
testcase.  Bootstrapped and ran C, C++, and Go tests on
x86_64-pc-linux-gnu.

OK for mainline?

Ian
From bae426745756896ec0ea27c9e12469c53b88d538 Mon Sep 17 00:00:00 2001
From: Ian Lance Taylor 
Date: Fri, 1 Jul 2022 14:51:45 -0700
Subject: [PATCH] tree-optimization: only DSE trapping insn if
 -fdelete-dead-exceptions

gcc/ChangeLog:

* tree-ssa-dse.cc (dse_optimize_stmt): Only delete a trapping
statement if -fdelete-dead-exceptions.

gcc/testsuite/ChangeLog:

* g++.dg/torture/except-1.C: New test.
---
 gcc/testsuite/g++.dg/torture/except-1.C | 44 +
 gcc/tree-ssa-dse.cc |  3 +-
 2 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/torture/except-1.C

diff --git a/gcc/testsuite/g++.dg/torture/except-1.C 
b/gcc/testsuite/g++.dg/torture/except-1.C
new file mode 100644
index 000..7050a33cc27
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/except-1.C
@@ -0,0 +1,44 @@
+// { dg-do run { target { i?86-*-linux* i?86-*-gnu* x86_64-*-linux* } } }
+// { dg-additional-options "-fexceptions -fnon-call-exceptions 
-fno-delete-dead-exceptions" }
+
+#include 
+#include 
+#include 
+
+static void
+sighandler (int signo, siginfo_t* si, void* uc)
+{
+  throw (5);
+}
+
+struct S { void *p1, *p2; };
+
+struct S v;
+
+__attribute__ ((noinline))
+int
+dosegv ()
+{
+  struct S *p = 0;
+  struct S s __attribute__((unused)) = *p;
+  return 0;
+}
+
+int main ()
+{
+  struct sigaction sa;
+
+  memset (&sa, 0, sizeof sa);
+  sa.sa_sigaction = sighandler;
+  sigaction (SIGSEGV, &sa, NULL);
+  sigaction (SIGBUS, &sa, NULL);
+
+  try {
+dosegv ();
+  }
+  catch (int x) {
+return (x != 5);
+  }
+
+  return 1;
+}
diff --git a/gcc/tree-ssa-dse.cc b/gcc/tree-ssa-dse.cc
index 62efafe384d..8d1739a4510 100644
--- a/gcc/tree-ssa-dse.cc
+++ b/gcc/tree-ssa-dse.cc
@@ -1463,7 +1463,8 @@ dse_optimize_stmt (function *fun, gimple_stmt_iterator 
*gsi, sbitmap live_bytes)
   gimple_call_set_lhs (stmt, NULL_TREE);
   update_stmt (stmt);
 }
-  else
+  else if (!stmt_could_throw_p (fun, stmt)
+  || fun->can_delete_dead_exceptions)
 delete_dead_or_redundant_assignment (gsi, "dead", need_eh_cleanup,
 need_ab_cleanup);
 }
-- 
2.37.0.rc0.161.g10f37bed90-goog



Go patch committe: Use correct init order for multi-value init

2022-07-01 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend uses the correct initialization order
for code like

var a = c
var b, c = x.(bool)

The global c is initialized by the preinit of b, but we were missing a
dependency of c on b, so a would be initialized to the zero value of c
rather than the correct value.

Simply adding the dependency of c on b didn't work because the preinit
of b refers to c, so that appeared circular.  So this patch changes
the init order to skip dependencies that only appear on the left hand
side of assignments in preinit blocks.

Doing that didn't work because the write barrier pass can transform "a
= b" into code like "gcWriteBarrier(&a, b)" that is not obviously a
simple assigment.  So this patch moves the collection of dependencies
to just after lowering, before the write barriers are inserted.

Making those changes permit relaxing the requirement that we don't
warn about self-dependency in preinit blocks, so now we correctly warn
for

var a, b any = b.(bool)

The test case is https://go.dev/cl/415238.

This fixes https://go.dev/issue/53619.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
23361df71a68478dde7c4aa516ba69f199556a2c
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 65f64e0fbfb..7b1d3011fff 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-ac438edc5335f69c95df9342f43712ad2f61ad66
+6479d5976c5d848ec6f5843041275723a6b0
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/go.cc b/gcc/go/gofrontend/go.cc
index 404cb124549..1512770af29 100644
--- a/gcc/go/gofrontend/go.cc
+++ b/gcc/go/gofrontend/go.cc
@@ -146,6 +146,9 @@ go_parse_input_files(const char** filenames, unsigned int 
filename_count,
   if (only_check_syntax)
 return;
 
+  // Record global variable initializer dependencies.
+  ::gogo->record_global_init_refs();
+
   // Do simple deadcode elimination.
   ::gogo->remove_deadcode();
 
diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc
index 67b91fab4ca..9197eef3e38 100644
--- a/gcc/go/gofrontend/gogo.cc
+++ b/gcc/go/gofrontend/gogo.cc
@@ -1086,8 +1086,8 @@ class Find_vars : public Traverse
 
  public:
   Find_vars()
-: Traverse(traverse_expressions),
-  vars_(), seen_objects_()
+: Traverse(traverse_expressions | traverse_statements),
+  vars_(), seen_objects_(), lhs_is_ref_(false)
   { }
 
   // An iterator through the variables found, after the traversal.
@@ -1104,11 +1104,16 @@ class Find_vars : public Traverse
   int
   expression(Expression**);
 
+  int
+  statement(Block*, size_t* index, Statement*);
+
  private:
   // Accumulated variables.
   Vars vars_;
   // Objects we have already seen.
   Seen_objects seen_objects_;
+  // Whether an assignment to a variable counts as a reference.
+  bool lhs_is_ref_;
 };
 
 // Collect global variables referenced by EXPR.  Look through function
@@ -1164,7 +1169,11 @@ Find_vars::expression(Expression** pexpr)
  if (ins.second)
{
  // This is the first time we have seen this name.
- if (f->func_value()->block()->traverse(this) == TRAVERSE_EXIT)
+ bool hold = this->lhs_is_ref_;
+ this->lhs_is_ref_ = true;
+ int r = f->func_value()->block()->traverse(this);
+ this->lhs_is_ref_ = hold;
+ if (r == TRAVERSE_EXIT)
return TRAVERSE_EXIT;
}
}
@@ -1192,6 +1201,29 @@ Find_vars::expression(Expression** pexpr)
   return TRAVERSE_CONTINUE;
 }
 
+// Check a statement while searching for variables.  This is where we
+// skip variables on the left hand side of assigments if appropriate.
+
+int
+Find_vars::statement(Block*, size_t*, Statement* s)
+{
+  if (this->lhs_is_ref_)
+return TRAVERSE_CONTINUE;
+  Assignment_statement* as = s->assignment_statement();
+  if (as == NULL)
+return TRAVERSE_CONTINUE;
+
+  // Only traverse subexpressions of the LHS.
+  if (as->lhs()->traverse_subexpressions(this) == TRAVERSE_EXIT)
+return TRAVERSE_EXIT;
+
+  Expression* rhs = as->rhs();
+  if (Expression::traverse(&rhs, this) == TRAVERSE_EXIT)
+return TRAVERSE_EXIT;
+
+  return TRAVERSE_SKIP_COMPONENTS;
+}
+
 // Return true if EXPR, PREINIT, or DEP refers to VAR.
 
 static bool
@@ -1230,11 +1262,11 @@ class Var_init
 {
  public:
   Var_init()
-: var_(NULL), init_(NULL), refs_(NULL), dep_count_(0)
+: var_(NULL), init_(NULL), dep_count_(0)
   { }
 
   Var_init(Named_object* var, Bstatement* init)
-: var_(var), init_(init), refs_(NULL), dep_count_(0)
+: var_(var), init_(init), dep_count_(0)
   { }
 
   // Return the variable.
@@ -1247,19 +1279,6 @@ class Var_init
   init() const
   { return this->init_; }
 
-  // Add a reference.
-  void
-  add_ref(Named_object* var);
-
-  // The variables which this variable's initializers refer to.
-  const std::vector*
-  refs()
-  { return this->refs_; 

Go patch committed: Better error message for unknown package name

2022-07-05 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend gives a  better error message for an
unknown package name, saying "undefined reference" rather than
"expected package".  This requires updating a test.  This fixes
https://go.dev/issue/51237.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
db1256cfb4620c4d52175002940347d399148502
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 7b1d3011fff..461e2fdf271 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-6479d5976c5d848ec6f5843041275723a6b0
+a209dca9ec918535977dcab99fd9bb60986ffacd
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/parse.cc b/gcc/go/gofrontend/parse.cc
index a3c6f630a09..c93d82bba39 100644
--- a/gcc/go/gofrontend/parse.cc
+++ b/gcc/go/gofrontend/parse.cc
@@ -191,7 +191,11 @@ Parse::qualified_ident(std::string* pname, Named_object** 
ppackage)
   Named_object* package = this->gogo_->lookup(name, NULL);
   if (package == NULL || !package->is_package())
 {
-  go_error_at(this->location(), "expected package");
+  if (package == NULL)
+   go_error_at(this->location(), "reference to undefined name %qs",
+   Gogo::message_name(name).c_str());
+  else
+   go_error_at(this->location(), "expected package");
   // We expect . IDENTIFIER; skip both.
   if (this->advance_token()->is_identifier())
this->advance_token();
diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue27938.go 
b/gcc/testsuite/go.test/test/fixedbugs/issue27938.go
index ed974e642df..aecc67678ac 100644
--- a/gcc/testsuite/go.test/test/fixedbugs/issue27938.go
+++ b/gcc/testsuite/go.test/test/fixedbugs/issue27938.go
@@ -11,13 +11,13 @@
 package p
 
 type _ struct {
-   F sync.Mutex // ERROR "undefined: sync|expected package"
+   F sync.Mutex // ERROR "undefined: sync|expected package|reference to 
undefined name"
 }
 
 type _ struct {
-   sync.Mutex // ERROR "undefined: sync|expected package"
+   sync.Mutex // ERROR "undefined: sync|expected package|reference to 
undefined name"
 }
 
 type _ interface {
-   sync.Mutex // ERROR "undefined: sync|expected package|expected 
signature or type name"
+   sync.Mutex // ERROR "undefined: sync|expected package|expected 
signature or type name|reference to undefined name"
 }


Go patch committed: Propagate array length error marker

2022-07-05 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend propagates the array length error marker
farther, to avoid a compiler crash on invalid code.  This fixes
https://go.dev/issue/53639.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
c70a48a8f8f6a43b35f783b5672c9a3c0a363c31
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 461e2fdf271..7c5c45672d7 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-a209dca9ec918535977dcab99fd9bb60986ffacd
+d295a0a2c96c0f7c3abd94fea3aa4e2303bf2af2
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 00d35a965a9..2492d9fe735 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -8486,6 +8486,11 @@ Builtin_call_expression::do_flatten(Gogo* gogo, 
Named_object* function,
 pa != this->args()->end();
 ++pa)
  {
+   if ((*pa)->is_error_expression())
+ {
+   go_assert(saw_errors());
+   return Expression::make_error(loc);
+ }
if ((*pa)->is_nil_expression())
  {
Expression* nil = Expression::make_nil(loc);
@@ -13391,6 +13396,7 @@ Array_index_expression::do_check_types(Gogo*)
   if (array_type == NULL)
 {
   go_assert(this->array_->type()->is_error());
+  this->set_is_error();
   return;
 }
 
diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc
index 4995283bb60..9f34801f695 100644
--- a/gcc/go/gofrontend/types.cc
+++ b/gcc/go/gofrontend/types.cc
@@ -7429,7 +7429,10 @@ bool
 Array_type::do_verify()
 {
   if (this->element_type()->is_error_type())
-return false;
+{
+  this->set_is_error();
+  return false;
+}
   if (!this->verify_length())
 {
   this->length_ = Expression::make_error(this->length_->location());


libbacktrace patch committed: Don't let "make clean" remove allocfail.sh

2022-07-07 Thread Ian Lance Taylor via Gcc-patches
The script allocfail.sh was being incorrectly removed by "make clean".
This patch fixes the problem.  This fixes
https://github.com/ianlancetaylor/libbacktrace/issues/81.  Ran
libbacktrace "make check" and "make clean" on x86_64-pc-linux-gnu.
Committed to mainline.

Ian

For https://github.com/ianlancetaylor/libbacktrace/issues/81
* Makefile.am (MAKETESTS): New variable split out of TESTS.
(CLEANFILES): Replace TESTS with BUILDTESTS and MAKETESTS.
* Makefile.in: Regenerate.
9ed57796235abcd24e06b1ce10fe72c3d0d07cc5
diff --git a/libbacktrace/Makefile.am b/libbacktrace/Makefile.am
index bf507b73918..9f8516d00e2 100644
--- a/libbacktrace/Makefile.am
+++ b/libbacktrace/Makefile.am
@@ -85,13 +85,19 @@ libbacktrace_la_DEPENDENCIES = $(libbacktrace_la_LIBADD)
 
 # Testsuite.
 
-# Add a test to this variable if you want it to be built.
+# Add a test to this variable if you want it to be built as a program,
+# with SOURCES, etc.
 check_PROGRAMS =
 
 # Add a test to this variable if you want it to be run.
 TESTS =
 
-# Add a test to this variable if you want it to be built and run.
+# Add a test to this variable if you want it to be built as a Makefile
+# target and run.
+MAKETESTS =
+
+# Add a test to this variable if you want it to be built as a program,
+# with SOURCES, etc., and run.
 BUILDTESTS =
 
 # Add a file to this variable if you want it to be built for testing.
@@ -250,7 +256,7 @@ b2test_LDFLAGS = -Wl,--build-id
 b2test_LDADD = libbacktrace_elf_for_test.la
 
 check_PROGRAMS += b2test
-TESTS += b2test_buildid
+MAKETESTS += b2test_buildid
 
 if HAVE_DWZ
 
@@ -260,7 +266,7 @@ b3test_LDFLAGS = -Wl,--build-id
 b3test_LDADD = libbacktrace_elf_for_test.la
 
 check_PROGRAMS += b3test
-TESTS += b3test_dwz_buildid
+MAKETESTS += b3test_dwz_buildid
 
 endif HAVE_DWZ
 
@@ -311,11 +317,11 @@ if HAVE_DWZ
  cp $< $@; \
fi
 
-TESTS += btest_dwz
+MAKETESTS += btest_dwz
 
 if HAVE_OBJCOPY_DEBUGLINK
 
-TESTS += btest_dwz_gnudebuglink
+MAKETESTS += btest_dwz_gnudebuglink
 
 endif HAVE_OBJCOPY_DEBUGLINK
 
@@ -416,7 +422,7 @@ endif HAVE_PTHREAD
 
 if HAVE_OBJCOPY_DEBUGLINK
 
-TESTS += btest_gnudebuglink
+MAKETESTS += btest_gnudebuglink
 
 %_gnudebuglink: %
$(OBJCOPY) --only-keep-debug $< $@.debug
@@ -494,7 +500,7 @@ endif USE_DSYMUTIL
 
 if HAVE_MINIDEBUG
 
-TESTS += mtest_minidebug
+MAKETESTS += mtest_minidebug
 
 %_minidebug: %
$(NM) -D $< -P --defined-only | $(AWK) '{ print $$1 }' | sort > $<.dsyms
@@ -536,10 +542,11 @@ endif HAVE_ELF
 
 check_PROGRAMS += $(BUILDTESTS)
 
-TESTS += $(BUILDTESTS)
+TESTS += $(MAKETESTS) $(BUILDTESTS)
 
 CLEANFILES = \
-   $(TESTS) *.debug elf_for_test.c edtest2_build.c gen_edtest2_build \
+   $(MAKETESTS) $(BUILDTESTS) *.debug elf_for_test.c edtest2_build.c \
+   gen_edtest2_build \
*.dsyms *.fsyms *.keepsyms *.dbg *.mdbg *.mdbg.xz *.strip
 
 clean-local:


libbacktrace patch committed: Don't exit Mach-O dyld loop on failure

2022-07-07 Thread Ian Lance Taylor via Gcc-patches
This libbacktrace patch changes the loop over dynamic libraries on
Mach-O to keep going if we fail to find the debug info for a
particular library.  We can still pick up debug info for other
libraries even if one fails.  Tested on x86_64-pc-linux-gnu which
admittedly does little, but others have tested it on Mach-o.
Committed to mainline.

Ian

* macho.c (backtrace_initialize) [HAVE_MACH_O_DYLD_H]: Don't exit
loop if we can't find debug info for one shared library.
d8ddf1fa098fa50929ea0a1569a8e38d80fadbaf
diff --git a/libbacktrace/macho.c b/libbacktrace/macho.c
index 3f40811719e..16f406507d2 100644
--- a/libbacktrace/macho.c
+++ b/libbacktrace/macho.c
@@ -1268,7 +1268,7 @@ backtrace_initialize (struct backtrace_state *state, 
const char *filename,
   mff = macho_nodebug;
   if (!macho_add (state, name, d, 0, NULL, base_address, 0,
  error_callback, data, &mff, &mfs))
-   return 0;
+   continue;
 
   if (mff != macho_nodebug)
macho_fileline_fn = mff;


libbacktrace patch committed: Check for sys/link.h

2022-07-08 Thread Ian Lance Taylor via Gcc-patches
Apparently QNX declares dl_iterate_phdr and friends in sys/link.h
rather than link.h.  This patch updates libbacktrace to check there.
This fixes https://github.com/ianlancetaylor/libbacktrace/issues/86.
Bootstrapped and ran libbacktrace testsuite on x86_64-pc-linux-gnu.
Committed to mainline.

Ian

* configure.ac: Check for sys/link.h.  Use either link.h or
sys/link.h when checking for dl_iterate_phdr.
* elf.c: Include sys/link.h if available.
* configure, config.h.in: Regenerate.
bab8b6e52fb0b48b5d9d1af5f93e5c8fb20d6240
diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac
index 857987a2859..1daaa2f62d2 100644
--- a/libbacktrace/configure.ac
+++ b/libbacktrace/configure.ac
@@ -335,13 +335,17 @@ fi
 AC_SUBST(BACKTRACE_USES_MALLOC)
 
 # Check for dl_iterate_phdr.
-AC_CHECK_HEADERS(link.h)
-if test "$ac_cv_header_link_h" = "no"; then
+AC_CHECK_HEADERS(link.h sys/link.h)
+if test "$ac_cv_header_link_h" = "no" -a "$ac_cv_header_sys_link_h" = "no"; 
then
   have_dl_iterate_phdr=no
 else
   if test -n "${with_target_subdir}"; then
+link_h=link.h
+if test "$ac_cv_header_link_h" = "no"; then
+   link_h=sys/link.h
+fi
 # When built as a GCC target library, we can't do a link test.
-AC_EGREP_HEADER([dl_iterate_phdr], [link.h], [have_dl_iterate_phdr=yes],
+AC_EGREP_HEADER([dl_iterate_phdr], [$link_h], [have_dl_iterate_phdr=yes],
[have_dl_iterate_phdr=no])
   else
 AC_CHECK_FUNC([dl_iterate_phdr], [have_dl_iterate_phdr=yes],
diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index 8b82dd45875..181d195fe35 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -40,7 +40,12 @@ POSSIBILITY OF SUCH DAMAGE.  */
 #include 
 
 #ifdef HAVE_DL_ITERATE_PHDR
-#include 
+ #ifdef HAVE_LINK_H
+  #include 
+ #endif
+ #ifdef HAVE_SYS_LINK_H
+  #include 
+ #endif
 #endif
 
 #include "backtrace.h"


libgo patch committed: Don't include in sysinfo.c

2022-07-13 Thread Ian Lance Taylor via Gcc-patches
This libgo patch stops including  when building
gen-sysinfo.go.  Removing this doesn't change anything at least with
glibc 2.33.  The include was added in https://go.dev/cl/6100049 but
it's not clear why.  This should fix GCC PR 106266.  Bootstrapped and
ran Go testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
9b487dbc298242fdde127e7827e728545c308aac
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 7c5c45672d7..5ea0406cd8e 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-d295a0a2c96c0f7c3abd94fea3aa4e2303bf2af2
+ff68b1a147eb60082fd60c198db0ef5477ade938
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/sysinfo.c b/libgo/sysinfo.c
index a4259c02ded..fc0210992fa 100644
--- a/libgo/sysinfo.c
+++ b/libgo/sysinfo.c
@@ -158,9 +158,6 @@
 #if defined(HAVE_LINUX_ETHER_H)
 #include 
 #endif
-#if defined(HAVE_LINUX_FS_H)
-#include 
-#endif
 #if defined(HAVE_LINUX_REBOOT_H)
 #include 
 #endif


Go patch committed: Don't crash on f(g()) if g returns a zero-sized value

2022-07-15 Thread Ian Lance Taylor via Gcc-patches
This patch to the GCC interface of the Go frontend fixes a crash in
f(g()) if g returns a zero-sized value.  In that case the GCC
interface modifies g to return void, since GCC's middle-end does not
have solid support for zero-sized values.  This patch detects the
f(g()) case and replaces the call to g() with (g(), zero).  The test
case for this is https://go.dev/cl/417481.  This fixes
https://go.dev/issue/23868.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian

* go-gcc.cc (Gcc_backend::call_expression): Handle a void
argument, as for f(g()) where g returns a zero-sized type.
1eb1495f7d0fa9b49f6f3c34bbbf4dd1e850607c
diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc
index f3de7a8c183..7b4b2adb058 100644
--- a/gcc/go/go-gcc.cc
+++ b/gcc/go/go-gcc.cc
@@ -2112,6 +2112,19 @@ Gcc_backend::call_expression(Bfunction*, // containing 
fcn for call
   args[i] = fn_args.at(i)->get_tree();
   if (args[i] == error_mark_node)
 return this->error_expression();
+  if (TREE_TYPE(args[i]) == void_type_node)
+   {
+ // This can happen for a case like f(g()) where g returns a
+ // zero-sized type, because in that case we've changed g to
+ // return void.
+ tree t = TYPE_ARG_TYPES(TREE_TYPE(TREE_TYPE(fn)));
+ for (size_t j = 0; j < i; ++j)
+   t = TREE_CHAIN(t);
+ tree arg_type = TREE_TYPE(TREE_VALUE(t));
+ args[i] = fold_build2_loc(EXPR_LOCATION(args[i]), COMPOUND_EXPR,
+   arg_type, args[i],
+   build_zero_cst(arg_type));
+   }
 }
 
   tree fndecl = fn;


Go patch committed: Handle f().x if f returns a zero-sized type

2022-07-16 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend handles the case of f().x when the
function f returns a zero-sized type.  In that case the GCC interface
will have changed f to return void, as the GCC middle-end does not
have complete support for zero-sized types.  This patch handles the
case of void when in a struct field expression.  The test case for
this is https://go.dev/cl/417874.  This fixes
https://go.dev/issue/23870.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian

* go-gcc.cc (Gcc_backend::struct_field_expression): Handle a void
expression, as for f().x where f returns a zero-sized type.
2b7b330427a60c8a5ef00d940adde0160ce04f27
diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc
index 7b4b2adb058..1ba7206caeb 100644
--- a/gcc/go/go-gcc.cc
+++ b/gcc/go/go-gcc.cc
@@ -1707,6 +1707,13 @@ Gcc_backend::struct_field_expression(Bexpression* 
bstruct, size_t index,
   if (struct_tree == error_mark_node
   || TREE_TYPE(struct_tree) == error_mark_node)
 return this->error_expression();
+
+  // A function call that returns a zero-sized object will have been
+  // changed to return void.  A zero-sized object can have a
+  // (zero-sized) field, so support that case.
+  if (TREE_TYPE(struct_tree) == void_type_node)
+return bstruct;
+
   gcc_assert(TREE_CODE(TREE_TYPE(struct_tree)) == RECORD_TYPE);
   tree field = TYPE_FIELDS(TREE_TYPE(struct_tree));
   if (field == NULL_TREE)


Re: libgo patch committed: Don't include in sysinfo.c

2022-07-21 Thread Ian Lance Taylor via Gcc-patches
On Thu, Jul 21, 2022 at 4:53 AM Martin Liška  wrote:
>
> On 7/21/22 12:19, Richard Biener via Gcc-patches wrote:
> > On Wed, Jul 13, 2022 at 6:03 PM Ian Lance Taylor via Gcc-patches
> >  wrote:
> >>
> >> This libgo patch stops including  when building
> >> gen-sysinfo.go.  Removing this doesn't change anything at least with
> >> glibc 2.33.  The include was added in https://go.dev/cl/6100049 but
> >> it's not clear why.  This should fix GCC PR 106266.  Bootstrapped and
> >> ran Go testsuite on x86_64-pc-linux-gnu.  Committed to mainline.
> >
> > Btw, active branches are affected the same way - can you please backport?
>
> I've just done that.

Thanks.

Ian


Re: [PATCH] libgo: make match.sh POSIX-shell compatible

2022-07-22 Thread Ian Lance Taylor via Gcc-patches
On Tue, Jul 19, 2022 at 11:35 PM  wrote:
>
> From: Sören Tempel 
>
> The `(( expression ))` syntax is a Bash extension and not supported by
> POSIX shell [1]. However, the arithmetic expressions used by the
> gobuild() function can also be expressed using arithmetic POSIX
> expansions with `$(( expression ))` [2].
>
> Contrary to the Bash extension, arithmetic expansion doesn't set
> the return value if the expression is non-zero but instead just prints
> the expression result. Hence, the expression also needs to be negated.
> Without this patch, match.sh does currently not work correctly if
> /bin/sh is not a symlink to Bash.
>
> [1]: https://www.gnu.org/software/bash/manual/bash.html#Conditional-Constructs
> [2]: 
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_04

Thanks.  Committed as follows, which also fixes the similar function
in the gotest script.

Ian
dbf607d2e92cbae9a7f7620b69b9272adbce6381
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 5ea0406cd8e..2f2fafde1f1 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-ff68b1a147eb60082fd60c198db0ef5477ade938
+a62f20ae78ddd41be682dde8cab075ca4f5dbb2a
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/match.sh b/libgo/match.sh
index 7ed587ff794..e5ed98de422 100755
--- a/libgo/match.sh
+++ b/libgo/match.sh
@@ -111,7 +111,7 @@ gobuild() {
 if test "$goarch" != "386"; then
line=$(echo "$line" | sed -e "s/\\(${wrap}\\)386\\(${wrap}\\)/\10\2/g")
 fi
-(($line))
+return $((!($line)))
 }
 
 matched=
diff --git a/libgo/testsuite/gotest b/libgo/testsuite/gotest
index 04e4267fbba..0a0a7e14d74 100755
--- a/libgo/testsuite/gotest
+++ b/libgo/testsuite/gotest
@@ -302,7 +302,7 @@ gobuild() {
 if test "$goarch" != "386"; then
line=$(echo "$line" | sed -e "s/\\(${wrap}\\)386\\(${wrap}\\)/\10\2/g")
 fi
-(($line))
+return $((!($line)))
 }
 
 case "x$gofiles" in


Merge from trunk to gccgo branch

2022-07-27 Thread Ian Lance Taylor via Gcc-patches
I merged trunk revision 5eb9f117a361538834b9740d59219911680717d1 to
the gccgo branch.

Ian


Re: [PATCH] libgo: Explicitly define SYS_timer_settime for 32-bit musl targets

2022-07-30 Thread Ian Lance Taylor via Gcc-patches
On Thu, Jul 28, 2022 at 11:15 AM  wrote:
>
> From: Sören Tempel 
>
> On 32-bit systems, musl only defines SYS_timer_settime32 not
> SYS_timer_settime. This causes the following compilation error:
>
> os_linux.go:251:30: error: reference to undefined name 
> '_SYS_timer_settime'
>   251 | return int32(syscall(_SYS_timer_settime, 
> uintptr(timerid), uintptr(flags), uintptr(unsafe.Pointer(new)), 
> uintptr(unsafe.Pointer(old)), 0, 0))
>   |  ^
>
> This commit fixes this error by "aliasing" SYS_timer_settime to
> SYS_timer_settime32 if the latter is defined. This is also what
> musl does internally [1].

Committed a slight variant of this, as appended.

Ian
f40686b01bdabba051e3b22165bb576e45ffca74
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 2f2fafde1f1..ca797045d66 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-a62f20ae78ddd41be682dde8cab075ca4f5dbb2a
+d53e8a0e94e34dc609e34dd5e404debda2640cfb
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/sysinfo.c b/libgo/sysinfo.c
index fc0210992fa..180f5c31d74 100644
--- a/libgo/sysinfo.c
+++ b/libgo/sysinfo.c
@@ -354,6 +354,11 @@ enum {
 };
 #endif
 
+#if !defined(SYS_timer_settime) && defined(SYS_timer_settime32)
+// musl defines SYS_timer_settim32 on 32-bit systems.
+#define SYS_timer_settime SYS_timer_settime32
+#endif
+
 #if defined(HAVE_LOFF_T)
 // loff_t can be defined as a macro; for -fgo-dump-spec make sure we
 // see a typedef.


Re: [PATCH] PR bootstrap/106472: Add libgo depends on libbacktrace to Makefile.def

2022-07-30 Thread Ian Lance Taylor via Gcc-patches
On Sat, Jul 30, 2022 at 2:38 PM Roger Sayle  wrote:
>
>
> This patch fixes PR bootstrap/106472 by adding a missing dependency
> to Makefile.def to allow make bootstrap when configured using
> "--enable-languages=go" (and not using make with multiple threads).
>
> Tested on x86-64-pc-linux-gnu.  Ok for mainline?
>
>
> 2022-07-30  Roger Sayle  
>
> ChangeLog
> PR bootstrap/106472
> * Makefile.def (dependencies): Make configure-target-libgo depend
> upon all-target-libbacktrace.

This is OK.  Thanks.

Ian


Re: [PATCH] [libbacktrace] fix up broken test

2023-08-03 Thread Ian Lance Taylor via Gcc-patches
On Thu, Aug 3, 2023 at 6:27 AM Richard Biener via Gcc-patches
 wrote:
>
> zstdtest has some inline data where some testcases lack the
> uncompressed length field.  Thus it computes that but still
> ends up allocating memory for the uncompressed buffer based on
> that (zero) length.  Oops.  Causes memory corruption if the
> allocator returns non-NULL.
>
> Tested on x86_64-unknown-linux-gnu, pushed as obvious.
>
> libbacktrace/
> * zstdtest.c (test_samples): Properly compute the allocation
> size for the uncompressed data.

Thanks.

Ian


Re: [RFC] GCC Security policy

2023-08-08 Thread Ian Lance Taylor via Gcc-patches
On Tue, Aug 8, 2023 at 6:02 AM Jakub Jelinek via Gcc-patches
 wrote:
>
> On Tue, Aug 08, 2023 at 02:52:57PM +0200, Richard Biener via Gcc-patches 
> wrote:
> > There's probably external tools to do this, not sure if we should replicate
> > things in the driver for this.
> >
> > But sure, I think the driver is the proper point to address any of such
> > issues - iff we want to address them at all.  Maybe a nice little
> > google summer-of-code project ;)
>
> What I'd really like to avoid is having all compiler bugs (primarily ICEs)
> considered to be security bugs (e.g. DoS category), it would be terrible to
> release every week a new compiler because of the "security" issues.
> Running compiler on untrusted sources can trigger ICEs (which we want to fix
> but there will always be some), or run into some compile time and/or compile
> memory issue (we have various quadratic or worse spots), compiler stack
> limits (deeply nested stuff e.g. during parsing but other areas as well).
> So, people running fuzzers and reporting issues is great, but if they'd get
> a CVE assigned for each ice-on-invalid-code, ice-on-valid-code,
> each compile-time-hog and each memory-hog, that wouldn't be useful.
> Runtime libraries or security issues in the code we generate for valid
> sources are of course a different thing.


I wonder if a security policy should say something about the -fplugin
option.  I agree that an ICE is not a security issue, but I wonder how
many people are aware that a poorly chosen command line option can
direct the compiler to run arbitrary code.  For that matter the same
is true of setting the GCC_EXEC_PREFIX environment variable, and no
doubt several other environment variables.  My point is not that we
should change these, but that a security policy should draw attention
to the fact that there are cases in which the compiler will
unexpectedly run other programs.

Ian


Re: [RFC] GCC Security policy

2023-08-08 Thread Ian Lance Taylor via Gcc-patches
On Tue, Aug 8, 2023 at 7:37 AM Jakub Jelinek  wrote:
>
> BTW, I think we should perhaps differentiate between production ready
> libraries (e.g. libgcc, libstdc++, libgomp, libatomic, libgfortran, 
> libquadmath,
> libssp) vs. e.g. the sanitizer libraries which are meant for debugging and
> I believe it is highly risky to run them in programs with extra priviledges
> - e.g. I think they use getenv rather than *secure_getenv to get at various
> tweaks for their behavior including where logging will happen and upstream
> doesn't really care.
> And not really sure what to say about lesser used language support
> libraries, libada, libphobos, libgo, libgm2, ... nor what to say about
> libvtv etc.

libgo is a complicated case because it has a lot of components
including a web server with TLS support, so there are a lot of
potential security issues for programs that use libgo.  The upstream
security policy is https://go.dev/security/policy.  I'm not sure what
to say about libgo in GCC, since realistically the support for
security problems is best-effort.  I guess we should at least accept
security reports, even if we can't promise to fix them quickly.

Ian


Re: [PATCH 1/2] go: update usage of TARGET_AIX to TARGET_AIX_OS

2023-06-16 Thread Ian Lance Taylor via Gcc-patches
On Fri, Jun 16, 2023 at 9:00 AM Paul E. Murphy via Gcc-patches
 wrote:
>
> TARGET_AIX is defined to a non-zero value on linux and maybe other
> powerpc64le targets.  This leads to unexpected behavior such as
> dropping the .go_export section when linking a shared library
> on linux/powerpc64le.
>
> Instead, use TARGET_AIX_OS to toggle AIX specific behavior.
>
> Fixes golang/go#60798.
>
> gcc/go/ChangeLog:
>
> * go-backend.cc [TARGET_AIX]: Rename and update usage to
> TARGET_AIX_OS.
> * go-lang.cc: Likewise.

This is OK.

Thanks.

Ian


libgo patch committed: Add benchmarks and examples to test list

2023-06-16 Thread Ian Lance Taylor via Gcc-patches
In https://go.dev/cl/384695
(https://gcc.gnu.org/pipermail/gcc-patches/2022-February/590289.html)
I simplified the code that built lists of benchmarks, examples, and
fuzz tests, and managed to break it. This patch corrects the code to
once again make the benchmarks available, and to run the examples with
output and the fuzz targets.

Doing this revealed a test failure in internal/fuzz on 32-bit x86: a
signalling NaN is turned into a quiet NaN on the 387 floating-point
stack that GCC uses by default. This CL skips the test.

This fixes https://go.dev/issue/60826.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
bc6bd0d608da1609c1caeb04ab795a83720add55
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 702257009d2..1191a8d663d 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-737de90a63002d4872b19772a7116404ee5815b4
+a3a3c3a2d1bc6a8ca51b302d08c94ef27cdd8f0f
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/go/internal/fuzz/encoding_test.go 
b/libgo/go/internal/fuzz/encoding_test.go
index 8e3800eb77f..53fc5b8dc71 100644
--- a/libgo/go/internal/fuzz/encoding_test.go
+++ b/libgo/go/internal/fuzz/encoding_test.go
@@ -6,6 +6,7 @@ package fuzz
 
 import (
"math"
+   "runtime"
"strconv"
"testing"
"unicode"
@@ -330,6 +331,14 @@ func FuzzFloat64RoundTrip(f *testing.F) {
f.Add(math.Float64bits(math.Inf(-1)))
 
f.Fuzz(func(t *testing.T, u1 uint64) {
+   // The signaling NaN test fails on 32-bit x86 with gccgo,
+   // which uses the 387 floating-point stack by default.
+   // Converting a signaling NaN in and out of the stack
+   // changes the NaN to a quiet NaN.
+   if runtime.GOARCH == "386" && u1 == 0x7FF1 {
+   t.Skip("skipping signalling NaN test on 386 with gccgo")
+   }
+
x1 := math.Float64frombits(u1)
 
b := marshalCorpusFile(x1)
diff --git a/libgo/testsuite/gotest b/libgo/testsuite/gotest
index 0a0a7e14d74..33c98d804d6 100755
--- a/libgo/testsuite/gotest
+++ b/libgo/testsuite/gotest
@@ -577,13 +577,13 @@ symtogo() {
 # Find Go benchmark/fuzz/example functions.
 # The argument is the function name prefix.
 findfuncs() {
-   pattern='$1([^a-z].*)?'
+   pattern="$1([^a-z].*)?"
syms=$($NM -p -v _gotest_.o | egrep " $text .*\."$pattern'$' | fgrep -v 
' __go_' | egrep -v '\.\.\w+$' | sed 's/.* //')
if $havex; then
xsyms=$($NM -p -v $xofile | egrep " $text .*\."$pattern'$' | fgrep 
-v ' __go_' | egrep -v '\.\.\w+$' | sed 's/.* //')
syms="$syms $xsyms"
fi
-$(symtogo "$benchmarksyms")
+symtogo "$syms"
 }
 
 # Takes an example name and puts any output into the file example.txt.
@@ -643,11 +643,13 @@ exampleoutput() {
fi
if $havex; then
needxtest=false
-   if test -n "$testxsyms" -o -n "$benchmarkxsyms"; then
+   if test -n "$testxsyms"; then
+   needxtest=true
+   elif echo "$benchmarks" | grep '_test\.' >/dev/null; then
needxtest=true
else
# Check whether any example has output.
-   for i in $(symtogo "$examplexsyms"); do
+   for i in $(echo "$examples" | grep '_test\.'); do
exampleoutput $i
if test -f example.txt; then
rm -f example.txt


libgo patch committed: Use a C function to call mmap

2023-06-20 Thread Ian Lance Taylor via Gcc-patches
This libgo patches changes the runtime pacakge to use a C function to call mmap.

The final argument to mmap, of type off_t, varies. In
https://go.dev/cl/445375
(https://gcc.gnu.org/pipermail/gcc-patches/2022-October/604158.html)
we changed it to always use the C off_t type, but that broke 32-bit
big-endian Linux systems.  On those systems, using the C off_t type
requires calling the mmap64 function.  In C this is automatically
handled by the  file.  In Go, we would have to change the
magic //extern comment to call mmap64 when appropriate.  Rather than
try to get that right, we instead go through a C function that uses C
implicit type conversions to pick the right type.

This fixes https://gcc.gnu.org/PR110297.

Bootstrapped and tested on x86_64-pc-linux-gnu and
powerpc-pc-linux-gnu (32-bit and 64-bit).  Committed to trunk and GCC
13 branch.

Ian
7f5a6c8a27190daf9daadf5e9f14ef5f4ece
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 1191a8d663d..dbb2d68f909 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-a3a3c3a2d1bc6a8ca51b302d08c94ef27cdd8f0f
+6a1d165c2218cd127ee937a1f45599075762f716
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/Makefile.am b/libgo/Makefile.am
index 207d5a98127..920f8cc7071 100644
--- a/libgo/Makefile.am
+++ b/libgo/Makefile.am
@@ -462,6 +462,7 @@ runtime_files = \
runtime/go-memclr.c \
runtime/go-memmove.c \
runtime/go-memequal.c \
+   runtime/go-mmap.c \
runtime/go-nanotime.c \
runtime/go-now.c \
runtime/go-nosys.c \
diff --git a/libgo/go/runtime/mem_gccgo.go b/libgo/go/runtime/mem_gccgo.go
index 1e84f4f5c56..e7b51ff37cc 100644
--- a/libgo/go/runtime/mem_gccgo.go
+++ b/libgo/go/runtime/mem_gccgo.go
@@ -14,8 +14,8 @@ import (
 //go:linkname sysAlloc
 //go:linkname sysFree
 
-//extern mmap
-func sysMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off 
_libgo_off_t_type) unsafe.Pointer
+//extern __go_mmap
+func sysMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off 
uintptr) unsafe.Pointer
 
 //extern munmap
 func munmap(addr unsafe.Pointer, length uintptr) int32
@@ -38,7 +38,7 @@ func init() {
 }
 
 func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uintptr) 
(unsafe.Pointer, int) {
-   p := sysMmap(addr, n, prot, flags, fd, _libgo_off_t_type(off))
+   p := sysMmap(addr, n, prot, flags, fd, off)
if uintptr(p) == _MAP_FAILED {
return nil, errno()
}
diff --git a/libgo/runtime/go-mmap.c b/libgo/runtime/go-mmap.c
new file mode 100644
index 000..b2327ba68f5
--- /dev/null
+++ b/libgo/runtime/go-mmap.c
@@ -0,0 +1,21 @@
+/* go-mmap.c -- functions for calling C mmap functions.
+
+   Copyright 2023 The Go Authors. All rights reserved.
+   Use of this source code is governed by a BSD-style
+   license that can be found in the LICENSE file.  */
+
+#include "config.h"
+
+#include 
+#include 
+
+/* The exact C function to call varies between mmap and mmap64, and
+   the size of the off_t argument also varies.  Here we provide a
+   function that Go code can call with consistent types.  */
+
+void *
+__go_mmap(void *addr, uintptr_t length, int32_t prot, int32_t flags,
+ int32_t fd, uintptr_t offset)
+{
+  return mmap(addr, length, prot, flags, fd, offset);
+}
diff --git a/libgo/runtime/runtime.h b/libgo/runtime/runtime.h
index b3dc4fd2414..699770d53ad 100644
--- a/libgo/runtime/runtime.h
+++ b/libgo/runtime/runtime.h
@@ -355,9 +355,6 @@ boolruntime_notetsleepg(Note*, int64)  // false - 
timeout
 /*
  * low level C-called
  */
-#define runtime_mmap mmap
-#define runtime_munmap munmap
-#define runtime_madvise madvise
 #define runtime_memclr(buf, size) __builtin_memset((buf), 0, (size))
 #define runtime_getcallerpc() __builtin_return_address(0)
 


Re: libgo patch committed: Use a C function to call mmap

2023-06-20 Thread Ian Lance Taylor via Gcc-patches
On Tue, Jun 20, 2023 at 11:35 AM Andreas Schwab  wrote:
>
> On Jun 20 2023, Ian Lance Taylor via Gcc-patches wrote:
>
> > This libgo patches changes the runtime pacakge to use a C function to call 
> > mmap.
> >
> > The final argument to mmap, of type off_t, varies. In
> > https://go.dev/cl/445375
> > (https://gcc.gnu.org/pipermail/gcc-patches/2022-October/604158.html)
> > we changed it to always use the C off_t type, but that broke 32-bit
> > big-endian Linux systems.
>
> This has nothing to do with big-endian, armv7 isn't big-endian.

OK, but I think that it does have something to do with big-endian.
The bug was that on some 32-bit systems it was passing a 64-bit value
to a function that expected a 32-bit value.  The problem didn't show
up on 32-bit x86 because it is little-endian, and did show up on
32-bit PPC because it is big-endian.  I guess the armv7 case was
failing for a different reason.

Ian


Merge from trunk to gccgo branch

2023-06-21 Thread Ian Lance Taylor via Gcc-patches
I merged trunk revision 577223aebc7acdd31e62b33c1682fe54a622ae27 to
the gccgo branch.

Ian


Go patch committed: Determine types of Slice_{value, info} expressions

2023-06-21 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend determines the types of a couple of
expressions types that accidentally failed to recurse into their
subexpressions.  The test case for this is https://go.dev/cl/505015.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
f42544e04a131cee886cb7cdc65df1e2f09baf8c
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index dbb2d68f909..a028350ba8e 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-6a1d165c2218cd127ee937a1f45599075762f716
+195060166e6045408a2cb95e6aa88c6f0b98f20b
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 4ac55af7433..2112de6abfc 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -18307,6 +18307,16 @@ Slice_value_expression::do_traverse(Traverse* traverse)
   return TRAVERSE_CONTINUE;
 }
 
+// Determine type of a slice value.
+
+void
+Slice_value_expression::do_determine_type(const Type_context*)
+{
+  this->valmem_->determine_type_no_context();
+  this->len_->determine_type_no_context();
+  this->cap_->determine_type_no_context();
+}
+
 Expression*
 Slice_value_expression::do_copy()
 {
diff --git a/gcc/go/gofrontend/expressions.h b/gcc/go/gofrontend/expressions.h
index 3d7e78711bd..bdb7ccd010d 100644
--- a/gcc/go/gofrontend/expressions.h
+++ b/gcc/go/gofrontend/expressions.h
@@ -4364,8 +4364,7 @@ class Slice_value_expression : public Expression
   { return this->type_; }
 
   void
-  do_determine_type(const Type_context*)
-  { }
+  do_determine_type(const Type_context*);
 
   Expression*
   do_copy();
@@ -4419,7 +4418,7 @@ class Slice_info_expression : public Expression
 
   void
   do_determine_type(const Type_context*)
-  { }
+  { this->slice_->determine_type_no_context(); }
 
   Expression*
   do_copy()


Re: [PATCH 1/2] go: update usage of TARGET_AIX to TARGET_AIX_OS

2023-06-22 Thread Ian Lance Taylor via Gcc-patches
On Thu, Jun 22, 2023, 4:47 PM Peter Bergner  wrote:

> On 6/22/23 6:37 PM, Peter Bergner via Gcc-patches wrote:
> > On 6/16/23 12:01 PM, Ian Lance Taylor via Gcc-patches wrote:
> >> On Fri, Jun 16, 2023 at 9:00 AM Paul E. Murphy via Gcc-patches
> >>  wrote:
> >>>
> >>> TARGET_AIX is defined to a non-zero value on linux and maybe other
> >>> powerpc64le targets.  This leads to unexpected behavior such as
> >>> dropping the .go_export section when linking a shared library
> >>> on linux/powerpc64le.
> >>>
> >>> Instead, use TARGET_AIX_OS to toggle AIX specific behavior.
> >>>
> >>> Fixes golang/go#60798.
> >>>
> >>> gcc/go/ChangeLog:
> >>>
> >>> * go-backend.cc [TARGET_AIX]: Rename and update usage to
> >>> TARGET_AIX_OS.
> >>> * go-lang.cc: Likewise.
> >>
> >> This is OK.
> >>
> >> Thanks.
> >>
> >> Ian
> >
> > I pushed this to trunk for Paul.
>
> I see this is broken on the release branches too.  Are backports ok
> after some burn-in on trunk?
>

Yes.  Thanks.

Ian

>


Go patch committed: Support bootstrapping Go 1.21

2023-06-23 Thread Ian Lance Taylor via Gcc-patches
compiler, libgo: support bootstrapping gc compiler

In the Go 1.21 release the package internal/profile imports
internal/lazyregexp.  That works when bootstrapping with Go 1.17,
because that compiler has internal/lazyregep and permits importing it.
We also have internal/lazyregexp in libgo, but since it is not
installed it is not available for importing.  This patch adds
internal/lazyregexp to the list of internal packages that are
installed for bootstrapping.

The Go 1.21, and earlier, releases have a couple of functions in the
internal/abi package that are always fully intrinsified.  The Go
frontend recognizes and intrinsifies those functions as well.
However, the Go frontend was also building function descriptors for
references to the functions without calling them, which failed because
there was nothing to refer to.  That is OK for the gc compiler, which
guarantees that the functions are only called, not referenced.  This
patch arranges to not generate function descriptors for these
functions.

This helps address https://go.dev/issue/60913.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline and GCC 12 and 13 branches.

Ian
2ad5553091d8afbc21bbd3a29a419df359e7aacc
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index a028350ba8e..ff07b1a1fa6 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-195060166e6045408a2cb95e6aa88c6f0b98f20b
+68a756b6aadc901534cfad2b1e73fae9e34f
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 2112de6abfc..d276bd811cc 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -12272,7 +12272,8 @@ Call_expression::intrinsify(Gogo* gogo,
   return Runtime::make_call(code, loc, 3, a1, a2, a3);
 }
 }
-  else if (package == "internal/abi")
+  else if (package == "internal/abi"
+  || package == "bootstrap/internal/abi") // for bootstrapping gc
 {
   if (is_method)
return NULL;
diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc
index 9197eef3e38..980db1ea07e 100644
--- a/gcc/go/gofrontend/gogo.cc
+++ b/gcc/go/gofrontend/gogo.cc
@@ -3296,6 +3296,9 @@ class Create_function_descriptors : public Traverse
   int
   expression(Expression**);
 
+  static bool
+  skip_descriptor(Gogo* gogo, const Named_object*);
+
  private:
   Gogo* gogo_;
 };
@@ -3306,6 +3309,9 @@ class Create_function_descriptors : public Traverse
 int
 Create_function_descriptors::function(Named_object* no)
 {
+  if (Create_function_descriptors::skip_descriptor(this->gogo_, no))
+return TRAVERSE_CONTINUE;
+
   if (no->is_function()
   && no->func_value()->enclosing() == NULL
   && !no->func_value()->is_method()
@@ -3393,6 +3399,28 @@ Create_function_descriptors::expression(Expression** 
pexpr)
   return TRAVERSE_CONTINUE;
 }
 
+// The gc compiler has some special cases that it always compiles as
+// intrinsics.  For those we don't want to generate a function
+// descriptor, as there will be no code for it to refer to.
+
+bool
+Create_function_descriptors::skip_descriptor(Gogo* gogo,
+const Named_object* no)
+{
+  const std::string& pkgpath(no->package() == NULL
+? gogo->pkgpath()
+: no->package()->pkgpath());
+
+  // internal/abi is the standard library package,
+  // bootstrap/internal/abi is the name used when bootstrapping the gc
+  // compiler.
+
+  return ((pkgpath == "internal/abi"
+  || pkgpath == "bootstrap/internal/abi")
+ && (no->name() == "FuncPCABI0"
+ || no->name() == "FuncPCABIInternal"));
+}
+
 // Create function descriptors as needed.  We need a function
 // descriptor for all exported functions and for all functions that
 // are referenced without being called.
@@ -3414,7 +3442,8 @@ Gogo::create_function_descriptors()
   if (no->is_function_declaration()
  && !no->func_declaration_value()->type()->is_method()
  && !Linemap::is_predeclared_location(no->location())
- && !Gogo::is_hidden_name(no->name()))
+ && !Gogo::is_hidden_name(no->name())
+ && !Create_function_descriptors::skip_descriptor(this, no))
fndecls.push_back(no);
 }
   for (std::vector::const_iterator p = fndecls.begin();
diff --git a/libgo/Makefile.am b/libgo/Makefile.am
index 920f8cc7071..c95dc2106cd 100644
--- a/libgo/Makefile.am
+++ b/libgo/Makefile.am
@@ -417,6 +417,7 @@ toolexeclibgounicode_DATA = \
 # Some internal packages are needed to bootstrap the gc toolchain.
 toolexeclibgointernaldir = $(toolexeclibgodir)/internal
 toolexeclibgointernal_DATA = \
+   internal/lazyregexp.gox \
internal/reflectlite.gox \
internal/unsafeheader.gox
 
diff --git a/libgo/go/internal/abi/abi.go b/libgo/go/internal/abi/abi.go

Go patch committed: Support -fgo-importcfg

2023-06-26 Thread Ian Lance Taylor via Gcc-patches
The gc Go compiler has a -importcfg option that takes a file that
provides a mapping from import paths to the files that satisfy those
imports.  This is used by the go build tool to let the compiler read
imported packages directly out of the build cache.  Without this
option the go build tool has to construct a tree of files to provide
the same mapping in the file system.

This patch to the Go frontend adds a -fgo-importcfg option that does
the same thing.  The go build tool already uses this option if it is
supported; with this patch, it is supported.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian

* lang.opt (fgo-importcfg): New option.
* go-c.h (struct go_create_gogo_args): Add importcfg field.
* go-lang.cc (go_importcfg): New static variable.
(go_langhook_init): Set args.importcfg.
(go_langhook_handle_option): Handle -fgo-importcfg.
* gccgo.texi (Invoking gccgo): Document -fgo-importcfg.
cd4f91ed9786caf207d6d68bf2e64f986ed19735
diff --git a/gcc/go/gccgo.texi b/gcc/go/gccgo.texi
index 4ab1a76818f..90651af8384 100644
--- a/gcc/go/gccgo.texi
+++ b/gcc/go/gccgo.texi
@@ -271,6 +271,14 @@ pattern to a list of file names, and @code{Files} maps 
each file name
 to a full path to the file.  This option is intended for use by the
 @command{go} command to implement @code{//go:embed}.
 
+@cindex @option{-fgo-importcfg}
+@item -fgo-importcfg=@var{file}
+Identify a file that provides mappings for import package paths found
+in the Go source files.  The file can contain two commands:
+@code{importpath} to rename import paths for vendoring and
+@code{packagefile} to map from package path to files containing export
+data.  This option is intended for use by the @command{go} command.
+
 @cindex @option{-g for gccgo}
 @item -g
 This is the standard @command{gcc} option (@pxref{Debugging Options, ,
diff --git a/gcc/go/go-c.h b/gcc/go/go-c.h
index c6050382aa8..6a2b57b3b44 100644
--- a/gcc/go/go-c.h
+++ b/gcc/go/go-c.h
@@ -41,6 +41,7 @@ struct go_create_gogo_args
   const char* prefix;
   const char* relative_import_path;
   const char* c_header;
+  const char* importcfg;
   const char* embedcfg;
   Backend* backend;
   Linemap* linemap;
diff --git a/gcc/go/go-lang.cc b/gcc/go/go-lang.cc
index c6c147b20a5..e85a4bfe949 100644
--- a/gcc/go/go-lang.cc
+++ b/gcc/go/go-lang.cc
@@ -90,6 +90,7 @@ static const char *go_prefix = NULL;
 static const char *go_relative_import_path = NULL;
 static const char *go_c_header = NULL;
 static const char *go_embedcfg = NULL;
+static const char *go_importcfg = NULL;
 
 /* Language hooks.  */
 
@@ -111,6 +112,7 @@ go_langhook_init (void)
   args.relative_import_path = go_relative_import_path;
   args.c_header = go_c_header;
   args.embedcfg = go_embedcfg;
+  args.importcfg = go_importcfg;
   args.check_divide_by_zero = go_check_divide_zero;
   args.check_divide_overflow = go_check_divide_overflow;
   args.compiling_runtime = go_compiling_runtime;
@@ -286,6 +288,10 @@ go_langhook_handle_option (
   go_embedcfg = arg;
   break;
 
+case OPT_fgo_importcfg_:
+  go_importcfg = arg;
+  break;
+
 default:
   /* Just return 1 to indicate that the option is valid.  */
   break;
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index ff07b1a1fa6..c44cdc2baac 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-68a756b6aadc901534cfad2b1e73fae9e34f
+92152c88ea8e2dd9e8c67e91bf4ae5e3edf1b506
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/embed.cc b/gcc/go/gofrontend/embed.cc
index 0584f707ce6..6dada5efc2a 100644
--- a/gcc/go/gofrontend/embed.cc
+++ b/gcc/go/gofrontend/embed.cc
@@ -19,8 +19,8 @@
 
 // Read a file into *DATA.  Returns false on error.
 
-static bool
-read_file(const char* filename, Location loc, std::string* data)
+bool
+Gogo::read_file(const char* filename, Location loc, std::string* data)
 {
   int fd = open(filename, O_RDONLY | O_BINARY);
   if (fd < 0)
@@ -346,7 +346,8 @@ Gogo::read_embedcfg(const char *filename)
 bool
 Embedcfg_reader::initialize_from_file()
 {
-  if (!read_file(this->filename_, Linemap::unknown_location(), &this->data_))
+  if (!Gogo::read_file(this->filename_, Linemap::unknown_location(),
+  &this->data_))
 return false;
   if (this->data_.empty())
 {
@@ -849,7 +850,7 @@ Gogo::initializer_for_embeds(Type* type,
}
 
   std::string data;
-  if (!read_file(this->embed_files_[paths[0]].c_str(), loc, &data))
+  if (!Gogo::read_file(this->embed_files_[paths[0]].c_str(), loc, &data))
return Expression::make_error(loc);
 
   Expression* e = Expression::make_string(data, loc);
@@ -909,7 +910,7 @@ Gogo::initializer_for_embeds(Type* type,
   std::string data;
   if ((*pp)[pp->size() - 1] != '/')
{
- if (!read_file(this->embed_files_[*pp].c_str(), loc, &data))
+ if (!Gogo::rea

Re: Merge from trunk to gccgo branch

2023-06-26 Thread Ian Lance Taylor via Gcc-patches
I merged trunk revision 3a39a31b8ae9c6465434aefa657f7fcc86f905c0 to
the gccgo branch.

Ian


Re: [PATCH] Always define `WIN32_LEAN_AND_MEAN` before

2023-03-05 Thread Ian Lance Taylor via Gcc-patches
On Fri, Mar 3, 2023 at 10:47 PM Xi Ruoyao  wrote:
>
> On Sat, 2023-01-07 at 06:52 +, Jonathan Yong via Gcc-patches wrote:
> > On 1/6/23 18:10, Jakub Jelinek wrote:
> > > On Sat, Jan 07, 2023 at 02:01:05AM +0800, LIU Hao via Gcc-patches
> > > wrote:
> > > > libgomp/
> > > >
> > > > PR middle-end/108300
> > > > * config/mingw32/proc.c: Define `WIN32_LEAN_AND_MEAN`
> > > > before
> > > > .
> > >
> > > This change is ok for trunk.
> > >
> > > Jakub
> > >
> >
> > Pushed to master branch, thanks LH.
>
> The patch touches libgo (w/o mentioning it in the ChangeLog).  I guess
> you need to contribute the libgo part into the upstream Go runtime or
> the change will be undone when Ian merges libgo next time.

Thanks, I've reverted the part of the patch that applies to libgo.

It's not worth changing upstream because gccgo doesn't support Windows
anyhow, and because that change is gone in the even-more-upstream
sources.

Ian


Re: Now gcc-13: [Fwd: [PATCH] gcc-12: Re-enable split-stack support for GNU/Hurd.]

2023-03-15 Thread Ian Lance Taylor via Gcc-patches
On Wed, Mar 15, 2023 at 9:14 AM Svante Signell  wrote:
>
> Package: gcc-snapshot
> Version: 1:20230315-1
> Severity: important
> Tags: patch
> User: debian-h...@lists.debian.org
> Usertags: hurd
> Affects: gcc-snapshot
> X-Debbugs-CC: debian-h...@lists.debian.org
>
> Hello, seems like the patch gcc_config_gnu.h.diff, in debian gcc-12 named:
> pr104290-followup.diff was lost (again).
>
> How can this patch ever become upstreamed??
>
> It seems like sending to gcc-patches is not enough. Create a regression bug?
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104290 is already reported as a
> regression, it has to be updated to cover upstream releases of gcc-13 now.
>
> For gcc-12 Debian has been carrying it as:
> pr104290-followup.diff
>
> Submitting this problem as new bug to Debian/gcc-13/gcc-snapshot!
>
> Thanks!
>
>
>
> -- Forwarded message --
> From: Svante Signell 
> To: gcc-patches 
> Cc: Ian Lance Taylor , Matthias Klose 
> Bcc:
> Date: Wed, 23 Feb 2022 11:13:50 +0100
> Subject: [PATCH] gcc-12: Re-enable split-stack support for GNU/Hurd.
> Hello,
>
> In line of porting the latest build of libgo/go with gcc-12 to GNU/Hurd, 
> support
> of split-stack was found to be removed.
>
> After patching the files in libgo the build of gotools fails:
> go1: error: '-fsplit-stack' currently only supported on GNU/Linux
> go1: error: '-fsplit-stack' is not supported by this compiler configuration
>
> The attached patch defines OPTION_GLIBC_P(opts) and OPTION_GLIBC that was lost
> in config/gnu.h, needed to enable split-stack support for GNU/Hurd.
>
> This problem happened with the latest commit as discussed in the mail thread
> starting with 
> https://gcc.gnu.org/pipermail/gcc-patches/2022-January/588973.html
> .
>
> The file first doing this check is: (first error: ..)
> src/gcc/common/config/i386/i386-common.cc
> in function:
> static bool ix86_supports_split_stack (bool report,
> struct gcc_options *opts ATTRIBUTE_UNUSED)
>
> and secondly in:src/gcc/opts.cc: (second error: ...)
> in function:
> void
> finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
> location_t loc)
>
> The checking logic is in function ix86_supports_split_stack():
> #if defined(TARGET_THREAD_SPLIT_STACK_OFFSET) && defined(OPTION_GLIBC_P)
>   if (!OPTION_GLIBC_P (opts))
> #endif
> {
>   if (report)
> error ("%<-fsplit-stack%> currently only supported on GNU/Linux");
>   return false;
> }
>
>   bool ret = true;
>
> In case of GNU/Hurd TARGET_THREAD_SPLIT_STACK_OFFSET is defined as well as
> OPTION_GLIBC_P but OPTION_GLIBC_P(opts) is needed to. The attached patch to
> src/gcc/config/gnu.h creates that definition. For GNU/Hurd, gnu.h is included 
> in
> the configure stage:
> Configuring stage 1 in ./gcc
> ...
> Using the following target machine macro files:
> ...
> ../../src/gcc/config/gnu.h
>
> For a longer history about this bug see:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104290
>
> Additionally, I would propose the text in 
> gcc/common/config/i386/i386-common.cc
> to change from:
> error ("%<-fsplit-stack%> currently only supported on GNU/Linux");
> to:
> error ("%<-fsplit-stack%> currently only supported on GLIBC-based systems");


If GNU/Hurd requires glibc, then I think it would be simpler to define
OPTION_GLIBC and OPTION_GLIBC_P as true.

Adding Thomas Schwinge as the GNU/Hurd maintainer.

Ian


libgo patch committed: Add syscall.prlimit

2023-05-11 Thread Ian Lance Taylor via Gcc-patches
As of https://go.dev/cl/476695 the package golang.org/x/sys/unix
expects a syscall.prlimit function to exist.  This libgo patch adds
that function.  This is for https://go.dev/issue/46279 and
https://go.dev/issue/59712.  Since this is a small patch and is needed
to compile the widely used x/sys/unix package, committed to tip and to
GCC 11, 12, and 13 branches.

Ian
ba8160449c646138a3a9e1723ac1db0716a8b103
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index e133650ad91..702257009d2 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-0411a2733fd468e69f1998edd91e8fe3ba40ff9e
+737de90a63002d4872b19772a7116404ee5815b4
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/go/syscall/libcall_linux.go 
b/libgo/go/syscall/libcall_linux.go
index 19ae4393cf1..03ca7261b59 100644
--- a/libgo/go/syscall/libcall_linux.go
+++ b/libgo/go/syscall/libcall_linux.go
@@ -189,6 +189,14 @@ func Gettid() (tid int) {
 //sys  PivotRoot(newroot string, putold string) (err error)
 //pivot_root(newroot *byte, putold *byte) _C_int
 
+// Used by golang.org/x/sys/unix.
+//sys  prlimit(pid int, resource int, newlimit *Rlimit, oldlimit *Rlimit) (err 
error)
+//prlimit(pid Pid_t, resource _C_int, newlimit *Rlimit, oldlimit *Rlimit) 
_C_int
+
+func Prlimit(pid int, resource int, newlimit *Rlimit, oldlimit *Rlimit) error {
+   return prlimit(pid, resource, newlimit, oldlimit)
+}
+
 //sys  Removexattr(path string, attr string) (err error)
 //removexattr(path *byte, name *byte) _C_int
 


Go driver patch committed: Always act as though -g was passed

2021-01-28 Thread Ian Lance Taylor via Gcc-patches
The go1 compiler always turns on debugging, to support Go stack traces
and functions like runtime.Callers.  With the recent switch to turn on
DWARF 5 by default, this caused failures with some versions of gas,
such as 2.35.1, because the assembly code would assume DWARF 5 but the
driver would not pass --gdwarf-5 to gas.  gas would then give an
error: "file number less than one".

This change avoids that problem by having the gccgo driver spec add a
-g option to the command line if no other -g option is present.  The
newly added -g option is passed to the assembler as --gdwarf-5.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian

* gospec.c (lang_specific_driver): Add -g if no debugging options
were passed.
a7dbc8f83a4c146f5ab851ad7796c3ddbfe17b51
diff --git a/gcc/go/gospec.c b/gcc/go/gospec.c
index aaf64e73949..cf8d0f2b60e 100644
--- a/gcc/go/gospec.c
+++ b/gcc/go/gospec.c
@@ -127,6 +127,9 @@ lang_specific_driver (struct cl_decoded_option 
**in_decoded_options,
   /* The first input file with an extension of .go.  */
   const char *first_go_file = NULL;  
 
+  /* Whether we saw any -g option.  */
+  bool saw_opt_g = false;
+
   argc = *in_decoded_options_count;
   decoded_options = *in_decoded_options;
   added_libraries = *in_added_libraries;
@@ -208,6 +211,18 @@ lang_specific_driver (struct cl_decoded_option 
**in_decoded_options,
  saw_opt_o = true;
  break;
 
+   case OPT_g:
+   case OPT_gdwarf:
+   case OPT_gdwarf_:
+   case OPT_ggdb:
+   case OPT_gstabs:
+   case OPT_gstabs_:
+   case OPT_gvms:
+   case OPT_gxcoff:
+   case OPT_gxcoff_:
+ saw_opt_g = true;
+ break;
+
case OPT_static:
  static_link = 1;
  break;
@@ -271,6 +286,15 @@ lang_specific_driver (struct cl_decoded_option 
**in_decoded_options,
   j++;
 }
 
+  /* The go1 compiler is going to enable debug info by default.  If we
+ don't see any -g options, force -g, so that we invoke the
+ assembler with the right debug option.  */
+  if (!saw_opt_g)
+{
+  generate_option (OPT_g, "1", 0, CL_DRIVER, &new_decoded_options[j]);
+  j++;
+}
+
   /* NOTE: We start at 1 now, not 0.  */
   while (i < argc)
 {


libgo: update to Go1.16rc1 release

2021-01-29 Thread Ian Lance Taylor via Gcc-patches
This patch updates libgo to the Go1.16rc1 release (the first 1.16
release candidate).  Bootstrapped and ran Go tests on
x86_64-pc-linux-gnu.  Committed to mainline.

The diffs are too large to attach, so I've trimmed out some
uninteresting changes to generated files.  They are of course
available in the repo.

Ian


patch.txt.bz2
Description: application/bzip


libgo patch committed: Correct reference to getsystemcgf

2021-01-29 Thread Ian Lance Taylor via Gcc-patches
This libgo patch by Clément Chigot directly sets getsystemcfg as
//extern in internal/cpu instead of trying to use the runtime as in Go
toolchain.  Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.
Committed to mainline.

Ian
7da2394fc591a3fb236190c8712f3960a4ee8e5f
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 366fcf02885..cb12c83a700 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-2663206528a6d46cbde60dbccf84c8288707ab8d
+271a043537f2f0ae93bde2cf4f4897e68a476ece
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/go/internal/cpu/cpu_ppc64x_aix.go 
b/libgo/go/internal/cpu/cpu_ppc64x_aix.go
index a932684baf2..e2422a6ddaa 100644
--- a/libgo/go/internal/cpu/cpu_ppc64x_aix.go
+++ b/libgo/go/internal/cpu/cpu_ppc64x_aix.go
@@ -17,5 +17,5 @@ func osinit() {
PPC64.IsPOWER9 = isSet(impl, _IMPL_POWER9)
 }
 
-// getsystemcfg is defined in runtime/os2_aix.go
+//extern getsystemcfg
 func getsystemcfg(label uint) uint
diff --git a/libgo/go/runtime/os_aix.go b/libgo/go/runtime/os_aix.go
index 630a1c22d7f..d902ae04dc9 100644
--- a/libgo/go/runtime/os_aix.go
+++ b/libgo/go/runtime/os_aix.go
@@ -13,9 +13,6 @@ import (
 //extern sysconf
 func sysconf(int32) _C_long
 
-//extern getsystemcfg
-func getsystemcfg(int32) uint64
-
 type mOS struct {
waitsema uintptr // semaphore for parking on locks
 }


gotools patch committed: Test file embedding

2021-02-02 Thread Ian Lance Taylor via Gcc-patches
This patch to the gotools Makefile runs "go test
embed/internal/embedtest" using the newly built go tool, to test that
file embedding works.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian

* Makefile.am (check-embed): New target.
(check): Depend on check-embed.  Examine embed-testlog.
(mostlyclean-local): Add check-embed-dir.
(.PHONY): Add check-embed.
* Makefile.in: Regenerate.
345484a6755260cd6a01c17ac5547da669422b20
diff --git a/gotools/Makefile.am b/gotools/Makefile.am
index 3bbccb96c28..6576fe77b85 100644
--- a/gotools/Makefile.am
+++ b/gotools/Makefile.am
@@ -102,7 +102,7 @@ MOSTLYCLEANFILES = \
 mostlyclean-local:
if test -d check-go-dir; then chmod -R u+w check-go-dir; fi
rm -rf check-go-dir cgo-test-dir carchive-test-dir \
-   check-vet-dir gocache-test
+   check-vet-dir check-embed-dir gocache-test
 
 if NATIVE
 
@@ -307,11 +307,28 @@ check-vet: go$(EXEEXT) $(noinst_PROGRAMS) check-head 
check-gccgo check-gcc
(cd check-vet-dir/src/cmd/vet && $(abs_builddir)/go$(EXEEXT) test 
-test.short -test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v) >> cmd_vet-testlog 
2>&1 || echo "--- $${fl}: go test cmd/vet (0.00s)" >> cmd_vet-testlog
grep '^--- ' cmd_vet-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' | 
sort -k 2
 
+# check-embed runs `go test embed/internal/embedtest` in our environment.
+check-embed: go$(EXEEXT) $(noinst_PROGRAMS) check-head check-gccgo check-gcc
+   rm -rf check-embed-dir embed-testlog
+   $(MKDIR_P) check-embed-dir/src/embed/internal
+   cp $(libgosrcdir)/go.mod check-embed-dir/src/
+   $(MKDIR_P) check-embed-dir/src/vendor
+   cp $(libgosrcdir)/vendor/modules.txt check-embed-dir/src/vendor/
+   cp -r $(libgosrcdir)/embed/internal/embedtest 
check-embed-dir/src/embed/internal
+   @abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
+   abs_checkdir=`cd check-embed-dir && $(PWD_COMMAND)`; \
+   echo "cd check-embed-dir/src/embed/internal/embedtest && $(ECHO_ENV) 
GOPATH=$${abs_checkdir} $(abs_builddir)/go$(EXEEXT) test -test.short 
-test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v" > embed-testlog
+   $(CHECK_ENV) \
+   GOPATH=`cd check-embed-dir && $(PWD_COMMAND)`; \
+   export GOPATH; \
+   (cd check-embed-dir/src/embed/internal/embedtest && 
$(abs_builddir)/go$(EXEEXT) test -test.short 
-test.timeout=$(GOTOOLS_TEST_TIMEOUT)s -test.v) >> embed-testlog 2>&1 || echo 
"--- $${fl}: go test embed/internal/embedtest (0.00s)" >> embed-testlog
+   grep '^--- ' embed-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' | 
sort -k 2
+
 # The check targets runs the tests and assembles the output files.
-check: check-head check-go-tool check-runtime check-cgo-test 
check-carchive-test check-vet
+check: check-head check-go-tool check-runtime check-cgo-test 
check-carchive-test check-vet check-embed
@mv gotools.head gotools.sum
@cp gotools.sum gotools.log
-   @for file in cmd_go-testlog runtime-testlog cgo-testlog 
carchive-testlog cmd_vet-testlog; do \
+   @for file in cmd_go-testlog runtime-testlog cgo-testlog 
carchive-testlog cmd_vet-testlog embed-testlog; do \
  testname=`echo $${file} | sed -e 's/-testlog//' -e 's|_|/|'`; \
  echo "Running $${testname}" >> gotools.sum; \
  echo "Running $${testname}" >> gotools.log; \
@@ -337,7 +354,8 @@ check: check-head check-go-tool check-runtime 
check-cgo-test check-carchive-test
@echo "runtest completed at `date`" >> gotools.log
@if grep '^FAIL' gotools.sum >/dev/null 2>&1; then exit 1; fi
 
-.PHONY: check check-head check-go-tool check-runtime check-cgo-test 
check-carchive-test check-vet
+.PHONY: check check-head check-go-tool check-runtime check-cgo-test
+.PHONY: check-carchive-test check-vet check-embed
 
 else
 


Merge from trunk to gccgo branch

2021-02-02 Thread Ian Lance Taylor via Gcc-patches
I merged trunk revision 8e4a738d2540ab6aff77506d368bf4e3fa6963bd to
the gccgo branch.

Ian


libgo patch committed: Install new packages

2021-02-03 Thread Ian Lance Taylor via Gcc-patches
In the update of libgo to the Go 1.16 beta and release candidate, I
forgot to update the Makefile to actually install new packages.  This
patch does that.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
8e6839059d52c02acb52a4ba1ea6a5fcda88d16b
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index cb12c83a700..905c6fe9326 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-271a043537f2f0ae93bde2cf4f4897e68a476ece
+78770fd9c29037dec8b2919c0f02067915c6ad33
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/Makefile.am b/libgo/Makefile.am
index 7be90a564fe..eea7ff15aed 100644
--- a/libgo/Makefile.am
+++ b/libgo/Makefile.am
@@ -130,6 +130,7 @@ toolexeclibgo_DATA = \
bytes.gox \
context.gox \
crypto.gox \
+   embed.gox \
encoding.gox \
errors.gox \
expvar.gox \
@@ -256,6 +257,11 @@ toolexeclibgogo_DATA = \
go/token.gox \
go/types.gox
 
+toolexeclibgogobuilddir = $(toolexeclibgogodir)/build
+
+toolexeclibgogobuild_DATA = \
+   go/build/constraint.gox
+
 toolexeclibgohashdir = $(toolexeclibgodir)/hash
 
 toolexeclibgohash_DATA = \
@@ -292,6 +298,7 @@ toolexeclibgoindex_DATA = \
 toolexeclibgoiodir = $(toolexeclibgodir)/io
 
 toolexeclibgoio_DATA = \
+   io/fs.gox \
io/ioutil.gox
 
 toolexeclibgologdir = $(toolexeclibgodir)/log
@@ -360,6 +367,7 @@ toolexeclibgoruntimedir = $(toolexeclibgodir)/runtime
 
 toolexeclibgoruntime_DATA = \
runtime/debug.gox \
+   runtime/metrics.gox \
runtime/pprof.gox \
runtime/trace.gox
 
@@ -371,6 +379,7 @@ toolexeclibgosync_DATA = \
 toolexeclibgotestingdir = $(toolexeclibgodir)/testing
 
 toolexeclibgotesting_DATA = \
+   testing/fstest.gox \
testing/iotest.gox \
testing/quick.gox
 


Re: Merge from trunk to gccgo branch

2021-02-03 Thread Ian Lance Taylor via Gcc-patches
I merged trunk revision 530203d6e3244c25eda4124f0fa5756ca9a5683e to
the gccgo branch.

Ian


libbacktrace patch committed: Use objcopy --help to check for option

2021-02-11 Thread Ian Lance Taylor via Gcc-patches
This patch changes the libbacktrace configure script to check for
whether objcopy supports --add-gnu-debuglink (a test that only affects
the libbacktrace testsuite) to look at the objcopy --help option
rather than trying to apply --add-gnu-debuglink to /bin/ls.  The
latter can trigger a warning if /bin/ls already has a separate debug
file.  Bootstrapped and ran libbacktrace testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian

* configure.ac: Check for objcopy --add-gnu-debuglink by using
objcopy --help.
* configure: Regenerate
diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac
index 83d4733509a..43a33a66b82 100644
--- a/libbacktrace/configure.ac
+++ b/libbacktrace/configure.ac
@@ -500,8 +500,7 @@ AC_CACHE_CHECK([whether objcopy supports debuglink],
   libbacktrace_cv_objcopy_debuglink=no
 elif ! test -n "${OBJCOPY}"; then
   libbacktrace_cv_objcopy_debuglink=no
-elif ${OBJCOPY} --add-gnu-debuglink=x /bin/ls /tmp/ls$$; then
-  rm -f /tmp/ls$$
+elif ${OBJCOPY} --help | fgrep add-gnu-debuglink >/dev/null 2>&1; then
   libbacktrace_cv_objcopy_debuglink=yes
 else
   libbacktrace_cv_objcopy_debuglink=no


Go patch committed: Use correct path for string/[]byte embed

2021-02-12 Thread Ian Lance Taylor via Gcc-patches
This patch by Michael Matloob fixes the Go frontend to use the correct
path when opening an embedded file for a string or []byte type.  For
the other embed.FS case we were correctly using the Files mapping, but
for string or []byte we were not.  Bootstrapped and ran Go testsuite
on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
7767de2344dca80cc95a982b048c341b72c169c2
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 905c6fe9326..3175ba0e005 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-78770fd9c29037dec8b2919c0f02067915c6ad33
+a5d7c4225fbbd06b97db6fa424cc0cb5191082d4
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/embed.cc b/gcc/go/gofrontend/embed.cc
index bea1003bc08..0a7df0531ec 100644
--- a/gcc/go/gofrontend/embed.cc
+++ b/gcc/go/gofrontend/embed.cc
@@ -812,8 +812,7 @@ Gogo::initializer_for_embeds(Type* type,
}
 
   // Each pattern in the embedcfg file maps to a list of file
-  // names.  For each file name, the embedcfg file records an
-  // absolute path.  Add those absolute paths to PATHS.
+  // names.  Add those file names to PATHS.
   for (std::vector::const_iterator pf = pp->second.begin();
   pf != pp->second.end();
   pf++)
@@ -865,7 +864,7 @@ Gogo::initializer_for_embeds(Type* type,
}
 
   std::string data;
-  if (!read_file(paths[0].c_str(), loc, &data))
+  if (!read_file(this->embed_files_[paths[0]].c_str(), loc, &data))
return Expression::make_error(loc);
 
   Expression* e = Expression::make_string(data, loc);


Re: Merge from trunk to gccgo branch

2021-02-12 Thread Ian Lance Taylor via Gcc-patches
I merged trunk revision 9769564e7456453e2273071d0faa5aab2554ff78 to
the gccgo branch.

Ian


Go patch committed: Unalias receiver type in export data

2021-02-16 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend unaliases the receiver type when
outputting export data for a method.  This avoids a crash when
importing such a package.  The test case for this is
https://golang.org/cl/292009.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
91dbe2eee631df74bd96153aaf34d6f0da4b1a02
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 3175ba0e005..eed9ce01905 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-a5d7c4225fbbd06b97db6fa424cc0cb5191082d4
+c406de0594782b1d6782a732a50f5b76387852dc
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc
index 62b06be827b..38a2f6f8f9e 100644
--- a/gcc/go/gofrontend/gogo.cc
+++ b/gcc/go/gofrontend/gogo.cc
@@ -5898,7 +5898,7 @@ Function::export_func_with_type(Export* exp, const 
Named_object* no,
   exp->write_name(receiver->name());
   exp->write_escape(receiver->note());
   exp->write_c_string(" ");
-  exp->write_type(receiver->type());
+  exp->write_type(receiver->type()->unalias());
   exp->write_c_string(") ");
 }
 


libgo patch committed: Update to Go1.16 release

2021-02-19 Thread Ian Lance Taylor via Gcc-patches
This patch updates libgo to the final Go 1.16 release.  Bootstrapped
and ran Go testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
c89b42d3b9d76dedb35e8478913ddf5367f3b5e6
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index eed9ce01905..217bdd55f1d 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-c406de0594782b1d6782a732a50f5b76387852dc
+78a840e4940159a66072237f6b002ab79f441b79
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/MERGE b/libgo/MERGE
index b2fc633f06c..183b0245ee2 100644
--- a/libgo/MERGE
+++ b/libgo/MERGE
@@ -1,4 +1,4 @@
-3e06467282c6d5678a6273747658c04314e013ef
+f21be2fdc6f1becdbed1592ea0b245cdeedc5ac8
 
 The first line of this file holds the git revision number of the
 last merge done from the master library sources.
diff --git a/libgo/VERSION b/libgo/VERSION
index a19294250b3..4befab24bc9 100644
--- a/libgo/VERSION
+++ b/libgo/VERSION
@@ -1 +1 @@
-go1.16rc1
+go1.16
diff --git a/libgo/go/archive/tar/strconv.go b/libgo/go/archive/tar/strconv.go
index 6d0a4038082..f0b61e6dba6 100644
--- a/libgo/go/archive/tar/strconv.go
+++ b/libgo/go/archive/tar/strconv.go
@@ -265,8 +265,27 @@ func parsePAXRecord(s string) (k, v, r string, err error) {
return "", "", s, ErrHeader
}
 
+   afterSpace := int64(sp + 1)
+   beforeLastNewLine := n - 1
+   // In some cases, "length" was perhaps padded/malformed, and
+   // trying to index past where the space supposedly is goes past
+   // the end of the actual record.
+   // For example:
+   //"30 
mtime=1432668921.098285006\n30 ctime=2147483649.15163319"
+   //  ^ ^
+   //  | |
+   //  |  afterSpace=35
+   //  |
+   //  beforeLastNewLine=29
+   // yet indexOf(firstSpace) MUST BE before endOfRecord.
+   //
+   // See https://golang.org/issues/40196.
+   if afterSpace >= beforeLastNewLine {
+   return "", "", s, ErrHeader
+   }
+
// Extract everything between the space and the final newline.
-   rec, nl, rem := s[sp+1:n-1], s[n-1:n], s[n:]
+   rec, nl, rem := s[afterSpace:beforeLastNewLine], 
s[beforeLastNewLine:n], s[n:]
if nl != "\n" {
return "", "", s, ErrHeader
}
diff --git a/libgo/go/archive/tar/strconv_test.go 
b/libgo/go/archive/tar/strconv_test.go
index dd3505a758a..add65e272ae 100644
--- a/libgo/go/archive/tar/strconv_test.go
+++ b/libgo/go/archive/tar/strconv_test.go
@@ -368,6 +368,13 @@ func TestParsePAXRecord(t *testing.T) {
{"16 longkeyname=hahaha\n", "16 longkeyname=hahaha\n", "", "", 
false},
{"3 somelongkey=\n", "3 somelongkey=\n", "", "", false},
{"50 tooshort=\n", "50 tooshort=\n", "", "", false},
+   {"30 
mtime=1432668921.098285006\n30 ctime=2147483649.15163319", 
"30 mtime=1432668921.098285006\n30 
ctime=2147483649.15163319", "mtime", "1432668921.098285006", false},
+   {"06 k=v\n", "06 k=v\n", "", "", false},
+   {"6 k=v\n", "6 k=v\n", "", "", false},
+   {"06 k=v\n", "06 k=v\n", "", "", false},
+   {"00 k=v\n", "00 k=v\n", "", "", false},
+   {"0 k=v\n", "0 k=v\n", "", "", false},
+   {"+005 x=\n", "+005 x=\n", "", "", false},
}
 
for _, v := range vectors {
diff --git a/libgo/go/cmd/go/alldocs.go b/libgo/go/cmd/go/alldocs.go
index 49d390297cd..e7c63f0749d 100644
--- a/libgo/go/cmd/go/alldocs.go
+++ b/libgo/go/cmd/go/alldocs.go
@@ -1808,7 +1808,7 @@
 // The directory where the go command will write
 // temporary source files, packages, and binaries.
 // GOVCS
-//   Lists version control commands that may be used with matching servers.
+// Lists version control commands that may be used with matching 
servers.
 // See 'go help vcs'.
 //
 // Environment variables for use with cgo:
@@ -2410,6 +2410,17 @@
 //
 // For a detailed reference on modules, see https://golang.org/ref/mod.
 //
+// By default, the go command may download modules from 
https://proxy.golang.org.
+// It may authenticate modules using the checksum database at
+// https://sum.golang.org. Both services are operated by the Go team at Google.
+// The privacy policies for these services are available at
+// https://proxy.golang.org/privacy and https://sum.golang.org/privacy,
+// respectively.
+//
+// The go command's download behavior may be configured using GOPROXY, GOSUMDB,
+// GOPRIVATE, and other environment variables. See 'go help environment'
+// and https://golang.org/ref/mod#private-module-p

libgo patch committed: Ensure 8 byte atomicity on ppc64

2021-02-25 Thread Ian Lance Taylor via Gcc-patches
This libgo patch by Lynn Boger ensures 8 byte atomicity in memmove and
memset on ppc64.

Go requires that pointer moves are done 8 bytes at a time, so that the
concurrent garbage collector always sees an entire pointer value.
gccgo uses libc's memmove and memset which does not require that, and
there are some cases where an 8 byte move might be done as 4+4.

To enforce 8 byte moves for memmove and memset, this adds a C
implementation in libgo/runtime for memmove and memset to be used on
ppc64le and ppc64.  Asm implementations were considered but discarded
to avoid different implementations for different target ISAs.

This fixes https://golang.org/issue/41428.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
0689d6198ac4f1c00ba4722e0321f0cedfdd6d16
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 217bdd55f1d..9806b9da1e1 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-78a840e4940159a66072237f6b002ab79f441b79
+56cf388da8d04bbd3824c4df34d77a8afa69749b
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/Makefile.am b/libgo/Makefile.am
index eea7ff15aed..dec98756673 100644
--- a/libgo/Makefile.am
+++ b/libgo/Makefile.am
@@ -454,6 +454,7 @@ runtime_files = \
runtime/go-fieldtrack.c \
runtime/go-matherr.c \
runtime/go-memclr.c \
+   runtime/go-memmove.c \
runtime/go-memequal.c \
runtime/go-nanotime.c \
runtime/go-now.c \
diff --git a/libgo/go/runtime/stubs.go b/libgo/go/runtime/stubs.go
index 6d20c384330..dea7234b3ad 100644
--- a/libgo/go/runtime/stubs.go
+++ b/libgo/go/runtime/stubs.go
@@ -106,9 +106,7 @@ func reflect_memclrNoHeapPointers(ptr unsafe.Pointer, n 
uintptr) {
memclrNoHeapPointers(ptr, n)
 }
 
-// memmove copies n bytes from "from" to "to".
 //go:noescape
-//extern __builtin_memmove
 func memmove(to, from unsafe.Pointer, n uintptr)
 
 //go:linkname reflect_memmove reflect.memmove
diff --git a/libgo/runtime/go-memclr.c b/libgo/runtime/go-memclr.c
index b5d4975e57d..53b81178539 100644
--- a/libgo/runtime/go-memclr.c
+++ b/libgo/runtime/go-memclr.c
@@ -13,5 +13,48 @@ void memclrNoHeapPointers(void *, uintptr)
 void
 memclrNoHeapPointers (void *p1, uintptr len)
 {
-  __builtin_memset (p1, 0, len);
+
+#if !defined(__PPC64__)
+  __builtin_memset(p1, 0, len);
+#else
+  int64 rem,drem,i;
+  uint64 offset;
+  volatile uint64 *vp;
+
+  if (len == 0) {
+return;
+  }
+  rem = len;
+
+  offset = (uint64)p1 % 8;
+  // This memset is OK since it can't contain
+  // an 8 byte aligned pointer.
+  if ((rem < 8) || (offset > 0 && offset+rem <= 16)) {
+__builtin_memset(p1, 0, rem);
+return;
+  }
+  // Move initial bytes to get to 8 byte boundary
+  if (offset > 0) {
+__builtin_memset(p1, 0, 8-offset);
+p1 = (void*)((char*)p1+8-offset);
+rem -= 8-offset;
+  }
+
+  // If at least 8 bytes left, clear
+  drem = rem>>3;
+
+  vp = (volatile uint64*)(p1);
+  // Without the use of volatile here, the compiler
+  // might convert the loop into a memset.
+  for (i=0; i 0) {
+__builtin_memset (p1, 0, rem);
+  }
+#endif
 }
diff --git a/libgo/runtime/go-memmove.c b/libgo/runtime/go-memmove.c
new file mode 100644
index 000..1ca3f4822b7
--- /dev/null
+++ b/libgo/runtime/go-memmove.c
@@ -0,0 +1,89 @@
+/* go-memmove.c -- memmove
+
+   Copyright 2021 The Go Authors. All rights reserved.
+   Use of this source code is governed by a BSD-style
+   license that can be found in the LICENSE file.  */
+
+#include "runtime.h"
+
+void gomemmove(void *, void *, uintptr)
+  __asm__ (GOSYM_PREFIX "runtime.memmove")
+  __attribute__ ((no_split_stack));
+
+// This implementation is necessary since
+// the __builtin_memmove might use __libc_memmove
+// which doesn't require atomicity of 8 byte
+// moves.
+
+void
+gomemmove (void *dst, void *src, uintptr len)
+{
+#if !defined(__PPC64__)
+  __builtin_memmove(dst, src, len);
+#else
+  uint64 offset, tail;
+  int64 rem;
+  uint64 dwords;
+  uint64 i;
+  char *bdst,*bsrc;
+
+  rem = len;
+
+  if (len == 0) {
+   return;
+  }
+
+  // If src and dst don't have the same 8 byte alignment then
+  // there is no issue with copying pointer atomicity. Use the
+  // builtin.
+  if (((uint64)dst % 8) != ((uint64)src % 8) || len < 8) {
+   __builtin_memmove(dst, src, len);
+   return;
+  }
+
+  // Length >= 8 && same ptr alignment
+  offset = (uint64)dst % 8;
+
+  // If not 8 byte alignment, move the intial bytes.
+  if (offset > 0) {
+   __builtin_memmove(dst, src, 8-offset);
+   dst += (8-offset);
+   src += (8-offset);
+   rem -= (8-offset);
+  }
+
+  // Move the tail bytes to make the backward move
+  // easier.
+  tail = rem % 8;
+  if (tail > 0) {
+   __builtin_memmove(dst+rem-tail, src+rem-tail, tail);
+   rem -= tail;
+  }
+
+  if (rem == 0) {
+   return;
+  }
+
+  // Must now be 8 byte alignment and r

libbacktrace patch committed: Pass -1 to error callback for unknown DWARF

2021-03-02 Thread Ian Lance Taylor via Gcc-patches
This libbacktrace patch passes -1 to the error callback function for
unknown DWARF versions.  This makes users of libbacktrace treat DWARF
versions that libbacktrace does not support as though no debug
information were available.  This fixes PR 98818.  Bootstrapped and
ran libbacktrace tests on x86_64-pc-linux-gnu.  Committed to mainline.

Ian

* dwarf.c (dwarf_buf_error): Add errnum parameter.  Change all
callers.
* backtrace.h: Update backtrace_error_callback comment.
df003d1e0bf2d0a8e2ed45a323d4e974b15dc95f
diff --git a/libbacktrace/backtrace.h b/libbacktrace/backtrace.h
index 2814763f417..caaa66d3686 100644
--- a/libbacktrace/backtrace.h
+++ b/libbacktrace/backtrace.h
@@ -71,13 +71,14 @@ struct backtrace_state;
invalid after this function returns.
 
As a special case, the ERRNUM argument will be passed as -1 if no
-   debug info can be found for the executable, but the function
-   requires debug info (e.g., backtrace_full, backtrace_pcinfo).  The
-   MSG in this case will be something along the lines of "no debug
-   info".  Similarly, ERRNUM will be passed as -1 if there is no
-   symbol table, but the function requires a symbol table (e.g.,
-   backtrace_syminfo).  This may be used as a signal that some other
-   approach should be tried.  */
+   debug info can be found for the executable, or if the debug info
+   exists but has an unsupported version, but the function requires
+   debug info (e.g., backtrace_full, backtrace_pcinfo).  The MSG in
+   this case will be something along the lines of "no debug info".
+   Similarly, ERRNUM will be passed as -1 if there is no symbol table,
+   but the function requires a symbol table (e.g., backtrace_syminfo).
+   This may be used as a signal that some other approach should be
+   tried.  */
 
 typedef void (*backtrace_error_callback) (void *data, const char *msg,
  int errnum);
diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c
index 9097df6cc76..546b4b26a32 100644
--- a/libbacktrace/dwarf.c
+++ b/libbacktrace/dwarf.c
@@ -410,13 +410,13 @@ struct dwarf_data
 /* Report an error for a DWARF buffer.  */
 
 static void
-dwarf_buf_error (struct dwarf_buf *buf, const char *msg)
+dwarf_buf_error (struct dwarf_buf *buf, const char *msg, int errnum)
 {
   char b[200];
 
   snprintf (b, sizeof b, "%s in %s at %d",
msg, buf->name, (int) (buf->buf - buf->start));
-  buf->error_callback (buf->data, b, 0);
+  buf->error_callback (buf->data, b, errnum);
 }
 
 /* Require at least COUNT bytes in BUF.  Return 1 if all is well, 0 on
@@ -430,7 +430,7 @@ require (struct dwarf_buf *buf, size_t count)
 
   if (!buf->reported_underflow)
 {
-  dwarf_buf_error (buf, "DWARF underflow");
+  dwarf_buf_error (buf, "DWARF underflow", 0);
   buf->reported_underflow = 1;
 }
 
@@ -592,7 +592,7 @@ read_address (struct dwarf_buf *buf, int addrsize)
 case 8:
   return read_uint64 (buf);
 default:
-  dwarf_buf_error (buf, "unrecognized address size");
+  dwarf_buf_error (buf, "unrecognized address size", 0);
   return 0;
 }
 }
@@ -643,7 +643,7 @@ read_uleb128 (struct dwarf_buf *buf)
ret |= ((uint64_t) (b & 0x7f)) << shift;
   else if (!overflow)
{
- dwarf_buf_error (buf, "LEB128 overflows uint64_t");
+ dwarf_buf_error (buf, "LEB128 overflows uint64_t", 0);
  overflow = 1;
}
   shift += 7;
@@ -678,7 +678,7 @@ read_sleb128 (struct dwarf_buf *buf)
val |= ((uint64_t) (b & 0x7f)) << shift;
   else if (!overflow)
{
- dwarf_buf_error (buf, "signed LEB128 overflows uint64_t");
+ dwarf_buf_error (buf, "signed LEB128 overflows uint64_t", 0);
  overflow = 1;
}
   shift += 7;
@@ -818,7 +818,7 @@ read_attribute (enum dwarf_form form, uint64_t implicit_val,
offset = read_offset (buf, is_dwarf64);
if (offset >= dwarf_sections->size[DEBUG_STR])
  {
-   dwarf_buf_error (buf, "DW_FORM_strp out of range");
+   dwarf_buf_error (buf, "DW_FORM_strp out of range", 0);
return 0;
  }
val->encoding = ATTR_VAL_STRING;
@@ -833,7 +833,7 @@ read_attribute (enum dwarf_form form, uint64_t implicit_val,
offset = read_offset (buf, is_dwarf64);
if (offset >= dwarf_sections->size[DEBUG_LINE_STR])
  {
-   dwarf_buf_error (buf, "DW_FORM_line_strp out of range");
+   dwarf_buf_error (buf, "DW_FORM_line_strp out of range", 0);
return 0;
  }
val->encoding = ATTR_VAL_STRING;
@@ -880,7 +880,8 @@ read_attribute (enum dwarf_form form, uint64_t implicit_val,
if (form == DW_FORM_implicit_const)
  {
dwarf_buf_error (buf,
-"DW_FORM_indirect to DW_FORM_implicit_const");
+"DW_FORM_indirect to DW_FORM_implicit_const",
+0);
return 0;
  }
return read_at

Go patch committed: All go:embed with import _ "embed"

2021-03-02 Thread Ian Lance Taylor via Gcc-patches
This patch by Michael Matloob fixes the Go frontend to permit
//go:embed comments in files that do
import _ "embed"

The embed spec allows for //go:embed to be used in files that
underscore-import package "embed".  This is useful for embeds to
[]byte and string vars because the embed.FS type may not be referenced
if those are the only types of embeds in a file.  Because the compiler
previously checked whether there were any aliases to the embed package
to decide if //go:embed could be used, it would reject files with only
underscore imports of embed.  Instead, record whether the embed import
is encountered at all, similar to what is done with unsafe, to decide
whether //go:embed is allowed.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
d1776b7757001d9da47efcfd64d3bb20afb8d96d
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 9806b9da1e1..5c9fc7db4e1 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-56cf388da8d04bbd3824c4df34d77a8afa69749b
+2c5188b5ad6143e791f2ba42f02a4ea7887d87b6
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/embed.cc b/gcc/go/gofrontend/embed.cc
index 0a7df0531ec..0584f707ce6 100644
--- a/gcc/go/gofrontend/embed.cc
+++ b/gcc/go/gofrontend/embed.cc
@@ -663,21 +663,6 @@ Embedcfg_reader::error(const char* msg)
this->filename_, msg);
 }
 
-// Return whether the current file imports "embed".
-
-bool
-Gogo::is_embed_imported() const
-{
-  Packages::const_iterator p = this->packages_.find("embed");
-  if (p == this->packages_.end())
-return false;
-
-  // We track current file imports in the package aliases, where a
-  // typical import will just list the package name in aliases.  So
-  // the package has been imported if there is at least one alias.
-  return !p->second->aliases().empty();
-}
-
 // Implement the sort order for a list of embedded files, as discussed
 // at the docs for embed.FS.
 
diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc
index 38a2f6f8f9e..9d4150eff7c 100644
--- a/gcc/go/gofrontend/gogo.cc
+++ b/gcc/go/gofrontend/gogo.cc
@@ -37,6 +37,7 @@ Gogo::Gogo(Backend* backend, Linemap* linemap, int, int 
pointer_size)
 imports_(),
 imported_unsafe_(false),
 current_file_imported_unsafe_(false),
+current_file_imported_embed_(false),
 packages_(),
 init_functions_(),
 var_deps_(),
@@ -469,6 +470,9 @@ Gogo::import_package(const std::string& filename,
   return;
 }
 
+  if (filename == "embed")
+this->current_file_imported_embed_ = true;
+
   Imports::const_iterator p = this->imports_.find(filename);
   if (p != this->imports_.end())
 {
@@ -2717,6 +2721,7 @@ Gogo::clear_file_scope()
 }
 
   this->current_file_imported_unsafe_ = false;
+  this->current_file_imported_embed_ = false;
 }
 
 // Queue up a type-specific hash function for later writing.  These
diff --git a/gcc/go/gofrontend/gogo.h b/gcc/go/gofrontend/gogo.h
index 51b6575ba47..f4155a29edb 100644
--- a/gcc/go/gofrontend/gogo.h
+++ b/gcc/go/gofrontend/gogo.h
@@ -397,10 +397,6 @@ class Gogo
   void
   read_embedcfg(const char* filename);
 
-  // Return whether the current file imports "embed".
-  bool
-  is_embed_imported() const;
-
   // Build an initializer for a variable with a go:embed directive.
   Expression*
   initializer_for_embeds(Type*, const std::vector*, Location);
@@ -709,6 +705,11 @@ class Gogo
   current_file_imported_unsafe() const
   { return this->current_file_imported_unsafe_; }
 
+  // Return whether the current file imported the embed package.
+  bool
+  current_file_imported_embed() const
+  { return this->current_file_imported_embed_; }
+
   // Clear out all names in file scope.  This is called when we start
   // parsing a new file.
   void
@@ -1251,6 +1252,8 @@ class Gogo
   bool imported_unsafe_;
   // Whether the magic unsafe package was imported by the current file.
   bool current_file_imported_unsafe_;
+  // Whether the embed package was imported by the current file.
+  bool current_file_imported_embed_;
   // Mapping from package names we have seen to packages.  This does
   // not include the package we are compiling.
   Packages packages_;
diff --git a/gcc/go/gofrontend/parse.cc b/gcc/go/gofrontend/parse.cc
index fd81a85c87f..e43b5f21448 100644
--- a/gcc/go/gofrontend/parse.cc
+++ b/gcc/go/gofrontend/parse.cc
@@ -1321,7 +1321,7 @@ Parse::declaration()
   embeds = new(std::vector);
   this->lex_->get_and_clear_embeds(embeds);
 
-  if (!this->gogo_->is_embed_imported())
+  if (!this->gogo_->current_file_imported_embed())
{
  go_error_at(token->location(),
  "invalid go:embed: missing import %");


libbacktrace patch committed: Don't special case file 0

2021-03-02 Thread Ian Lance Taylor via Gcc-patches
This libbacktrace patch stops special casing file 0.  It's no longer
necessary as for DWARF 5 support we now set up filename 0 in all
cases.  Bootstrapped and ran libbacktrace and Go tests on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian

* dwarf.c (read_line_program): Don't special case file 0.
(read_function_entry): Likewise.
b3176ab8787a7f988a931e26bce9227edd2e6d1a
diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c
index 546b4b26a32..e6b1f238cd3 100644
--- a/libbacktrace/dwarf.c
+++ b/libbacktrace/dwarf.c
@@ -2857,20 +2857,15 @@ read_line_program (struct backtrace_state *state, 
struct dwarf_data *ddata,
uint64_t fileno;
 
fileno = read_uleb128 (line_buf);
-   if (fileno == 0)
- filename = "";
-   else
+   if (fileno >= hdr->filenames_count)
  {
-   if (fileno >= hdr->filenames_count)
- {
-   dwarf_buf_error (line_buf,
-("invalid file number in "
- "line number program"),
-0);
-   return 0;
- }
-   filename = hdr->filenames[fileno];
+   dwarf_buf_error (line_buf,
+("invalid file number in "
+ "line number program"),
+0);
+   return 0;
  }
+   filename = hdr->filenames[fileno];
  }
  break;
case DW_LNS_set_column:
@@ -3298,21 +3293,15 @@ read_function_entry (struct backtrace_state *state, 
struct dwarf_data *ddata,
case DW_AT_call_file:
  if (val.encoding == ATTR_VAL_UINT)
{
- if (val.u.uint == 0)
-   function->caller_filename = "";
- else
+ if (val.u.uint >= lhdr->filenames_count)
{
- if (val.u.uint >= lhdr->filenames_count)
-   {
- dwarf_buf_error (unit_buf,
-  ("invalid file number in "
-   "DW_AT_call_file attribute"),
-  0);
- return 0;
-   }
- function->caller_filename =
-   lhdr->filenames[val.u.uint];
+ dwarf_buf_error (unit_buf,
+  ("invalid file number in "
+   "DW_AT_call_file attribute"),
+  0);
+ return 0;
}
+ function->caller_filename = lhdr->filenames[val.u.uint];
}
  break;
 


libgo patch committed: Cast SIGSTKSZ to uintptr

2021-03-08 Thread Ian Lance Taylor via Gcc-patches
This libgo patch casts SIGSTKSZ to uintptr before comparing it to a
uintptr value.  This fixes build failures with newer versions of glibc
in which SIGSTKSZ has changed such that the type is now long.  The
build failure is a signed-unsigned comparison warning that turns into
an error due to -Werror.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline and GCC 9 and 10 branches.

Ian
d03d1688cebc0985aac189bcf6f46089044056ad
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 5c9fc7db4e1..5b45f03a26e 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-2c5188b5ad6143e791f2ba42f02a4ea7887d87b6
+93380a9126e76b71fa208e62c31c7914084c0e37
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/runtime/proc.c b/libgo/runtime/proc.c
index c037df645b9..38bf7a6b255 100644
--- a/libgo/runtime/proc.c
+++ b/libgo/runtime/proc.c
@@ -802,8 +802,8 @@ runtime_malg(bool allocatestack, bool signalstack, byte** 
ret_stack, uintptr* re
if(signalstack) {
stacksize = 32 * 1024; // OS X wants >= 8K, GNU/Linux 
>= 2K
 #ifdef SIGSTKSZ
-   if(stacksize < SIGSTKSZ)
-   stacksize = SIGSTKSZ;
+   if(stacksize < (uintptr)(SIGSTKSZ))
+   stacksize = (uintptr)(SIGSTKSZ);
 #endif
}
 


Go patch committed: Support unsafe.Add and unsafe.Slice

2021-08-02 Thread Ian Lance Taylor via Gcc-patches
The upcoming Go 1.17 release adds two new functions to the unsafe
package: unsafe.Add and unsafe.Slice.  These functions must be
implemented in the compiler.  This patch implements them for gccgo.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
06d0437d4a5faca2b695918cbe1d54a61935c98b
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 5323e186eab..19fbd647840 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-920549b6382a2623538d31001271941f0e9e5a51
+ad667e7c70cea9fa5730660d72ad891b5753eb62
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index a0472acc209..46e71e5a13b 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -8252,12 +8252,16 @@ Builtin_call_expression::Builtin_call_expression(Gogo* 
gogo,
 this->code_ = BUILTIN_REAL;
   else if (name == "recover")
 this->code_ = BUILTIN_RECOVER;
+  else if (name == "Add")
+this->code_ = BUILTIN_ADD;
   else if (name == "Alignof")
 this->code_ = BUILTIN_ALIGNOF;
   else if (name == "Offsetof")
 this->code_ = BUILTIN_OFFSETOF;
   else if (name == "Sizeof")
 this->code_ = BUILTIN_SIZEOF;
+  else if (name == "Slice")
+this->code_ = BUILTIN_SLICE;
   else
 go_unreachable();
 }
@@ -8694,6 +8698,119 @@ Builtin_call_expression::do_flatten(Gogo* gogo, 
Named_object* function,
 
 return Runtime::make_call(code, loc, 3, e1, e2, e3);
   }
+
+case BUILTIN_ADD:
+  {
+   Expression* ptr = this->args()->front();
+   Type* uintptr_type = Type::lookup_integer_type("uintptr");
+   ptr = Expression::make_cast(uintptr_type, ptr, loc);
+   Expression* len = this->args()->back();
+   len = Expression::make_cast(uintptr_type, len, loc);
+   Expression* add = Expression::make_binary(OPERATOR_PLUS, ptr, len,
+ loc);
+   return Expression::make_cast(this->args()->front()->type(), add, loc);
+  }
+
+case BUILTIN_SLICE:
+  {
+   Expression* ptr = this->args()->front();
+   Temporary_statement* ptr_temp = NULL;
+   if (!ptr->is_multi_eval_safe())
+ {
+   ptr_temp = Statement::make_temporary(NULL, ptr, loc);
+   inserter->insert(ptr_temp);
+   ptr = Expression::make_temporary_reference(ptr_temp, loc);
+ }
+
+   Expression* len = this->args()->back();
+   Temporary_statement* len_temp = NULL;
+   if (!len->is_multi_eval_safe())
+ {
+   len_temp = Statement::make_temporary(NULL, len, loc);
+   inserter->insert(len_temp);
+   len = Expression::make_temporary_reference(len_temp, loc);
+ }
+
+   bool fits_in_int;
+   Numeric_constant nc;
+   if (this->args()->back()->numeric_constant_value(&nc))
+ {
+   // We gave an error for constants that don't fit in int in
+   // check_types.
+   fits_in_int = true;
+ }
+   else
+ {
+   Integer_type* itype = this->args()->back()->type()->integer_type();
+   go_assert(itype != NULL);
+   int ebits = itype->bits();
+   int intbits =
+ Type::lookup_integer_type("int")->integer_type()->bits();
+
+   // We can treat ebits == intbits as small even for an
+   // unsigned integer type, because we will convert the
+   // value to int and then reject it in the runtime if it is
+   // negative.
+
+   fits_in_int = ebits <= intbits;
+ }
+
+   Runtime::Function code = (fits_in_int
+ ? Runtime::UNSAFESLICE
+ : Runtime::UNSAFESLICE64);
+   Expression* td =
+ Expression::make_type_descriptor(ptr->type()->points_to(), loc);
+   Expression* check = Runtime::make_call(code, loc, 3,
+  td, ptr, len);
+
+   if (ptr_temp == NULL)
+ ptr = ptr->copy();
+   else
+ ptr = Expression::make_temporary_reference(ptr_temp, loc);
+   Expression* nil = Expression::make_nil(loc);
+   nil = Expression::make_cast(ptr->type(), nil, loc);
+   Expression* is_nil = Expression::make_binary(OPERATOR_EQEQ, ptr, nil,
+loc);
+
+   if (len_temp == NULL)
+ len = len->copy();
+   else
+ len = Expression::make_temporary_reference(len_temp, loc);
+   Expression* zero = Expression::make_integer_ul(0, len->type(), loc);
+   Expression* is_zero = Expression::make_binary(OPERATOR_EQEQ, len, zero,
+ loc);
+
+   Expression* cond = Expression::make_binary(OPERATOR_ANDAND, is_nil,
+  is_zero, loc);
+
+  

Go patch committed: Allow converting from slice to pointer-to-array

2021-08-02 Thread Ian Lance Taylor via Gcc-patches
The upcoming Go 1.17 release has a new language feature: it permits
conversions from slice types to pointer-to-array types.  If the slice
is too short, the conversion panics.  This patch implements this new
feature in gccgo.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
7459bfa8a37a4fbd6ed5153bff76f49d372b4ace
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 19fbd647840..95b9340b42d 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-ad667e7c70cea9fa5730660d72ad891b5753eb62
+0a4d612e6b211780b294717503fc739bbd1f509c
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 46e71e5a13b..15c9eabc6bf 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -3866,11 +3866,12 @@ Type_conversion_expression::do_traverse(Traverse* 
traverse)
   return TRAVERSE_CONTINUE;
 }
 
-// Convert to a constant at lowering time.
+// Convert to a constant at lowering time.  Also lower conversions
+// from slice to pointer-to-array, as they can panic.
 
 Expression*
 Type_conversion_expression::do_lower(Gogo*, Named_object*,
-Statement_inserter*, int)
+Statement_inserter* inserter, int)
 {
   Type* type = this->type_;
   Expression* val = this->expr_;
@@ -3958,6 +3959,54 @@ Type_conversion_expression::do_lower(Gogo*, 
Named_object*,
}
 }
 
+  if (type->points_to() != NULL
+  && type->points_to()->array_type() != NULL
+  && !type->points_to()->is_slice_type()
+  && val->type()->is_slice_type())
+{
+  Temporary_statement* val_temp = NULL;
+  if (!val->is_multi_eval_safe())
+   {
+ val_temp = Statement::make_temporary(val->type(), NULL, location);
+ inserter->insert(val_temp);
+ val = Expression::make_set_and_use_temporary(val_temp, val,
+  location);
+   }
+
+  Type* int_type = Type::lookup_integer_type("int");
+  Temporary_statement* vallen_temp =
+   Statement::make_temporary(int_type, NULL, location);
+  inserter->insert(vallen_temp);
+
+  Expression* arrlen = type->points_to()->array_type()->length();
+  Expression* vallen =
+   Expression::make_slice_info(val, Expression::SLICE_INFO_LENGTH,
+   location);
+  vallen = Expression::make_set_and_use_temporary(vallen_temp, vallen,
+ location);
+  Expression* cond = Expression::make_binary(OPERATOR_GT, arrlen, vallen,
+location);
+
+  vallen = Expression::make_temporary_reference(vallen_temp, location);
+  Expression* panic = Runtime::make_call(Runtime::PANIC_SLICE_CONVERT,
+location, 2, arrlen, vallen);
+
+  Expression* nil = Expression::make_nil(location);
+  Expression* check = Expression::make_conditional(cond, panic, nil,
+  location);
+
+  if (val_temp == NULL)
+   val = val->copy();
+  else
+   val = Expression::make_temporary_reference(val_temp, location);
+  Expression* ptr =
+   Expression::make_slice_info(val, Expression::SLICE_INFO_VALUE_POINTER,
+   location);
+  ptr = Expression::make_unsafe_cast(type, ptr, location);
+
+  return Expression::make_compound(check, ptr, location);
+}
+
   return this;
 }
 
diff --git a/gcc/go/gofrontend/runtime.def b/gcc/go/gofrontend/runtime.def
index 231d92d2661..fad8cebc012 100644
--- a/gcc/go/gofrontend/runtime.def
+++ b/gcc/go/gofrontend/runtime.def
@@ -582,6 +582,11 @@ DEF_GO_RUNTIME(PANIC_EXTEND_SLICE3_C, 
"runtime.goPanicExtendSlice3C",
 DEF_GO_RUNTIME(PANIC_EXTEND_SLICE3_C_U, "runtime.goPanicExtendSlice3CU",
   P2(UINT64, INT), R0())
 
+// Panic for conversion of slice to pointer-to-array if the slice is
+// too short.
+DEF_GO_RUNTIME(PANIC_SLICE_CONVERT, "runtime.goPanicSliceConvert",
+  P2(INT, INT), R0())
+
 // Remove helper macros.
 #undef ABFT6
 #undef ABFT2
diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc
index ab7166b8b1b..7c7b2eb8271 100644
--- a/gcc/go/gofrontend/types.cc
+++ b/gcc/go/gofrontend/types.cc
@@ -842,6 +842,13 @@ Type::are_convertible(const Type* lhs, const Type* rhs, 
std::string* reason)
return true;
 }
 
+  // A slice may be converted to a pointer-to-array.
+  if (rhs->is_slice_type()
+  && lhs->points_to() != NULL
+  && lhs->points_to()->array_type() != NULL
+  && !lhs->points_to()->is_slice_type())
+return true;
+
   // An unsafe.Pointer type may be converted to any pointer type or to
   // a type whose underlying type is uintptr, and v

Re: Go patch committed: Allow converting from slice to pointer-to-array

2021-08-03 Thread Ian Lance Taylor via Gcc-patches
On Mon, Aug 2, 2021 at 3:53 PM Ian Lance Taylor  wrote:
>
> The upcoming Go 1.17 release has a new language feature: it permits
> conversions from slice types to pointer-to-array types.  If the slice
> is too short, the conversion panics.  This patch implements this new
> feature in gccgo.  Bootstrapped and ran Go testsuite on
> x86_64-pc-linux-gnu.  Committed to mainline.

I didn't get the type checking right: I forgot to check that the
element types of the slice and array are identical.  Fixed with this
patches.  Bootstrapped and tested on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
7ff2742eacee93c7e7d9262d07c2496f87d801a7
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 95b9340b42d..801e039a155 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-0a4d612e6b211780b294717503fc739bbd1f509c
+54361805bd611d896042b879ee7f6d2d4d088537
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 15c9eabc6bf..51a8b7e4322 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -3962,7 +3962,10 @@ Type_conversion_expression::do_lower(Gogo*, 
Named_object*,
   if (type->points_to() != NULL
   && type->points_to()->array_type() != NULL
   && !type->points_to()->is_slice_type()
-  && val->type()->is_slice_type())
+  && val->type()->is_slice_type()
+  && Type::are_identical(type->points_to()->array_type()->element_type(),
+val->type()->array_type()->element_type(),
+0, NULL))
 {
   Temporary_statement* val_temp = NULL;
   if (!val->is_multi_eval_safe())
diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc
index 7c7b2eb8271..0c44186f507 100644
--- a/gcc/go/gofrontend/types.cc
+++ b/gcc/go/gofrontend/types.cc
@@ -846,7 +846,9 @@ Type::are_convertible(const Type* lhs, const Type* rhs, 
std::string* reason)
   if (rhs->is_slice_type()
   && lhs->points_to() != NULL
   && lhs->points_to()->array_type() != NULL
-  && !lhs->points_to()->is_slice_type())
+  && !lhs->points_to()->is_slice_type()
+  && Type::are_identical(lhs->points_to()->array_type()->element_type(),
+rhs->array_type()->element_type(), 0, reason))
 return true;
 
   // An unsafe.Pointer type may be converted to any pointer type or to


Go patch committed: Return two values from selectnbrecv

2021-08-03 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend and libgo changes selectnbrecv to return
two values.  The only difference between selectnbrecv and
selectnbrecv2 is that the latter uses a pointer argument as the second
return value from chanrecv.  This patch changes selectnbrecv to return
the two values from chanrecv and gets
rid of selectnbrecv2.  The compiler now calls only selectnbrecv, which
is simpler.

This is the gofrontend version of https://golang.org/cl/292890.  I'm
committing it now as part of updating to the Go 1.17 release.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
e435e72ad713cadd661072427588ec1c777c04e3
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 801e039a155..5a097ffee85 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-54361805bd611d896042b879ee7f6d2d4d088537
+2031f0be9c0b5fda6421d290a0261eb6bd1c8205
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/runtime.def b/gcc/go/gofrontend/runtime.def
index fad8cebc012..87a27085d60 100644
--- a/gcc/go/gofrontend/runtime.def
+++ b/gcc/go/gofrontend/runtime.def
@@ -204,12 +204,8 @@ DEF_GO_RUNTIME(SELECTNBSEND, "runtime.selectnbsend", 
P2(CHAN, POINTER), R1(BOOL)
 
 // Non-blocking receive a value from a channel, used for two-case select
 // statement with a default case.
-DEF_GO_RUNTIME(SELECTNBRECV, "runtime.selectnbrecv", P2(POINTER, CHAN), 
R1(BOOL))
-
-// Non-blocking tuple receive from a channel, used for two-case select
-// statement with a default case.
-DEF_GO_RUNTIME(SELECTNBRECV2, "runtime.selectnbrecv2", P3(POINTER, POINTER, 
CHAN),
-   R1(BOOL))
+DEF_GO_RUNTIME(SELECTNBRECV, "runtime.selectnbrecv", P2(POINTER, CHAN),
+  R2(BOOL, BOOL))
 
 // Block execution.  Used for zero-case select.
 DEF_GO_RUNTIME(BLOCK, "runtime.block", P0(), R0())
diff --git a/gcc/go/gofrontend/statements.cc b/gcc/go/gofrontend/statements.cc
index 9643d1b42b3..95fa3c48709 100644
--- a/gcc/go/gofrontend/statements.cc
+++ b/gcc/go/gofrontend/statements.cc
@@ -6051,7 +6051,7 @@ Select_statement::lower_two_case(Block* b)
   Expression* chanref = Expression::make_temporary_reference(chantmp, loc);
 
   Block* bchan;
-  Expression* call;
+  Expression* cond;
   if (chancase.is_send())
 {
   // if selectnbsend(chan, &val) { body } else { default body }
@@ -6065,7 +6065,7 @@ Select_statement::lower_two_case(Block* b)
 
   Expression* ref = Expression::make_temporary_reference(ts, loc);
   Expression* addr = Expression::make_unary(OPERATOR_AND, ref, loc);
-  call = Runtime::make_call(Runtime::SELECTNBSEND, loc, 2, chanref, addr);
+  cond = Runtime::make_call(Runtime::SELECTNBSEND, loc, 2, chanref, addr);
   bchan = chancase.statements();
 }
   else
@@ -6075,34 +6075,31 @@ Select_statement::lower_two_case(Block* b)
 
   Expression* ref = Expression::make_temporary_reference(ts, loc);
   Expression* addr = Expression::make_unary(OPERATOR_AND, ref, loc);
-  Expression* okref = NULL;
-  if (chancase.closed() == NULL && chancase.closedvar() == NULL)
-{
-  // Simple receive.
-  // if selectnbrecv(&lhs, chan) { body } else { default body }
-  call = Runtime::make_call(Runtime::SELECTNBRECV, loc, 2, addr, 
chanref);
-}
-  else
-{
-  // Tuple receive.
-  // if selectnbrecv2(&lhs, &ok, chan) { body } else { default body }
-
-  Type* booltype = Type::make_boolean_type();
-  Temporary_statement* okts = Statement::make_temporary(booltype, NULL,
-loc);
-  b->add_statement(okts);
-
-  okref = Expression::make_temporary_reference(okts, loc);
-  Expression* okaddr = Expression::make_unary(OPERATOR_AND, okref, 
loc);
-  call = Runtime::make_call(Runtime::SELECTNBRECV2, loc, 3, addr, 
okaddr,
-chanref);
-}
+
+  // selected, ok = selectnbrecv(&lhs, chan)
+  Call_expression* call = Runtime::make_call(Runtime::SELECTNBRECV, loc, 2,
+addr, chanref);
+
+  Temporary_statement* selected_temp =
+   Statement::make_temporary(Type::make_boolean_type(),
+ Expression::make_call_result(call, 0),
+ loc);
+  b->add_statement(selected_temp);
+
+  Temporary_statement* ok_temp =
+   Statement::make_temporary(Type::make_boolean_type(),
+ Expression::make_call_result(call, 1),
+ loc);
+  b->add_statement(ok_temp);
+
+  cond = Expression::make_temporary_reference(selected_temp, loc);
 
   Location cloc = chancase.location();
   bchan = new Block(b, loc);
   if (chancase.val() != NULL && !chancase.val()->is_sink_expression())

Go patch committed: Support new language constructs in escape analysis

2021-08-03 Thread Ian Lance Taylor via Gcc-patches
This Go frontend patch by Cherry Mui supports the new language
constructs in escape analysis.  Previous patches added new language
constructs in Go 1.17, specifically, unsafe.Add, unsafe.Slice, and
conversion from a slice to a pointer
to an array. This patch handles them in the escape analysis.

At the point of the escape analysis, unsafe.Add and unsafe.Slice are
still builtin calls, so just handle them in data flow.  Conversion
from a slice to a pointer to an array has already been lowered to a
combination of compound expression, conditional expression and slice
info expressions, so handle them in the escape analysis.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
98b3c98f4acd7d6f74d0f6ad592a7623ebafecd4
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 5a097ffee85..be1a90f7aa1 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-2031f0be9c0b5fda6421d290a0261eb6bd1c8205
+616ee658a6238e7de53592ebda5997f6de6a00de
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/escape.cc b/gcc/go/gofrontend/escape.cc
index cf688740443..347ac2534c9 100644
--- a/gcc/go/gofrontend/escape.cc
+++ b/gcc/go/gofrontend/escape.cc
@@ -2325,19 +2325,55 @@ Escape_analysis_assign::assign(Node* dst, Node* src)
  }
  break;
 
+case Expression::EXPRESSION_SLICE_INFO:
+  {
+Slice_info_expression* sie = e->slice_info_expression();
+if (sie->info() == Expression::SLICE_INFO_VALUE_POINTER)
+  {
+Node* slice = Node::make_node(sie->slice());
+this->assign(dst, slice);
+  }
+  }
+  break;
+
case Expression::EXPRESSION_CALL:
  {
Call_expression* call = e->call_expression();
 if (call->is_builtin())
   {
 Builtin_call_expression* bce = call->builtin_call_expression();
-if (bce->code() == Builtin_call_expression::BUILTIN_APPEND)
+switch (bce->code())
   {
-// Append returns the first argument.
-// The subsequent arguments are already leaked because
-// they are operands to append.
-Node* appendee = Node::make_node(call->args()->front());
-this->assign(dst, appendee);
+  case Builtin_call_expression::BUILTIN_APPEND:
+{
+  // Append returns the first argument.
+  // The subsequent arguments are already leaked because
+  // they are operands to append.
+  Node* appendee = Node::make_node(call->args()->front());
+  this->assign(dst, appendee);
+}
+break;
+
+  case Builtin_call_expression::BUILTIN_ADD:
+{
+  // unsafe.Add(p, off).
+  // Flow p to result.
+  Node* arg = Node::make_node(call->args()->front());
+  this->assign(dst, arg);
+}
+break;
+
+  case Builtin_call_expression::BUILTIN_SLICE:
+{
+  // unsafe.Slice(p, len).
+  // The resulting slice has the same backing store as p. 
Flow p to result.
+  Node* arg = Node::make_node(call->args()->front());
+  this->assign(dst, arg);
+}
+break;
+
+  default:
+break;
   }
 break;
   }
@@ -2592,6 +2628,21 @@ Escape_analysis_assign::assign(Node* dst, Node* src)
  }
  break;
 
+case Expression::EXPRESSION_CONDITIONAL:
+  {
+Conditional_expression* ce = e->conditional_expression();
+this->assign(dst, Node::make_node(ce->then_expr()));
+this->assign(dst, Node::make_node(ce->else_expr()));
+  }
+  break;
+
+case Expression::EXPRESSION_COMPOUND:
+  {
+Compound_expression* ce = e->compound_expression();
+this->assign(dst, Node::make_node(ce->expr()));
+  }
+  break;
+
default:
  // TODO(cmang): Add debug info here; this should not be reachable.
  // For now, just to be conservative, we'll just say dst flows to src.
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 51a8b7e4322..3e433d6c20d 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -18009,49 +18009,7 @@ Expression::make_type_info(Type* type, Type_info 
type_info)
   return new Type_info_expression(type, type_info);
 }
 
-// An expression that e

Go patch committed: Be strict about escape analysis of builtin functions

2021-08-04 Thread Ian Lance Taylor via Gcc-patches
This Go frontend patch by Cherry Mui makes the escape analysis pass
stricter about builtin functions  In the places where we handle
builtin functions, list all supported ones, and fail if an unexpected
one is seen. So if a new builtin function is added in the future we
can detect it, instead of silently treating it as nonescaping.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
5b720746d8456986f4bb6b53d30b462f93ff58c4
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index be1a90f7aa1..394530c1cbc 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-616ee658a6238e7de53592ebda5997f6de6a00de
+b47bcf942daa9a0c252db9b57b8f138adbfcdaa2
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/escape.cc b/gcc/go/gofrontend/escape.cc
index 347ac2534c9..c8978ac9239 100644
--- a/gcc/go/gofrontend/escape.cc
+++ b/gcc/go/gofrontend/escape.cc
@@ -1608,8 +1608,33 @@ Escape_analysis_assign::expression(Expression** pexpr)
 }
 break;
 
-  default:
+  case Builtin_call_expression::BUILTIN_CLOSE:
+  case Builtin_call_expression::BUILTIN_DELETE:
+  case Builtin_call_expression::BUILTIN_PRINT:
+  case Builtin_call_expression::BUILTIN_PRINTLN:
+  case Builtin_call_expression::BUILTIN_LEN:
+  case Builtin_call_expression::BUILTIN_CAP:
+  case Builtin_call_expression::BUILTIN_COMPLEX:
+  case Builtin_call_expression::BUILTIN_REAL:
+  case Builtin_call_expression::BUILTIN_IMAG:
+  case Builtin_call_expression::BUILTIN_RECOVER:
+  case Builtin_call_expression::BUILTIN_ALIGNOF:
+  case Builtin_call_expression::BUILTIN_OFFSETOF:
+  case Builtin_call_expression::BUILTIN_SIZEOF:
+// these do not escape.
+break;
+
+  case Builtin_call_expression::BUILTIN_ADD:
+  case Builtin_call_expression::BUILTIN_SLICE:
+// handled in ::assign.
 break;
+
+  case Builtin_call_expression::BUILTIN_MAKE:
+  case Builtin_call_expression::BUILTIN_NEW:
+// should have been lowered to runtime calls at this point.
+// fallthrough
+  default:
+go_unreachable();
   }
 break;
   }
@@ -2372,8 +2397,35 @@ Escape_analysis_assign::assign(Node* dst, Node* src)
 }
 break;
 
-  default:
+  case Builtin_call_expression::BUILTIN_LEN:
+  case Builtin_call_expression::BUILTIN_CAP:
+  case Builtin_call_expression::BUILTIN_COMPLEX:
+  case Builtin_call_expression::BUILTIN_REAL:
+  case Builtin_call_expression::BUILTIN_IMAG:
+  case Builtin_call_expression::BUILTIN_RECOVER:
+  case Builtin_call_expression::BUILTIN_ALIGNOF:
+  case Builtin_call_expression::BUILTIN_OFFSETOF:
+  case Builtin_call_expression::BUILTIN_SIZEOF:
+// these do not escape.
+break;
+
+  case Builtin_call_expression::BUILTIN_COPY:
+// handled in ::expression.
 break;
+
+  case Builtin_call_expression::BUILTIN_CLOSE:
+  case Builtin_call_expression::BUILTIN_DELETE:
+  case Builtin_call_expression::BUILTIN_PRINT:
+  case Builtin_call_expression::BUILTIN_PRINTLN:
+  case Builtin_call_expression::BUILTIN_PANIC:
+// these do not have result.
+// fallthrough
+  case Builtin_call_expression::BUILTIN_MAKE:
+  case Builtin_call_expression::BUILTIN_NEW:
+// should have been lowered to runtime calls at this point.
+// fallthrough
+  default:
+go_unreachable();
   }
 break;
   }


Go patch committed: extend runtime/internal/atomic to sync/atomic

2021-08-05 Thread Ian Lance Taylor via Gcc-patches
This Go patch extends the internal runtime/internal/atomic package to
match the externally visible sync/atomic package.  This is the
gofrontend version of https://golang.org/cl/289152.  Bootstrapped and
ran Go testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
a6b138f257a431f3337f3c6bf53f7865c455ba60
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 394530c1cbc..19ab2de5c18 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-b47bcf942daa9a0c252db9b57b8f138adbfcdaa2
+32590102c464679f845667b5554e1dcce2549ad2
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 3e433d6c20d..33177a709ab 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -11590,12 +11590,10 @@ Call_expression::intrinsify(Gogo* gogo,
   // sync/atomic functions and runtime/internal/atomic functions
   // are very similar. In order not to duplicate code, we just
   // redirect to the latter and let the code below to handle them.
-  // In case there is no equivalent functions (slight variance
-  // in types), we just make an artificial name (begin with '$').
   // Note: no StorePointer, SwapPointer, and CompareAndSwapPointer,
   // as they need write barriers.
   if (name == "LoadInt32")
-name = "$Loadint32";
+name = "Loadint32";
   else if (name == "LoadInt64")
 name = "Loadint64";
   else if (name == "LoadUint32")
@@ -11607,9 +11605,9 @@ Call_expression::intrinsify(Gogo* gogo,
   else if (name == "LoadPointer")
 name = "Loadp";
   else if (name == "StoreInt32")
-name = "$Storeint32";
+name = "Storeint32";
   else if (name == "StoreInt64")
-name = "$Storeint64";
+name = "Storeint64";
   else if (name == "StoreUint32")
 name = "Store";
   else if (name == "StoreUint64")
@@ -11617,7 +11615,7 @@ Call_expression::intrinsify(Gogo* gogo,
   else if (name == "StoreUintptr")
 name = "Storeuintptr";
   else if (name == "AddInt32")
-name = "$Xaddint32";
+name = "Xaddint32";
   else if (name == "AddInt64")
 name = "Xaddint64";
   else if (name == "AddUint32")
@@ -11627,9 +11625,9 @@ Call_expression::intrinsify(Gogo* gogo,
   else if (name == "AddUintptr")
 name = "Xadduintptr";
   else if (name == "SwapInt32")
-name = "$Xchgint32";
+name = "Xchgint32";
   else if (name == "SwapInt64")
-name = "$Xchgint64";
+name = "Xchgint64";
   else if (name == "SwapUint32")
 name = "Xchg";
   else if (name == "SwapUint64")
@@ -11637,9 +11635,9 @@ Call_expression::intrinsify(Gogo* gogo,
   else if (name == "SwapUintptr")
 name = "Xchguintptr";
   else if (name == "CompareAndSwapInt32")
-name = "$Casint32";
+name = "Casint32";
   else if (name == "CompareAndSwapInt64")
-name = "$Casint64";
+name = "Casint64";
   else if (name == "CompareAndSwapUint32")
 name = "Cas";
   else if (name == "CompareAndSwapUint64")
@@ -11875,7 +11873,7 @@ Call_expression::intrinsify(Gogo* gogo,
 
   if ((name == "Load" || name == "Load64" || name == "Loadint64" || name 
== "Loadp"
|| name == "Loaduint" || name == "Loaduintptr" || name == "LoadAcq"
-   || name == "$Loadint32")
+   || name == "Loadint32")
   && this->args_ != NULL && this->args_->size() == 1)
 {
   if (int_size < 8 && (name == "Load64" || name == "Loadint64"))
@@ -11895,7 +11893,7 @@ Call_expression::intrinsify(Gogo* gogo,
   code = Runtime::ATOMIC_LOAD_8;
   res_type = uint64_type;
 }
-  else if (name == "$Loadint32")
+  else if (name == "Loadint32")
 {
   code = Runtime::ATOMIC_LOAD_4;
   res_type = int32_type;
@@ -11942,10 +11940,10 @@ Call_expression::intrinsify(Gogo* gogo,
 
   if ((name == "Store" || name == "Store64" || name == "StorepNoWB"
|| name == "Storeuintptr" || name == "StoreRel"
-   || name == "$Storeint32" || name == "$Storeint64")
+   || name == "Storeint32" || name == "Storeint64")
   && this->args_ != NULL && this->args_->size() == 2)
 {
-  if (int_size < 8 && (name == "Store64" || name == "$Storeint64"))
+  if (int_size < 8 && (name == "Store64" || name == "Storeint64"))
 return NULL;
 
   Runtime::Function code;
@@ -11955,9 +11953,9 @@ Call_expression::intrinsify(Gogo* gogo,
 code = Runtime::ATOMIC_STORE_4;
   else if (name == "Store64")
 code = Runtime::ATOMIC_STORE_8;
-  else if (name == "$Storeint32")
+  else if (name == "Storeint32")
 code = Runtime::ATOMIC_STORE_4;

Re: Go patch committed: Be strict about escape analysis of builtin functions

2021-08-06 Thread Ian Lance Taylor via Gcc-patches
On Wed, Aug 4, 2021 at 9:24 PM Ian Lance Taylor  wrote:
>
> This Go frontend patch by Cherry Mui makes the escape analysis pass
> stricter about builtin functions  In the places where we handle
> builtin functions, list all supported ones, and fail if an unexpected
> one is seen. So if a new builtin function is added in the future we
> can detect it, instead of silently treating it as nonescaping.
> Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
> to mainline.

Here is a follow-on patch by Cherry Mui that does the same thing for
runtime functions.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
1157b8141443caed32f0fb7ea40aa74a1ba36fac
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 19ab2de5c18..9ed527f7eb4 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-32590102c464679f845667b5554e1dcce2549ad2
+747f3a2d78c073e9b03dd81914d0edb7ddc5be14
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/escape.cc b/gcc/go/gofrontend/escape.cc
index c8978ac9239..6da29edc419 100644
--- a/gcc/go/gofrontend/escape.cc
+++ b/gcc/go/gofrontend/escape.cc
@@ -1646,6 +1646,7 @@ Escape_analysis_assign::expression(Expression** pexpr)
  case Runtime::MAKECHAN:
  case Runtime::MAKECHAN64:
  case Runtime::MAKEMAP:
+ case Runtime::MAKEMAP64:
  case Runtime::MAKESLICE:
  case Runtime::MAKESLICE64:
 this->context_->track(n);
@@ -1705,8 +1706,52 @@ Escape_analysis_assign::expression(Expression** pexpr)
 }
 break;
 
+  case Runtime::MEMCMP:
+  case Runtime::DECODERUNE:
+  case Runtime::INTSTRING:
+  case Runtime::MAKEMAP_SMALL:
+  case Runtime::MAPACCESS1:
+  case Runtime::MAPACCESS1_FAST32:
+  case Runtime::MAPACCESS1_FAST64:
+  case Runtime::MAPACCESS1_FASTSTR:
+  case Runtime::MAPACCESS1_FAT:
+  case Runtime::MAPACCESS2:
+  case Runtime::MAPACCESS2_FAST32:
+  case Runtime::MAPACCESS2_FAST64:
+  case Runtime::MAPACCESS2_FASTSTR:
+  case Runtime::MAPACCESS2_FAT:
+  case Runtime::MAPASSIGN_FAST32:
+  case Runtime::MAPASSIGN_FAST64:
+  case Runtime::MAPITERINIT:
+  case Runtime::MAPITERNEXT:
+  case Runtime::MAPCLEAR:
+  case Runtime::CHANRECV2:
+  case Runtime::SELECTGO:
+  case Runtime::SELECTNBSEND:
+  case Runtime::SELECTNBRECV:
+  case Runtime::BLOCK:
+  case Runtime::IFACET2IP:
+  case Runtime::EQTYPE:
+  case Runtime::MEMCLRHASPTR:
+  case Runtime::FIELDTRACK:
+  case Runtime::BUILTIN_MEMSET:
+  case Runtime::PANIC_SLICE_CONVERT:
+// these do not escape.
+break;
+
+  case Runtime::IFACEE2E2:
+  case Runtime::IFACEI2E2:
+  case Runtime::IFACEE2I2:
+  case Runtime::IFACEI2I2:
+  case Runtime::IFACEE2T2P:
+  case Runtime::IFACEI2T2P:
+// handled in ::assign.
+break;
+
  default:
-   break;
+// should not see other runtime calls. they are not yet
+// lowered to runtime calls at this point.
+go_unreachable();
  }
  }
 else


Re: Go patch committed: Support unsafe.Add and unsafe.Slice

2021-08-07 Thread Ian Lance Taylor via Gcc-patches
On Mon, Aug 2, 2021 at 3:23 PM Ian Lance Taylor  wrote:
>
> The upcoming Go 1.17 release adds two new functions to the unsafe
> package: unsafe.Add and unsafe.Slice.  These functions must be
> implemented in the compiler.  This patch implements them for gccgo.
> Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
> to mainline.

This patch makes unsafe.Add and unsafe.Slice work when they appear in
functions that can be inlined across packages.  Bootstrapped and ran
Go testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
b00c45d66d337e18a02674075ca792fd38094acf
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 9ed527f7eb4..b983fdab35c 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-747f3a2d78c073e9b03dd81914d0edb7ddc5be14
+d5d51242efc432fa62d4e9b141b01c280af32d19
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/export.cc b/gcc/go/gofrontend/export.cc
index e99c680f709..3d11334884d 100644
--- a/gcc/go/gofrontend/export.cc
+++ b/gcc/go/gofrontend/export.cc
@@ -106,11 +106,12 @@ class Collect_export_references : public Traverse
 {
  public:
   Collect_export_references(Export* exp,
+   const std::map& packages,
 Unordered_set(Named_object*)* exports,
 Unordered_set(const Package*)* imports)
 : Traverse(traverse_expressions
| traverse_types),
-  exp_(exp), exports_(exports), imports_(imports),
+  exp_(exp), packages_(packages), exports_(exports), imports_(imports),
   inline_fcn_worklist_(NULL), exports_finalized_(false)
   { }
 
@@ -150,6 +151,8 @@ class Collect_export_references : public Traverse
 
   // The exporter.
   Export* exp_;
+  // The list of packages known to this compilation.
+  const std::map& packages_;
   // The set of named objects to export.
   Unordered_set(Named_object*)* exports_;
   // Set containing all directly and indirectly imported packages.
@@ -257,6 +260,24 @@ Collect_export_references::expression(Expression** pexpr)
   return TRAVERSE_CONTINUE;
 }
 
+  const Call_expression* call = expr->call_expression();
+  if (call != NULL)
+{
+  const Builtin_call_expression* bce = call->builtin_call_expression();
+  if (bce != NULL
+ && (bce->code() == Builtin_call_expression::BUILTIN_ADD
+ || bce->code() == Builtin_call_expression::BUILTIN_SLICE))
+   {
+ // This is a reference to unsafe.Add or unsafe.Slice.  Make
+ // sure we list the "unsafe" package in the imports and give
+ // it a package index.
+ const std::map::const_iterator p =
+   this->packages_.find("unsafe");
+ go_assert(p != this->packages_.end());
+ this->imports_->insert(p->second);
+   }
+}
+
   return TRAVERSE_CONTINUE;
 }
 
@@ -589,7 +610,7 @@ Export::export_globals(const std::string& package_name,
   // Track all imported packages mentioned in export data.
   Unordered_set(const Package*) all_imports;
 
-  Collect_export_references collect(this, &exports, &all_imports);
+  Collect_export_references collect(this, packages, &exports, &all_imports);
 
   // Walk the set of inlinable routine bodies collected above. This
   // can potentially expand the exports set.
@@ -1274,6 +1295,25 @@ Export::package_index(const Package* pkg) const
   return index;
 }
 
+// Return the index of the "unsafe" package.
+
+int
+Export::unsafe_package_index() const
+{
+  for (Unordered_map(const Package*, int)::const_iterator p =
+this->packages_.begin();
+   p != this->packages_.end();
+   ++p)
+{
+  if (p->first->pkgpath() == "unsafe")
+   {
+ go_assert(p->second != 0);
+ return p->second;
+   }
+}
+  go_unreachable();
+}
+
 // Return the index of a type.
 
 int
diff --git a/gcc/go/gofrontend/export.h b/gcc/go/gofrontend/export.h
index c93bced4eb4..1f613434cab 100644
--- a/gcc/go/gofrontend/export.h
+++ b/gcc/go/gofrontend/export.h
@@ -216,6 +216,11 @@ class Export : public String_dump
   int
   package_index(const Package* p) const;
 
+  // Return the index of the "unsafe" package, which must be one of
+  // the exported packages.
+  int
+  unsafe_package_index() const;
+
  private:
   Export(const Export&);
   Export& operator=(const Export&);
@@ -377,6 +382,11 @@ class Export_function_body : public String_dump
   package_index(const Package* p) const
   { return this->exp_->package_index(p); }
 
+  // Return the index of the "unsafe" package.
+  int
+  unsafe_package_index() const
+  { return this->exp_->unsafe_package_index(); }
+
   // Record a temporary statement and return its index.
   unsigned int
   record_temporary(const Temporary_statement*);
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 33177a709ab..f462b0e2a34 100644
--- a/gcc/go/gofrontend/expr

Go patch committed: Don't crash on a, b := int(0)

2021-08-10 Thread Ian Lance Taylor via Gcc-patches
This patch the Go frontend avoids a crash on the invalid code "a, b :=
int(0)".  This fixes GCC PR 101851.  Bootstrapped and ran Go testsuite
on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
498e91bf7d6a8000bb4b74f95c404064b8eac644
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index b983fdab35c..be092de568b 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-d5d51242efc432fa62d4e9b141b01c280af32d19
+7e092d2cc5af7648036496485b639f2c9db2f2d8
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index f462b0e2a34..67917dac95d 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -11202,12 +11202,23 @@ Call_expression::do_lower(Gogo* gogo, Named_object* 
function,
 {
   Location loc = this->location();
 
+  if (this->is_error_expression())
+return Expression::make_error(loc);
+
   // A type cast can look like a function call.
   if (this->fn_->is_type_expression()
   && this->args_ != NULL
   && this->args_->size() == 1)
-return Expression::make_cast(this->fn_->type(), this->args_->front(),
-loc);
+{
+  if (this->expected_result_count_ != 0
+ && this->expected_result_count_ != 1)
+   {
+ this->report_error(_("type conversion result count mismatch"));
+ return Expression::make_error(loc);
+   }
+  return Expression::make_cast(this->fn_->type(), this->args_->front(),
+  loc);
+}
 
   // Because do_type will return an error type and thus prevent future
   // errors, check for that case now to ensure that the error gets


Re: [PATCH] libbacktrace: fix b2test_buildid test on non-english locales

2021-08-12 Thread Ian Lance Taylor via Gcc-patches
On Thu, Aug 12, 2021 at 3:35 PM Sergei Trofimovich via Gcc-patches
 wrote:
>
> From: Sergei Trofimovich 
>
> On LANG=ru_RU.UTF-8 'b2test_buildid' test fails due to localized readelf
> output:
>
> $ LANG=ru_RU.UTF-8 readelf -n b2test | fgrep 4e37e8f
> ID сборки: 4e37e8fead8d6e8b0a9dc95ea25cd784dff3a393
> $ LANG=C readelf -n b2test | fgrep 4e37e8f
> Build ID: 4e37e8fead8d6e8b0a9dc95ea25cd784dff3a393
>
> libbacktrace/
>
> * install-debuginfo-for-buildid.sh.in: Force non-localized readelf
> output with LANG=C.
> ---
>  libbacktrace/install-debuginfo-for-buildid.sh.in | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libbacktrace/install-debuginfo-for-buildid.sh.in 
> b/libbacktrace/install-debuginfo-for-buildid.sh.in
> index 1364779d703..91dfdfe89a4 100644
> --- a/libbacktrace/install-debuginfo-for-buildid.sh.in
> +++ b/libbacktrace/install-debuginfo-for-buildid.sh.in
> @@ -47,7 +47,7 @@ mkdir_p="@MKDIR_P@"
>  build_id_dir="$1"
>  src="$2"
>
> -buildid=$($readelf -n $src \
> +buildid=$(LANG=C $readelf -n $src \
>   | $grep "Build ID" \
>   | $awk '{print $3}')
>


This is OK.

Thanks.

Ian


Re: [PATCH] libbacktrace: fix fd leak tests on systems with extra descriptors

2021-08-12 Thread Ian Lance Taylor via Gcc-patches
On Thu, Aug 12, 2021 at 3:34 PM Sergei Trofimovich via Gcc-patches
 wrote:
>
> From: Sergei Trofimovich 
>
> I noticed test failures when ran gcc test suite from under mc shell.
> mc opens fd=9 and exposes it to child processes. As a result a few
> tests failes:
> FAIL: b2test_buildid
> FAIL: btest_gnudebuglink
> FAIL: btest
> FAIL: btest_lto
> FAIL: btest_alloc
> FAIL: ctestg
> FAIL: ctesta
> FAIL: ctestg_alloc
> FAIL: ctesta_alloc
> FAIL: dwarf5
> FAIL: dwarf5_alloc
>
> Instead of trying to close file descripts in range test polls for
> first available file descriptor by creating it via dup(1).
>
> libbacktrace/
>
> * btest.c (check_open_files): Use last free file descriptor as a
> signal for flie descriptor leak.

This isn't a useful replacement, as this will pass as long as
libbacktrace closes the first file descriptor that it opens.  It won't
check whether libbacktrace left any other file descriptors open.

Perhaps at program startup we could fstat descriptors up to 10 and
record whether they are valid, and then skip those files in
check_open_files.

Ian


Go patch committed: Store pointers to go:notinheap types indirectly

2021-08-12 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend and libgo stores pointers to
go:notinheap types indirectly.  This provides better support for using
cgo with incomplete types.  This is the gofrontend version of
https://golang.org/cl/264480.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
493219b84da47449c53883d0702dbc4457912f5e
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index be092de568b..539d886b08f 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-7e092d2cc5af7648036496485b639f2c9db2f2d8
+5edbb624b2595d644eb6842c952a292c41f7d6fa
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 67917dac95d..8d4d168f4e3 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -408,7 +408,14 @@ Expression::convert_type_to_interface(Type* lhs_type, 
Expression* rhs,
 {
   // We are assigning a non-pointer value to the interface; the
   // interface gets a copy of the value in the heap if it escapes.
-  if (rhs->is_constant())
+
+  // An exception is &global if global is notinheap, which is a
+  // pointer value but not a direct-iface type and we can't simply
+  // take its address.
+  bool is_address = (rhs->unary_expression() != NULL
+ && rhs->unary_expression()->op() == OPERATOR_AND);
+
+  if (rhs->is_constant() && !is_address)
 obj = Expression::make_unary(OPERATOR_AND, rhs, location);
   else
 {
@@ -11331,6 +11338,7 @@ Call_expression::do_lower(Gogo* gogo, Named_object* 
function,
   // We always pass a pointer when calling a method, except for
   // direct interface types when calling a value method.
   if (!first_arg->type()->is_error()
+  && first_arg->type()->points_to() == NULL
   && !first_arg->type()->is_direct_iface_type())
{
  first_arg = Expression::make_unary(OPERATOR_AND, first_arg, loc);
@@ -18630,12 +18638,20 @@ 
Interface_mtable_expression::do_get_backend(Translate_context* context)
   else
m = st->method_function(p->name(), &is_ambiguous);
   go_assert(m != NULL);
-  Named_object* no =
-(this->is_pointer_
- && this->type_->is_direct_iface_type()
- && m->is_value_method()
- ? m->iface_stub_object()
- : m->named_object());
+
+  // See the comment in Type::method_constructor.
+  bool use_direct_iface_stub = false;
+  if (m->is_value_method()
+ && this->is_pointer_
+ && this->type_->is_direct_iface_type())
+   use_direct_iface_stub = true;
+  if (!m->is_value_method()
+ && this->is_pointer_
+ && !this->type_->in_heap())
+   use_direct_iface_stub = true;
+  Named_object* no = (use_direct_iface_stub
+ ? m->iface_stub_object()
+ : m->named_object());
 
   go_assert(no->is_function() || no->is_function_declaration());
 
diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc
index 0c44186f507..e76600daab9 100644
--- a/gcc/go/gofrontend/types.cc
+++ b/gcc/go/gofrontend/types.cc
@@ -2464,8 +2464,16 @@ Type::is_direct_iface_type() const
 bool
 Type::is_direct_iface_type_helper(Unordered_set(const Type*)* visited) const
 {
-  if (this->points_to() != NULL
-  || this->channel_type() != NULL
+  if (this->points_to() != NULL)
+{
+  // Pointers to notinheap types must be stored indirectly.  See
+  // https://golang.org/issue/42076.
+  if (!this->points_to()->in_heap())
+   return false;
+  return true;
+}
+
+  if (this->channel_type() != NULL
   || this->function_type() != NULL
   || this->map_type() != NULL)
 return true;
@@ -3597,10 +3605,36 @@ Type::method_constructor(Gogo*, Type* method_type,
   vals->push_back(Expression::make_unary(OPERATOR_AND, s, bloc));
 }
 
-  bool use_direct_iface_stub =
-this->points_to() != NULL
-&& this->points_to()->is_direct_iface_type()
-&& m->is_value_method();
+  // The direct_iface_stub dereferences the value stored in the
+  // interface when calling the method.
+  //
+  // We need this for a value method if this type is a pointer to a
+  // direct-iface type.  For example, if we have "type C chan int" and M
+  // is a value method on C, then since a channel is a direct-iface type
+  // M expects a value of type C.  We are generating the method table
+  // for *C, so the value stored in the interface is *C.  We have to
+  // call the direct-iface stub to dereference *C to get C to pass to M.
+  //
+  // We also need this for a pointer method if the pointer itself is not
+  // a direct-iface type, as arises for notinheap types.  In this case
+  // we have "type NIH ..." where NIH is go:notinheap.  Since NIH is
+  // notinheap, *NIH is a pointer type that is not a

libgo patch committed: Update to Go1.17rc2 release

2021-08-12 Thread Ian Lance Taylor via Gcc-patches
This patch updates libgo from the Go1.16.5 release to the Go 1.17rc2
release.  As usual with these version updates, the patch itself is too
large to attach to this e-mail message.  I've attached the changes to
files that are specific to gccgo.  Bootstraped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
5fe441d33024fe33b9835c3e8d6b9f6cf24715f1
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 539d886b08f..bcbe1d93018 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-5edbb624b2595d644eb6842c952a292c41f7d6fa
+33f65dce43bd01c1fa38cd90a78c9aea6ca6dd59
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/MERGE b/libgo/MERGE
index ac842716022..4286d5c5433 100644
--- a/libgo/MERGE
+++ b/libgo/MERGE
@@ -1,4 +1,4 @@
-7677616a263e8ded606cc8297cb67ddc667a876e
+72ab3ff68b1ec894fe5599ec82b8849f3baa9d94
 
 The first line of this file holds the git revision number of the
 last merge done from the master library sources.
diff --git a/libgo/Makefile.am b/libgo/Makefile.am
index dec98756673..92fedcf6eb8 100644
--- a/libgo/Makefile.am
+++ b/libgo/Makefile.am
@@ -366,6 +366,7 @@ toolexeclibgoregexp_DATA = \
 toolexeclibgoruntimedir = $(toolexeclibgodir)/runtime
 
 toolexeclibgoruntime_DATA = \
+   runtime/cgo.gox \
runtime/debug.gox \
runtime/metrics.gox \
runtime/pprof.gox \
@@ -428,7 +429,9 @@ noinst_DATA = \
internal/testenv.gox \
internal/trace.gox \
net/internal/socktest.gox \
-   os/signal/internal/pty.gox
+   os/signal/internal/pty.gox \
+   reflect/internal/example1.gox \
+   reflect/internal/example2.gox
 
 if LIBGO_IS_RTEMS
 rtems_task_variable_add_file = runtime/rtems-task-variable-add.c
@@ -480,14 +483,10 @@ version.go: s-version; @true
 s-version: Makefile
rm -f version.go.tmp
echo "package sys" > version.go.tmp
-   echo 'func init() { DefaultGoroot = "$(prefix)" }' >> version.go.tmp
-   echo 'const TheVersion = "'`cat $(srcdir)/VERSION | sed 1q`' '`$(GOC) 
--version | sed 1q`'"' >> version.go.tmp
-   echo 'const Goexperiment = ``' >> version.go.tmp
echo 'const GOARCH = "'$(GOARCH)'"' >> version.go.tmp
echo 'const GOOS = "'$(GOOS)'"' >> version.go.tmp
echo 'const GccgoToolDir = "$(libexecsubdir)"' >> version.go.tmp
-   echo >> version.go.tmp
-   echo "type ArchFamilyType int" >> version.go.tmp
+   echo 'const StackGuardMultiplierDefault = 1' >> version.go.tmp
echo >> version.go.tmp
echo "const (" >> version.go.tmp
echo "  UNKNOWN ArchFamilyType = iota" >> version.go.tmp
@@ -507,13 +506,13 @@ s-version: Makefile
done
echo >> version.go.tmp
echo "const (" >> version.go.tmp
-   echo "  ArchFamily = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) family`" 
>> version.go.tmp
-   echo "  BigEndian = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) bigendian`" 
>> version.go.tmp
-   echo "  CacheLineSize = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) 
cachelinesize`" >> version.go.tmp
-   echo "  DefaultPhysPageSize = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) 
defaultphyspagesize`" >> version.go.tmp
-   echo "  Int64Align = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) 
int64align`" >> version.go.tmp
-   echo "  MinFrameSize = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) 
minframesize`" >> version.go.tmp
-   echo "  PCQuantum = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) pcquantum`" 
>> version.go.tmp
+   echo "  _ArchFamily = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) family`" 
>> version.go.tmp
+   echo "  _BigEndian = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) 
bigendian`" >> version.go.tmp
+   echo "  _DefaultPhysPageSize = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) 
defaultphyspagesize`" >> version.go.tmp
+   echo "  _Int64Align = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) 
int64align`" >> version.go.tmp
+   echo "  _MinFrameSize = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) 
minframesize`" >> version.go.tmp
+   echo "  _PCQuantum = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) 
pcquantum`" >> version.go.tmp
+   echo "  _StackAlign = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) 
stackalign`" >> version.go.tmp
echo ")" >> version.go.tmp
echo >> version.go.tmp
for a in $(ALLGOOS); do \
@@ -526,7 +525,6 @@ s-version: Makefile
  fi; \
done
echo >> version.go.tmp
-   echo "type Uintreg uintptr" >> version.go.tmp
$(SHELL) $(srcdir)/mvifdiff.sh version.go.tmp version.go
$(STAMP) $@
 
@@ -547,24 +545,31 @@ s-gcpu: Makefile
$(SHELL) $(srcdir)/mvifdiff.sh gcpugen.go.tmp gcpugen.go
$(STAMP) $@
 
+buildcfg.go: s-buildcfg; @true
+s-buildcfg: Makefile
+   rm -f buildcfg.go.tmp
+   echo "package buildcfg" > buildcfg.go.tmp
+   echo "import \"runtime\"" >> buildcfg.go.tmp
+   echo 'func defaultGOROOTValue()

Re: [PATCH] libbacktrace: fix fd leak tests on systems with extra descriptors

2021-08-13 Thread Ian Lance Taylor via Gcc-patches
On Fri, Aug 13, 2021 at 12:05 AM Sergei Trofimovich  wrote:
>
> On Thu, 12 Aug 2021 16:16:04 -0700
> Ian Lance Taylor  wrote:
>
> > On Thu, Aug 12, 2021 at 3:34 PM Sergei Trofimovich via Gcc-patches
> >  wrote:
> > >
> > > From: Sergei Trofimovich 
> > >
> > > I noticed test failures when ran gcc test suite from under mc shell.
> > > mc opens fd=9 and exposes it to child processes. As a result a few
> > > tests failes:
> > > FAIL: b2test_buildid
> > > FAIL: btest_gnudebuglink
> > > FAIL: btest
> > > FAIL: btest_lto
> > > FAIL: btest_alloc
> > > FAIL: ctestg
> > > FAIL: ctesta
> > > FAIL: ctestg_alloc
> > > FAIL: ctesta_alloc
> > > FAIL: dwarf5
> > > FAIL: dwarf5_alloc
> > >
> > > Instead of trying to close file descripts in range test polls for
> > > first available file descriptor by creating it via dup(1).
> > >
> > > libbacktrace/
> > >
> > > * btest.c (check_open_files): Use last free file descriptor as a
> > > signal for flie descriptor leak.
> >
> > This isn't a useful replacement, as this will pass as long as
> > libbacktrace closes the first file descriptor that it opens.  It won't
> > check whether libbacktrace left any other file descriptors open.
> >
> > Perhaps at program startup we could fstat descriptors up to 10 and
> > record whether they are valid, and then skip those files in
> > check_open_files.
>
> Oh, great point! Completely missed it. Changed the patch to poll for present
> file descriptors with fcntl(fd, F_GETFD) to compare before/after.

I believe that we currently run some of the tests on Windows systems.
Do you know if fcntl(fd, F_GETFD) will work there?

Ian


Re: libgo patch committed: Update to Go1.17rc2 release

2021-08-13 Thread Ian Lance Taylor via Gcc-patches
On Fri, Aug 13, 2021 at 5:43 AM Rainer Orth  
wrote:
>
> Hi Ian,
>
> > This patch updates libgo from the Go1.16.5 release to the Go 1.17rc2
> > release.  As usual with these version updates, the patch itself is too
> > large to attach to this e-mail message.  I've attached the changes to
> > files that are specific to gccgo.  Bootstraped and ran Go testsuite on
> > x86_64-pc-linux-gnu.  Committed to mainline.
>
> this patch broke Solaris bootstrap:
>
> /vol/gcc/src/hg/master/local/libgo/runtime/stack.c: In function 
> 'onCurrentStack':
> /vol/gcc/src/hg/master/local/libgo/runtime/stack.c:177:21: error: expected 
> expression before 'uintptr'
>   177 | if (uintptr(initialsp2) < uintptr(nextsp2)) {
>   | ^~~
>
> Fixed by turning those into proper casts.

Sorry about that.  I've committed this patch.

Ian
a91ca5ff5fa56b54cfc03f43891ff613d714b722
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index bcbe1d93018..3000285fbf0 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-33f65dce43bd01c1fa38cd90a78c9aea6ca6dd59
+f2b7a2ce94127ad444a772bd1631516c5c67fb73
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/runtime/stack.c b/libgo/runtime/stack.c
index 0c0c30e46ac..65e8fa30077 100644
--- a/libgo/runtime/stack.c
+++ b/libgo/runtime/stack.c
@@ -174,7 +174,7 @@ bool onCurrentStack(uintptr p)
nextsp2 = secondary_stack_pointer();
if (nextsp2 != nil) {
initialsp2 = (byte*)(void*)(gp->gcinitialsp2);
-   if (uintptr(initialsp2) < uintptr(nextsp2)) {
+   if ((uintptr)(initialsp2) < (uintptr)(nextsp2)) {
temp = initialsp2;
initialsp2 = nextsp2;
nextsp2 = temp;


Re: libgo patch committed: Update to Go1.17rc2 release

2021-08-14 Thread Ian Lance Taylor via Gcc-patches
On Fri, Aug 13, 2021 at 2:08 PM Rainer Orth  
wrote:
>
> unfortunately, things are considerably worse: syscall.lo fails to build
> and go1 even ICEs:
>
> /vol/gcc/src/hg/master/local/libgo/go/syscall/libcall_posix_utimesnano.go:13:1:
>  error: redefinition of ‘UtimesNano’
>13 | func UtimesNano(path string, ts []Timespec) error {
>   | ^
> /vol/gcc/src/hg/master/local/libgo/go/syscall/libcall_linux_utimesnano.go:13:1:
>  note: previous definition of ‘UtimesNano’ was here
>13 | func UtimesNano(path string, ts []Timespec) (err error) {
>   | ^
>
> The second file is Linux-only and needs a corresponding build guard.
>
> /vol/gcc/src/hg/master/local/libgo/go/syscall/exec_unix.go:193:16: error: use 
> of undefined type ‘SysProcAttr’
>   193 | Sys   *SysProcAttr
>   |^
> /vol/gcc/src/hg/master/local/libgo/go/syscall/exec_unix.go:235:15: error: 
> reference to field ‘Chroot’ in object which has no fields or methods
>   235 | if sys.Chroot != "" {
>   |   ^
> /vol/gcc/src/hg/master/local/libgo/go/syscall/exec_unix.go:236:52: error: 
> reference to field ‘Chroot’ in object which has no fields or methods
>   236 | chroot, err = BytePtrFromString(sys.Chroot)
>   |^
> /vol/gcc/src/hg/master/local/libgo/go/syscall/exec_unix.go:251:15: error: 
> reference to field ‘Setctty’ in object which has no fields or methods
>   251 | if sys.Setctty && sys.Foreground {
>   |   ^
> /vol/gcc/src/hg/master/local/libgo/go/syscall/exec_unix.go:251:30: error: 
> reference to field ‘Foreground’ in object which has no fields or methods
>   251 | if sys.Setctty && sys.Foreground {
>   |  ^
> /vol/gcc/src/hg/master/local/libgo/go/syscall/exec_unix.go:254:15: error: 
> reference to field ‘Setctty’ in object which has no fields or methods
>   254 | if sys.Setctty && sys.Ctty >= len(attr.Files) {
>   |   ^
> /vol/gcc/src/hg/master/local/libgo/go/syscall/exec_unix.go:254:30: error: 
> reference to field ‘Ctty’ in object which has no fields or methods
>   254 | if sys.Setctty && sys.Ctty >= len(attr.Files) {
>   |  ^
> /vol/gcc/src/hg/master/local/libgo/go/syscall/exec_unix.go:269:21: error: 
> reference to undefined name ‘forkAndExecInChild’
>   269 | pid, err1 = forkAndExecInChild(argv0p, argvp, envvp, chroot, 
> dir, attr, sys, p[1])
>   | ^
>
> I found that upstream has exec_libc.go for AIX and Solaris with the
> missing SysProcAttr and forkAndExecInChild definitions.  It doesn't work
> out of the box, though:
>
> /vol/gcc/src/hg/master/local/libgo/go/syscall/exec_libc.go:63:9: error: 
> reference to undefined name ‘execveLibc’
>63 | execveLibc = execve
>   | ^
> /vol/gcc/src/hg/master/local/libgo/go/syscall/exec_libc.go:137:25: error: 
> reference to undefined name ‘_Pid_t’
>   137 | pgrp := _Pid_t(sys.Pgid)
>   | ^
> /vol/gcc/src/hg/master/local/libgo/go/syscall/exec_libc.go:144:32: error: 
> reference to undefined name ‘_Pid_t’
>   144 | pgrp = _Pid_t(r1)
>   |^
>
> For one, switching to Pid_t is needed:
>
>
> Besides, support for execveLibc has been dropped in exec_unix.go
> compared to upstream.
>
> terminate called after throwing an instance of 'std::out_of_range'
>   what():  vector::_M_range_check: __n (which is 1) >= this->size() (which is 
> 1)
> go1: internal compiler error: Abort
> 0xce1abf crash_signal
> /vol/gcc/src/hg/master/local/gcc/toplev.c:328
>
> This went away after the fixes above.
>
> Next, I get
>
> /vol/gcc/src/hg/master/local/libgo/go/internal/syscall/unix/getrandom_solaris.go:10:15:
>  error: imported and not used: unsafe
>10 | "unsafe"
>   |   ^
> /vol/gcc/src/hg/master/local/libgo/go/internal/syscall/unix/getrandom_solaris.go:32:30:
>  error: reference to undefined name 'getrandomUnsupported'
>32 | if atomic.LoadInt32(&getrandomUnsupported) != 0 {
>   |  ^
> /vol/gcc/src/hg/master/local/libgo/go/internal/syscall/unix/getrandom_solaris.go:41:44:
>  error: reference to undefined name 'getrandomUnsupported'
>41 | atomic.StoreInt32(&getrandomUnsupported, 1)
>   |^
> make[4]: *** [Makefile:3008: internal/syscall/unix.lo] Error 1
>
> The definition dropped compared to upstream.
>
> /vol/gcc/src/hg/master/local/libgo/go/os/user/listgroups_unix.go:39:15: 
> error: reference to undefined name ‘libc_getgrouplist’
>39 | rv := libc_getgrouplist(nameC, userGID, &gidsC[0], &n)
>   |   ^
> /vol/gcc/src/hg/master/local/libgo/go/os/user/listgroups_unix.go:49:23: 
> error: reference to undefined name ‘libc_getgrouplist’
>49 |  

libbacktrace: Add support for MiniDebugInfo

2020-09-14 Thread Ian Lance Taylor via Gcc-patches
This patch to libbacktrace adds support for MiniDebugInfo, as
requested in PR 93608.

MiniDebugInfo stores compressed symbol tables for an executable, where
the executable is otherwise stripped.  It is documented at
https://fedoraproject.org/wiki/Features/MiniDebugInfo and
https://sourceware.org/gdb/current/onlinedocs/gdb/MiniDebugInfo.html.

Unfortunately, although debug info processors are already required to
handle data compressed using zlib aka gzip in order to handle zdebug
and SHT_COMPRESSED, the MiniDebugInfo implementation choose to instead
compress the debug information with xz which uses LZMA2.  This in
effect forces all debug info processors to add a second decompression
algorithm.  Note to future developers: do not do this.

This libbacktrace implementation includes a new small LZMA
decompressor that just decompresses from one buffer to another.  It is
not heavily optimized, and on my laptop runs at about 78% of the speed
of using liblzma directly.  I think this is a decent tradeoff for
keeping the code reasonably small.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian

PR libbacktrace/93608
Add support for MiniDebugInfo.
* elf.c (struct elf_view): Define.  Replace most uses of
backtrace_view with elf_view.
(elf_get_view): New static functions.  Replace most calls of
backtrace_get_view with elf_get_view.
(elf_release_view): New static functions.  Replace most calls of
backtrace_release_view with elf_release_view.
(elf_uncompress_failed): Rename from elf_zlib_failed.  Change all
callers.
(LZMA_STATES, LZMA_POS_STATES, LZMA_DIST_STATES): Define.
(LZMA_DIST_SLOTS, LZMA_DIST_MODEL_START): Define.
(LZMA_DIST_MODEL_END, LZMA_FULL_DISTANCES): Define.
(LZMA_ALIGN_SIZE, LZMA_LEN_LOW_SYMBOLS): Define.
(LZMA_LEN_MID_SYMBOLS, LZMA_LEN_HIGH_SYMBOLS): Define.
(LZMA_LITERAL_CODERS_MAX, LZMA_LITERAL_CODER_SIZE): Define.
(LZMA_PROB_IS_MATCH_LEN, LZMA_PROB_IS_REP_LEN): Define.
(LZMA_PROB_IS_REP0_LEN, LZMA_PROB_IS_REP1_LEN): Define.
(LZMA_PROB_IS_REP2_LEN, LZMA_PROB_IS_REP0_LONG_LEN): Define.
(LZMA_PROB_DIST_SLOT_LEN, LZMA_PROB_DIST_SPECIAL_LEN): Define.
(LZMA_PROB_DIST_ALIGN_LEN): Define.
(LZMA_PROB_MATCH_LEN_CHOICE_LEN): Define.
(LZMA_PROB_MATCH_LEN_CHOICE2_LEN): Define.
(LZMA_PROB_MATCH_LEN_LOW_LEN): Define.
(LZMA_PROB_MATCH_LEN_MID_LEN): Define.
(LZMA_PROB_MATCH_LEN_HIGH_LEN): Define.
(LZMA_PROB_REP_LEN_CHOICE_LEN): Define.
(LZMA_PROB_REP_LEN_CHOICE2_LEN): Define.
(LZMA_PROB_REP_LEN_LOW_LEN): Define.
(LZMA_PROB_REP_LEN_MID_LEN): Define.
(LZMA_PROB_REP_LEN_HIGH_LEN): Define.
(LZMA_PROB_LITERAL_LEN): Define.
(LZMA_PROB_IS_MATCH_OFFSET, LZMA_PROB_IS_REP_OFFSET): Define.
(LZMA_PROB_IS_REP0_OFFSET, LZMA_PROB_IS_REP1_OFFSET): Define.
(LZMA_PROB_IS_REP2_OFFSET): Define.
(LZMA_PROB_IS_REP0_LONG_OFFSET): Define.
(LZMA_PROB_DIST_SLOT_OFFSET): Define.
(LZMA_PROB_DIST_SPECIAL_OFFSET): Define.
(LZMA_PROB_DIST_ALIGN_OFFSET): Define.
(LZMA_PROB_MATCH_LEN_CHOICE_OFFSET): Define.
(LZMA_PROB_MATCH_LEN_CHOICE2_OFFSET): Define.
(LZMA_PROB_MATCH_LEN_LOW_OFFSET): Define.
(LZMA_PROB_MATCH_LEN_MID_OFFSET): Define.
(LZMA_PROB_MATCH_LEN_HIGH_OFFSET): Define.
(LZMA_PROB_REP_LEN_CHOICE_OFFSET): Define.
(LZMA_PROB_REP_LEN_CHOICE2_OFFSET): Define.
(LZMA_PROB_REP_LEN_LOW_OFFSET): Define.
(LZMA_PROB_REP_LEN_MID_OFFSET): Define.
(LZMA_PROB_REP_LEN_HIGH_OFFSET): Define.
(LZMA_PROB_LITERAL_OFFSET): Define.
(LZMA_PROB_TOTAL_COUNT): Define.
(LZMA_IS_MATCH, LZMA_IS_REP, LZMA_IS_REP0): Define.
(LZMA_IS_REP1, LZMA_IS_REP2, LZMA_IS_REP0_LONG): Define.
(LZMA_DIST_SLOT, LZMA_DIST_SPECIAL, LZMA_DIST_ALIGN): Define.
(LZMA_MATCH_LEN_CHOICE, LZMA_MATCH_LEN_CHOICE2): Define.
(LZMA_MATCH_LEN_LOW, LZMA_MATCH_LEN_MID): Define.
(LZMA_MATCH_LEN_HIGH, LZMA_REP_LEN_CHOICE): Define.
(LZMA_REP_LEN_CHOICE2, LZMA_REP_LEN_LOW): Define.
(LZMA_REP_LEN_MID, LZMA_REP_LEN_HIGH, LZMA_LITERAL): Define.
(elf_lzma_varint): New static function.
(elf_lzma_range_normalize): New static function.
(elf_lzma_bit, elf_lzma_integer): New static functions.
(elf_lzma_reverse_integer): New static function.
(elf_lzma_len, elf_uncompress_lzma_block): New static functions.
(elf_uncompress_lzma): New static function.
(backtrace_uncompress_lzma): New function.
(elf_add): Add memory and memory_size parameters.  Change all
callers.  Look for .gnu_debugdata section, and, if found,
decompress it and use it for symbols and debug info.  Permit the
descriptor parameter to be -1.
* internal.h (backtrace_uncompress_lzma): Declare.
* mtest.c: New file.
* xztest.c: New file.
* configure.ac: Check for nm, xz, and comm programs.  Check for
liblzma library.
(HAVE_MINIDEBUG): Define.
* Makefile.am (mtest_SOURCES): Define.
(mtest_CFLAGS, mtest_LDADD): Define.
(TESTS): Add mtest_minidebug if HAVE_MINIDEBUG.
(%_minidebug): New pattern rule, if HAVE_MINIDEBUG.
(xztest_SOURCES, xztest_CFLAGS, xztest_LDADD): Define.
(xztest_alloc_SOURCES, xztest_alloc_CFLAGS): Define
(xztest_alloc_LDADD): Define.
(BUILDTESTS): Add mtest, xztest, xztest_alloc.
(CLEANFILES): Add files created b

libgo: add additional references in sysinfo.c

2020-09-15 Thread Ian Lance Taylor via Gcc-patches
This libgo patch by Than McIntosh adds a few more explicit references
to enumeration constants (RUSAGE_SELF, DT_UNKNOWN) in sysinfo.c to
insure that their hosting enums are emitted into DWARF, when using a
clang host compiler during the gollvm build.  Bootstrapped and ran Go
testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
d04a5acb18867932d937351ab9804d6cfc83c5f0
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index dc63f4a696a..df9d2118dfd 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-b75a139fcc7c56988ce2d5b3a2b9e274eb521b0d
+a47485cd0e9ce6a8b3e88e53ccc0a440f0bd4351
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/sysinfo.c b/libgo/sysinfo.c
index 0692fd41eb7..76405597128 100644
--- a/libgo/sysinfo.c
+++ b/libgo/sysinfo.c
@@ -316,6 +316,7 @@ enum {
 SREF(dirent);
 SREF(dirent64);
 OTREF(DIR);
+EREF(DT_UNKNOWN);
 
 // From fcntl.h
 SREF(flock);
@@ -437,6 +438,7 @@ SREF(rusage);
 SREF(rlimit64);
 EREF(RLIMIT_NOFILE);
 EREF(PRIO_USER);
+EREF(RUSAGE_SELF);
 
 // From sys/select.h
 TREF(fd_set);


Re: libbacktrace: Add support for MiniDebugInfo

2020-09-16 Thread Ian Lance Taylor via Gcc-patches
On Wed, Sep 16, 2020, 4:03 AM Alex Coplan  wrote:

> Hi Ian,
>
> On 14/09/2020 14:12, Ian Lance Taylor via Gcc-patches wrote:
> > This patch to libbacktrace adds support for MiniDebugInfo, as
> > requested in PR 93608.
>
> This appears to introduce a failure in the libbacktrace testsuite
> (observed on both x86 and aarch64):
>
> ../gcc/libbacktrace/../test-driver: line 107:  7905 Segmentation fault
>   (core dumped) "$@" > $log_file 2>&1
> FAIL: mtest_minidebug



I tested on x86 without seeing anything like this.  Can you give me any
more details?  Thanks.

Ian




> > MiniDebugInfo stores compressed symbol tables for an executable, where
> > the executable is otherwise stripped.  It is documented at
> > https://fedoraproject.org/wiki/Features/MiniDebugInfo and
> > https://sourceware.org/gdb/current/onlinedocs/gdb/MiniDebugInfo.html.
> >
> > Unfortunately, although debug info processors are already required to
> > handle data compressed using zlib aka gzip in order to handle zdebug
> > and SHT_COMPRESSED, the MiniDebugInfo implementation choose to instead
> > compress the debug information with xz which uses LZMA2.  This in
> > effect forces all debug info processors to add a second decompression
> > algorithm.  Note to future developers: do not do this.
> >
> > This libbacktrace implementation includes a new small LZMA
> > decompressor that just decompresses from one buffer to another.  It is
> > not heavily optimized, and on my laptop runs at about 78% of the speed
> > of using liblzma directly.  I think this is a decent tradeoff for
> > keeping the code reasonably small.
> >
> > Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
> > to mainline.
> >
> > Ian
>
> Thanks,
> Alex
>


Re: libbacktrace: Add support for MiniDebugInfo

2020-09-16 Thread Ian Lance Taylor via Gcc-patches
On Wed, Sep 16, 2020 at 8:54 AM Alex Coplan  wrote:
>
> On 16/09/2020 07:26, Ian Lance Taylor wrote:
> > On Wed, Sep 16, 2020, 4:03 AM Alex Coplan  wrote:
> >
> > > Hi Ian,
> > >
> > > On 14/09/2020 14:12, Ian Lance Taylor via Gcc-patches wrote:
> > > > This patch to libbacktrace adds support for MiniDebugInfo, as
> > > > requested in PR 93608.
> > >
> > > This appears to introduce a failure in the libbacktrace testsuite
> > > (observed on both x86 and aarch64):
> > >
> > > ../gcc/libbacktrace/../test-driver: line 107:  7905 Segmentation fault
> > >   (core dumped) "$@" > $log_file 2>&1
> > > FAIL: mtest_minidebug
> >
> >
> >
> > I tested on x86 without seeing anything like this.  Can you give me any
> > more details?  Thanks.
>
> Sure. On an Ubuntu 18.04 / x86-64 system with current trunk, configuring
> with:
>
> ~/toolchain/src/gcc/configure \
>   --prefix=`pwd` \
>   --enable-languages=c,c++ \
>   --disable-multilib \
>   --disable-bootstrap
>
> running `make && make check-libbacktrace` gives the failure described
> above. Here is the contents of libbacktrace/test-suite.log:
>
> =
> package-unused version-unused: ./test-suite.log
> =
>
> # TOTAL: 33
> # PASS:  32
> # SKIP:  0
> # XFAIL: 0
> # FAIL:  1
> # XPASS: 0
> # ERROR: 0
>
> .. contents:: :depth: 2
>
> FAIL: mtest_minidebug
> =
>
> no debug info in ELF executable
> no debug info in ELF executable
> no debug info in ELF executable
> no debug info in ELF executable
> no debug info in ELF executable
> no debug info in ELF executable
> no debug info in ELF executable
> test1: not enough frames; got 0, expected at least 3
> test1: [0]: got  expected f3
> test1: [1]: got  expected f2
> FAIL mtest_minidebug (exit status: 139)
>
> ---
>
> Let me know if you need any more info.


Thanks.  I think the problem arises when libbacktrace is unable to
find debug info for any shared library involved in the link.

This patch should fix it.  Bootstrapped and ran libbacktrace tests on
x86_64-pc-linux-gnu and aarch64-linux-gnu.  Committed to mainline.

Ian

PR libbacktrace/97080
* fileline.c (backtrace_syminfo_to_full_callback): New function.
(backtrace_syminfo_to_full_error_callback): New function.
* elf.c (elf_nodebug): Call syminfo_fn if possible.
* internal.h (struct backtrace_call_full): Define.
(backtrace_syminfo_to_full_callback): Declare.
(backtrace_syminfo_to_full_error_callback): Declare.
* mtest.c (f3): Only check all[i] if data.index permits.
diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index dd004708246..941f820d944 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -547,18 +547,6 @@ elf_crc32_file (struct backtrace_state *state, int 
descriptor,
   return ret;
 }
 
-/* A dummy callback function used when we can't find any debug info.  */
-
-static int
-elf_nodebug (struct backtrace_state *state ATTRIBUTE_UNUSED,
-uintptr_t pc ATTRIBUTE_UNUSED,
-backtrace_full_callback callback ATTRIBUTE_UNUSED,
-backtrace_error_callback error_callback, void *data)
-{
-  error_callback (data, "no debug info in ELF executable", -1);
-  return 0;
-}
-
 /* A dummy callback function used when we can't find a symbol
table.  */
 
@@ -571,6 +559,33 @@ elf_nosyms (struct backtrace_state *state ATTRIBUTE_UNUSED,
   error_callback (data, "no symbol table in ELF executable", -1);
 }
 
+/* A callback function used when we can't find any debug info.  */
+
+static int
+elf_nodebug (struct backtrace_state *state, uintptr_t pc,
+backtrace_full_callback callback,
+backtrace_error_callback error_callback, void *data)
+{
+  if (state->syminfo_fn != NULL && state->syminfo_fn != elf_nosyms)
+{
+  struct backtrace_call_full bdata;
+
+  /* Fetch symbol information so that we can least get the
+function name.  */
+
+  bdata.full_callback = callback;
+  bdata.full_error_callback = error_callback;
+  bdata.full_data = data;
+  bdata.ret = 0;
+  state->syminfo_fn (state, pc, backtrace_syminfo_to_full_callback,
+backtrace_syminfo_to_full_error_callback, &bdata);
+  return bdata.ret;
+}
+
+  error_callback (data, "no debug info in ELF executable", -1);
+  return 0;
+}
+
 /* Compare struct elf_symbol for qsort.  */
 
 static int
diff --git a/libbacktrace/fileline.c b/libbacktrace/fileline.c
index be62b9899c5..cd1e10dd58c 100644
--- a/libbacktrace/fileline.c
+++ b/libbacktrace/fileline.c
@@ -317,3 +317,30 @@ backtrace_syminfo (struct b

libgo patch committed: glibc ptrace is a varargs function

2020-09-17 Thread Ian Lance Taylor via Gcc-patches
This patch by Paul Murphy fixes calls from libgo to ptrace.  In glibc,
ptrace is actually declared as a variadic function.  On ppc64le the
ABI requires to the caller to allocate space for the parameters and
allows the caller to modify them.

On ppc64le, depending on how and what version of GCC is used, it will
save to parameter save area.  This happened to clobber a saved LR, and
caused syscall.TestExecPtrace to fail with a timeout when the tracee
segfaults, and waits for the parent process to inspect.

Wrap the ptrace function to avoid directly calling glibc's ptrace from go.

This resolves GCC PR #92567 and https://golang.org/issue/36698.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
e70264072c595701eb9df189e46b25da52d832b3
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index df9d2118dfd..6b590f6fd94 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-a47485cd0e9ce6a8b3e88e53ccc0a440f0bd4351
+6fd6418efb983827717f648a11bb5ca6fe93af30
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/go/syscall/libcall_glibc.go 
b/libgo/go/syscall/libcall_glibc.go
index a90fc9b3f8b..823343d5075 100644
--- a/libgo/go/syscall/libcall_glibc.go
+++ b/libgo/go/syscall/libcall_glibc.go
@@ -32,7 +32,7 @@ func Futimes(fd int, tv []Timeval) (err error) {
 }
 
 //sys  ptrace(request int, pid int, addr uintptr, data uintptr) (err error)
-//ptrace(request _C_int, pid Pid_t, addr *byte, data *byte) _C_long
+//__go_ptrace(request _C_int, pid Pid_t, addr *byte, data *byte) _C_long
 
 //sys  accept4(fd int, sa *RawSockaddrAny, len *Socklen_t, flags int) (nfd 
int, err error)
 //accept4(fd _C_int, sa *RawSockaddrAny, len *Socklen_t, flags _C_int) _C_int
diff --git a/libgo/go/syscall/libcall_linux.go 
b/libgo/go/syscall/libcall_linux.go
index 88286c07b6e..78fda0ea7ef 100644
--- a/libgo/go/syscall/libcall_linux.go
+++ b/libgo/go/syscall/libcall_linux.go
@@ -11,7 +11,7 @@ import (
 )
 
 //sysnb raw_ptrace(request int, pid int, addr *byte, data *byte) (err Errno)
-//ptrace(request _C_int, pid Pid_t, addr *byte, data *byte) _C_long
+//__go_ptrace(request _C_int, pid Pid_t, addr *byte, data *byte) _C_long
 
 func ptracePeek(req int, pid int, addr uintptr, out []byte) (count int, err 
error) {
// The peek requests are machine-size oriented, so we wrap it
diff --git a/libgo/runtime/go-varargs.c b/libgo/runtime/go-varargs.c
index 2b186ef8b81..f9270a97bfd 100644
--- a/libgo/runtime/go-varargs.c
+++ b/libgo/runtime/go-varargs.c
@@ -18,6 +18,9 @@
 #ifdef HAVE_SYS_SYSCALL_H
 #include 
 #endif
+#ifdef HAVE_SYS_PTRACE_H
+#include 
+#endif
 
 /* The syscall package calls C functions.  The Go compiler can not
represent a C varargs functions.  On some systems it's important
@@ -110,3 +113,16 @@ __go_syscall6(uintptr_t flag, uintptr_t a1, uintptr_t a2, 
uintptr_t a3,
 }
 
 #endif
+
+#ifdef HAVE_SYS_PTRACE_H
+
+// Despite documented appearances, this is actually implemented as
+// a variadic function within glibc.
+
+long
+__go_ptrace(int request, pid_t pid, uintptr_t addr, uintptr_t data)
+{
+  return ptrace (request, pid, addr, data);
+}
+
+#endif


libsanitizer patch committed: Update for libbacktrace changes

2020-09-21 Thread Ian Lance Taylor via Gcc-patches
Recent changes to libbacktrace have introduced a few more globally
symbols.  These then need to be renamed in the libsanitizer copy.
This patch does that.  Tested by configuring
--with-build-config=bootstrap-asan and running a bootstrap.  Committed
to mainline as obvious.

Ian

* libbacktrace/backtrace-rename.h (backtrace_uncompress_lzma):
Define.
(backtrace_syminfo_to_full_callback): Define.
(backtrace_syminfo_to_full_error_callback): Define.
diff --git a/libsanitizer/libbacktrace/backtrace-rename.h 
b/libsanitizer/libbacktrace/backtrace-rename.h
index 2555fe508c2..2ec37a3307f 100644
--- a/libsanitizer/libbacktrace/backtrace-rename.h
+++ b/libsanitizer/libbacktrace/backtrace-rename.h
@@ -11,10 +11,13 @@
 #define backtrace_qsort __asan_backtrace_qsort
 #define backtrace_release_view __asan_backtrace_release_view
 #define backtrace_syminfo __asan_backtrace_syminfo
+#define backtrace_uncompress_lzma __asan_backtrace_uncompress_lzma
 #define backtrace_uncompress_zdebug __asan_backtrace_uncompress_zdebug
 #define backtrace_vector_finish __asan_backtrace_vector_finish
 #define backtrace_vector_grow __asan_backtrace_vector_grow
 #define backtrace_vector_release __asan_backtrace_vector_release
+#define backtrace_syminfo_to_full_callback 
__asan_backtrace_syminfo_to_full_callback
+#define backtrace_syminfo_to_full_error_callback 
__asan_backtrace_syminfo_to_full_error_callback
 
 #define cplus_demangle_builtin_types __asan_cplus_demangle_builtin_types
 #define cplus_demangle_fill_ctor __asan_cplus_demangle_fill_ctor


Re: libsanitizer patch committed: Update for libbacktrace changes

2020-09-21 Thread Ian Lance Taylor via Gcc-patches
On Mon, Sep 21, 2020 at 12:04 PM Ian Lance Taylor  wrote:
>
> Recent changes to libbacktrace have introduced a few more globally
> symbols.  These then need to be renamed in the libsanitizer copy.
> This patch does that.  Tested by configuring
> --with-build-config=bootstrap-asan and running a bootstrap.  Committed
> to mainline as obvious.
>
> Ian
>
> * libbacktrace/backtrace-rename.h (backtrace_uncompress_lzma):
> Define.
> (backtrace_syminfo_to_full_callback): Define.
> (backtrace_syminfo_to_full_error_callback): Define.


I forgot to mention that this fixes PR 97136.

Ian


libgo patch committed: Don't put golang.org packages in zstdpkglist.go

2020-09-21 Thread Ian Lance Taylor via Gcc-patches
This patch to libgo avoids putting golang.org packages in
zstdpkglist.go.  This ensures that internal/goroot.IsStandardPackage
does not treat golang.org packages as being in the standard library.
This fixes https://golang.org/issue/41499.  Committed to mainline and
GCC 10 branch.

Ian
507f392ade582742d2895cd8aea070f1a5b796a3
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 6b590f6fd94..f79a1f04201 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-6fd6418efb983827717f648a11bb5ca6fe93af30
+f2706d92d9560657333682a3de548f1f98e9f9b0
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/Makefile.am b/libgo/Makefile.am
index 9ce0cab9d6a..e3f08a2df39 100644
--- a/libgo/Makefile.am
+++ b/libgo/Makefile.am
@@ -620,7 +620,7 @@ s-zstdpkglist: Makefile
echo 'package goroot' > zstdpkglist.go.tmp
echo "" >> zstdpkglist.go.tmp
echo 'var stdpkg = map[string]bool{' >> zstdpkglist.go.tmp
-   echo $(libgo_go_objs) 'unsafe.lo' 'runtime/cgo.lo' | sed 
's|[a-z0-9_./]*_c\.lo||g' | sed 's|\([a-z0-9_./]*\)\.lo|"\1": true,|g' >> 
zstdpkglist.go.tmp
+   echo $(libgo_go_objs) 'unsafe.lo' 'runtime/cgo.lo' | sed 
's|[a-z0-9_./]*_c\.lo||g' | sed 's|golang\.org/[a-z0-9_./]*\.lo||g' | sed 
's|\([a-z0-9_./]*\)\.lo|"\1": true,|g' >> zstdpkglist.go.tmp
echo '}' >> zstdpkglist.go.tmp
$(SHELL) $(srcdir)/mvifdiff.sh zstdpkglist.go.tmp zstdpkglist.go
$(STAMP) $@


libgo patch committed: Recognize aixbigafMagic archives

2020-09-21 Thread Ian Lance Taylor via Gcc-patches
This libgo patch by Clément Chigot recognizes aixbigafMagic archives.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
1b785ecdc817ee14417beb1fd7389622fd8d035f
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index f79a1f04201..d8db888e4b6 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-f2706d92d9560657333682a3de548f1f98e9f9b0
+6f309797e4f7eed635950687e902a294126e6fc6
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/go/go/internal/gccgoimporter/importer.go 
b/libgo/go/go/internal/gccgoimporter/importer.go
index ff484a72fc9..391477d5a73 100644
--- a/libgo/go/go/internal/gccgoimporter/importer.go
+++ b/libgo/go/go/internal/gccgoimporter/importer.go
@@ -198,7 +198,7 @@ func GetImporter(searchpaths []string, initmap 
map[*types.Package]InitData) Impo
return
}
 
-   if magics == archiveMagic {
+   if magics == archiveMagic || magics == aixbigafMagic {
reader, err = arExportData(reader)
if err != nil {
return


Go patch committed: Finalize methods for type aliases of struct types

2020-09-21 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend finalizes methods for type aliases of
struct types.  Previously we would finalize the methods of the alias
type itself, but since its a type alias we really need to finalize the
methods of the aliased type.

This patch also handles method expressions of unnamed struct types.

The test case for both is https://golang.org/cl/251168.

This fixes https://golang.org/issue/38125.

Bootstrapped and tested on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
4e4b1f97342d9aa032591fb868318d8bead8dafa
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index d8db888e4b6..e4f8fac5ab3 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-6f309797e4f7eed635950687e902a294126e6fc6
+a59167c29d6ad2ddf533b3a12b365f72df0e1476
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 8bbc557c65f..0350e51d3a6 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -14529,21 +14529,19 @@ Selector_expression::lower_method_expression(Gogo* 
gogo)
   is_pointer = true;
   type = type->points_to();
 }
-  Named_type* nt = type->named_type();
-  if (nt == NULL)
-{
-  go_error_at(location,
-  ("method expression requires named type or "
-   "pointer to named type"));
-  return Expression::make_error(location);
-}
 
+  Named_type* nt = type->named_type();
+  Struct_type* st = type->struct_type();
   bool is_ambiguous;
-  Method* method = nt->method_function(name, &is_ambiguous);
+  Method* method = NULL;
+  if (nt != NULL)
+method = nt->method_function(name, &is_ambiguous);
+  else if (st != NULL)
+method = st->method_function(name, &is_ambiguous);
   const Typed_identifier* imethod = NULL;
   if (method == NULL && !is_pointer)
 {
-  Interface_type* it = nt->interface_type();
+  Interface_type* it = type->interface_type();
   if (it != NULL)
imethod = it->find_method(name);
 }
@@ -14551,16 +14549,28 @@ Selector_expression::lower_method_expression(Gogo* 
gogo)
   if ((method == NULL && imethod == NULL)
   || (left_type->named_type() != NULL && left_type->points_to() != NULL))
 {
-  if (!is_ambiguous)
-   go_error_at(location, "type %<%s%s%> has no method %<%s%>",
-is_pointer ? "*" : "",
-nt->message_name().c_str(),
-Gogo::message_name(name).c_str());
+  if (nt != NULL)
+   {
+ if (!is_ambiguous)
+   go_error_at(location, "type %<%s%s%> has no method %<%s%>",
+   is_pointer ? "*" : "",
+   nt->message_name().c_str(),
+   Gogo::message_name(name).c_str());
+ else
+   go_error_at(location, "method %<%s%s%> is ambiguous in type %<%s%>",
+   Gogo::message_name(name).c_str(),
+   is_pointer ? "*" : "",
+   nt->message_name().c_str());
+   }
   else
-   go_error_at(location, "method %<%s%s%> is ambiguous in type %<%s%>",
-Gogo::message_name(name).c_str(),
-is_pointer ? "*" : "",
-nt->message_name().c_str());
+   {
+ if (!is_ambiguous)
+   go_error_at(location, "type has no method %<%s%>",
+   Gogo::message_name(name).c_str());
+ else
+   go_error_at(location, "method %<%s%> is ambiguous",
+   Gogo::message_name(name).c_str());
+   }
   return Expression::make_error(location);
 }
 
@@ -14657,7 +14667,7 @@ Selector_expression::lower_method_expression(Gogo* gogo)
   Expression* ve = Expression::make_var_reference(vno, location);
   Expression* bm;
   if (method != NULL)
-bm = Type::bind_field_or_method(gogo, nt, ve, name, location);
+bm = Type::bind_field_or_method(gogo, type, ve, name, location);
   else
 bm = Expression::make_interface_field_reference(ve, name, location);
 
diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc
index 82d4c1fd54d..aef1c47d26e 100644
--- a/gcc/go/gofrontend/gogo.cc
+++ b/gcc/go/gofrontend/gogo.cc
@@ -3508,6 +3508,10 @@ Finalize_methods::type(Type* t)
 case Type::TYPE_NAMED:
   {
Named_type* nt = t->named_type();
+
+   if (nt->is_alias())
+ return TRAVERSE_CONTINUE;
+
Type* rt = nt->real_type();
if (rt->classification() != Type::TYPE_STRUCT)
  {


Go patch committed: Use runtime.eqtype for type switches on AIX

2020-09-22 Thread Ian Lance Taylor via Gcc-patches
This patch by Clément Chigot changes the Go frontend to call
runtime.eqtype for non-interface type switches on AIX.  All type
switch clauses must call runtime.eqtype if the linker isn't able to
merge type descriptors pointers. Previously, only interface-type
clauses were doing it.  This is for https://golang.org/issue/39276.
Bootstrapped and ran Go tests on x86_64-pc-linux-gnu.  Committed to
mainline.

Ian
bd68301dee0f1fd6419ab7e1e416f724dffe8bc4
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index e4f8fac5ab3..a8ba5a35e44 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-a59167c29d6ad2ddf533b3a12b365f72df0e1476
+b24062f0b2e8f6173731d5654afe0addf857270e
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/statements.cc b/gcc/go/gofrontend/statements.cc
index a059ee4d0d9..ad898070f6e 100644
--- a/gcc/go/gofrontend/statements.cc
+++ b/gcc/go/gofrontend/statements.cc
@@ -4627,7 +4627,8 @@ Type_case_clauses::Type_case_clause::traverse(Traverse* 
traverse)
 // statements.
 
 void
-Type_case_clauses::Type_case_clause::lower(Type* switch_val_type,
+Type_case_clauses::Type_case_clause::lower(Gogo* gogo,
+  Type* switch_val_type,
   Block* b,
   Temporary_statement* descriptor_temp,
   Unnamed_label* break_label,
@@ -4666,9 +4667,16 @@ Type_case_clauses::Type_case_clause::lower(Type* 
switch_val_type,
   Expression::make_nil(loc),
   loc);
   else if (type->interface_type() == NULL)
-cond = Expression::make_binary(OPERATOR_EQEQ, ref,
-   Expression::make_type_descriptor(type, 
loc),
-   loc);
+   {
+ if (!gogo->need_eqtype())
+   cond = Expression::make_binary(OPERATOR_EQEQ, ref,
+  
Expression::make_type_descriptor(type, loc),
+  loc);
+ else
+   cond = Runtime::make_call(Runtime::EQTYPE, loc, 2,
+ Expression::make_type_descriptor(type, 
loc),
+ ref);
+   }
   else
cond = Runtime::make_call(Runtime::IFACET2IP, loc, 2,
  Expression::make_type_descriptor(type, loc),
@@ -4826,7 +4834,8 @@ Type_case_clauses::check_duplicates() const
 // BREAK_LABEL is the label at the end of the type switch.
 
 void
-Type_case_clauses::lower(Type* switch_val_type, Block* b,
+Type_case_clauses::lower(Gogo* gogo, Type* switch_val_type,
+Block* b,
 Temporary_statement* descriptor_temp,
 Unnamed_label* break_label) const
 {
@@ -4838,7 +4847,7 @@ Type_case_clauses::lower(Type* switch_val_type, Block* b,
++p)
 {
   if (!p->is_default())
-   p->lower(switch_val_type, b, descriptor_temp, break_label,
+   p->lower(gogo, switch_val_type, b, descriptor_temp, break_label,
 &stmts_label);
   else
{
@@ -4850,7 +4859,7 @@ Type_case_clauses::lower(Type* switch_val_type, Block* b,
   go_assert(stmts_label == NULL);
 
   if (default_case != NULL)
-default_case->lower(switch_val_type, b, descriptor_temp, break_label,
+default_case->lower(gogo, switch_val_type, b, descriptor_temp, break_label,
NULL);
 }
 
@@ -4905,7 +4914,7 @@ Type_switch_statement::do_traverse(Traverse* traverse)
 // equality testing.
 
 Statement*
-Type_switch_statement::do_lower(Gogo*, Named_object*, Block* enclosing,
+Type_switch_statement::do_lower(Gogo* gogo, Named_object*, Block* enclosing,
Statement_inserter*)
 {
   const Location loc = this->location();
@@ -4943,7 +4952,7 @@ Type_switch_statement::do_lower(Gogo*, Named_object*, 
Block* enclosing,
   b->add_statement(s);
 
   if (this->clauses_ != NULL)
-this->clauses_->lower(val_type, b, descriptor_temp, this->break_label());
+this->clauses_->lower(gogo, val_type, b, descriptor_temp, 
this->break_label());
 
   s = Statement::make_unnamed_label_statement(this->break_label_);
   b->add_statement(s);
diff --git a/gcc/go/gofrontend/statements.h b/gcc/go/gofrontend/statements.h
index f1c6be9c98a..47092b4912a 100644
--- a/gcc/go/gofrontend/statements.h
+++ b/gcc/go/gofrontend/statements.h
@@ -2089,7 +2089,7 @@ class Type_case_clauses
 
   // Lower to if and goto statements.
   void
-  lower(Type*, Block*, Temporary_statement* descriptor_temp,
+  lower(Gogo*, Type*, Block*, Temporary_statement* descriptor_temp,
Unnamed_label* break_label) const;
 
   // Return true if these clauses may fall through to the statements
@@ -2138,7 +2138,7 @@ class Type_ca

Re: Go patch committed: Finalize methods for type aliases of struct types

2020-09-22 Thread Ian Lance Taylor via Gcc-patches
On Mon, Sep 21, 2020 at 3:54 PM Ian Lance Taylor  wrote:
>
> This patch to the Go frontend finalizes methods for type aliases of
> struct types.  Previously we would finalize the methods of the alias
> type itself, but since its a type alias we really need to finalize the
> methods of the aliased type.
>
> This patch also handles method expressions of unnamed struct types.
>
> The test case for both is https://golang.org/cl/251168.
>
> This fixes https://golang.org/issue/38125.
>
> Bootstrapped and tested on x86_64-pc-linux-gnu.  Committed to mainline.

This requires a change to one of the Go tests.  Updated like so,
committed to mainline.

Ian
diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue4458.go 
b/gcc/testsuite/go.test/test/fixedbugs/issue4458.go
index 820f18cb8d7..82b104a0fdf 100644
--- a/gcc/testsuite/go.test/test/fixedbugs/issue4458.go
+++ b/gcc/testsuite/go.test/test/fixedbugs/issue4458.go
@@ -16,5 +16,5 @@ func (T) foo() {}
 func main() {
av := T{}
pav := &av
-   (**T).foo(&pav) // ERROR "no method foo|requires named type or pointer 
to named"
+   (**T).foo(&pav) // ERROR "no method|requires named type or pointer to 
named"
 }


Re: libbacktrace patch committed: Avoid ambiguous binary search

2020-09-22 Thread Ian Lance Taylor via Gcc-patches
On Tue, Sep 8, 2020 at 6:22 PM Ian Lance Taylor  wrote:
>
> This patch to libbacktrace avoids ambiguous binary searches.
> Searching for a range match can cause the search order to not match
> the sort order, which can cause libbacktrace to miss matching entries.
> This patch allocates an extra entry at the end of function_addrs and
> unit_addrs vectors, so that we can safely compare to the next entry
> when searching.  It adjusts the matching code accordingly.  This fixes
> https://github.com/ianlancetaylor/libbacktrace/issues/44.
> Bootstrapped and ran libbacktrace and libgo tests on
> x86_64-pc-linux-gnu.  Committed to mainline.

I realized that this isn't quite right for the case where the PC value
we are looking up is equal to the low value in the array we are
searching.  In that case to ensure consistent results we have to step
forward to the end of the sequence of identical low values, and only
then step backward.  This patch implements that.  It also ensures that
the right thing happens if someone decides to look up the PC value -1.
Bootstrapped and ran libbacktrace and Go tests on x86_64-pc-linux-gnu.
Committed to mainline.

Ian

* dwarf.c (report_inlined_functions): Handle PC == -1 and PC ==
p->low.
(dwarf_lookup_pc): Likewise.
diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c
index 386701bffea..582f34bc816 100644
--- a/libbacktrace/dwarf.c
+++ b/libbacktrace/dwarf.c
@@ -3558,6 +3558,11 @@ report_inlined_functions (uintptr_t pc, struct function 
*function,
   if (function->function_addrs_count == 0)
 return 0;
 
+  /* Our search isn't safe if pc == -1, as that is the sentinel
+ value.  */
+  if (pc + 1 == 0)
+return 0;
+
   p = ((struct function_addrs *)
bsearch (&pc, function->function_addrs,
function->function_addrs_count,
@@ -3567,9 +3572,12 @@ report_inlined_functions (uintptr_t pc, struct function 
*function,
 return 0;
 
   /* Here pc >= p->low && pc < (p + 1)->low.  The function_addrs are
- sorted by low, so we are at the end of a range of function_addrs
- with the same low alue.  Walk backward and use the first range
- that includes pc.  */
+ sorted by low, so if pc > p->low we are at the end of a range of
+ function_addrs with the same low value.  If pc == p->low walk
+ forward to the end of the range with that low value.  Then walk
+ backward and use the first range that includes pc.  */
+  while (pc == (p + 1)->low)
+++p;
   match = NULL;
   while (1)
 {
@@ -3636,8 +3644,10 @@ dwarf_lookup_pc (struct backtrace_state *state, struct 
dwarf_data *ddata,
 
   *found = 1;
 
-  /* Find an address range that includes PC.  */
-  entry = (ddata->addrs_count == 0
+  /* Find an address range that includes PC.  Our search isn't safe if
+ PC == -1, as we use that as a sentinel value, so skip the search
+ in that case.  */
+  entry = (ddata->addrs_count == 0 || pc + 1 == 0
   ? NULL
   : bsearch (&pc, ddata->addrs, ddata->addrs_count,
  sizeof (struct unit_addrs), unit_addrs_search));
@@ -3649,9 +3659,12 @@ dwarf_lookup_pc (struct backtrace_state *state, struct 
dwarf_data *ddata,
 }
 
   /* Here pc >= entry->low && pc < (entry + 1)->low.  The unit_addrs
- are sorted by low, so we are at the end of a range of unit_addrs
- with the same low value.  Walk backward and use the first range
- that includes pc.  */
+ are sorted by low, so if pc > p->low we are at the end of a range
+ of unit_addrs with the same low value.  If pc == p->low walk
+ forward to the end of the range with that low value.  Then walk
+ backward and use the first range that includes pc.  */
+  while (pc == (entry + 1)->low)
+++entry;
   found_entry = 0;
   while (1)
 {
@@ -3832,9 +3845,12 @@ dwarf_lookup_pc (struct backtrace_state *state, struct 
dwarf_data *ddata,
 return callback (data, pc, ln->filename, ln->lineno, NULL);
 
   /* Here pc >= p->low && pc < (p + 1)->low.  The function_addrs are
- sorted by low, so we are at the end of a range of function_addrs
- with the same low alue.  Walk backward and use the first range
- that includes pc.  */
+ sorted by low, so if pc > p->low we are at the end of a range of
+ function_addrs with the same low value.  If pc == p->low walk
+ forward to the end of the range with that low value.  Then walk
+ backward and use the first range that includes pc.  */
+  while (pc == (p + 1)->low)
+++p;
   fmatch = NULL;
   while (1)
 {


libgo patch committed: Fix build errors on AIX

2020-09-22 Thread Ian Lance Taylor via Gcc-patches
This libgo patch by Clément Chigot fixes build errors on AIX.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
63cd53d2f5da07856340bbea11ee09ab1125e8c0
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index a8ba5a35e44..d17d39702c8 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-b24062f0b2e8f6173731d5654afe0addf857270e
+5605a0727d3395becba1fbd4447807073984ec13
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/go/internal/cpu/cpu_no_init.go 
b/libgo/go/internal/cpu/cpu_no_init.go
index fb381e1ce2d..e7ff87383c3 100644
--- a/libgo/go/internal/cpu/cpu_no_init.go
+++ b/libgo/go/internal/cpu/cpu_no_init.go
@@ -6,6 +6,7 @@
 // +build !amd64
 // +build !arm
 // +build !arm64
+// +build !ppc
 // +build !ppc64
 // +build !ppc64le
 // +build !s390x
diff --git a/libgo/go/internal/cpu/cpu_ppc64x.go 
b/libgo/go/internal/cpu/cpu_ppc64x.go
deleted file mode 100644
index b726cc86d52..000
--- a/libgo/go/internal/cpu/cpu_ppc64x.go
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2017 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build ppc64 ppc64le
-
-package cpu
-
-// ppc64x doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2.
-// These are initialized by archauxv and should not be changed after they are
-// initialized.
-// On aix/ppc64, these values are initialized early in the runtime in 
runtime/os_aix.go.
-var HWCap uint
-var HWCap2 uint
-
-// HWCAP/HWCAP2 bits. These are exposed by the kernel.
-const (
-   // ISA Level
-   PPC_FEATURE2_ARCH_2_07 = 0x8000
-   PPC_FEATURE2_ARCH_3_00 = 0x0080
-
-   // CPU features
-   PPC_FEATURE2_DARN = 0x0020
-   PPC_FEATURE2_SCV  = 0x0010
-)
-
-func doinit() {
-   options = []option{
-   {Name: "darn", Feature: &PPC64.HasDARN},
-   {Name: "scv", Feature: &PPC64.HasSCV},
-   {Name: "power9", Feature: &PPC64.IsPOWER9},
-   {Name: "power8", Feature: &PPC64.IsPOWER8},
-   }
-
-   // HWCAP2 feature bits
-   PPC64.IsPOWER8 = isSet(HWCap2, PPC_FEATURE2_ARCH_2_07)
-   PPC64.IsPOWER9 = isSet(HWCap2, PPC_FEATURE2_ARCH_3_00)
-   PPC64.HasDARN = isSet(HWCap2, PPC_FEATURE2_DARN)
-   PPC64.HasSCV = isSet(HWCap2, PPC_FEATURE2_SCV)
-}
-
-func isSet(hwc uint, value uint) bool {
-   return hwc&value != 0
-}
diff --git a/libgo/go/internal/cpu/cpu_ppcx.go 
b/libgo/go/internal/cpu/cpu_ppcx.go
new file mode 100644
index 000..56ff87524ee
--- /dev/null
+++ b/libgo/go/internal/cpu/cpu_ppcx.go
@@ -0,0 +1,44 @@
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build ppc ppc64 ppc64le
+
+package cpu
+
+// ppc64x doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2.
+// These are initialized by archauxv and should not be changed after they are
+// initialized.
+// On aix/ppc64, these values are initialized early in the runtime in 
runtime/os_aix.go.
+var HWCap uint
+var HWCap2 uint
+
+// HWCAP/HWCAP2 bits. These are exposed by the kernel.
+const (
+   // ISA Level
+   PPC_FEATURE2_ARCH_2_07 = 0x8000
+   PPC_FEATURE2_ARCH_3_00 = 0x0080
+
+   // CPU features
+   PPC_FEATURE2_DARN = 0x0020
+   PPC_FEATURE2_SCV  = 0x0010
+)
+
+func doinit() {
+   options = []option{
+   {Name: "darn", Feature: &PPC64.HasDARN},
+   {Name: "scv", Feature: &PPC64.HasSCV},
+   {Name: "power9", Feature: &PPC64.IsPOWER9},
+   {Name: "power8", Feature: &PPC64.IsPOWER8},
+   }
+
+   // HWCAP2 feature bits
+   PPC64.IsPOWER8 = isSet(HWCap2, PPC_FEATURE2_ARCH_2_07)
+   PPC64.IsPOWER9 = isSet(HWCap2, PPC_FEATURE2_ARCH_3_00)
+   PPC64.HasDARN = isSet(HWCap2, PPC_FEATURE2_DARN)
+   PPC64.HasSCV = isSet(HWCap2, PPC_FEATURE2_SCV)
+}
+
+func isSet(hwc uint, value uint) bool {
+   return hwc&value != 0
+}
diff --git a/libgo/go/net/interface_aix.go b/libgo/go/net/interface_aix.go
index f57c5ff6622..bd5538699bb 100644
--- a/libgo/go/net/interface_aix.go
+++ b/libgo/go/net/interface_aix.go
@@ -33,8 +33,6 @@ const _RTAX_NETMASK = 2
 const _RTAX_IFA = 5
 const _RTAX_MAX = 8
 
-const _SIOCGIFMTU = -0x3fd796aa
-
 func getIfList() ([]byte, error) {
needed, err := syscall.Getkerninfo(_KINFO_RT_IFLIST, 0, 0, 0)
if err != nil {
diff --git a/libgo/go/runtime/os_aix.go b/libgo/go/runtime/os_aix.go
index b337330c8f2..951aeb6cffd 100644
--- a/libgo/go/runtime/os_aix.go
+++ b/libgo/go/runtime/os_aix.go
@@ -46,7 +46,7 @@ func clock_gettime(clock_id int64, timeout *timespec) int32
 
 //go:nosplit
 func semacreate(mp *m) {
-   if mp.mos.waitsema != 0 {
+   if mp.waitsema != 0 {

libgo patch committed: Remove ptrace for ppc64 AIX

2020-09-22 Thread Ian Lance Taylor via Gcc-patches
This libgo patch by Clément Chigot removes the ptrace syscall on ppc64
AIX.  ptrace is available only for 32 bits programs.  Bootstrapped and
ran Go testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
bbc644a3e0d9da37d0987918be5764d17a6069c4
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index d17d39702c8..59b580f0956 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-5605a0727d3395becba1fbd4447807073984ec13
+99ab98d2ed8fa8a33947c52925f89b344d7cb8ae
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/go/syscall/libcall_aix.go b/libgo/go/syscall/libcall_aix.go
index 8d9f59eb62f..27b469e1e47 100644
--- a/libgo/go/syscall/libcall_aix.go
+++ b/libgo/go/syscall/libcall_aix.go
@@ -16,9 +16,6 @@ const SYS_EXECVE = 0
 //sys  Openat(dirfd int, path string, flags int, mode uint32) (fd int, err 
error)
 //open64at(dirfd _C_int, path *byte, flags _C_int, mode Mode_t) _C_int
 
-//sys  ptrace(request int, id int, addr uintptr, data int, buff uintptr) (val 
int)
-//ptrace(request _C_int, id int, addr uintptr, data _C_int, buff *byte) _C_int
-
 //sys  ptrace64(request int, id int64, addr int64, data int, buff uintptr) 
(err error)
 //ptrace64(request _C_int, id int64, addr int64, data _C_int, buff *byte) 
_C_int
 
diff --git a/libgo/go/syscall/syscall_aix_ppc.go 
b/libgo/go/syscall/syscall_aix_ppc.go
index 83ed1e64c3a..2e89081 100644
--- a/libgo/go/syscall/syscall_aix_ppc.go
+++ b/libgo/go/syscall/syscall_aix_ppc.go
@@ -8,6 +8,9 @@ package syscall
 
 import "unsafe"
 
+//sys  ptrace(request int, id int, addr uintptr, data int, buff uintptr) (val 
int)
+//ptrace(request _C_int, id int, addr uintptr, data _C_int, buff *byte) _C_int
+
 // AIX does not define a specific structure but instead uses separate
 // ptrace calls for the different registers.
 type PtraceRegs struct {


libgo patch committed: Fix syscall tests that call Ioctl on AIX

2020-09-22 Thread Ian Lance Taylor via Gcc-patches
This libgo patch by Clément Chigot fixes the syscall package tests
that call Ioctl on AIX, by calling raw_ioctl_ptr rather than syscall.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
e884ced05231a04b1a3c70ece7237d0b1eeebf19
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 59b580f0956..5d26b7e2da1 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-99ab98d2ed8fa8a33947c52925f89b344d7cb8ae
+cfee06e20a172753552b1515dd3a4fde5d5cad7b
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/go/syscall/export_aix_test.go 
b/libgo/go/syscall/export_aix_test.go
new file mode 100644
index 000..044337b9993
--- /dev/null
+++ b/libgo/go/syscall/export_aix_test.go
@@ -0,0 +1,16 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build aix
+
+package syscall
+
+import (
+   "unsafe"
+)
+
+func Ioctl(fd, req, arg uintptr) (err Errno) {
+   _, err = raw_ioctl_ptr(int(fd), req, unsafe.Pointer(arg))
+   return err
+}
diff --git a/libgo/go/syscall/export_unix_test.go 
b/libgo/go/syscall/export_unix_test.go
index dc11f455de0..4d67be9ac2d 100644
--- a/libgo/go/syscall/export_unix_test.go
+++ b/libgo/go/syscall/export_unix_test.go
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build aix darwin dragonfly freebsd hurd linux netbsd openbsd solaris
+// +build darwin dragonfly freebsd hurd linux netbsd openbsd solaris
 
 package syscall
 


libgo patch committed: Update to Go1.15.2 release

2020-09-23 Thread Ian Lance Taylor via Gcc-patches
This patch updates libgo to the Go1.15.2 release.  Bootstrapped and
ran Go testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
928fa8ccc0e1ef8f3861a28b5ad2d2d220f7219d
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 5d26b7e2da1..f51dac55365 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-cfee06e20a172753552b1515dd3a4fde5d5cad7b
+6a7648c97c3e0cdbecbec7e760b30246521a6d90
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/MERGE b/libgo/MERGE
index a84f1e38f9d..cfbf488398e 100644
--- a/libgo/MERGE
+++ b/libgo/MERGE
@@ -1,4 +1,4 @@
-c4f8cb43caf0bcd0c730d7d04a3fce129393cecc
+9706f510a5e2754595d716bd64be8375997311fb
 
 The first line of this file holds the git revision number of the
 last merge done from the master library sources.
diff --git a/libgo/VERSION b/libgo/VERSION
index 2d962d8cd27..c19def3de44 100644
--- a/libgo/VERSION
+++ b/libgo/VERSION
@@ -1 +1 @@
-go1.15rc2
+go1.15.2
diff --git a/libgo/go/cmd/go/internal/test/test.go 
b/libgo/go/cmd/go/internal/test/test.go
index 873a76aa380..77bfc11fe9a 100644
--- a/libgo/go/cmd/go/internal/test/test.go
+++ b/libgo/go/cmd/go/internal/test/test.go
@@ -1079,9 +1079,13 @@ func (c *runCache) builderRunTest(b *work.Builder, a 
*work.Action) error {
}
 
var stdout io.Writer = os.Stdout
+   var err error
if testJSON {
json := test2json.NewConverter(lockedStdout{}, 
a.Package.ImportPath, test2json.Timestamp)
-   defer json.Close()
+   defer func() {
+   json.Exited(err)
+   json.Close()
+   }()
stdout = json
}
 
@@ -1185,7 +1189,7 @@ func (c *runCache) builderRunTest(b *work.Builder, a 
*work.Action) error {
}
 
t0 := time.Now()
-   err := cmd.Start()
+   err = cmd.Start()
 
// This is a last-ditch deadline to detect and
// stop wedged test binaries, to keep the builders
diff --git a/libgo/go/cmd/go/internal/test/testflag.go 
b/libgo/go/cmd/go/internal/test/testflag.go
index 1ff34f7445c..4f0a8924f12 100644
--- a/libgo/go/cmd/go/internal/test/testflag.go
+++ b/libgo/go/cmd/go/internal/test/testflag.go
@@ -214,9 +214,13 @@ func testFlags(args []string) (packageNames, passToTest 
[]string) {
 
explicitArgs := make([]string, 0, len(args))
inPkgList := false
+   afterFlagWithoutValue := false
for len(args) > 0 {
f, remainingArgs, err := cmdflag.ParseOne(&CmdTest.Flag, args)
 
+   wasAfterFlagWithoutValue := afterFlagWithoutValue
+   afterFlagWithoutValue = false // provisionally
+
if errors.Is(err, flag.ErrHelp) {
exitWithUsage()
}
@@ -233,10 +237,24 @@ func testFlags(args []string) (packageNames, passToTest 
[]string) {
if nf := (cmdflag.NonFlagError{}); errors.As(err, &nf) {
if !inPkgList && packageNames != nil {
// We already saw the package list previously, 
and this argument is not
-   // a flag, so it — and everything after it — 
must be a literal argument
-   // to the test binary.
-   explicitArgs = append(explicitArgs, args...)
-   break
+   // a flag, so it — and everything after it — 
must be either a value for
+   // a preceding flag or a literal argument to 
the test binary.
+   if wasAfterFlagWithoutValue {
+   // This argument could syntactically be 
a flag value, so
+   // optimistically assume that it is and 
keep looking for go command
+   // flags after it.
+   //
+   // (If we're wrong, we'll at least be 
consistent with historical
+   // behavior; see 
https://golang.org/issue/40763.)
+   explicitArgs = append(explicitArgs, 
nf.RawArg)
+   args = remainingArgs
+   continue
+   } else {
+   // This argument syntactically cannot 
be a flag value, so it must be a
+   // positional argument, and so must 
everything after it.
+   explicitArgs = append(explicitArgs, 
args...)
+   break
+   }
}
 
inPkgList = true
@@ -272,6 +290,9 @@ func testFlags(args []string) (packageNames, passToTes

libgo patch committed: Don't build __go_ptrace on AIX

2020-09-24 Thread Ian Lance Taylor via Gcc-patches
This libgo patch by Clément Chigot removes __go_ptrace on AIX.  AIX
ptrace syscalls doesn't have the same semantic than the glibc one.
The syscall package is already handling it correctly so disable the
new __go_ptrace C function for AIX.  Bootstrapped and ran Go testsuite
on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
763460e4776ce2d1ca2fe87678fc233f27f70e64
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index f51dac55365..daa0d2d6177 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-6a7648c97c3e0cdbecbec7e760b30246521a6d90
+2357468ae9b071de0e2ebe6574d78572967b7183
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/runtime/go-varargs.c b/libgo/runtime/go-varargs.c
index f9270a97bfd..9cb4a7e79bd 100644
--- a/libgo/runtime/go-varargs.c
+++ b/libgo/runtime/go-varargs.c
@@ -114,7 +114,9 @@ __go_syscall6(uintptr_t flag, uintptr_t a1, uintptr_t a2, 
uintptr_t a3,
 
 #endif
 
-#ifdef HAVE_SYS_PTRACE_H
+// AIX ptrace is really different from Linux ptrace. Let syscall
+// package handles it.
+#if defined(HAVE_SYS_PTRACE_H) && !defined(_AIX)
 
 // Despite documented appearances, this is actually implemented as
 // a variadic function within glibc.


libbacktrace patch committed: Only use dsymutil with Mach-O

2020-09-28 Thread Ian Lance Taylor via Gcc-patches
This patch changes the libbacktrace tests to only run dsymutil when
building for Mach-O.  This should fix GCC PR 97227.  Bootstrapped and
ran libbacktrace tests on x86_64-pc-linux-gnu.  Committed to mainline.

Ian

PR libbacktrace/97227
* configure.ac (USE_DSYMUTIL): Define instead of HAVE_DSYMUTIL.
* Makefile.am: Change all uses of HAVE_DSYMUTIL to USE_DSYMUTIL.
* configure: Regenerate.
* Makefile.in: Regenerate.
diff --git a/libbacktrace/Makefile.am b/libbacktrace/Makefile.am
index 4d349386c9b..f7e8ca2cf5c 100644
--- a/libbacktrace/Makefile.am
+++ b/libbacktrace/Makefile.am
@@ -100,12 +100,12 @@ check_DATA =
 # Flags to use when compiling test programs.
 libbacktrace_TEST_CFLAGS = $(EXTRA_FLAGS) $(WARN_FLAGS) -g
 
-if HAVE_DSYMUTIL
+if USE_DSYMUTIL
 
 %.dSYM: %
$(DSYMUTIL) $<
 
-endif HAVE_DSYMUTIL
+endif USE_DSYMUTIL
 
 if NATIVE
 check_LTLIBRARIES = libbacktrace_alloc.la
@@ -237,9 +237,9 @@ allocfail.sh: allocfail
 
 TESTS += allocfail.sh
 
-if HAVE_DSYMUTIL
+if USE_DSYMUTIL
 check_DATA += allocfail.dSYM
-endif HAVE_DSYMUTIL
+endif USE_DSYMUTIL
 
 if HAVE_ELF
 if HAVE_OBJCOPY_DEBUGLINK
@@ -273,9 +273,9 @@ btest_LDADD = libbacktrace.la
 
 BUILDTESTS += btest
 
-if HAVE_DSYMUTIL
+if USE_DSYMUTIL
 check_DATA += btest.dSYM
-endif HAVE_DSYMUTIL
+endif USE_DSYMUTIL
 
 if HAVE_ELF
 
@@ -293,9 +293,9 @@ btest_alloc_LDADD = libbacktrace_alloc.la
 
 BUILDTESTS += btest_alloc
 
-if HAVE_DSYMUTIL
+if USE_DSYMUTIL
 check_DATA += btest_alloc.dSYM
-endif HAVE_DSYMUTIL
+endif USE_DSYMUTIL
 
 if HAVE_DWZ
 
@@ -323,9 +323,9 @@ stest_LDADD = libbacktrace.la
 
 BUILDTESTS += stest
 
-if HAVE_DSYMUTIL
+if USE_DSYMUTIL
 check_DATA += stest.dSYM
-endif HAVE_DSYMUTIL
+endif USE_DSYMUTIL
 
 stest_alloc_SOURCES = $(stest_SOURCES)
 stest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS)
@@ -333,9 +333,9 @@ stest_alloc_LDADD = libbacktrace_alloc.la
 
 BUILDTESTS += stest_alloc
 
-if HAVE_DSYMUTIL
+if USE_DSYMUTIL
 check_DATA += stest_alloc.dSYM
-endif HAVE_DSYMUTIL
+endif USE_DSYMUTIL
 
 if HAVE_ELF
 
@@ -366,17 +366,17 @@ edtest_LDADD = libbacktrace.la
 
 BUILDTESTS += edtest
 
-if HAVE_DSYMUTIL
+if USE_DSYMUTIL
 check_DATA += edtest.dSYM
-endif HAVE_DSYMUTIL
+endif USE_DSYMUTIL
 
 edtest_alloc_SOURCES = $(edtest_SOURCES)
 edtest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 edtest_alloc_LDADD = libbacktrace_alloc.la
 
-if HAVE_DSYMUTIL
+if USE_DSYMUTIL
 check_DATA += edtest_alloc.dSYM
-endif HAVE_DSYMUTIL
+endif USE_DSYMUTIL
 
 BUILDTESTS += edtest_alloc
 
@@ -394,9 +394,9 @@ ttest_SOURCES = ttest.c testlib.c
 ttest_CFLAGS = $(libbacktrace_TEST_CFLAGS) -pthread
 ttest_LDADD = libbacktrace.la
 
-if HAVE_DSYMUTIL
+if USE_DSYMUTIL
 check_DATA += ttest.dSYM
-endif HAVE_DSYMUTIL
+endif USE_DSYMUTIL
 
 BUILDTESTS += ttest_alloc
 
@@ -404,9 +404,9 @@ ttest_alloc_SOURCES = $(ttest_SOURCES)
 ttest_alloc_CFLAGS = $(ttest_CFLAGS)
 ttest_alloc_LDADD = libbacktrace_alloc.la
 
-if HAVE_DSYMUTIL
+if USE_DSYMUTIL
 check_DATA += ttest_alloc.dSYM
-endif HAVE_DSYMUTIL
+endif USE_DSYMUTIL
 
 endif HAVE_PTHREAD
 
@@ -462,9 +462,9 @@ dwarf5_LDADD = libbacktrace.la
 
 BUILDTESTS += dwarf5
 
-if HAVE_DSYMUTIL
+if USE_DSYMUTIL
 check_DATA += dwarf5.dSYM
-endif HAVE_DSYMUTIL
+endif USE_DSYMUTIL
 
 dwarf5_alloc_SOURCES = $(dwarf5_SOURCES)
 dwarf5_alloc_CFLAGS = $(dwarf5_CFLAGS)
@@ -472,9 +472,9 @@ dwarf5_alloc_LDADD = libbacktrace_alloc.la
 
 BUILDTESTS += dwarf5_alloc
 
-if HAVE_DSYMUTIL
+if USE_DSYMUTIL
 check_DATA += dwarf5_alloc.dSYM
-endif HAVE_DSYMUTIL
+endif USE_DSYMUTIL
 
 endif
 
diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac
index 0659ea60484..ec456bf4a1f 100644
--- a/libbacktrace/configure.ac
+++ b/libbacktrace/configure.ac
@@ -510,7 +510,7 @@ AM_CONDITIONAL(HAVE_OBJCOPY_DEBUGLINK, test 
"$libbacktrace_cv_objcopy_debuglink"
 
 AC_ARG_VAR(DSYMUTIL, [location of dsymutil])
 AC_CHECK_PROG(DSYMUTIL, dsymutil, dsymutil)
-AM_CONDITIONAL(HAVE_DSYMUTIL, test -n "${DSYMUTIL}")
+AM_CONDITIONAL(USE_DSYMUTIL, test -n "${DSYMUTIL}" -a "$FORMAT_FILE" = 
"macho.lo")
 
 AC_ARG_VAR(NM, [location of nm])
 AC_CHECK_PROG(NM, nm, nm)


libbacktrace patch committed: Create mtest.dsym

2020-09-28 Thread Ian Lance Taylor via Gcc-patches
This libbacktrace patch creates mtest.dsym when using dsymutil.  This
is for PR 97082, but it probably doesn't fix the PR.  Bootstrapped and
ran libbacktrace tests on x86_64-pc-linux-gnu.  Committed to mainline.

Ian

PR libbacktrace/97082
* Makefile.am (check_DATA): Add mtest.dSYM if USE_DSYMUTIL.
* Makefile.in: Regenerate.
diff --git a/libbacktrace/Makefile.am b/libbacktrace/Makefile.am
index f7e8ca2cf5c..5899a2157f4 100644
--- a/libbacktrace/Makefile.am
+++ b/libbacktrace/Makefile.am
@@ -484,6 +484,10 @@ mtest_LDADD = libbacktrace.la
 
 BUILDTESTS += mtest
 
+if USE_DSYMUTIL
+check_DATA += mtest.dSYM
+endif USE_DSYMUTIL
+
 if HAVE_MINIDEBUG
 
 TESTS += mtest_minidebug


Re: [PATCH] New patch for the port of gccgo to GNU/Hurd

2020-09-28 Thread Ian Lance Taylor via Gcc-patches
On Fri, Sep 25, 2020 at 8:04 AM Svante Signell  wrote:
>
> Latest Debian snapshot of gcc (20200917-1) FTBFS due to a missing hurd
> entry in the // +build line of libgo/go/net/fd_posix.go. Attached is a
> patch for that missing entry.

Thanks.  Committed to mainline.

Ian


libgo patch committed: Add 32-bit RISC-V support

2020-09-30 Thread Ian Lance Taylor via Gcc-patches
This libgo patch by Maciej W. Rozycki adds 32-bit RISC-V support.
Bootstrapped and ran Go tests on x86_64-pc-linux-gnu.  Committed to
mainline.

Ian
a119b20263517656379c4833a3341031a6d58dc4
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 314ffd2efab..8d9fda54619 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-9e55baf44ab63ba06af0b57038e7b3aab8216222
+c9c084bce713e258721e12041a351ec8ad33ad17
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/configure.ac b/libgo/configure.ac
index abc58b87b53..f15f8d830bb 100644
--- a/libgo/configure.ac
+++ b/libgo/configure.ac
@@ -342,8 +342,14 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([
 [GOARCH=ppc64le],
 [GOARCH=ppc64])])
 ;;
-  riscv64-*-*)
-GOARCH=riscv64
+  riscv*-*-*)
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([
+#if __riscv_xlen == 64
+#error 64-bit
+#endif
+])],
+[GOARCH=riscv],
+[GOARCH=riscv64])
 ;;
   s390*-*-*)
 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
diff --git a/libgo/go/cmd/cgo/main.go b/libgo/go/cmd/cgo/main.go
index 80f35681d75..6de6d69ce6c 100644
--- a/libgo/go/cmd/cgo/main.go
+++ b/libgo/go/cmd/cgo/main.go
@@ -184,6 +184,7 @@ var ptrSizeMap = map[string]int64{
"ppc": 4,
"ppc64":   8,
"ppc64le": 8,
+   "riscv":   4,
"riscv64": 8,
"s390":4,
"s390x":   8,
@@ -210,6 +211,7 @@ var intSizeMap = map[string]int64{
"ppc": 4,
"ppc64":   8,
"ppc64le": 8,
+   "riscv":   4,
"riscv64": 8,
"s390":4,
"s390x":   8,
diff --git a/libgo/go/cmd/go/testdata/script/link_syso_issue33139.txt 
b/libgo/go/cmd/go/testdata/script/link_syso_issue33139.txt
index 46b0ef4200e..3030ee924ff 100644
--- a/libgo/go/cmd/go/testdata/script/link_syso_issue33139.txt
+++ b/libgo/go/cmd/go/testdata/script/link_syso_issue33139.txt
@@ -8,8 +8,9 @@
 # See: https://github.com/golang/go/issues/8912
 [linux] [ppc64] skip
 
-# External linking is not supported on linux/riscv64.
+# External linking is not supported on linux/riscv, linux/riscv64.
 # See: https://github.com/golang/go/issues/36739
+[linux] [riscv] skip
 [linux] [riscv64] skip
 
 cc -c -o syso/objTestImpl.syso syso/src/objTestImpl.c
diff --git a/libgo/go/cmd/internal/sys/arch.go 
b/libgo/go/cmd/internal/sys/arch.go
index e8687363def..60a3b3c8ecd 100644
--- a/libgo/go/cmd/internal/sys/arch.go
+++ b/libgo/go/cmd/internal/sys/arch.go
@@ -19,6 +19,7 @@ const (
MIPS
MIPS64
PPC64
+   RISCV
RISCV64
S390X
Wasm
@@ -143,6 +144,15 @@ var ArchPPC64LE = &Arch{
MinLC: 4,
 }
 
+var ArchRISCV = &Arch{
+   Name:  "riscv",
+   Family:RISCV,
+   ByteOrder: binary.LittleEndian,
+   PtrSize:   4,
+   RegSize:   4,
+   MinLC: 4,
+}
+
 var ArchRISCV64 = &Arch{
Name:  "riscv64",
Family:RISCV64,
@@ -181,6 +191,7 @@ var Archs = [...]*Arch{
ArchMIPS64LE,
ArchPPC64,
ArchPPC64LE,
+   ArchRISCV,
ArchRISCV64,
ArchS390X,
ArchWasm,
diff --git a/libgo/go/debug/elf/file.go b/libgo/go/debug/elf/file.go
index b9a8b1e0cbb..48178d480d7 100644
--- a/libgo/go/debug/elf/file.go
+++ b/libgo/go/debug/elf/file.go
@@ -617,6 +617,8 @@ func (f *File) applyRelocations(dst []byte, rels []byte) 
error {
return f.applyRelocationsMIPS(dst, rels)
case f.Class == ELFCLASS64 && f.Machine == EM_MIPS:
return f.applyRelocationsMIPS64(dst, rels)
+   case f.Class == ELFCLASS32 && f.Machine == EM_RISCV:
+   return f.applyRelocationsRISCV(dst, rels)
case f.Class == ELFCLASS64 && f.Machine == EM_RISCV:
return f.applyRelocationsRISCV64(dst, rels)
case f.Class == ELFCLASS64 && f.Machine == EM_S390:
@@ -1008,6 +1010,47 @@ func (f *File) applyRelocationsMIPS64(dst []byte, rels 
[]byte) error {
return nil
 }
 
+func (f *File) applyRelocationsRISCV(dst []byte, rels []byte) error {
+   // 12 is the size of Rela32.
+   if len(rels)%12 != 0 {
+   return errors.New("length of relocation section is not a 
multiple of 12")
+   }
+
+   symbols, _, err := f.getSymbols(SHT_SYMTAB)
+   if err != nil {
+   return err
+   }
+
+   b := bytes.NewReader(rels)
+   var rela Rela32
+
+   for b.Len() > 0 {
+   binary.Read(b, f.ByteOrder, &rela)
+   symNo := rela.Info >> 8
+   t := R_RISCV(rela.Info & 0xff)
+
+   if symNo == 0 || symNo > uint32(len(symbols)) {
+   continue
+   }
+   sym := &symbols[symNo-1]
+   needed, val := relocSymbolTargetOK(sym)
+   if !needed {
+   continue
+   }
+
+   switch t {
+   case R_RISCV_3

Go patch committed: Set varargs correctly for type of method expression

2020-10-01 Thread Ian Lance Taylor via Gcc-patches
This Go frontend patch set varargs correctly for the type of method
expression.  This fixes https://golang.org/issue/41737.  Bootstrapped
and ran Go testsuite on x86_64-pc-linux-gnu.  Committed to mainline
and GCC 10 branch.

Ian
8e23cd3a2d23ad851938bf7015fc97539d65a8c6
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 8d9fda54619..94827406df1 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-c9c084bce713e258721e12041a351ec8ad33ad17
+801c458a562d22260ff176c26d65639dd32c8a90
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc
index 7f65b4a5db2..e7a742f6366 100644
--- a/gcc/go/gofrontend/types.cc
+++ b/gcc/go/gofrontend/types.cc
@@ -5350,8 +5350,12 @@ Function_type::copy_with_receiver_as_param(bool 
want_pointer_receiver) const
   ++p)
new_params->push_back(*p);
 }
-  return Type::make_function_type(NULL, new_params, this->results_,
- this->location_);
+  Function_type* ret = Type::make_function_type(NULL, new_params,
+   this->results_,
+   this->location_);
+  if (this->is_varargs_)
+ret->set_is_varargs();
+  return ret;
 }
 
 // Make a copy of a function type ignoring any receiver and adding a
diff --git a/libgo/go/reflect/all_test.go b/libgo/go/reflect/all_test.go
index ee37359814b..68efab6e145 100644
--- a/libgo/go/reflect/all_test.go
+++ b/libgo/go/reflect/all_test.go
@@ -2396,8 +2396,14 @@ func TestVariadicMethodValue(t *testing.T) {
points := []Point{{20, 21}, {22, 23}, {24, 25}}
want := int64(p.TotalDist(points[0], points[1], points[2]))
 
+   // Variadic method of type.
+   tfunc := TypeOf((func(Point, ...Point) int)(nil))
+   if tt := TypeOf(p).Method(4).Type; tt != tfunc {
+   t.Errorf("Variadic Method Type from TypeOf is %s; want %s", tt, 
tfunc)
+   }
+
// Curried method of value.
-   tfunc := TypeOf((func(...Point) int)(nil))
+   tfunc = TypeOf((func(...Point) int)(nil))
v := ValueOf(p).Method(4)
if tt := v.Type(); tt != tfunc {
t.Errorf("Variadic Method Type is %s; want %s", tt, tfunc)


Re: [PATCH] lto: fix LTO debug sections copying.

2020-10-05 Thread Ian Lance Taylor via Gcc-patches
On Mon, Oct 5, 2020 at 9:09 AM Martin Liška  wrote:
>
> The previous patch was not correct. This one should be.
>
> Ready for master?

I don't understand why this code uses symtab_indices_shndx at all.
There should only be one SHT_SYMTAB_SHNDX section.  There shouldn't be
any need for the symtab_indices_shndx vector.

But in any case this patch looks OK.

Thanks.

Ian


Go patch committed: correct file reading logic in Stream_from_file

2020-10-05 Thread Ian Lance Taylor via Gcc-patches
This Go frontend patch by Nikhil Benesch fixes the file reading logic
in the Stream_from_file class.  That class is almost never used, and I
guess nobody noticed these problems.  Bootstrapped and ran Go
testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
500c2690e24054730a2ecf9989720e9d501c9eb1
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 94827406df1..701b2d427e3 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-801c458a562d22260ff176c26d65639dd32c8a90
+d00febdab0535546ccbf1ef634be1f23b09c8b77
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/import.cc b/gcc/go/gofrontend/import.cc
index c63ae24f533..081afefa083 100644
--- a/gcc/go/gofrontend/import.cc
+++ b/gcc/go/gofrontend/import.cc
@@ -1487,7 +1487,7 @@ Stream_from_file::~Stream_from_file()
 bool
 Stream_from_file::do_peek(size_t length, const char** bytes)
 {
-  if (this->data_.length() <= length)
+  if (this->data_.length() >= length)
 {
   *bytes = this->data_.data();
   return true;
@@ -1504,7 +1504,7 @@ Stream_from_file::do_peek(size_t length, const char** 
bytes)
   return false;
 }
 
-  if (lseek(this->fd_, - got, SEEK_CUR) != 0)
+  if (lseek(this->fd_, - got, SEEK_CUR) < 0)
 {
   if (!this->saw_error())
go_fatal_error(Linemap::unknown_location(), "lseek failed: %m");
@@ -1524,7 +1524,7 @@ Stream_from_file::do_peek(size_t length, const char** 
bytes)
 void
 Stream_from_file::do_advance(size_t skip)
 {
-  if (lseek(this->fd_, skip, SEEK_CUR) != 0)
+  if (lseek(this->fd_, skip, SEEK_CUR) < 0)
 {
   if (!this->saw_error())
go_fatal_error(Linemap::unknown_location(), "lseek failed: %m");
@@ -1532,7 +1532,7 @@ Stream_from_file::do_advance(size_t skip)
 }
   if (!this->data_.empty())
 {
-  if (this->data_.length() < skip)
+  if (this->data_.length() > skip)
this->data_.erase(0, skip);
   else
this->data_.clear();


Re: [PATCH] lto: fix LTO debug sections copying.

2020-10-06 Thread Ian Lance Taylor via Gcc-patches
On Tue, Oct 6, 2020 at 3:20 AM Martin Liška  wrote:
>
> On 10/6/20 10:00 AM, Richard Biener wrote:
> > On Tue, Oct 6, 2020 at 9:01 AM Martin Liška  wrote:
> >>
> >> On 10/5/20 6:34 PM, Ian Lance Taylor wrote:
> >>> On Mon, Oct 5, 2020 at 9:09 AM Martin Liška  wrote:
> 
>  The previous patch was not correct. This one should be.
> 
>  Ready for master?
> >>>
> >>> I don't understand why this code uses symtab_indices_shndx at all.
> >>> There should only be one SHT_SYMTAB_SHNDX section.  There shouldn't be
> >>> any need for the symtab_indices_shndx vector.
> >>
> >> Well, the question is if we can have multiple .symtab sections in one ELF
> >> file? Theoretically yes, so we should also handle SHT_SYMTAB_SHNDX 
> >> sections.
> >> Note that the original usage of the SHT_SYMTAB_SHNDX section was motivated
> >> by PR81968 which is about Solaris ld.
> >
> > It wasn't my code but I suppose this way the implementation was
> > "easiest".  There
> > should be exactly one symtab / shndx section.  Rainer authored this support.
>
> If we expect at maximum one SHT_SYMTAB_SHNDX section section, then I'm 
> suggesting
> an updated version of the patch. It's what Ian offered.

This is OK with me with one minor change.

> + return "Multiple SYMTAB SECTION INDICES sections";

I think simply "More than one SHT_SYMTAB_SHNDX section".  SYMTAB
SECTION INDICES doesn't mean anything to me, and at least people can
do a web search for SHT_SYMTAB_SHNDX.

Thanks.

Ian


  1   2   3   4   5   6   >