libbacktrace patch committed: Use __has_attribute for fallthrough

2024-07-18 Thread Ian Lance Taylor
This libbacktrace patch uses __has_attribute for fallthrough.  It also
fixes some FALLTHROUGH comments to use ATTRIBUTE_FALLTHROUGH.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian

* internal.h: Use __has_attribute to check for fallthrough
attribute.
* elf.c (elf_zstd_decompress): Use ATTRIBUTE_FALLTHROUGH rather
than a FALLTHROUGH comment.
58b219d3cf69a0464d3c74d43e4cc24117e64647
diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index e8d67feab6d..0040479143d 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -4848,25 +4848,25 @@ elf_zstd_decompress (const unsigned char *pin, size_t 
sin,
  {
  case 8:
*pout++ = *plit++;
-   /* FALLTHROUGH */
+   ATTRIBUTE_FALLTHROUGH;
  case 7:
*pout++ = *plit++;
-   /* FALLTHROUGH */
+   ATTRIBUTE_FALLTHROUGH;
  case 6:
*pout++ = *plit++;
-   /* FALLTHROUGH */
+   ATTRIBUTE_FALLTHROUGH;
  case 5:
*pout++ = *plit++;
-   /* FALLTHROUGH */
+   ATTRIBUTE_FALLTHROUGH;
  case 4:
*pout++ = *plit++;
-   /* FALLTHROUGH */
+   ATTRIBUTE_FALLTHROUGH;
  case 3:
*pout++ = *plit++;
-   /* FALLTHROUGH */
+   ATTRIBUTE_FALLTHROUGH;
  case 2:
*pout++ = *plit++;
-   /* FALLTHROUGH */
+   ATTRIBUTE_FALLTHROUGH;
  case 1:
*pout++ = *plit++;
break;
diff --git a/libbacktrace/internal.h b/libbacktrace/internal.h
index a119cda692f..fe2abe50b0f 100644
--- a/libbacktrace/internal.h
+++ b/libbacktrace/internal.h
@@ -56,6 +56,11 @@ POSSIBILITY OF SUCH DAMAGE.  */
 # endif
 #endif
 
+#ifdef __has_attribute
+# if __has_attribute(fallthrough)
+#  define ATTRIBUTE_FALLTHROUGH __attribute__ ((fallthrough))
+# endif
+#endif
 #ifndef ATTRIBUTE_FALLTHROUGH
 # if (GCC_VERSION >= 7000)
 #  define ATTRIBUTE_FALLTHROUGH __attribute__ ((__fallthrough__))


[gcc r15-2145] libbacktrace: use __has_attribute for fallthrough

2024-07-18 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:248e8530dd0298e9bbe099c651d5d9c4d2a0c0f9

commit r15-2145-g248e8530dd0298e9bbe099c651d5d9c4d2a0c0f9
Author: Ian Lance Taylor 
Date:   Thu Jul 18 11:34:09 2024 -0700

libbacktrace: use __has_attribute for fallthrough

Also convert some FALLTHROUGH comments to ATTRIBUTE_FALLTHROUGH.

* internal.h: Use __has_attribute to check for fallthrough
attribute.
* elf.c (elf_zstd_decompress): Use ATTRIBUTE_FALLTHROUGH rather
than a FALLTHROUGH comment.

Diff:
---
 libbacktrace/elf.c  | 14 +++---
 libbacktrace/internal.h |  5 +
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index e8d67feab6d3..0040479143d6 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -4848,25 +4848,25 @@ elf_zstd_decompress (const unsigned char *pin, size_t 
sin,
  {
  case 8:
*pout++ = *plit++;
-   /* FALLTHROUGH */
+   ATTRIBUTE_FALLTHROUGH;
  case 7:
*pout++ = *plit++;
-   /* FALLTHROUGH */
+   ATTRIBUTE_FALLTHROUGH;
  case 6:
*pout++ = *plit++;
-   /* FALLTHROUGH */
+   ATTRIBUTE_FALLTHROUGH;
  case 5:
*pout++ = *plit++;
-   /* FALLTHROUGH */
+   ATTRIBUTE_FALLTHROUGH;
  case 4:
*pout++ = *plit++;
-   /* FALLTHROUGH */
+   ATTRIBUTE_FALLTHROUGH;
  case 3:
*pout++ = *plit++;
-   /* FALLTHROUGH */
+   ATTRIBUTE_FALLTHROUGH;
  case 2:
*pout++ = *plit++;
-   /* FALLTHROUGH */
+   ATTRIBUTE_FALLTHROUGH;
  case 1:
*pout++ = *plit++;
break;
diff --git a/libbacktrace/internal.h b/libbacktrace/internal.h
index a119cda692fd..fe2abe50b0f3 100644
--- a/libbacktrace/internal.h
+++ b/libbacktrace/internal.h
@@ -56,6 +56,11 @@ POSSIBILITY OF SUCH DAMAGE.  */
 # endif
 #endif
 
+#ifdef __has_attribute
+# if __has_attribute(fallthrough)
+#  define ATTRIBUTE_FALLTHROUGH __attribute__ ((fallthrough))
+# endif
+#endif
 #ifndef ATTRIBUTE_FALLTHROUGH
 # if (GCC_VERSION >= 7000)
 #  define ATTRIBUTE_FALLTHROUGH __attribute__ ((__fallthrough__))


Re: libbacktrace patch committed: Better backtrace_print if no debug info

2024-07-17 Thread Ian Lance Taylor
On Wed, Jul 17, 2024 at 5:40 PM Ian Lance Taylor  wrote:
>
> This libbacktrace patch improves backtrace_print when there is no
> debug info.  It falls back to calling backtrace_syminfo, and uses that
> to print an offset from a symbol if it can.  This is a partial fix for
> https://github.com/ianlancetaylor/libbacktrace/issues/59.
> Bootstrapped and ran libbacktrace testsuite on x86_64-pc-linux-gnu.
> Committed to mainline.

And this patch corrects a bug in that patch.

Ian
c7c8bcdbb412c71c9522f7874d43a3bd9319b940
diff --git a/libbacktrace/print.c b/libbacktrace/print.c
index 70f5a93c49d..d4637af9a4f 100644
--- a/libbacktrace/print.c
+++ b/libbacktrace/print.c
@@ -77,7 +77,7 @@ static void print_syminfo_callback (void *data, uintptr_t pc,
 fprintf (pdata->f, "0x%lx ???\n\t%s+0x%lx:0\n",
 (unsigned long) pc,
 symname,
-pc - symval);
+(unsigned long) (pc - symval));
 }
 
 /* Print one level of a backtrace.  */


[gcc r15-2119] libbacktrace: add cast to avoid warning

2024-07-17 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:93c54caa64fee2a0fa7251d214cdf639b8d7899f

commit r15-2119-g93c54caa64fee2a0fa7251d214cdf639b8d7899f
Author: Ian Lance Taylor 
Date:   Wed Jul 17 17:58:56 2024 -0700

libbacktrace: add cast to avoid warning

* print.c (print_syminfo_callback): Add cast to avoid warning.

Diff:
---
 libbacktrace/print.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libbacktrace/print.c b/libbacktrace/print.c
index 70f5a93c49de..d4637af9a4fd 100644
--- a/libbacktrace/print.c
+++ b/libbacktrace/print.c
@@ -77,7 +77,7 @@ static void print_syminfo_callback (void *data, uintptr_t pc,
 fprintf (pdata->f, "0x%lx ???\n\t%s+0x%lx:0\n",
 (unsigned long) pc,
 symname,
-pc - symval);
+(unsigned long) (pc - symval));
 }
 
 /* Print one level of a backtrace.  */


libbacktrace patch committed: Better backtrace_print if no debug info

2024-07-17 Thread Ian Lance Taylor
This libbacktrace patch improves backtrace_print when there is no
debug info.  It falls back to calling backtrace_syminfo, and uses that
to print an offset from a symbol if it can.  This is a partial fix for
https://github.com/ianlancetaylor/libbacktrace/issues/59.
Bootstrapped and ran libbacktrace testsuite on x86_64-pc-linux-gnu.
Committed to mainline.

Ian

* print.c (print_syminfo_callback): New static function.
(print_callback): Call backtrace_syminfo if there is no function
or file name.
4dbb53eb10767d111228224ae3113aee0d4d6213
diff --git a/libbacktrace/print.c b/libbacktrace/print.c
index 3e61f02ebbc..70f5a93c49d 100644
--- a/libbacktrace/print.c
+++ b/libbacktrace/print.c
@@ -47,6 +47,39 @@ struct print_data
   FILE *f;
 };
 
+/* Print errors to stderr.  */
+
+static void
+error_callback (void *data, const char *msg, int errnum)
+{
+  struct print_data *pdata = (struct print_data *) data;
+
+  if (pdata->state->filename != NULL)
+fprintf (stderr, "%s: ", pdata->state->filename);
+  fprintf (stderr, "libbacktrace: %s", msg);
+  if (errnum > 0)
+fprintf (stderr, ": %s", strerror (errnum));
+  fputc ('\n', stderr);
+}
+
+/* Print one level of a backtrace if we couldn't get a file or function name.
+   Use syminfo to try to get a symbol name.  */
+
+static void print_syminfo_callback (void *data, uintptr_t pc,
+   const char *symname, uintptr_t symval,
+   uintptr_t symsize ATTRIBUTE_UNUSED)
+{
+  struct print_data *pdata = (struct print_data *) data;
+
+  if (symname == NULL)
+fprintf (pdata->f, "0x%lx ???\n\t???:0\n", (unsigned long) pc);
+  else
+fprintf (pdata->f, "0x%lx ???\n\t%s+0x%lx:0\n",
+(unsigned long) pc,
+symname,
+pc - symval);
+}
+
 /* Print one level of a backtrace.  */
 
 static int
@@ -55,6 +88,13 @@ print_callback (void *data, uintptr_t pc, const char 
*filename, int lineno,
 {
   struct print_data *pdata = (struct print_data *) data;
 
+  if (function == NULL && filename == NULL)
+{
+  backtrace_syminfo (pdata->state, pc, print_syminfo_callback,
+error_callback, data);
+  return 0;
+}
+
   fprintf (pdata->f, "0x%lx %s\n\t%s:%d\n",
   (unsigned long) pc,
   function == NULL ? "???" : function,
@@ -63,21 +103,6 @@ print_callback (void *data, uintptr_t pc, const char 
*filename, int lineno,
   return 0;
 }
 
-/* Print errors to stderr.  */
-
-static void
-error_callback (void *data, const char *msg, int errnum)
-{
-  struct print_data *pdata = (struct print_data *) data;
-
-  if (pdata->state->filename != NULL)
-fprintf (stderr, "%s: ", pdata->state->filename);
-  fprintf (stderr, "libbacktrace: %s", msg);
-  if (errnum > 0)
-fprintf (stderr, ": %s", strerror (errnum));
-  fputc ('\n', stderr);
-}
-
 /* Print a backtrace.  */
 
 void __attribute__((noinline))


[gcc r15-2116] libbacktrace: better backtrace_print when no debug info

2024-07-17 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:30875fa698e2ffed536f7a7d15a430e69a6a28ba

commit r15-2116-g30875fa698e2ffed536f7a7d15a430e69a6a28ba
Author: Ian Lance Taylor 
Date:   Wed Jul 17 17:36:25 2024 -0700

libbacktrace: better backtrace_print when no debug info

Fixes https://github.com/ianlancetaylor/libbacktrace/issues/59

* print.c (print_syminfo_callback): New static function.
(print_callback): Call backtrace_syminfo if there is no function
or file name.

Diff:
---
 libbacktrace/print.c | 55 ++--
 1 file changed, 40 insertions(+), 15 deletions(-)

diff --git a/libbacktrace/print.c b/libbacktrace/print.c
index 3e61f02ebbc2..70f5a93c49de 100644
--- a/libbacktrace/print.c
+++ b/libbacktrace/print.c
@@ -47,6 +47,39 @@ struct print_data
   FILE *f;
 };
 
+/* Print errors to stderr.  */
+
+static void
+error_callback (void *data, const char *msg, int errnum)
+{
+  struct print_data *pdata = (struct print_data *) data;
+
+  if (pdata->state->filename != NULL)
+fprintf (stderr, "%s: ", pdata->state->filename);
+  fprintf (stderr, "libbacktrace: %s", msg);
+  if (errnum > 0)
+fprintf (stderr, ": %s", strerror (errnum));
+  fputc ('\n', stderr);
+}
+
+/* Print one level of a backtrace if we couldn't get a file or function name.
+   Use syminfo to try to get a symbol name.  */
+
+static void print_syminfo_callback (void *data, uintptr_t pc,
+   const char *symname, uintptr_t symval,
+   uintptr_t symsize ATTRIBUTE_UNUSED)
+{
+  struct print_data *pdata = (struct print_data *) data;
+
+  if (symname == NULL)
+fprintf (pdata->f, "0x%lx ???\n\t???:0\n", (unsigned long) pc);
+  else
+fprintf (pdata->f, "0x%lx ???\n\t%s+0x%lx:0\n",
+(unsigned long) pc,
+symname,
+pc - symval);
+}
+
 /* Print one level of a backtrace.  */
 
 static int
@@ -55,6 +88,13 @@ print_callback (void *data, uintptr_t pc, const char 
*filename, int lineno,
 {
   struct print_data *pdata = (struct print_data *) data;
 
+  if (function == NULL && filename == NULL)
+{
+  backtrace_syminfo (pdata->state, pc, print_syminfo_callback,
+error_callback, data);
+  return 0;
+}
+
   fprintf (pdata->f, "0x%lx %s\n\t%s:%d\n",
   (unsigned long) pc,
   function == NULL ? "???" : function,
@@ -63,21 +103,6 @@ print_callback (void *data, uintptr_t pc, const char 
*filename, int lineno,
   return 0;
 }
 
-/* Print errors to stderr.  */
-
-static void
-error_callback (void *data, const char *msg, int errnum)
-{
-  struct print_data *pdata = (struct print_data *) data;
-
-  if (pdata->state->filename != NULL)
-fprintf (stderr, "%s: ", pdata->state->filename);
-  fprintf (stderr, "libbacktrace: %s", msg);
-  if (errnum > 0)
-fprintf (stderr, ": %s", strerror (errnum));
-  fputc ('\n', stderr);
-}
-
 /* Print a backtrace.  */
 
 void __attribute__((noinline))


libbacktrace patch committed: Mention dl_iterate_phdr in README

2024-07-17 Thread Ian Lance Taylor
This patch adds some notes about dl_iterate_phdr to the libbacktrace
README file.  In general dl_iterate_phdr is not async-signal-safe and
does call malloc, so programs that want to use libbacktrace functions
from a signal handler or within malloc must make an initiali
libbacktrace call in order to call dl_iterate_phdr.  Committed to
mainline.

Ian

* README: Add notes about dl_iterate_phdr.
14667f4cc51b6c59cf9e6c05f3bcac17df94ef10
diff --git a/libbacktrace/README b/libbacktrace/README
index 6225f92b855..6e6ec332fe2 100644
--- a/libbacktrace/README
+++ b/libbacktrace/README
@@ -5,8 +5,18 @@ The libbacktrace library may be linked into a program or 
library and
 used to produce symbolic backtraces.
 Sample uses would be to print a detailed backtrace when an error
 occurs or to gather detailed profiling information.
+
 In general the functions provided by this library are async-signal-safe,
 meaning that they may be safely called from a signal handler.
+That said, on systems that use dl_iterate_phdr, such as GNU/Linux,
+the first call to a libbacktrace function will call dl_iterate_phdr,
+which is not in general async-signal-safe.  Therefore, programs
+that call libbacktrace from a signal handler should ensure that they
+make an initial call from outside of a signal handler.
+Similar considerations apply when arranging to call libbacktrace
+from within malloc; dl_iterate_phdr can also call malloc,
+so make an initial call to a libbacktrace function outside of
+malloc before trying to call libbacktrace functions within malloc.
 
 The libbacktrace library is provided under a BSD license.
 See the source files for the exact license text.
@@ -20,7 +30,7 @@ will work.
 See the source file backtrace-supported.h.in for the macros that it
 defines.
 
-As of October 2020, libbacktrace supports ELF, PE/COFF, Mach-O, and
+As of July 2024, libbacktrace supports ELF, PE/COFF, Mach-O, and
 XCOFF executables with DWARF debugging information.
 In other words, it supports GNU/Linux, *BSD, macOS, Windows, and AIX.
 The library is written to make it straightforward to add support for


[gcc r15-2114] libbacktrace: add notes about dl_iterate_phdr to README

2024-07-17 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:a8b5ce1580b0774b19f0ca9cfc77c52095cdaa55

commit r15-2114-ga8b5ce1580b0774b19f0ca9cfc77c52095cdaa55
Author: Ian Lance Taylor 
Date:   Wed Jul 17 17:02:56 2024 -0700

libbacktrace: add notes about dl_iterate_phdr to README

* README: Add notes about dl_iterate_phdr.

Diff:
---
 libbacktrace/README | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/libbacktrace/README b/libbacktrace/README
index 6225f92b855e..6e6ec332fe2d 100644
--- a/libbacktrace/README
+++ b/libbacktrace/README
@@ -5,8 +5,18 @@ The libbacktrace library may be linked into a program or 
library and
 used to produce symbolic backtraces.
 Sample uses would be to print a detailed backtrace when an error
 occurs or to gather detailed profiling information.
+
 In general the functions provided by this library are async-signal-safe,
 meaning that they may be safely called from a signal handler.
+That said, on systems that use dl_iterate_phdr, such as GNU/Linux,
+the first call to a libbacktrace function will call dl_iterate_phdr,
+which is not in general async-signal-safe.  Therefore, programs
+that call libbacktrace from a signal handler should ensure that they
+make an initial call from outside of a signal handler.
+Similar considerations apply when arranging to call libbacktrace
+from within malloc; dl_iterate_phdr can also call malloc,
+so make an initial call to a libbacktrace function outside of
+malloc before trying to call libbacktrace functions within malloc.
 
 The libbacktrace library is provided under a BSD license.
 See the source files for the exact license text.
@@ -20,7 +30,7 @@ will work.
 See the source file backtrace-supported.h.in for the macros that it
 defines.
 
-As of October 2020, libbacktrace supports ELF, PE/COFF, Mach-O, and
+As of July 2024, libbacktrace supports ELF, PE/COFF, Mach-O, and
 XCOFF executables with DWARF debugging information.
 In other words, it supports GNU/Linux, *BSD, macOS, Windows, and AIX.
 The library is written to make it straightforward to add support for


Re: [RFC 1/2] libbacktrace: add FDPIC support

2024-07-16 Thread Ian Lance Taylor
On Tue, Jul 16, 2024 at 5:41 PM David Edelsohn  wrote:
>
> I believe that this patch broke bootstrap on AIX:
>
> /nasfarm/edelsohn/src/src/libbacktrace/xcoff.c: In function 'xcoff_add':
> /nasfarm/edelsohn/src/src/libbacktrace/xcoff.c:1309:40: error: incompatible 
> type for argument 2 of 'backtrace_dwarf_add'
>  1309 |   if (!backtrace_dwarf_add (state, base_address, _sections,
>   |^~~~
>   ||
>   |uintptr_t {aka long unsigned 
> int}
> In file included from /nasfarm/edelsohn/src/src/libbacktrace/xcoff.c:45:
> /nasfarm/edelsohn/src/src/libbacktrace/internal.h:363:66: note: expected 
> 'struct libbacktrace_base_address' but argument is of type 'uintptr_t' {aka 
> 'long unsigned int'}
>   363 | struct libbacktrace_base_address 
> base_address,
>   | 
> ~^~~~
> make[4]: *** [Makefile:1538: xcoff.lo] Error 1

Whoops, apologies.  This patch fixes the problem, and adds the missing
Makefile dependency that caused me to miss this problem earlier.
Committed to mainline.

Ian

* xcoff.c (struct xcoff_fileline_data): Change base_address field
to struct libbacktrace_base_address.
(xcoff_initialize_syminfo): Change base_address to struct
libbacktrace_base_address.  Use libbacktrace_add_base.
(xcoff_initialize_fileline): Likewise.
(xcoff_lookup_pc): Use libbacktrace_add_base.
(xcoff_add): Change base_address to struct
libbacktrace_base_address.
(xcoff_armem_add, xcoff_add_shared_libs): Likewise.
(backtrace_initialize): Likewise.
* Makefile.am (xcoff.lo): Remove unused target.
(xcoff_32.lo, xcoff_64.lo): New targets.
* Makefile.in: Regenerate.
f438299ef6860b8233ffe1c5fda7d63f2f6c56ae
diff --git a/libbacktrace/Makefile.am b/libbacktrace/Makefile.am
index 8215cfd9bd5..4a2bc038127 100644
--- a/libbacktrace/Makefile.am
+++ b/libbacktrace/Makefile.am
@@ -702,7 +702,8 @@ sort.lo: config.h backtrace.h internal.h
 stest.lo: config.h backtrace.h internal.h
 state.lo: config.h backtrace.h backtrace-supported.h internal.h
 unknown.lo: config.h backtrace.h internal.h
-xcoff.lo: config.h backtrace.h internal.h
+xcoff_32.lo: config.h backtrace.h internal.h
+xcoff_64.lo: config.h backtrace.h internal.h
 xztest.lo: config.h backtrace.h backtrace-supported.h internal.h testlib.h
 ztest.lo: config.h backtrace.h backtrace-supported.h internal.h testlib.h
 
diff --git a/libbacktrace/xcoff.c b/libbacktrace/xcoff.c
index e22f15dd5ce..01443c48401 100644
--- a/libbacktrace/xcoff.c
+++ b/libbacktrace/xcoff.c
@@ -385,7 +385,7 @@ struct xcoff_fileline_data
   size_t linenos_size;
   uint64_t lnnoptr0;
   /* Loader address.  */
-  uintptr_t base_address;
+  struct libbacktrace_base_address base_address;
 };
 
 /* Information we gather for the DWARF sections we care about.  */
@@ -586,7 +586,7 @@ xcoff_symname (const b_xcoff_syment *asym,
 
 static int
 xcoff_initialize_syminfo (struct backtrace_state *state,
- uintptr_t base_address,
+ struct libbacktrace_base_address base_address,
  const b_xcoff_syment *syms, size_t nsyms,
  const unsigned char *strtab, size_t strtab_size,
  backtrace_error_callback error_callback, void *data,
@@ -628,7 +628,8 @@ xcoff_initialize_syminfo (struct backtrace_state *state,
{
  const b_xcoff_auxent *aux = (const b_xcoff_auxent *) (asym + 1);
  xcoff_symbols[j].name = xcoff_symname (asym, strtab, strtab_size);
- xcoff_symbols[j].address = base_address + asym->n_value;
+ xcoff_symbols[j].address =
+   libbacktrace_add_base (asym->n_value, base_address);
  /* x_fsize will be 0 if there is no debug information.  */
  xcoff_symbols[j].size = aux->x_fcn.x_fsize;
  ++j;
@@ -766,7 +767,8 @@ xcoff_lookup_pc (struct backtrace_state *state 
ATTRIBUTE_UNUSED,
   lineno = (const b_xcoff_lineno *) lineptr;
   if (lineno->l_lnno == 0)
break;
-  if (pc <= fdata->base_address + lineno->l_addr.l_paddr)
+  if (pc <= libbacktrace_add_base (lineno->l_addr.l_paddr,
+  fdata->base_address))
break;
   match = lnnoptr;
   lnno = lineno->l_lnno;
@@ -860,7 +862,7 @@ xcoff_fileline (struct backtrace_state *state, uintptr_t pc,
 
 static int
 xcoff_initialize_fileline (struct backtrace_state *state,
-  uintptr_t base_address,
+  struct libbacktrace_base_address base_address,
   const b_xcoff_scnhdr *sects,
   const b_xcoff_syment *syms, size_t nsyms,
   const unsigned char *strtab, size_t strtab_size,
@@ -1001,7 +1003,7 @@ xcoff_initialize_fileline (struct backtrace_state *state,
fn->name = xcoff_symname 

[gcc r15-2082] libbacktrace: update xcoff.c for base_address changes

2024-07-16 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:f438299ef6860b8233ffe1c5fda7d63f2f6c56ae

commit r15-2082-gf438299ef6860b8233ffe1c5fda7d63f2f6c56ae
Author: Ian Lance Taylor 
Date:   Tue Jul 16 21:27:05 2024 -0700

libbacktrace: update xcoff.c for base_address changes

* xcoff.c (struct xcoff_fileline_data): Change base_address field
to struct libbacktrace_base_address.
(xcoff_initialize_syminfo): Change base_address to struct
libbacktrace_base_address.  Use libbacktrace_add_base.
(xcoff_initialize_fileline): Likewise.
(xcoff_lookup_pc): Use libbacktrace_add_base.
(xcoff_add): Change base_address to struct
libbacktrace_base_address.
(xcoff_armem_add, xcoff_add_shared_libs): Likewise.
(backtrace_initialize): Likewise.
* Makefile.am (xcoff.lo): Remove unused target.
(xcoff_32.lo, xcoff_64.lo): New targets.
* Makefile.in: Regenerate.

Diff:
---
 libbacktrace/Makefile.am |  3 ++-
 libbacktrace/Makefile.in |  3 ++-
 libbacktrace/xcoff.c | 46 +++---
 3 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/libbacktrace/Makefile.am b/libbacktrace/Makefile.am
index 8215cfd9bd5b..4a2bc038127e 100644
--- a/libbacktrace/Makefile.am
+++ b/libbacktrace/Makefile.am
@@ -702,7 +702,8 @@ sort.lo: config.h backtrace.h internal.h
 stest.lo: config.h backtrace.h internal.h
 state.lo: config.h backtrace.h backtrace-supported.h internal.h
 unknown.lo: config.h backtrace.h internal.h
-xcoff.lo: config.h backtrace.h internal.h
+xcoff_32.lo: config.h backtrace.h internal.h
+xcoff_64.lo: config.h backtrace.h internal.h
 xztest.lo: config.h backtrace.h backtrace-supported.h internal.h testlib.h
 ztest.lo: config.h backtrace.h backtrace-supported.h internal.h testlib.h
 
diff --git a/libbacktrace/Makefile.in b/libbacktrace/Makefile.in
index 7241e70002dd..7b61bbffe5df 100644
--- a/libbacktrace/Makefile.in
+++ b/libbacktrace/Makefile.in
@@ -2772,7 +2772,8 @@ sort.lo: config.h backtrace.h internal.h
 stest.lo: config.h backtrace.h internal.h
 state.lo: config.h backtrace.h backtrace-supported.h internal.h
 unknown.lo: config.h backtrace.h internal.h
-xcoff.lo: config.h backtrace.h internal.h
+xcoff_32.lo: config.h backtrace.h internal.h
+xcoff_64.lo: config.h backtrace.h internal.h
 xztest.lo: config.h backtrace.h backtrace-supported.h internal.h testlib.h
 ztest.lo: config.h backtrace.h backtrace-supported.h internal.h testlib.h
 
diff --git a/libbacktrace/xcoff.c b/libbacktrace/xcoff.c
index e22f15dd5cec..01443c48401b 100644
--- a/libbacktrace/xcoff.c
+++ b/libbacktrace/xcoff.c
@@ -385,7 +385,7 @@ struct xcoff_fileline_data
   size_t linenos_size;
   uint64_t lnnoptr0;
   /* Loader address.  */
-  uintptr_t base_address;
+  struct libbacktrace_base_address base_address;
 };
 
 /* Information we gather for the DWARF sections we care about.  */
@@ -586,7 +586,7 @@ xcoff_symname (const b_xcoff_syment *asym,
 
 static int
 xcoff_initialize_syminfo (struct backtrace_state *state,
- uintptr_t base_address,
+ struct libbacktrace_base_address base_address,
  const b_xcoff_syment *syms, size_t nsyms,
  const unsigned char *strtab, size_t strtab_size,
  backtrace_error_callback error_callback, void *data,
@@ -628,7 +628,8 @@ xcoff_initialize_syminfo (struct backtrace_state *state,
{
  const b_xcoff_auxent *aux = (const b_xcoff_auxent *) (asym + 1);
  xcoff_symbols[j].name = xcoff_symname (asym, strtab, strtab_size);
- xcoff_symbols[j].address = base_address + asym->n_value;
+ xcoff_symbols[j].address =
+   libbacktrace_add_base (asym->n_value, base_address);
  /* x_fsize will be 0 if there is no debug information.  */
  xcoff_symbols[j].size = aux->x_fcn.x_fsize;
  ++j;
@@ -766,7 +767,8 @@ xcoff_lookup_pc (struct backtrace_state *state 
ATTRIBUTE_UNUSED,
   lineno = (const b_xcoff_lineno *) lineptr;
   if (lineno->l_lnno == 0)
break;
-  if (pc <= fdata->base_address + lineno->l_addr.l_paddr)
+  if (pc <= libbacktrace_add_base (lineno->l_addr.l_paddr,
+  fdata->base_address))
break;
   match = lnnoptr;
   lnno = lineno->l_lnno;
@@ -860,7 +862,7 @@ xcoff_fileline (struct backtrace_state *state, uintptr_t pc,
 
 static int
 xcoff_initialize_fileline (struct backtrace_state *state,
-  uintptr_t base_address,
+  struct libbacktrace_base_address base_address,
   const b_xcoff_scnhdr *sects,
   const b_xcoff_syment *syms, size_t nsyms,
   const unsigned char *strtab, size_t strtab_size,
@@ -1001,7 +1003,7 @@ xcoff_initialize_fileline (struct backt

[gcc r15-2051] libbacktrace: support FDPIC

2024-07-15 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:c6803cdaba7a7bf933e52cd36f901430253cc2b0

commit r15-2051-gc6803cdaba7a7bf933e52cd36f901430253cc2b0
Author: Ian Lance Taylor 
Date:   Mon Jul 15 17:27:18 2024 -0700

libbacktrace: support FDPIC

Based on patch by Max Filippov.

* internal.h: If FDPIC, #include  and/or .
(libbacktrace_using_fdpic): Define.
(struct libbacktrace_base_address): Define.
(libbacktrace_add_base): Define.
(backtrace_dwarf_add): Change base_address to struct
libbacktrace_base_address.
* dwarf.c (struct dwarf_data): Change base_address to struct
libbacktrace_base_address.
(add_ranges, find_address_ranges, build_ddress_map): Likewise.
(build_dwarf_data, build_dwarf_add): Likewise.
(add_low_high_range): Change base_address to struct
libbacktrace_base_address.  Use libbacktrace_add_base.
(add_ranges_from_ranges, add_ranges_from_rnglists): Likewise.
(add_line): Use libbacktrace_add_base.
* elf.c (elf_initialize_syminfo): Change base_address to struct
libbacktrace_base_address.  Use libbacktrace_add_base.
(elf_add): Change base_address to struct
libbacktrace_base_address.
(phdr_callback): Likewise.  Initialize base_address.m.
(backtrace_initialize): If using FDPIC, don't call elf_add with
main executable; always use dl_iterate_phdr.
* macho.c (macho_add_symtab): Change base_address to struct
libbacktrace_base_address.  Use libbacktrace_add_base.
(macho_syminfo): Change base_address to struct
libbacktrace_base_address.
(macho_add_fat, macho_add_dsym, macho_add): Likewise.
(backtrace_initialize): Likewise.  Initialize base_address.m.
* pecoff.c (coff_initialize_syminfo): Change base_address to
struct libbacktrace_base_address.  Use libbacktrace_add_base.
(coff_add): Change base_address to struct
libbacktrace_base_address.  Initialize base_address.m.

Diff:
---
 libbacktrace/dwarf.c| 63 +++--
 libbacktrace/elf.c  | 31 +---
 libbacktrace/internal.h | 36 +++-
 libbacktrace/macho.c| 25 
 libbacktrace/pecoff.c   | 30 ---
 5 files changed, 123 insertions(+), 62 deletions(-)

diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c
index cc36a0a2990d..96ffc4cc481b 100644
--- a/libbacktrace/dwarf.c
+++ b/libbacktrace/dwarf.c
@@ -388,8 +388,8 @@ struct dwarf_data
   struct dwarf_data *next;
   /* The data for .gnu_debugaltlink.  */
   struct dwarf_data *altlink;
-  /* The base address for this file.  */
-  uintptr_t base_address;
+  /* The base address mapping for this file.  */
+  struct libbacktrace_base_address base_address;
   /* A sorted list of address ranges.  */
   struct unit_addrs *addrs;
   /* Number of address ranges in list.  */
@@ -1610,8 +1610,9 @@ update_pcrange (const struct attr* attr, const struct 
attr_val* val,
 static int
 add_low_high_range (struct backtrace_state *state,
const struct dwarf_sections *dwarf_sections,
-   uintptr_t base_address, int is_bigendian,
-   struct unit *u, const struct pcrange *pcrange,
+   struct libbacktrace_base_address base_address,
+   int is_bigendian, struct unit *u,
+   const struct pcrange *pcrange,
int (*add_range) (struct backtrace_state *state,
  void *rdata, uintptr_t lowpc,
  uintptr_t highpc,
@@ -1646,8 +1647,8 @@ add_low_high_range (struct backtrace_state *state,
 
   /* Add in the base address of the module when recording PC values,
  so that we can look up the PC directly.  */
-  lowpc += base_address;
-  highpc += base_address;
+  lowpc = libbacktrace_add_base (lowpc, base_address);
+  highpc = libbacktrace_add_base (highpc, base_address);
 
   return add_range (state, rdata, lowpc, highpc, error_callback, data, vec);
 }
@@ -1659,7 +1660,7 @@ static int
 add_ranges_from_ranges (
 struct backtrace_state *state,
 const struct dwarf_sections *dwarf_sections,
-uintptr_t base_address, int is_bigendian,
+struct libbacktrace_base_address base_address, int is_bigendian,
 struct unit *u, uintptr_t base,
 const struct pcrange *pcrange,
 int (*add_range) (struct backtrace_state *state, void *rdata,
@@ -1705,10 +1706,11 @@ add_ranges_from_ranges (
base = (uintptr_t) high;
   else
{
- if (!add_range (state, rdata,
- (uintptr_t) low + base + base_address,
- (uintptr_t) high + base + base_address,
- error_callback, data, vec

Re: [RFC 1/2] libbacktrace: add FDPIC support

2024-07-15 Thread Ian Lance Taylor
On Mon, Jul 15, 2024 at 3:17 PM Max Filippov  wrote:
>
> On Mon, Jul 15, 2024 at 10:21:18AM -0700, Ian Lance Taylor wrote:
> > Can you see whether this patch works for FDPIC support?  This is based
> > on your patch but has various changes.  Thanks.
>
> Yes, it is working.

Thanks for testing.  Committed to mainline with this ChangeLog entry:

* internal.h: If FDPIC, #include  and/or .
(libbacktrace_using_fdpic): Define.
(struct libbacktrace_base_address): Define.
(libbacktrace_add_base): Define.
(backtrace_dwarf_add): Change base_address to struct
libbacktrace_base_address.
* dwarf.c (struct dwarf_data): Change base_address to struct
libbacktrace_base_address.
(add_ranges, find_address_ranges, build_ddress_map): Likewise.
(build_dwarf_data, build_dwarf_add): Likewise.
(add_low_high_range): Change base_address to struct
libbacktrace_base_address.  Use libbacktrace_add_base.
(add_ranges_from_ranges, add_ranges_from_rnglists): Likewise.
(add_line): Use libbacktrace_add_base.
* elf.c (elf_initialize_syminfo): Change base_address to struct
libbacktrace_base_address.  Use libbacktrace_add_base.
(elf_add): Change base_address to struct
libbacktrace_base_address.
(phdr_callback): Likewise.  Initialize base_address.m.
(backtrace_initialize): If using FDPIC, don't call elf_add with
main executable; always use dl_iterate_phdr.
* macho.c (macho_add_symtab): Change base_address to struct
libbacktrace_base_address.  Use libbacktrace_add_base.
(macho_syminfo): Change base_address to struct
libbacktrace_base_address.
(macho_add_fat, macho_add_dsym, macho_add): Likewise.
(backtrace_initialize): Likewise.  Initialize base_address.m.
* pecoff.c (coff_initialize_syminfo): Change base_address to
struct libbacktrace_base_address.  Use libbacktrace_add_base.
(coff_add): Change base_address to struct
libbacktrace_base_address.  Initialize base_address.m.

Ian


Re: [RFC 1/2] libbacktrace: add FDPIC support

2024-07-15 Thread Ian Lance Taylor
Can you see whether this patch works for FDPIC support?  This is based
on your patch but has various changes.  Thanks.

Ian
diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c
index cc36a0a2990..96ffc4cc481 100644
--- a/libbacktrace/dwarf.c
+++ b/libbacktrace/dwarf.c
@@ -388,8 +388,8 @@ struct dwarf_data
   struct dwarf_data *next;
   /* The data for .gnu_debugaltlink.  */
   struct dwarf_data *altlink;
-  /* The base address for this file.  */
-  uintptr_t base_address;
+  /* The base address mapping for this file.  */
+  struct libbacktrace_base_address base_address;
   /* A sorted list of address ranges.  */
   struct unit_addrs *addrs;
   /* Number of address ranges in list.  */
@@ -1610,8 +1610,9 @@ update_pcrange (const struct attr* attr, const struct 
attr_val* val,
 static int
 add_low_high_range (struct backtrace_state *state,
const struct dwarf_sections *dwarf_sections,
-   uintptr_t base_address, int is_bigendian,
-   struct unit *u, const struct pcrange *pcrange,
+   struct libbacktrace_base_address base_address,
+   int is_bigendian, struct unit *u,
+   const struct pcrange *pcrange,
int (*add_range) (struct backtrace_state *state,
  void *rdata, uintptr_t lowpc,
  uintptr_t highpc,
@@ -1646,8 +1647,8 @@ add_low_high_range (struct backtrace_state *state,
 
   /* Add in the base address of the module when recording PC values,
  so that we can look up the PC directly.  */
-  lowpc += base_address;
-  highpc += base_address;
+  lowpc = libbacktrace_add_base (lowpc, base_address);
+  highpc = libbacktrace_add_base (highpc, base_address);
 
   return add_range (state, rdata, lowpc, highpc, error_callback, data, vec);
 }
@@ -1659,7 +1660,7 @@ static int
 add_ranges_from_ranges (
 struct backtrace_state *state,
 const struct dwarf_sections *dwarf_sections,
-uintptr_t base_address, int is_bigendian,
+struct libbacktrace_base_address base_address, int is_bigendian,
 struct unit *u, uintptr_t base,
 const struct pcrange *pcrange,
 int (*add_range) (struct backtrace_state *state, void *rdata,
@@ -1705,10 +1706,11 @@ add_ranges_from_ranges (
base = (uintptr_t) high;
   else
{
- if (!add_range (state, rdata,
- (uintptr_t) low + base + base_address,
- (uintptr_t) high + base + base_address,
- error_callback, data, vec))
+ uintptr_t rl, rh;
+
+ rl = libbacktrace_add_base ((uintptr_t) low + base, base_address);
+ rh = libbacktrace_add_base ((uintptr_t) high + base, base_address);
+ if (!add_range (state, rdata, rl, rh, error_callback, data, vec))
return 0;
}
 }
@@ -1726,7 +1728,7 @@ static int
 add_ranges_from_rnglists (
 struct backtrace_state *state,
 const struct dwarf_sections *dwarf_sections,
-uintptr_t base_address, int is_bigendian,
+struct libbacktrace_base_address base_address, int is_bigendian,
 struct unit *u, uintptr_t base,
 const struct pcrange *pcrange,
 int (*add_range) (struct backtrace_state *state, void *rdata,
@@ -1809,9 +1811,10 @@ add_ranges_from_rnglists (
 u->addrsize, is_bigendian, index,
 error_callback, data, ))
  return 0;
-   if (!add_range (state, rdata, low + base_address,
-   high + base_address, error_callback, data,
-   vec))
+   if (!add_range (state, rdata,
+   libbacktrace_add_base (low, base_address),
+   libbacktrace_add_base (high, base_address),
+   error_callback, data, vec))
  return 0;
  }
  break;
@@ -1828,7 +1831,7 @@ add_ranges_from_rnglists (
 error_callback, data, ))
  return 0;
length = read_uleb128 (_buf);
-   low += base_address;
+   low = libbacktrace_add_base (low, base_address);
if (!add_range (state, rdata, low, low + length,
error_callback, data, vec))
  return 0;
@@ -1842,8 +1845,9 @@ add_ranges_from_rnglists (
 
low = read_uleb128 (_buf);
high = read_uleb128 (_buf);
-   if (!add_range (state, rdata, low + base + base_address,
-   high + base + base_address,
+   if (!add_range (state, rdata,
+   libbacktrace_add_base (low + base, base_address),
+   libbacktrace_add_base (high + base, base_address),
error_callback, data, vec))
  return 0;
  }
@@ -1860,9 +1864,10 @@ add_ranges_from_rnglists (
 
low = 

Re: [RFC 1/2] libbacktrace: add FDPIC support

2024-07-15 Thread Ian Lance Taylor
On Sat, Jul 13, 2024 at 7:52 PM Max Filippov  wrote:
>
> On Wed, Jul 10, 2024 at 12:49 PM Ian Lance Taylor  wrote:
> > On Sun, May 26, 2024 at 11:51 PM Max Filippov  wrote:
> > > diff --git a/libbacktrace/internal.h b/libbacktrace/internal.h
> > > index 4fa0af8cb6c9..456911166026 100644
> > > --- a/libbacktrace/internal.h
> > > +++ b/libbacktrace/internal.h
> > > @@ -323,10 +323,22 @@ struct dwarf_sections
> > >
> > >  struct dwarf_data;
> > >
> > > +#if defined (HAVE_DL_ITERATE_PHDR) && defined (__FDPIC__)
> > > +typedef struct elf32_fdpic_loadaddr base_address_type;
> > > +#define __RELOC_UINTPTR(ptr, base) ((uintptr_t)__RELOC_POINTER (ptr, 
> > > base))
> > > +#define no_base_address ((struct elf32_fdpic_loadaddr){0})
> > > +#else
> > > +typedef uintptr_t base_address_type;
> > > +#define __RELOC_POINTER(ptr, base) ((ptr) + (base))
> > > +#define __RELOC_UINTPTR(ptr, base) ((uintptr_t)__RELOC_POINTER (ptr, 
> > > base))
> > > +#define no_base_address ((uintptr_t)0)
> > > +#endif
> > > +
> > > +
> >
> > When I look at the uClibc sources, I don't understand how this works.
> > This sets no_base_address to have a zero map field.  But
> > __RELOC_POINTER will crash when given a zero map field.
>
> That's right. But __RELOC_POINTER should never be called for base
> address set to no_base_address, that's what the following hunk ensures:
>
> --->8---
> @@ -6636,9 +6636,15 @@ elf_add (struct backtrace_state *state, const
> char *filename, int descriptor,
>
>   /* If the executable is ET_DYN, it is either a PIE, or we are running
>  directly a shared library with .interp.  We need to wait for
> - dl_iterate_phdr in that case to determine the actual base_address.  */
> + dl_iterate_phdr in that case to determine the actual base_address.
> + In case of FDPIC we always need the actual base_address.  */
> +#ifndef __FDPIC__
>   if (exe && ehdr.e_type == ET_DYN)
> return -1;
> +#else
> +  if (exe)
> +return -1;
> +#endif
>
>   shoff = ehdr.e_shoff;
>   shnum = ehdr.e_shnum;

I see.  The code is using dl_iterate_phdr for everything.  This is a
confusing execution flow.  It means that we do some pointless work.

Ian


[gcc r15-1988] libbacktrace: avoid infinite recursion

2024-07-11 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:bf406a53693ef664b7ee0c77c4940a71a83866c5

commit r15-1988-gbf406a53693ef664b7ee0c77c4940a71a83866c5
Author: Ian Lance Taylor 
Date:   Thu Jul 11 19:29:04 2024 -0700

libbacktrace: avoid infinite recursion

We could get an infinite recursion in an odd case in which a
.gnu_debugdata section was added to a debug file, and mini_debuginfo
was put into the debug file, and the debug file was put into a
/usr/lib/debug directory to be found by build ID.  This combination
doesn't really make sense but we shouldn't get an infinite recursion.

* elf.c (elf_add): Don't use .gnu_debugdata if we are already
reading a debuginfo file.
* Makefile.am (m2test_*): New test targets.
(CHECK_PROGRAMS): Add m2test.
(MAKETESTS): Add m2test_minidebug2.
(%_minidebug2): New pattern.
(CLEANFILES): Remove minidebug2 files.
* Makefile.in: Regenerate.

Diff:
---
 libbacktrace/Makefile.am |  36 -
 libbacktrace/Makefile.in | 137 +--
 libbacktrace/elf.c   |   3 +-
 3 files changed, 134 insertions(+), 42 deletions(-)

diff --git a/libbacktrace/Makefile.am b/libbacktrace/Makefile.am
index bed42c293295..8215cfd9bd5b 100644
--- a/libbacktrace/Makefile.am
+++ b/libbacktrace/Makefile.am
@@ -594,6 +594,39 @@ MAKETESTS += mtest_minidebug
$(OBJCOPY) --add-section .gnu_debugdata=$<.mdbg.xz $<.strip
mv $<.strip $@
 
+if HAVE_ELF
+if HAVE_BUILDID
+if HAVE_OBJCOPY_DEBUGLINK
+
+m2test_SOURCES = $(mtest_SOURCES)
+m2test_CFLAGS = $(libbacktrace_TEST_CFLAGS) -O
+m2test_LDFLAGS = -Wl,--build-id $(libbacktrace_testing_ldflags)
+m2test_LDADD = libbacktrace_elf_for_test.la
+
+check_PROGRAMS += m2test
+MAKETESTS += m2test_minidebug2
+
+# minidebug2 is like minidebug but also adds the gnu_debugdata section
+# to the debug file, and uses a build ID file.  There is no reason to do
+# this but it was causing an infinite recursion.
+%_minidebug2: %
+   $(NM) -D $< -P --defined-only | $(AWK) '{ print $$1 }' | sort > 
$<.dsyms2
+   $(NM) $< -P --defined-only | $(AWK) '{ if ($$2 == "T" || $$2 == "t" || 
$$2 == "D") print $$1 }' | sort > $<.fsyms2
+   $(COMM) -13 $<.dsyms2 $<.fsyms2 > $<.keepsyms2
+   $(OBJCOPY) --only-keep-debug $< $<.dbg2
+   $(OBJCOPY) -S --remove-section .gdb_index --remove-section .comment 
--keep-symbols=$<.keepsyms2 $<.dbg2 $<.mdbg2
+   $(OBJCOPY) --strip-all --remove-section ..comment $< $<.strip2
+   rm -f $<.mdbg2.xz
+   $(XZ) $<.mdbg2
+   $(OBJCOPY) --add-section .gnu_debugdata=$<.mdbg2.xz $<.dbg2
+   $(OBJCOPY) --add-section .gnu_debugdata=$<.mdbg2.xz $<.strip2
+   $(SHELL) ./install-debuginfo-for-buildid.sh $(TEST_BUILD_ID_DIR) $<.dbg2
+   mv $<.strip2 $@
+
+endif HAVE_OBJCOPY_DEBUGLINK
+endif HAVE_BUILDID
+endif HAVE_ELF
+
 endif HAVE_MINIDEBUG
 
 endif NATIVE
@@ -629,7 +662,8 @@ TESTS += $(MAKETESTS) $(BUILDTESTS)
 CLEANFILES = \
$(MAKETESTS) $(BUILDTESTS) *.debug elf_for_test.c edtest2_build.c \
gen_edtest2_build \
-   *.dsyms *.fsyms *.keepsyms *.dbg *.mdbg *.mdbg.xz *.strip
+   *.dsyms *.fsyms *.keepsyms *.dbg *.mdbg *.mdbg.xz *.strip \
+   *.dsyms2 *.fsyms2 *.keepsyms2 *.dbg2 *.mdbg2 *.mdbg2.xz *.strip2
 
 clean-local:
-rm -rf usr
diff --git a/libbacktrace/Makefile.in b/libbacktrace/Makefile.in
index 0260ca81798b..7241e70002dd 100644
--- a/libbacktrace/Makefile.in
+++ b/libbacktrace/Makefile.in
@@ -121,8 +121,8 @@ build_triplet = @build@
 host_triplet = @host@
 target_triplet = @target@
 check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
-   $(am__EXEEXT_16)
-TESTS = $(am__append_4) $(MAKETESTS) $(am__EXEEXT_16)
+   $(am__EXEEXT_4) $(am__EXEEXT_17)
+TESTS = $(am__append_4) $(MAKETESTS) $(am__EXEEXT_17)
 @HAVE_ELF_TRUE@@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@am__append_1 = 
libbacktrace_elf_for_test.la
 @NATIVE_TRUE@am__append_2 = test_elf_32 test_elf_64 test_macho \
 @NATIVE_TRUE@  test_xcoff_32 test_xcoff_64 test_pecoff \
@@ -163,9 +163,11 @@ TESTS = $(am__append_4) $(MAKETESTS) $(am__EXEEXT_16)
 @NATIVE_TRUE@am__append_28 = mtest
 @NATIVE_TRUE@@USE_DSYMUTIL_TRUE@am__append_29 = mtest.dSYM
 @HAVE_MINIDEBUG_TRUE@@NATIVE_TRUE@am__append_30 = mtest_minidebug
-@HAVE_ELF_TRUE@@HAVE_LIBLZMA_TRUE@am__append_31 = -llzma
-@HAVE_ELF_TRUE@@HAVE_LIBLZMA_TRUE@am__append_32 = -llzma
-@HAVE_ELF_TRUE@am__append_33 = xztest xztest_alloc
+@HAVE_BUILDID_TRUE@@HAVE_ELF_TRUE@@HAVE_MINIDEBUG_TRUE@@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@am__append_31
 = m2test
+@HAVE_BUILDID_TRUE@@HAVE_ELF_TRUE@@HAVE_MINIDEBUG_TRUE@@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@am__append_32
 = m2test_minidebug2
+@HAVE_ELF_TRUE@@HAVE_LIBLZMA_TRUE@am__append_33 = -llzma
+@HAVE_ELF_TRUE@@HAVE_LIBLZMA_TRUE@am__append_34 = -llzma
+@HAVE_EL

libbacktrace patch committed: Avoid infinite recursion

2024-07-11 Thread Ian Lance Taylor
libbacktrace could get an infinite recursion in an odd case in which a
.gnu_debugdata section was added to a debug file, and mini_debuginfo
was put into the debug file, and the debug file was put into a
/usr/lib/debug directory to be found by build ID.  This combination
doesn't really make sense but we shouldn't get an infinite recursion.
This patch fixes the problem.  Bootstrapped and ran libbacktrace tests
on x86_64-pc-linux-gnu.  Committed to mainline.

Ian

* elf.c (elf_add): Don't use .gnu_debugdata if we are already
reading a debuginfo file.
* Makefile.am (m2test_*): New test targets.
(CHECK_PROGRAMS): Add m2test.
(MAKETESTS): Add m2test_minidebug2.
(%_minidebug2): New pattern.
(CLEANFILES): Remove minidebug2 files.
* Makefile.in: Regenerate.
8a3a34665210105a89b14f380c3bec780c209046
diff --git a/libbacktrace/Makefile.am b/libbacktrace/Makefile.am
index bed42c29329..8215cfd9bd5 100644
--- a/libbacktrace/Makefile.am
+++ b/libbacktrace/Makefile.am
@@ -594,6 +594,39 @@ MAKETESTS += mtest_minidebug
$(OBJCOPY) --add-section .gnu_debugdata=$<.mdbg.xz $<.strip
mv $<.strip $@
 
+if HAVE_ELF
+if HAVE_BUILDID
+if HAVE_OBJCOPY_DEBUGLINK
+
+m2test_SOURCES = $(mtest_SOURCES)
+m2test_CFLAGS = $(libbacktrace_TEST_CFLAGS) -O
+m2test_LDFLAGS = -Wl,--build-id $(libbacktrace_testing_ldflags)
+m2test_LDADD = libbacktrace_elf_for_test.la
+
+check_PROGRAMS += m2test
+MAKETESTS += m2test_minidebug2
+
+# minidebug2 is like minidebug but also adds the gnu_debugdata section
+# to the debug file, and uses a build ID file.  There is no reason to do
+# this but it was causing an infinite recursion.
+%_minidebug2: %
+   $(NM) -D $< -P --defined-only | $(AWK) '{ print $$1 }' | sort > 
$<.dsyms2
+   $(NM) $< -P --defined-only | $(AWK) '{ if ($$2 == "T" || $$2 == "t" || 
$$2 == "D") print $$1 }' | sort > $<.fsyms2
+   $(COMM) -13 $<.dsyms2 $<.fsyms2 > $<.keepsyms2
+   $(OBJCOPY) --only-keep-debug $< $<.dbg2
+   $(OBJCOPY) -S --remove-section .gdb_index --remove-section .comment 
--keep-symbols=$<.keepsyms2 $<.dbg2 $<.mdbg2
+   $(OBJCOPY) --strip-all --remove-section ..comment $< $<.strip2
+   rm -f $<.mdbg2.xz
+   $(XZ) $<.mdbg2
+   $(OBJCOPY) --add-section .gnu_debugdata=$<.mdbg2.xz $<.dbg2
+   $(OBJCOPY) --add-section .gnu_debugdata=$<.mdbg2.xz $<.strip2
+   $(SHELL) ./install-debuginfo-for-buildid.sh $(TEST_BUILD_ID_DIR) $<.dbg2
+   mv $<.strip2 $@
+
+endif HAVE_OBJCOPY_DEBUGLINK
+endif HAVE_BUILDID
+endif HAVE_ELF
+
 endif HAVE_MINIDEBUG
 
 endif NATIVE
@@ -629,7 +662,8 @@ TESTS += $(MAKETESTS) $(BUILDTESTS)
 CLEANFILES = \
$(MAKETESTS) $(BUILDTESTS) *.debug elf_for_test.c edtest2_build.c \
gen_edtest2_build \
-   *.dsyms *.fsyms *.keepsyms *.dbg *.mdbg *.mdbg.xz *.strip
+   *.dsyms *.fsyms *.keepsyms *.dbg *.mdbg *.mdbg.xz *.strip \
+   *.dsyms2 *.fsyms2 *.keepsyms2 *.dbg2 *.mdbg2 *.mdbg2.xz *.strip2
 
 clean-local:
-rm -rf usr
diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index e6a66c0db90..107c96892a0 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -6841,7 +6841,8 @@ elf_add (struct backtrace_state *state, const char 
*filename, int descriptor,
}
}
 
-  if (!gnu_debugdata_view_valid
+  if (!debuginfo
+ && !gnu_debugdata_view_valid
  && strcmp (name, ".gnu_debugdata") == 0)
{
  if (!elf_get_view (state, descriptor, memory, memory_size,


[gcc r15-1985] libbacktrace: don't fail if symbol size is unknown

2024-07-11 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:d7318f4cf89c2a934fcd1f87d711081285fad242

commit r15-1985-gd7318f4cf89c2a934fcd1f87d711081285fad242
Author: Ian Lance Taylor 
Date:   Thu Jul 11 17:58:17 2024 -0700

libbacktrace: don't fail if symbol size is unknown

* btest.c (test5): Don't fail if symbol size is 0.
* mtest.c (test5): Likewise.

Diff:
---
 libbacktrace/btest.c | 2 +-
 libbacktrace/mtest.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libbacktrace/btest.c b/libbacktrace/btest.c
index c4b2db2cce2f..3b603f643fa7 100644
--- a/libbacktrace/btest.c
+++ b/libbacktrace/btest.c
@@ -440,7 +440,7 @@ test5 (void)
   (unsigned long) (uintptr_t) );
  symdata.failed = 1;
}
-  else if (symdata.size != sizeof (global))
+  else if (symdata.size != sizeof (global) && symdata.size != 0)
{
  fprintf (stderr,
   "test5: unexpected syminfo size got %lx expected %lx\n",
diff --git a/libbacktrace/mtest.c b/libbacktrace/mtest.c
index f793391653dc..5ec43c7bbcea 100644
--- a/libbacktrace/mtest.c
+++ b/libbacktrace/mtest.c
@@ -373,7 +373,7 @@ test5 (void)
   (unsigned long) (uintptr_t) );
  symdata.failed = 1;
}
-  else if (symdata.size != sizeof (global))
+  else if (symdata.size != sizeof (global) && symdata.size != 0)
{
  fprintf (stderr,
   "test5: unexpected syminfo size got %lx expected %lx\n",


libbacktrace patch committed: Don't fail if symbol size is unknown

2024-07-11 Thread Ian Lance Taylor
Mach-O and PE/COFF don't record symbol sizes in the symbol table.
Adjust the libbacktrace testsuite so that it doesn't fail if the
symbol size is unknown, only if it is incorrect.  Ran libbacktrace
tests on macOS on the compile farm and on x86_64-pc-linux-gnu.
Committed to mainline.

Ian

* btest.c (test5): Don't fail if symbol size is 0.
* mtest.c (test5): Likewise.
d7318f4cf89c2a934fcd1f87d711081285fad242
diff --git a/libbacktrace/btest.c b/libbacktrace/btest.c
index c4b2db2cce2..3b603f643fa 100644
--- a/libbacktrace/btest.c
+++ b/libbacktrace/btest.c
@@ -440,7 +440,7 @@ test5 (void)
   (unsigned long) (uintptr_t) );
  symdata.failed = 1;
}
-  else if (symdata.size != sizeof (global))
+  else if (symdata.size != sizeof (global) && symdata.size != 0)
{
  fprintf (stderr,
   "test5: unexpected syminfo size got %lx expected %lx\n",
diff --git a/libbacktrace/mtest.c b/libbacktrace/mtest.c
index f793391653d..5ec43c7bbce 100644
--- a/libbacktrace/mtest.c
+++ b/libbacktrace/mtest.c
@@ -373,7 +373,7 @@ test5 (void)
   (unsigned long) (uintptr_t) );
  symdata.failed = 1;
}
-  else if (symdata.size != sizeof (global))
+  else if (symdata.size != sizeof (global) && symdata.size != 0)
{
  fprintf (stderr,
   "test5: unexpected syminfo size got %lx expected %lx\n",


libbacktrace patch committed: Correctly gather Mach-O symbols

2024-07-11 Thread Ian Lance Taylor
The libbacktrace symbol table code was incorrectly discarding global
Mach-O symbols.  This patch fixes the problem.  Tested on macOS on the
compile farm, and also on x86_64-pc-linux-gnu.  Committed to mainline.

Ian

For PR libbacktrace/97082
* macho.c (MACH_O_N_EXT): Don't define.
(MACH_O_N_UNDF): Define.
(macho_defined_symbol): Don't discard N_EXT symbols.  Do
discard N_UNDF symbols.
af827b2ab90b9d726c7182c41fa2409005909db8
diff --git a/libbacktrace/macho.c b/libbacktrace/macho.c
index 5ceff05b29a..8f768f14a57 100644
--- a/libbacktrace/macho.c
+++ b/libbacktrace/macho.c
@@ -271,12 +271,14 @@ struct macho_nlist_64
 
 /* Value found in nlist n_type field.  */
 
-#define MACH_O_N_EXT   0x01/* Extern symbol */
+#define MACH_O_N_STAB  0xe0/* Stabs debugging symbol */
+#define MACH_O_N_TYPE  0x0e/* Mask for type bits */
+
+/* Values found after masking with MACH_O_N_TYPE.  */
+#define MACH_O_N_UNDF  0x00/* Undefined symbol */
 #define MACH_O_N_ABS   0x02/* Absolute symbol */
-#define MACH_O_N_SECT  0x0e/* Defined in section */
+#define MACH_O_N_SECT  0x0e/* Defined in section from n_sect field */
 
-#define MACH_O_N_TYPE  0x0e/* Mask for type bits */
-#define MACH_O_N_STAB  0xe0/* Stabs debugging symbol */
 
 /* Information we keep for a Mach-O symbol.  */
 
@@ -492,10 +494,10 @@ macho_defined_symbol (uint8_t type)
 {
   if ((type & MACH_O_N_STAB) != 0)
 return 0;
-  if ((type & MACH_O_N_EXT) != 0)
-return 0;
   switch (type & MACH_O_N_TYPE)
 {
+case MACH_O_N_UNDF:
+  return 0;
 case MACH_O_N_ABS:
   return 1;
 case MACH_O_N_SECT:


[gcc r15-1984] libbacktrace: correctly gather Mach-O symbol table

2024-07-11 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:b870086904cfd480cf4297525ece00d169482ec7

commit r15-1984-gb870086904cfd480cf4297525ece00d169482ec7
Author: Ian Lance Taylor 
Date:   Thu Jul 11 17:50:18 2024 -0700

libbacktrace: correctly gather Mach-O symbol table

For PR libbacktrace/97082.
* macho.c (MACH_O_N_EXT): Don't define.
(MACH_O_N_UNDF): Define.
(macho_defined_symbol): Don't discard N_EXT symbols.  Do
discard N_UNDF symbols.

Diff:
---
 libbacktrace/macho.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/libbacktrace/macho.c b/libbacktrace/macho.c
index 5ceff05b29a5..8f768f14a579 100644
--- a/libbacktrace/macho.c
+++ b/libbacktrace/macho.c
@@ -271,12 +271,14 @@ struct macho_nlist_64
 
 /* Value found in nlist n_type field.  */
 
-#define MACH_O_N_EXT   0x01/* Extern symbol */
+#define MACH_O_N_STAB  0xe0/* Stabs debugging symbol */
+#define MACH_O_N_TYPE  0x0e/* Mask for type bits */
+
+/* Values found after masking with MACH_O_N_TYPE.  */
+#define MACH_O_N_UNDF  0x00/* Undefined symbol */
 #define MACH_O_N_ABS   0x02/* Absolute symbol */
-#define MACH_O_N_SECT  0x0e/* Defined in section */
+#define MACH_O_N_SECT  0x0e/* Defined in section from n_sect field */
 
-#define MACH_O_N_TYPE  0x0e/* Mask for type bits */
-#define MACH_O_N_STAB  0xe0/* Stabs debugging symbol */
 
 /* Information we keep for a Mach-O symbol.  */
 
@@ -492,10 +494,10 @@ macho_defined_symbol (uint8_t type)
 {
   if ((type & MACH_O_N_STAB) != 0)
 return 0;
-  if ((type & MACH_O_N_EXT) != 0)
-return 0;
   switch (type & MACH_O_N_TYPE)
 {
+case MACH_O_N_UNDF:
+  return 0;
 case MACH_O_N_ABS:
   return 1;
 case MACH_O_N_SECT:


Re: libbacktrace patch committed: Add clang optnone attribute

2024-07-11 Thread Ian Lance Taylor
On Thu, Jul 11, 2024 at 4:18 PM Andrew Pinski  wrote:
>
> On Thu, Jul 11, 2024 at 4:14 PM Ian Lance Taylor  wrote:
> >
> > The libbacktrace testsuite was not passing when run with current
> > versions of clang.  Add the optnone attribute to make it pass.  Add
> > -Wno-attributes and -Wno-unknown-attributes to disable warnings about
> > unrecognized function attributes.  Bootstrapped and ran libbacktrace
> > testsuite on x86_64-pc-linux-gnu.  Committed to mainline.
>
> NoteI see they have `noclone` and `noinline`, maybe it should have
> `noipa` on them too. noipa disables a few more things than
> noclone/noinline that might make a difference too.

Thanks, I looked into that, and as far as I can tell for purposes of
the libbacktrace testsuite it doesn't matter.  All that matters here
is that the function isn't inlined, so that it shows up in the call
stack.  It's OK if the compiler makes other deductions about what the
function does.  And indeed the tests are passing.  Of course we can
change the testsuite again if I'm mistaken.

Ian


libbacktrace patch committed: Add clang optnone attribute

2024-07-11 Thread Ian Lance Taylor
The libbacktrace testsuite was not passing when run with current
versions of clang.  Add the optnone attribute to make it pass.  Add
-Wno-attributes and -Wno-unknown-attributes to disable warnings about
unrecognized function attributes.  Bootstrapped and ran libbacktrace
testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian

* btest.c (test1, test3): Add optnone attribute.
* edtest.c (test1): Likewise.
* mtest.c (test1, test3): Likewise.
* configure.ac: Use -Wno-attributes and -Wno-unknown-attributes.
* configure: Regenerate.
67130485e51fb4391908dc8beb7259623a94fbd6
diff --git a/libbacktrace/btest.c b/libbacktrace/btest.c
index d9fc372d33d..c4b2db2cce2 100644
--- a/libbacktrace/btest.c
+++ b/libbacktrace/btest.c
@@ -49,7 +49,7 @@ POSSIBILITY OF SUCH DAMAGE.  */
 
 /* Test the backtrace function with non-inlined functions.  */
 
-static int test1 (void) __attribute__ ((noinline, noclone, unused));
+static int test1 (void) __attribute__ ((noinline, noclone, optnone, unused));
 static int f2 (int) __attribute__ ((noinline, noclone));
 static int f3 (int, int) __attribute__ ((noinline, noclone));
 
@@ -163,7 +163,7 @@ f13 (int f1line, int f2line)
 
 /* Test the backtrace_simple function with non-inlined functions.  */
 
-static int test3 (void) __attribute__ ((noinline, noclone, unused));
+static int test3 (void) __attribute__ ((noinline, noclone, optnone, unused));
 static int f22 (int) __attribute__ ((noinline, noclone));
 static int f23 (int, int) __attribute__ ((noinline, noclone));
 
diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac
index 59e9c415db8..bfd7f35d2d2 100644
--- a/libbacktrace/configure.ac
+++ b/libbacktrace/configure.ac
@@ -144,7 +144,8 @@ AC_SUBST(EXTRA_FLAGS)
 
 ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wwrite-strings -Wstrict-prototypes \
  -Wmissing-prototypes -Wold-style-definition \
- -Wmissing-format-attribute -Wcast-qual],
+ -Wmissing-format-attribute -Wcast-qual \
+ -Wno-attributes -Wno-unknown-attributes],
  [WARN_FLAGS])
 
 AC_ARG_ENABLE([werror],
diff --git a/libbacktrace/edtest.c b/libbacktrace/edtest.c
index d99b8a60295..b644d93788c 100644
--- a/libbacktrace/edtest.c
+++ b/libbacktrace/edtest.c
@@ -43,7 +43,7 @@ POSSIBILITY OF SUCH DAMAGE.  */
 
 #include "testlib.h"
 
-static int test1 (void) __attribute__ ((noinline, noclone, unused));
+static int test1 (void) __attribute__ ((noinline, noclone, optnone, unused));
 extern int f2 (int);
 extern int f3 (int, int);
 
diff --git a/libbacktrace/mtest.c b/libbacktrace/mtest.c
index 9afe7089514..f793391653d 100644
--- a/libbacktrace/mtest.c
+++ b/libbacktrace/mtest.c
@@ -47,7 +47,7 @@ POSSIBILITY OF SUCH DAMAGE.  */
 
 #include "testlib.h"
 
-static int test1 (void) __attribute__ ((noinline, noclone, unused));
+static int test1 (void) __attribute__ ((noinline, noclone, optnone, unused));
 static int f2 (int) __attribute__ ((noinline, noclone));
 static int f3 (int, int) __attribute__ ((noinline, noclone));
 
@@ -211,7 +211,7 @@ f3 (int f1line __attribute__ ((unused)), int f2line 
__attribute__ ((unused)))
 
 /* Test the backtrace_simple function with non-inlined functions.  */
 
-static int test3 (void) __attribute__ ((noinline, noclone, unused));
+static int test3 (void) __attribute__ ((noinline, noclone, optnone, unused));
 static int f22 (int) __attribute__ ((noinline, noclone));
 static int f23 (int, int) __attribute__ ((noinline, noclone));
 


[gcc r15-1982] libbacktrace: fix testsuite for clang

2024-07-11 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:8f7c06df424fffa88422f83ba0a7c58576ae3d91

commit r15-1982-g8f7c06df424fffa88422f83ba0a7c58576ae3d91
Author: Ian Lance Taylor 
Date:   Thu Jul 11 16:07:06 2024 -0700

libbacktrace: fix testsuite for clang

* btest.c (test1, test3): Add optnone attribute.
* edtest.c (test1): Likewise.
* mtest.c (test1, test3): Likewise.
* configure.ac: Use -Wno-attributes and -Wno-unknown-attributes.
* configure: Regenerate.

Diff:
---
 libbacktrace/btest.c  | 4 ++--
 libbacktrace/configure| 3 ++-
 libbacktrace/configure.ac | 3 ++-
 libbacktrace/edtest.c | 2 +-
 libbacktrace/mtest.c  | 4 ++--
 5 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/libbacktrace/btest.c b/libbacktrace/btest.c
index d9fc372d33d9..c4b2db2cce2f 100644
--- a/libbacktrace/btest.c
+++ b/libbacktrace/btest.c
@@ -49,7 +49,7 @@ POSSIBILITY OF SUCH DAMAGE.  */
 
 /* Test the backtrace function with non-inlined functions.  */
 
-static int test1 (void) __attribute__ ((noinline, noclone, unused));
+static int test1 (void) __attribute__ ((noinline, noclone, optnone, unused));
 static int f2 (int) __attribute__ ((noinline, noclone));
 static int f3 (int, int) __attribute__ ((noinline, noclone));
 
@@ -163,7 +163,7 @@ f13 (int f1line, int f2line)
 
 /* Test the backtrace_simple function with non-inlined functions.  */
 
-static int test3 (void) __attribute__ ((noinline, noclone, unused));
+static int test3 (void) __attribute__ ((noinline, noclone, optnone, unused));
 static int f22 (int) __attribute__ ((noinline, noclone));
 static int f23 (int, int) __attribute__ ((noinline, noclone));
 
diff --git a/libbacktrace/configure b/libbacktrace/configure
index ab94a85f45c1..fe0bb2083eb1 100755
--- a/libbacktrace/configure
+++ b/libbacktrace/configure
@@ -12384,7 +12384,8 @@ WARN_FLAGS=
 save_CFLAGS="$CFLAGS"
 for real_option in -W -Wall -Wwrite-strings -Wstrict-prototypes \
  -Wmissing-prototypes -Wold-style-definition \
- -Wmissing-format-attribute -Wcast-qual; do
+ -Wmissing-format-attribute -Wcast-qual \
+ -Wno-attributes -Wno-unknown-attributes; do
   # Do the check with the no- prefix removed since gcc silently
   # accepts any -Wno-* option on purpose
   case $real_option in
diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac
index 59e9c415db8f..bfd7f35d2d2b 100644
--- a/libbacktrace/configure.ac
+++ b/libbacktrace/configure.ac
@@ -144,7 +144,8 @@ AC_SUBST(EXTRA_FLAGS)
 
 ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wwrite-strings -Wstrict-prototypes \
  -Wmissing-prototypes -Wold-style-definition \
- -Wmissing-format-attribute -Wcast-qual],
+ -Wmissing-format-attribute -Wcast-qual \
+ -Wno-attributes -Wno-unknown-attributes],
  [WARN_FLAGS])
 
 AC_ARG_ENABLE([werror],
diff --git a/libbacktrace/edtest.c b/libbacktrace/edtest.c
index d99b8a602950..b644d93788cb 100644
--- a/libbacktrace/edtest.c
+++ b/libbacktrace/edtest.c
@@ -43,7 +43,7 @@ POSSIBILITY OF SUCH DAMAGE.  */
 
 #include "testlib.h"
 
-static int test1 (void) __attribute__ ((noinline, noclone, unused));
+static int test1 (void) __attribute__ ((noinline, noclone, optnone, unused));
 extern int f2 (int);
 extern int f3 (int, int);
 
diff --git a/libbacktrace/mtest.c b/libbacktrace/mtest.c
index 9afe70895148..f793391653dc 100644
--- a/libbacktrace/mtest.c
+++ b/libbacktrace/mtest.c
@@ -47,7 +47,7 @@ POSSIBILITY OF SUCH DAMAGE.  */
 
 #include "testlib.h"
 
-static int test1 (void) __attribute__ ((noinline, noclone, unused));
+static int test1 (void) __attribute__ ((noinline, noclone, optnone, unused));
 static int f2 (int) __attribute__ ((noinline, noclone));
 static int f3 (int, int) __attribute__ ((noinline, noclone));
 
@@ -211,7 +211,7 @@ f3 (int f1line __attribute__ ((unused)), int f2line 
__attribute__ ((unused)))
 
 /* Test the backtrace_simple function with non-inlined functions.  */
 
-static int test3 (void) __attribute__ ((noinline, noclone, unused));
+static int test3 (void) __attribute__ ((noinline, noclone, optnone, unused));
 static int f22 (int) __attribute__ ((noinline, noclone));
 static int f23 (int, int) __attribute__ ((noinline, noclone));


libbacktrace patch committed: Suggest -g if no debug info

2024-07-11 Thread Ian Lance Taylor
This small libbacktrace patch suggests compiling with -g (and, on
macOS, running dsymutil), if there is no debug info.  Ran libbacktrace
testsuite.  Committed to mainline.

Ian

* elf.c (elf_nodebug): Suggest -g.
* macho.c (macho_nodebug): Suggest -g and dsymutil.
* pecoff.c (coff_nodebug): Suggest -g.
b96789abf8a51e8f70309799b5dfee36d4fb3da6
diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index 735f8752500..e6a66c0db90 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -589,7 +589,7 @@ elf_nodebug (struct backtrace_state *state, uintptr_t pc,
   return bdata.ret;
 }
 
-  error_callback (data, "no debug info in ELF executable", -1);
+  error_callback (data, "no debug info in ELF executable (make sure to compile 
with -g)", -1);
   return 0;
 }
 
diff --git a/libbacktrace/macho.c b/libbacktrace/macho.c
index 42f24721e6a..5ceff05b29a 100644
--- a/libbacktrace/macho.c
+++ b/libbacktrace/macho.c
@@ -324,7 +324,7 @@ macho_nodebug (struct backtrace_state *state 
ATTRIBUTE_UNUSED,
   backtrace_full_callback callback ATTRIBUTE_UNUSED,
   backtrace_error_callback error_callback, void *data)
 {
-  error_callback (data, "no debug info in Mach-O executable", -1);
+  error_callback (data, "no debug info in Mach-O executable (make sure to 
compile with -g; may need to run dsymutil)", -1);
   return 0;
 }
 
diff --git a/libbacktrace/pecoff.c b/libbacktrace/pecoff.c
index bbb59e26d7a..e88e4d2b038 100644
--- a/libbacktrace/pecoff.c
+++ b/libbacktrace/pecoff.c
@@ -240,7 +240,7 @@ coff_nodebug (struct backtrace_state *state 
ATTRIBUTE_UNUSED,
  backtrace_full_callback callback ATTRIBUTE_UNUSED,
  backtrace_error_callback error_callback, void *data)
 {
-  error_callback (data, "no debug info in PE/COFF executable", -1);
+  error_callback (data, "no debug info in PE/COFF executable (make sure to 
compile with -g)", -1);
   return 0;
 }
 


[gcc r15-1979] libbacktrace: suggest how to fix missing debug info

2024-07-11 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:b96789abf8a51e8f70309799b5dfee36d4fb3da6

commit r15-1979-gb96789abf8a51e8f70309799b5dfee36d4fb3da6
Author: Ian Lance Taylor 
Date:   Thu Jul 11 15:39:07 2024 -0700

libbacktrace: suggest how to fix missing debug info

* elf.c (elf_nodebug): Suggest -g.
* macho.c (macho_nodebug): Suggest -g and dsymutil.
* pecoff.c (coff_nodebug): Suggest -g.

Diff:
---
 libbacktrace/elf.c| 2 +-
 libbacktrace/macho.c  | 2 +-
 libbacktrace/pecoff.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index 735f87525008..e6a66c0db905 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -589,7 +589,7 @@ elf_nodebug (struct backtrace_state *state, uintptr_t pc,
   return bdata.ret;
 }
 
-  error_callback (data, "no debug info in ELF executable", -1);
+  error_callback (data, "no debug info in ELF executable (make sure to compile 
with -g)", -1);
   return 0;
 }
 
diff --git a/libbacktrace/macho.c b/libbacktrace/macho.c
index 42f24721e6ac..5ceff05b29a5 100644
--- a/libbacktrace/macho.c
+++ b/libbacktrace/macho.c
@@ -324,7 +324,7 @@ macho_nodebug (struct backtrace_state *state 
ATTRIBUTE_UNUSED,
   backtrace_full_callback callback ATTRIBUTE_UNUSED,
   backtrace_error_callback error_callback, void *data)
 {
-  error_callback (data, "no debug info in Mach-O executable", -1);
+  error_callback (data, "no debug info in Mach-O executable (make sure to 
compile with -g; may need to run dsymutil)", -1);
   return 0;
 }
 
diff --git a/libbacktrace/pecoff.c b/libbacktrace/pecoff.c
index bbb59e26d7a6..e88e4d2b0383 100644
--- a/libbacktrace/pecoff.c
+++ b/libbacktrace/pecoff.c
@@ -240,7 +240,7 @@ coff_nodebug (struct backtrace_state *state 
ATTRIBUTE_UNUSED,
  backtrace_full_callback callback ATTRIBUTE_UNUSED,
  backtrace_error_callback error_callback, void *data)
 {
-  error_callback (data, "no debug info in PE/COFF executable", -1);
+  error_callback (data, "no debug info in PE/COFF executable (make sure to 
compile with -g)", -1);
   return 0;
 }


libbacktrace patch committed: Remove trailing whitespace

2024-07-11 Thread Ian Lance Taylor
This minor libbacktrace patch removes trailing whitespace.  Ran
libbacktrace tests.  Committed to mainline.

Ian

* dwarf.c: Remove trailing whitespace.
* macho.c: Likewise.
3f660179d6a0ebcd83d6a546f48a163d1a685f72
diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c
index ed0672964c2..cc36a0a2990 100644
--- a/libbacktrace/dwarf.c
+++ b/libbacktrace/dwarf.c
@@ -1705,7 +1705,7 @@ add_ranges_from_ranges (
base = (uintptr_t) high;
   else
{
- if (!add_range (state, rdata, 
+ if (!add_range (state, rdata,
  (uintptr_t) low + base + base_address,
  (uintptr_t) high + base + base_address,
  error_callback, data, vec))
@@ -1904,7 +1904,7 @@ add_ranges (struct backtrace_state *state,
const struct dwarf_sections *dwarf_sections,
uintptr_t base_address, int is_bigendian,
struct unit *u, uintptr_t base, const struct pcrange *pcrange,
-   int (*add_range) (struct backtrace_state *state, void *rdata, 
+   int (*add_range) (struct backtrace_state *state, void *rdata,
  uintptr_t lowpc, uintptr_t highpc,
  backtrace_error_callback error_callback,
  void *data, void *vec),
diff --git a/libbacktrace/macho.c b/libbacktrace/macho.c
index b4856346ccc..42f24721e6a 100644
--- a/libbacktrace/macho.c
+++ b/libbacktrace/macho.c
@@ -674,7 +674,6 @@ macho_add_symtab (struct backtrace_state *state, int 
descriptor,
  struct macho_syminfo_data *p;
 
  p = backtrace_atomic_load_pointer (pp);
- 
  if (p == NULL)
break;
 


[gcc r15-1978] libbacktrace: remove trailing whitespace

2024-07-11 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:02f7525e5e9e8d749c9ba2b9a925da4b202553ce

commit r15-1978-g02f7525e5e9e8d749c9ba2b9a925da4b202553ce
Author: Ian Lance Taylor 
Date:   Thu Jul 11 15:27:18 2024 -0700

libbacktrace: remove trailing whitespace

* dwarf.c: Remove trailing whitespace.
* macho.c: Likewise.

Diff:
---
 libbacktrace/dwarf.c | 4 ++--
 libbacktrace/macho.c | 1 -
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c
index ed0672964c24..cc36a0a2990d 100644
--- a/libbacktrace/dwarf.c
+++ b/libbacktrace/dwarf.c
@@ -1705,7 +1705,7 @@ add_ranges_from_ranges (
base = (uintptr_t) high;
   else
{
- if (!add_range (state, rdata, 
+ if (!add_range (state, rdata,
  (uintptr_t) low + base + base_address,
  (uintptr_t) high + base + base_address,
  error_callback, data, vec))
@@ -1904,7 +1904,7 @@ add_ranges (struct backtrace_state *state,
const struct dwarf_sections *dwarf_sections,
uintptr_t base_address, int is_bigendian,
struct unit *u, uintptr_t base, const struct pcrange *pcrange,
-   int (*add_range) (struct backtrace_state *state, void *rdata, 
+   int (*add_range) (struct backtrace_state *state, void *rdata,
  uintptr_t lowpc, uintptr_t highpc,
  backtrace_error_callback error_callback,
  void *data, void *vec),
diff --git a/libbacktrace/macho.c b/libbacktrace/macho.c
index b4856346ccc2..42f24721e6ac 100644
--- a/libbacktrace/macho.c
+++ b/libbacktrace/macho.c
@@ -674,7 +674,6 @@ macho_add_symtab (struct backtrace_state *state, int 
descriptor,
  struct macho_syminfo_data *p;
 
  p = backtrace_atomic_load_pointer (pp);
- 
  if (p == NULL)
break;


Re: [RFC 1/2] libbacktrace: add FDPIC support

2024-07-10 Thread Ian Lance Taylor
On Sun, May 26, 2024 at 11:51 PM Max Filippov  wrote:
>
> diff --git a/libbacktrace/internal.h b/libbacktrace/internal.h
> index 4fa0af8cb6c9..456911166026 100644
> --- a/libbacktrace/internal.h
> +++ b/libbacktrace/internal.h
> @@ -323,10 +323,22 @@ struct dwarf_sections
>
>  struct dwarf_data;
>
> +#if defined (HAVE_DL_ITERATE_PHDR) && defined (__FDPIC__)
> +typedef struct elf32_fdpic_loadaddr base_address_type;
> +#define __RELOC_UINTPTR(ptr, base) ((uintptr_t)__RELOC_POINTER (ptr, base))
> +#define no_base_address ((struct elf32_fdpic_loadaddr){0})
> +#else
> +typedef uintptr_t base_address_type;
> +#define __RELOC_POINTER(ptr, base) ((ptr) + (base))
> +#define __RELOC_UINTPTR(ptr, base) ((uintptr_t)__RELOC_POINTER (ptr, base))
> +#define no_base_address ((uintptr_t)0)
> +#endif
> +
> +

When I look at the uClibc sources, I don't understand how this works.
This sets no_base_address to have a zero map field.  But
__RELOC_POINTER will crash when given a zero map field.  At least that
is what it looks like in
uClibc/libc/sysdeps/linux/bfin/bits/elf-fdpic.h.  What target and what
library are you using?  Thanks.

Ian


libbacktrace patch committed: OK if zero backward bits

2024-06-16 Thread Ian Lance Taylor
I've committed this libbacktrace patch to not fail on the case where
there are no bits available when looking backward.  This can happen at
the very end of the frame if no bits are actually required.  The test
case is long and may be proprietary, so not including it.
Bootstrapped and ran libbacktrace and Go testsuite.  Committed to
mainline.

Ian

* elf.c (elf_fetch_bits_backward) Don't fail if no bits are
available.
dda0996e11dbc07f63d3456e36dc5eaec7361004
diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index 3cd87020b03..735f8752500 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -1182,14 +1182,7 @@ elf_fetch_bits_backward (const unsigned char **ppin,
   val = *pval;
 
   if (unlikely (pin <= pinend))
-{
-  if (bits == 0)
-   {
- elf_uncompress_failed ();
- return 0;
-   }
-  return 1;
-}
+return 1;
 
   pin -= 4;
 


[gcc r15-1360] libbacktrace: it's OK if zstd decompressor sees no backward bits

2024-06-16 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:8348f8c22ff1ac61df45d63739e1028f87d6ef88

commit r15-1360-g8348f8c22ff1ac61df45d63739e1028f87d6ef88
Author: Ian Lance Taylor 
Date:   Sun Jun 16 15:39:53 2024 -0700

libbacktrace: it's OK if zstd decompressor sees no backward bits

* elf.c (elf_fetch_bits_backward) Don't fail if no bits are
available.

Diff:
---
 libbacktrace/elf.c | 9 +
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index 3cd87020b031..735f87525008 100644
--- a/libbacktrace/elf.c
+++ b/libbacktrace/elf.c
@@ -1182,14 +1182,7 @@ elf_fetch_bits_backward (const unsigned char **ppin,
   val = *pval;
 
   if (unlikely (pin <= pinend))
-{
-  if (bits == 0)
-   {
- elf_uncompress_failed ();
- return 0;
-   }
-  return 1;
-}
+return 1;
 
   pin -= 4;


Re: [PATCH 04/52] go: Replace uses of {FLOAT, {, LONG_}DOUBLE}_TYPE_SIZE

2024-06-12 Thread Ian Lance Taylor
"Kewen.Lin"  writes:

> Hi,
>
> Gentle ping:
>
> https://gcc.gnu.org/pipermail/gcc-patches/2024-June/653387.html
>
> BR,
> Kewen
>
> on 2024/6/3 11:00, Kewen Lin wrote:
>> Joseph pointed out "floating types should have their mode,
>> not a poorly defined precision value" in the discussion[1],
>> as he and Richi suggested, the existing macros
>> {FLOAT,{,LONG_}DOUBLE}_TYPE_SIZE will be replaced with a
>> hook mode_for_floating_type.  To be prepared for that, this
>> patch is to replace use of {FLOAT,{,LONG_}DOUBLE}_TYPE_SIZE
>> in go with TYPE_PRECISION of {float,{,long_}double}_type_node.
>> 
>> [1] https://gcc.gnu.org/pipermail/gcc-patches/2024-May/651209.html
>> 
>> gcc/go/ChangeLog:
>> 
>>  * go-gcc.cc (Gcc_backend::float_type): Use TYPE_PRECISION of
>>  {float,double,long_double}_type_node to replace
>>  {FLOAT,DOUBLE,LONG_DOUBLE}_TYPE_SIZE.
>>  (Gcc_backend::complex_type): Likewise.

This is fine if the other parts of the patch are accepted.

Thanks.

Ian


Re: [PATCH] go: Fix gccgo -v on Solaris with ld

2024-06-06 Thread Ian Lance Taylor
On Thu, Jun 6, 2024 at 7:13 AM Rainer Orth  
wrote:
>
> The Go testsuite's go.sum file ends in
>
> Couldn't determine version of 
> /var/gcc/regression/master/11.4-gcc-64/build/gcc/gccgo
>
> on Solaris.  It turns out this happens because gccgo -v is confused:
>
> [...]
> gcc version 15.0.0 20240531 (experimental) [master 
> a0d60660f2aae2d79685f73d568facb2397582d8] (GCC)
> COMPILER_PATH=./:/usr/ccs/bin/
> LIBRARY_PATH=./:/lib/amd64/:/usr/lib/amd64/:/lib/:/usr/lib/
> COLLECT_GCC_OPTIONS='-g1' '-B' './' '-v' '-shared-libgcc' '-mtune=generic' 
> '-march=x86-64' '-dumpdir' 'a.'
>  ./collect2 -V -M ./libgcc-unwind.map -Qy /usr/lib/amd64/crt1.o ./crtp.o 
> /usr/lib/amd64/crti.o /usr/lib/amd64/values-Xa.o /usr/lib/amd64/values-xpg6.o 
> ./crtbegin.o -L. -L/lib/amd64 -L/usr/lib/amd64 -t -lgcc_s -lgcc -lc -lgcc_s 
> -lgcc ./crtend.o /usr/lib/amd64/crtn.o
> ld: Software Generation Utilities - Solaris Link Editors: 5.11-1.3297
> Undefined   first referenced
>  symbol in file
> main/usr/lib/amd64/crt1.o
> ld: fatal: symbol referencing errors
> collect2: error: ld returned 1 exit status
>
> trying to invoke the linker without adding any object file.  This only
> happens when Solaris ld is in use.  gccgo passes -t to the linker in
> that case, but does it unconditionally, even with -v.
>
> When configured to use GNU ld, gccgo -v is fine instead.
>
> This patch avoids this by restricting the -t to actually linking.
>
> Tested on i386-pc-solaris2.11 and sparc-sun-solaris2.11 (ld and gld).
>
> Ok for trunk?
>
> I believe this has to go via gofrontend, though.
>
> Raine
>
> --
> -
> Rainer Orth, Center for Biotechnology, Bielefeld University
>
>
> 2024-06-05  Rainer Orth  
>
> gcc/go:
> * gospec.cc (lang_specific_driver) [TARGET_SOLARIS !USE_GLD]: Only
> add -t if linking.



This is OK.  Thanks.

You can just go ahead and commit this change.  The files in the gcc/go
directory itself live in the GCC tree.  The files in gcc/go/gofrontend
are copied in from a different repository.

Ian


Re: [PATCH] testsuite: go: Require split-stack support for go.test/test/index0.go [PR87589]

2024-06-06 Thread Ian Lance Taylor
On Thu, Jun 6, 2024 at 7:00 AM Rainer Orth  
wrote:
>
> The index0-out.go test FAILs on Solaris (SPARC and x86, 32 and 64-bit),
> as well as several others:
>
> FAIL: ./index0-out.go execution,  -O0 -g -fno-var-tracking-assignments
>
> The test SEGVs because it tries a stack acess way beyond the stack
> area.  As Ian analyzed in the PR, the testcase currently requires
> split-stack support, so this patch requires just that.
>
> Tested on i386-pc-solaris2.11 and sparc-sun-solaris2.11.
>
> Ok for trunk?
>
> Rainer
>
> --
> -
> Rainer Orth, Center for Biotechnology, Bielefeld University
>
>
> 2024-06-05  Rainer Orth  
>
> gcc/testsuite:
> PR go/87589
> * go.test/go-test.exp (go-gc-tests): Require split-stack support
> for index0.go.



This is OK.  Thanks.

Ian


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

2024-05-30 Thread Ian Lance Taylor
On Thu, May 30, 2024 at 12:48 AM Martin Uecker  wrote:
>
>
> Hi Ian,
>
> can you give me a green light for the go changes. The C FE
> changes were approved.
>
> The only change with respect to the last version are
> the removal of the unneeded null check for the
> main variant (as discussed) and that I also removed the
>
> container->decls_seen.add (TREE_TYPE (decl));
>
> and the corresponding check, because I think it is
> redundant if we also test for the main variant.
> (it wasn't with TYPE_CANONICAL because this was
> only added conditionally).
>
> The other code in the file only checks for added
> declarations not types, so should not depend on this.

Apologies.  I thought that I had already said that the Go changes are
fine if the libgo tests still pass.  Anyhow, that is the case: if the
tests pass, the change is fine.  Thanks.

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


[gcc r15-140] libbacktrace: add DLLS as they are loaded

2024-05-03 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:b69dac54ef769a33bcdca6de243c1b08e05c7881

commit r15-140-gb69dac54ef769a33bcdca6de243c1b08e05c7881
Author: Ian Lance Taylor 
Date:   Fri May 3 15:23:23 2024 -0700

libbacktrace: add DLLS as they are loaded

Patch from Björn Schäpers.

* pecoff.c (struct dll_notification_data): Define.
(LDR_DLL_NOTIFICATION): New typedef.
(LDR_REGISTER_FUNCTION): New typedef.
(struct dll_notification_context): Define.
(dll_notification): New static function.
(backtrace_initialize): Register DLL notification.

Diff:
---
 libbacktrace/pecoff.c | 106 ++
 1 file changed, 106 insertions(+)

diff --git a/libbacktrace/pecoff.c b/libbacktrace/pecoff.c
index 4f267841178..bbb59e26d7a 100644
--- a/libbacktrace/pecoff.c
+++ b/libbacktrace/pecoff.c
@@ -61,6 +61,34 @@ POSSIBILITY OF SUCH DAMAGE.  */
 #undef Module32Next
 #endif
 #endif
+
+#if defined(_ARM_)
+#define NTAPI
+#else
+#define NTAPI __stdcall
+#endif
+
+/* This is a simplified (but binary compatible) version of what Microsoft
+   defines in their documentation. */
+struct dll_notification_data
+{
+  ULONG reserved;
+  /* The name as UNICODE_STRING struct. */
+  PVOID full_dll_name;
+  PVOID base_dll_name;
+  PVOID dll_base;
+  ULONG size_of_image;
+};
+
+#define LDR_DLL_NOTIFICATION_REASON_LOADED 1
+
+typedef LONG NTSTATUS;
+typedef VOID CALLBACK (*LDR_DLL_NOTIFICATION)(ULONG,
+ struct dll_notification_data*,
+ PVOID);
+typedef NTSTATUS NTAPI (*LDR_REGISTER_FUNCTION)(ULONG,
+   LDR_DLL_NOTIFICATION, PVOID,
+   PVOID*);
 #endif
 
 /* Coff file header.  */
@@ -911,6 +939,53 @@ coff_add (struct backtrace_state *state, int descriptor,
   return 0;
 }
 
+#ifdef HAVE_WINDOWS_H
+struct dll_notification_context
+{
+  struct backtrace_state *state;
+  backtrace_error_callback error_callback;
+  void *data;
+};
+
+static VOID CALLBACK
+dll_notification (ULONG reason,
+ struct dll_notification_data *notification_data,
+ PVOID context)
+{
+  char module_name[MAX_PATH];
+  int descriptor;
+  struct dll_notification_context* dll_context =
+(struct dll_notification_context*) context;
+  struct backtrace_state *state = dll_context->state;
+  void *data = dll_context->data;
+  backtrace_error_callback error_callback = dll_context->data;
+  fileline fileline;
+  int found_sym;
+  int found_dwarf;
+  HMODULE module_handle;
+
+  if (reason != LDR_DLL_NOTIFICATION_REASON_LOADED)
+return;
+
+  if (!GetModuleHandleExW ((GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
+   | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT),
+  (wchar_t*) notification_data->dll_base,
+  _handle))
+return;
+
+  if (!GetModuleFileNameA ((HMODULE) module_handle, module_name, MAX_PATH - 1))
+return;
+
+  descriptor = backtrace_open (module_name, error_callback, data, NULL);
+
+  if (descriptor < 0)
+return;
+
+  coff_add (state, descriptor, error_callback, data, , _sym,
+   _dwarf, (uintptr_t) module_handle);
+}
+#endif /* defined(HAVE_WINDOWS_H) */
+
 /* Initialize the backtrace data we need from an ELF executable.  At
the ELF level, all we need to do is find the debug info
sections.  */
@@ -933,6 +1008,8 @@ backtrace_initialize (struct backtrace_state *state,
 #endif
 
 #ifdef HAVE_WINDOWS_H
+  HMODULE nt_dll_handle;
+
   module_handle = (uintptr_t) GetModuleHandle (NULL);
 #endif
 
@@ -980,6 +1057,35 @@ backtrace_initialize (struct backtrace_state *state,
 }
 #endif
 
+#ifdef HAVE_WINDOWS_H
+  nt_dll_handle = GetModuleHandleW (L"ntdll.dll");
+  if (nt_dll_handle)
+{
+  LDR_REGISTER_FUNCTION register_func;
+  const char register_name[] = "LdrRegisterDllNotification";
+  register_func = (void*) GetProcAddress (nt_dll_handle,
+ register_name);
+
+  if (register_func)
+   {
+ PVOID cookie;
+ struct dll_notification_context *context
+   = backtrace_alloc (state,
+  sizeof (struct dll_notification_context),
+  error_callback, data);
+
+ if (context)
+   {
+ context->state = state;
+ context->data = data;
+ context->error_callback = error_callback;
+
+ register_func (0, _notification, context, );
+   }
+   }
+}
+#endif /* defined(HAVE_WINDOWS_H) */
+
   if (!state->threaded)
 {
   if (found_sym)


Re: Updated Sourceware infrastructure plans

2024-05-02 Thread Ian Lance Taylor
Pedro Alves via Overseers  writes:

> When GDB upstream tried to use gerrit, I found it basically impossible to
> follow development, given the volume...  The great thing with email is the
> threading of discussions.  A discussion can fork into its own subthread, and 
> any
> sane email client will display the discussion tree.  Email archives also let
> you follow the discussion subthreads.  That is great for archaeology too.
> With Gerrit that was basically lost, everything is super flat.  And
> then following
> development via the gerrit instance website alone is just basically
> impossible too.
> I mean, gerrit is great to track your own patches, and for the actual review
> and diffing between versions.  But for a maintainer who wants to stay
> on top of a
> project, then it's severely lacking, IME and IMO.

My experience is the exact opposite.  As I'm sure you know, Gerritt
supports specific comments on a code review, and discussions on those
comments are tracked separately.  For a complex patch, or series of
patches, you don't get lost in lots of separate discussions, as Gerritt
tracks them all for you separately.

But it's true that to use that effectively you have to look at the web
interface.  The comments are available via git commands, but not in a
directly usable format.

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: Updated Sourceware infrastructure plans

2024-05-02 Thread Ian Lance Taylor via Gcc
On Wed, May 1, 2024 at 11:48 PM Richard Biener
 wrote:
>
> We'd only know for sure if we try.  But then I'm almost 100% sure that
> having to click in a GUI is slower than 'nrOK^X' in the text-mode mail UA
> I am using for "quick" patch review.  It might be comparable to the
> review parts I do in the gmail UI or when I have to download attachments
> and cut parts into the reply.  It might be also more convenient
> for "queued" for review patches which just end up in New state in either
> inbox.

Gerritt does not require clicking in a GUI, though that is of course
the more widely used option.  Patches can be approved from the command
line.


> But then would using gitlab or any similar service enforce the use of
> pull requests / forks for each change done or can I just continue to
> post patches and push them from the command-line for changes I
> can approve myself?

Gerritt permits submitting patches from the command line for people
who can self-approve.


> Btw, for any forge like tool I'd even consider there'd be the requirement
> that _all_ functionality is also accessible via a documented (stable) API,
> aka there's command-line tooling available or at least possible to write.

True of Gerritt.

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   " 

[gcc r15-53] runtime: dump registers on Solaris

2024-04-29 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:a05efc8bf5ed329ea7d9b1740c326bdc6b04e37a

commit r15-53-ga05efc8bf5ed329ea7d9b1740c326bdc6b04e37a
Author: Ian Lance Taylor 
Date:   Sun Apr 28 13:30:39 2024 -0700

runtime: dump registers on Solaris

Patch by Rainer Orth .

Fixes PR go/106813

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/581724

Diff:
---
 gcc/go/gofrontend/MERGE   |  2 +-
 libgo/runtime/go-signal.c | 63 ---
 2 files changed, 60 insertions(+), 5 deletions(-)

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__)))
+   {
+   

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*),


[gcc r15-52] runtime: use

2024-04-29 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:678dc5e85053f1a1ca76997eec95ba8823bb6830

commit r15-52-g678dc5e85053f1a1ca76997eec95ba8823bb6830
Author: Ian Lance Taylor 
Date:   Sun Apr 28 09:57:35 2024 -0700

runtime: use 

 has been available since C99. Use it rather than defining
our own boolean type and values.

Fixes https://gcc.gnu.org/PR114875

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/582275

Diff:
---
 gcc/go/gofrontend/MERGE | 2 +-
 libgo/runtime/runtime.h | 7 +--
 2 files changed, 2 insertions(+), 7 deletions(-)

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 via Gcc
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 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)


[gcc r15-25] libbacktrace: load Windows modules

2024-04-28 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:942a9cf2a958113d2ab46f5b015c36e569abedcf

commit r15-25-g942a9cf2a958113d2ab46f5b015c36e569abedcf
Author: Ian Lance Taylor 
Date:   Sun Apr 28 11:14:17 2024 -0700

libbacktrace: load Windows modules

Patch from Björn Schäpers .

* configure.ac: Checked for tlhelp32.h
* pecoff.c: Include  if available.
(backtrace_initialize): Use tlhelp32 api for a snapshot to
detect loaded modules.
(coff_add): New argument for the module handle of the file,
to get the base address.
* configure, config.h.in: Regenerate.

Diff:
---
 libbacktrace/config.h.in  |  3 ++
 libbacktrace/configure| 15 ++
 libbacktrace/configure.ac |  4 +++
 libbacktrace/pecoff.c | 73 +--
 4 files changed, 87 insertions(+), 8 deletions(-)

diff --git a/libbacktrace/config.h.in b/libbacktrace/config.h.in
index ee2616335c7..9b8ab88ab63 100644
--- a/libbacktrace/config.h.in
+++ b/libbacktrace/config.h.in
@@ -101,6 +101,9 @@
 /* Define to 1 if you have the  header file. */
 #undef HAVE_SYS_TYPES_H
 
+/* Define to 1 if you have the  header file. */
+#undef HAVE_TLHELP32_H
+
 /* Define to 1 if you have the  header file. */
 #undef HAVE_UNISTD_H
 
diff --git a/libbacktrace/configure b/libbacktrace/configure
index d6d6606a72c..ab94a85f45c 100755
--- a/libbacktrace/configure
+++ b/libbacktrace/configure
@@ -13523,6 +13523,21 @@ fi
 
 done
 
+for ac_header in tlhelp32.h
+do :
+  ac_fn_c_check_header_compile "$LINENO" "tlhelp32.h" 
"ac_cv_header_tlhelp32_h" "#ifdef HAVE_WINDOWS_H
+#  include 
+#endif
+"
+if test "x$ac_cv_header_tlhelp32_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_TLHELP32_H 1
+_ACEOF
+
+fi
+
+done
+
 
 # Check for the fcntl function.
 if test -n "${with_target_subdir}"; then
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;
+
+ d

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


[gcc r14-10095] libbacktrace: test --compress-debug-sections=ARG for each ARG

2024-04-23 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:d2f05fed44951001de3cb02c9193c687e9376170

commit r14-10095-gd2f05fed44951001de3cb02c9193c687e9376170
Author: Ian Lance Taylor 
Date:   Tue Apr 23 10:00:03 2024 -0700

libbacktrace: test --compress-debug-sections=ARG for each ARG

This should fix a testsuite problem with Solaris ld that supports zlib
but not zlib-gabi.

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

Diff:
---
 libbacktrace/Makefile.am  |  41 ++
 libbacktrace/Makefile.in  | 186 +++---
 libbacktrace/configure|  80 +++-
 libbacktrace/configure.ac |  23 --
 4 files changed, 214 insertions(+), 116 deletions(-)

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/Makefile.in b/libbacktrace/Makefile.in
index 49852a21d37..0260ca81798 100644
--- a/libbacktrace/Makefile.in
+++ b/libbacktrace/Makefile.in
@@ -153,9 +153,9 @@ TESTS = $(am__append_4) $(MAKETESTS) $(am__EXEEXT_16)
 @HAVE_PTHREAD_TRUE@@NATIVE_TRUE@@USE_DSYMUTIL_TRUE@ttest.dSYM \
 @HAVE_PTHREAD_TRUE@@NATIVE_TRUE@@USE_DSYMUTIL_TRUE@ttest_alloc.dSYM
 @HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@am__append_22 = btest_gnudebuglink 
btest_gnudebuglinkfull
-@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@am__append_23 = ctestg ctesta
-@HAVE_COMPRESSED_DEBUG_TRUE@@HAVE_COMPRESSED_DEBUG_ZSTD_TRUE@@NATIVE_TRUE@am__append_24
 = ctestzstd
-@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@am__append_25 = ctestg_alloc 
ctesta_alloc
+@HAVE_COMPRESSED_DEBUG_ZLIB_GNU_TRUE@@NATIVE_TRUE@am__append_23 = ctestg 
ctestg_alloc
+@HAVE_COMPRESSED_DEBUG_ZLIB_GABI_TRUE@@NATIVE_TRUE@am__append_24 = ctesta 
ctesta_alloc
+@HAVE_COMPRESSED_DEBUG_ZSTD_TRUE@@NATIVE_TRUE@am__append_25 = ctestzstd 
ctestzstd_alloc
 @HAVE_DWARF5_TRUE@@NATIVE_TRUE@am__append_26 = dwarf5 dwarf5_alloc
 @HAVE_DWARF5_TRUE@@NATIVE_TRUE@@USE_DSYMUTIL_TRUE@am__append_27 =  \
 @HAVE_DWARF5_TRUE@@NATIVE_TRUE@@USE_DSYMUTIL_TRUE@ dwarf5.dSYM \
@@ -239,12 +239,12 @@ libbacktrace_noformat_la_OBJECTS =  \
 @NATIVE_TRUE@am__EXEEXT_8 = edtest$(EXEEXT) edtest_alloc$(EXEEXT)
 @HAVE_PTHREAD_TRUE@@NATIVE_TRUE@am__EXEEXT_9 = ttest$(EXEEXT) \
 @HAVE_PTHREAD_TRUE@@NATIVE_TRUE@   ttest_alloc$(EXEEXT)
-@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@am__EXEEXT_10 =  \
-@HAVE_COMPRESSED_DEBU

Re: Updated Sourceware infrastructure plans

2024-04-23 Thread Ian Lance Taylor via Gcc
On Tue, Apr 23, 2024 at 2:32 AM Richard Earnshaw (lists) via Gcc
 wrote:
>
> I've been forced to use gerrit occasionally.  I hate it.  No, I LOATHE it.  
> The UI is anything but intuitive with features hidden behind unobvious 
> selections.  IMO It's not a tool for a casual developer, which makes it a bad 
> introduction to developing software.

I would be shocked if GCC ever adopted Gerrit.  But I don't understand
this objection.  Yes, Gerrit is not a tool for a casual developer.
But so what?  Casual developers don't have to use it, except that they
have to run a particular git command to submit a patch.  It's the GCC
maintainers who have to use Gerrit.

Ian


Re: Updated Sourceware infrastructure plans

2024-04-22 Thread Ian Lance Taylor
Tom Tromey via Overseers  writes:

> Jason> Someone mentioned earlier that gerrit was previously tried
> Jason> unsuccessfully.
>
> We tried it and gdb and then abandoned it.  We tried to integrate it
> into the traditional gdb development style, having it send email to
> gdb-patches.  I found these somewhat hard to read and in the end we
> agreed not to use it.

Current Gerrit e-mails are pretty nice, with a nice diff of the change.
And patches can be submitted entirely via git, which is not the same as
today but should be acceptable for almost all contributors.  What
doesn't work in Gerrit, as far as I know, is a pure e-mail based
workflow for maintainers.  To approve a patch, maintainers have to go to
a web site and click a button, or they have to run a command line tool
("ssh  gerrit review").


> I've come around again to thinking we should probably abandon email
> instead.  For me the main benefit is that gerrit has patch tracking,
> unlike our current system, where losing patches is fairly routine.

You can lose patches in Gerrit quite easily, but at least there is a
dashboard showing all the ones you lost.

I'm definitely a Gerrit fan.

Ian


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


Re: Sourceware mitigating and preventing the next xz-backdoor

2024-04-03 Thread Ian Lance Taylor via Gcc
On Wed, Apr 3, 2024 at 11:05 AM Toon Moene  wrote:
>
> Two questions arise (as far as I am concerned):
>
> 1. Do daemons like sshd *have* to be linked with shared libraries ?
> Or could it be left to the security minded of the downstream
> (binary) distributions to link it statically with known & proven
> correct libraries ?

I like static linking personally, but it seems like glibc has made a
decision that shared linking is much preferred over static.  That said
my guess is that this kind of attack would have been effective on any
executable built as PIE.  It relied on using an IFUNC hook to adjust
the PLT entry for a different function.  And, of course, most
executables are built as PIE these days, because that is more secure
against different kinds of attacks.

> 2. Is it a limitation of the Unix / Linux daemon concept that, once
> such a process needs root access, it has to have root access
> *always* - even when performing trivial tasks like compressing
> data ?
>
> I recall quite well (vis-a-vis question 2) that the VMS equivalent would
> drop all privileges at the start of the code, and request only those
> relevant when actually needed (e.g., to open a file for reading that was
> owned by [the equivalent on VMS] of root - or perform other functions
> that only root could do), and then drop them immediately afterwards again.

Note that the attack really didn't have anything to do with
compressing data.  The library used an IFUNC to change the PLT of a
different function, so it effectively took control of the code that
verified the cryptographic key.  The only part of the attack that
involved compression was the fact that it happened to live in a
compression library.  And it wouldn't matter whether the code that
verified the cryptographic key was run as root either; the effect of
the attack was to say that the key was OK, and that sshd should
execute the command, and of course that execution must be done on
behalf of the requesting user, which (as I understand it) could be
root.

Ian


Re: Sourceware mitigating and preventing the next xz-backdoor

2024-04-02 Thread Ian Lance Taylor via Gcc
On Tue, Apr 2, 2024 at 1:21 PM Paul Koning via Gcc  wrote:
>
> Would it help to require (rather than just recommend) "don't use root except 
> for the actual 'install' step" ?

Seems reasonable, but note that it wouldn't make any difference to
this attack.  The liblzma library was modified to corrupt the sshd
binary, when sshd was linked against liblzma.  The actual attack
occurred via a connection to a corrupt sshd.  If sshd was running as
root, as is normal, the attacker had root access to the machine.  None
of the attacking steps had anything to do with having root access
while building or installing the program.

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


[gcc r14-9698] compiler: use correct size and comparison in index value overflow check

2024-03-27 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:bd8a3eecc4edffad6e5091ae42c1cb1c1730b2ab

commit r14-9698-gbd8a3eecc4edffad6e5091ae42c1cb1c1730b2ab
Author: Ian Lance Taylor 
Date:   Wed Mar 27 13:37:45 2024 -0700

compiler: use correct size and comparison in index value overflow check

This has apparently been wrong since I introduced the code ten years ago.

Fixes PR go/114500

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/574835

Diff:
---
 gcc/go/gofrontend/MERGE  | 2 +-
 gcc/go/gofrontend/expressions.cc | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

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)


[gcc r14-9695] gcc/testsuite/go.test: update issue16016

2024-03-27 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:9ff034fcff8ccab6eb82bf2cd36e2d24b2df9b78

commit r14-9695-g9ff034fcff8ccab6eb82bf2cd36e2d24b2df9b78
Author: Ian Lance Taylor 
Date:   Wed Mar 27 11:44:42 2024 -0700

gcc/testsuite/go.test: update issue16016

This backports https://go.dev/cl/574536 into the GCC testsuite.

Fixes PR go/114453

Diff:
---
 gcc/testsuite/go.test/test/fixedbugs/issue16016.go | 18 --
 1 file changed, 16 insertions(+), 2 deletions(-)

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


[gcc r14-9693] compiler: initialize local variable in lower_method_expression

2024-03-27 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:f85d3362cdb4bab611508dd9a38d9015c02ff7ca

commit r14-9693-gf85d3362cdb4bab611508dd9a38d9015c02ff7ca
Author: Ian Lance Taylor 
Date:   Tue Mar 26 13:00:03 2024 -0700

compiler: initialize local variable in lower_method_expression

Fixes PR go/114463

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/574476

Diff:
---
 gcc/go/gofrontend/MERGE  | 2 +-
 gcc/go/gofrontend/expressions.cc | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

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;
 


[gcc r14-9402] libbacktrace: don't assume compressed section is aligned

2024-03-08 Thread Ian Lance Taylor via Gcc-cvs
https://gcc.gnu.org/g:5825bd0e0d0040126e78269e56c9b9f533e2a520

commit r14-9402-g5825bd0e0d0040126e78269e56c9b9f533e2a520
Author: Ian Lance Taylor 
Date:   Fri Mar 8 13:55:34 2024 -0800

libbacktrace: don't assume compressed section is aligned

Patch originally by GitHub user ubyte at
https://github.com/ianlancetaylor/libbacktrace/pull/120.

* elf.c (elf_uncompress_chdr): Don't assume compressed section is
aligned.

Diff:
---
 libbacktrace/elf.c | 23 +--
 1 file changed, 13 insertions(+), 10 deletions(-)

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


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 4/4] libbacktrace: get debug information for loaded dlls

2023-11-30 Thread Ian Lance Taylor via Gcc
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 3/4] libbacktrace: work with aslr on windows

2023-11-30 Thread Ian Lance Taylor via Gcc
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 via Gcc
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 ();
}


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

  1   2   3   4   5   6   7   8   9   10   >