bfd: Print cached message in _bfd_abort

Message ID 20240302132108.398436-1-hjl.tools@gmail.com
State Accepted
Headers
Series bfd: Print cached message in _bfd_abort |

Checks

Context Check Description
snail/binutils-gdb-check success Github commit url

Commit Message

H.J. Lu March 2, 2024, 1:21 p.m. UTC
  bfd_check_format_matches sets _bfd_error_handler to error_handler_sprintf
to cache warning and error messages before restoring the original
_bfd_error_handler.  When something went wrong in between and _bfd_abort
is called, there is no abort message.  Update _bfd_abort to print cached
messages.

	PR ld/31444
	* bfd.c (_bfd_abort): Check and print cached messages.
---
 bfd/bfd.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
  

Patch

diff --git a/bfd/bfd.c b/bfd/bfd.c
index c9f374e0948..be4c9af0f62 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -2077,7 +2077,26 @@  _bfd_abort (const char *file, int line, const char *fn)
       /* xgettext:c-format */
       (_("BFD %s internal error, aborting at %s:%d\n"),
        BFD_VERSION_STRING, file, line);
-  _bfd_error_handler (_("Please report this bug.\n"));
+
+  struct per_xvec_message **list
+    = _bfd_per_xvec_warn (error_handler_bfd->xvec, 0);
+  if (*list)
+    {
+      fflush (stdout);
+      for (struct per_xvec_message *warn = *list; warn;)
+	{
+	  struct per_xvec_message *next = warn->next;
+	  fputs (warn->message, stderr);
+	  fputc ('\n', stderr);
+	  free (warn);
+	  warn = next;
+	}
+      fputs (_("Please report this bug.\n"), stderr);
+      fflush (stderr);
+    }
+  else
+    _bfd_error_handler (_("Please report this bug.\n"));
+
   _exit (EXIT_FAILURE);
 }