public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: binutils@sourceware.org
Cc: gdb-patches@sourceware.org
Subject: [PATCH] bfd: Handle bmmap failure in _bfd_mmap_read_temporary
Date: Wed,  3 Apr 2024 15:37:44 -0700	[thread overview]
Message-ID: <20240403223744.506469-1-hjl.tools@gmail.com> (raw)

bmmap may return MAP_FAILED.  _bfd_mmap_readonly_temporary returns
MAP_FAILED when called from GDB on an object with opncls_iovec.  Update
_bfd_mmap_read_temporary to handle bmmap failure.

	* libbfd.c (_bfd_mmap_read_temporary): Handle bmmap failure.
---
 bfd/libbfd.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/bfd/libbfd.c b/bfd/libbfd.c
index 869f0ed5c66..34197b75b5e 100644
--- a/bfd/libbfd.c
+++ b/bfd/libbfd.c
@@ -1207,7 +1207,11 @@ _bfd_mmap_read_temporary (void **data_p, size_t *size_p,
     {
       data = _bfd_mmap_readonly_temporary (abfd, size, mmap_base,
 					   size_p);
-      if (data == NULL || data == MAP_FAILED)
+      /* MAP_FAILED is returned when called from GDB on an object with
+	 opncls_iovec.  Use bfd_read in this case.  */
+      if (data == MAP_FAILED)
+	goto mmap_failed;
+      if (data == NULL)
 	abort ();
       *data_p = data;
       return true;
@@ -1216,6 +1220,7 @@ _bfd_mmap_read_temporary (void **data_p, size_t *size_p,
 
   if (data == NULL)
     {
+mmap_failed:
       data = bfd_malloc (size);
       if (data == NULL)
 	return false;
-- 
2.44.0


             reply	other threads:[~2024-04-03 22:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-03 22:37 H.J. Lu [this message]
2024-04-04  7:15 ` Alan Modra
2024-04-04 13:53   ` H.J. Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240403223744.506469-1-hjl.tools@gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).