Re: libgo: Consider '--with-build-sysroot=[...]' for target libraries' build-tree testing (instead of build-time 'CC' etc.) [PR109951] (was: [PATCH 3/4] libgo/test: Fix compilation for build sysroot)

2023-09-12 Thread Ian Lance Taylor via Gcc-patches
On Tue, Sep 12, 2023 at 4:16 AM Thomas Schwinge  wrote:
>
> As we've found, this is conceptually problematic, as discussed in
> 
> "Consider '--with-build-sysroot=[...]' for target libraries' build-tree 
> testing (instead of build-time 'CC' etc.)
> [PR109951]".
> I therefore suggest to apply to libgo the conceptually same changes
> as I've just pushed for libgomp:
> 
> "libgomp: Consider '--with-build-sysroot=[...]' for target libraries' 
> build-tree testing (instead of build-time 'CC'
> etc.) [PR91884, PR109951]".
> OK to push (via Ian/Go upstream) the attached
> "libgo: Consider '--with-build-sysroot=[...]' for target libraries' 
> build-tree testing (instead of build-time 'CC' etc.) [PR109951]"?
>
> By the way, I've tested this one via hard-coding
> 'libgo/configure.ac:USE_DEJAGNU' to 'yes', and observing that my
> "quick hack to replicate the original requirement"
> ('internal_error ("MISSING SYSROOT");') no longer triggers.

Thanks.  Committed.

Ian


godump.cc patch committed: Handle _BitInt

2023-09-06 Thread Ian Lance Taylor via Gcc-patches
This patch to godump.cc adds support for BITINT_TYPE.  Bootstrapped
and ran godump and Go tests on x86_64-pc-linux-gnu.  Committed to
mainline.

Ian

gcc/
PR go/111310
* godump.cc (go_format_type): Handle BITINT_TYPE.

gcc/testsuite/
PR go/111310
   * gcc.misc-tests/godump-1.c: Add _BitInt test cases.
diff --git a/gcc/godump.cc b/gcc/godump.cc
index 0893d5fbc97..bdd2d108d76 100644
--- a/gcc/godump.cc
+++ b/gcc/godump.cc
@@ -760,6 +760,25 @@ go_format_type (class godump_container *container, tree 
type,
   }
   break;
 
+case BITINT_TYPE:
+  {
+   const char *s;
+   char buf[100];
+
+   s = go_get_uinttype_for_precision (TYPE_PRECISION (type),
+  TYPE_UNSIGNED (type));
+   if (s == NULL)
+ {
+   snprintf (buf, sizeof buf, "INVALID-bitint-%u%s",
+ TYPE_PRECISION (type),
+ TYPE_UNSIGNED (type) ? "u" : "");
+   s = buf;
+   ret = false;
+ }
+   obstack_grow (ob, s, strlen(s));
+  }
+  break;
+
 case REAL_TYPE:
   {
const char *s;
diff --git a/gcc/testsuite/gcc.misc-tests/godump-1.c 
b/gcc/testsuite/gcc.misc-tests/godump-1.c
index 95dabdc0e4c..f359a657827 100644
--- a/gcc/testsuite/gcc.misc-tests/godump-1.c
+++ b/gcc/testsuite/gcc.misc-tests/godump-1.c
@@ -234,6 +234,17 @@ const char cc_v1;
 cc_t cc_v2;
 /* { dg-final { scan-file godump-1.out "(?n)^var _cc_v2 _cc_t$" } } */
 
+_BitInt(32) b32_v;
+/* { dg-final { scan-file godump-1.out "(?n)^var _b32_v int32$" } } */
+
+_BitInt(64) b64_v;
+/* { dg-final { scan-file godump-1.out "(?n)^var _b64_v int64$" } } */
+
+unsigned _BitInt(32) b32u_v;
+/* { dg-final { scan-file godump-1.out "(?n)^var _b32u_v uint32$" } } */
+
+_BitInt(33) b33_v;
+/* { dg-final { scan-file godump-1.out "(?n)^// var _b33_v INVALID-bitint-33$" 
} } */
 
 /*** pointer and array types ***/
 typedef void *vp_t;


libgo patch committed: permit $AR to include options

2023-09-06 Thread Ian Lance Taylor via Gcc-patches
This libgo patch changes the go tool to permit the AR environment
variable to include options.  This mirrors the way it already handles
the CC environment variable.

This ports https://go.dev/cl/526275 to the gofrontend repo.

This is needed for gccgo testing because the top-level GCC Makefile
now passes a --plugin option to ar if it supports one.

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

Ian
dab7163feedc99bd94549ee490031f86f8d0a6ca
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 83ab3e2d64c..30710e856cb 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-d04b024021bb7dbaa434a6d902bd12beb08e315f
+53cdfab53ce79d8dfc1df01a696d4ffc43f17c3d
 
 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 c1026c71e01..3e07f8791eb 100644
--- a/libgo/go/cmd/go/internal/work/gccgo.go
+++ b/libgo/go/cmd/go/internal/work/gccgo.go
@@ -45,12 +45,8 @@ func (gccgoToolchain) linker() string {
return GccgoBin
 }
 
-func (gccgoToolchain) ar() string {
-   ar := cfg.Getenv("AR")
-   if ar == "" {
-   ar = "ar"
-   }
-   return ar
+func (gccgoToolchain) ar() []string {
+   return envList("AR", "ar")
 }
 
 func checkGccgoBin() {


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: [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: [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


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:


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


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


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(), >data_))
+  if (!Gogo::read_file(this->filename_, Linemap::unknown_location(),
+  >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, ))
+  if (!Gogo::read_file(this->embed_files_[paths[0]].c_str(), loc, ))
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, ))
+ if 

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 

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: 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()


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


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


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)
 


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


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


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


libgo patch committed: Remove test ordering dependency in mime

2023-04-07 Thread Ian Lance Taylor via Gcc-patches
This libgo patch removes a test ordering dependency in the mime
package.  This is a backport of https://go.dev/cl/421442 from the
upstream repo.  This fixes https://go.dev/issue/51648.  Bootstrapped
and ran mime tests on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
f22c12d7361d22d47cce73d342edf2e1ebf20520
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index addef6f8f51..e133650ad91 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-63ba7dd52f2cc49dab4b70ac81309296a920d4dc
+0411a2733fd468e69f1998edd91e8fe3ba40ff9e
 
 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/mime/type_test.go b/libgo/go/mime/type_test.go
