Re: [C PATCH]: allow aliasing of compatible types derived from enumeral types [PR115157]

2024-05-23 Thread Ian Lance Taylor
On Thu, May 23, 2024 at 2:48 PM Martin Uecker  wrote:
>
> Am Donnerstag, dem 23.05.2024 um 14:30 -0700 schrieb Ian Lance Taylor:
> > On Thu, May 23, 2024 at 2:00 PM Joseph Myers  wrote:
> > >
> > > On Tue, 21 May 2024, Martin Uecker wrote:
> > > >
> > > > C: allow aliasing of compatible types derived from enumeral types 
> > > > [PR115157]
> > > >
> > > > Aliasing of enumeral types with the underlying integer is now 
> > > > allowed
> > > > by setting the aliasing set to zero.  But this does not allow 
> > > > aliasing
> > > > of derived types which are compatible as required by ISO C.  
> > > > Instead,
> > > > initially set structural equality.  Then set TYPE_CANONICAL and 
> > > > update
> > > > pointers and main variants when the type is completed (as done for
> > > > structures and unions in C23).
> > > >
> > > > PR 115157
> > > >
> > > > gcc/c/
> > > > * c-decl.cc (shadow_tag-warned,parse_xref_tag,start_enum,
> > > > finish_enum): Set SET_TYPE_STRUCTURAL_EQUALITY / 
> > > > TYPE_CANONICAL.
> > > > * c-obj-common.cc (get_alias_set): Remove special case.
> > > > (get_aka_type): Add special case.
> > > >
> > > > gcc/
> > > > * godump.cc (go_output_typedef): use TYPE_MAIN_VARIANT 
> > > > instead
> > > > of TYPE_CANONICAL.
> > > >
> > > > gcc/testsuite/
> > > > * gcc.dg/enum-alias-1.c: New test.
> > > > * gcc.dg/enum-alias-2.c: New test.
> > > > * gcc.dg/enum-alias-3.c: New test.
> > >
> > > OK, in the absence of objections on middle-end or Go grounds within the
> > > next week.
> >
> > The godump.cc patch is
> >
> >&& (TYPE_CANONICAL (TREE_TYPE (decl)) == NULL_TREE
> >   || !container->decls_seen.contains
> > -   (TYPE_CANONICAL (TREE_TYPE (decl)
> > +   (TYPE_MAIN_VARIANT (TREE_TYPE (decl)
> >  {
> >
> > What is the problem you are seeing?
>
> Test failures in godump-1.c
>
> >
> > This patch isn't right:
> >
> > 1) The code is saying if "X == NULL_TREE || !already_seen(X)".  This
> > patch is changing the latter X but not the former.  They should be
> > consistent.
>
> Maybe the X == NULL_TREE can be removed if we
> add TYPE_MAIN_VARIANTs instead?

If TYPE_MAIN_VARIANT is never NULL_TREE, then I agree that the
NULL_TREE test can be removed.

Ian


Re: [C PATCH]: allow aliasing of compatible types derived from enumeral types [PR115157]

2024-05-23 Thread Ian Lance Taylor
On Thu, May 23, 2024 at 2:00 PM Joseph Myers  wrote:
>
> On Tue, 21 May 2024, Martin Uecker wrote:
> >
> > C: allow aliasing of compatible types derived from enumeral types 
> > [PR115157]
> >
> > Aliasing of enumeral types with the underlying integer is now allowed
> > by setting the aliasing set to zero.  But this does not allow aliasing
> > of derived types which are compatible as required by ISO C.  Instead,
> > initially set structural equality.  Then set TYPE_CANONICAL and update
> > pointers and main variants when the type is completed (as done for
> > structures and unions in C23).
> >
> > PR 115157
> >
> > gcc/c/
> > * c-decl.cc (shadow_tag-warned,parse_xref_tag,start_enum,
> > finish_enum): Set SET_TYPE_STRUCTURAL_EQUALITY / TYPE_CANONICAL.
> > * c-obj-common.cc (get_alias_set): Remove special case.
> > (get_aka_type): Add special case.
> >
> > gcc/
> > * godump.cc (go_output_typedef): use TYPE_MAIN_VARIANT instead
> > of TYPE_CANONICAL.
> >
> > gcc/testsuite/
> > * gcc.dg/enum-alias-1.c: New test.
> > * gcc.dg/enum-alias-2.c: New test.
> > * gcc.dg/enum-alias-3.c: New test.
>
> OK, in the absence of objections on middle-end or Go grounds within the
> next week.

The godump.cc patch is

   && (TYPE_CANONICAL (TREE_TYPE (decl)) == NULL_TREE
  || !container->decls_seen.contains
-   (TYPE_CANONICAL (TREE_TYPE (decl)
+   (TYPE_MAIN_VARIANT (TREE_TYPE (decl)
 {

What is the problem you are seeing?

This patch isn't right:

1) The code is saying if "X == NULL_TREE || !already_seen(X)".  This
patch is changing the latter X but not the former.  They should be
consistent.

2) At the bottom of that conditional block is code that adds a value
to container->decls_seen.  Today that code is adding TYPE_CANONICAL.
If we change the condition to test TYPE_MAIN_VARIANT, then we need to
add TYPE_MAIN_VARIANT to decls_seen.

Hope that makes sense.

I don't know why the patch is required, but it's fine with those
changes as long as the libgo tests continue to pass.

Ian


Re: [PATCH 5/4] libbacktrace: improve getting debug information for loaded dlls

2024-05-03 Thread Ian Lance Taylor
On Thu, May 2, 2024 at 12:23 PM Björn Schäpers  wrote:
>
> Am 28.04.2024 um 20:16 schrieb Ian Lance Taylor:
> >
> > Which of your other patches are still relevant?  Thanks.
> >
> only this one.

Thanks.  Committed.

Ian


Re: [COMMITTED] Remove obsolete Solaris 11.3 support

2024-05-02 Thread Ian Lance Taylor
On Thu, May 2, 2024 at 7:06 AM Rainer Orth  
wrote:
>
> * libgo configure.ac and Makefile.am can now expect HAVE_STAT_TIMESPEC
>   to be true and libgo_cv_lib_setcontext_clobbers_tls doesn't apply any
>   longer.  Any change would have to go upstream first and I don't know
>   about Ian's policy for keeping older versions supported.

There's no reason for libgo to support a version that GCC itself
doesn't support.  If you send me a patch I can apply it.  Thanks.

Ian


Re: [COMMITTED] Reduce startup costs for Value_Range.

2024-05-02 Thread Ian Lance Taylor
On Wed, May 1, 2024 at 7:50 PM Andrew Pinski  wrote:
>
> On Wed, May 1, 2024 at 7:40 PM Ian Lance Taylor  wrote:
> >
> > On Wed, May 1, 2024 at 12:43 AM Aldy Hernandez  wrote:
> > >
> > > gcc/ChangeLog:
> > >
> > > * ipa-fnsummary.cc (evaluate_properties_for_edge): Initialize 
> > > Value_Range's.
> > > * value-range.h (class Value_Range): Add a buffer and remove
> > > m_irange and m_frange.
> > > (Value_Range::Value_Range): Call init.
> > > (Value_Range::set_type): Same.
> > > (Value_Range::init): Use in place new to initialize buffer.
> > > (Value_Range::operator=): Tidy.
> >
> >
> > I'm seeing a crash building on sparc-sun-solaris2.11 that may be due
> > to this change.  The crash occurs in stage 1, the first time the newly
> > built compiler is used.
> >
> > ./xgcc -B./ -B/var/gcc/iant/install/sparc-sun-solaris2.11/bin/
> > -isystem /var/gcc/iant/install/sparc-sun-solaris2.11/include -isystem
> > /var/gcc/iant/install/sparc-sun-solaris2.11/sys-include
> > -L/var/gcc/iant/bootstrap/gcc/../ld  -xc -nostdinc /dev/null -S -o
> > /dev/null -fself-test=../../gcc/gcc/testsuite/selftests
> > In function ‘test_fn’:
> > cc1: internal compiler error: Bus Error
> > 0x1c7db03 crash_signal
> > ../../gcc/gcc/toplev.cc:319
> > 0x104a82c void wi::copy > generic_wide_int >
> > >(wide_int_storage&, generic_wide_int > false> > const&)
> > ../../gcc/gcc/wide-int.h:2191
> > 0x1049da3 wide_int_storage&
> > wide_int_storage::operator=(wi::hwi_with_prec
> > const&)
> > ../../gcc/gcc/wide-int.h:1247
> > 0x104929b generic_wide_int&
> > generic_wide_int::operator=(wi::hwi_with_prec
> > const&)
> > ../../gcc/gcc/wide-int.h:1002
> > 0x104757f irange_bitmask::set_unknown(unsigned int)
> > ../../gcc/gcc/value-range.h:163
> > 0x1047b6f irange::set_varying(tree_node*)
> > ../../gcc/gcc/value-range.h:1067
> > 0x1774d1b Value_Range::set_varying(tree_node*)
> > ../../gcc/gcc/value-range.h:720
> > 0x1aef213 range_cast(vrange&, tree_node*)
> > ../../gcc/gcc/range-op.h:248
> > 0x1ada517 operator_lshift::op1_range(irange&, tree_node*, irange
> > const&, irange const&, relation_trio) const
> > ../../gcc/gcc/range-op.cc:2706
> > 0x1aeaa6b range_op_lshift_tests
> > ../../gcc/gcc/range-op.cc:4750
> > 0x1aee20f selftest::range_op_tests()
> > ../../gcc/gcc/range-op.cc:4887
> > 0x2dfaa37 test_ranges
> > ../../gcc/gcc/function-tests.cc:585
> > 0x2dfb337 selftest::function_tests_cc_tests()
> > ../../gcc/gcc/function-tests.cc:681
> > 0x308a027 selftest::run_tests()
> > ../../gcc/gcc/selftest-run-tests.cc:108
> > 0x1c833ef toplev::run_self_tests()
> > ../../gcc/gcc/toplev.cc:2213
> > Please submit a full bug report, with preprocessed source (by using
> > -freport-bug).
> > Please include the complete backtrace with any bug report.
> > See <https://gcc.gnu.org/bugs/> for instructions.
> > make: *** [../../gcc/gcc/c/Make-lang.in:153: s-selftest-c] Error 1
>
> This was also reported here: 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114912

Thanks.

> The same question applies really, what compiler are you using to
> compile GCC with? I suspect this is making a difference. It might also
> be the sparc compiler that both of you two are using is causing wrong
> code with some more complex C++ code even though it is at -O0.
> The adding of the deconstructor to Value_Range might be causing the
> structure to become a "non-POD" and different argument passing and it
> was broken even at -O0 (this is just a guess).

I am building stage1 with GCC 9.1.0.

Ian


Re: [COMMITTED] Reduce startup costs for Value_Range.

2024-05-01 Thread Ian Lance Taylor
On Wed, May 1, 2024 at 12:43 AM Aldy Hernandez  wrote:
>
> gcc/ChangeLog:
>
> * ipa-fnsummary.cc (evaluate_properties_for_edge): Initialize 
> Value_Range's.
> * value-range.h (class Value_Range): Add a buffer and remove
> m_irange and m_frange.
> (Value_Range::Value_Range): Call init.
> (Value_Range::set_type): Same.
> (Value_Range::init): Use in place new to initialize buffer.
> (Value_Range::operator=): Tidy.


I'm seeing a crash building on sparc-sun-solaris2.11 that may be due
to this change.  The crash occurs in stage 1, the first time the newly
built compiler is used.

./xgcc -B./ -B/var/gcc/iant/install/sparc-sun-solaris2.11/bin/
-isystem /var/gcc/iant/install/sparc-sun-solaris2.11/include -isystem
/var/gcc/iant/install/sparc-sun-solaris2.11/sys-include
-L/var/gcc/iant/bootstrap/gcc/../ld  -xc -nostdinc /dev/null -S -o
/dev/null -fself-test=../../gcc/gcc/testsuite/selftests
In function ‘test_fn’:
cc1: internal compiler error: Bus Error
0x1c7db03 crash_signal
../../gcc/gcc/toplev.cc:319
0x104a82c void wi::copy >
>(wide_int_storage&, generic_wide_int > const&)
../../gcc/gcc/wide-int.h:2191
0x1049da3 wide_int_storage&
wide_int_storage::operator=(wi::hwi_with_prec
const&)
../../gcc/gcc/wide-int.h:1247
0x104929b generic_wide_int&
generic_wide_int::operator=(wi::hwi_with_prec
const&)
../../gcc/gcc/wide-int.h:1002
0x104757f irange_bitmask::set_unknown(unsigned int)
../../gcc/gcc/value-range.h:163
0x1047b6f irange::set_varying(tree_node*)
../../gcc/gcc/value-range.h:1067
0x1774d1b Value_Range::set_varying(tree_node*)
../../gcc/gcc/value-range.h:720
0x1aef213 range_cast(vrange&, tree_node*)
../../gcc/gcc/range-op.h:248
0x1ada517 operator_lshift::op1_range(irange&, tree_node*, irange
const&, irange const&, relation_trio) const
../../gcc/gcc/range-op.cc:2706
0x1aeaa6b range_op_lshift_tests
../../gcc/gcc/range-op.cc:4750
0x1aee20f selftest::range_op_tests()
../../gcc/gcc/range-op.cc:4887
0x2dfaa37 test_ranges
../../gcc/gcc/function-tests.cc:585
0x2dfb337 selftest::function_tests_cc_tests()
../../gcc/gcc/function-tests.cc:681
0x308a027 selftest::run_tests()
../../gcc/gcc/selftest-run-tests.cc:108
0x1c833ef toplev::run_self_tests()
../../gcc/gcc/toplev.cc:2213
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See  for instructions.
make: *** [../../gcc/gcc/c/Make-lang.in:153: s-selftest-c] Error 1

Ian


libgo patch commited: Dump register on Solaris

2024-04-29 Thread Ian Lance Taylor
This libgo patch, by Rainer Orth, dumps register values on Solaris on
a crash.  This fixes GC PR 106813.  Bootstrapped and ran Go testsuite
on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
a05efc8bf5ed329ea7d9b1740c326bdc6b04e37a
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 8a2810d5b2d..9a4b402573a 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-1f0c8364cd35026a647aa4e66ee4d8563c8a5d27
+60f985a7852632834936b4b859aa75d9df88f038
 
 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-signal.c b/libgo/runtime/go-signal.c
index aa1b6305ad0..c48c8ee58e3 100644
--- a/libgo/runtime/go-signal.c
+++ b/libgo/runtime/go-signal.c
@@ -216,6 +216,10 @@ getSiginfoCode(siginfo_t *info)
return (uintptr)(info->si_code);
 }
 
+#if defined(__sparc__) && defined(__arch64__) && defined(__linux__)
+  #define gregs mc_gregs
+#endif
+
 struct getSiginfoRet {
uintptr sigaddr;
uintptr sigpc;
@@ -242,9 +246,9 @@ getSiginfo(siginfo_t *info, void *context 
__attribute__((unused)))
// Use unportable code to pull it from context, and if that fails
// try a stack backtrace across the signal handler.
 
-#if defined(__x86_64__) && defined(__linux__)
+#if defined(__x86_64__) && (defined(__linux__) || (defined(__sun__) && 
defined(__svr4__)))
ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.gregs[REG_RIP];
-#elif defined(__i386__) && defined(__linux__)
+#elif defined(__i386__) && (defined(__linux__) || (defined(__sun__) && 
defined(__svr4__)))
ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.gregs[REG_EIP];
 #elif defined(__alpha__) && defined(__linux__)
ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.sc_pc;
@@ -263,6 +267,9 @@ getSiginfo(siginfo_t *info, void *context 
__attribute__((unused)))
 #elif defined(__NetBSD__)
ret.sigpc = _UC_MACHINE_PC(((ucontext_t*)(context)));
 #endif
+#if defined(__sparc__) && (defined(__linux__) || (defined(__sun__) && 
defined(__svr4__)))
+   ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.gregs[REG_PC];
+#endif
 
if (ret.sigpc == 0) {
// Skip getSiginfo/sighandler/sigtrampgo/sigtramp/handler.
@@ -285,7 +292,7 @@ void dumpregs(siginfo_t *, void *)
 void
 dumpregs(siginfo_t *info __attribute__((unused)), void *context 
__attribute__((unused)))
 {
-#if defined(__x86_64__) && defined(__linux__)
+#if defined(__x86_64__) && (defined(__linux__) || (defined(__sun__) && 
defined(__svr4__)))
{
mcontext_t *m = &((ucontext_t*)(context))->uc_mcontext;
 
@@ -306,12 +313,22 @@ dumpregs(siginfo_t *info __attribute__((unused)), void 
*context __attribute__((u
runtime_printf("r14%X\n", m->gregs[REG_R14]);
runtime_printf("r15%X\n", m->gregs[REG_R15]);
runtime_printf("rip%X\n", m->gregs[REG_RIP]);
+#if defined(REG_EFL)
runtime_printf("rflags %X\n", m->gregs[REG_EFL]);
+#elif defined(REG_RFL)
+   runtime_printf("rflags %X\n", m->gregs[REG_RFL]);
+#endif
+#if defined(REG_CSGSFS)
runtime_printf("cs %X\n", m->gregs[REG_CSGSFS] & 0x);
runtime_printf("fs %X\n", (m->gregs[REG_CSGSFS] >> 16) & 
0x);
runtime_printf("gs %X\n", (m->gregs[REG_CSGSFS] >> 32) & 
0x);
+#elif defined(REG_CS) && defined(REG_FS) && defined(REG_GS)
+   runtime_printf("cs %X\n", m->gregs[REG_CS]);
+   runtime_printf("fs %X\n", m->gregs[REG_FS]);
+   runtime_printf("gs %X\n", m->gregs[REG_GS]);
+#endif
  }
-#elif defined(__i386__) && defined(__linux__)
+#elif defined(__i386__) && (defined(__linux__) || (defined(__sun__) && 
defined(__svr4__)))
{
mcontext_t *m = &((ucontext_t*)(context))->uc_mcontext;
 
@@ -423,5 +440,43 @@ dumpregs(siginfo_t *info __attribute__((unused)), void 
*context __attribute__((u
runtime_printf("pc %X\n", m->pc);
runtime_printf("pstate %X\n", m->pstate);
  }
+#elif defined(__sparc__) && (defined(__linux__) || (defined(__sun__) && 
defined(__svr4__)))
+   {
+   mcontext_t *m = &((ucontext_t*)(context))->uc_mcontext;
+
+#ifdef __sparcv9
+  #define REG_FMT "%X"
+#else
+  #define REG_FMT "%x"
+#endif
+
+#ifdef REG_CCR
+   runtime_printf("ccr  " REG_FMT "\n", m->gregs[REG_CCR]);
+#else
+   runtime_printf("psr  " REG_FMT "\n", m->gregs[REG_PSR]);
+#endif
+   runtime_printf("pc   " REG_FMT "\n", m->gregs[REG_PC]);
+   runtime_printf("npc  " REG_FMT "\n", m->gregs[REG_nPC]);
+   runtime_printf("y" REG_FMT "\n", m->gregs[REG_Y]);
+   runtime_printf("g1   " REG_FMT "\n", m->gregs[REG_G1]);
+   runtime_printf("g2   " REG_FMT "\n", m->gregs[REG_G2]);
+   runtime_printf("g3   " 

libgo patch committed: Use in runtime/runtime.h

2024-04-29 Thread Ian Lance Taylor
This libgo patch changes runtime/runtime.h to use the C99 
header file rather than defining a bool type and true/false constants
itself.  C99 was a long time ago and in case this file is always
compiled by the newly built GCC.  This should fix GCC PR 114875.
Bootstrapped on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
ef246d48fd487805f1c4181c7482545c54a4d4a9
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 50d430d5034..8a2810d5b2d 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-98e92493db2ab7857a5934a950a830fc1f95a4e5
+1f0c8364cd35026a647aa4e66ee4d8563c8a5d27
 
 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/runtime.h b/libgo/runtime/runtime.h
index 699770d53ad..da31e11bb77 100644
--- a/libgo/runtime/runtime.h
+++ b/libgo/runtime/runtime.h
@@ -7,6 +7,7 @@
 #include "go-assert.h"
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -51,7 +52,6 @@ typedef uintptr   uintreg;
 
 /* Defined types.  */
 
-typedef_Bool   bool;
 typedefuint8   byte;
 typedefstruct  g   G;
 typedefstruct  mutex   Lock;
@@ -114,11 +114,6 @@ extern M*  runtime_m(void);
 extern G*  runtime_g(void)
   __asm__(GOSYM_PREFIX "runtime.getg");
 
-enum
-{
-   true= 1,
-   false   = 0,
-};
 enum
 {
PtrSize = sizeof(void*),


Re: [PATCH 5/4] libbacktrace: improve getting debug information for loaded dlls

2024-04-28 Thread Ian Lance Taylor
On Thu, Apr 25, 2024 at 1:15 PM Björn Schäpers  wrote:
>
> > Attached is the combined version of the two patches, only implementing the
> > variant with the tlhelp32 API.
> >
> > Tested on x86 and x86_64 windows.
> >
> > Kind regards,
> > Björn.
>
> A friendly ping.

Thanks.  Committed as follows.

Which of your other patches are still relevant?  Thanks.

Ian
942a9cf2a958113d2ab46f5b015c36e569abedcf
diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac
index 3e0075a2b79..59e9c415db8 100644
--- a/libbacktrace/configure.ac
+++ b/libbacktrace/configure.ac
@@ -380,6 +380,10 @@ if test "$have_loadquery" = "yes"; then
 fi
 
 AC_CHECK_HEADERS(windows.h)
+AC_CHECK_HEADERS(tlhelp32.h, [], [],
+[#ifdef HAVE_WINDOWS_H
+#  include 
+#endif])
 
 # Check for the fcntl function.
 if test -n "${with_target_subdir}"; then
diff --git a/libbacktrace/pecoff.c b/libbacktrace/pecoff.c
index 9e437d810c7..4f267841178 100644
--- a/libbacktrace/pecoff.c
+++ b/libbacktrace/pecoff.c
@@ -49,6 +49,18 @@ POSSIBILITY OF SUCH DAMAGE.  */
 #endif
 
 #include 
+
+#ifdef HAVE_TLHELP32_H
+#include 
+
+#ifdef UNICODE
+/* If UNICODE is defined, all the symbols are replaced by a macro to use the
+   wide variant. But we need the ansi variant, so undef the macros. */
+#undef MODULEENTRY32
+#undef Module32First
+#undef Module32Next
+#endif
+#endif
 #endif
 
 /* Coff file header.  */
@@ -592,7 +604,8 @@ coff_syminfo (struct backtrace_state *state, uintptr_t addr,
 static int
 coff_add (struct backtrace_state *state, int descriptor,
  backtrace_error_callback error_callback, void *data,
- fileline *fileline_fn, int *found_sym, int *found_dwarf)
+ fileline *fileline_fn, int *found_sym, int *found_dwarf,
+ uintptr_t module_handle ATTRIBUTE_UNUSED)
 {
   struct backtrace_view fhdr_view;
   off_t fhdr_off;
@@ -870,12 +883,7 @@ coff_add (struct backtrace_state *state, int descriptor,
 }
 
 #ifdef HAVE_WINDOWS_H
-  {
-uintptr_t module_handle;
-
-module_handle = (uintptr_t) GetModuleHandle (NULL);
-base_address = module_handle - image_base;
-  }
+  base_address = module_handle - image_base;
 #endif
 
   if (!backtrace_dwarf_add (state, base_address, _sections,
@@ -917,12 +925,61 @@ backtrace_initialize (struct backtrace_state *state,
   int found_sym;
   int found_dwarf;
   fileline coff_fileline_fn;
+  uintptr_t module_handle = 0;
+#ifdef HAVE_TLHELP32_H
+  fileline module_fileline_fn;
+  int module_found_sym;
+  HANDLE snapshot;
+#endif
+
+#ifdef HAVE_WINDOWS_H
+  module_handle = (uintptr_t) GetModuleHandle (NULL);
+#endif
 
   ret = coff_add (state, descriptor, error_callback, data,
- _fileline_fn, _sym, _dwarf);
+ _fileline_fn, _sym, _dwarf, module_handle);
   if (!ret)
 return 0;
 
+#ifdef HAVE_TLHELP32_H
+  do
+{
+  snapshot = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE, 0);
+}
+  while (snapshot == INVALID_HANDLE_VALUE
+&& GetLastError () == ERROR_BAD_LENGTH);
+
+  if (snapshot != INVALID_HANDLE_VALUE)
+{
+  MODULEENTRY32 entry;
+  BOOL ok;
+  entry.dwSize = sizeof (MODULEENTRY32);
+
+  for (ok = Module32First (snapshot, ); ok; ok = Module32Next 
(snapshot, ))
+   {
+ if (strcmp (filename, entry.szExePath) == 0)
+   continue;
+
+ module_handle = (uintptr_t) entry.hModule;
+ if (module_handle == 0)
+   continue;
+
+ descriptor = backtrace_open (entry.szExePath, error_callback, data,
+  NULL);
+ if (descriptor < 0)
+   continue;
+
+ coff_add (state, descriptor, error_callback, data,
+   _fileline_fn, _found_sym, _dwarf,
+   module_handle);
+ if (module_found_sym)
+   found_sym = 1;
+   }
+
+  CloseHandle (snapshot);
+}
+#endif
+
   if (!state->threaded)
 {
   if (found_sym)


Re: [PATCH] libbacktrace: Avoid GNU ld --compress-debug-sections=zlib-gabi

2024-04-23 Thread Ian Lance Taylor
On Tue, Apr 23, 2024 at 7:24 AM Jakub Jelinek  wrote:
>
> What we could do is drop the HAVE_COMPRESSED_DEBUG stuff altogether, and
> instead similarly how we have HAVE_COMPRESSED_DEBUG_ZSTD have
> HAVE_COMPRESSED_DEBUG_{ZLIB,ZLIB_GABI,ZLIB_GNU} and for each of those
> if linker supports them test with that corresponding flag.

I think that's right.  Committed this patch after testing on
x86_64-pc-linux-gnu.  While I was at it I added an _alloc version of
ctestzstd.

Ian

* configure.ac: Test --compress-debug-sections=zlib-gnu and
--compress-debug-sections=zlib-gabi separately, setting new
automake conditionals.
* Makefile.am (ctestg, ctestg_alloc): Only build if
HAVE_COMPRESSED_DEBUG_ZLIB_GNU.
(ctesta, ctesta_alloc): Only build if
HAVE_COMPRESSED_DEBUG_ZLIB_GABI.
(ctestzstd_alloc): New test if HAVE_COMPRESSED_DEBUG_ZSTD.
* configure, Makefile.in: Regenerate.
3943de6986271466652cb619dbc60881060b180c
diff --git a/libbacktrace/Makefile.am b/libbacktrace/Makefile.am
index 5677ecd8865..bed42c29329 100644
--- a/libbacktrace/Makefile.am
+++ b/libbacktrace/Makefile.am
@@ -493,19 +493,37 @@ endif HAVE_OBJCOPY_DEBUGLINK
  $<
$(OBJCOPY) --strip-all $< $@
 
-if HAVE_COMPRESSED_DEBUG
+if HAVE_COMPRESSED_DEBUG_ZLIB_GNU
 
 ctestg_SOURCES = btest.c testlib.c
 ctestg_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 ctestg_LDFLAGS = -Wl,--compress-debug-sections=zlib-gnu 
$(libbacktrace_testing_ldflags)
 ctestg_LDADD = libbacktrace.la
 
+ctestg_alloc_SOURCES = $(ctestg_SOURCES)
+ctestg_alloc_CFLAGS = $(ctestg_CFLAGS)
+ctestg_alloc_LDFLAGS = $(ctestg_LDFLAGS) $(libbacktrace_testing_ldflags)
+ctestg_alloc_LDADD = libbacktrace_alloc.la
+
+BUILDTESTS += ctestg ctestg_alloc
+
+endif
+
+if HAVE_COMPRESSED_DEBUG_ZLIB_GABI
+
 ctesta_SOURCES = btest.c testlib.c
 ctesta_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 ctesta_LDFLAGS = -Wl,--compress-debug-sections=zlib-gabi 
$(libbacktrace_testing_ldflags)
 ctesta_LDADD = libbacktrace.la
 
-BUILDTESTS += ctestg ctesta
+ctesta_alloc_SOURCES = $(ctesta_SOURCES)
+ctesta_alloc_CFLAGS = $(ctesta_CFLAGS)
+ctesta_alloc_LDFLAGS = $(ctesta_LDFLAGS) $(libbacktrace_testing_ldflags)
+ctesta_alloc_LDADD = libbacktrace_alloc.la
+
+BUILDTESTS += ctesta ctesta_alloc
+
+endif
 
 if HAVE_COMPRESSED_DEBUG_ZSTD
 
@@ -514,21 +532,12 @@ ctestzstd_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 ctestzstd_LDFLAGS = -Wl,--compress-debug-sections=zstd 
$(libbacktrace_testing_ldflags)
 ctestzstd_LDADD = libbacktrace.la
 
-BUILDTESTS += ctestzstd
-
-endif
-
-ctestg_alloc_SOURCES = $(ctestg_SOURCES)
-ctestg_alloc_CFLAGS = $(ctestg_CFLAGS)
-ctestg_alloc_LDFLAGS = $(ctestg_LDFLAGS) $(libbacktrace_testing_ldflags)
-ctestg_alloc_LDADD = libbacktrace_alloc.la
-
-ctesta_alloc_SOURCES = $(ctesta_SOURCES)
-ctesta_alloc_CFLAGS = $(ctesta_CFLAGS)
-ctesta_alloc_LDFLAGS = $(ctesta_LDFLAGS) $(libbacktrace_testing_ldflags)
-ctesta_alloc_LDADD = libbacktrace_alloc.la
+ctestzstd_alloc_SOURCES = $(ctestzstd_SOURCES)
+ctestzstd_alloc_CFLAGS = $(ctestzstd_CFLAGS)
+ctestzstd_alloc_LDFLAGS = $(ctestzstd_LDFLAGS) $(libbacktrace_testing_ldflags)
+ctestzstd_alloc_LDADD = libbacktrace_alloc.la
 
-BUILDTESTS += ctestg_alloc ctesta_alloc
+BUILDTESTS += ctestzstd ctestzstd_alloc
 
 endif
 
diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac
index 0f61f2b28ab..3e0075a2b79 100644
--- a/libbacktrace/configure.ac
+++ b/libbacktrace/configure.ac
@@ -502,16 +502,27 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM(,)],
 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],
+dnl Test whether the linker supports the --compress-debug-sections=zlib-gnu
+dnl option.
+AC_CACHE_CHECK([whether --compress-debug-sections=zlib-gnu is supported],
+[libgo_cv_ld_compress_zlib_gnu],
 [LDFLAGS_hold=$LDFLAGS
 LDFLAGS="$LDFLAGS -Wl,--compress-debug-sections=zlib-gnu"
 AC_LINK_IFELSE([AC_LANG_PROGRAM(,)],
-[libgo_cv_ld_compress=yes],
-[libgo_cv_ld_compress=no])
+[libgo_cv_ld_compress_zlib_gnu=yes],
+[libgo_cv_ld_compress_zlib_gnu=no])
 LDFLAGS=$LDFLAGS_hold])
-AM_CONDITIONAL(HAVE_COMPRESSED_DEBUG, test "$libgo_cv_ld_compress" = yes)
+AM_CONDITIONAL(HAVE_COMPRESSED_DEBUG_ZLIB_GNU, test 
"$libgo_cv_ld_compress_zlib_gnu" = yes)
+
+AC_CACHE_CHECK([whether --compress-debug-sections=zlib-gabi is supported],
+[libgo_cv_ld_compress_zlib_gabi],
+[LDFLAGS_hold=$LDFLAGS
+LDFLAGS="$LDFLAGS -Wl,--compress-debug-sections=zlib-gabi"
+AC_LINK_IFELSE([AC_LANG_PROGRAM(,)],
+[libgo_cv_ld_compress_zlib_gabi=yes],
+[libgo_cv_ld_compress_zlib_gabi=no])
+LDFLAGS=$LDFLAGS_hold])
+AM_CONDITIONAL(HAVE_COMPRESSED_DEBUG_ZLIB_GABI, test 
"$libgo_cv_ld_compress_zlib_gabi" = yes)
 
 AC_CHECK_LIB([zstd], [ZSTD_compress],
 [AC_DEFINE(HAVE_ZSTD, 1, [Define if -lzstd is available.])])


Re: [PATCH] gotools: Workaround non-reproduceability of automake

2024-04-15 Thread Ian Lance Taylor
On Mon, Apr 15, 2024 at 5:42 AM Jakub Jelinek  wrote:
>
> 2024-04-15  Jakub Jelinek  
>
> * Makefile.am (install-exec-local, uninstall-local): Add goals
> on the else branch of if NATIVE to ensure reproducibility.
> * Makefile.in: Regenerate.

This is OK.  Go ahead and commit.  Thanks.

Ian


Re: [PATCH] go: Add go.install-dvi rule in go/Make-lang.in

2024-04-04 Thread Ian Lance Taylor
On Thu, Apr 4, 2024 at 9:27 AM Christophe Lyon
 wrote:
>
> go has a go.dvi build rule, but lacks the go.install-dvi one.
>
> 2024-04-04  Christophe Lyon  
>
> gcc/go/
> * Make-lang.in (go.install-dvi): New rule.

This is OK.  Thanks.

Ian


Go patch committed: Use correct check for index value overflow

2024-03-27 Thread Ian Lance Taylor
This patch to the Go frontend uses the correct size and comparison
when doing an index value overflow check.  This has apparently been
wrong since I introduced the code ten years ago.  This fixes GCC PR
114500.  Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.
Committed to mainline.

Ian
1091113a0036c7315197e09af572dce2beaf1c4c
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index de6e21fb3b5..50d430d5034 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-3f597287b6b858794dabdfe1bf83b386aad18102
+98e92493db2ab7857a5934a950a830fc1f95a4e5
 
 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 8429e553eac..238d5a56ca2 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -18790,7 +18790,7 @@ Composite_literal_expression::lower_array(Type* type)
 
  Named_type* ntype = Type::lookup_integer_type("int");
  Integer_type* inttype = ntype->integer_type();
- if (sizeof(index) <= static_cast(inttype->bits() * 8)
+ if (sizeof(index) >= static_cast(inttype->bits() / 8)
  && index >> (inttype->bits() - 1) != 0)
{
  go_error_at(index_expr->location(), "index value overflow");


Go patch committed: Update issue16016 test

2024-03-27 Thread Ian Lance Taylor
This patch to the Go testsuite updates issue16016.go.  This backports
https://go.dev/cl/574536 into the GCC testsuite.  This fixes PR
go/114453.  Bootstrapped and ran test.  Committed to mainline.

Ian
5b6f599670994bef957bd15c683102468a7104f1
diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue16016.go 
b/gcc/testsuite/go.test/test/fixedbugs/issue16016.go
index e738e1dba0e..b1947f5548d 100644
--- a/gcc/testsuite/go.test/test/fixedbugs/issue16016.go
+++ b/gcc/testsuite/go.test/test/fixedbugs/issue16016.go
@@ -6,7 +6,10 @@
 
 package main
 
-import "time"
+import (
+   "runtime"
+   "time"
+)
 
 type T struct{}
 
@@ -24,8 +27,19 @@ type Q interface {
 }
 
 func main() {
+   var count = 1
+   if runtime.Compiler == "gccgo" {
+   // On targets without split-stack libgo allocates
+   // a large stack for each goroutine. On 32-bit
+   // systems this test can run out of memory.
+   const intSize = 32 << (^uint(0) >> 63) // 32 or 64
+   if intSize < 64 {
+   count = 100
+   }
+   }
+
var q Q = {{}}
-   for i := 0; i < 1; i++ {
+   for i := 0; i < count; i++ {
go func() {
defer q.Foo([]interface{}{"meow"})
time.Sleep(100 * time.Millisecond)


Go patch committed: initialize local variable in lower_method_expression

2024-03-27 Thread Ian Lance Taylor
This patch to the Go frontend fixes an uninitialized variables in
lower_method_expression.  This fixes GCC PR 114463.  Bootstrapped and
ran Go testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
7b2a24f3964509bd5b74c4579c7ea5684e82aee1
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 73cb095322c..de6e21fb3b5 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-e15a14e410b8fc5d28012d5b313cb6c8476c7df9
+3f597287b6b858794dabdfe1bf83b386aad18102
 
 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 51ff0206129..8429e553eac 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -9059,7 +9059,7 @@ Selector_expression::lower_method_expression(Gogo* gogo)
 
   Named_type* nt = type->named_type();
   Struct_type* st = type->struct_type();
-  bool is_ambiguous;
+  bool is_ambiguous = false;
   Method* method = NULL;
   if (nt != NULL)
 method = nt->method_function(name, _ambiguous);


Re: No rule to make target '../libbacktrace/libbacktrace.la', needed by 'libgo.la'. [PR106472]

2024-03-26 Thread Ian Lance Taylor
On Tue, Mar 26, 2024 at 9:33 AM Дилян Палаузов
 wrote:
>
> Makefile.def contains already:
>
> host_modules= { module= libbacktrace; bootstrap=true; }; // since eff02e4f84 
> - "libbacktrace/: * Initial implementation" year 2012
>
> host_modules= { module= libcpp; bootstrap=true; }; // since 4f4e53dd8517c0b2 
> - year 2004

Yes.  I was just trying to answer your question.

Ian

> Am 25. März 2024 23:59:52 UTC schrieb Ian Lance Taylor :
>>
>> On Sat, Mar 23, 2024 at 4:32 AM Дилян Палаузов
>>  wrote:
>>>
>>>
>>>  Can the build experts say what needs to be changed?  The dependencies I 
>>> added are missing in the build configuration (@if gcc-bootstrap).
>>>
>>>  I cannot say if libbacktrace should or should not be a bootstrap=true 
>>> module.
>>
>>
>> I don't count as a build expert these days, but since GCC itself links
>> against libbacktrace, my understanding is that the libbacktrace
>> host_module should be bootstrap=true, just like, say, libcpp.
>>
>> Ian


Re: No rule to make target '../libbacktrace/libbacktrace.la', needed by 'libgo.la'. [PR106472]

2024-03-25 Thread Ian Lance Taylor
On Sat, Mar 23, 2024 at 4:32 AM Дилян Палаузов
 wrote:
>
> Can the build experts say what needs to be changed?  The dependencies I added 
> are missing in the build configuration (@if gcc-bootstrap).
>
> I cannot say if libbacktrace should or should not be a bootstrap=true module.

I don't count as a build expert these days, but since GCC itself links
against libbacktrace, my understanding is that the libbacktrace
host_module should be bootstrap=true, just like, say, libcpp.

Ian


libbacktrace patch committed: Don't assume compressed section aligned

2024-03-08 Thread Ian Lance Taylor
Reportedly when lld compresses debug sections, it fails to set the
alignment of the compressed section such that the compressed header
can be read directly.  To me this seems like a bug in lld.  However,
libbacktrace needs to work around it.  This patch, originally by the
GitHub user ubyte, does that.  Bootstrapped and tested on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian

* elf.c (elf_uncompress_chdr): Don't assume compressed section is
aligned.
5825bd0e0d0040126e78269e56c9b9f533e2a520
diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index 7841c86cd9c..3cd87020b03 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -5076,7 +5076,7 @@ elf_uncompress_chdr (struct backtrace_state *state,
 backtrace_error_callback error_callback, void *data,
 unsigned char **uncompressed, size_t *uncompressed_size)
 {
-  const b_elf_chdr *chdr;
+  b_elf_chdr chdr;
   char *alc;
   size_t alc_len;
   unsigned char *po;
@@ -5088,27 +5088,30 @@ elf_uncompress_chdr (struct backtrace_state *state,
   if (compressed_size < sizeof (b_elf_chdr))
 return 1;
 
-  chdr = (const b_elf_chdr *) compressed;
+  /* The lld linker can misalign a compressed section, so we can't safely read
+ the fields directly as we can for other ELF sections.  See
+ https://github.com/ianlancetaylor/libbacktrace/pull/120.  */
+  memcpy (, compressed, sizeof (b_elf_chdr));
 
   alc = NULL;
   alc_len = 0;
-  if (*uncompressed != NULL && *uncompressed_size >= chdr->ch_size)
+  if (*uncompressed != NULL && *uncompressed_size >= chdr.ch_size)
 po = *uncompressed;
   else
 {
-  alc_len = chdr->ch_size;
+  alc_len = chdr.ch_size;
   alc = backtrace_alloc (state, alc_len, error_callback, data);
   if (alc == NULL)
return 0;
   po = (unsigned char *) alc;
 }
 
-  switch (chdr->ch_type)
+  switch (chdr.ch_type)
 {
 case ELFCOMPRESS_ZLIB:
   if (!elf_zlib_inflate_and_verify (compressed + sizeof (b_elf_chdr),
compressed_size - sizeof (b_elf_chdr),
-   zdebug_table, po, chdr->ch_size))
+   zdebug_table, po, chdr.ch_size))
goto skip;
   break;
 
@@ -5116,7 +5119,7 @@ elf_uncompress_chdr (struct backtrace_state *state,
   if (!elf_zstd_decompress (compressed + sizeof (b_elf_chdr),
compressed_size - sizeof (b_elf_chdr),
(unsigned char *)zdebug_table, po,
-   chdr->ch_size))
+   chdr.ch_size))
goto skip;
   break;
 
@@ -5126,7 +5129,7 @@ elf_uncompress_chdr (struct backtrace_state *state,
 }
 
   *uncompressed = po;
-  *uncompressed_size = chdr->ch_size;
+  *uncompressed_size = chdr.ch_size;
 
   return 1;
 
@@ -6876,8 +6879,8 @@ elf_add (struct backtrace_state *state, const char 
*filename, int descriptor,
}
 }
 
-  // A debuginfo file may not have a useful .opd section, but we can use the
-  // one from the original executable.
+  /* A debuginfo file may not have a useful .opd section, but we can use the
+ one from the original executable.  */
   if (opd == NULL)
 opd = caller_opd;
 


libbacktrace patch committed: Link test programs with -no-install

2024-03-02 Thread Ian Lance Taylor
Some of the libbacktrace tests link a program and then modify the
debug info in some way.  When configured with --enable-shared the
linking, using libtool, generates a shell script.  That causes the
tests to fail because they can't modify the debug info of a shell
script.  This patch, originally by Jan Tojnar, pass the -no-install
flag to libtool to avoid generating a shell script.  Bootstrapped and
ran libbacktrace tests on x86_64-pc-linux-gnu.  Committed to mainline.

Ian

* Makefile.am (libbacktrace_testing_ldflags): Define.
(*_LDFLAGS): Add $(libbacktrace_testing_ldflags) for test
programs.
* Makefile.in: Regenerate
9b0d218544cd1b12bf63792c70052d2970acc69b
diff --git a/libbacktrace/Makefile.am b/libbacktrace/Makefile.am
index 750ed80ed05..5677ecd8865 100644
--- a/libbacktrace/Makefile.am
+++ b/libbacktrace/Makefile.am
@@ -106,6 +106,10 @@ check_DATA =
 # Flags to use when compiling test programs.
 libbacktrace_TEST_CFLAGS = $(EXTRA_FLAGS) $(WARN_FLAGS) -g
 
+# Flags to use when linking test programs.
+# This avoids generating a shell script when configured with --enable-shared.
+libbacktrace_testing_ldflags = -no-install
+
 if USE_DSYMUTIL
 
 %.dSYM: %
@@ -170,54 +174,63 @@ xcoff_%.c: xcoff.c
 
 test_elf_32_SOURCES = test_format.c testlib.c
 test_elf_32_CFLAGS = $(libbacktrace_TEST_CFLAGS)
+test_elf_32_LDFLAGS = $(libbacktrace_testing_ldflags)
 test_elf_32_LDADD = libbacktrace_noformat.la elf_32.lo
 
 BUILDTESTS += test_elf_32
 
 test_elf_64_SOURCES = test_format.c testlib.c
 test_elf_64_CFLAGS = $(libbacktrace_TEST_CFLAGS)
+test_elf_64_LDFLAGS = $(libbacktrace_testing_ldflags)
 test_elf_64_LDADD = libbacktrace_noformat.la elf_64.lo
 
 BUILDTESTS += test_elf_64
 
 test_macho_SOURCES = test_format.c testlib.c
 test_macho_CFLAGS = $(libbacktrace_TEST_CFLAGS)
+test_macho_LDFLAGS = $(libbacktrace_testing_ldflags)
 test_macho_LDADD = libbacktrace_noformat.la macho.lo
 
 BUILDTESTS += test_macho
 
 test_xcoff_32_SOURCES = test_format.c testlib.c
 test_xcoff_32_CFLAGS = $(libbacktrace_TEST_CFLAGS)
+test_xcoff_32_LDFLAGS = $(libbacktrace_testing_ldflags)
 test_xcoff_32_LDADD = libbacktrace_noformat.la xcoff_32.lo
 
 BUILDTESTS += test_xcoff_32
 
 test_xcoff_64_SOURCES = test_format.c testlib.c
 test_xcoff_64_CFLAGS = $(libbacktrace_TEST_CFLAGS)
+test_xcoff_64_LDFLAGS = $(libbacktrace_testing_ldflags)
 test_xcoff_64_LDADD = libbacktrace_noformat.la xcoff_64.lo
 
 BUILDTESTS += test_xcoff_64
 
 test_pecoff_SOURCES = test_format.c testlib.c
 test_pecoff_CFLAGS = $(libbacktrace_TEST_CFLAGS)
+test_pecoff_LDFLAGS = $(libbacktrace_testing_ldflags)
 test_pecoff_LDADD = libbacktrace_noformat.la pecoff.lo
 
 BUILDTESTS += test_pecoff
 
 test_unknown_SOURCES = test_format.c testlib.c
 test_unknown_CFLAGS = $(libbacktrace_TEST_CFLAGS)
+test_unknown_LDFLAGS = $(libbacktrace_testing_ldflags)
 test_unknown_LDADD = libbacktrace_noformat.la unknown.lo
 
 BUILDTESTS += test_unknown
 
 unittest_SOURCES = unittest.c testlib.c
 unittest_CFLAGS = $(libbacktrace_TEST_CFLAGS)
+unittest_LDFLAGS = $(libbacktrace_testing_ldflags)
 unittest_LDADD = libbacktrace.la
 
 BUILDTESTS += unittest
 
 unittest_alloc_SOURCES = $(unittest_SOURCES)
 unittest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS)
+unittest_alloc_LDFLAGS = $(libbacktrace_testing_ldflags)
 unittest_alloc_LDADD = libbacktrace_alloc.la
 
 BUILDTESTS += unittest_alloc
@@ -253,7 +266,7 @@ if HAVE_OBJCOPY_DEBUGLINK
 
 b2test_SOURCES = $(btest_SOURCES)
 b2test_CFLAGS = $(libbacktrace_TEST_CFLAGS)
-b2test_LDFLAGS = -Wl,--build-id
+b2test_LDFLAGS = -Wl,--build-id $(libbacktrace_testing_ldflags)
 b2test_LDADD = libbacktrace_elf_for_test.la
 
 check_PROGRAMS += b2test
@@ -263,7 +276,7 @@ if HAVE_DWZ
 
 b3test_SOURCES = $(btest_SOURCES)
 b3test_CFLAGS = $(libbacktrace_TEST_CFLAGS)
-b3test_LDFLAGS = -Wl,--build-id
+b3test_LDFLAGS = -Wl,--build-id $(libbacktrace_testing_ldflags)
 b3test_LDADD = libbacktrace_elf_for_test.la
 
 check_PROGRAMS += b3test
@@ -277,6 +290,7 @@ endif HAVE_ELF
 
 btest_SOURCES = btest.c testlib.c
 btest_CFLAGS = $(libbacktrace_TEST_CFLAGS) -O
+btest_LDFLAGS = $(libbacktrace_testing_ldflags)
 btest_LDADD = libbacktrace.la
 
 BUILDTESTS += btest
@@ -289,6 +303,7 @@ if HAVE_ELF
 
 btest_lto_SOURCES = btest.c testlib.c
 btest_lto_CFLAGS = $(libbacktrace_TEST_CFLAGS) -O -flto
+btest_lto_LDFLAGS = $(libbacktrace_testing_ldflags)
 btest_lto_LDADD = libbacktrace.la
 
 BUILDTESTS += btest_lto
@@ -297,6 +312,7 @@ endif HAVE_ELF
 
 btest_alloc_SOURCES = $(btest_SOURCES)
 btest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS)
+btest_alloc_LDFLAGS = $(libbacktrace_testing_ldflags)
 btest_alloc_LDADD = libbacktrace_alloc.la
 
 BUILDTESTS += btest_alloc
@@ -331,6 +347,7 @@ endif HAVE_DWZ
 
 stest_SOURCES = stest.c
 stest_CFLAGS = $(libbacktrace_TEST_CFLAGS)
+stest_LDFLAGS = $(libbacktrace_testing_ldflags)
 stest_LDADD = libbacktrace.la
 
 BUILDTESTS += stest
@@ -341,6 +358,7 @@ endif USE_DSYMUTIL
 
 stest_alloc_SOURCES = $(stest_SOURCES)
 stest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS)

libbacktrace patch committed: Skip all LZMA block header padding bytes

2024-03-02 Thread Ian Lance Taylor
This patch to libbacktrace corrects the LZMA block header parsing to
skip all the padding bytes, verifying that they are zero.  This fixes
https://github.com/ianlancetaylor/libbacktrace/issues/118.
Bootstrapped and ran libbacktrace tests on x86_64-pc-linux-gnu.  I was
able to verify that the problem occurred when setting the environment
variable XZ_OPT="--threads=2", and that this patch fixes the bug.
Committed to mainline.

Ian

* elf.c (elf_uncompress_lzma_block): Skip all header padding bytes
and verify that they are zero.
23f9fbed3c97ed70d2615d7d3fa7c249cc862553
diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index f4527e2477d..7841c86cd9c 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -5568,6 +5568,7 @@ elf_uncompress_lzma_block (const unsigned char 
*compressed,
   uint64_t header_compressed_size;
   uint64_t header_uncompressed_size;
   unsigned char lzma2_properties;
+  size_t crc_offset;
   uint32_t computed_crc;
   uint32_t stream_crc;
   size_t uncompressed_offset;
@@ -5671,19 +5672,20 @@ elf_uncompress_lzma_block (const unsigned char 
*compressed,
   /* The properties describe the dictionary size, but we don't care
  what that is.  */
 
-  /* Block header padding.  */
-  if (unlikely (off + 4 > compressed_size))
+  /* Skip to just before CRC, verifying zero bytes in between.  */
+  crc_offset = block_header_offset + block_header_size - 4;
+  if (unlikely (crc_offset + 4 > compressed_size))
 {
   elf_uncompress_failed ();
   return 0;
 }
-
-  off = (off + 3) &~ (size_t) 3;
-
-  if (unlikely (off + 4 > compressed_size))
+  for (; off < crc_offset; off++)
 {
-  elf_uncompress_failed ();
-  return 0;
+  if (compressed[off] != 0)
+   {
+ elf_uncompress_failed ();
+ return 0;
+   }
 }
 
   /* Block header CRC.  */


Re: libbacktrace patch committed: Read symbol table of debuginfo file

2024-03-01 Thread Ian Lance Taylor
On Thu, Feb 29, 2024 at 7:47 PM Ian Lance Taylor  wrote:
>
> This patch to libbacktrace reads symbol tables from debuginfo files.
> These become another symbol table to search.  This is needed if people
> use --strip-all rather than --strip-debug when adding a debuglink
> section.  This fixes
> https://github.com/ianlancetaylor/libbacktrace/issues/113.
> Bootstrapped and ran libbacktrace and libgo tests on
> x86_64-pc-linux-gnu.  Committed to mainline.

This introduced a bug on the PPC v1 ABI, where libbacktrace uses the
.opd section to convert from a function descriptor address to a code
address.  The .opd section is missing from a debuginfo file.  This
patch changes the code to use the original .opd section if it is
missing.  Checked on powerpc64-linux-gnu and x86_64-pc-linux-gnu.
Committed to mainline.

Ian

PR libbacktrace/114201
* elf.c (elf_add): Add caller_opd parameter.  Change all callers.
Release opd data after all recursive calls.
f692b338cd27a4e0d38fcb5af3d416cd66fbf814
diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index 664937e1438..f4527e2477d 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -6501,8 +6501,9 @@ backtrace_uncompress_lzma (struct backtrace_state *state,
 static int
 elf_add (struct backtrace_state *state, const char *filename, int descriptor,
 const unsigned char *memory, size_t memory_size,
-uintptr_t base_address, backtrace_error_callback error_callback,
-void *data, fileline *fileline_fn, int *found_sym, int *found_dwarf,
+uintptr_t base_address, struct elf_ppc64_opd_data *caller_opd,
+backtrace_error_callback error_callback, void *data,
+fileline *fileline_fn, int *found_sym, int *found_dwarf,
 struct dwarf_data **fileline_entry, int exe, int debuginfo,
 const char *with_buildid_data, uint32_t with_buildid_size)
 {
@@ -6557,6 +6558,7 @@ elf_add (struct backtrace_state *state, const char 
*filename, int descriptor,
   struct elf_view split_debug_view[DEBUG_MAX];
   unsigned char split_debug_view_valid[DEBUG_MAX];
   struct elf_ppc64_opd_data opd_data, *opd;
+  int opd_view_valid;
   struct dwarf_sections dwarf_sections;
 
   if (!debuginfo)
@@ -6584,6 +6586,7 @@ elf_add (struct backtrace_state *state, const char 
*filename, int descriptor,
   debug_view_valid = 0;
   memset (_debug_view_valid[0], 0, sizeof split_debug_view_valid);
   opd = NULL;
+  opd_view_valid = 0;
 
   if (!elf_get_view (state, descriptor, memory, memory_size, 0, sizeof ehdr,
 error_callback, data, _view))
@@ -6867,9 +6870,15 @@ elf_add (struct backtrace_state *state, const char 
*filename, int descriptor,
  opd->addr = shdr->sh_addr;
  opd->data = (const char *) opd_data.view.view.data;
  opd->size = shdr->sh_size;
+ opd_view_valid = 1;
}
 }
 
+  // A debuginfo file may not have a useful .opd section, but we can use the
+  // one from the original executable.
+  if (opd == NULL)
+opd = caller_opd;
+
   if (symtab_shndx == 0)
 symtab_shndx = dynsym_shndx;
   if (symtab_shndx != 0)
@@ -6948,9 +6957,9 @@ elf_add (struct backtrace_state *state, const char 
*filename, int descriptor,
elf_release_view (state, _view, error_callback, data);
  if (debugaltlink_view_valid)
elf_release_view (state, _view, error_callback, data);
- ret = elf_add (state, "", d, NULL, 0, base_address, error_callback,
-data, fileline_fn, found_sym, found_dwarf, NULL, 0,
-1, NULL, 0);
+ ret = elf_add (state, "", d, NULL, 0, base_address, opd,
+error_callback, data, fileline_fn, found_sym,
+found_dwarf, NULL, 0, 1, NULL, 0);
  if (ret < 0)
backtrace_close (d, error_callback, data);
  else if (descriptor >= 0)
@@ -6965,12 +6974,6 @@ elf_add (struct backtrace_state *state, const char 
*filename, int descriptor,
   buildid_view_valid = 0;
 }
 
-  if (opd)
-{
-  elf_release_view (state, >view, error_callback, data);
-  opd = NULL;
-}
-
   if (debuglink_name != NULL)
 {
   int d;
@@ -6985,9 +6988,9 @@ elf_add (struct backtrace_state *state, const char 
*filename, int descriptor,
  elf_release_view (state, _view, error_callback, data);
  if (debugaltlink_view_valid)
elf_release_view (state, _view, error_callback, data);
- ret = elf_add (state, "", d, NULL, 0, base_address, error_callback,
-data, fileline_fn, found_sym, found_dwarf, NULL, 0,
-1, NULL, 0);
+ ret = elf_add (state, "", d, NULL, 0, base_address, opd,
+error_callback, data, fileline_fn, found_sym,
+found_dwarf, NULL, 0, 1, NULL, 0);
  if (ret < 0)
backtrace_close (d, error

libbacktrace patch committed: Read symbol table of debuginfo file

2024-02-29 Thread Ian Lance Taylor
This patch to libbacktrace reads symbol tables from debuginfo files.
These become another symbol table to search.  This is needed if people
use --strip-all rather than --strip-debug when adding a debuglink
section.  This fixes
https://github.com/ianlancetaylor/libbacktrace/issues/113.
Bootstrapped and ran libbacktrace and libgo tests on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian

* elf.c (elf_add): Add the symbol table from a debuginfo file.
* Makefile.am (MAKETESTS): Add buildidfull and gnudebuglinkfull
variants of buildid and gnudebuglink tests.
(%_gnudebuglinkfull, %_buildidfull): New patterns.
* Makefile.in: Regenerate.
24810fbf7b0ce274dfa46cc362305ac77ee5a72c
diff --git a/libbacktrace/Makefile.am b/libbacktrace/Makefile.am
index 16a72d2abf7..750ed80ed05 100644
--- a/libbacktrace/Makefile.am
+++ b/libbacktrace/Makefile.am
@@ -257,7 +257,7 @@ b2test_LDFLAGS = -Wl,--build-id
 b2test_LDADD = libbacktrace_elf_for_test.la
 
 check_PROGRAMS += b2test
-MAKETESTS += b2test_buildid
+MAKETESTS += b2test_buildid b2test_buildidfull
 
 if HAVE_DWZ
 
@@ -267,7 +267,7 @@ b3test_LDFLAGS = -Wl,--build-id
 b3test_LDADD = libbacktrace_elf_for_test.la
 
 check_PROGRAMS += b3test
-MAKETESTS += b3test_dwz_buildid
+MAKETESTS += b3test_dwz_buildid b3test_dwz_buildidfull
 
 endif HAVE_DWZ
 
@@ -443,12 +443,16 @@ endif HAVE_PTHREAD
 
 if HAVE_OBJCOPY_DEBUGLINK
 
-MAKETESTS += btest_gnudebuglink
+MAKETESTS += btest_gnudebuglink btest_gnudebuglinkfull
 
 %_gnudebuglink: %
$(OBJCOPY) --only-keep-debug $< $@.debug
$(OBJCOPY) --strip-debug --add-gnu-debuglink=$@.debug $< $@
 
+%_gnudebuglinkfull: %
+   $(OBJCOPY) --only-keep-debug $< $@.debug
+   $(OBJCOPY) --strip-all --add-gnu-debuglink=$@.debug $< $@
+
 endif HAVE_OBJCOPY_DEBUGLINK
 
 %_buildid: %
@@ -457,6 +461,12 @@ endif HAVE_OBJCOPY_DEBUGLINK
  $<
$(OBJCOPY) --strip-debug $< $@
 
+%_buildidfull: %
+   ./install-debuginfo-for-buildid.sh \
+ "$(TEST_BUILD_ID_DIR)" \
+ $<
+   $(OBJCOPY) --strip-all $< $@
+
 if HAVE_COMPRESSED_DEBUG
 
 ctestg_SOURCES = btest.c testlib.c
diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index c506cc29fe1..664937e1438 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -6872,7 +6872,7 @@ elf_add (struct backtrace_state *state, const char 
*filename, int descriptor,
 
   if (symtab_shndx == 0)
 symtab_shndx = dynsym_shndx;
-  if (symtab_shndx != 0 && !debuginfo)
+  if (symtab_shndx != 0)
 {
   const b_elf_shdr *symtab_shdr;
   unsigned int strtab_shndx;


Re: [PATCH RFA] build: drop target libs from LD_LIBRARY_PATH [PR105688]

2024-02-07 Thread Ian Lance Taylor
On Tue, Feb 6, 2024 at 6:08 PM Jason Merrill  wrote:
>
> Tested x86_64-pc-linux-gnu.  Any thoughts?

It still makes sense to me, for what that's worth.

Ian


> -- 8< --
>
> The patch for PR22340 (r104978) moved the adding of TARGET_LIB_PATH to
> RPATH_ENVVAR from POSTSTAGE1_HOST_EXPORTS to HOST_EXPORTS, but didn't
> mention that in the ChangeLog; it also wasn't part of the patch that was
> sent to gcc-patches.  I suspect it was included accidentally?
>
> It also causes PR105688 when rebuilding stage1: once the stage1 libstdc++
> has been built, if calling the system gcc to build host code involves
> invoking any tool that links against libstdc++.so (gold, ccache) they get
> the just-built library instead of the system library they expect.
>
> Reverting that hunk of the change fixed my problem with bubblestrapping GCC
> 12 with ccache on a host with a newer system libstdc++.
>
> But I believe that adding TARGET_LIB_PATH to RPATH_ENVVAR is not needed for
> post-stage1 either, at this point.  Including TARGET_LIB_PATH goes back to
> r37545, with the stated rationale of getting other C++ library configury to
> succeed, but it looks to me like that is no longer necessary.
>
> So I propose to stop adding target libraries to LD_LIBRARY_PATH; see
> https://gcc.gnu.org/legacy-ml/gcc/2012-06/msg00325.html for a previous
> proposal by Ian to make this change.
>
> I have tried and failed to test this on a system without system libstdc++;
> bootstrap on cfarm220 and cfarm240 failed for unrelated reasons.
>
> PR bootstrap/105688
>
> ChangeLog:
>
> * Makefile.tpl (HOST_EXPORTS): Don't add TARGET_LIB_PATH to
> RPATH_ENVVAR.
> * Makefile.in: Regenerate.
> ---
>  Makefile.in  | 3 ---
>  Makefile.tpl | 3 ---
>  2 files changed, 6 deletions(-)
>
> diff --git a/Makefile.in b/Makefile.in
> index edb0c8a9a42..c2843d5df89 100644
> --- a/Makefile.in
> +++ b/Makefile.in
> @@ -242,9 +242,6 @@ HOST_EXPORTS = \
> ISLLIBS="$(HOST_ISLLIBS)"; export ISLLIBS; \
> ISLINC="$(HOST_ISLINC)"; export ISLINC; \
> XGCC_FLAGS_FOR_TARGET="$(XGCC_FLAGS_FOR_TARGET)"; export 
> XGCC_FLAGS_FOR_TARGET; \
> -@if gcc-bootstrap
> -   $(RPATH_ENVVAR)=`echo "$(TARGET_LIB_PATH)$$$(RPATH_ENVVAR)" | sed 
> 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR); \
> -@endif gcc-bootstrap
> $(RPATH_ENVVAR)=`echo "$(HOST_LIB_PATH)$$$(RPATH_ENVVAR)" | sed 
> 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR);
>
>  POSTSTAGE1_CXX_EXPORT = \
> diff --git a/Makefile.tpl b/Makefile.tpl
> index adbcbdd1d57..cb39fbd0434 100644
> --- a/Makefile.tpl
> +++ b/Makefile.tpl
> @@ -245,9 +245,6 @@ HOST_EXPORTS = \
> ISLLIBS="$(HOST_ISLLIBS)"; export ISLLIBS; \
> ISLINC="$(HOST_ISLINC)"; export ISLINC; \
> XGCC_FLAGS_FOR_TARGET="$(XGCC_FLAGS_FOR_TARGET)"; export 
> XGCC_FLAGS_FOR_TARGET; \
> -@if gcc-bootstrap
> -   $(RPATH_ENVVAR)=`echo "$(TARGET_LIB_PATH)$$$(RPATH_ENVVAR)" | sed 
> 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR); \
> -@endif gcc-bootstrap
> $(RPATH_ENVVAR)=`echo "$(HOST_LIB_PATH)$$$(RPATH_ENVVAR)" | sed 
> 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR);
>
>  POSTSTAGE1_CXX_EXPORT = \
>
> base-commit: c5d34912ad576be1ef19be92f7eabde54b9089eb
> --
> 2.43.0
>


libgo patch committed: Bump version number

2024-02-05 Thread Ian Lance Taylor
This libgo patch bumps the version number for the GCC 14 release.
This is for GCC PR 113668.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
7b0597eba6b29387b56b8d6a4b38f3586e6b49a5
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index ec7e2ab1acf..73cb095322c 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-1cb83a415e86ab4de0d436d277377d8fc060cb61
+e15a14e410b8fc5d28012d5b313cb6c8476c7df9
 
 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 22158ac7f5d..898091276f7 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=22:0:0
+libtool_VERSION=23:0:0
 AC_SUBST(libtool_VERSION)
 
 AM_ENABLE_MULTILIB(, ..)


Go frontend patch committed: print types in a more readable way

2024-02-05 Thread Ian Lance Taylor
This patch to the Go frontend adds Type::message_name to print types
in ways that makes sense to users.  As we move toward generics, the
error messages need to be able to refer to types in a readable manner.
Today we use this new feature in AST dumps.  Bootstrapped and ran Go
testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
3818237cd5111fdd089f9c9470d384eebbe6ee1e
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 429904a2b8f..ec7e2ab1acf 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-8c056e335cecec67d1d223a329b7ba4dac778a65
+1cb83a415e86ab4de0d436d277377d8fc060cb61
 
 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/ast-dump.cc b/gcc/go/gofrontend/ast-dump.cc
index eca0bf1fad2..12f49e68700 100644
--- a/gcc/go/gofrontend/ast-dump.cc
+++ b/gcc/go/gofrontend/ast-dump.cc
@@ -223,14 +223,7 @@ Ast_dump_context::dump_type(const Type* t)
   if (t == NULL)
 this->ostream() << "(nil type)";
   else
-// FIXME: write a type pretty printer instead of
-// using mangled names.
-if (this->gogo_ != NULL)
-  {
-   Backend_name bname;
-   t->backend_name(this->gogo_, );
-   this->ostream() << "(" << bname.name() << ")";
-  }
+this->ostream() << "(" << t->message_name() << ")";
 }
 
 // Dump a textual representation of a block to the
diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc
index b349ad10d6f..a39cfbf7679 100644
--- a/gcc/go/gofrontend/types.cc
+++ b/gcc/go/gofrontend/types.cc
@@ -270,6 +270,16 @@ Type::set_is_error()
   this->classification_ = TYPE_ERROR;
 }
 
+// Return a string version of this type to use in an error message.
+
+std::string
+Type::message_name() const
+{
+  std::string ret;
+  this->do_message_name();
+  return ret;
+}
+
 // If this is a pointer type, return the type to which it points.
 // Otherwise, return NULL.
 
@@ -742,16 +752,14 @@ Type::are_assignable(const Type* lhs, const Type* rhs, 
std::string* reason)
 {
   if (rhs->interface_type() != NULL)
reason->assign(_("need explicit conversion"));
-  else if (lhs_orig->named_type() != NULL
-  && rhs_orig->named_type() != NULL)
+  else
{
- size_t len = (lhs_orig->named_type()->name().length()
-   + rhs_orig->named_type()->name().length()
-   + 100);
+ const std::string& lhs_name(lhs_orig->message_name());
+ const std::string& rhs_name(rhs_orig->message_name());
+ size_t len = lhs_name.length() + rhs_name.length() + 100;
  char* buf = new char[len];
  snprintf(buf, len, _("cannot use type %s as type %s"),
-  rhs_orig->named_type()->message_name().c_str(),
-  lhs_orig->named_type()->message_name().c_str());
+  rhs_name.c_str(), lhs_name.c_str());
  reason->assign(buf);
  delete[] buf;
}
@@ -4244,6 +4252,33 @@ Integer_type::is_identical(const Integer_type* t) const
   return this->is_abstract_ == t->is_abstract_;
 }
 
+// Message name.
+
+void
+Integer_type::do_message_name(std::string* ret) const
+{
+  ret->append("is_byte_)
+ret->append("byte");
+  else if (this->is_rune_)
+ret->append("rune");
+  else
+{
+  if (this->is_unsigned_)
+   ret->push_back('u');
+  if (this->is_abstract_)
+   ret->append("int");
+  else
+   {
+ ret->append("int");
+ char buf[10];
+ snprintf(buf, sizeof buf, "%d", this->bits_);
+ ret->append(buf);
+   }
+}
+  ret->push_back('>');
+}
+
 // Hash code.
 
 unsigned int
@@ -4382,6 +4417,21 @@ Float_type::is_identical(const Float_type* t) const
   return this->is_abstract_ == t->is_abstract_;
 }
 
+// Message name.
+
+void
+Float_type::do_message_name(std::string* ret) const
+{
+  ret->append("is_abstract_)
+{
+  char buf[10];
+  snprintf(buf, sizeof buf, "%d", this->bits_);
+  ret->append(buf);
+}
+  ret->push_back('>');
+}
+
 // Hash code.
 
 unsigned int
@@ -4496,6 +4546,21 @@ Complex_type::is_identical(const Complex_type *t) const
   return this->is_abstract_ == t->is_abstract_;
 }
 
+// Message name.
+
+void
+Complex_type::do_message_name(std::string* ret) const
+{
+  ret->append("is_abstract_)
+{
+  char buf[10];
+  snprintf(buf, sizeof buf, "%d", this->bits_);
+  ret->append(buf);
+}
+  ret->push_back('>');
+}
+
 // Hash code.
 
 unsigned int
@@ -4661,6 +4726,10 @@ class Sink_type : public Type
   { }
 
  protected:
+  void
+  do_message_name(std::string* ret) const
+  { ret->append(""); }
+
   bool
   do_compare_is_identity(Gogo*)
   { return false; }
@@ -4696,6 +4765,70 @@ Type::make_sink_type()
 
 // Class Function_type.
 
+// Message name.
+
+void
+Function_type::do_message_name(std::string* ret) const
+{
+  ret->append("func");
+  if (this->receiver_ != NULL)
+{
+  

libgo patch committed: Better error messages for unsupported target

2024-02-02 Thread Ian Lance Taylor
This libgo patch generates better error messages then the Go GOARCH
and GOOS values can't be determined from the target.  This indicates
that the target is not supported.  This is for GCC PR 113530.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
cfc6d9ae8143cf0e903384bc63e8d659ca1c9fe7
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 18281c6cd1e..429904a2b8f 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-7ab229670f7dad1d79f33929f9a4f8e6e4a71526
+8c056e335cecec67d1d223a329b7ba4dac778a65
 
 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 c95dc2106cd..3eccadbac67 100644
--- a/libgo/Makefile.am
+++ b/libgo/Makefile.am
@@ -497,6 +497,10 @@ s-version: Makefile
 zgoarch.go: s-zgoarch; @true
 s-zgoarch: Makefile goarch.sh
rm -f zgoarch.go.tmp
+   if ! $(SHELL) $(srcdir)/goarch.sh $(GOARCH) family >/dev/null 
2>/dev/null;  then \
+ $(SHELL) $(srcdir)/goarch.sh $(GOARCH) family; \
+ exit 1; \
+   fi
echo "package goarch" > zgoarch.go.tmp
echo >> zgoarch.go.tmp
echo 'const GOARCH = "'$(GOARCH)'"' >> zgoarch.go.tmp
diff --git a/libgo/configure.ac b/libgo/configure.ac
index e8d66f8415d..22158ac7f5d 100644
--- a/libgo/configure.ac
+++ b/libgo/configure.ac
@@ -209,6 +209,10 @@ AM_CONDITIONAL(LIBGO_IS_BSD, test $is_darwin = yes -o 
$is_dragonfly = yes -o $is
 AC_SUBST(GOOS)
 AC_SUBST(ALLGOOS)
 
+if test "${GOOS}" = "unknown"; then
+   AC_MSG_ERROR("could not determine GOOS from ${host}")
+fi
+
 dnl Test whether we need to use DejaGNU or whether we can use the
 dnl simpler gotest approach.  We can only use gotest for a native
 dnl build.
@@ -376,6 +380,10 @@ AC_SUBST(GOARCH)
 AC_SUBST(ALLGOARCH)
 AC_SUBST(ALLGOARCHFAMILY)
 
+if test "${GOARCH}" = "unknown"; then
+   AC_MSG_ERROR("could not determine GOARCH from ${host}")
+fi
+
 AM_CONDITIONAL(LIBGO_IS_X86, test "$GOARCH" = "386" -o "$GOARCH" = "amd64" -o 
"$GOARCH" = "amd64p32")
 
 FUNCTION_DESCRIPTORS=false


Go patch committed: Export the type "any" as a builtin

2024-02-02 Thread Ian Lance Taylor
This patch to the Go frontend exports the type "any" as a builtin.
Otherwise we can't tell the difference between builtin type "any" and
a locally defined type "any".

This will require updates to the gccgo export data parsers in the main
Go repo and the x/tools repo.  These updates are https://go.dev/cl/537195
and https://go.dev/cl/537215.

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

Ian
e52d31804a910642c9817bdd400c290a593c98ef
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index c2a6032ae80..18281c6cd1e 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-ddf3758e4a45ca2816fb68f3e4224501a3c4c438
+7ab229670f7dad1d79f33929f9a4f8e6e4a71526
 
 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 7373deee310..40f6d5d4b2f 100644
--- a/gcc/go/gofrontend/export.cc
+++ b/gcc/go/gofrontend/export.cc
@@ -1661,6 +1661,7 @@ Export::register_builtin_types(Gogo* gogo)
   this->register_builtin_type(gogo, "error", BUILTIN_ERROR);
   this->register_builtin_type(gogo, "byte", BUILTIN_BYTE);
   this->register_builtin_type(gogo, "rune", BUILTIN_RUNE);
+  this->register_builtin_type(gogo, "any", BUILTIN_ANY);
 }
 
 // Register one builtin type in the export table.
diff --git a/gcc/go/gofrontend/export.h b/gcc/go/gofrontend/export.h
index 1f613434cab..be117ece2ce 100644
--- a/gcc/go/gofrontend/export.h
+++ b/gcc/go/gofrontend/export.h
@@ -51,8 +51,9 @@ enum Builtin_code
   BUILTIN_ERROR = -19,
   BUILTIN_BYTE = -20,
   BUILTIN_RUNE = -21,
+  BUILTIN_ANY = -22,
 
-  SMALLEST_BUILTIN_CODE = -21
+  SMALLEST_BUILTIN_CODE = -22
 };
 
 // Export data version number. New export data is written with the
diff --git a/gcc/go/gofrontend/import.cc b/gcc/go/gofrontend/import.cc
index 21691fa5ff4..3cc8a720ee4 100644
--- a/gcc/go/gofrontend/import.cc
+++ b/gcc/go/gofrontend/import.cc
@@ -1408,6 +1408,7 @@ Import::register_builtin_types(Gogo* gogo)
   this->register_builtin_type(gogo, "error", BUILTIN_ERROR);
   this->register_builtin_type(gogo, "byte", BUILTIN_BYTE);
   this->register_builtin_type(gogo, "rune", BUILTIN_RUNE);
+  this->register_builtin_type(gogo, "any", BUILTIN_ANY);
 }
 
 // Register a single builtin type.
diff --git a/libgo/go/go/internal/gccgoimporter/parser.go 
b/libgo/go/go/internal/gccgoimporter/parser.go
index 48335fa6d8f..2161df7f368 100644
--- a/libgo/go/go/internal/gccgoimporter/parser.go
+++ b/libgo/go/go/internal/gccgoimporter/parser.go
@@ -187,7 +187,6 @@ func (p *parser) parseQualifiedNameStr(unquotedName string) 
(pkgpath, name strin
 // getPkg returns the package for a given path. If the package is
 // not found but we have a package name, create the package and
 // add it to the p.imports map.
-//
 func (p *parser) getPkg(pkgpath, name string) *types.Package {
// package unsafe is not in the imports map - handle explicitly
if pkgpath == "unsafe" {
@@ -904,6 +903,7 @@ const (
gccgoBuiltinERROR  = 19
gccgoBuiltinBYTE   = 20
gccgoBuiltinRUNE   = 21
+   gccgoBuiltinANY= 22
 )
 
 func lookupBuiltinType(typ int) types.Type {
@@ -928,13 +928,13 @@ func lookupBuiltinType(typ int) types.Type {
gccgoBuiltinERROR:  types.Universe.Lookup("error").Type(),
gccgoBuiltinBYTE:   types.Universe.Lookup("byte").Type(),
gccgoBuiltinRUNE:   types.Universe.Lookup("rune").Type(),
+   gccgoBuiltinANY:types.Universe.Lookup("any").Type(),
}[typ]
 }
 
 // Type = "<" "type" ( "-" int | int [ TypeSpec ] ) ">" .
 //
 // parseType updates the type map to t for all type numbers n.
-//
 func (p *parser) parseType(pkg *types.Package, n ...any) types.Type {
p.expect('<')
t, _ := p.parseTypeAfterAngle(pkg, n...)
@@ -1117,9 +1117,10 @@ func (p *parser) maybeCreatePackage() {
 }
 
 // InitDataDirective = ( "v1" | "v2" | "v3" ) ";" |
-// "priority" int ";" |
-// "init" { PackageInit } ";" |
-// "checksum" unquotedString ";" .
+//
+// "priority" int ";" |
+// "init" { PackageInit } ";" |
+// "checksum" unquotedString ";" .
 func (p *parser) parseInitDataDirective() {
if p.tok != scanner.Ident {
// unexpected token kind; panic
@@ -1170,15 +1171,16 @@ func (p *parser) parseInitDataDirective() {
 }
 
 // Directive = InitDataDirective |
-// "package" unquotedString [ unquotedString ] [ unquotedString ] 
";" |
-// "pkgpath" unquotedString ";" |
-// "prefix" unquotedString ";" |
-// "import" unquotedString unquotedString string ";" |
-// "indirectimport" unquotedString unquotedstring ";" |
-// "func" Func ";" |
-// "type" Type ";" |
-// "var" Var ";" |
-// "const" 

Re: [PATCH 5/4] libbacktrace: improve getting debug information for loaded dlls

2024-01-25 Thread Ian Lance Taylor
On Thu, Jan 25, 2024 at 11:53 AM Björn Schäpers  wrote:
>
> Am 23.01.2024 um 23:37 schrieb Ian Lance Taylor:
> > On Thu, Jan 4, 2024 at 2:33 PM Björn Schäpers  wrote:
> >>
> >> Am 03.01.2024 um 00:12 schrieb Björn Schäpers:
> >>> Am 30.11.2023 um 20:53 schrieb Ian Lance Taylor:
> >>>> On Fri, Jan 20, 2023 at 2:55 AM Björn Schäpers  wrote:
> >>>>>
> >>>>> From: Björn Schäpers 
> >>>>>
> >>>>> Fixes https://github.com/ianlancetaylor/libbacktrace/issues/53, except
> >>>>> that libraries loaded after the backtrace_initialize are not handled.
> >>>>> But as far as I can see that's the same for elf.
> >>>>
> >>>> Thanks, but I don't want a patch that loops using goto statements.
> >>>> Please rewrite to avoid that.  It may be simpler to call a function.
> >>>>
> >>>> Also starting with a module count of 1000 seems like a lot.  Do
> >>>> typical Windows programs load that many modules?
> >>>>
> >>>> Ian
> >>>>
> >>>>
> >>>
> >>> Rewritten using a function.
> >>>
> >>> If that is commited, could you attribute that commit to me 
> >>> (--author="Björn
> >>> Schäpers ")?
> >>>
> >>> Thanks and kind regards,
> >>> Björn.
> >>
> >> I noticed that under 64 bit libraries loaded with LoadLibrary were missing.
> >> EnumProcessModules stated the correct number of modules, but did not fill 
> >> the
> >> the HMODULEs, but set them to 0. While trying to investigate I noticed if 
> >> I do
> >> the very same thing from main (in C++) I even got fewer module HMODULEs.
> >>
> >> So I went a different way. This detects all libraries correctly, in 32 and 
> >> 64
> >> bit. The question is, if it should be a patch on top of the previous, or 
> >> should
> >> they be merged, or even only this solution and drop the EnumProcessModules 
> >> variant?
> >
> > Is there any reason to use both patches?  Seems simpler to just use
> > this one if it works.  Thanks.
> >
> > Ian
>
> This one needs the tlhelp32 header and its functions, which are (accoridng to
> the microsoft documentation) are only available since Windows XP rsp. Windows
> Server 2003.
>
> If that's no problem, and in my opinion it shouldn't be, then I can basically
> drop patch 4 and rebase this one.

I don't see that as a problem.  It seems like the patch will fall back
cleanly on ancient Windows and simply fail to pick up other loaded
DLLs.  I think that is fine.  I'll look for an updated patch.  Thanks.

Ian


Re: [PATCH 5/4] libbacktrace: improve getting debug information for loaded dlls

2024-01-23 Thread Ian Lance Taylor
On Thu, Jan 4, 2024 at 2:33 PM Björn Schäpers  wrote:
>
> Am 03.01.2024 um 00:12 schrieb Björn Schäpers:
> > Am 30.11.2023 um 20:53 schrieb Ian Lance Taylor:
> >> On Fri, Jan 20, 2023 at 2:55 AM Björn Schäpers  wrote:
> >>>
> >>> From: Björn Schäpers 
> >>>
> >>> Fixes https://github.com/ianlancetaylor/libbacktrace/issues/53, except
> >>> that libraries loaded after the backtrace_initialize are not handled.
> >>> But as far as I can see that's the same for elf.
> >>
> >> Thanks, but I don't want a patch that loops using goto statements.
> >> Please rewrite to avoid that.  It may be simpler to call a function.
> >>
> >> Also starting with a module count of 1000 seems like a lot.  Do
> >> typical Windows programs load that many modules?
> >>
> >> Ian
> >>
> >>
> >
> > Rewritten using a function.
> >
> > If that is commited, could you attribute that commit to me (--author="Björn
> > Schäpers ")?
> >
> > Thanks and kind regards,
> > Björn.
>
> I noticed that under 64 bit libraries loaded with LoadLibrary were missing.
> EnumProcessModules stated the correct number of modules, but did not fill the
> the HMODULEs, but set them to 0. While trying to investigate I noticed if I do
> the very same thing from main (in C++) I even got fewer module HMODULEs.
>
> So I went a different way. This detects all libraries correctly, in 32 and 64
> bit. The question is, if it should be a patch on top of the previous, or 
> should
> they be merged, or even only this solution and drop the EnumProcessModules 
> variant?

Is there any reason to use both patches?  Seems simpler to just use
this one if it works.  Thanks.

Ian


Go patch committed: Don't pass iota value to lowering pass

2024-01-22 Thread Ian Lance Taylor
This patch to the Go frontend stops passing the iota value to the
lowering pass.  It is no longer used.  The iota value is now handled
in the determine-types pass.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
896148947b9ff4845c8bc334f8eff30f91ff3c9a
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index b41ac99f7a8..c2a6032ae80 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-61b29a99dadf33c48a0a063f50f61e877fb419b8
+ddf3758e4a45ca2816fb68f3e4224501a3c4c438
 
 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 a09d33b868e..51ff0206129 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -1007,7 +1007,7 @@ Expression::make_type(Type* type, Location location)
 
 Expression*
 Var_expression::do_lower(Gogo* gogo, Named_object* function,
-Statement_inserter* inserter, int)
+Statement_inserter* inserter)
 {
   if (this->variable_->is_variable())
 {
@@ -1158,7 +1158,7 @@ Enclosed_var_expression::do_traverse(Traverse*)
 
 Expression*
 Enclosed_var_expression::do_lower(Gogo* gogo, Named_object* function,
- Statement_inserter* inserter, int)
+ Statement_inserter* inserter)
 {
   gogo->lower_expression(function, inserter, >reference_);
   return this;
@@ -2097,7 +2097,7 @@ Unknown_expression::do_is_addressable() const
 // Lower a reference to an unknown name.
 
 Expression*
-Unknown_expression::do_lower(Gogo*, Named_object*, Statement_inserter*, int)
+Unknown_expression::do_lower(Gogo*, Named_object*, Statement_inserter*)
 {
   if (this->is_error_expression())
 return Expression::make_error(this->location());
@@ -3642,7 +3642,7 @@ Const_expression::do_is_zero_value() const
 // predeclared constant iota into an integer value.
 
 Expression*
-Const_expression::do_lower(Gogo* gogo, Named_object*, Statement_inserter*, int)
+Const_expression::do_lower(Gogo* gogo, Named_object*, Statement_inserter*)
 {
   Location loc = this->location();
 
@@ -4120,7 +4120,7 @@ class Iota_expression : public Parser_expression
   { }
 
   Expression*
-  do_lower(Gogo*, Named_object*, Statement_inserter*, int)
+  do_lower(Gogo*, Named_object*, Statement_inserter*)
   { go_unreachable(); }
 
   // There should only ever be one of these.
@@ -4171,7 +4171,7 @@ Type_conversion_expression::do_type()
 
 Expression*
 Type_conversion_expression::do_lower(Gogo* gogo, Named_object*,
-Statement_inserter* inserter, int)
+Statement_inserter* inserter)
 {
   Type* type = this->type_;
   Expression* val = this->expr_;
@@ -4997,7 +4997,7 @@ Unary_expression::check_operand_address_taken(Gogo*)
 // instead.
 
 Expression*
-Unary_expression::do_lower(Gogo* gogo, Named_object*, Statement_inserter*, int)
+Unary_expression::do_lower(Gogo* gogo, Named_object*, Statement_inserter*)
 {
   Location loc = this->location();
 
@@ -6677,7 +6677,7 @@ Binary_expression::eval_complex(Operator op, const 
Numeric_constant* left_nc,
 
 Expression*
 Binary_expression::do_lower(Gogo* gogo, Named_object*,
-   Statement_inserter* inserter, int)
+   Statement_inserter* inserter)
 {
   Location location = this->location();
 
@@ -8955,7 +8955,7 @@ class Selector_expression : public Parser_expression
   do_issue_nil_check();
 
   Expression*
-  do_lower(Gogo*, Named_object*, Statement_inserter*, int);
+  do_lower(Gogo*, Named_object*, Statement_inserter*);
 
   Expression*
   do_copy()
@@ -9030,7 +9030,7 @@ Selector_expression::do_issue_nil_check()
 // Lower a selector expression to the resolved value.
 
 Expression*
-Selector_expression::do_lower(Gogo*, Named_object*, Statement_inserter*, int)
+Selector_expression::do_lower(Gogo*, Named_object*, Statement_inserter*)
 {
   if (this->is_error_expression() || this->resolved_ == NULL)
 return Expression::make_error(this->location());
@@ -9360,7 +9360,7 @@ Builtin_call_expression::do_set_recover_arg(Expression* 
arg)
 
 Expression*
 Builtin_call_expression::do_lower(Gogo* gogo, Named_object* function,
- Statement_inserter* inserter, int)
+ Statement_inserter* inserter)
 {
   if (this->is_error_expression())
 return this;
@@ -12564,7 +12564,7 @@ Call_expression::do_discarding_value()
 
 Expression*
 Call_expression::do_lower(Gogo* gogo, Named_object*,
- Statement_inserter* inserter, int)
+ Statement_inserter* inserter)
 {
   if (this->lowered_ != NULL)
 return this->lowered_;
@@ -14836,7 +14836,7 @@ Index_expression::do_issue_nil_check()
 // expression into an array index, a string index, or a map index.
 
 

Re: Go patch committed: Move lowering pass after check types pass

2024-01-18 Thread Ian Lance Taylor
On Mon, Dec 18, 2023 at 5:32 PM Ian Lance Taylor  wrote:
>
> This Go frontend patch moves the lowering pass after the type
> determination and the type checking passes.  This lets us simplify
> some of the code that determines the type of an expression, which
> previously had to work correctly both before and after type
> determination.
>
> I'm doing this to help with future generic support.  For example, with
> generics, we can see code like
>
> func ident[T any](v T) T { return v }
>
> func F() int32 {
> s := int32(1)
> return ident(s)
> }
>
> Before this change, we would type check return statements in the
> lowering pass (see Return_statement::do_lower).  With a generic
> example like the above, that means we have to determine the type of s,
> and use that to infer the type arguments passed to ident, and use that
> to determine the result type of ident.  That is too much to do at
> lowering time.  Of course we can change the way that return statements
> work, but similar issues arise with index expressions, the types of
> closures for function literals, and probably other cases as well.
>
> Rather than try to deal with all those cases, we move the lowering
> pass after type checking.  This requires a bunch of changes, notably
> for determining constant types.  We have to add type checking for
> various constructs that formerly disappeared in the lowering pass. So
> it's a lot of shuffling.  Sorry for the size of the patch.
>
> Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
> to mainline.

Sorry, I forgot to commit the changes to some of the test files.  I've
committed this patch to fix them.  This fixes PR 113447.

Ian
3d7820c58f9466a80916dfa50dcdfde457b4c597
diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue20185.go 
b/gcc/testsuite/go.test/test/fixedbugs/issue20185.go
index 9065868d7f2..24d74f09126 100644
--- a/gcc/testsuite/go.test/test/fixedbugs/issue20185.go
+++ b/gcc/testsuite/go.test/test/fixedbugs/issue20185.go
@@ -10,7 +10,7 @@
 package p
 
 func F() {
-   switch t := nil.(type) { // ERROR "cannot type switch on non-interface 
value"
+   switch t := nil.(type) { // ERROR "cannot type switch on non-interface 
value|defined to nil type"
default:
_ = t
}
diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue33386.go 
b/gcc/testsuite/go.test/test/fixedbugs/issue33386.go
index 7b2f565285e..c5073910a4c 100644
--- a/gcc/testsuite/go.test/test/fixedbugs/issue33386.go
+++ b/gcc/testsuite/go.test/test/fixedbugs/issue33386.go
@@ -18,7 +18,7 @@ func _() {
 
 func _() {
defer func() { // no error here about deferred function
-   1 +// GCCGO_ERROR "value computed is not used"
+   1 +
}()// ERROR "expecting expression|expected operand"
 }
 
diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue4085a.go 
b/gcc/testsuite/go.test/test/fixedbugs/issue4085a.go
index 200290a081d..f457fcf2b12 100644
--- a/gcc/testsuite/go.test/test/fixedbugs/issue4085a.go
+++ b/gcc/testsuite/go.test/test/fixedbugs/issue4085a.go
@@ -10,9 +10,9 @@ type T []int
 
 func main() {
_ = make(T, -1)// ERROR "negative"
-   _ = make(T, 0.5)   // ERROR "constant 0.5 truncated to 
integer|non-integer len argument"
+   _ = make(T, 0.5)   // ERROR "truncated to integer|non-integer len 
argument"
_ = make(T, 1.0)   // ok
-   _ = make(T, 1<<63) // ERROR "len argument too large"
+   _ = make(T, 1<<63) // ERROR "integer constant overflow|len argument too 
large"
_ = make(T, 0, -1) // ERROR "negative cap"
_ = make(T, 10, 0) // ERROR "len larger than cap"
 }
diff --git a/gcc/testsuite/go.test/test/shift1.go 
b/gcc/testsuite/go.test/test/shift1.go
index d6a6c38839f..3b1aa9e6900 100644
--- a/gcc/testsuite/go.test/test/shift1.go
+++ b/gcc/testsuite/go.test/test/shift1.go
@@ -189,12 +189,12 @@ func _() {
var m1 map[int]string
delete(m1, 1<

Go patch committed: Move lowering pass after check types pass

2023-12-18 Thread Ian Lance Taylor
This Go frontend patch moves the lowering pass after the type
determination and the type checking passes.  This lets us simplify
some of the code that determines the type of an expression, which
previously had to work correctly both before and after type
determination.

I'm doing this to help with future generic support.  For example, with
generics, we can see code like

func ident[T any](v T) T { return v }

func F() int32 {
s := int32(1)
return ident(s)
}

Before this change, we would type check return statements in the
lowering pass (see Return_statement::do_lower).  With a generic
example like the above, that means we have to determine the type of s,
and use that to infer the type arguments passed to ident, and use that
to determine the result type of ident.  That is too much to do at
lowering time.  Of course we can change the way that return statements
work, but similar issues arise with index expressions, the types of
closures for function literals, and probably other cases as well.

Rather than try to deal with all those cases, we move the lowering
pass after type checking.  This requires a bunch of changes, notably
for determining constant types.  We have to add type checking for
various constructs that formerly disappeared in the lowering pass. So
it's a lot of shuffling.  Sorry for the size of the patch.

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

Ian


patch.txt.bz2
Description: application/bzip


Re: [PATCH] libiberty: Fix build with GCC < 7

2023-12-05 Thread Ian Lance Taylor
On Tue, Dec 5, 2023 at 2:06 PM Jakub Jelinek  wrote:
>
> Ok for trunk (both gcc and binutils)?
>
> 2023-12-05  Jakub Jelinek  
>
> * configure.ac (HAVE_X86_SHA1_HW_SUPPORT): Verify __get_cpuid and
> __get_cpuid_count are not implicitly declared.
> * configure: Regenerated.

This is fine.  Thanks.

Ian


Re: Darwin: Replace environment runpath with embedded [PR88590]

2023-11-30 Thread Ian Lance Taylor
On Thu, Nov 30, 2023 at 11:58 AM Ian Lance Taylor  wrote:
>
> On Thu, Nov 30, 2023 at 11:56 AM Iain Sandoe  wrote:
> >
> > > On 30 Nov 2023, at 19:43, Ian Lance Taylor  wrote:
> > >
> > > On Sun, Oct 22, 2023 at 2:18 PM FX Coudert  wrote:
> > >>
> > >> Thanks a lot Alexandre for the review!
> > >
> > > This patch changed the files lingo/configure.ac and libgo/configure.
> > > Those files live in an upstream repository and should be changed there
> > > and then merged into the GCC repo, as described in libgo/README.gcc.
> > > This is not a big deal, and I can take care of changing the upstream
> > > repository.  But I don't understand the changes in libgo.  As far as I
> > > can tell, all they do is add an automake conditional that is never
> > > used.  Is there any reason for that?
> >
> > It’s not used (yet) because we do not build libgo on Darwin, if/when we
> > do it would be used in the same way as for the other runtimes.
> >
> > >  Should I just revert the changes to libgo?
> >
> > That is also fine (because we do not yet build it on Darwin), it seems 
> > unlikely
> > we’d forget to re-add it.
>
> Thanks, I'll make the change upstream.

Now done.

Ian


Re: [PATCH] libgo, libstdc++: Regenerate GCC_CHECK_ASSEMBLER_HWCAP users

2023-11-30 Thread Ian Lance Taylor
On Thu, Nov 30, 2023 at 11:46 AM Ian Lance Taylor  wrote:
>
> On Thu, Nov 30, 2023 at 1:30 AM Rainer Orth  
> wrote:
> >
> > the gcc-autoregen bot correctly complained that the libgo and libstdc++
> > configure scripts hadn't been regenerated.  I'd have commited the
> > following as obvious (just whitespace change), but since libgo is
> > imported from upstream, I'm uncertain how best to handle that part.
>
> I can update libgo/configure upstream, but first I'd like to
> understand the change in git revision
> 6a6d3817afa02bbcd2388c8e005da6faf88932f1, which seems unnecessary.
> Asked in https://gcc.gnu.org/pipermail/gcc-patches/2023-November/638814.html.

OK, fixed now in the GCC repo.

Ian


Re: Darwin: Replace environment runpath with embedded [PR88590]

2023-11-30 Thread Ian Lance Taylor
On Thu, Nov 30, 2023 at 11:56 AM Iain Sandoe  wrote:
>
> > On 30 Nov 2023, at 19:43, Ian Lance Taylor  wrote:
> >
> > On Sun, Oct 22, 2023 at 2:18 PM FX Coudert  wrote:
> >>
> >> Thanks a lot Alexandre for the review!
> >
> > This patch changed the files lingo/configure.ac and libgo/configure.
> > Those files live in an upstream repository and should be changed there
> > and then merged into the GCC repo, as described in libgo/README.gcc.
> > This is not a big deal, and I can take care of changing the upstream
> > repository.  But I don't understand the changes in libgo.  As far as I
> > can tell, all they do is add an automake conditional that is never
> > used.  Is there any reason for that?
>
> It’s not used (yet) because we do not build libgo on Darwin, if/when we
> do it would be used in the same way as for the other runtimes.
>
> >  Should I just revert the changes to libgo?
>
> That is also fine (because we do not yet build it on Darwin), it seems 
> unlikely
> we’d forget to re-add it.

Thanks, I'll make the change upstream.

Ian


Re: [PATCH 4/4] libbacktrace: get debug information for loaded dlls

2023-11-30 Thread Ian Lance Taylor
On Fri, Jan 20, 2023 at 2:55 AM Björn Schäpers  wrote:
>
> From: Björn Schäpers 
>
> Fixes https://github.com/ianlancetaylor/libbacktrace/issues/53, except
> that libraries loaded after the backtrace_initialize are not handled.
> But as far as I can see that's the same for elf.

Thanks, but I don't want a patch that loops using goto statements.
Please rewrite to avoid that.  It may be simpler to call a function.

Also starting with a module count of 1000 seems like a lot.  Do
typical Windows programs load that many modules?

Ian




> Tested on x86_64-linux and i686-w64-mingw32.
>
> -- >8 --
>
> * pecoff.c (coff_add): New argument for the module handle of the
> file, to get the base address.
> * pecoff.c (backtrace_initialize): Iterate over loaded libraries
> and call coff_add.
>
> Signed-off-by: Björn Schäpers 
> ---
>  libbacktrace/pecoff.c | 76 ---
>  1 file changed, 72 insertions(+), 4 deletions(-)
>
> diff --git a/libbacktrace/pecoff.c b/libbacktrace/pecoff.c
> index 296f1357b5f..40395109e51 100644
> --- a/libbacktrace/pecoff.c
> +++ b/libbacktrace/pecoff.c
> @@ -49,6 +49,7 @@ POSSIBILITY OF SUCH DAMAGE.  */
>  #endif
>
>  #include 
> +#include 
>  #endif
>
>  /* Coff file header.  */
> @@ -592,7 +593,8 @@ coff_syminfo (struct backtrace_state *state, uintptr_t 
> addr,
>  static int
>  coff_add (struct backtrace_state *state, int descriptor,
>   backtrace_error_callback error_callback, void *data,
> - fileline *fileline_fn, int *found_sym, int *found_dwarf)
> + fileline *fileline_fn, int *found_sym, int *found_dwarf,
> + uintptr_t module_handle ATTRIBUTE_UNUSED)
>  {
>struct backtrace_view fhdr_view;
>off_t fhdr_off;
> @@ -623,7 +625,6 @@ coff_add (struct backtrace_state *state, int descriptor,
>int is_64;
>uintptr_t image_base;
>uintptr_t base_address = 0;
> -  uintptr_t module_handle;
>struct dwarf_sections dwarf_sections;
>
>*found_sym = 0;
> @@ -871,7 +872,6 @@ coff_add (struct backtrace_state *state, int descriptor,
>  }
>
>  #ifdef HAVE_WINDOWS_H
> -module_handle = (uintptr_t) GetModuleHandleW (NULL);
>  base_address = module_handle - image_base;
>  #endif
>
> @@ -914,12 +914,80 @@ backtrace_initialize (struct backtrace_state *state,
>int found_sym;
>int found_dwarf;
>fileline coff_fileline_fn;
> +  uintptr_t module_handle = 0;
> +
> +#ifdef HAVE_WINDOWS_H
> +  DWORD i;
> +  DWORD module_count;
> +  DWORD bytes_needed_for_modules;
> +  HMODULE *modules;
> +  char module_name[MAX_PATH];
> +  int module_found_sym;
> +  fileline module_fileline_fn;
> +
> +  module_handle = (uintptr_t) GetModuleHandleW (NULL);
> +#endif
>
>ret = coff_add (state, descriptor, error_callback, data,
> - _fileline_fn, _sym, _dwarf);
> + _fileline_fn, _sym, _dwarf, module_handle);
>if (!ret)
>  return 0;
>
> +#ifdef HAVE_WINDOWS_H
> +  module_count = 1000;
> + alloc_modules:
> +  modules = backtrace_alloc (state, module_count * sizeof(HMODULE),
> +error_callback, data);
> +  if (modules == NULL)
> +goto skip_modules;
> +  if (!EnumProcessModules (GetCurrentProcess (), modules, module_count,
> +  _needed_for_modules))
> +{
> +  error_callback(data, "Could not enumerate process modules",
> +(int) GetLastError ());
> +  goto free_modules;
> +}
> +  if (bytes_needed_for_modules > module_count * sizeof(HMODULE))
> +{
> +  backtrace_free (state, modules, module_count * sizeof(HMODULE),
> + error_callback, data);
> +  // Add an extra of 2, if some module is loaded in another thread.
> +  module_count = bytes_needed_for_modules / sizeof(HMODULE) + 2;
> +  modules = NULL;
> +  goto alloc_modules;
> +}
> +
> +  for (i = 0; i < bytes_needed_for_modules / sizeof(HMODULE); ++i)
> +{
> +  if (GetModuleFileNameA (modules[i], module_name, MAX_PATH - 1))
> +   {
> + if (strcmp (filename, module_name) == 0)
> +   continue;
> +
> + module_handle = (uintptr_t) GetModuleHandleA (module_name);
> + if (module_handle == 0)
> +   continue;
> +
> + descriptor = backtrace_open (module_name, error_callback, data, 
> NULL);
> + if (descriptor < 0)
> +   continue;
> +
> + coff_add (state, descriptor, error_callback, data,
> +   _fileline_fn, _found_sym, _dwarf,
> +   module_handle);
> + if (module_found_sym)
> +   found_sym = 1;
> +   }
> +}
> +
> + free_modules:
> +  if (modules)
> +backtrace_free(state, modules, module_count * sizeof(HMODULE),
> +  error_callback, data);
> +  modules = NULL;
> + skip_modules:
> +#endif
> +
>if (!state->threaded)
>  {
>if (found_sym)
> --
> 2.38.1
>


Re: [PATCH] libgo, libstdc++: Regenerate GCC_CHECK_ASSEMBLER_HWCAP users

2023-11-30 Thread Ian Lance Taylor
On Thu, Nov 30, 2023 at 1:30 AM Rainer Orth  
wrote:
>
> the gcc-autoregen bot correctly complained that the libgo and libstdc++
> configure scripts hadn't been regenerated.  I'd have commited the
> following as obvious (just whitespace change), but since libgo is
> imported from upstream, I'm uncertain how best to handle that part.

I can update libgo/configure upstream, but first I'd like to
understand the change in git revision
6a6d3817afa02bbcd2388c8e005da6faf88932f1, which seems unnecessary.
Asked in https://gcc.gnu.org/pipermail/gcc-patches/2023-November/638814.html.

Ian


Re: Darwin: Replace environment runpath with embedded [PR88590]

2023-11-30 Thread Ian Lance Taylor
On Sun, Oct 22, 2023 at 2:18 PM FX Coudert  wrote:
>
> Thanks a lot Alexandre for the review!

This patch changed the files lingo/configure.ac and libgo/configure.
Those files live in an upstream repository and should be changed there
and then merged into the GCC repo, as described in libgo/README.gcc.
This is not a big deal, and I can take care of changing the upstream
repository.  But I don't understand the changes in libgo.  As far as I
can tell, all they do is add an automake conditional that is never
used.  Is there any reason for that?  Should I just revert the changes
to libgo?

To be clear, I am asking about this change in git revision
6a6d3817afa02bbcd2388c8e005da6faf88932f1 and the corresponding change
in the generated file libgo/configure.ac.  Thanks.

diff --git a/libgo/configure.ac b/libgo/configure.ac
index 54c35c0903c..e8d66f8415d 100644
--- a/libgo/configure.ac
+++ b/libgo/configure.ac
@@ -53,6 +53,7 @@ AC_LIBTOOL_DLOPEN
 AM_PROG_LIBTOOL
 AC_SUBST(enable_shared)
 AC_SUBST(enable_static)
+AM_CONDITIONAL([ENABLE_DARWIN_AT_RPATH], [test
x$enable_darwin_at_rpath = xyes])

 CC_FOR_BUILD=${CC_FOR_BUILD:-gcc}
 AC_SUBST(CC_FOR_BUILD)


Re: [PATCH 3/4] libbacktrace: work with aslr on windows

2023-11-30 Thread Ian Lance Taylor
On Mon, Nov 20, 2023 at 11:58 AM Björn Schäpers  wrote:
>
> An updated version, using neither A or W, but just the macro.

Thanks.  Committed as follows.

Ian
1017495bc91d40570f58c37e88ca013164782129
diff --git a/libbacktrace/pecoff.c b/libbacktrace/pecoff.c
index 56af4828e27..f976a963bf3 100644
--- a/libbacktrace/pecoff.c
+++ b/libbacktrace/pecoff.c
@@ -39,6 +39,18 @@ POSSIBILITY OF SUCH DAMAGE.  */
 #include "backtrace.h"
 #include "internal.h"
 
+#ifdef HAVE_WINDOWS_H
+#ifndef WIN32_MEAN_AND_LEAN
+#define WIN32_MEAN_AND_LEAN
+#endif
+
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+
+#include 
+#endif
+
 /* Coff file header.  */
 
 typedef struct {
@@ -610,6 +622,7 @@ coff_add (struct backtrace_state *state, int descriptor,
   int debug_view_valid;
   int is_64;
   uintptr_t image_base;
+  uintptr_t base_address = 0;
   struct dwarf_sections dwarf_sections;
 
   *found_sym = 0;
@@ -856,7 +869,16 @@ coff_add (struct backtrace_state *state, int descriptor,
  + (sections[i].offset - min_offset));
 }
 
-  if (!backtrace_dwarf_add (state, /* base_address */ 0, _sections,
+#ifdef HAVE_WINDOWS_H
+  {
+uintptr_t module_handle;
+
+module_handle = (uintptr_t) GetModuleHandle (NULL);
+base_address = module_handle - image_base;
+  }
+#endif
+
+  if (!backtrace_dwarf_add (state, base_address, _sections,
0, /* FIXME: is_bigendian */
NULL, /* altlink */
error_callback, data, fileline_fn,


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

2023-11-29 Thread Ian Lance Taylor
On Mon, Nov 20, 2023 at 11:57 AM Björn Schäpers  wrote:
>
> this is what I'm using with GCC 12 and 13 on my windows machines, rebased onto
> the current HEAD.

Thanks.  Committed as follows.

Ian

* fileline.c: Include  if available.
(windows_get_executable_path): New static function.
(fileline_initialize): Call windows_get_executable_path.
* configure.ac: Checked for windows.h
* configure: Regenerate.
* config.h.in: Regenerate.
0ee01dfacbcc9bc05d11433a69c0a0ac13afa42f
diff --git a/libbacktrace/config.h.in b/libbacktrace/config.h.in
index a4f5bf6..ee2616335c7 100644
--- a/libbacktrace/config.h.in
+++ b/libbacktrace/config.h.in
@@ -104,6 +104,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 0ccc060901d..7ade966b54d 100755
--- a/libbacktrace/configure
+++ b/libbacktrace/configure
@@ -13509,6 +13509,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 71cd50f8cdf..00acb42eb6d 100644
--- a/libbacktrace/configure.ac
+++ b/libbacktrace/configure.ac
@@ -379,6 +379,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 0e560b44e7a..773f3a92969 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"
 
@@ -165,6 +177,37 @@ macho_get_executable_path (struct backtrace_state *state,
 
 #endif /* !HAVE_DECL__PGMPTR */
 
+#ifdef HAVE_WINDOWS_H
+
+#define FILENAME_BUF_SIZE (MAX_PATH)
+
+static char *
+windows_get_executable_path (char *buf, backtrace_error_callback 
error_callback,
+void *data)
+{
+  size_t got;
+  int error;
+
+  got = GetModuleFileNameA (NULL, buf, FILENAME_BUF_SIZE - 1);
+  error = GetLastError ();
+  if (got == 0
+  || (got == FILENAME_BUF_SIZE - 1 && error == ERROR_INSUFFICIENT_BUFFER))
+{
+  error_callback (data,
+ "could not get the filename of the current executable",
+ error);
+  return NULL;
+}
+  return buf;
+}
+
+#else /* !defined (HAVE_WINDOWS_H) */
+
+#define windows_get_executable_path(buf, error_callback, data) NULL
+#define FILENAME_BUF_SIZE 64
+
+#endif /* !defined (HAVE_WINDOWS_H) */
+
 /* Initialize the fileline information from the executable.  Returns 1
on success, 0 on failure.  */
 
@@ -178,7 +221,7 @@ fileline_initialize (struct backtrace_state *state,
   int called_error_callback;
   int descriptor;
   const char *filename;
-  char buf[64];
+  char buf[FILENAME_BUF_SIZE];
 
   if (!state->threaded)
 failed = state->fileline_initialization_failed;
@@ -202,7 +245,7 @@ fileline_initialize (struct backtrace_state *state,
 
   descriptor = -1;
   called_error_callback = 0;
-  for (pass = 0; pass < 9; ++pass)
+  for (pass = 0; pass < 10; ++pass)
 {
   int does_not_exist;
 
@@ -239,6 +282,9 @@ fileline_initialize (struct backtrace_state *state,
case 8:
  filename = macho_get_executable_path (state, error_callback, data);
  break;
+   case 9:
+ filename = windows_get_executable_path (buf, error_callback, data);
+ break;
default:
  abort ();
}


libstdc++ patch RFA: Fix dl_iterate_phdr configury for libbacktrace

2023-11-02 Thread Ian Lance Taylor
The libbacktrace sources, as used by libstdc++-v3, fail to correctly
determine whether the system supports dl_iterate_phdr.  The issue is
that the libbacktrace configure assumes that _GNU_SOURCE is defined
during compilation, but the libstdc++-v3 configure does not do that.
This configury failure is the cause of PR 112263.

This patch fixes the problem.  OK for mainline?

Ian

PR libbacktrace/112263
* acinclude.m4: Set -D_GNU_SOURCE in BACKTRACE_CPPFLAGS and when
grepping link.h for dl_iterate_phdr.
* configure: Regenerate.
diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index d8f0ba1c3e2..41446c2c3d6 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -5443,7 +5443,7 @@ AC_DEFUN([GLIBCXX_ENABLE_BACKTRACE], [
 
   # Most of this is adapted from libsanitizer/configure.ac
 
-  BACKTRACE_CPPFLAGS=
+  BACKTRACE_CPPFLAGS="-D_GNU_SOURCE"
 
   # libbacktrace only needs atomics for int, which we've already tested
   if test "$glibcxx_cv_atomic_int" = "yes"; then
@@ -5471,8 +5471,11 @@ AC_DEFUN([GLIBCXX_ENABLE_BACKTRACE], [
 have_dl_iterate_phdr=no
   else
 # When built as a GCC target library, we can't do a link test.
+ac_save_CPPFLAGS="$CPPFLAGS"
+CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
 AC_EGREP_HEADER([dl_iterate_phdr], [link.h], [have_dl_iterate_phdr=yes],
[have_dl_iterate_phdr=no])
+CPPFLAGS="$ac_save_CPPFLAGS"
   fi
   if test "$have_dl_iterate_phdr" = "yes"; then
 BACKTRACE_CPPFLAGS="$BACKTRACE_CPPFLAGS -DHAVE_DL_ITERATE_PHDR=1"
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index 9f12c5baa3f..693564d3c7e 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -73299,7 +73299,7 @@ fi
 
   # Most of this is adapted from libsanitizer/configure.ac
 
-  BACKTRACE_CPPFLAGS=
+  BACKTRACE_CPPFLAGS="-D_GNU_SOURCE"
 
   # libbacktrace only needs atomics for int, which we've already tested
   if test "$glibcxx_cv_atomic_int" = "yes"; then
@@ -73382,6 +73382,8 @@ done
 have_dl_iterate_phdr=no
   else
 # When built as a GCC target library, we can't do a link test.
+ac_save_CPPFLAGS="$CPPFLAGS"
+CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include 
@@ -73395,6 +73397,7 @@ else
 fi
 rm -f conftest*
 
+CPPFLAGS="$ac_save_CPPFLAGS"
   fi
   if test "$have_dl_iterate_phdr" = "yes"; then
 BACKTRACE_CPPFLAGS="$BACKTRACE_CPPFLAGS -DHAVE_DL_ITERATE_PHDR=1"


Re: [PATCH] testsuite: Fix _BitInt in gcc.misc-tests/godump-1.c

2023-10-25 Thread Ian Lance Taylor
On Tue, Oct 24, 2023, 11:03 AM Jeff Law  wrote:

>
>
> On 10/24/23 09:26, Stefan Schulze Frielinghaus wrote:
> > Currently _BitInt is only supported on x86_64 which means that for other
> > targets all tests fail with e.g.
> >
> > gcc.misc-tests/godump-1.c:237:1: sorry, unimplemented: '_BitInt(32)' is
> not supported on this target
> >237 | _BitInt(32) b32_v;
> >| ^~~
> >
> > Instead of requiring _BitInt support for godump-1.c, move _BitInt tests
> > into godump-2.c such that all other tests in godump-1.c are still
> > executed in case of missing _BitInt support.
> >
> > Tested on s390x and x86_64.  Ok for mainline?
> >
> > gcc/testsuite/ChangeLog:
> >
> >   * gcc.misc-tests/godump-1.c: Move _BitInt tests into godump-2.c.
> >   * gcc.misc-tests/godump-2.c: New test.
> OK
>

Thanks.

Ian

>


Go patch committed: Move Selector_expression up in file

2023-10-23 Thread Ian Lance Taylor
This patch to the Go frontend just moves Selector_expression up in
file.  This is a mechanical change to expressions.cc.  This will make
Selector_expression visible to Builtin_call_expression for later work.
This produces a very large "git --diff", but "git diff --minimal" is
clear.  Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.
Committed to mainline.

Ian
02aa322c8cfd3f60fa5a3a0eee4340bb644261fe
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 35b9cd780da..aff74bd74dc 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-3c2a441ef6cafb018bb3cc16f8403ae3d1daf2e1
+e997b0201512110e9c20b1fdfd40014830031047
 
 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 f218731041b..c9177b71174 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -8426,6 +8426,287 @@ Expression::make_bound_method(Expression* expr, const 
Method* method,
   return new Bound_method_expression(expr, method, function, location);
 }
 
+// A general selector.  This is a Parser_expression for LEFT.NAME.  It
+// is lowered after we know the type of the left hand side.
+
+class Selector_expression : public Parser_expression
+{
+ public:
+  Selector_expression(Expression* left, const std::string& name,
+ Location location)
+: Parser_expression(EXPRESSION_SELECTOR, location),
+  left_(left), name_(name)
+  { }
+
+ protected:
+  int
+  do_traverse(Traverse* traverse)
+  { return Expression::traverse(>left_, traverse); }
+
+  Expression*
+  do_lower(Gogo*, Named_object*, Statement_inserter*, int);
+
+  Expression*
+  do_copy()
+  {
+return new Selector_expression(this->left_->copy(), this->name_,
+  this->location());
+  }
+
+  void
+  do_dump_expression(Ast_dump_context* ast_dump_context) const;
+
+ private:
+  Expression*
+  lower_method_expression(Gogo*);
+
+  // The expression on the left hand side.
+  Expression* left_;
+  // The name on the right hand side.
+  std::string name_;
+};
+
+// Lower a selector expression once we know the real type of the left
+// hand side.
+
+Expression*
+Selector_expression::do_lower(Gogo* gogo, Named_object*, Statement_inserter*,
+ int)
+{
+  Expression* left = this->left_;
+  if (left->is_type_expression())
+return this->lower_method_expression(gogo);
+  return Type::bind_field_or_method(gogo, left->type(), left, this->name_,
+   this->location());
+}
+
+// Lower a method expression T.M or (*T).M.  We turn this into a
+// function literal.
+
+Expression*
+Selector_expression::lower_method_expression(Gogo* gogo)
+{
+  Location location = this->location();
+  Type* left_type = this->left_->type();
+  Type* type = left_type;
+  const std::string& name(this->name_);
+
+  bool is_pointer;
+  if (type->points_to() == NULL)
+is_pointer = false;
+  else
+{
+  is_pointer = true;
+  type = type->points_to();
+}
+
+  Named_type* nt = type->named_type();
+  Struct_type* st = type->struct_type();
+  bool is_ambiguous;
+  Method* method = NULL;
+  if (nt != NULL)
+method = nt->method_function(name, _ambiguous);
+  else if (st != NULL)
+method = st->method_function(name, _ambiguous);
+  const Typed_identifier* imethod = NULL;
+  if (method == NULL && !is_pointer)
+{
+  Interface_type* it = type->interface_type();
+  if (it != NULL)
+   imethod = it->find_method(name);
+}
+
+  if ((method == NULL && imethod == NULL)
+  || (left_type->named_type() != NULL && left_type->points_to() != NULL))
+{
+  if (nt != NULL)
+   {
+ if (!is_ambiguous)
+   go_error_at(location, "type %<%s%s%> has no method %<%s%>",
+   is_pointer ? "*" : "",
+   nt->message_name().c_str(),
+   Gogo::message_name(name).c_str());
+ else
+   go_error_at(location, "method %<%s%s%> is ambiguous in type %<%s%>",
+   Gogo::message_name(name).c_str(),
+   is_pointer ? "*" : "",
+   nt->message_name().c_str());
+   }
+  else
+   {
+ if (!is_ambiguous)
+   go_error_at(location, "type has no method %<%s%>",
+   Gogo::message_name(name).c_str());
+ else
+   go_error_at(location, "method %<%s%> is ambiguous",
+   Gogo::message_name(name).c_str());
+   }
+  return Expression::make_error(location);
+}
+
+  if (method != NULL && !is_pointer && !method->is_value_method())
+{
+  go_error_at(location, "method requires pointer (use %<(*%s).%s%>)",
+  nt->message_name().c_str(),
+  Gogo::message_name(name).c_str());
+  return Expression::make_error(location);
+ 

Go patch committed: Make xx_constant_value methods non-const

2023-10-23 Thread Ian Lance Taylor
This patch to the Go frontend changes the Expression
{numeric,string,boolean}_constant_value methods to be non-const.  This
does not affect anything immediately, but will be useful for later CLs
in this series.

The only real effect is to Builtin_call_expression::do_export, which
remains const and can no longer call numeric_constant_value.  But it
never needed to call it, as do_export runs after do_lower, and
do_lower replaces a constant expression with the actual constant.

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

Ian
597dba85b3e66a0836dd7442edcc2fda7e0703fc
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index d962c4f5770..35b9cd780da 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-806217827fe30553d535f876f182a9e92f5f648e
+3c2a441ef6cafb018bb3cc16f8403ae3d1daf2e1
 
 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 c7b442d3a03..f218731041b 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -846,7 +846,7 @@ class Error_expression : public Expression
   { return false; }
 
   bool
-  do_numeric_constant_value(Numeric_constant* nc) const
+  do_numeric_constant_value(Numeric_constant* nc)
   {
 nc->set_unsigned_long(NULL, 0);
 return true;
@@ -1992,7 +1992,7 @@ class Boolean_expression : public Expression
   { return this->val_ == false; }
 
   bool
-  do_boolean_constant_value(bool* val) const
+  do_boolean_constant_value(bool* val)
   {
 *val = this->val_;
 return true;
@@ -2537,7 +2537,7 @@ class Integer_expression : public Expression
   { return true; }
 
   bool
-  do_numeric_constant_value(Numeric_constant* nc) const;
+  do_numeric_constant_value(Numeric_constant* nc);
 
   Type*
   do_type();
@@ -2602,7 +2602,7 @@ Integer_expression::do_traverse(Traverse* traverse)
 // this as a character when appropriate.
 
 bool
-Integer_expression::do_numeric_constant_value(Numeric_constant* nc) const
+Integer_expression::do_numeric_constant_value(Numeric_constant* nc)
 {
   if (this->is_character_constant_)
 nc->set_rune(this->type_, this->val_);
@@ -2983,7 +2983,7 @@ class Float_expression : public Expression
   { return true; }
 
   bool
-  do_numeric_constant_value(Numeric_constant* nc) const
+  do_numeric_constant_value(Numeric_constant* nc)
   {
 nc->set_float(this->type_, this->val_);
 return true;
@@ -3219,7 +3219,7 @@ class Complex_expression : public Expression
   { return true; }
 
   bool
-  do_numeric_constant_value(Numeric_constant* nc) const
+  do_numeric_constant_value(Numeric_constant* nc)
   {
 nc->set_complex(this->type_, this->val_);
 return true;
@@ -3480,7 +3480,7 @@ Const_expression::do_lower(Gogo* gogo, Named_object*,
 // Return a numeric constant value.
 
 bool
-Const_expression::do_numeric_constant_value(Numeric_constant* nc) const
+Const_expression::do_numeric_constant_value(Numeric_constant* nc)
 {
   if (this->seen_)
 return false;
@@ -3508,7 +3508,7 @@ 
Const_expression::do_numeric_constant_value(Numeric_constant* nc) const
 }
 
 bool
-Const_expression::do_string_constant_value(std::string* val) const
+Const_expression::do_string_constant_value(std::string* val)
 {
   if (this->seen_)
 return false;
@@ -3523,7 +3523,7 @@ Const_expression::do_string_constant_value(std::string* 
val) const
 }
 
 bool
-Const_expression::do_boolean_constant_value(bool* val) const
+Const_expression::do_boolean_constant_value(bool* val)
 {
   if (this->seen_)
 return false;
@@ -4180,7 +4180,7 @@ Type_conversion_expression::do_is_static_initializer() 
const
 
 bool
 Type_conversion_expression::do_numeric_constant_value(
-Numeric_constant* nc) const
+Numeric_constant* nc)
 {
   if (!this->type_->is_numeric_type())
 return false;
@@ -4192,7 +4192,7 @@ Type_conversion_expression::do_numeric_constant_value(
 // Return the constant string value if there is one.
 
 bool
-Type_conversion_expression::do_string_constant_value(std::string* val) const
+Type_conversion_expression::do_string_constant_value(std::string* val)
 {
   if (this->type_->is_string_type() && this->expr_->type()->is_string_type())
 return this->expr_->string_constant_value(val);
@@ -4229,7 +4229,7 @@ 
Type_conversion_expression::do_string_constant_value(std::string* val) const
 // Return the constant boolean value if there is one.
 
 bool
-Type_conversion_expression::do_boolean_constant_value(bool* val) const
+Type_conversion_expression::do_boolean_constant_value(bool* val)
 {
   if (!this->type_->is_boolean_type())
 return false;
@@ -5141,7 +5141,7 @@ Unary_expression::eval_constant(Operator op, const 
Numeric_constant* unc,
 // Return the integral constant value of a unary expression, if it has one.
 
 bool
-Unary_expression::do_numeric_constant_value(Numeric_constant* nc) const

Go patch committed: Pass Gogo to Runtime::make_call

2023-10-23 Thread Ian Lance Taylor
This Go frontend patches passes the Gogo IR pointer to
Runtime::make_call.  This is a boilerplate change that doesn't affect
compiler output.  It's not currently used but will be used by later
CLs in this series.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
45a5ab0503569e57883dca4d8e76d83dc3a60ff6
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index d4095637cea..d962c4f5770 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-1c0a7c9338801d15afba7e39109554ed3406654e
+806217827fe30553d535f876f182a9e92f5f648e
 
 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 5bea6238def..c7b442d3a03 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -305,8 +305,8 @@ Expression::convert_for_assignment(Gogo* gogo, Type* 
lhs_type,
 {
   // Type to interface conversions have been made explicit early.
   go_assert(rhs_type->interface_type() != NULL);
-  return Expression::convert_interface_to_interface(lhs_type, rhs, false,
-location);
+  return Expression::convert_interface_to_interface(gogo, lhs_type, rhs,
+   false, location);
 }
   else if (!are_identical && rhs_type->interface_type() != NULL)
 return Expression::convert_interface_to_type(gogo, lhs_type, rhs, 
location);
@@ -525,7 +525,8 @@ Expression::get_interface_type_descriptor(Expression* rhs)
 // interface type.
 
 Expression*
-Expression::convert_interface_to_interface(Type *lhs_type, Expression* rhs,
+Expression::convert_interface_to_interface(Gogo* gogo, Type *lhs_type,
+  Expression* rhs,
bool for_type_guard,
Location location)
 {
@@ -558,7 +559,7 @@ Expression::convert_interface_to_interface(Type *lhs_type, 
Expression* rhs,
   if (for_type_guard)
 {
   // A type assertion fails when converting a nil interface.
-  first_field = Runtime::make_call(Runtime::ASSERTITAB, location, 2,
+  first_field = Runtime::make_call(gogo, Runtime::ASSERTITAB, location, 2,
   lhs_type_expr, rhs_type_expr);
 }
   else if (lhs_is_empty)
@@ -571,7 +572,7 @@ Expression::convert_interface_to_interface(Type *lhs_type, 
Expression* rhs,
 {
   // A conversion to a non-empty interface may fail, but unlike a
   // type assertion converting nil will always succeed.
-  first_field = Runtime::make_call(Runtime::REQUIREITAB, location, 2,
+  first_field = Runtime::make_call(gogo, Runtime::REQUIREITAB, location, 2,
   lhs_type_expr, rhs_type_expr);
 }
 
@@ -610,7 +611,7 @@ Expression::convert_interface_to_type(Gogo* gogo, Type 
*lhs_type, Expression* rh
 
   Expression* cond;
   if (gogo->need_eqtype()) {
-cond = Runtime::make_call(Runtime::EQTYPE, location,
+cond = Runtime::make_call(gogo, Runtime::EQTYPE, location,
   2, lhs_type_expr,
   rhs_descriptor);
   } else {
@@ -619,7 +620,7 @@ Expression::convert_interface_to_type(Gogo* gogo, Type 
*lhs_type, Expression* rh
   }
 
   rhs_descriptor = Expression::get_interface_type_descriptor(rhs);
-  Expression* panic = Runtime::make_call(Runtime::PANICDOTTYPE, location,
+  Expression* panic = Runtime::make_call(gogo, Runtime::PANICDOTTYPE, location,
  3, lhs_type_expr->copy(),
  rhs_descriptor,
  rhs_inter_expr);
@@ -719,7 +720,8 @@ 
Expression::backend_numeric_constant_expression(Translate_context* context,
 // functions, which will panic.
 
 void
-Expression::check_bounds(Expression* val, Operator op, Expression* bound,
+Expression::check_bounds(Gogo* gogo, Expression* val, Operator op,
+Expression* bound,
 Runtime::Function code,
 Runtime::Function code_u,
 Runtime::Function code_extend,
@@ -813,7 +815,7 @@ Expression::check_bounds(Expression* val, Operator op, 
Expression* bound,
 }
 
   Expression* ignore = Expression::make_boolean(true, loc);
-  Expression* crash = Runtime::make_call(c, loc, 2,
+  Expression* crash = Runtime::make_call(gogo, c, loc, 2,
 val->copy(), bound->copy());
   Expression* cond = Expression::make_conditional(check, ignore, crash, loc);
   inserter->insert(Statement::make_statement(cond, true));
@@ -3916,7 +3918,7 @@ Type_conversion_expression::do_traverse(Traverse* 
traverse)
 // from slice to pointer-to-array, as they can panic.
 
 Expression*

Go patch committed: Add Expression::is_untyped method

2023-10-23 Thread Ian Lance Taylor
This Go frontend patches adds an Expression::is_untyped method.  This
method is not currently used by anything, but it will be used by later
changes in this series.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
ac50e9b72bf9bb6d5b28096bb164fb050db6e290
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 0f961157dfd..d4095637cea 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-081ec9824a74ec9d82628d8d2f6b9a7a4c35a529
+1c0a7c9338801d15afba7e39109554ed3406654e
 
 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 273831fabf3..5bea6238def 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -201,6 +201,19 @@ Expression::report_error(const char* msg)
   this->set_is_error();
 }
 
+// A convenience function for handling a type in do_is_untyped.  If
+// TYPE is not abstract, return false.  Otherwise set *PTYPE to TYPE
+// and return true.
+
+bool
+Expression::is_untyped_type(Type* type, Type** ptype)
+{
+  if (!type->is_abstract())
+return false;
+  *ptype = type;
+  return true;
+}
+
 // Set types of variables and constants.  This is implemented by the
 // child class.
 
@@ -826,6 +839,10 @@ class Error_expression : public Expression
   do_is_constant() const
   { return true; }
 
+  bool
+  do_is_untyped(Type**) const
+  { return false; }
+
   bool
   do_numeric_constant_value(Numeric_constant* nc) const
   {
@@ -1965,6 +1982,9 @@ class Boolean_expression : public Expression
   do_is_constant() const
   { return true; }
 
+  bool
+  do_is_untyped(Type**) const;
+
   bool
   do_is_zero_value() const
   { return this->val_ == false; }
@@ -2023,6 +2043,15 @@ Boolean_expression::do_traverse(Traverse* traverse)
   return TRAVERSE_CONTINUE;
 }
 
+bool
+Boolean_expression::do_is_untyped(Type** ptype) const
+{
+  if (this->type_ != NULL)
+return Expression::is_untyped_type(this->type_, ptype);
+  *ptype = Type::make_boolean_type();
+  return true;
+}
+
 // Get the type.
 
 Type*
@@ -2096,6 +2125,15 @@ String_expression::do_traverse(Traverse* traverse)
   return TRAVERSE_CONTINUE;
 }
 
+bool
+String_expression::do_is_untyped(Type** ptype) const
+{
+  if (this->type_ != NULL)
+return Expression::is_untyped_type(this->type_, ptype);
+  *ptype = Type::make_string_type();
+  return true;
+}
+
 // Get the type.
 
 Type*
@@ -2485,6 +2523,9 @@ class Integer_expression : public Expression
   do_is_constant() const
   { return true; }
 
+  bool
+  do_is_untyped(Type**) const;
+
   bool
   do_is_zero_value() const
   { return mpz_sgn(this->val_) == 0; }
@@ -2568,6 +2609,18 @@ 
Integer_expression::do_numeric_constant_value(Numeric_constant* nc) const
   return true;
 }
 
+bool
+Integer_expression::do_is_untyped(Type** ptype) const
+{
+  if (this->type_ != NULL)
+return Expression::is_untyped_type(this->type_, ptype);
+  if (this->is_character_constant_)
+*ptype = Type::make_abstract_character_type();
+  else
+*ptype = Type::make_abstract_integer_type();
+  return true;
+}
+
 // Return the current type.  If we haven't set the type yet, we return
 // an abstract integer type.
 
@@ -2913,6 +2966,9 @@ class Float_expression : public Expression
   do_is_constant() const
   { return true; }
 
+  bool
+  do_is_untyped(Type**) const;
+
   bool
   do_is_zero_value() const
   {
@@ -2979,6 +3035,15 @@ Float_expression::do_traverse(Traverse* traverse)
   return TRAVERSE_CONTINUE;
 }
 
+bool
+Float_expression::do_is_untyped(Type** ptype) const
+{
+  if (this->type_ != NULL)
+return Expression::is_untyped_type(this->type_, ptype);
+  *ptype = Type::make_abstract_float_type();
+  return true;
+}
+
 // Return the current type.  If we haven't set the type yet, we return
 // an abstract float type.
 
@@ -3135,6 +3200,9 @@ class Complex_expression : public Expression
   do_is_constant() const
   { return true; }
 
+  bool
+  do_is_untyped(Type**) const;
+
   bool
   do_is_zero_value() const
   {
@@ -3205,6 +3273,15 @@ Complex_expression::do_traverse(Traverse* traverse)
   return TRAVERSE_CONTINUE;
 }
 
+bool
+Complex_expression::do_is_untyped(Type** ptype) const
+{
+  if (this->type_ != NULL)
+return Expression::is_untyped_type(this->type_, ptype);
+  *ptype = Type::make_abstract_complex_type();
+  return true;
+}
+
 // Return the current type.  If we haven't set the type yet, we return
 // an abstract complex type.
 
@@ -3458,6 +3535,21 @@ Const_expression::do_boolean_constant_value(bool* val) 
const
   return ok;
 }
 
+// Whether this is untyped.
+
+bool
+Const_expression::do_is_untyped(Type** ptype) const
+{
+  if (this->type_ != NULL)
+return Expression::is_untyped_type(this->type_, ptype);
+
+  Named_constant* nc = this->constant_->const_value();
+  if (nc->type() != NULL)
+return Expression::is_untyped_type(nc->type(), ptype);
+
+ 

libgo patch committed: Add missing type conversion

2023-10-23 Thread Ian Lance Taylor
This libgo patch adds a missing type conversion.  The gofrontend
incorrectly accepted code that was missing a type conversion.  The
test case for this is bug518.go in https://go.dev/cl/536537.  Future
CLs in this series will detect the type error.  Bootstrapped and ran
Go testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
2621bd1bac614b63e52d0deb4ab2ff287a9fafa8
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 398d2671b64..0f961157dfd 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-c201fa2a684ada551ca9a0825a3075a0a69498de
+081ec9824a74ec9d82628d8d2f6b9a7a4c35a529
 
 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/errstr.go b/libgo/go/syscall/errstr.go
index 9f688e2a0c7..02f228adc59 100644
--- a/libgo/go/syscall/errstr.go
+++ b/libgo/go/syscall/errstr.go
@@ -24,7 +24,7 @@ func Errstr(errnum int) string {
}
return string(b[:i])
}
-   if errno != ERANGE {
+   if Errno(errno) != ERANGE {
return "strerror_r failure"
}
}


Go patch committed: Remove the traverse_assignments code

2023-10-22 Thread Ian Lance Taylor
This patch to the Go frontend removes the traverse_assignments
support.  The last caller was removed in https://go.dev/cl/18261 in
2016.  Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.
Committed to mainline.

Ian
a6e74b0b3316f3f0b2096d6a175c31bed58ae4ed
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index d31fb336e41..398d2671b64 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-75b08794cb1485c955d13784c53a89174764af55
+c201fa2a684ada551ca9a0825a3075a0a69498de
 
 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 b43f1393e33..91c7627a0e3 100644
--- a/gcc/go/gofrontend/statements.cc
+++ b/gcc/go/gofrontend/statements.cc
@@ -64,16 +64,6 @@ Statement::traverse_contents(Traverse* traverse)
   return this->do_traverse(traverse);
 }
 
-// Traverse assignments.
-
-bool
-Statement::traverse_assignments(Traverse_assignments* tassign)
-{
-  if (this->classification_ == STATEMENT_ERROR)
-return false;
-  return this->do_traverse_assignments(tassign);
-}
-
 // Traverse an expression in a statement.  This is a helper function
 // for child classes.
 
@@ -288,17 +278,6 @@ Variable_declaration_statement::do_traverse(Traverse*)
   return TRAVERSE_CONTINUE;
 }
 
-// Traverse the assignments in a variable declaration.  Note that this
-// traversal is different from the usual traversal.
-
-bool
-Variable_declaration_statement::do_traverse_assignments(
-Traverse_assignments* tassign)
-{
-  tassign->initialize_variable(this->var_);
-  return true;
-}
-
 // Lower the variable's initialization expression.
 
 Statement*
@@ -510,17 +489,6 @@ Temporary_statement::do_traverse(Traverse* traverse)
 return this->traverse_expression(traverse, >init_);
 }
 
-// Traverse assignments.
-
-bool
-Temporary_statement::do_traverse_assignments(Traverse_assignments* tassign)
-{
-  if (this->init_ == NULL)
-return false;
-  tassign->value(>init_, true, true);
-  return true;
-}
-
 // Determine types.
 
 void
@@ -889,13 +857,6 @@ Assignment_statement::do_traverse(Traverse* traverse)
   return this->traverse_expression(traverse, >rhs_);
 }
 
-bool
-Assignment_statement::do_traverse_assignments(Traverse_assignments* tassign)
-{
-  tassign->assignment(>lhs_, >rhs_);
-  return true;
-}
-
 // Lower an assignment to a map index expression to a runtime function
 // call.  Mark some slice assignments as not requiring a write barrier.
 
@@ -1212,10 +1173,6 @@ class Assignment_operation_statement : public Statement
   int
   do_traverse(Traverse*);
 
-  bool
-  do_traverse_assignments(Traverse_assignments*)
-  { go_unreachable(); }
-
   Statement*
   do_lower(Gogo*, Named_object*, Block*, Statement_inserter*);
 
@@ -1365,10 +1322,6 @@ class Tuple_assignment_statement : public Statement
   int
   do_traverse(Traverse* traverse);
 
-  bool
-  do_traverse_assignments(Traverse_assignments*)
-  { go_unreachable(); }
-
   Statement*
   do_lower(Gogo*, Named_object*, Block*, Statement_inserter*);
 
@@ -1511,10 +1464,6 @@ public:
   int
   do_traverse(Traverse* traverse);
 
-  bool
-  do_traverse_assignments(Traverse_assignments*)
-  { go_unreachable(); }
-
   Statement*
   do_lower(Gogo*, Named_object*, Block*, Statement_inserter*);
 
@@ -1719,10 +1668,6 @@ class Tuple_receive_assignment_statement : public 
Statement
   int
   do_traverse(Traverse* traverse);
 
-  bool
-  do_traverse_assignments(Traverse_assignments*)
-  { go_unreachable(); }
-
   Statement*
   do_lower(Gogo*, Named_object*, Block*, Statement_inserter*);
 
@@ -1862,10 +1807,6 @@ class Tuple_type_guard_assignment_statement : public 
Statement
   int
   do_traverse(Traverse*);
 
-  bool
-  do_traverse_assignments(Traverse_assignments*)
-  { go_unreachable(); }
-
   Statement*
   do_lower(Gogo*, Named_object*, Block*, Statement_inserter*);
 
@@ -2277,10 +2218,6 @@ class Inc_dec_statement : public Statement
   do_traverse(Traverse* traverse)
   { return this->traverse_expression(traverse, >expr_); }
 
-  bool
-  do_traverse_assignments(Traverse_assignments*)
-  { go_unreachable(); }
-
   Statement*
   do_lower(Gogo*, Named_object*, Block*, Statement_inserter*);
 
@@ -2412,18 +2349,6 @@ Thunk_statement::do_traverse(Traverse* traverse)
   return this->traverse_expression(traverse, >call_);
 }
 
-// We implement traverse_assignment for a thunk statement because it
-// effectively copies the function call.
-
-bool
-Thunk_statement::do_traverse_assignments(Traverse_assignments* tassign)
-{
-  Expression* fn = this->call_->call_expression()->fn();
-  Expression* fn2 = fn;
-  tassign->value(, true, false);
-  return true;
-}
-
 // Determine types in a thunk statement.
 
 void
@@ -3148,23 +3073,6 @@ Statement::make_defer_statement(Call_expression* call,
 
 // Class Return_statement.
 
-// Traverse assignments.  We treat each return value as a top level
-// RHS in an expression.
-
-bool

Go patch committed: Remove name_ field from Type_switch_statement

2023-10-22 Thread Ian Lance Taylor
This patch to the Go frontend removes the name_ field from the
Type_switch_statement class.  It's not used for anything.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
1a1fba1e25779247a4969789885ce80b7b4a2359
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 28683d6852b..d31fb336e41 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-06ada1f2ab9b05e54641438db28c557c6900b2a3
+75b08794cb1485c955d13784c53a89174764af55
 
 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 c93d82bba39..d7410588347 100644
--- a/gcc/go/gofrontend/parse.cc
+++ b/gcc/go/gofrontend/parse.cc
@@ -4932,7 +4932,7 @@ Parse::type_switch_body(Label* label, const Type_switch& 
type_switch,
 }
 
   Type_switch_statement* statement =
-  Statement::make_type_switch_statement(var_name, init, location);
+  Statement::make_type_switch_statement(init, location);
   this->push_break_statement(statement, label);
 
   Type_case_clauses* case_clauses = new Type_case_clauses();
diff --git a/gcc/go/gofrontend/statements.cc b/gcc/go/gofrontend/statements.cc
index 33b568e3eeb..b43f1393e33 100644
--- a/gcc/go/gofrontend/statements.cc
+++ b/gcc/go/gofrontend/statements.cc
@@ -5046,8 +5046,6 @@ 
Type_switch_statement::do_dump_statement(Ast_dump_context* ast_dump_context)
 {
   ast_dump_context->print_indent();
   ast_dump_context->ostream() << "switch ";
-  if (!this->name_.empty())
-ast_dump_context->ostream() << this->name_ << " = ";
   ast_dump_context->dump_expression(this->expr_);
   ast_dump_context->ostream() << " .(type)";
   if (ast_dump_context->dump_subblocks())
@@ -5062,10 +5060,9 @@ 
Type_switch_statement::do_dump_statement(Ast_dump_context* ast_dump_context)
 // Make a type switch statement.
 
 Type_switch_statement*
-Statement::make_type_switch_statement(const std::string& name, Expression* 
expr,
- Location location)
+Statement::make_type_switch_statement(Expression* expr, Location location)
 {
-  return new Type_switch_statement(name, expr, location);
+  return new Type_switch_statement(expr, location);
 }
 
 // Class Send_statement.
diff --git a/gcc/go/gofrontend/statements.h b/gcc/go/gofrontend/statements.h
index eb795c4b920..9ef63cb9a61 100644
--- a/gcc/go/gofrontend/statements.h
+++ b/gcc/go/gofrontend/statements.h
@@ -253,7 +253,7 @@ class Statement
 
   // Make a type switch statement.
   static Type_switch_statement*
-  make_type_switch_statement(const std::string&, Expression*, Location);
+  make_type_switch_statement(Expression*, Location);
 
   // Make a send statement.
   static Send_statement*
@@ -2191,10 +2191,9 @@ class Type_case_clauses
 class Type_switch_statement : public Statement
 {
  public:
-  Type_switch_statement(const std::string& name, Expression* expr,
-   Location location)
+  Type_switch_statement(Expression* expr, Location location)
 : Statement(STATEMENT_TYPE_SWITCH, location),
-  name_(name), expr_(expr), clauses_(NULL), break_label_(NULL)
+  expr_(expr), clauses_(NULL), break_label_(NULL)
   { }
 
   // Add the clauses.
@@ -2227,10 +2226,7 @@ class Type_switch_statement : public Statement
   do_may_fall_through() const;
 
  private:
-  // The name of the variable declared in the type switch guard.  Empty if 
there
-  // is no variable declared.
-  std::string name_;
-  // The expression we are switching on if there is no variable.
+  // The expression we are switching on.
   Expression* expr_;
   // The type case clauses.
   Type_case_clauses* clauses_;


Go patch committed: pass Gogo to more passes

2023-10-22 Thread Ian Lance Taylor
This patch to the G frontend passes a pointer to the Gogo IR to the
determine types pass and the type verification pass.  This is a
straight refactoring that does not change the compiler behavior.  This
is in preparation for future CLs that rearrange the pass ordering.

This introduces one new call to go_get_gogo, which will be removed in
a future CL.

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

Ian
b513aa235d6e5d7e2a36ee789c60891fce873340
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index d24054e0d93..28683d6852b 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-967a215d6419c3db58f8f59a0c252c458abce395
+06ada1f2ab9b05e54641438db28c557c6900b2a3
 
 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 d276bd811cc..273831fabf3 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -205,18 +205,18 @@ Expression::report_error(const char* msg)
 // child class.
 
 void
-Expression::determine_type(const Type_context* context)
+Expression::determine_type(Gogo* gogo, const Type_context* context)
 {
-  this->do_determine_type(context);
+  this->do_determine_type(gogo, context);
 }
 
 // Set types when there is no context.
 
 void
-Expression::determine_type_no_context()
+Expression::determine_type_no_context(Gogo* gogo)
 {
   Type_context context;
-  this->do_determine_type();
+  this->do_determine_type(gogo, );
 }
 
 // Return true if two expressions refer to the same variable or struct
@@ -842,7 +842,7 @@ class Error_expression : public Expression
   { return Type::make_error_type(); }
 
   void
-  do_determine_type(const Type_context*)
+  do_determine_type(Gogo*, const Type_context*)
   { }
 
   Expression*
@@ -897,7 +897,7 @@ Type_expression : public Expression
   { return this->type_; }
 
   void
-  do_determine_type(const Type_context*)
+  do_determine_type(Gogo*, const Type_context*)
   { }
 
   void
@@ -998,10 +998,10 @@ Var_expression::do_type()
 // Determine the type of a reference to a variable.
 
 void
-Var_expression::do_determine_type(const Type_context*)
+Var_expression::do_determine_type(Gogo* gogo, const Type_context*)
 {
   if (this->variable_->is_variable())
-this->variable_->var_value()->determine_type();
+this->variable_->var_value()->determine_type(gogo);
 }
 
 // Something takes the address of this variable.  This means that we
@@ -1303,9 +1303,10 @@ Set_and_use_temporary_expression::do_type()
 
 void
 Set_and_use_temporary_expression::do_determine_type(
+Gogo* gogo,
 const Type_context* context)
 {
-  this->expr_->determine_type(context);
+  this->expr_->determine_type(gogo, context);
 }
 
 // Take the address.
@@ -1378,7 +1379,7 @@ class Sink_expression : public Expression
   do_type();
 
   void
-  do_determine_type(const Type_context*);
+  do_determine_type(Gogo*, const Type_context*);
 
   Expression*
   do_copy()
@@ -1410,7 +1411,7 @@ Sink_expression::do_type()
 // Determine the type of a sink expression.
 
 void
-Sink_expression::do_determine_type(const Type_context* context)
+Sink_expression::do_determine_type(Gogo*, const Type_context* context)
 {
   if (context->type != NULL)
 this->type_ = context->type;
@@ -1805,7 +1806,7 @@ class Func_code_reference_expression : public Expression
   { return Type::make_pointer_type(Type::make_void_type()); }
 
   void
-  do_determine_type(const Type_context*)
+  do_determine_type(Gogo*, const Type_context*)
   { }
 
   Expression*
@@ -1983,7 +1984,7 @@ class Boolean_expression : public Expression
   do_type();
 
   void
-  do_determine_type(const Type_context*);
+  do_determine_type(Gogo*, const Type_context*);
 
   Expression*
   do_copy()
@@ -2035,7 +2036,7 @@ Boolean_expression::do_type()
 // Set the type from the context.
 
 void
-Boolean_expression::do_determine_type(const Type_context* context)
+Boolean_expression::do_determine_type(Gogo*, const Type_context* context)
 {
   if (this->type_ != NULL && !this->type_->is_abstract())
 ;
@@ -2108,7 +2109,7 @@ String_expression::do_type()
 // Set the type from the context.
 
 void
-String_expression::do_determine_type(const Type_context* context)
+String_expression::do_determine_type(Gogo*, const Type_context* context)
 {
   if (this->type_ != NULL && !this->type_->is_abstract())
 ;
@@ -2278,7 +2279,7 @@ class String_info_expression : public Expression
   do_type();
 
   void
-  do_determine_type(const Type_context*)
+  do_determine_type(Gogo*, const Type_context*)
   { go_unreachable(); }
 
   Expression*
@@ -2390,7 +2391,7 @@ class String_value_expression : public Expression
   { return Type::make_string_type(); }
 
   void
-  do_determine_type(const Type_context*)
+  do_determine_type(Gogo*, const Type_context*)
   { go_unreachable(); }
 
   Expression*
@@ -2499,7 +2500,7 @@ class Integer_expression : 

Re: [PATCH v2] libiberty: Use posix_spawn in pex-unix when available.

2023-10-03 Thread Ian Lance Taylor
On Tue, Oct 3, 2023 at 12:04 PM Brendan Shanks  wrote:
>
> +  ret = posix_spawnattr_init ();
> +  if (ret) { *err = ret; *errmsg = "posix_spawnattr_init"; goto exit; }

Sorry, but let's keep the formatting used in the rest of the file.

if (ret != 0)
  {
*err = ret;
*errmsg = "posix_spawnattr_init";
goto exit;
  }



> +  if (in != STDIN_FILE_NO)
> +close (in);
> +  if (out != STDOUT_FILE_NO)
> +close (out);
> +  if (errdes != STDERR_FILE_NO)
> +close (errdes);

Not a big deal, but the other version of this function checks the
error result of close.

Ian


Re: [PATCH] libiberty: Use posix_spawn in pex-unix when available.

2023-10-02 Thread Ian Lance Taylor
On Fri, Sep 29, 2023 at 12:18 PM Brendan Shanks  wrote:
>
> +  #define ERR_ON_FAILURE(ret, func) \
> +do { if (ret) { *err = ret; *errmsg = func; goto exit; } else {} } while 
> (0)

Thanks, but please don't use a macro that changes control flow.

Ian


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;


Re: [PATCH] go: Fix up go.test/test/fixedbugs/bug207.go failure [PR109258]

2023-03-24 Thread Ian Lance Taylor
Jakub Jelinek  writes:

> 2023-03-24  Jakub Jelinek  
>
>   PR middle-end/109258
>   * go-gcc.cc (Gcc_backend): Add new static data members builtin_pure
>   and builtin_nothrow.
>   (Gcc_backend::Gcc_backend): Pass builtin_pure | builtin_nothrow for
>   BUILT_IN_MEMCMP.
>   (Gcc_backend::define_builtin): Handle builtin_pure and builtin_nothrow
>   in flags.

This is OK.  Thanks.  Go ahead and commit.

Ian


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 ping: Re: [PATCH] libgcc, i386, optabs, v2: Add __float{, un}tibf to libgcc and expand BF -> integral through SF intermediate [PR107703]

2023-03-10 Thread Ian Lance Taylor
Jakub Jelinek  writes:

> On Wed, Mar 01, 2023 at 01:32:43PM +0100, Jakub Jelinek via Gcc-patches wrote:
>> On Wed, Nov 16, 2022 at 12:51:14PM +0100, Jakub Jelinek via Gcc-patches 
>> wrote:
>> > On Wed, Nov 16, 2022 at 10:06:17AM +0100, Jakub Jelinek via
>> > Gcc-patches wrote:
>> > > Thoughts on this?  I guess my preference would be the BF -> SF -> TI
>> > > path because we won't need to waste
>> > > 32: 00015e10 321 FUNC GLOBAL DEFAULT 13
>> > > __fixbfti@@GCC_13.0.0
>> > > 89: 00015f60 299 FUNC GLOBAL DEFAULT 13
>> > > __fixunsbfti@@GCC_13.0.0
>> > > If so, I'd need to cut the fix parts of the patch below and
>> > > do something in the middle-end.
>> > 
>> > Here is adjusted patch that does that.
>> > 
>> > 2022-11-16  Jakub Jelinek  
>> > 
>> >PR target/107703
>> >* optabs.cc (expand_fix): For conversions from BFmode to integral,
>> >use shifts to convert it to SFmode first and then convert SFmode
>> >to integral.
>> > 
>> >* soft-fp/floattibf.c: New file.
>> >* soft-fp/floatuntibf.c: New file.
>> >* config/i386/libgcc-glibc.ver: Export __float{,un}tibf @ GCC_13.0.0.
>> >* config/i386/64/t-softfp (softfp_extras): Add floattibf and
>> >floatuntibf.
>> >(CFLAGS-floattibf.c, CFLAGS-floatunstibf.c): Add -msse2.
>> 
>> I'd like to ping the libgcc non-i386 part of this patch, Uros said the i386
>> part is ok but that one depends on the generic libgcc changes.
>> I'll ping the optabs.cc change separately.
>> 
>> https://gcc.gnu.org/pipermail/gcc-patches/2022-November/606398.html
>> with more info in
>> https://gcc.gnu.org/pipermail/gcc-patches/2022-November/606382.html
>
> I'd like to ping this again.  I've posted the previously added
> bfloat16 changes as well as the above 2 new files to libc-alpha as well
> https://sourceware.org/pipermail/libc-alpha/2023-March/146246.html
> if it makes the review easier.


The libgcc parts of this are fine.  Thanks.

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][stage1] Remove conditionals around free()

2023-03-01 Thread Ian Lance Taylor
Bernhard Reutner-Fischer  writes:

>  libgo/runtime/go-setenv.c|6 ++
>  libgo/runtime/go-unsetenv.c  |3 +--

Files in the libgo directory are mirrored from upstream sources, as
described in libgo/README.gcc.  Please don't change them in the gcc
repository.  Thanks.

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 bit

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 

  1   2   3   4   5   6   7   8   9   10   >