index 5e4d25cc872..5769c6a55de 100644
--- a/libgo/go/mime/type_test.go
+++ b/libgo/go/mime/type_test.go
@@ -14,7 +14,10 @@ import (
 func setMimeInit(fn func()) (cleanup func()) {
once = sync.Once{}
testInitMime = fn
-   return func() { testInitMime = nil }
+   return func() {
+   testInitMime = nil
+   once = sync.Once{}
+   }
 }
 
 func clearMimeTypes() {
diff --git a/libgo/go/mime/type_unix_test.go b/libgo/go/mime/type_unix_test.go
index 4d109aa71a2..43db44b7aa1 100644
--- a/libgo/go/mime/type_unix_test.go
+++ b/libgo/go/mime/type_unix_test.go
@@ -11,6 +11,7 @@ import (
 )
 
 func initMimeUnixTest(t *testing.T) {
+   once.Do(initMime)
err := loadMimeGlobsFile("testdata/test.types.globs2")
if err != nil {
t.Fatal(err)


Merge from trunk to gccgo branch

2023-03-29 Thread Ian Lance Taylor via Gcc-patches
I merged trunk revision aa8f4242efc99f24de73c59d53996f28db28c13f to
the gccgo branch.

Ian


Go patch committed: Mark Call_expression multi-results as result struct

2023-03-28 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend marks a Call_expression multiple results
struct as a result struct.  In https://go.dev/cl/343873 we stopped
padding zero-sized trailing fields in functions that return multiple
results where the last result is zero-sized. This CL makes the
corresponding change on the caller side.

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

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

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

Ian
c8e7c9c973e6b0b3a3a061619831bc5df371f2ef
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 8c8025dec2e..addef6f8f51 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-9ffd6e679ff0e3a908d0ec2ed5c6efa1de827c3f
+63ba7dd52f2cc49dab4b70ac81309296a920d4dc
 
 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 53901306ef7..4ac55af7433 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -11267,6 +11267,7 @@ Call_expression::do_lower(Gogo* gogo, Named_object* 
function,
 
   Struct_type* st = Type::make_struct_type(sfl, loc);
   st->set_is_struct_incomparable();
+  st->set_is_results_struct();
   this->call_temp_ = Statement::make_temporary(st, NULL, loc);
   inserter->insert(this->call_temp_);
 }


libbacktrace patch committed: Tweaks to zstd decompression

2023-03-28 Thread Ian Lance Taylor via Gcc-patches
In looking over the recently committed support for zstd decompression
in libbacktrace, I found a few minor cases that needed fixing.
Bootstrapped and tested on x86_64-pc-linux-gnu.  Committed to
mainline.

Ian


* elf.c (elf_zstd_read_fse): Call elf_fetch_bits after reading
bits, not before.  Add unlikely for error case.
(elf_zstd_offset_table): Regenerate.
(elf_zstd_read_huff): Clear 13 entries in weight_mark, not 12.
(elf_zstd_read_literals): For a single stream adjust by
total_streams_size, not compressed_size.
2e71f05403c36d25216107a7ae43c7055a282d73
diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index efd509bba6b..665b3dd1a53 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -2806,18 +2806,18 @@ elf_zstd_read_fse (const unsigned char **ppin, const 
unsigned char *pinend,
  while ((val & 0xfff) == 0xfff)
{
  zidx += 3 * 6;
- if  (!elf_fetch_bits (, pinend, , ))
-   return 0;
  val >>= 12;
  bits -= 12;
+ if  (!elf_fetch_bits (, pinend, , ))
+   return 0;
}
  while ((val & 3) == 3)
{
  zidx += 3;
- if (!elf_fetch_bits (, pinend, , ))
-   return 0;
  val >>= 2;
  bits -= 2;
+ if (!elf_fetch_bits (, pinend, , ))
+   return 0;
}
  /* We have at least 13 bits here, don't need to fetch.  */
  zidx += val & 3;
@@ -2947,7 +2947,7 @@ elf_zstd_build_fse (const int16_t *norm, int idx, 
uint16_t *next,
pos = (pos + step) & mask;
}
 }
-  if (pos != 0)
+  if (unlikely (pos != 0))
 {
   elf_uncompress_failed ();
   return 0;
@@ -3423,17 +3423,17 @@ static const struct elf_zstd_fse_baseline_entry 
elf_zstd_match_table[64] =
 
 static const struct elf_zstd_fse_baseline_entry elf_zstd_offset_table[32] =
 {
-  { 1, 0, 5, 0 }, { 64, 6, 4, 0 }, { 512, 9, 5, 0 },
-  { 32768, 15, 5, 0 }, { 2097152, 21, 5, 0 }, { 8, 3, 5, 0 },
-  { 128, 7, 4, 0 }, { 4096, 12, 5, 0 }, { 262144, 18, 5, 0 },
-  { 8388608, 23, 5, 0 }, { 32, 5, 5, 0 }, { 256, 8, 4, 0 },
-  { 16384, 14, 5, 0 }, { 1048576, 20, 5, 0 }, { 4, 2, 5, 0 },
-  { 128, 7, 4, 16 }, { 2048, 11, 5, 0 }, { 131072, 17, 5, 0 },
-  { 4194304, 22, 5, 0 }, { 16, 4, 5, 0 }, { 256, 8, 4, 16 },
-  { 8192, 13, 5, 0 }, { 524288, 19, 5, 0 }, { 2, 1, 5, 0 },
-  { 64, 6, 4, 16 }, { 1024, 10, 5, 0 }, { 65536, 16, 5, 0 },
-  { 268435456, 28, 5, 0 }, { 134217728, 27, 5, 0 }, { 67108864, 26, 5, 0 },
-  { 33554432, 25, 5, 0 }, { 16777216, 24, 5, 0 },
+  { 1, 0, 5, 0 }, { 61, 6, 4, 0 }, { 509, 9, 5, 0 },
+  { 32765, 15, 5, 0 }, { 2097149, 21, 5, 0 }, { 5, 3, 5, 0 },
+  { 125, 7, 4, 0 }, { 4093, 12, 5, 0 }, { 262141, 18, 5, 0 },
+  { 8388605, 23, 5, 0 }, { 29, 5, 5, 0 }, { 253, 8, 4, 0 },
+  { 16381, 14, 5, 0 }, { 1048573, 20, 5, 0 }, { 1, 2, 5, 0 },
+  { 125, 7, 4, 16 }, { 2045, 11, 5, 0 }, { 131069, 17, 5, 0 },
+  { 4194301, 22, 5, 0 }, { 13, 4, 5, 0 }, { 253, 8, 4, 16 },
+  { 8189, 13, 5, 0 }, { 524285, 19, 5, 0 }, { 2, 1, 5, 0 },
+  { 61, 6, 4, 16 }, { 1021, 10, 5, 0 }, { 65533, 16, 5, 0 },
+  { 268435453, 28, 5, 0 }, { 134217725, 27, 5, 0 }, { 67108861, 26, 5, 0 },
+  { 33554429, 25, 5, 0 }, { 16777213, 24, 5, 0 },
 };
 
 /* Read a zstd Huffman table and build the decoding table in *TABLE, reading
@@ -3618,7 +3618,7 @@ elf_zstd_read_huff (const unsigned char **ppin, const 
unsigned char *pinend,
 }
 
   weight_mark = (uint32_t *) (weights + 256);
-  memset (weight_mark, 0, 12 * sizeof (uint32_t));
+  memset (weight_mark, 0, 13 * sizeof (uint32_t));
   weight_mask = 0;
   for (i = 0; i < count; ++i)
 {
@@ -3685,7 +3685,7 @@ elf_zstd_read_huff (const unsigned char **ppin, const 
unsigned char *pinend,
 
   /* Change WEIGHT_MARK from a count of weights to the index of the first
  symbol for that weight.  We shift the indexes to also store how many we
- hae seen so far, below.  */
+ have seen so far, below.  */
   {
 uint32_t next;
 
@@ -3766,7 +3766,7 @@ elf_zstd_read_literals (const unsigned char **ppin,
 {
   int raw;
 
-  /* Raw_literals_Block or RLE_Literals_Block */
+  /* Raw_Literals_Block or RLE_Literals_Block */
 
   raw = (hdr & 3) == 0;
 
@@ -3948,7 +3948,7 @@ elf_zstd_read_literals (const unsigned char **ppin,
   unsigned int bits;
   uint32_t i;
 
-  pback = pin + compressed_size - 1;
+  pback = pin + total_streams_size - 1;
   pbackend = pin;
   if (!elf_fetch_backward_init (, pbackend, , ))
return 0;


Go patch committed: Add missing Slice_info_expression::do_traverse

2023-03-22 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend adds the missing
Slice_info_expression::do_traverse method.  Lack of the method caused
https://go.dev/issue/59169.  The test case is
https://go.dev/cl/478217.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline and GCC 12 branch.

Ian
187edaf5e88b548db4e6790b723be1f8d1dab2d5
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 4a1a4c8c021..8c8025dec2e 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-8c786f716c58d7973623c2b9293e2ad360877817
+9ffd6e679ff0e3a908d0ec2ed5c6efa1de827c3f
 
 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.h b/gcc/go/gofrontend/expressions.h
index a1e3733aa1d..3d7e78711bd 100644
--- a/gcc/go/gofrontend/expressions.h
+++ b/gcc/go/gofrontend/expressions.h
@@ -4410,6 +4410,10 @@ class Slice_info_expression : public Expression
   { return this->slice_info_; }
 
  protected:
+  int
+  do_traverse(Traverse* traverse)
+  { return Expression::traverse(>slice_, traverse); }
+
   Type*
   do_type();
 


Add notes for Go to gcc 12 and 13 changes file

2023-03-20 Thread Ian Lance Taylor via Gcc-patches
I committed this patch to the gcc-wwwdocs repo to add some notes about
Go to the gcc 12 and 13 changes file.

Ian

pat
e24f9ef56c11c69fc07bddf9a708ea2fc662f2b3
diff --git a/htdocs/gcc-12/changes.html b/htdocs/gcc-12/changes.html
index c47d3285..d565c217 100644
--- a/htdocs/gcc-12/changes.html
+++ b/htdocs/gcc-12/changes.html
@@ -618,7 +618,14 @@ function Multiply (S1, S2 : Sign) return Sign is
   
 
 
-
+Go
+
+
+  GCC 12 provides a complete implementation of the Go 1.18 user
+packages.
+  Although Go 1.18 includes support for generic programming, that
+support is not yet available in GCC.
+
 
 
 libgccjit
diff --git a/htdocs/gcc-13/changes.html b/htdocs/gcc-13/changes.html
index a4b71ffa..4fae1f7a 100644
--- a/htdocs/gcc-13/changes.html
+++ b/htdocs/gcc-13/changes.html
@@ -380,7 +380,14 @@ a work-in-progress.
   
 
 
-
+Go
+
+
+  GCC 13, like GCC 12, provides a complete implementation of the
+Go 1.18 user packages.
+  Although Go 1.18 includes support for generic programming, that
+support is not yet available in GCC.
+
 
 Modula-2
 


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


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: [PATCH 2/4] libbacktrace: detect executable path on windows

2023-02-05 Thread Ian Lance Taylor via Gcc-patches
On Sun, Feb 5, 2023 at 1:21 AM Björn Schäpers  wrote:
>
> Am 24.01.2023 um 19:32 schrieb Ian Lance Taylor:
> > On Tue, Jan 24, 2023 at 10:12 AM Eli Zaretskii via Gcc-patches
> >  wrote:
> >>
> >>> From: Ian Lance Taylor 
> >>> Date: Tue, 24 Jan 2023 09:58:10 -0800
> >>> Cc: g...@hazardy.de, gcc-patches@gcc.gnu.org, g...@gcc.gnu.org
> >>>
> >>> I'd rather that the patch look like the appended.  Can someone with a
> >>> Windows system test to see what that builds and passes the tests?
> >>
> >> ENOPATCH
> >
> > Gah.
> >
> > Ian
> >
> That seems to be my original patch, right? That one I have tested (and
> am actually using) on x86 and x64 windows.

It's very similar but I changed the windows_get_executable_path function.

Ian


Re: [PATCH 2/4] libbacktrace: detect executable path on windows

2023-01-24 Thread Ian Lance Taylor via Gcc-patches
On Tue, Jan 24, 2023 at 10:12 AM Eli Zaretskii via Gcc-patches
 wrote:
>
> > From: Ian Lance Taylor 
> > Date: Tue, 24 Jan 2023 09:58:10 -0800
> > Cc: g...@hazardy.de, gcc-patches@gcc.gnu.org, g...@gcc.gnu.org
> >
> > I'd rather that the patch look like the appended.  Can someone with a
> > Windows system test to see what that builds and passes the tests?
>
> ENOPATCH

Gah.

Ian
diff --git a/libbacktrace/config.h.in b/libbacktrace/config.h.in
index 94621c2e385..29d1ad3911a 100644
--- a/libbacktrace/config.h.in
+++ b/libbacktrace/config.h.in
@@ -100,6 +100,9 @@
 /* Define to 1 if you have the  header file. */
 #undef HAVE_UNISTD_H
 
+/* Define to 1 if you have the  header file. */
+#undef HAVE_WINDOWS_H
+
 /* Define if -lz is available. */
 #undef HAVE_ZLIB
 
diff --git a/libbacktrace/configure b/libbacktrace/configure
index 6af2c04c81a..0a27cfb7799 100755
--- a/libbacktrace/configure
+++ b/libbacktrace/configure
@@ -13409,6 +13409,19 @@ $as_echo "#define HAVE_LOADQUERY 1" >>confdefs.h
 
 fi
 
+for ac_header in windows.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "windows.h" "ac_cv_header_windows_h" 
"$ac_includes_default"
+if test "x$ac_cv_header_windows_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_WINDOWS_H 1
+_ACEOF
+
+fi
+
+done
+
+
 # Check for the fcntl function.
 if test -n "${with_target_subdir}"; then
case "${host}" in
diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac
index 39e6bf41e35..e3e10abd7b5 100644
--- a/libbacktrace/configure.ac
+++ b/libbacktrace/configure.ac
@@ -377,6 +377,8 @@ if test "$have_loadquery" = "yes"; then
   AC_DEFINE(HAVE_LOADQUERY, 1, [Define if AIX loadquery is available.])
 fi
 
+AC_CHECK_HEADERS(windows.h)
+
 # Check for the fcntl function.
 if test -n "${with_target_subdir}"; then
case "${host}" in
diff --git a/libbacktrace/fileline.c b/libbacktrace/fileline.c
index 674bf33cdcf..e110b54ee24 100644
--- a/libbacktrace/fileline.c
+++ b/libbacktrace/fileline.c
@@ -47,6 +47,18 @@ POSSIBILITY OF SUCH DAMAGE.  */
 #include 
 #endif
 
+#ifdef HAVE_WINDOWS_H
+#ifndef WIN32_MEAN_AND_LEAN
+#define WIN32_MEAN_AND_LEAN
+#endif
+
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+
+#include 
+#endif
+
 #include "backtrace.h"
 #include "internal.h"
 
@@ -155,6 +167,27 @@ macho_get_executable_path (struct backtrace_state *state,
 
 #endif /* !defined (HAVE_MACH_O_DYLD_H) */
 
+#ifdef HAVE_WINDOWS_H
+
+static char *
+windows_get_executable_path (char *buf, backtrace_error_callback 
error_callback,
+void *data)
+{
+  size_t got;
+
+  got = GetModuleFileNameA (NULL, buf, MAX_PATH - 1);
+  if (got == 0
+  || (got == MAX_PATH - 1 && GetLastError () == ERROR_INSUFFICIENT_BUFFER))
+return NULL;
+  return buf;
+}
+
+#else /* !defined (HAVE_WINDOWS_H) */
+
+#define windows_get_executable_path(buf, error_callback, data) NULL
+
+#endif /* !defined (HAVE_WINDOWS_H) */
+
 /* Initialize the fileline information from the executable.  Returns 1
on success, 0 on failure.  */
 
@@ -168,7 +201,11 @@ fileline_initialize (struct backtrace_state *state,
   int called_error_callback;
   int descriptor;
   const char *filename;
+#ifdef HAVE_WINDOWS_H
+  char buf[MAX_PATH];
+#else
   char buf[64];
+#endif
 
   if (!state->threaded)
 failed = state->fileline_initialization_failed;
@@ -192,7 +229,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;
 
@@ -224,6 +261,9 @@ fileline_initialize (struct backtrace_state *state,
case 7:
  filename = macho_get_executable_path (state, error_callback, data);
  break;
+   case 8:
+ filename = windows_get_executable_path (buf, error_callback, data);
+ break;
default:
  abort ();
}


Re: [PATCH 2/4] libbacktrace: detect executable path on windows

2023-01-24 Thread Ian Lance Taylor via Gcc-patches
On Tue, Jan 24, 2023 at 8:53 AM Eli Zaretskii via Gcc-patches
 wrote:
>
> > From: Ian Lance Taylor 
> > Date: Tue, 24 Jan 2023 06:35:21 -0800
> > Cc: g...@hazardy.de, gcc-patches@gcc.gnu.org, g...@gcc.gnu.org
> >
> > > > On Windows it seems that MAX_PATH is not
> > > > a true limit, as an extended length path may be up to 32767 bytes.
> > >
> > > The limit of 32767 characters (not bytes, AFAIK) is only applicable
> > > when using the Unicode (a.k.a. "wide") versions of the Windows Win32
> > > APIs, see
> > >
> > >   
> > > https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
> > >
> > > Since the above code uses GetModuleFileNameA, which is an "ANSI"
> > > single-byte API, it is still subject to the MAX_PATH limitation, and
> > > MAX_PATH is defined as 260 on Windows headers.
> >
> > Thanks.  Should this code be using GetModuleFileNameW?  Or would that
> > mean that the later call to open will fail?
>
> We'd need to use _wopen or somesuch, and the file name will have to be
> a wchar_t array, not a char array, yes.  So this is not very practical
> when file names need to be passed between functions, unless they are
> converted to UTF-8 (and back again before using them in Windows APIs).
>
> And note that even then, the 260-byte limit could be lifted only if
> the user has a new enough Windows version _and_ has opted in to the
> long-name feature by turning it on in the Registry.  Otherwise, file
> names used in "wide" APIs can only break the 260-byte limit if they
> use the special format "\\?\D:\foo\bar", which means file names
> specified by user outside of the program or file names that come from
> other programs will need to be reformatted to this special format.
>
> > 260 bytes does not seem like very much for a path name these days.
>
> That's true.  But complications with using longer file names are still
> a PITA on Windows, even though they are a step closer to practically
> possible.


OK, thanks.

I'd rather that the patch look like the appended.  Can someone with a
Windows system test to see what that builds and passes the tests?
Thanks.

Ian


Re: [PATCH 2/4] libbacktrace: detect executable path on windows

2023-01-24 Thread Ian Lance Taylor via Gcc-patches
On Tue, Jan 24, 2023 at 5:11 AM Eli Zaretskii via Gcc-patches
 wrote:
>
> > Date: Mon, 23 Jan 2023 15:00:56 -0800
> > Cc: gcc-patches@gcc.gnu.org, g...@gcc.gnu.org
> > From: Ian Lance Taylor via Gcc 
> >
> > > +#ifdef HAVE_WINDOWS_H
> > > +
> > > +static char *
> > > +windows_get_executable_path (char *buf, backtrace_error_callback 
> > > error_callback,
> > > +void *data)
> > > +{
> > > +  if (GetModuleFileNameA (NULL, buf, MAX_PATH - 1) == 0)
> > > +{
> > > +  error_callback (data,
> > > + "could not get the filename of the current 
> > > executable",
> > > + (int) GetLastError ());
> > > +  return NULL;
> > > +}
> > > +  return buf;
> > > +}
> >
> > Thanks, but this seems incomplete.  The docs for GetModuleFileNameA
> > say that if the pathname is too long to fit into the buffer it returns
> > the size of the buffer and sets the error to
> > ERROR_INSUFFICIENT_BUFFER.  It seems to me that in that case we should
> > allocate a larger buffer and try again.
>
> This is correct in general, but not in this particular case.
>
> > On Windows it seems that MAX_PATH is not
> > a true limit, as an extended length path may be up to 32767 bytes.
>
> The limit of 32767 characters (not bytes, AFAIK) is only applicable
> when using the Unicode (a.k.a. "wide") versions of the Windows Win32
> APIs, see
>
>   
> https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
>
> Since the above code uses GetModuleFileNameA, which is an "ANSI"
> single-byte API, it is still subject to the MAX_PATH limitation, and
> MAX_PATH is defined as 260 on Windows headers.

Thanks.  Should this code be using GetModuleFileNameW?  Or would that
mean that the later call to open will fail?

260 bytes does not seem like very much for a path name these days.

Ian


Re: [PATCH 2/4] libbacktrace: detect executable path on windows

2023-01-23 Thread Ian Lance Taylor via Gcc-patches
On Fri, Jan 20, 2023 at 2:56 AM Björn Schäpers  wrote:
>
> From: Björn Schäpers 
>
> This is actually needed so that libstdc++'s  implementation
> to be able to work on windows.
>
> Tested on x86_64-linux and i686-w64-mingw32.
>
> -- >8 --
>
> * configure.ac: Add a check for windows.h.
> * configure, config.h.in: Regenerate.
> * fileline.c: Add windows_get_executable_path.
> * fileline.c (fileline_initialiez): Add a pass using
> windows_get_executable_path.
>
> +#ifdef HAVE_WINDOWS_H
> +
> +static char *
> +windows_get_executable_path (char *buf, backtrace_error_callback 
> error_callback,
> +void *data)
> +{
> +  if (GetModuleFileNameA (NULL, buf, MAX_PATH - 1) == 0)
> +{
> +  error_callback (data,
> + "could not get the filename of the current executable",
> + (int) GetLastError ());
> +  return NULL;
> +}
> +  return buf;
> +}

Thanks, but this seems incomplete.  The docs for GetModuleFileNameA
say that if the pathname is too long to fit into the buffer it returns
the size of the buffer and sets the error to
ERROR_INSUFFICIENT_BUFFER.  It seems to me that in that case we should
allocate a larger buffer and try again.  And, in general, it will be
simpler if we always allocate the buffer, as macho_get_executable_path
does.  Unfortunately it appears that Windows does not provide a way to
ask for the required length.  On Windows it seems that MAX_PATH is not
a true limit, as an extended length path may be up to 32767 bytes.

So probably something like (untested)

static char *
windows_get_executable_path (struct backtrace_state *state,
 backtrace_error_callback error_callback,
 void *data)
{
  uint32_t len;
  char *buf;

  len = MAX_PATH;
  while (1)
{
  uint32_t got;

  name = (char *) backtrace_alloc (state, len, error_callback, data);
  if (name == NULL)
return NULL;
  got = GetModuleFileNameA (NULL, name, len);
  if (got < len - 1) /* -1 because NULB is not counted */
return name;
  backtrace_free (state, name, len, error_callback, data);
  if (GetLastError () != ERROR_INSUFFICIENT_BUFFER)
return NULL;
  len *= 2;
}
}

Ian


Re: [PATCH 1/4] libbacktrace: change all pc related variables to uintptr_t

2023-01-20 Thread Ian Lance Taylor via Gcc-patches
On Fri, Jan 20, 2023 at 2:54 AM Björn Schäpers  wrote:
>
> From: Björn Schäpers 
>
> It's the right thing to do, since the PC shouldn't go out of the
> uintptr_t domain, and in backtrace_pcinfo the pc is uintptr_t.
> This is a preparation for a following patch.
>
> Tested on x86_64-linux and i686-w64-mingw32.

Thanks.  Committed like so, with some additional tweaks.

For future reference, when pinging a patch, please reply to the
original patch to maintain the thread.  Or at least mention the
original patch.  It was still on my list, I just hadn't gotten to it.
Thanks.

Ian

Change variables holding PC values from uint64_t to uintptr_t.
Patch by Björn Schäpers.
* dwarf.c (struct function_addrs): Change low and high fields to
uintptr_t.
(struct unit_addrs): Likewise.
(resolve_addr_index): Change address parameter to uintptr_t*.
(add_unit_addr): Change lowpc and highpc parameters to uintptr_t.
(add_function_range): Likewise.
(struct pcrange): Change lowpc and highpc fields to uintptr_t.
(add_low_high_range): Change add_range lowpc and highpc parameters
to uintptr_t.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): Likewise.
(add_low_high_range): Chnage lowpc and highpc variables to
uintpr_t.
(add_ranges_from_rnglists): Change some local variables to
uintptr_t.
(add_ranges_from_ranges): Change base parameter to uintptr_t.
(add_ranges_from_rnglists): Likewise.
(read_function_entry): Likewise.
(resolve_addr_index): Add explicit casts to uintptr_t.
(update_pcrange): Likewise.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): Likewise.
(read_function_entry): Likewise.
0c193cabe1d8f209359f3ccb8e74cf87b38fc4bc
diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c
index 2d41f3b0397..8ff1fb3ce3d 100644
--- a/libbacktrace/dwarf.c
+++ b/libbacktrace/dwarf.c
@@ -136,7 +136,7 @@ enum attr_val_encoding
   /* An address.  */
   ATTR_VAL_ADDRESS,
   /* An index into the .debug_addr section, whose value is relative to
-   * the DW_AT_addr_base attribute of the compilation unit.  */
+ the DW_AT_addr_base attribute of the compilation unit.  */
   ATTR_VAL_ADDRESS_INDEX,
   /* A unsigned integer.  */
   ATTR_VAL_UINT,
@@ -274,8 +274,8 @@ struct function
 struct function_addrs
 {
   /* Range is LOW <= PC < HIGH.  */
-  uint64_t low;
-  uint64_t high;
+  uintptr_t low;
+  uintptr_t high;
   /* Function for this address range.  */
   struct function *function;
 };
@@ -356,8 +356,8 @@ struct unit
 struct unit_addrs
 {
   /* Range is LOW <= PC < HIGH.  */
-  uint64_t low;
-  uint64_t high;
+  uintptr_t low;
+  uintptr_t high;
   /* Compilation unit for this address range.  */
   struct unit *u;
 };
@@ -1094,7 +1094,7 @@ resolve_addr_index (const struct dwarf_sections 
*dwarf_sections,
uint64_t addr_base, int addrsize, int is_bigendian,
uint64_t addr_index,
backtrace_error_callback error_callback, void *data,
-   uint64_t *address)
+   uintptr_t *address)
 {
   uint64_t offset;
   struct dwarf_buf addr_buf;
@@ -1115,7 +1115,7 @@ resolve_addr_index (const struct dwarf_sections 
*dwarf_sections,
   addr_buf.data = data;
   addr_buf.reported_underflow = 0;
 
-  *address = read_address (_buf, addrsize);
+  *address = (uintptr_t) read_address (_buf, addrsize);
   return 1;
 }
 
@@ -1194,7 +1194,7 @@ function_addrs_search (const void *vkey, const void 
*ventry)
 
 static int
 add_unit_addr (struct backtrace_state *state, void *rdata,
-  uint64_t lowpc, uint64_t highpc,
+  uintptr_t lowpc, uintptr_t highpc,
   backtrace_error_callback error_callback, void *data,
   void *pvec)
 {
@@ -1530,10 +1530,10 @@ lookup_abbrev (struct abbrevs *abbrevs, uint64_t code,
lowpc/highpc is set or ranges is set.  */
 
 struct pcrange {
-  uint64_t lowpc;  /* The low PC value.  */
+  uintptr_t lowpc; /* The low PC value.  */
   int have_lowpc;  /* Whether a low PC value was found.  */
   int lowpc_is_addr_index; /* Whether lowpc is in .debug_addr.  */
-  uint64_t highpc; /* The high PC value.  */
+  uintptr_t highpc;/* The high PC value.  */
   int have_highpc; /* Whether a high PC value was found.  */
   int highpc_is_relative;  /* Whether highpc is relative to lowpc.  */
   int highpc_is_addr_index;/* Whether highpc is in .debug_addr.  */
@@ -1553,12 +1553,12 @@ update_pcrange (const struct attr* attr, const struct 
attr_val* val,
 case DW_AT_low_pc:
   if (val->encoding == ATTR_VAL_ADDRESS)
{
- pcrange->lowpc = val->u.uint;
+ pcrange->lowpc = (uintptr_t) val->u.uint;
  pcrange->have_lowpc = 1;
}
   else if (val->encoding == ATTR_VAL_ADDRESS_INDEX)
{
- pcrange->lowpc = val->u.uint;
+ pcrange->lowpc = (uintptr_t) val->u.uint;
  pcrange->have_lowpc = 1;
  pcrange->lowpc_is_addr_index = 1;
}
@@ 

Go patch committed: Define builtin functions

2023-01-17 Thread Ian Lance Taylor via Gcc-patches
This patch by Andrew Pinski defines two builtin functions that are
used by the middle-end.  This fixes PR 108426.  Bootstrapped and
tested on x86_64-pc-linux-gnu.  Committed to mainline.

Ian

PR go/108426
* go-gcc.cc (Gcc_backend::Gcc_backend): Define __builtin_ctzl and
__builtin_clzl.  Patch by Andrew Pinski.
2bee478038d75487b52e35e29e54c70e4bfa1e2b
diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc
index a4a0e5d903e..07c34a58241 100644
--- a/gcc/go/go-gcc.cc
+++ b/gcc/go/go-gcc.cc
@@ -627,6 +627,11 @@ Gcc_backend::Gcc_backend()
unsigned_type_node,
NULL_TREE),
   builtin_const);
+  this->define_builtin(BUILT_IN_CTZL, "__builtin_ctzl", "ctzl",
+ build_function_type_list(integer_type_node,
+  long_unsigned_type_node,
+  NULL_TREE),
+ builtin_const);
   this->define_builtin(BUILT_IN_CTZLL, "__builtin_ctzll", "ctzll",
   build_function_type_list(integer_type_node,
long_long_unsigned_type_node,
@@ -637,6 +642,11 @@ Gcc_backend::Gcc_backend()
unsigned_type_node,
NULL_TREE),
   builtin_const);
+  this->define_builtin(BUILT_IN_CLZL, "__builtin_clzl", "clzl",
+ build_function_type_list(integer_type_node,
+  long_unsigned_type_node,
+  NULL_TREE),
+ builtin_const);
   this->define_builtin(BUILT_IN_CLZLL, "__builtin_clzll", "clzll",
   build_function_type_list(integer_type_node,
long_long_unsigned_type_node,


libbacktrace patch committed: Only test --build-id if supported

2023-01-06 Thread Ian Lance Taylor via Gcc-patches
PR 108297 points out that there are systems that use ELF but for which
the linker does not support the --build-id option.  This libbacktrace
patch skips --build-id tests when it doesn't work.  Bootstrapped and
ran libbacktrace tests on x86_64-pc-linux-gnu.  Committed to mainline.

Ian

PR libbacktrace/108297
* configure.ac: Test whether linker supports --build-id.
* Makefile.am: Only run --build-id tests if supported.
* configure, Makefile.in: Regenerate.
diff --git a/libbacktrace/Makefile.am b/libbacktrace/Makefile.am
index 047b573c29a..1c4ac2baeb6 100644
--- a/libbacktrace/Makefile.am
+++ b/libbacktrace/Makefile.am
@@ -248,6 +248,7 @@ check_DATA += allocfail.dSYM
 endif USE_DSYMUTIL
 
 if HAVE_ELF
+if HAVE_BUILDID
 if HAVE_OBJCOPY_DEBUGLINK
 
 b2test_SOURCES = $(btest_SOURCES)
@@ -271,6 +272,7 @@ MAKETESTS += b3test_dwz_buildid
 endif HAVE_DWZ
 
 endif HAVE_OBJCOPY_DEBUGLINK
+endif HAVE_BUILDID
 endif HAVE_ELF
 
 btest_SOURCES = btest.c testlib.c
diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac
index d0a0475cfa8..28e3a688c24 100644
--- a/libbacktrace/configure.ac
+++ b/libbacktrace/configure.ac
@@ -484,7 +484,18 @@ AC_CHECK_LIB([z], [compress],
 [AC_DEFINE(HAVE_ZLIB, 1, [Define if -lz is available.])])
 AM_CONDITIONAL(HAVE_ZLIB, test "$ac_cv_lib_z_compress" = yes)
 
-dnl Test whether the linker supports the --compress_debug_sections option.
+dnl Test whether the linker supports the --build-id option.
+AC_CACHE_CHECK([whether --build-id is supported],
+[libbacktrace_cv_ld_buildid],
+[LDFLAGS_hold=$LDFLAGS
+LDFLAGS="$LDFLAGS -Wl,--build-id"
+AC_LINK_IFELSE([AC_LANG_PROGRAM(,)],
+[libbacktrace_cv_ld_buildid=yes],
+[libbacktrace_cv_ld_buildid=no])
+LDFLAGS=$LDFLAGS_hold])
+AM_CONDITIONAL(HAVE_BUILDID, test "$libbacktrace_cv_ld_buildid" = yes)
+
+dnl Test whether the linker supports the --compress-debug-sections option.
 AC_CACHE_CHECK([whether --compress-debug-sections is supported],
 [libgo_cv_ld_compress],
 [LDFLAGS_hold=$LDFLAGS


Re: [PATCH] go: fix clang warnings

2022-12-22 Thread Ian Lance Taylor via Gcc-patches
On Wed, Dec 21, 2022 at 12:05 AM Martin Liška  wrote:
>
> The patch fixes the following Clang warnings:
>
> gcc/go/gofrontend/escape.cc:1290:17: warning: private field 'fn_' is not used 
> [-Wunused-private-field]
> gcc/go/gofrontend/escape.cc:3478:19: warning: private field 'context_' is not 
> used [-Wunused-private-field]
> gcc/go/gofrontend/lex.h:564:15: warning: private field 'input_file_name_' is 
> not used [-Wunused-private-field]
> gcc/go/gofrontend/types.cc:5788:20: warning: private field 'call_' is not 
> used [-Wunused-private-field]
> gcc/go/gofrontend/wb.cc:206:9: warning: private field 'gogo_' is not used 
> [-Wunused-private-field]
>
> Ready for master?

Thanks.  Committed to mainline.

Ian


Re: [PATCH] libgo: check if -lucontext is required for {make, set, get}context

2022-12-20 Thread Ian Lance Taylor via Gcc-patches
On Mon, Dec 19, 2022 at 8:59 AM  wrote:
>
> From: Sören Tempel 
>
> This patch is similar to the existing check for librt. If libucontext
> is installed and libucontext.a provides the aforementioned symbols, then
> it is added to $LIBS. If not, no error is emitted. We could,
> alternatively, also check libc.a for these symbols and thus prefer libc
> over libucontext if both are installed and provide the symbols. If
> deemed desirable, this could be achieved by changing the invocation
> to AC_SEARCH_LIBS([makecontext], [c ucontext]).
>
> This version of this patch has been tested on x86_64 Alpine Linux Edge
> (libucontext 1.2 + musl 1.2.3) and Arch Linux (glibc 2.36). On the
> latter, the check is a no-op and $LIBS is not modified.

Thanks.  I don't see a reason to check for all the functions.
Committed like so after testing on x86_64-pc-linux-gnu with glibc.

Ian
e1e810e2f1d4f6c45021741cb3f8d7f2be15926d
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index d8c4e02d6e6..d123c746fb2 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-9906861dc86c1733bb304d3d45b1534adb32712c
+ecc2a2e70e44fa76a75b12d0893bc1702b72a1b4
 
 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 b/libgo/configure
index 460fdad70a8..a607dbff68e 100755
--- a/libgo/configure
+++ b/libgo/configure
@@ -14818,6 +14818,63 @@ fi
 
 
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing 
makecontext" >&5
+$as_echo_n "checking for library containing makecontext... " >&6; }
+if ${ac_cv_search_makecontext+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char makecontext ();
+int
+main ()
+{
+return makecontext ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' ucontext; do
+  if test -z "$ac_lib"; then
+ac_res="none required"
+  else
+ac_res=-l$ac_lib
+LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_search_makecontext=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+conftest$ac_exeext
+  if ${ac_cv_search_makecontext+:} false; then :
+  break
+fi
+done
+if ${ac_cv_search_makecontext+:} false; then :
+
+else
+  ac_cv_search_makecontext=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_makecontext" >&5
+$as_echo "$ac_cv_search_makecontext" >&6; }
+ac_res=$ac_cv_search_makecontext
+if test "$ac_res" != no; then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+fi
+
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing 
sched_yield" >&5
 $as_echo_n "checking for library containing sched_yield... " >&6; }
 if ${ac_cv_search_sched_yield+:} false; then :
diff --git a/libgo/configure.ac b/libgo/configure.ac
index 09554a37a23..a59aa091d1d 100644
--- a/libgo/configure.ac
+++ b/libgo/configure.ac
@@ -570,6 +570,9 @@ PTHREAD_LIBS=
 AC_CHECK_LIB([pthread], [pthread_create], PTHREAD_LIBS=-lpthread)
 AC_SUBST(PTHREAD_LIBS)
 
+dnl Test if -lucontext is required for makecontext.
+AC_SEARCH_LIBS([makecontext], [ucontext])
+
 dnl Test if -lrt is required for sched_yield or nanosleep or clock_gettime.
 AC_SEARCH_LIBS([sched_yield], [rt])
 AC_SEARCH_LIBS([nanosleep], [rt])


Re: Add zstd support to libbacktrace

2022-12-16 Thread Ian Lance Taylor via Gcc-patches
Some more tweaks of the libbacktrace zstd decompressor to make
decompressing slightly faster: unpack all the literal data into the
output buffer, rather than using scratch space.  Bootstrapped and ran
libbacktrace tests on x86_64-pc-linux-gnu.  Committed to mainline.

Ian

* elf.c (elf_fetch_backward_init): New static function.
(ZSTD_TABLE_SIZE): Use huffman scratch space size rather than
literal size.
(ZSTD_TABLE_WORK_LIT_SIZE): Don't define.
(elf_zstd_read_huff): Use elf_fetch_backward_init.
(elf_zstd_read_literals): New static function.
(ZSTD_LIT_RAW, ZSTD_LIT_RLE, ZSTD_LIT_HUFF): Don't define.
(struct elf_zstd_literals): Don't define.
(elf_zstd_literal_output): Remove static function.
(elf_zstd_decompress): Use elf_fetch_backward_init and
elf_zstd_read_literals.  Rewrite literal copying.<
diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index ece02db27f1..135a94245a4 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -1223,6 +1223,57 @@ elf_fetch_bits_backward (const unsigned char **ppin,
   return 1;
 }
 
+/* Initialize backward fetching when the bitstream starts with a 1 bit in the
+   last byte in memory (which is the first one that we read).  This is used by
+   zstd decompression.  Returns 1 on success, 0 on error.  */
+
+static int
+elf_fetch_backward_init (const unsigned char **ppin,
+const unsigned char *pinend,
+uint64_t *pval, unsigned int *pbits)
+{
+  const unsigned char *pin;
+  unsigned int stream_start;
+  uint64_t val;
+  unsigned int bits;
+
+  pin = *ppin;
+  stream_start = (unsigned int)*pin;
+  if (unlikely (stream_start == 0))
+{
+  elf_uncompress_failed ();
+  return 0;
+}
+  val = 0;
+  bits = 0;
+
+  /* Align to a 32-bit boundary.  */
+  while uintptr_t)pin) & 3) != 0)
+{
+  val <<= 8;
+  val |= (uint64_t)*pin;
+  bits += 8;
+  --pin;
+}
+
+  val <<= 8;
+  val |= (uint64_t)*pin;
+  bits += 8;
+
+  *ppin = pin;
+  *pval = val;
+  *pbits = bits;
+  if (!elf_fetch_bits_backward (ppin, pinend, pval, pbits))
+return 0;
+
+  *pbits -= __builtin_clz (stream_start) - (sizeof (unsigned int) - 1) * 8 + 1;
+
+  if (!elf_fetch_bits_backward (ppin, pinend, pval, pbits))
+return 0;
+
+  return 1;
+}
+
 /* Huffman code tables, like the rest of the zlib format, are defined
by RFC 1951.  We store a Huffman code table as a series of tables
stored sequentially in memory.  Each entry in a table is 16 bits.
@@ -2617,14 +2668,13 @@ elf_zlib_inflate_and_verify (const unsigned char *pin, 
size_t sin,
- scratch space, one of
  - to build an FSE table: 512 uint16_t values == 1024 bytes
  - to build a Huffman tree: 512 uint16_t + 256 uint32_t == 2048 bytes
- - buffer for literal values == 2048 bytes
 */
 
 #define ZSTD_TABLE_SIZE\
   (2 * 512 * sizeof (struct elf_zstd_fse_baseline_entry)   \
+ 256 * sizeof (struct elf_zstd_fse_baseline_entry) \
+ 2048 * sizeof (uint16_t)  \
-   + 2048)
+   + 512 * sizeof (uint16_t) + 256 * sizeof (uint32_t))
 
 #define ZSTD_TABLE_LITERAL_FSE_OFFSET (0)
 
@@ -2642,8 +2692,6 @@ elf_zlib_inflate_and_verify (const unsigned char *pin, 
size_t sin,
 #define ZSTD_TABLE_WORK_OFFSET \
   (ZSTD_TABLE_HUFFMAN_OFFSET + 2048 * sizeof (uint16_t))
 
-#define ZSTD_TABLE_WORK_LIT_SIZE 2048
-
 /* An entry in a zstd FSE table.  */
 
 struct elf_zstd_fse_entry
@@ -3427,7 +3475,6 @@ elf_zstd_read_huff (const unsigned char **ppin, const 
unsigned char *pinend,
   uint16_t *scratch;
   const unsigned char *pfse;
   const unsigned char *pback;
-  unsigned char stream_start;
   uint64_t val;
   unsigned int bits;
   unsigned int state1, state2;
@@ -3454,31 +3501,8 @@ elf_zstd_read_huff (const unsigned char **ppin, const 
unsigned char *pinend,
 FSE_TABLE.  */
 
   pback = pin + hdr - 1;
-  stream_start = *pback;
-  if (unlikely (stream_start == 0))
-   {
- elf_uncompress_failed ();
- return 0;
-   }
-  val = 0;
-  bits = 0;
-  while uintptr_t)pback) & 3) != 0)
-   {
- val <<= 8;
- val |= (uint64_t)*pback;
- bits += 8;
- --pback;
-   }
-  val <<= 8;
-  val |= (uint64_t)*pback;
-  bits += 8;
-
-  if (!elf_fetch_bits_backward (, pfse, , ))
-   return 0;
-
-  bits -= __builtin_clz (stream_start) - 24 + 1;
 
-  if (!elf_fetch_bits_backward (, pfse, , ))
+  if (!elf_fetch_backward_init (, pfse, , ))
return 0;
 
   bits -= fse_table_bits;
@@ -3702,331 +3726,615 @@ elf_zstd_read_huff (const unsigned char **ppin, const 
unsigned char *pinend,
   return 1;
 }
 
-/* The information used to decompress a sequence code, which can be a literal
-   length, an offset, or a match length.  */
+/* Read and decompress the literals and store them ending at POUTEND.  This
+   works because we are going to use all the 

libgo patch committed: Bump major version

2022-12-12 Thread Ian Lance Taylor via Gcc-patches
This libgo patch bumps the major version.  The current version is the
same as for GCC 12, but there have been minor changes like new type
descriptors that make it impossible to run Go programs built with GCC
12 with the current GCC.  This fixes https://gcc.gnu.org/PR108057.
Bootstrapped on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
3c2e866832dd5612de1468807bc144e4824593c7
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index a26f779557d..d8c4e02d6e6 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-1c5bfd57131b68b91d8400bb017f35d416f7aa7b
+9906861dc86c1733bb304d3d45b1534adb32712c
 
 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 274fcfc35c7..09554a37a23 100644
--- a/libgo/configure.ac
+++ b/libgo/configure.ac
@@ -10,7 +10,7 @@ AC_INIT(package-unused, version-unused,, libgo)
 AC_CONFIG_SRCDIR(Makefile.am)
 AC_CONFIG_HEADER(config.h)
 
-libtool_VERSION=21:0:0
+libtool_VERSION=22:0:0
 AC_SUBST(libtool_VERSION)
 
 AM_ENABLE_MULTILIB(, ..)


Re: Add zstd support to libbacktrace

2022-12-09 Thread Ian Lance Taylor via Gcc-patches
On Wed, Dec 7, 2022 at 4:22 PM Ian Lance Taylor  wrote:
>
> This patch adds zstd support to libbacktrace, to support the new
> linker option --compress-debug-sections=zstd.

This patch rewrites and simplifies the main zstd decompression loop
using some ideas from the reference implementation.  This speeds it up
a bit, although it still runs at about 35% of the speed of the
reference implementaiton.  Bootstrapped and ran libbacktrace tests on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian

* elf.c (ZSTD_TABLE_*): Use elf_zstd_fse_baseline_entry.
(ZSTD_ENCODE_BASELINE_BITS): Define.
(ZSTD_DECODE_BASELINE, ZSTD_DECODE_BASEBITS): Define.
(elf_zstd_literal_length_base): New static const array.
(elf_zstd_match_length_base): Likewise.
(struct elf_zstd_fse_baseline_entry): Define.
(elf_zstd_make_literal_baseline_fse): New static function.
(elf_zstd_make_offset_baseline_fse): Likewise.
(elf_zstd_make_match_baseline_fse): Likewise.
(print_table, main): Use elf_zstd_fse_baseline_entry.
(elf_zstd_lit_table, elf_zstd_match_table): Likewise.
(elf_zstd_offset_table): Likewise.
(struct elf_zstd_seq_decode): Likewise.  Remove use_rle and rle
fields.
(elf_zstd_unpack_seq_decode): Use elf_zstd_fse_baseline_entry,
taking a conversion function.  Convert RLE to FSE.
(elf_zstd_literal_length_baseline): Remove.
(elf_zstd_literal_length_bits): Remove.
(elf_zstd_match_length_baseline): Remove.
(elf_zstd_match_length_bits): Remove.
(elf_zstd_decompress): Use elf_zstd_fse_baseline_entry.  Rewrite
and simplify main loop.
diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index 15e6f284db6..ece02db27f1 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -2610,9 +2610,9 @@ elf_zlib_inflate_and_verify (const unsigned char *pin, 
size_t sin,
 }
 
 /* For working memory during zstd compression, we need
-   - a literal length FSE table: 512 32-bit values == 2048 bytes
-   - a match length FSE table: 512 32-bit values == 2048 bytes
-   - a offset FSE table: 256 32-bit values == 1024 bytes
+   - a literal length FSE table: 512 64-bit values == 4096 bytes
+   - a match length FSE table: 512 64-bit values == 4096 bytes
+   - a offset FSE table: 256 64-bit values == 2048 bytes
- a Huffman tree: 2048 uint16_t values == 4096 bytes
- scratch space, one of
  - to build an FSE table: 512 uint16_t values == 1024 bytes
@@ -2620,21 +2620,24 @@ elf_zlib_inflate_and_verify (const unsigned char *pin, 
size_t sin,
  - buffer for literal values == 2048 bytes
 */
 
-#define ZSTD_TABLE_SIZE\
-  (2 * 512 * sizeof (struct elf_zstd_fse_entry)\
-   + 256 * sizeof (struct elf_zstd_fse_entry)  \
-   + 2048 * sizeof (uint16_t)  \
+#define ZSTD_TABLE_SIZE\
+  (2 * 512 * sizeof (struct elf_zstd_fse_baseline_entry)   \
+   + 256 * sizeof (struct elf_zstd_fse_baseline_entry) \
+   + 2048 * sizeof (uint16_t)  \
+ 2048)
 
 #define ZSTD_TABLE_LITERAL_FSE_OFFSET (0)
 
-#define ZSTD_TABLE_MATCH_FSE_OFFSET (512 * sizeof (struct elf_zstd_fse_entry))
+#define ZSTD_TABLE_MATCH_FSE_OFFSET\
+  (512 * sizeof (struct elf_zstd_fse_baseline_entry))
 
-#define ZSTD_TABLE_OFFSET_FSE_OFFSET \
-  (ZSTD_TABLE_MATCH_FSE_OFFSET + 512 * sizeof (struct elf_zstd_fse_entry))
+#define ZSTD_TABLE_OFFSET_FSE_OFFSET   \
+  (ZSTD_TABLE_MATCH_FSE_OFFSET \
+   + 512 * sizeof (struct elf_zstd_fse_baseline_entry))
 
-#define ZSTD_TABLE_HUFFMAN_OFFSET \
-  (ZSTD_TABLE_OFFSET_FSE_OFFSET + 256 * sizeof (struct elf_zstd_fse_entry))
+#define ZSTD_TABLE_HUFFMAN_OFFSET  \
+  (ZSTD_TABLE_OFFSET_FSE_OFFSET
\
+   + 256 * sizeof (struct elf_zstd_fse_baseline_entry))
 
 #define ZSTD_TABLE_WORK_OFFSET \
   (ZSTD_TABLE_HUFFMAN_OFFSET + 2048 * sizeof (uint16_t))
@@ -2645,8 +2648,11 @@ elf_zlib_inflate_and_verify (const unsigned char *pin, 
size_t sin,
 
 struct elf_zstd_fse_entry
 {
+  /* The value that this FSE entry represents.  */
   unsigned char symbol;
+  /* The number of bits to read to determine the next state.  */
   unsigned char bits;
+  /* Add the bits to this base to get the next state.  */
   uint16_t base;
 };
 
@@ -2925,6 +2931,270 @@ elf_zstd_build_fse (const int16_t *norm, int idx, 
uint16_t *next,
   return 1;
 }
 
+/* Encode the baseline and bits into a single 32-bit value.  */
+
+#define ZSTD_ENCODE_BASELINE_BITS(baseline, basebits)  \
+  ((uint32_t)(baseline) | ((uint32_t)(basebits) << 24))
+
+#define ZSTD_DECODE_BASELINE(baseline_basebits)\
+  ((uint32_t)(baseline_basebits) & 0xff)
+
+#define ZSTD_DECODE_BASEBITS(baseline_basebits)\
+  ((uint32_t)(baseline_basebits) >> 24)
+
+/* Given a literal length code, we need to read a number of bits and add that
+   to a baseline.  For states 0 to 15 the baseline is the state and the number
+   of bits is zero.  */
+
+#define 

Add zstd support to libbacktrace

2022-12-07 Thread Ian Lance Taylor via Gcc-patches
This patch adds zstd support to libbacktrace, to support the new
linker option --compress-debug-sections=zstd.

The zstd format is fairly complicated, so it's likely that there are
some bugs here.  It does pass the tests, at least.

Unfortunately this decompressor only runs at about 1/3 the speed to
the zstd library decompressor.  Still, it's smaller and simpler, and I
think it uses less memory.  Plus of course it uses the signal-safe
libbacktrace memory allocator.  Perhaps people can make a bit faster
over time.

Bootstrapped and ran libbacktrace and Go tests while using a linker
that compressed using zstd.

Committed to mainline.

Ian

Support decompressing --compress-debug-sections=zstd.
* configure.ac: Check for zstd library and
--compress-debug-sections=zstd linker option.
* Makefile.am (zstdtest_*): New targets.
(zstdtest_alloc_*, ctestzstd_*): New targets.
(BUILDTESTS): Add zstdtest, zstdtest_alloc, ctestzstd as
appropriate.
* elf.c (ELFCOMPRESS_ZSTD): Define.
(elf_fetch_bits): Rename from elf_zlib_fetch.  Update uses.
(elf_fetch_bits_backward): New static function.
(ZLIB_HUFFMAN_*): Rename from HUFFMAN_*.  Update uses.
(ZLIB_TABLE_*): Rename from ZDEBUG_TABLE_*.  Update uses.
(ZSTD_TABLE_*): Define.
(struct elf_zstd_fse_entry): Define.
(elf_zstd_read_fse): New static function.
(elf_zstd_build_fse): Likewise.
(lit): Define if BACKTRACE_GENERATE_ZSTD_FSE_TABLES.
(match, offset, next, print_table, main): Likewise.
(elf_zstd_lit_table): New static const array.
(elf_zstd_match_table, elf_zstd_offset_table): Likewise.
(elf_zstd_read_huff): New static function.
(struct elf_zstd_seq_decode): Define.
(elf_zstd_unpack_seq_decode): New static function.
(ZSTD_LIT_*): Define.
(struct elf_zstd_literals): Define.
(elf_zstd_literal_output): New static function.
(ZSTD_LITERAL_LENGTH_BASELINE_OFFSET): Define.
(elf_zstd_literal_length_baseline): New static const array.
(elf_zstd_literal_length_bits): Likewise.
(ZSTD_MATCH_LENGTH_BASELINE_OFFSET): Define.
(elf_zstd_match_length_baseline): New static const array.
(elf_zstd_match_length_bits): Likewise.
(elf_zstd_decompress): New static function.
(ZDEBUG_TABLE_SIZE): New definition.
(elf_uncompress_chdr): Support ELF_COMPRESS_ZSTD.
(backtrace_uncompress_zstd): New function.
(elf_add): Use ZLIB_TABLE_SIZE for zlib-gnu sections.
* internal.h (backtrace_uncompress_zstd): Declare.
* zstdtest.c: New file.
* configure, config.h.in, Makefile.in: Regenerate.
diff --git a/libbacktrace/Makefile.am b/libbacktrace/Makefile.am
index 9f8516d00e2..047b573c29a 100644
--- a/libbacktrace/Makefile.am
+++ b/libbacktrace/Makefile.am
@@ -368,6 +368,25 @@ ztest_alloc_CFLAGS = $(ztest_CFLAGS)
 
 BUILDTESTS += ztest_alloc
 
+zstdtest_SOURCES = zstdtest.c testlib.c
+zstdtest_CFLAGS = $(libbacktrace_TEST_CFLAGS) -DSRCDIR=\"$(srcdir)\"
+zstdtest_LDADD = libbacktrace.la
+zstdtest_alloc_LDADD = libbacktrace_alloc.la
+
+if HAVE_ZSTD
+zstdtest_LDADD += -lzstd
+zstdtest_alloc_LDADD += -lzstd
+endif
+zstdtest_LDADD += $(CLOCK_GETTIME_LINK)
+zstdtest_alloc_LDADD += $(CLOCK_GETTIME_LINK)
+
+BUILDTESTS += zstdtest
+
+zstdtest_alloc_SOURCES = $(zstdtest_SOURCES)
+zstdtest_alloc_CFLAGS = $(zstdtest_CFLAGS)
+
+BUILDTESTS += zstdtest_alloc
+
 endif HAVE_ELF
 
 edtest_SOURCES = edtest.c edtest2_build.c testlib.c
@@ -450,6 +469,17 @@ ctesta_LDADD = libbacktrace.la
 
 BUILDTESTS += ctestg ctesta
 
+if HAVE_COMPRESSED_DEBUG_ZSTD
+
+ctestzstd_SOURCES = btest.c testlib.c
+ctestzstd_CFLAGS = $(libbacktrace_TEST_CFLAGS)
+ctestzstd_LDFLAGS = -Wl,--compress-debug-sections=zstd
+ctestzstd_LDADD = libbacktrace.la
+
+BUILDTESTS += ctestzstd
+
+endif
+
 ctestg_alloc_SOURCES = $(ctestg_SOURCES)
 ctestg_alloc_CFLAGS = $(ctestg_CFLAGS)
 ctestg_alloc_LDFLAGS = $(ctestg_LDFLAGS)
diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac
index 1daaa2f62d2..d0a0475cfa8 100644
--- a/libbacktrace/configure.ac
+++ b/libbacktrace/configure.ac
@@ -495,6 +495,21 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM(,)],
 LDFLAGS=$LDFLAGS_hold])
 AM_CONDITIONAL(HAVE_COMPRESSED_DEBUG, test "$libgo_cv_ld_compress" = yes)
 
+AC_CHECK_LIB([zstd], [ZSTD_compress],
+[AC_DEFINE(HAVE_ZSTD, 1, [Define if -lzstd is available.])])
+AM_CONDITIONAL(HAVE_ZSTD, test "$ac_cv_lib_zstd_ZSTD_compress" = yes)
+
+dnl Test whether the linker supports --compress-debug-sections=zstd option.
+AC_CACHE_CHECK([whether --compress-debug-sections=zstd is supported],
+[libgo_cv_ld_compress_zstd],
+[LDFLAGS_hold=$LDFLAGS
+LDFLAGS="$LDFLAGS -Wl,--compress-debug-sections=zstd"
+AC_LINK_IFELSE([AC_LANG_PROGRAM(,)],
+[libgo_cv_ld_compress_zstd=yes],
+[libgo_cv_ld_compress_zstd=no])
+LDFLAGS=$LDFLAGS_hold])
+AM_CONDITIONAL(HAVE_COMPRESSED_DEBUG_ZSTD, test "$libgo_cv_ld_compress_zstd" = 
yes)
+
 AC_ARG_VAR(OBJCOPY, [location of objcopy])
 AC_CHECK_PROG(OBJCOPY, objcopy, objcopy,)
 AC_CHECK_PROG(READELF, readelf, readelf)
diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index 181d195fe35..15e6f284db6 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -184,6 +184,7 @@ 

Re: [PATCH v2] libgo: Don't rely on GNU-specific strerror_r variant on Linux

2022-11-30 Thread Ian Lance Taylor via Gcc-patches
On Tue, Nov 29, 2022 at 4:10 PM Ian Lance Taylor  wrote:
>
> On Tue, Nov 29, 2022 at 9:54 AM  wrote:
> >
> > From: Sören Tempel 
> >
> > On glibc, there are two versions of strerror_r: An XSI-compliant and a
> > GNU-specific version. The latter is only available on glibc. In order
> > to avoid duplicating the post-processing code of error messages, this
> > commit provides a separate strerror_go symbol which always refers to the
> > XSI-compliant version of strerror_r (even on glibc) by selectively
> > undefining the corresponding feature test macro.
> >
> > Previously, gofrontend assumed that the GNU-specific version of
> > strerror_r was always available on Linux (which isn't the case when
> > using a musl as a libc, for example). This commit thereby improves
> > compatibility with Linux systems that are not using glibc.
> >
> > Tested on x86_64 Alpine Linux Edge and Arch Linux (glibc 2.36).
>
> Thanks.  I committed a version of this, as attached.

I've committed this follow-on patch for Hurd.

Ian
91607eba8fe49c064192122ec60a3e03dd8f2515
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 984d8324004..a26f779557d 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-fef6aa3c1678cdbe7dca454b2cebb369d8ba81bf
+1c5bfd57131b68b91d8400bb017f35d416f7aa7b
 
 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-strerror.c b/libgo/runtime/go-strerror.c
index 13d1d91df84..8ff5ffbdfec 100644
--- a/libgo/runtime/go-strerror.c
+++ b/libgo/runtime/go-strerror.c
@@ -12,7 +12,7 @@
exists to selectively undefine it and provides an alias to the
XSI-compliant version of strerror_r(3).  */
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__gnu_hurd__)
 
 /* Force selection of XSI-compliant strerror_r by glibc.  */
 #undef XOPEN_SOURCE
@@ -21,7 +21,7 @@
 #define _POSIX_C_SOURCE 200112L
 #undef _GNU_SOURCE
 
-#endif /* __linux__ */
+#endif /* defined(__linux__) || defined(__gnu_hurd__) */
 
 #include 
 


Re: [PATCH v2] libgo: Don't rely on GNU-specific strerror_r variant on Linux

2022-11-29 Thread Ian Lance Taylor via Gcc-patches
On Tue, Nov 29, 2022 at 9:54 AM  wrote:
>
> From: Sören Tempel 
>
> On glibc, there are two versions of strerror_r: An XSI-compliant and a
> GNU-specific version. The latter is only available on glibc. In order
> to avoid duplicating the post-processing code of error messages, this
> commit provides a separate strerror_go symbol which always refers to the
> XSI-compliant version of strerror_r (even on glibc) by selectively
> undefining the corresponding feature test macro.
>
> Previously, gofrontend assumed that the GNU-specific version of
> strerror_r was always available on Linux (which isn't the case when
> using a musl as a libc, for example). This commit thereby improves
> compatibility with Linux systems that are not using glibc.
>
> Tested on x86_64 Alpine Linux Edge and Arch Linux (glibc 2.36).

Thanks.  I committed a version of this, as attached.

Ian
b6c6a3d64f2e4e9347733290aca3c75898c44b2e
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 7e531c3f90b..984d8324004 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-5e658f4659c551330ea68f5667e4f951b218f32d
+fef6aa3c1678cdbe7dca454b2cebb369d8ba81bf
 
 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 b03e6553e90..207d5a98127 100644
--- a/libgo/Makefile.am
+++ b/libgo/Makefile.am
@@ -465,6 +465,7 @@ runtime_files = \
runtime/go-nanotime.c \
runtime/go-now.c \
runtime/go-nosys.c \
+   runtime/go-strerror.c \
runtime/go-reflect-call.c \
runtime/go-setenv.c \
runtime/go-signal.c \
diff --git a/libgo/go/syscall/errstr.go b/libgo/go/syscall/errstr.go
index 59f7a82c6d7..9f688e2a0c7 100644
--- a/libgo/go/syscall/errstr.go
+++ b/libgo/go/syscall/errstr.go
@@ -4,23 +4,19 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build !hurd && !linux
-// +build !hurd,!linux
-
 package syscall
 
-//sysnbstrerror_r(errnum int, buf []byte) (err Errno)
-//strerror_r(errnum _C_int, buf *byte, buflen Size_t) _C_int
+import "internal/bytealg"
+
+//extern go_strerror
+func go_strerror(_C_int, *byte, Size_t) _C_int
 
 func Errstr(errnum int) string {
-   for len := 128; ; len *= 2 {
-   b := make([]byte, len)
-   errno := strerror_r(errnum, b)
+   for size := 128; ; size *= 2 {
+   b := make([]byte, size)
+   errno := go_strerror(_C_int(errnum), [0], Size_t(len(b)))
if errno == 0 {
-   i := 0
-   for b[i] != 0 {
-   i++
-   }
+   i := bytealg.IndexByte(b, 0)
// Lowercase first letter: Bad -> bad, but
// STREAM -> STREAM.
if i > 1 && 'A' <= b[0] && b[0] <= 'Z' && 'a' <= b[1] 
&& b[1] <= 'z' {
@@ -29,7 +25,7 @@ func Errstr(errnum int) string {
return string(b[:i])
}
if errno != ERANGE {
-   return "errstr failure"
+   return "strerror_r failure"
}
}
 }
diff --git a/libgo/go/syscall/errstr_glibc.go b/libgo/go/syscall/errstr_glibc.go
deleted file mode 100644
index 03a327dbc90..000
--- a/libgo/go/syscall/errstr_glibc.go
+++ /dev/null
@@ -1,34 +0,0 @@
-// errstr_glibc.go -- GNU/Linux and GNU/Hurd specific error strings.
-
-// Copyright 2010 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.
-
-// We use this rather than errstr.go because on GNU/Linux sterror_r
-// returns a pointer to the error message, and may not use buf at all.
-
-//go:build hurd || linux
-// +build hurd linux
-
-package syscall
-
-import "unsafe"
-
-//sysnbstrerror_r(errnum int, b []byte) (errstr *byte)
-//strerror_r(errnum _C_int, b *byte, len Size_t) *byte
-
-func Errstr(errnum int) string {
-   a := make([]byte, 128)
-   p := strerror_r(errnum, a)
-   b := (*[1000]byte)(unsafe.Pointer(p))
-   i := 0
-   for b[i] != 0 {
-   i++
-   }
-   // Lowercase first letter: Bad -> bad, but STREAM -> STREAM.
-   if i > 1 && 'A' <= b[0] && b[0] <= 'Z' && 'a' <= b[1] && b[1] <= 'z' {
-   c := b[0] + 'a' - 'A'
-   return string(c) + string(b[1:i])
-   }
-   return string(b[:i])
-}
diff --git a/libgo/runtime/go-strerror.c b/libgo/runtime/go-strerror.c
new file mode 100644
index 000..13d1d91df84
--- /dev/null
+++ b/libgo/runtime/go-strerror.c
@@ -0,0 +1,37 @@
+/* go-strerror.c -- wrapper around XSI-compliant strerror_r.
+
+   Copyright 2022 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 

Re: [PATCH] lto: Stream current working directory for first streamed relative filename and adjust relative paths [PR93865]

2022-11-14 Thread Ian Lance Taylor via Gcc-patches
On Thu, Sep 10, 2020 at 1:39 AM Jakub Jelinek via Gcc-patches
 wrote:
>
> If the gcc -c -flto ... commands to compile some or all objects are run in a
> different directory (or in different directories) from the directory in
> which the gcc -flto link line is invoked, then the .debug_line will be
> incorrect if there are any relative filenames, it will use those relative
> filenames while .debug_info will contain a different DW_AT_comp_dir.
>
> The following patch streams (at most once after each clear_line_info)
> the current working directory (what we record in DW_AT_comp_dir) when
> encountering the first relative pathname, and when reading the location info
> reads it back and if the current working directory at that point is
> different from the saved one, adjusts relative paths by adding a relative
> prefix how to go from the current working directory to the previously saved
> path (with a fallback e.g. for DOS e:\\foo vs. d:\\bar change to use
> absolute directory).
>
> Bootstrapped/regtested on x86_64-linux (both lto bootstrap and normal one;
> i686-linux doesn't build due to some unrelated libgo bugs), ok for trunk?
>
> 2020-09-10  Jakub Jelinek  
>
> PR debug/93865
> * lto-streamer.h (struct output_block): Add emit_pad member.
> * lto-streamer-out.c: Include toplev.h.
> (clear_line_info): Set emit_pwd.
> (lto_output_location_1): Encode the ob->current_file != xloc.file
> bit directly into the location number.  If changing file, emit
> additionally a bit whether pwd is emitted and emit it before the
> first relative pathname since clear_line_info.
> (output_function, output_constructor): Don't call clear_line_info
> here.
> * lto-streamer-in.c (struct string_pair_map): New type.
> (struct string_pair_map_hasher): New type.
> (string_pair_map_hasher::hash): New method.
> (string_pair_map_hasher::equal): New method.
> (path_name_pair_hash_table, string_pair_map_allocator): New variables.
> (relative_path_prefix, canon_relative_path_prefix,
> canon_relative_file_name): New functions.
> (canon_file_name): Add relative_prefix argument, if non-NULL
> and string is a relative path, return canon_relative_file_name.
> (lto_location_cache::input_location_and_block): Decode file change
> bit from the location number.  If changing file, unpack bit whether
> pwd is streamed and stream in pwd.  Adjust canon_file_name caller.
> (lto_free_file_name_hash): Delete path_name_pair_hash_table
> and string_pair_map_allocator.


Hi, I've noticed that this patch is incomplete.  It streams the result
of get_src_pwd without passing it through remap_debug_filename.  As in
comp_dir_output in dwarf2out.cc, we should always remap all file and
directory names, including the result of get_src_pwd.

Ian




> --- gcc/lto-streamer.h.jj   2020-09-09 09:08:13.102815586 +0200
> +++ gcc/lto-streamer.h  2020-09-09 12:36:13.120070769 +0200
> @@ -718,6 +718,7 @@ struct output_block
>int current_col;
>bool current_sysp;
>bool reset_locus;
> +  bool emit_pwd;
>tree current_block;
>
>/* Cache of nodes written in this section.  */
> --- gcc/lto-streamer-out.c.jj   2020-09-09 09:08:13.077815963 +0200
> +++ gcc/lto-streamer-out.c  2020-09-09 13:21:34.093021582 +0200
> @@ -47,6 +47,7 @@ along with GCC; see the file COPYING3.
>  #include "file-prefix-map.h" /* remap_debug_filename()  */
>  #include "output.h"
>  #include "ipa-utils.h"
> +#include "toplev.h"
>
>
>  static void lto_write_tree (struct output_block*, tree, bool);
> @@ -61,6 +62,7 @@ clear_line_info (struct output_block *ob
>ob->current_col = 0;
>ob->current_sysp = false;
>ob->reset_locus = true;
> +  ob->emit_pwd = true;
>/* Initialize to something that will never appear as block,
>   so that the first location with block in a function etc.
>   always streams a change_block bit and the first block.  */
> @@ -189,9 +191,6 @@ lto_output_location_1 (struct output_blo
>  {
>location_t loc = LOCATION_LOCUS (orig_loc);
>
> -  bp_pack_int_in_range (bp, 0, RESERVED_LOCATION_COUNT,
> -   loc < RESERVED_LOCATION_COUNT
> -   ? loc : RESERVED_LOCATION_COUNT);
>if (loc >= RESERVED_LOCATION_COUNT)
>  {
>expanded_location xloc = expand_location (loc);
> @@ -207,13 +206,30 @@ lto_output_location_1 (struct output_blo
>   ob->reset_locus = false;
> }
>
> -  bp_pack_value (bp, ob->current_file != xloc.file, 1);
> +  /* As RESERVED_LOCATION_COUNT is 2, we can use the spare value of
> +3 without wasting additional bits to signalize file change.
> +If RESERVED_LOCATION_COUNT changes, reconsider this.  */
> +  gcc_checking_assert (RESERVED_LOCATION_COUNT == 2);
> +  bp_pack_int_in_range (bp, 0, RESERVED_LOCATION_COUNT + 1,
> +   

Go patch committed: Define __atomic_fetch_add functions

2022-11-09 Thread Ian Lance Taylor via Gcc-patches
This patch to the GCC-specific part of the Go frontend defines the
__atomic_fetch_add functions.  The frontend only generates calls to
the __atomic_add_fetch functions, but in some cases the middle-end can
transform the latter into the former.  This patch is originally by
Marc Poulhiès.  This fixes PR  107581.  Bootstrapped and ran Go
testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc
index 1ba7206caeb..6e5887aecab 100644
--- a/gcc/go/go-gcc.cc
+++ b/gcc/go/go-gcc.cc
@@ -886,16 +886,20 @@ Gcc_backend::Gcc_backend()
uint32_type_node,
integer_type_node,
NULL_TREE);
-  this->define_builtin(BUILT_IN_ATOMIC_ADD_FETCH_4, "__atomic_add_fetch_4", 
NULL,
-   t, 0);
+  this->define_builtin(BUILT_IN_ATOMIC_ADD_FETCH_4, "__atomic_add_fetch_4",
+  NULL, t, 0);
+  this->define_builtin(BUILT_IN_ATOMIC_FETCH_ADD_4, "__atomic_fetch_add_4",
+  NULL, t, 0);
 
   t = build_function_type_list(uint64_type_node,
ptr_type_node,
uint64_type_node,
integer_type_node,
NULL_TREE);
-  this->define_builtin(BUILT_IN_ATOMIC_ADD_FETCH_8, "__atomic_add_fetch_8", 
NULL,
-   t, 0);
+  this->define_builtin(BUILT_IN_ATOMIC_ADD_FETCH_8, "__atomic_add_fetch_8",
+  NULL, t, 0);
+  this->define_builtin(BUILT_IN_ATOMIC_FETCH_ADD_8, "__atomic_fetch_add_8",
+  NULL, t, 0);
 
   t = build_function_type_list(unsigned_char_type_node,
   ptr_type_node,


Re: [PATCH] libgo: use _off_t for mmap offset argument

2022-10-27 Thread Ian Lance Taylor via Gcc-patches
On Sat, Oct 22, 2022 at 6:45 AM Sören Tempel  wrote:
>
> PING.
>
> soe...@soeren-tempel.net wrote:
> > From: Sören Tempel 
> >
> > On glibc-based systems, off_t is a 32-bit type on 32-bit systems and a
> > 64-bit type on 64-bit systems by default. However, on systems using musl
> > libc off_t is unconditionally a 64-bit type. As such, it is insufficient
> > to use a uintptr type for the mmap offset parameter.
> >
> > Presently, the (incorrect) mmap declaration causes a libgo run-time
> > failure on 32-bit musl systems (fatal error: runtime: cannot allocate
> > memory). This commit fixes this run-time error.
> >
> > Signed-off-by: Sören Tempel 
> > ---
> > This implements what has been proposed by Ian in a GitHub comment
> > https://github.com/golang/go/issues/51280#issuecomment-1046322011
> >
> > I don't have access to a 32-bit glibc system to test this on but
> > this does seem to work fine on 32-bit and 64-bit musl systems.

Thanks.  Committed as follows using _libgo_off_t_type to avoid the
confusion between off_t and off64_t.

Sorry for the delay.

Ian
11a5fc0c76aedb100b5d7ecc7dd4bed33d850bb8
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 5b95b38a541..7e531c3f90b 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-6c188108858e3ae8c8ea8e4cc55427d8cf01bbc8
+5e658f4659c551330ea68f5667e4f951b218f32d
 
 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/runtime/mem_gccgo.go b/libgo/go/runtime/mem_gccgo.go
index fa3389d857e..1e84f4f5c56 100644
--- a/libgo/go/runtime/mem_gccgo.go
+++ b/libgo/go/runtime/mem_gccgo.go
@@ -15,7 +15,7 @@ import (
 //go:linkname sysFree
 
 //extern mmap
-func sysMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off 
uintptr) unsafe.Pointer
+func sysMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off 
_libgo_off_t_type) 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, off)
+   p := sysMmap(addr, n, prot, flags, fd, _libgo_off_t_type(off))
if uintptr(p) == _MAP_FAILED {
return nil, errno()
}
@@ -47,6 +47,7 @@ func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd 
int32, off uintptr) (u
 
 // Don't split the stack as this method may be invoked without a valid G, which
 // prevents us from allocating more stack.
+//
 //go:nosplit
 func sysAlloc(n uintptr, sysStat *sysMemStat) unsafe.Pointer {
p, err := mmap(nil, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_PRIVATE, 
mmapFD, 0)
@@ -165,6 +166,7 @@ func sysHugePage(v unsafe.Pointer, n uintptr) {
 
 // Don't split the stack as this function may be invoked without a valid G,
 // which prevents us from allocating more stack.
+//
 //go:nosplit
 func sysFree(v unsafe.Pointer, n uintptr, sysStat *sysMemStat) {
sysStat.add(-int64(n))


Go patch committed: Treat S("") as a string constant

2022-10-10 Thread Ian Lance Taylor via Gcc-patches
This Go frontend patch treats S("") as a string constant.  The
compiler neglected to notice that a conversion from a string constant
to a string type was a valid string constant.

I didn't add a test case because this only caused a compiler failure
when compiling without optimization, which is not the normal case, and
is not a case that we test.

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

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

Ian
29b0fe393859729215b0db5d28f2faea30c6ec32
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 1c2466090f1..5b95b38a541 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-164f2aeb1deec4c11e55b8bfb152ff7ff4c1dd4c
+6c188108858e3ae8c8ea8e4cc55427d8cf01bbc8
 
 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 247ae1bba34..71838b14629 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -4092,6 +4092,9 @@ Type_conversion_expression::do_numeric_constant_value(
 bool
 Type_conversion_expression::do_string_constant_value(std::string* val) const
 {
+  if (this->type_->is_string_type() && this->expr_->type()->is_string_type())
+return this->expr_->string_constant_value(val);
+
   if (this->type_->is_string_type()
   && this->expr_->type()->integer_type() != NULL)
 {


Go patch committed: Only build thunk struct type when needed

2022-10-10 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend delays building the struct type for a
go/defer thunk until it is needed.  We were building it in the
determine_types pass.  Now, we delay until the
simplify_thunk_statements pass.  That ensures that we are consistent
in determining whether an argument is constant.

With this change we no longer need to add a field for a call to
recover, as the simplify_thunk_statements pass runs after the
build_recover_thunks pass, so the additional argument will already
have been added to the call.

The test case for this is https://go.dev/cl/440297.

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

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

Ian
10c26259a8ea34a63a14e85b18e6066766ad6a7a
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 10ed3fee67c..1c2466090f1 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-50707b4b51266166ce9bcf9de187e35760ec50f9
+164f2aeb1deec4c11e55b8bfb152ff7ff4c1dd4c
 
 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 b442830b0b7..af8c7d15998 100644
--- a/gcc/go/gofrontend/statements.cc
+++ b/gcc/go/gofrontend/statements.cc
@@ -2349,7 +2349,7 @@ Thunk_statement::Thunk_statement(Statement_classification 
classification,
 Call_expression* call,
 Location location)
 : Statement(classification, location),
-  call_(call), struct_type_(NULL)
+  call_(call)
 {
 }
 
@@ -2430,15 +2430,6 @@ void
 Thunk_statement::do_determine_types()
 {
   this->call_->determine_type_no_context();
-
-  // Now that we know the types of the call, build the struct used to
-  // pass parameters.
-  Call_expression* ce = this->call_->call_expression();
-  if (ce == NULL)
-return;
-  Function_type* fntype = ce->get_function_type();
-  if (fntype != NULL && !this->is_simple(fntype))
-this->struct_type_ = this->build_struct(fntype);
 }
 
 // Check types in a thunk statement.
@@ -2581,6 +2572,8 @@ Thunk_statement::simplify_statement(Gogo* gogo, 
Named_object* function,
   if (this->is_simple(fntype))
 return false;
 
+  Struct_type* struct_type = this->build_struct(fntype);
+
   Expression* fn = ce->fn();
   Interface_field_reference_expression* interface_method =
 fn->interface_field_reference_expression();
@@ -2600,7 +2593,7 @@ Thunk_statement::simplify_statement(Gogo* gogo, 
Named_object* function,
   std::string thunk_name = gogo->thunk_name();
 
   // Build the thunk.
-  this->build_thunk(gogo, thunk_name);
+  this->build_thunk(gogo, thunk_name, struct_type);
 
   // Generate code to call the thunk.
 
@@ -2630,8 +2623,7 @@ Thunk_statement::simplify_statement(Gogo* gogo, 
Named_object* function,
 
   // Build the struct.
   Expression* constructor =
-Expression::make_struct_composite_literal(this->struct_type_, vals,
- location);
+Expression::make_struct_composite_literal(struct_type, vals, location);
 
   // Allocate the initialized struct on the heap.
   constructor = Expression::make_heap_expression(constructor, location);
@@ -2745,15 +2737,6 @@ Thunk_statement::build_struct(Function_type* fntype)
   fields->push_back(Struct_field(tid));
 }
 
-  // The predeclared recover function has no argument.  However, we
-  // add an argument when building recover thunks.  Handle that here.
-  if (ce->is_recover_call())
-{
-  fields->push_back(Struct_field(Typed_identifier("can_recover",
- Type::lookup_bool_type(),
- location)));
-}
-
   const Expression_list* args = ce->args();
   if (args != NULL)
 {
@@ -2781,7 +2764,8 @@ Thunk_statement::build_struct(Function_type* fntype)
 // artificial, function.
 
 void
-Thunk_statement::build_thunk(Gogo* gogo, const std::string& thunk_name)
+Thunk_statement::build_thunk(Gogo* gogo, const std::string& thunk_name,
+Struct_type* struct_type)
 {
   Location location = this->location();
 
@@ -2807,7 +2791,7 @@ Thunk_statement::build_thunk(Gogo* gogo, const 
std::string& thunk_name)
   // which is a pointer to the special structure we build.
   const char* const parameter_name = "__go_thunk_parameter";
   Typed_identifier_list* thunk_parameters = new Typed_identifier_list();
-  Type* pointer_to_struct_type = Type::make_pointer_type(this->struct_type_);
+  Type* pointer_to_struct_type = Type::make_pointer_type(struct_type);
   thunk_parameters->push_back(Typed_identifier(parameter_name,
   pointer_to_struct_type,
   location));
@@ -2914,7 +2898,7 @@ Thunk_statement::build_thunk(Gogo* gogo, const 
std::string& thunk_name)
 }
 
   Expression_list* call_params = 

Go patch committed: better argument checking for builtins

2022-10-06 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend by Than McIntosh does some better
argument type checking for some builtin functions.  This avoids a
compiler crash on cases like panic(panic("bad")).  This fixes
https://go.dev/issue/56071.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
05c581aef882b3a6369acde2d37a437ef144705c
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 4793c821eba..10ed3fee67c 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-8f1a91aeff400d572857895b7f5e863ec5a4d93e
+50707b4b51266166ce9bcf9de187e35760ec50f9
 
 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 2492d9fe735..247ae1bba34 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -10316,7 +10316,12 @@ Builtin_call_expression::do_check_types(Gogo*)
 case BUILTIN_PANIC:
 case BUILTIN_SIZEOF:
 case BUILTIN_ALIGNOF:
-  this->check_one_arg();
+  if (this->check_one_arg())
+{
+ Expression* arg = this->one_arg();
+ if (arg->type()->is_void_type())
+   this->report_error(_("argument to builtin has void type"));
+}
   break;
 
 case BUILTIN_RECOVER:


Re: [PATCH v2] libgo: Portable access to thread ID in struct sigevent

2022-09-27 Thread Ian Lance Taylor via Gcc-patches
On Fri, Sep 23, 2022 at 6:59 AM  wrote:
>
> From: Sören Tempel 
>
> Tested on x86_64 Arch Linux (glibc) and Alpine Linux (musl libc).
>
> Previously, libgo relied on the _sigev_un implementation-specific
> field in struct sigevent, which is only available on glibc. This
> patch uses the sigev_notify_thread_id macro instead which is mandated
> by timer_create(2). In theory, this should work with any libc
> implementation for Linux. Unfortunately, there is an open glibc bug
> as glibc does not define this macro. For this reason, a glibc-specific
> workaround is required. Other libcs (such as musl) define the macro
> and don't require the workaround.
>
> This makes go_signal compatible with musl libc.
>
> See: https://sourceware.org/bugzilla/show_bug.cgi?id=27417

Thanks.  Committed with some changes, as appended.

Sorry for the delay.

Ian
e73d9fcafbd07bc3714fbaf8a82db71d50015c92
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 73aa712dbdf..4793c821eba 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-0140cca9bc0fad1108c7ed369376ac71cc4bfecf
+8f1a91aeff400d572857895b7f5e863ec5a4d93e
 
 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/runtime/os_linux.go b/libgo/go/runtime/os_linux.go
index 96fb178870e..2b2d827cee8 100644
--- a/libgo/go/runtime/os_linux.go
+++ b/libgo/go/runtime/os_linux.go
@@ -22,6 +22,12 @@ type mOS struct {
profileTimerValid uint32
 }
 
+// setSigeventTID is written in C to set the sigev_notify_thread_id
+// field of a sigevent struct.
+//
+//go:noescape
+func setSigeventTID(*_sigevent, int32)
+
 func getProcID() uint64 {
return uint64(gettid())
 }
@@ -52,9 +58,12 @@ const (
 )
 
 // Atomically,
+//
 // if(*addr == val) sleep
+//
 // Might be woken up spuriously; that's allowed.
 // Don't sleep longer than ns; ns < 0 means forever.
+//
 //go:nosplit
 func futexsleep(addr *uint32, val uint32, ns int64) {
// Some Linux kernels have a bug where futex of
@@ -73,6 +82,7 @@ func futexsleep(addr *uint32, val uint32, ns int64) {
 }
 
 // If any procs are sleeping on addr, wake up at most cnt.
+//
 //go:nosplit
 func futexwakeup(addr *uint32, cnt uint32) {
ret := futex(unsafe.Pointer(addr), _FUTEX_WAKE_PRIVATE, cnt, nil, nil, 
0)
@@ -365,7 +375,7 @@ func setThreadCPUProfiler(hz int32) {
var sevp _sigevent
sevp.sigev_notify = _SIGEV_THREAD_ID
sevp.sigev_signo = _SIGPROF
-   *((*int32)(unsafe.Pointer(_sigev_un))) = int32(mp.procid)
+   setSigeventTID(, int32(mp.procid))
ret := timer_create(_CLOCK_THREAD_CPUTIME_ID, , )
if ret != 0 {
// If we cannot create a timer for this M, leave 
profileTimerValid false
diff --git a/libgo/runtime/go-signal.c b/libgo/runtime/go-signal.c
index 528d9b6d9fe..aa1b6305ad0 100644
--- a/libgo/runtime/go-signal.c
+++ b/libgo/runtime/go-signal.c
@@ -183,6 +183,24 @@ setSigactionHandler(struct sigaction* sa, uintptr handler)
sa->sa_sigaction = (void*)(handler);
 }
 
+#ifdef __linux__
+
+// Workaround for https://sourceware.org/bugzilla/show_bug.cgi?id=27417
+#ifndef sigev_notify_thread_id
+  #define sigev_notify_thread_id _sigev_un._tid
+#endif
+
+void setSigeventTID(struct sigevent*, int32_t)
+   __asm__ (GOSYM_PREFIX "runtime.setSigeventTID");
+
+void
+setSigeventTID(struct sigevent *sev, int32_t v)
+{
+   sev->sigev_notify_thread_id = v;
+}
+
+#endif // defined(__linux__)
+
 // C code to fetch values from the siginfo_t and ucontext_t pointers
 // passed to a signal handler.
 


libgo patch committed: Synchronize empty struct field handling

2022-09-27 Thread Ian Lance Taylor via Gcc-patches
This libgo patch by Funan Zeng synchronizes the handling of empty
struct fields between the Go frontend and the libgo FFI code.  In the
compiler the logic for allocating one byte for the last field of a
struct is:
1. the last field has zero size
2. the struct itself does not have zero size
3. the last field is not blank
This patch adds the last two conditions to runtime.structToFFI.  This
is for https://go.dev/issue/55146.  Bootstrapped and ran Go testsuite
on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
085bacba3502ff77c70a7660c19a68f50e9b7877
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index f7a7985287d..73aa712dbdf 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-42efec8c126cf3787bc7c89d9c7f224eff7c5a21
+0140cca9bc0fad1108c7ed369376ac71cc4bfecf
 
 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/runtime/ffi.go b/libgo/go/runtime/ffi.go
index cd8479ef551..86ce5b85d04 100644
--- a/libgo/go/runtime/ffi.go
+++ b/libgo/go/runtime/ffi.go
@@ -4,6 +4,7 @@
 
 // Only build this file if libffi is supported.
 
+//go:build libffi
 // +build libffi
 
 package runtime
@@ -221,9 +222,6 @@ func stringToFFI() *__ffi_type {
 // structToFFI returns an ffi_type for a Go struct type.
 func structToFFI(typ *structtype) *__ffi_type {
c := len(typ.fields)
-   if c == 0 {
-   return emptyStructToFFI()
-   }
if typ.typ.kind != 0 {
return ffi_type_pointer()
}
@@ -231,6 +229,7 @@ func structToFFI(typ *structtype) *__ffi_type {
fields := make([]*__ffi_type, 0, c+1)
checkPad := false
lastzero := false
+   sawnonzero := false
for i, v := range typ.fields {
// Skip zero-sized fields; they confuse libffi,
// and there is no value to pass in any case.
@@ -239,10 +238,13 @@ func structToFFI(typ *structtype) *__ffi_type {
// next field.
if v.typ.size == 0 {
checkPad = true
-   lastzero = true
+   if v.name == nil || *v.name != "_" {
+   lastzero = true
+   }
continue
}
lastzero = false
+   sawnonzero = true
 
if checkPad {
off := uintptr(0)
@@ -263,6 +265,10 @@ func structToFFI(typ *structtype) *__ffi_type {
fields = append(fields, typeToFFI(v.typ))
}
 
+   if !sawnonzero {
+   return emptyStructToFFI()
+   }
+
if lastzero {
// The compiler adds one byte padding to non-empty struct ending
// with a zero-sized field (types.cc:get_backend_struct_fields).


Merge from trunk to gccgo branch

2022-09-22 Thread Ian Lance Taylor via Gcc-patches
I've merged trunk revision f35be1268c996d993ab0b4ff329734d467474445 to
the gccgo branch.

Ian


libgo patch committed: Add cgo.Incomplete

2022-09-22 Thread Ian Lance Taylor via Gcc-patches
This libgo patch changes the cgo command to use runtime/cgo.Incomplete
instead of //go:notinheap, and to define the new type in the
runtime/cgo package.  This ports https://go.dev/cl/421879 to libgo.
This is a quick port to update libgo to work with the version of cgo
in gc mainline.  A more complete port will follow, changing the gc
version of cmd/cgo to choose an approach based on feature testing the
gccgo in use.  Bootstrapped and tested on x86_64-pc-linux-gnu.
Committed to mainline.

Ian
c69b87678d3c4e9b995b8ccb51fb38c75a134323
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index dce38e727a7..f7a7985287d 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-6543b7fc6da533eb976b37649a925e7fd5a521fa
+42efec8c126cf3787bc7c89d9c7f224eff7c5a21
 
 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/cgo/gcc.go b/libgo/go/cmd/cgo/gcc.go
index 02391495bbe..e786aeaafa9 100644
--- a/libgo/go/cmd/cgo/gcc.go
+++ b/libgo/go/cmd/cgo/gcc.go
@@ -132,12 +132,11 @@ func (p *Package) addToFlag(flag string, args []string) {
 //
 // For example, the following string:
 //
-// `a b:"c d" 'e''f'  "g\""`
+// `a b:"c d" 'e''f'  "g\""`
 //
 // Would be parsed as:
 //
-// []string{"a", "b:c d", "ef", `g"`}
-//
+// []string{"a", "b:c d", "ef", `g"`}
 func splitQuoted(s string) (r []string, err error) {
var args []string
arg := make([]rune, len(s))
@@ -1156,13 +1155,19 @@ func (p *Package) mangle(f *File, arg *ast.Expr, 
addPosition bool) (ast.Expr, bo
 
 // checkIndex checks whether arg has the form [i], possibly inside
 // type conversions. If so, then in the general case it writes
-//_cgoIndexNN := a
-//_cgoNN := [i] // with type conversions, if any
+//
+// _cgoIndexNN := a
+// _cgoNN := [i] // with type conversions, if any
+//
 // to sb, and writes
-//_cgoCheckPointer(_cgoNN, _cgoIndexNN)
+//
+// _cgoCheckPointer(_cgoNN, _cgoIndexNN)
+//
 // to sbCheck, and returns true. If a is a simple variable or field reference,
 // it writes
-//_cgoIndexNN := 
+//
+// _cgoIndexNN := 
+//
 // and dereferences the uses of _cgoIndexNN. Taking the address avoids
 // making a copy of an array.
 //
@@ -1210,10 +1215,14 @@ func (p *Package) checkIndex(sb, sbCheck *bytes.Buffer, 
arg ast.Expr, i int) boo
 
 // checkAddr checks whether arg has the form , possibly inside type
 // conversions. If so, it writes
-//_cgoBaseNN := 
-//_cgoNN := _cgoBaseNN // with type conversions, if any
+//
+// _cgoBaseNN := 
+// _cgoNN := _cgoBaseNN // with type conversions, if any
+//
 // to sb, and writes
-//_cgoCheckPointer(_cgoBaseNN, true)
+//
+// _cgoCheckPointer(_cgoBaseNN, true)
+//
 // to sbCheck, and returns true. This tells _cgoCheckPointer to check
 // just the contents of the pointer being passed, not any other part
 // of the memory allocation. This is run after checkIndex, which looks
@@ -2131,8 +2140,8 @@ type typeConv struct {
// Type names X for which there exists an XGetTypeID function with type 
func() CFTypeID.
getTypeIDs map[string]bool
 
-   // badStructs contains C structs that should be marked NotInHeap.
-   notInHeapStructs map[string]bool
+   // incompleteStructs contains C structs that should be marked 
Incomplete.
+   incompleteStructs map[string]bool
 
// Predeclared types.
bool   ast.Expr
@@ -2145,7 +2154,6 @@ type typeConv struct {
string ast.Expr
goVoid ast.Expr // _Ctype_void, denotes 
C's void
goVoidPtr  ast.Expr // unsafe.Pointer or 
*byte
-   goVoidPtrNoHeapast.Expr // 
*_Ctype_void_notinheap, like goVoidPtr but marked NotInHeap
 
ptrSize int64
intSize int64
@@ -2169,7 +2177,7 @@ func (c *typeConv) Init(ptrSize, intSize int64) {
c.m = make(map[string]*Type)
c.ptrs = make(map[string][]*Type)
c.getTypeIDs = make(map[string]bool)
-   c.notInHeapStructs = make(map[string]bool)
+   c.incompleteStructs = make(map[string]bool)
c.bool = c.Ident("bool")
c.byte = c.Ident("byte")
c.int8 = c.Ident("int8")
@@ -2188,7 +2196,6 @@ func (c *typeConv) Init(ptrSize, intSize int64) {
c.void = c.Ident("void")
c.string = c.Ident("string")
c.goVoid = c.Ident("_Ctype_void")
-   c.goVoidPtrNoHeap = c.Ident("*_Ctype_void_notinheap")
 
// Normally cgo translates void* to unsafe.Pointer,
// but for historical reasons -godefs uses *byte instead.
@@ -2531,19 +2538,13 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos 
token.Pos, parent string) *Typ
// other than try to determine a Go representation.
tt := *t
tt.C = {"%s %s", 

Re: libgo patch committed: Make runtime.Version return a useful value

2022-09-13 Thread Ian Lance Taylor via Gcc-patches
On Tue, Jun 28, 2022 at 10:20 AM Ian Lance Taylor  wrote:
>
> This libgo patch makes runtime.Version return a meaningful string.
> This also means that "go version" will print something useful, e.g.,
>
> go version go1.18 gccgo (GCC) 12.0.1 20220216 (experimental) linux/amd64
>
> This fixes https://go.dev/issue/51850.
>
> Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
> to mainline.

I've committed this to the GCC 12 branch, for PR 106747.

Ian


Re: libgo patch committed: Ignore __morestack in runtime.Callers

2022-09-13 Thread Ian Lance Taylor via Gcc-patches
On Tue, Sep 6, 2022 at 6:40 PM Ian Lance Taylor  wrote:
>
> This libgo patch ignores the __morestack function in runtime.Callers.
> We were ignoring all functions starting with "__morestack_", but not
> the function "__morestack" itself.  Without this change, some tests
> such as recover.go started failing recently, though I'm not sure
> exactly what changed.  Bootstrapped and ran Go testsuite on
> x86_64-pc-linux-gnu.  Committed to mainline.

I've also committed this patch to GCC 12 branch.

Ian


libgo patch committed: Ignore __morestack in runtime.Callers

2022-09-06 Thread Ian Lance Taylor via Gcc-patches
This libgo patch ignores the __morestack function in runtime.Callers.
We were ignoring all functions starting with "__morestack_", but not
the function "__morestack" itself.  Without this change, some tests
such as recover.go started failing recently, though I'm not sure
exactly what changed.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
c0852b51b7a68ada822955eb7ef83d933cc33e47
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index ca797045d66..dce38e727a7 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-d53e8a0e94e34dc609e34dd5e404debda2640cfb
+6543b7fc6da533eb976b37649a925e7fd5a521fa
 
 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-callers.c b/libgo/runtime/go-callers.c
index 31783696a08..1d4dee66279 100644
--- a/libgo/runtime/go-callers.c
+++ b/libgo/runtime/go-callers.c
@@ -107,7 +107,7 @@ callback (void *data, uintptr_t pc, const char *filename, 
int lineno,
   p = function;
   if (__builtin_strncmp (p, "___", 3) == 0)
++p;
-  if (__builtin_strncmp (p, "__morestack_", 12) == 0)
+  if (__builtin_strncmp (p, "__morestack", 11) == 0)
return 0;
 }
   else if (filename != NULL)


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] 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.


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


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


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)


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;


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


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"


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, , ))
-   return 0;
+   continue;
 
   if (mff != macho_nodebug)
macho_fileline_fn = mff;


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:


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());


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 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(, 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(, 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_; }
-
- 

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 (, 0, sizeof sa);
+  sa.sa_sigaction = sighandler;
+  sigaction (SIGSEGV, , NULL);
+  sigaction (SIGBUS, , 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 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(,
+  if (!no->type_value()->struct_type()->can_write_to_c_header(,
  ))
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(, ))
+ can_write_to_c_header(, ))
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(), ,
+   if (!this->can_write_type_to_c_header(t->points_to(), ,
  ))
  os << "void*";
else


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


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

2022-06-29 Thread Ian Lance Taylor via Gcc-patches
On Tue, Jun 28, 2022 at 7:32 AM Sören Tempel  wrote:
>
> Ian Lance Taylor  wrote:
> > Given that pretty much every one of these musl patches has led to
> > problems on some glibc systems, it would be very nice if you could do
> > some testing with glibc.  Thanks.
>
> Sorry, my bad.
>
> I just tested this on Arch Linux and it compiles fine with the patch.
>
> > Can you expand on the st_atim issue?
>
> The st_atim issue is simply that struct stat contains additional struct
> fields on 32-bit musl architectures (__st_{a,m,c}tim32) in addition to
> st_{a,m,c}tim [1]. The sed expression currently only replaces the first
> occurrence (i.e. __st_{a,m,c}tim32) from gen-sysinfo.go:
>
> $ grep 'st_[acm]tim' sysinfo.go
> type _stat struct { st_dev uint64; __st_dev_padding int32; 
> __st_ino_truncated int32; st_mode uint32; st_nlink uint32; st_uid uint32; 
> st_gid uint32; st_rdev uint64; __st_rdev_padding int32; st_size int64; 
> st_blksize int32; st_blocks int64; __st_atim32 struct { tv_sec int32; tv_nsec 
> int32; }; __st_mtim32 struct { tv_sec int32; tv_nsec int32; }; __st_ctim32 
> struct { tv_sec int32; tv_nsec int32; }; st_ino uint64; st_atim Timespec; 
> st_mtim Timespec; st_ctim Timespec; }
> type Stat_t struct { Dev uint64; __st_dev_padding int32; 
> __Ino_truncated int32; Mode uint32; Nlink uint32; Uid uint32; Gid uint32; 
> Rdev uint64; __st_rdev_padding int32; Size int64; Blksize int32; Blocks 
> int64; __Atim32 struct { tv_sec int32; tv_nsec int32; }; __Mtim32 struct { 
> tv_sec int32; tv_nsec int32; }; __Ctim32 struct { tv_sec int32; tv_nsec 
> int32; }; Ino uint64; st_atim Timespec; st_mtim Timespec; st_ctim Timespec; }
>
> This causes the following build error on 32-bit musl architectures:
>
> stat_atim.go: error: reference to undefined field or method 'Mtim'
>17 | fs.modTime = timespecToTime(fs.sys.Mtim)
>   |   ^
> stat_atim.go: error: reference to undefined field or method 'Atim'
>52 | return timespecToTime(fi.Sys().(*syscall.Stat_t).Atim)
>   | ^
>
> This is fixed by the proposed patch by replacing both members in struct stat.
>
> > What does the musl type look like in gen-sysinfo.go?
>
> $ grep 'st_[acm]tim' gen-sysinfo.go
> // unknowndefine st_atime st_atim.tv_sec
> // unknowndefine st_mtime st_mtim.tv_sec
> // unknowndefine st_ctime st_ctim.tv_sec
> type _stat struct { st_dev uint64; __st_dev_padding int32; 
> __st_ino_truncated int32; st_mode uint32; st_nlink uint32; st_uid uint32; 
> st_gid uint32; st_rdev uint64; __st_rdev_padding int32; st_size int64; 
> st_blksize int32; st_blocks int64; __st_atim32 struct { tv_sec int32; tv_nsec 
> int32; }; __st_mtim32 struct { tv_sec int32; tv_nsec int32; }; __st_ctim32 
> struct { tv_sec int32; tv_nsec int32; }; st_ino uint64; st_atim _timespec; 
> st_mtim _timespec; st_ctim _timespec; }
>
> > What is the value of SYS_SECCOMP in musl?  Is it a system call number?
>
> SYS_SECCOMP is a macro defined in signal.h which can be used to check
> the si_code member of siginfo_t for SIGSYS, see the SECCOMP_RET_TRAP
> description in seccomp(2). As such, it is not a system call number.
> The value of SYS_SECCOMP is simply 1 [2].
>
> > What does it look like in gen-sysinfo.go?
>
> Defined in gen-sysinfo.go as follows:
>
> 4688:const _SYS_seccomp = 317
> 4775:const _SYS_SECCOMP = 1
>
> where the former is the syscall and the latter is the expanded
> SYS_SECCOMP macro constant. When generating sysinfo.go the name seems to
> be uppercased, thus resulting in a compilation failure. The generated
> sysinfo.go contains the following lines:
>
> 3067:const _SYS_seccomp = 317
> 3154:const _SYS_SECCOMP = 1
> 6600:const SYS_SECCOMP = _SYS_seccomp
> 6606:const SYS_SECCOMP = _SYS_SECCOMP
>
> Build error:
>
> sysinfo.go:6606:7: error: redefinition of 'SYS_SECCOMP'
>  6606 | const SYS_SECCOMP = _SYS_SECCOMP
>   |   ^
> sysinfo.go:6600:7: note: previous definition of 'SYS_SECCOMP' was here
>  6600 | const SYS_SECCOMP = _SYS_seccomp
>   |   ^
>
> This is fixed by the patch by only extracting _SYS_seccomp, not _SYS_SECCOMP.
>
> If you need more information, just let me know :)


Thanks for the info.  Does this patch work?  It tweaks the handling of
SYS_SECCOMP to be specific to that constant.

Ian
diff --git a/libgo/mksysinfo.sh b/libgo/mksysinfo.sh
index 5aa309155..ea1fa17d4 100755
--- a/libgo/mksysinfo.sh
+++ b/libgo/mksysinfo.sh
@@ -127,6 +127,7 @@ fi
 
 # The syscall numbers.  We force the names to upper case.
 grep '^const _SYS_' gen-sysinfo.go | \
+  grep -v '^const _SYS_SECCOMP = ' | \
   sed -e 's/const _\(SYS_[^= ]*\).*$/\1/' | \
   while read sys; do
 sup=`echo $sys | tr abcdefghijklmnopqrstuvwxyz 

Go patch committed: Check repeated const expressions in new scop

2022-06-29 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend checks repeated const expressions in new
scope, in case they refer to a newly defined name.  The test case is
const8.go in https://go.dev/cl/414795.  This fixes
https://go.dev/issue/53585.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
dabc73c20057d016027fd1af22575e2325cad9ef
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 13cb6ea4046..4fde25af76e 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-c7238f58a26131b7611eff6f555cab02af8a623c
+63782f8a318e9eebfdc983f171a920c7a937c759
 
 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 aadca9710e6..00d35a965a9 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -3352,97 +3352,7 @@ class Find_named_object : public Traverse
   bool found_;
 };
 
-// A reference to a const in an expression.
-
-class Const_expression : public Expression
-{
- public:
-  Const_expression(Named_object* constant, Location location)
-: Expression(EXPRESSION_CONST_REFERENCE, location),
-  constant_(constant), type_(NULL), seen_(false)
-  { }
-
-  Named_object*
-  named_object()
-  { return this->constant_; }
-
-  const Named_object*
-  named_object() const
-  { return this->constant_; }
-
-  // Check that the initializer does not refer to the constant itself.
-  void
-  check_for_init_loop();
-
- protected:
-  int
-  do_traverse(Traverse*);
-
-  Expression*
-  do_lower(Gogo*, Named_object*, Statement_inserter*, int);
-
-  bool
-  do_is_constant() const
-  { return true; }
-
-  bool
-  do_is_zero_value() const
-  { return this->constant_->const_value()->expr()->is_zero_value(); }
-
-  bool
-  do_is_static_initializer() const
-  { return true; }
-
-  bool
-  do_numeric_constant_value(Numeric_constant* nc) const;
-
-  bool
-  do_string_constant_value(std::string* val) const;
-
-  bool
-  do_boolean_constant_value(bool* val) const;
-
-  Type*
-  do_type();
-
-  // The type of a const is set by the declaration, not the use.
-  void
-  do_determine_type(const Type_context*);
-
-  void
-  do_check_types(Gogo*);
-
-  Expression*
-  do_copy()
-  { return this; }
-
-  Bexpression*
-  do_get_backend(Translate_context* context);
-
-  int
-  do_inlining_cost() const
-  { return 1; }
-
-  // When exporting a reference to a const as part of a const
-  // expression, we export the value.  We ignore the fact that it has
-  // a name.
-  void
-  do_export(Export_function_body* efb) const
-  { this->constant_->const_value()->expr()->export_expression(efb); }
-
-  void
-  do_dump_expression(Ast_dump_context*) const;
-
- private:
-  // The constant.
-  Named_object* constant_;
-  // The type of this reference.  This is used if the constant has an
-  // abstract type.
-  Type* type_;
-  // Used to prevent infinite recursion when a constant incorrectly
-  // refers to itself.
-  mutable bool seen_;
-};
+// Class Const_expression.
 
 // Traversal.
 
@@ -3454,6 +3364,14 @@ Const_expression::do_traverse(Traverse* traverse)
   return TRAVERSE_CONTINUE;
 }
 
+// Whether this is the zero value.
+
+bool
+Const_expression::do_is_zero_value() const
+{
+  return this->constant_->const_value()->expr()->is_zero_value();
+}
+
 // Lower a constant expression.  This is where we convert the
 // predeclared constant iota into an integer value.
 
@@ -3708,6 +3626,16 @@ Const_expression::do_get_backend(Translate_context* 
context)
   return expr->get_backend(context);
 }
 
+// When exporting a reference to a const as part of a const
+// expression, we export the value.  We ignore the fact that it has
+// a name.
+
+void
+Const_expression::do_export(Export_function_body* efb) const
+{
+  this->constant_->const_value()->expr()->export_expression(efb);
+}
+
 // Dump ast representation for constant expression.
 
 void
diff --git a/gcc/go/gofrontend/expressions.h b/gcc/go/gofrontend/expressions.h
index 707c19336d8..a1e3733aa1d 100644
--- a/gcc/go/gofrontend/expressions.h
+++ b/gcc/go/gofrontend/expressions.h
@@ -28,6 +28,7 @@ class Map_type;
 class Struct_type;
 class Struct_field;
 class Expression_list;
+class Const_expression;
 class Var_expression;
 class Enclosed_var_expression;
 class Temporary_reference_expression;
@@ -626,6 +627,20 @@ class Expression
   is_type_expression() const
   { return this->classification_ == EXPRESSION_TYPE; }
 
+  // If this is a const reference, return the Const_expression
+  // structure.  Otherwise, return NULL.  This is a controlled dynamic
+  // cast.
+  Const_expression*
+  const_expression()
+  { return this->convert(); }
+
+  const Const_expression*
+  const_expression() const
+  {
+return this->convert();
+  }
+
   // If this is a variable reference, return the Var_expression
   // structure.  Otherwise, return NULL.  This is a controlled dynamic
   // cast.
@@ -1453,6 

Go patch committed: Use package path with embedded builtin

2022-06-28 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend changes the mangled name of a struct to
use the package path with an embedded builtin type.  The test case is
https://go.dev/cl/414235.  This fixes https://go.dev/issue/52856.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
74956337e8276e5bc9524104b01c147374dd94e7
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 551ea650acf..13cb6ea4046 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-d5b4abed2f206e492890acc20738e89617ea542c
+c7238f58a26131b7611eff6f555cab02af8a623c
 
 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/names.cc b/gcc/go/gofrontend/names.cc
index f85d84ceadf..dac7f20f5c1 100644
--- a/gcc/go/gofrontend/names.cc
+++ b/gcc/go/gofrontend/names.cc
@@ -831,15 +831,28 @@ Struct_type::do_mangled_name(Gogo* gogo, std::string* ret,
  ret->push_back(' ');
}
 
- // For an anonymous field with an alias type, the field name
- // is the alias name.
- if (p->is_anonymous()
- && p->type()->named_type() != NULL
- && p->type()->named_type()->is_alias())
-   p->type()->named_type()->append_symbol_type_name(gogo, true, ret,
-is_non_identifier);
+ const Type* ft = p->type();
+ const Named_type* nt = ft->named_type();
+
+ if (p->is_anonymous() && nt != NULL && nt->is_builtin())
+   {
+ // For an embedded field with a builtin type, we must
+ // include a package path.  Otherwise embedding builtin
+ // types in different packages will produce identical
+ // types, which shouldn't happen because the builtin
+ // types are not exported.
+ ret->append(gogo->pkgpath());
+ ret->push_back('.');
+ nt->append_symbol_type_name(gogo, true, ret, is_non_identifier);
+   }
+ else if (p->is_anonymous() && nt != NULL && nt->is_alias())
+   {
+ // For an anonymous field with an alias type, the field name
+ // is the alias name.
+ nt->append_symbol_type_name(gogo, true, ret, is_non_identifier);
+   }
  else
-   this->append_mangled_name(p->type(), gogo, ret, is_non_identifier);
+   this->append_mangled_name(ft, gogo, ret, is_non_identifier);
 
  if (p->has_tag())
{


libgo patch committed: Make runtime.Version return a useful value

2022-06-28 Thread Ian Lance Taylor via Gcc-patches
This libgo patch makes runtime.Version return a meaningful string.
This also means that "go version" will print something useful, e.g.,

go version go1.18 gccgo (GCC) 12.0.1 20220216 (experimental) linux/amd64

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

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

Ian
0d8541c7c906c92c750c779958beafb0e0dbfe47
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index a0e386ab4f6..551ea650acf 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-28fe9fad4acb4e02083faf5503b06e3e6e8eecaf
+d5b4abed2f206e492890acc20738e89617ea542c
 
 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 a5d4b6a3525..b03e6553e90 100644
--- a/libgo/Makefile.am
+++ b/libgo/Makefile.am
@@ -568,6 +568,7 @@ s-goroot: Makefile
rm -f goroot.go.tmp
echo "package runtime" > goroot.go.tmp
echo 'var defaultGOROOT = `$(prefix)`' >> goroot.go.tmp
+   echo 'var buildVersion = `'`cat $(srcdir)/VERSION | sed 1q`' '`$(GOC) 
--version | sed 1q`'`' >> goroot.go.tmp
$(SHELL) $(srcdir)/mvifdiff.sh goroot.go.tmp goroot.go
$(STAMP) $@
 
diff --git a/libgo/Makefile.in b/libgo/Makefile.in
index 22f48a52938..16ed62a82ed 100644
--- a/libgo/Makefile.in
+++ b/libgo/Makefile.in
@@ -2780,6 +2780,7 @@ s-goroot: Makefile
rm -f goroot.go.tmp
echo "package runtime" > goroot.go.tmp
echo 'var defaultGOROOT = `$(prefix)`' >> goroot.go.tmp
+   echo 'var buildVersion = `'`cat $(srcdir)/VERSION | sed 1q`' '`$(GOC) 
--version | sed 1q`'`' >> goroot.go.tmp
$(SHELL) $(srcdir)/mvifdiff.sh goroot.go.tmp goroot.go
$(STAMP) $@
 
diff --git a/libgo/go/runtime/extern.go b/libgo/go/runtime/extern.go
index a371d9c0ee0..8e226147965 100644
--- a/libgo/go/runtime/extern.go
+++ b/libgo/go/runtime/extern.go
@@ -231,16 +231,6 @@ func GOROOT() string {
return defaultGOROOT
 }
 
-// buildVersion is the Go tree's version string at build time.
-//
-// If any GOEXPERIMENTs are set to non-default values, it will include
-// "X:".
-//
-// This is set by the linker.
-//
-// This is accessed by "go version ".
-var buildVersion string
-
 // Version returns the Go tree's version string.
 // It is either the commit hash and date at the time of the build or,
 // when possible, a release tag like "go1.3".


Go patch committed: Permit abstract bool expressions to remain abstract

2022-06-28 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend permits expressions of abstract bool to
remain abstract, rather than forcing them into the named type bool.
The test case for this is https://go.dev/cl/414755.  This fixes
https://go.dev/issue/51475.  Bootstrarpped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
eebc9c8f0b23acddea253eb5a44f59f44f3f466b
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 16d274ce99d..a0e386ab4f6 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-927528cdc112fc51e0d07ee79e7a1254b586eabe
+28fe9fad4acb4e02083faf5503b06e3e6e8eecaf
 
 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 f59f61d19ad..aadca9710e6 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -6829,11 +6829,12 @@ Binary_expression::do_determine_type(const 
Type_context* context)
 {
   if ((tleft->integer_type() != NULL && tright->integer_type() != NULL)
  || (tleft->float_type() != NULL && tright->float_type() != NULL)
- || (tleft->complex_type() != NULL && tright->complex_type() != NULL))
+ || (tleft->complex_type() != NULL && tright->complex_type() != NULL)
+ || (tleft->is_boolean_type() && tright->is_boolean_type()))
{
- // Both sides have an abstract integer, abstract float, or
- // abstract complex type.  Just let CONTEXT determine
- // whether they may remain abstract or not.
+ // Both sides have an abstract integer, abstract float,
+ // abstract complex, or abstract boolean type.  Just let
+ // CONTEXT determine whether they may remain abstract or not.
}
   else if (tleft->complex_type() != NULL)
subcontext.type = tleft;


Re: [PATCH v2 3/7] libbacktrace: use grep instead of fgrep

2022-06-27 Thread Ian Lance Taylor via Gcc-patches
On Sun, Jun 26, 2022 at 11:10 PM Xi Ruoyao via Gcc-patches
 wrote:
>
> libbacktrace/ChangeLog:
>
> * configure.ac (AC_PROG_FGREP): Use grep instead of fgrep.
> * configure: Regenerate.

Thanks.  Committed to mainline.

Ian


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

2022-06-27 Thread Ian Lance Taylor via Gcc-patches
On Mon, Jun 27, 2022 at 9:47 AM  wrote:
>
> From: Sören Tempel 
>
> This patch addresses two minor compatibility issues with musl libc:
>
> * On some architecture (e.g. PowerPC), musl has more than one field
>   prefixed with st_{a,m,c}tim in struct stat. This causes the sed(1)
>   invocation to not work correctly (since it will only replace the first
>   occurrence) [1]. This can be fixed by passing the 'g' flag to replace
>   all occurrences.
> * Since version 1.2.3, musl defines SYS_SECCOMP in signal.h [2]. This
>   conflicts with mksysinfo extraction of syscall numbers [3]. By
>   restricting the grep expression to only match lower case characters we
>   can avoid a redefinition of SYS_SECCOMP. This is GCC PR 105225.
>
> This patch combines two Alpine Linux patches which have been written by
> Ariadne Conill and Natanael Copa. I haven't tested this with glibc but I
> strongly suspect that both changes should not introduce any issue with
> glibc.

Given that pretty much every one of these musl patches has led to
problems on some glibc systems, it would be very nice if you could do
some testing with glibc.  Thanks.

Can you expand on the st_atim issue?  What does the musl type look
like in gen-sysinfo.go?

What is the value of SYS_SECCOMP in musl?  Is it a system call number?
 What does it look like in gen-sysinfo.go?

Thanks.

Ian


Go patch committed: Don't use sink as method expression thunk parameter

2022-06-27 Thread Ian Lance Taylor via Gcc-patches
This Go frontend patch avoids using a sink name (_) as a parameter
name when creating a method expression thunk.  The patch also fixes a
couple of cases where the error led to a later compiler crash.  The
test case is https://go.dev/cl/414336.  This fixes
https://go.dev/issue/52871.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
5f6b6494035fb984d745efa28d334f7893e7272b
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index f84347ea575..16d274ce99d 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-6edae0ef6521569e8f949fa9dc1139825051
+927528cdc112fc51e0d07ee79e7a1254b586eabe
 
 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 135dae02262..f59f61d19ad 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -1426,7 +1426,12 @@ Sink_expression::do_get_backend(Translate_context* 
context)
   Gogo* gogo = context->gogo();
   if (this->bvar_ == NULL)
 {
-  go_assert(this->type_ != NULL && !this->type_->is_sink_type());
+  if (this->type_ == NULL || this->type_->is_sink_type())
+   {
+ go_assert(saw_errors());
+ return gogo->backend()->error_expression();
+   }
+
   Named_object* fn = context->function();
   go_assert(fn != NULL);
   Bfunction* fn_ctx = fn->func_value()->get_or_make_decl(gogo, fn);
@@ -15235,7 +15240,7 @@ Selector_expression::lower_method_expression(Gogo* gogo)
   p != method_parameters->end();
   ++p, ++i)
{
- if (!p->name().empty())
+ if (!p->name().empty() && !Gogo::is_sink_name(p->name()))
parameters->push_back(*p);
  else
{
diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc
index 39aea769eb2..e82be6840aa 100644
--- a/gcc/go/gofrontend/types.cc
+++ b/gcc/go/gofrontend/types.cc
@@ -4654,8 +4654,11 @@ class Sink_type : public Type
   { return false; }
 
   Btype*
-  do_get_backend(Gogo*)
-  { go_unreachable(); }
+  do_get_backend(Gogo* gogo)
+  {
+go_assert(saw_errors());
+return gogo->backend()->error_type();
+  }
 
   Expression*
   do_type_descriptor(Gogo*, Named_type*)


Go patch committed: Always initialize mpfr in integer import

2022-06-27 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend corrects the integer import code to
always initialize an mpfr value.  The test case for this is
https://go.dev/cl/413980.  This fixes https://go.dev/issue/52862.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
722750a44a93ce7d23e09df240d8ab700a2d30e6
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index e20212e990a..f84347ea575 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-6a7ba754e5d98efe0875f1f41f40098e976e7958
+6edae0ef6521569e8f949fa9dc1139825051
 
 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 734ecb9492e..135dae02262 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -2715,7 +2715,7 @@ Integer_expression::do_import(Import_expression* imp, 
Location loc)
  return Expression::make_error(loc);
}
   if (pos == std::string::npos)
-   mpfr_set_ui(real, 0, MPFR_RNDN);
+   mpfr_init_set_ui(real, 0, MPFR_RNDN);
   else
{
  std::string real_str = num.substr(0, pos);


Go patch committed: Use bool for comma-ok if not already boolean

2022-06-24 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend uses bool for a comma-ok statement if
the variable already has a type that is not a boolean type.  This is a
statement like

v, ok := m[k]

Otherwise we may try to convert an unnamed bool type to an interface
type, which will fail.  But we don't want to always use bool, because
the type of the comma-ok variable may be a named bool type, in which
case the assignment would fail (or need an explicit conversion).

The test case is https://go.dev/cl/404496.  This fixes
https://go.dev/issue/52535.

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

Ian
3bfc16d86b29600fd559dd733a6909c9441aac25
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index f882812d219..e20212e990a 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-6b314f7947b4b31a86c09d166fe6664cd9968824
+6a7ba754e5d98efe0875f1f41f40098e976e7958
 
 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 b3db843365e..b442830b0b7 100644
--- a/gcc/go/gofrontend/statements.cc
+++ b/gcc/go/gofrontend/statements.cc
@@ -1594,9 +1594,9 @@ Tuple_map_assignment_statement::do_lower(Gogo* gogo, 
Named_object*,
 
   // var present_temp bool
   Temporary_statement* present_temp =
-Statement::make_temporary((this->present_->type()->is_sink_type())
- ? Type::make_boolean_type()
- : this->present_->type(),
+Statement::make_temporary((this->present_->type()->is_boolean_type()
+  ? this->present_->type()
+  : Type::lookup_bool_type()),
  NULL, loc);
   b->add_statement(present_temp);
 
@@ -1789,9 +1789,9 @@ Tuple_receive_assignment_statement::do_lower(Gogo*, 
Named_object*,
 
   // var closed_temp bool
   Temporary_statement* closed_temp =
-Statement::make_temporary((this->closed_->type()->is_sink_type())
- ? Type::make_boolean_type()
- : this->closed_->type(),
+Statement::make_temporary((this->closed_->type()->is_boolean_type()
+  ? this->closed_->type()
+  : Type::lookup_bool_type()),
  NULL, loc);
   b->add_statement(closed_temp);
 
@@ -1965,6 +1965,8 @@ Tuple_type_guard_assignment_statement::do_lower(Gogo*, 
Named_object*,
   b->add_statement(s);
 
   res = Expression::make_call_result(call, 1);
+  if (!this->ok_->type()->is_boolean_type())
+   res = Expression::make_cast(Type::lookup_bool_type(), res, loc);
   s = Statement::make_assignment(this->ok_, res, loc);
   b->add_statement(s);
 }
@@ -2001,7 +2003,9 @@ 
Tuple_type_guard_assignment_statement::lower_to_object_type(
   Temporary_statement* ok_temp = NULL;
   if (!this->ok_->is_sink_expression())
 {
-  ok_temp = Statement::make_temporary(this->ok_->type(),
+  ok_temp = Statement::make_temporary((this->ok_->type()->is_boolean_type()
+  ? this->ok_->type()
+  : Type::lookup_bool_type()),
  NULL, loc);
   b->add_statement(ok_temp);
 }


Go patch committed: In Sort_bindings handle same value passed twice

2022-06-23 Thread Ian Lance Taylor via Gcc-patches
This patch by zhangjian to the Go frontend changes Sort_bindings to
return false if comparing a value to itself.  Apparently some versions
of std::sort may pass elements at the same iterator location.  This
fixes https://go.dev/issue/53483.  Bootstrapped and ran Go testsuite
on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
5ee8e1d1b0c0d9f6310d27a37a6162e0be80e413
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 629bc666dc0..f882812d219 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-6c3752315dc9b82d0f3f3ac646a1e7376818f84a
+6b314f7947b4b31a86c09d166fe6664cd9968824
 
 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 a30b11af31e..7373deee310 100644
--- a/gcc/go/gofrontend/export.cc
+++ b/gcc/go/gofrontend/export.cc
@@ -530,6 +530,9 @@ struct Sort_bindings
   bool
   operator()(const Named_object* n1, const Named_object* n2) const
   {
+if (n1 == n2)
+  return false;
+
 if (n1->package() != n2->package())
   {
if (n1->package() == NULL)


Go patch committed: unalias types for hash/equality functions

2022-06-23 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend makes sure to unalias types when
creating hash/equality functions.  This fixes
https://go.dev/issue/52846.  There is a test case at
https://go.dev/cl/413694.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
3e134d9c6716f6acaf3e17458c603c3786003fb2
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 737bc483274..629bc666dc0 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-77821de1a149c2e6ef9c154ae384c16292173039
+6c3752315dc9b82d0f3f3ac646a1e7376818f84a
 
 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 d35c6baf582..e13df0da22b 100644
--- a/gcc/go/gofrontend/gogo.cc
+++ b/gcc/go/gofrontend/gogo.cc
@@ -2811,7 +2811,7 @@ Specific_type_functions::type(Type* t)
 
 case Type::TYPE_MAP:
   {
-   Type* key_type = t->map_type()->key_type();
+   Type* key_type = t->map_type()->key_type()->unalias();
if (key_type->needs_specific_type_functions(this->gogo_))
  key_type->hash_function(this->gogo_, NULL);
   }
diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc
index eb3afd94682..39aea769eb2 100644
--- a/gcc/go/gofrontend/types.cc
+++ b/gcc/go/gofrontend/types.cc
@@ -1764,6 +1764,9 @@ Type::needs_specific_type_functions(Gogo* gogo)
 Named_object*
 Type::hash_function(Gogo* gogo, Function_type* hash_fntype)
 {
+  if (this->named_type() != NULL)
+go_assert(!this->named_type()->is_alias());
+
   if (!this->is_comparable())
 return NULL;
 
@@ -2067,6 +2070,9 @@ Type::write_identity_hash(Gogo* gogo, int64_t size)
 Named_object*
 Type::equal_function(Gogo* gogo, Named_type* name, Function_type* equal_fntype)
 {
+  if (this->named_type() != NULL)
+go_assert(!this->named_type()->is_alias());
+
   // If the unaliased type is not a named type, then the type does not
   // have a name after all.
   if (name != NULL)
@@ -6700,7 +6706,8 @@ Struct_type::write_hash_function(Gogo* gogo, 
Function_type* hash_fntype)
   subkey = Expression::make_cast(key_arg_type, subkey, bloc);
 
   // Get the hash function to use for the type of this field.
-  Named_object* hash_fn = pf->type()->hash_function(gogo, hash_fntype);
+  Named_object* hash_fn =
+   pf->type()->unalias()->hash_function(gogo, hash_fntype);
 
   // Call the hash function for the field, passing retval as the seed.
   ref = Expression::make_temporary_reference(retval, bloc);
@@ -7553,8 +7560,8 @@ Array_type::write_hash_function(Gogo* gogo, 
Function_type* hash_fntype)
   gogo->start_block(bloc);
 
   // Get the hash function for the element type.
-  Named_object* hash_fn = this->element_type_->hash_function(gogo,
-hash_fntype);
+  Named_object* hash_fn =
+this->element_type_->unalias()->hash_function(gogo, hash_fntype);
 
   // Get a pointer to this element in the loop.
   Expression* subkey = Expression::make_temporary_reference(key, bloc);
@@ -8441,8 +8448,8 @@ Map_type::do_type_descriptor(Gogo* gogo, Named_type* name)
   ++p;
   go_assert(p->is_field_name("hasher"));
   Function_type* hasher_fntype = p->type()->function_type();
-  Named_object* hasher_fn = this->key_type_->hash_function(gogo,
-  hasher_fntype);
+  Named_object* hasher_fn =
+this->key_type_->unalias()->hash_function(gogo, hasher_fntype);
   if (hasher_fn == NULL)
 vals->push_back(Expression::make_cast(hasher_fntype,
  Expression::make_nil(bloc),


Re: [PATCH] libgo: Recognize off64_t / loff_t type definition of musl libc

2022-06-21 Thread Ian Lance Taylor via Gcc-patches
On Tue, Jun 21, 2022 at 8:16 AM Andreas Schwab  wrote:
>
> On Jun 21 2022, Ian Lance Taylor via Gcc-patches wrote:
>
> > which seems to be Linux 3.13 and glibc 4.8.4.  On that system I see
>
> That's stone age.

I don't know who maintains these systems on the GCC compile farm.

Ian


Re: [PATCH] libgo: Recognize off64_t / loff_t type definition of musl libc

2022-06-21 Thread Ian Lance Taylor via Gcc-patches
On Sat, Jun 18, 2022 at 8:59 AM Andreas Schwab  wrote:
>
> On Jun 18 2022, Ian Lance Taylor wrote:
>
> > What target?
>
> aarch64-suse-linux, of course.

Thanks.  Sorry for missing that.


> > What is the output of
> >
> > grep loff_t TARGET/libgo/gen-sysinfo.go
>
> type ___loff_t int64
> type _loff_t int64
> type ___kernel_loff_t int64

Hmmm, it does work as expected on gcc114 in the GCC compile farm,
which seems to be Linux 3.13 and glibc 4.8.4.  On that system I see

> grep loff_t aarch64-unknown-linux-gnu/libgo/gen-sysinfo.go
type ___loff_t int64
type _loff_t int64
type ___kernel_loff_t int64
type _libgo_loff_t_type int64

Still, I may see the problem.  I've committed this patch that should fix it.

Ian
7afe467c665bba27574a183dad5c00f2c0f676e1
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 4b75dd37355..737bc483274 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-a409e049737ec9a358a19233e017d957db3d6d2a
+77821de1a149c2e6ef9c154ae384c16292173039
 
 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 b/libgo/configure
index b7ff9b32867..61a49947eb9 100755
--- a/libgo/configure
+++ b/libgo/configure
@@ -15549,7 +15549,10 @@ fi
 
 CFLAGS_hold="$CFLAGS"
 CFLAGS="$OSCFLAGS $CFLAGS"
-ac_fn_c_check_type "$LINENO" "loff_t" "ac_cv_type_loff_t" "#include 
+ac_fn_c_check_type "$LINENO" "loff_t" "ac_cv_type_loff_t" "
+#include 
+#include 
+
 "
 if test "x$ac_cv_type_loff_t" = xyes; then :
 
diff --git a/libgo/configure.ac b/libgo/configure.ac
index bac58b07b41..274fcfc35c7 100644
--- a/libgo/configure.ac
+++ b/libgo/configure.ac
@@ -604,7 +604,10 @@ AC_TYPE_OFF_T
 
 CFLAGS_hold="$CFLAGS"
 CFLAGS="$OSCFLAGS $CFLAGS"
-AC_CHECK_TYPES([loff_t], [], [], [[#include ]])
+AC_CHECK_TYPES([loff_t], [], [], [[
+#include 
+#include 
+]])
 CFLAGS="$CFLAGS_hold"
 
 LIBS_hold="$LIBS"


Re: [PATCH] libgo: Recognize off64_t / loff_t type definition of musl libc

2022-06-18 Thread Ian Lance Taylor via Gcc-patches
On Sat, Jun 18, 2022 at 12:19 AM Andreas Schwab  wrote:
>
> ../../../libgo/go/syscall/libcall_linux.go:220:25: error: reference to 
> undefined name '_libgo_loff_t_type'
>   220 | lroff = _libgo_loff_t_type(*roff)
>   | ^
> ../../../libgo/go/syscall/libcall_linux.go:226:25: error: reference to 
> undefined name '_libgo_loff_t_type'
>   226 | lwoff = _libgo_loff_t_type(*woff)
>   | ^
> ../../../libgo/go/syscall/libcall_linux.go:217:19: error: use of undefined 
> type '_libgo_loff_t_type'
>   217 | var lroff _libgo_loff_t_type
>   |   ^
> ../../../libgo/go/syscall/libcall_linux.go:217:19: error: use of undefined 
> type '_libgo_loff_t_type'
> ../../../libgo/go/syscall/libcall_linux.go:217:19: error: use of undefined 
> type '_libgo_loff_t_type'
> ../../../libgo/go/syscall/libcall_linux.go:217:19: error: use of undefined 
> type '_libgo_loff_t_type'
> ../../../libgo/go/syscall/libcall_linux.go:217:19: error: use of undefined 
> type '_libgo_loff_t_type'
> ../../../libgo/go/syscall/libcall_linux.go:217:19: error: use of undefined 
> type '_libgo_loff_t_type'
> ../../../libgo/go/syscall/libcall_linux.go:217:19: error: use of undefined 
> type '_libgo_loff_t_type'
> ../../../libgo/go/syscall/libcall_linux.go:217:19: error: use of undefined 
> type '_libgo_loff_t_type'
> make[4]: *** [Makefile:3038: syscall.lo] Error 1
>
> From config.log:
>
> configure:15552: checking for loff_t
> configure:15552: /opt/gcc/gcc-20220618/Build/./gcc/xgcc 
> -B/opt/gcc/gcc-20220618/Build/./gcc/ -B/usr/aarch64-suse-linux/bin/ 
> -B/usr/aarch64-suse-linux/lib/ -isystem /usr/aarch64-suse-linux/include 
> -isystem /usr/aarch64-suse-linux/sys-include-c -D_GNU_SOURCE 
> -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g  conftest.c >&5
> conftest.c: In function 'main':
> conftest.c:104:13: error: 'loff_t' undeclared (first use in this function); 
> did you mean 'off_t'?
>   104 | if (sizeof (loff_t))
>   | ^~
>   | off_t
> conftest.c:104:13: note: each undeclared identifier is reported only once for 
> each function it appears in
> configure:15552: $? = 1


What target?

What is the output of

grep loff_t TARGET/libgo/gen-sysinfo.go

?

Thanks.

Ian


Re: [PATCH] libgo: Recognize off64_t / loff_t type definition of musl libc

2022-06-17 Thread Ian Lance Taylor via Gcc-patches
On Tue, May 31, 2022 at 12:41 PM Sören Tempel  wrote:
>
> PING.
>
> If there is anything else that needs to be addressed please let me know.

Thanks.  Committed as follows.  Sorry for the delay.

Ian
e584afe7976a40df42eed4df6ce6852abab74030
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 0cda305c648..4b75dd37355 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-8db6b78110f84e22c409f334aeaefb80a8b39917
+a409e049737ec9a358a19233e017d957db3d6d2a
 
 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 7e2b98ba67c..bac58b07b41 100644
--- a/libgo/configure.ac
+++ b/libgo/configure.ac
@@ -579,7 +579,7 @@ AC_C_BIGENDIAN
 
 GCC_CHECK_UNWIND_GETIPINFO
 
-AC_CHECK_HEADERS(port.h sched.h semaphore.h sys/file.h sys/mman.h syscall.h 
sys/epoll.h sys/event.h sys/inotify.h sys/ptrace.h sys/syscall.h sys/sysctl.h 
sys/user.h sys/utsname.h sys/select.h sys/socket.h net/bpf.h net/if.h 
net/if_arp.h net/route.h netpacket/packet.h sys/prctl.h sys/mount.h sys/vfs.h 
sys/statfs.h sys/timex.h sys/sysinfo.h utime.h linux/ether.h linux/fs.h 
linux/ptrace.h linux/reboot.h netinet/in_syst.h netinet/ip.h 
netinet/ip_mroute.h netinet/if_ether.h lwp.h)
+AC_CHECK_HEADERS(fcntl.h port.h sched.h semaphore.h sys/file.h sys/mman.h 
syscall.h sys/epoll.h sys/event.h sys/inotify.h sys/ptrace.h sys/syscall.h 
sys/sysctl.h sys/user.h sys/utsname.h sys/select.h sys/socket.h net/bpf.h 
net/if.h net/if_arp.h net/route.h netpacket/packet.h sys/prctl.h sys/mount.h 
sys/vfs.h sys/statfs.h sys/timex.h sys/sysinfo.h utime.h linux/ether.h 
linux/fs.h linux/ptrace.h linux/reboot.h netinet/in_syst.h netinet/ip.h 
netinet/ip_mroute.h netinet/if_ether.h lwp.h)
 
 AC_CHECK_HEADERS([netinet/icmp6.h], [], [],
 [#include 
@@ -601,7 +601,11 @@ AC_STRUCT_DIRENT_D_TYPE
 
 AC_CHECK_FUNCS(accept4 dup3 epoll_create1 faccessat fallocate fchmodat 
fchownat futimesat getxattr inotify_add_watch inotify_init inotify_init1 
inotify_rm_watch listxattr mkdirat mknodat open64 openat pipe2 removexattr 
renameat setxattr sync_file_range splice syscall tee unlinkat unshare utimensat)
 AC_TYPE_OFF_T
-AC_CHECK_TYPES([loff_t])
+
+CFLAGS_hold="$CFLAGS"
+CFLAGS="$OSCFLAGS $CFLAGS"
+AC_CHECK_TYPES([loff_t], [], [], [[#include ]])
+CFLAGS="$CFLAGS_hold"
 
 LIBS_hold="$LIBS"
 LIBS="$LIBS -lm"
diff --git a/libgo/go/syscall/libcall_linux.go 
b/libgo/go/syscall/libcall_linux.go
index 7bec2fbaeb5..19ae4393cf1 100644
--- a/libgo/go/syscall/libcall_linux.go
+++ b/libgo/go/syscall/libcall_linux.go
@@ -210,20 +210,20 @@ func Gettid() (tid int) {
 //sys  Setxattr(path string, attr string, data []byte, flags int) (err error)
 //setxattr(path *byte, name *byte, value *byte, size Size_t, flags _C_int) 
_C_int
 
-//sys  splice(rfd int, roff *_loff_t, wfd int, woff *_loff_t, len int, flags 
int) (n int64, err error)
-//splice(rfd _C_int, roff *_loff_t, wfd _C_int, woff *_loff_t, len Size_t, 
flags _C_uint) Ssize_t
+//sys  splice(rfd int, roff *_libgo_loff_t_type, wfd int, woff 
*_libgo_loff_t_type, len int, flags int) (n int64, err error)
+//splice(rfd _C_int, roff *_libgo_loff_t_type, wfd _C_int, woff 
*_libgo_loff_t_type, len Size_t, flags _C_uint) Ssize_t
 
 func Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n 
int64, err error) {
-   var lroff _loff_t
-   var plroff *_loff_t
+   var lroff _libgo_loff_t_type
+   var plroff *_libgo_loff_t_type
if roff != nil {
-   lroff = _loff_t(*roff)
+   lroff = _libgo_loff_t_type(*roff)
plroff = 
}
-   var lwoff _loff_t
-   var plwoff *_loff_t
+   var lwoff _libgo_loff_t_type
+   var plwoff *_libgo_loff_t_type
if woff != nil {
-   lwoff = _loff_t(*woff)
+   lwoff = _libgo_loff_t_type(*woff)
plwoff = 
}
n, err = splice(rfd, plroff, wfd, plwoff, len, flags)
diff --git a/libgo/mksysinfo.sh b/libgo/mksysinfo.sh
index 0c52ea5d71a..5aa309155c3 100755
--- a/libgo/mksysinfo.sh
+++ b/libgo/mksysinfo.sh
@@ -403,11 +403,7 @@ fi
 # Some basic types.
 echo 'type Size_t _size_t' >> ${OUT}
 echo "type Ssize_t _ssize_t" >> ${OUT}
-if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go > /dev/null 2>&1; then
-  echo "type Offset_t _off64_t" >> ${OUT}
-else
-  echo "type Offset_t _off_t" >> ${OUT}
-fi
+echo "type Offset_t _libgo_off_t_type" >> ${OUT}
 echo "type Mode_t _mode_t" >> ${OUT}
 echo "type Pid_t _pid_t" >> ${OUT}
 echo "type Uid_t _uid_t" >> ${OUT}
diff --git a/libgo/sysinfo.c b/libgo/sysinfo.c
index 8ce061e2f5f..a4259c02ded 100644
--- a/libgo/sysinfo.c
+++ b/libgo/sysinfo.c
@@ -357,6 +357,18 @@ enum {
 };
 #endif
 
+#if defined(HAVE_LOFF_T)
+// loff_t can be defined as a macro; for -fgo-dump-spec make sure we
+// see a typedef.
+typedef loff_t libgo_loff_t_type;
+#endif
+
+#if defined(HAVE_OFF64_T)
+typedef off64_t 

Go patch committed: Skip stubs for ambiguous direct iface methods

2022-06-16 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend by Михаил Аблакатов (Mikhail Ablakatov)
avoids generating stubs for ambiguous direct interface methods.  The
current implementation checks whether it has to generate a stub method
for a promoted method of an embedded struct field in
Type::build_stub_methods().  If the promoted method is ambiguous it's
simply skipped.  But struct types that can fit in an interface value
(e.g. structs that consist of a single pointer field) get a second
chance in Type::build_direct_iface_stub_methods().

This patch adds the same check used by Type::build_stub_methods() to
Type::build_direct_iface_stub_methods().

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

This fixes https://go.dev/issue/52870.  The test case is
https://go.dev/cl/412535.

Committed to mainline.

Ian
79d599b057cca42b84303ae25c7ab9f43e9f5eac
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index aeada9f8d0c..0cda305c648 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-bbb3a4347714faee620dc205674510a0f20b81ae
+8db6b78110f84e22c409f334aeaefb80a8b39917
 
 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 a8e309041e7..eb3afd94682 100644
--- a/gcc/go/gofrontend/types.cc
+++ b/gcc/go/gofrontend/types.cc
@@ -11891,7 +11891,7 @@ Type::build_direct_iface_stub_methods(Gogo* gogo, const 
Type* type,
 need_stub = true;
   if (!in_heap && !m->is_value_method())
 need_stub = true;
-  if (!need_stub)
+  if (!need_stub || m->is_ambiguous())
 continue;
 
   Type* receiver_type = const_cast(type);


libgo patch committed: Format the syscall package

2022-06-14 Thread Ian Lance Taylor via Gcc-patches
This Go formatter is starting to format documentation comments in some
cases.  As a step toward that in libgo, this patch adds blank lines
after //sys comments in the syscall package where needed, and then
runs the new formatter on the syscall package files.  This is the
libgo version of https://go.dev/cl/407136.  Bootstrapped and ran Go
testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
3f4a86eef4ebc28e394a7108a2353098d2ca4856
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 2cf7141c4fa..aeada9f8d0c 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-0058658a9efb6e5c5faa6f0f65949beea5ddbc98
+bbb3a4347714faee620dc205674510a0f20b81ae
 
 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/dir_plan9.go b/libgo/go/syscall/dir_plan9.go
index 4ed052de761..1667cbc02f4 100644
--- a/libgo/go/syscall/dir_plan9.go
+++ b/libgo/go/syscall/dir_plan9.go
@@ -184,6 +184,7 @@ func gbit8(b []byte) (uint8, []byte) {
 }
 
 // gbit16 reads a 16-bit number in little-endian order from b and returns it 
with the remaining slice of b.
+//
 //go:nosplit
 func gbit16(b []byte) (uint16, []byte) {
return uint16(b[0]) | uint16(b[1])<<8, b[2:]
diff --git a/libgo/go/syscall/errstr.go b/libgo/go/syscall/errstr.go
index 6c2441d364d..59f7a82c6d7 100644
--- a/libgo/go/syscall/errstr.go
+++ b/libgo/go/syscall/errstr.go
@@ -4,8 +4,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build !hurd
-// +build !linux
+//go:build !hurd && !linux
+// +build !hurd,!linux
 
 package syscall
 
diff --git a/libgo/go/syscall/errstr_glibc.go b/libgo/go/syscall/errstr_glibc.go
index 5b19e6f202d..03a327dbc90 100644
--- a/libgo/go/syscall/errstr_glibc.go
+++ b/libgo/go/syscall/errstr_glibc.go
@@ -7,6 +7,7 @@
 // We use this rather than errstr.go because on GNU/Linux sterror_r
 // returns a pointer to the error message, and may not use buf at all.
 
+//go:build hurd || linux
 // +build hurd linux
 
 package syscall
diff --git a/libgo/go/syscall/exec_bsd.go b/libgo/go/syscall/exec_bsd.go
index 86e513efdea..e631593cbd9 100644
--- a/libgo/go/syscall/exec_bsd.go
+++ b/libgo/go/syscall/exec_bsd.go
@@ -49,6 +49,7 @@ func runtime_AfterForkInChild()
 // For the same reason compiler does not race instrument it.
 // The calls to RawSyscall are okay because they are assembly
 // functions that do not grow the stack.
+//
 //go:norace
 func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, 
attr *ProcAttr, sys *SysProcAttr, pipe int) (pid int, err Errno) {
// Declare all variables at top in case any
diff --git a/libgo/go/syscall/exec_freebsd.go b/libgo/go/syscall/exec_freebsd.go
index f02f89d1ca0..8e8ecb7e989 100644
--- a/libgo/go/syscall/exec_freebsd.go
+++ b/libgo/go/syscall/exec_freebsd.go
@@ -57,6 +57,7 @@ func runtime_AfterForkInChild()
 // For the same reason compiler does not race instrument it.
 // The calls to RawSyscall are okay because they are assembly
 // functions that do not grow the stack.
+//
 //go:norace
 func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, 
attr *ProcAttr, sys *SysProcAttr, pipe int) (pid int, err Errno) {
// Declare all variables at top in case any
diff --git a/libgo/go/syscall/exec_hurd.go b/libgo/go/syscall/exec_hurd.go
index 06df513c55c..a62b3e920e6 100644
--- a/libgo/go/syscall/exec_hurd.go
+++ b/libgo/go/syscall/exec_hurd.go
@@ -49,6 +49,7 @@ func runtime_AfterForkInChild()
 // For the same reason compiler does not race instrument it.
 // The calls to RawSyscall are okay because they are assembly
 // functions that do not grow the stack.
+//
 //go:norace
 func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, 
attr *ProcAttr, sys *SysProcAttr, pipe int) (pid int, err Errno) {
// Declare all variables at top in case any
diff --git a/libgo/go/syscall/exec_linux.go b/libgo/go/syscall/exec_linux.go
index 86fb8e84a66..77846af89e4 100644
--- a/libgo/go/syscall/exec_linux.go
+++ b/libgo/go/syscall/exec_linux.go
@@ -80,6 +80,7 @@ func runtime_AfterFork()
 func runtime_AfterForkInChild()
 
 // Implemented in clone_linux.c
+//
 //go:noescape
 func rawClone(flags _C_ulong, child_stack *byte, ptid *Pid_t, ctid *Pid_t, 
regs unsafe.Pointer) _C_long
 
@@ -92,6 +93,7 @@ func rawClone(flags _C_ulong, child_stack *byte, ptid *Pid_t, 
ctid *Pid_t, regs
 // For the same reason compiler does not race instrument it.
 // The calls to RawSyscall are okay because they are assembly
 // functions that do not grow the stack.
+//
 //go:norace
 func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, 
attr *ProcAttr, sys *SysProcAttr, pipe int) (pid int, err Errno) {
// Set up and fork. This returns immediately in the parent or
diff --git a/libgo/go/syscall/exec_stubs.go b/libgo/go/syscall/exec_stubs.go
index 

libbacktrace patch committed: Update README

2022-05-28 Thread Ian Lance Taylor via Gcc-patches
This patch updates the libbacktrace README to a near copy of the one
from github.com/ianlancetaylor/libbacktrace.  Committed to mainline.
This fixes GCC PR 105721.

Ian

* README: Update.
6cf19361732bd7f8b41716ef9f4b5c205a3193b8
diff --git a/libbacktrace/README b/libbacktrace/README
index e8b225745c9..6225f92b855 100644
--- a/libbacktrace/README
+++ b/libbacktrace/README
@@ -1,23 +1,31 @@
 The libbacktrace library
-Initially written by Ian Lance Taylor 
+Initially written by Ian Lance Taylor 
 
 The libbacktrace library may be linked into a program or library and
-used to produce symbolic backtraces.  Sample uses would be to print a
-detailed backtrace when an error occurs or to gather detailed
-profiling information.
+used to produce symbolic backtraces.
+Sample uses would be to print a detailed backtrace when an error
+occurs or to gather detailed profiling information.
+In general the functions provided by this library are async-signal-safe,
+meaning that they may be safely called from a signal handler.
 
-The libbacktrace library is provided under a BSD license.  See the
-source files for the exact license text.
+The libbacktrace library is provided under a BSD license.
+See the source files for the exact license text.
 
 The public functions are declared and documented in the header file
 backtrace.h, which should be #include'd by a user of the library.
 
 Building libbacktrace will generate a file backtrace-supported.h,
 which a user of the library may use to determine whether backtraces
-will work.  See the source file backtrace-supported.h.in for the
-macros that it defines.
+will work.
+See the source file backtrace-supported.h.in for the macros that it
+defines.
 
-As of September 2012, libbacktrace only supports ELF executables with
-DWARF debugging information.  The library is written to make it
-straightforward to add support for other object file and debugging
-formats.
+As of October 2020, libbacktrace supports ELF, PE/COFF, Mach-O, and
+XCOFF executables with DWARF debugging information.
+In other words, it supports GNU/Linux, *BSD, macOS, Windows, and AIX.
+The library is written to make it straightforward to add support for
+other object file and debugging formats.
+
+The library relies on the C++ unwind API defined at
+https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html
+This API is provided by GCC and clang.


Re: libiberty: Would it be reasonable to add support for GnuCOBOL function name demangling?

2022-05-27 Thread Ian Lance Taylor via Gcc-patches
On Fri, May 27, 2022 at 12:17 AM Simon Sobisch via Gcc-patches
 wrote:
>
> As noted: the first question is: is it reasonable to add support for
> GnuCOBOL?

It seems fine to me to add support for demangling GnuCOBOL symbol
names controlled by a DMGL option (options are defined in
include/demangle.h).


> * How would the demangler know it is to be called? Just "best match"
> (GnuCOBOL modules always have some symbols in it which should be
> available if there is any debugging information in, if that helps)?
> * Giving the work of gcc-cobol which was discussed on this mailing list
> some months ago (not sure about its current state) there possibly will
> be a COBOL support be "integrated" - with possibly different name
> mangling. But still - GnuCOBOL is used "in the wild" (for production
> environments) since years (and will be for many years to come, both
> based on GCC and with other compilers) and the name mangling rules did
> not change.

The demangler doesn't see a list of symbol names, it only sees a
single string at a time.  If GnuCOBOL symbols are to be demangled by
default, then there must be a clear distinction between COBOL names
and other names.  For example, C++ demangled names, with a few minor
exceptions, always start with "_Z".  If there is no such marker then
we would have to require that the names only be demangle with a DMGL
option.  There could be a corresponding command line option for
c++filt.

Ian


Go patch committed: Traverse expressions with exporting consts

2022-05-18 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend by Julia Lapenko traverses expressions
when exporting constants.  When exporting a constant A that is
expressed through a constant B from another package, it is necessary
to traverse an expression representing the constant A to generate a
sequence of type casts from the constant B.  Before this patch the
frontend didn't collect types of constants contained in such
expressions. This change fetches these types.  This fixes
https://go.dev/issue/51291.  The test case is
https://go.dev/cl/406916.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
4105b492d64412b03c3776b49f7663aa094a3f07
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 5fa8becde3e..2cf7141c4fa 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-9d07072e58ca4f9f05343dfd3475b9f49dae5ec5
+0058658a9efb6e5c5faa6f0f65949beea5ddbc98
 
 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 70d3f708d32..a30b11af31e 100644
--- a/gcc/go/gofrontend/export.cc
+++ b/gcc/go/gofrontend/export.cc
@@ -124,6 +124,11 @@ class Collect_export_references : public Traverse
   void
   prepare_types(const std::vector& sorted_exports);
 
+  // Third entry point (called after the method above), to find
+  // all types in expressions referenced by exports.
+  void
+  prepare_expressions(const std::vector& sorted_exports);
+
  protected:
   // Override of parent class method.
   int
@@ -281,6 +286,28 @@ Collect_export_references::expression(Expression** pexpr)
   return TRAVERSE_CONTINUE;
 }
 
+// Collect up the set of types mentioned in expressions of things we're 
exporting,
+// and collect all the packages encountered during type traversal, to make sure
+// we can declare things referered to indirectly (for example, in the body of 
an
+// exported inline function from another package).
+
+void
+Collect_export_references::prepare_expressions(const 
std::vector& sorted_exports)
+{
+  for (std::vector::const_iterator p = sorted_exports.begin();
+   p != sorted_exports.end();
+   ++p)
+{
+  Named_object* no = *p;
+  if (no->classification() == Named_object::NAMED_OBJECT_CONST)
+{
+  Expression* e = no->const_value()->expr();
+  if (e != NULL)
+Expression::traverse(, this);
+}
+}
+}
+
 // Collect up the set of types mentioned in things we're exporting, and collect
 // all the packages encountered during type traversal, to make sure we can
 // declare things referered to indirectly (for example, in the body of an
@@ -891,6 +918,7 @@ Export::export_globals(const std::string& package_name,
   // Collect up the set of types mentioned in things we're exporting,
   // and any packages that may be referred to indirectly.
   collect.prepare_types(sorted_exports);
+  collect.prepare_expressions(sorted_exports);
 
   // Assign indexes to all exported types and types referenced by
   // things we're exporting.  Return value is index of first non-exported


Go patch committed: load LHS subexpressions of op= only once

2022-05-17 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend loads LHS subexpressions of op=
assignment only once.  This avoids inconsistencies if the variables
are changed by evaluating the RHS.  This fixes
https://go.dev/issue/52811.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.  There is a test case in
the main Go repo that will be copied over at some point.

Ian
88c35c4d23e2458687508187601f8d2b8570bbe3
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index daa725f9de9..5fa8becde3e 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-f5bc28a30b7503015bbef38afb5812313184e822
+9d07072e58ca4f9f05343dfd3475b9f49dae5ec5
 
 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 95fa3c48709..b3db843365e 100644
--- a/gcc/go/gofrontend/statements.cc
+++ b/gcc/go/gofrontend/statements.cc
@@ -1260,6 +1260,16 @@ Assignment_operation_statement::do_lower(Gogo*, 
Named_object*,
   Move_ordered_evals moe(b);
   this->lhs_->traverse_subexpressions();
 
+  // We can still be left with subexpressions that have to be loaded
+  // even if they don't have side effects themselves, in case the RHS
+  // changes variables named on the LHS.
+  int i;
+  if (this->lhs_->must_eval_subexpressions_in_order())
+{
+  Move_subexpressions ms(i, b);
+  this->lhs_->traverse_subexpressions();
+}
+
   Expression* lval = this->lhs_->copy();
 
   Operator op;


Re: [PATCH] c: use CONST_DECL for enumerators in TYPE_VALUES

2022-05-17 Thread Ian Lance Taylor via Gcc-patches
On Tue, May 17, 2022 at 2:46 PM Marek Polacek  wrote:
>
> On Tue, May 17, 2022 at 09:35:14PM +, Joseph Myers wrote:
> > On Tue, 17 May 2022, Marek Polacek via Gcc-patches wrote:
> >
> > > The C and C++ FEs differ in TYPE_VALUES for an enum type: an entry in
> > > the list in the C++ FE has a CONST_DECL in the TREE_VALUE, but the C FE
> > > has only the numerical value of the CONST_DECL there.  This has caused
> > > me some trouble in my PR105497 patch.  Using a CONST_DECL is preferable
> > > because a CONST_DECL can track more information (e.g., attributes), and
> > > you can always get the value simply by looking at its DECL_INITIAL.
> > >
> > > This turned out to be a trivial change.  One place in godump.cc had to be
> > > adjusted.  I'm not changing the CONST_DECL check in c_do_switch_warnings
> > > because I'll be changing it soon in my next patch.  I didn't see any other
> > > checks that this patch makes redundant.
> > >
> > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> > >
> > > gcc/c/ChangeLog:
> > >
> > > * c-decl.cc (finish_enum): Store the CONST_DECL into TREE_VALUE, not
> > > its value.
> >
> > The C front-end changes are OK.
>
> Thanks.  Ian, are the (more or less obvious) godump.cc changes also OK?

Yes, that change is OK (assuming it works).  Thanks.

Ian


Go patch committed: Always sort interface parse methods

2022-05-13 Thread Ian Lance Taylor via Gcc-patches
This patch to the Go frontend always sorts interface parse methods.

The exporter relies on sorting interface parse methods.  It would sort
them as it encountered interface types.  However, when an interface
type is an element of a struct or array type, the exporter might
encounter that interface type before sorting the parse methods.  If it
then encountered an identical interface type again, it could get
confused about whether the two types are identical or not.

Fix the problem by always sorting the parse methods in the
finalize_methods pass.

Also firm up the export type sorting to make sure we never have this
kind of confusion again.  Doing this revealed that we need to be more
careful about sorting in order to handle aliases correctly.

Also fix the interface type hash computation to use the right hash
value when looking at parse methods rather than all methods.

The test case for this is https://go.dev/cl/405759.

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

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

Ian
59d8d7177a02a71b385c233bd4605098d21069ec
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 3ec315f6892..daa725f9de9 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-6a33e7e30c89edc12340dc470b44791bb1066feb
+f5bc28a30b7503015bbef38afb5812313184e822
 
 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 3d11334884d..70d3f708d32 100644
--- a/gcc/go/gofrontend/export.cc
+++ b/gcc/go/gofrontend/export.cc
@@ -360,16 +360,6 @@ Collect_export_references::type(Type* type)
   if (type->is_abstract())
 return TRAVERSE_SKIP_COMPONENTS;
 
-  // For interfaces make sure that embedded methods are sorted, since the
-  // comparison function we use for indexing types relies on it (this call has
-  // to happen before the record_type call below).
-  if (type->classification() == Type::TYPE_INTERFACE)
-{
-  Interface_type* it = type->interface_type();
-  if (it != NULL)
-it->sort_embedded();
-}
-
   if (!this->exp_->record_type(type))
 {
   // We've already seen this type.
@@ -501,6 +491,11 @@ should_export(Named_object* no)
   return true;
 }
 
+// Compare Typed_identifier_list's.
+
+static int
+compare_til(const Typed_identifier_list*, const Typed_identifier_list*);
+
 // A functor to sort Named_object pointers by name.
 
 struct Sort_bindings
@@ -514,10 +509,57 @@ struct Sort_bindings
  return true;
if (n2->package() == NULL)
  return false;
-   return n1->package()->pkgpath() < n2->package()->pkgpath();
+
+   // Make sure we don't see the same pkgpath twice.
+   const std::string& p1(n1->package()->pkgpath());
+   const std::string& p2(n2->package()->pkgpath());
+   go_assert(p1 != p2);
+
+   return p1 < p2;
   }
 
-return n1->name() < n2->name();
+if (n1->name() != n2->name())
+  return n1->name() < n2->name();
+
+// We shouldn't see the same name twice, but it can happen for
+// nested type names.
+
+go_assert(n1->is_type() && n2->is_type());
+
+unsigned int ind1;
+const Named_object* g1 = n1->type_value()->in_function();
+unsigned int ind2;
+const Named_object* g2 = n2->type_value()->in_function();
+
+if (g1 == NULL)
+  {
+   go_assert(g2 != NULL);
+   return true;
+  }
+else if (g2 == NULL)
+  return false;
+else if (g1 == g2)
+  {
+   go_assert(ind1 != ind2);
+   return ind1 < ind2;
+  }
+else if ((g1->package() != g2->package()) || (g1->name() != g2->name()))
+  return Sort_bindings()(g1, g2);
+else
+  {
+   // This case can happen if g1 or g2 is a method.
+   if (g1 != NULL && g1->func_value()->is_method())
+ {
+   const Typed_identifier* r = g1->func_value()->type()->receiver();
+   g1 = r->type()->named_type()->named_object();
+ }
+   if (g2 != NULL && g2->func_value()->is_method())
+ {
+   const Typed_identifier* r = g2->func_value()->type()->receiver();
+   g2 = r->type()->named_type()->named_object();
+ }
+   return Sort_bindings()(g1, g2);
+  }
   }
 };
 
@@ -528,17 +570,20 @@ struct Sort_types
   bool
   operator()(const Type* t1, const Type* t2) const
   {
+t1 = t1->forwarded();
+t2 = t2->forwarded();
+
 const Named_type* nt1 = t1->named_type();
 const Named_type* nt2 = t2->named_type();
 if (nt1 != NULL)
   {
-if (nt2 != NULL)
-  {
-Sort_bindings sb;
-return sb(nt1->named_object(), nt2->named_object());
-  }
-else
-  return true;
+   if (nt2 != NULL)
+ {
+   Sort_bindings sb;
+   return sb(nt1->named_object(), nt2->named_object());
+ }
+   else
+ return true;
   }
   

Re: [PATCH] libgo: Recognize off64_t / loff_t type definition of musl libc

2022-05-12 Thread Ian Lance Taylor via Gcc-patches
On Thu, May 12, 2022 at 11:23 AM Sören Tempel via Gcc-patches
 wrote:
>
> The off64_t type is used for defining Offset_t:
>
> 
> https://github.com/golang/gofrontend/blob/4bdff733a0c2a9ddc3eff104b1be03df058a79c4/libgo/mksysinfo.sh#L406-L410
>
> On musl, _HAVE_OFF64_T is defined since autoconf doesn't mind it
> being defined as a macro but -fdump-go-spec does, hence you end up
> with the following compilation error (even with your patch applied):

Ah, thanks.


> Apart from off64_t stuff, there is only one minor issue (see below).
>
> > index 7e2b98ba6..487099a33 100644
> > --- a/libgo/configure.ac
> > +++ b/libgo/configure.ac
> > @@ -579,7 +579,7 @@ AC_C_BIGENDIAN
> > +
> > +CFLAGS_hold="$CFLAGS"
> > +CFLAGS="$OSCFLAGS $CFLAGS"
> >  AC_CHECK_TYPES([loff_t])
> > +CFLAGS="$CFLAGS_hold"
>
> The AC_CHECK_TYPES invocation is missing an include of fcntl.h (which
> defines loff_t in musl) and as such fails and causes libgo compilation
> to fail with "reference to undefined name '_libgo_loff_t_type'" as
> HAVE_LOFF_T is not defined. The invocation needs to be changed to:
>
> AC_CHECK_TYPES([loff_t], [], [], [[#include ]])
>
> and this needs to be adjusted accordingly in configure as well.

Hmmm, I added fcntl.h to AC_CHECK_HEADERS.  I thought that would be
enough to cause it to be included in future tests.  Perhaps not.

Ian


Re: [PATCH] libgo: Recognize off64_t / loff_t type definition of musl libc

2022-05-09 Thread Ian Lance Taylor via Gcc-patches
On Sun, Apr 24, 2022 at 3:20 AM  wrote:
>
> From: Sören Tempel 
>
> The libgo code assumes both off64_t and loff_t to be present. For
> example, for the splice(2) function prototype. Similar to glibc,
> musl libc supports these types but defines them as macros, not as
> typedefs. Unfortunately, -fdump-go-spec only recognizes types defined
> using typedef. To workaround that, this commit adds explicit typedefs
> for these types if off64_t or loff_t are defined as macros.
>
> Furthermore, loff_t is only defined on musl with -D_GNU_SOURCE and
> requires an include of fcntl.h (this is in accordance with the splice(2)
> man page). Therefore, the configure script has also been adjusted
> accordingly.

I see uses of loff_t but I don't see any uses of off64_t.

We don't have to treat loff_t differently based on whether it is a
macro, we can just use a different name.

Does this patch work for you?

Ian
diff --git a/libgo/config.h.in b/libgo/config.h.in
index 25b8ab8f9..2c3c74696 100644
--- a/libgo/config.h.in
+++ b/libgo/config.h.in
@@ -70,6 +70,9 @@
 /* Define to 1 if you have the `fchownat' function. */
 #undef HAVE_FCHOWNAT
 
+/* Define to 1 if you have the  header file. */
+#undef HAVE_FCNTL_H
+
 /* Define to 1 if you have the `futimesat' function. */
 #undef HAVE_FUTIMESAT
 
diff --git a/libgo/configure b/libgo/configure
index ffe17c9be..eaea892a6 100755
--- a/libgo/configure
+++ b/libgo/configure
@@ -15249,7 +15249,7 @@ $as_echo "#define HAVE_GETIPINFO 1" >>confdefs.h
   fi
 
 
-for ac_header in port.h sched.h semaphore.h sys/file.h sys/mman.h syscall.h 
sys/epoll.h sys/event.h sys/inotify.h sys/ptrace.h sys/syscall.h sys/sysctl.h 
sys/user.h sys/utsname.h sys/select.h sys/socket.h net/bpf.h net/if.h 
net/if_arp.h net/route.h netpacket/packet.h sys/prctl.h sys/mount.h sys/vfs.h 
sys/statfs.h sys/timex.h sys/sysinfo.h utime.h linux/ether.h linux/fs.h 
linux/ptrace.h linux/reboot.h netinet/in_syst.h netinet/ip.h 
netinet/ip_mroute.h netinet/if_ether.h lwp.h
+for ac_header in fcntl.h port.h sched.h semaphore.h sys/file.h sys/mman.h 
syscall.h sys/epoll.h sys/event.h sys/inotify.h sys/ptrace.h sys/syscall.h 
sys/sysctl.h sys/user.h sys/utsname.h sys/select.h sys/socket.h net/bpf.h 
net/if.h net/if_arp.h net/route.h netpacket/packet.h sys/prctl.h sys/mount.h 
sys/vfs.h sys/statfs.h sys/timex.h sys/sysinfo.h utime.h linux/ether.h 
linux/fs.h linux/ptrace.h linux/reboot.h netinet/in_syst.h netinet/ip.h 
netinet/ip_mroute.h netinet/if_ether.h lwp.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" 
"$ac_includes_default"
@@ -15546,6 +15546,9 @@ _ACEOF
 
 fi
 
+
+CFLAGS_hold="$CFLAGS"
+CFLAGS="$OSCFLAGS $CFLAGS"
 ac_fn_c_check_type "$LINENO" "loff_t" "ac_cv_type_loff_t" 
"$ac_includes_default"
 if test "x$ac_cv_type_loff_t" = xyes; then :
 
@@ -15556,6 +15559,7 @@ _ACEOF
 
 fi
 
+CFLAGS="$CFLAGS_hold"
 
 LIBS_hold="$LIBS"
 LIBS="$LIBS -lm"
diff --git a/libgo/configure.ac b/libgo/configure.ac
index 7e2b98ba6..487099a33 100644
--- a/libgo/configure.ac
+++ b/libgo/configure.ac
@@ -579,7 +579,7 @@ AC_C_BIGENDIAN
 
 GCC_CHECK_UNWIND_GETIPINFO
 
-AC_CHECK_HEADERS(port.h sched.h semaphore.h sys/file.h sys/mman.h syscall.h 
sys/epoll.h sys/event.h sys/inotify.h sys/ptrace.h sys/syscall.h sys/sysctl.h 
sys/user.h sys/utsname.h sys/select.h sys/socket.h net/bpf.h net/if.h 
net/if_arp.h net/route.h netpacket/packet.h sys/prctl.h sys/mount.h sys/vfs.h 
sys/statfs.h sys/timex.h sys/sysinfo.h utime.h linux/ether.h linux/fs.h 
linux/ptrace.h linux/reboot.h netinet/in_syst.h netinet/ip.h 
netinet/ip_mroute.h netinet/if_ether.h lwp.h)
+AC_CHECK_HEADERS(fcntl.h port.h sched.h semaphore.h sys/file.h sys/mman.h 
syscall.h sys/epoll.h sys/event.h sys/inotify.h sys/ptrace.h sys/syscall.h 
sys/sysctl.h sys/user.h sys/utsname.h sys/select.h sys/socket.h net/bpf.h 
net/if.h net/if_arp.h net/route.h netpacket/packet.h sys/prctl.h sys/mount.h 
sys/vfs.h sys/statfs.h sys/timex.h sys/sysinfo.h utime.h linux/ether.h 
linux/fs.h linux/ptrace.h linux/reboot.h netinet/in_syst.h netinet/ip.h 
netinet/ip_mroute.h netinet/if_ether.h lwp.h)
 
 AC_CHECK_HEADERS([netinet/icmp6.h], [], [],
 [#include 
@@ -601,7 +601,11 @@ AC_STRUCT_DIRENT_D_TYPE
 
 AC_CHECK_FUNCS(accept4 dup3 epoll_create1 faccessat fallocate fchmodat 
fchownat futimesat getxattr inotify_add_watch inotify_init inotify_init1 
inotify_rm_watch listxattr mkdirat mknodat open64 openat pipe2 removexattr 
renameat setxattr sync_file_range splice syscall tee unlinkat unshare utimensat)
 AC_TYPE_OFF_T
+
+CFLAGS_hold="$CFLAGS"
+CFLAGS="$OSCFLAGS $CFLAGS"
 AC_CHECK_TYPES([loff_t])
+CFLAGS="$CFLAGS_hold"
 
 LIBS_hold="$LIBS"
 LIBS="$LIBS -lm"
diff --git a/libgo/go/syscall/libcall_linux.go 
b/libgo/go/syscall/libcall_linux.go
index 96974bd32..d41af5e28 100644
--- a/libgo/go/syscall/libcall_linux.go
+++ b/libgo/go/syscall/libcall_linux.go
@@ -209,19 +209,19 @@ func Gettid() (tid int) {
 //sys  Setxattr(path 

  1   2   3   4   5   6   >