* [PATCH v2] bfd: Handle bmmap failure in _bfd_mmap_read_temporary
@ 2024-04-04 13:52 H.J. Lu
2024-04-04 22:24 ` Alan Modra
0 siblings, 1 reply; 2+ messages in thread
From: H.J. Lu @ 2024-04-04 13:52 UTC (permalink / raw)
To: binutils; +Cc: amodra, gdb-patches
iovec->bmmap may return MAP_FAILED, which happens in GDB on objects with
iovec == opncls_iovec. Update _bfd_mmap_read_temporary to handle
iovec->bmmap failure.
* libbfd.c (_bfd_mmap_read_temporary): Handle iovec->bmmap
failure.
---
bfd/libbfd.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/bfd/libbfd.c b/bfd/libbfd.c
index 869f0ed5c66..5126ee207a8 100644
--- a/bfd/libbfd.c
+++ b/bfd/libbfd.c
@@ -1205,12 +1205,18 @@ _bfd_mmap_read_temporary (void **data_p, size_t *size_p,
&& (abfd->flags & BFD_PLUGIN) == 0);
if (use_mmmap)
{
- data = _bfd_mmap_readonly_temporary (abfd, size, mmap_base,
- size_p);
- if (data == NULL || data == MAP_FAILED)
- abort ();
- *data_p = data;
- return true;
+ void *mmaped = _bfd_mmap_readonly_temporary (abfd, size,
+ mmap_base,
+ size_p);
+ /* MAP_FAILED is returned when called from GDB on an object with
+ opncls_iovec. Use bfd_read in this case. */
+ if (mmaped != MAP_FAILED)
+ {
+ if (mmaped == NULL)
+ abort ();
+ *data_p = mmaped;
+ return true;
+ }
}
#endif
--
2.44.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] bfd: Handle bmmap failure in _bfd_mmap_read_temporary
2024-04-04 13:52 [PATCH v2] bfd: Handle bmmap failure in _bfd_mmap_read_temporary H.J. Lu
@ 2024-04-04 22:24 ` Alan Modra
0 siblings, 0 replies; 2+ messages in thread
From: Alan Modra @ 2024-04-04 22:24 UTC (permalink / raw)
To: H.J. Lu; +Cc: binutils, gdb-patches
On Thu, Apr 04, 2024 at 06:52:27AM -0700, H.J. Lu wrote:
> iovec->bmmap may return MAP_FAILED, which happens in GDB on objects with
> iovec == opncls_iovec. Update _bfd_mmap_read_temporary to handle
> iovec->bmmap failure.
>
> * libbfd.c (_bfd_mmap_read_temporary): Handle iovec->bmmap
> failure.
OK.
> bfd/libbfd.c | 18 ++++++++++++------
> 1 file changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/bfd/libbfd.c b/bfd/libbfd.c
> index 869f0ed5c66..5126ee207a8 100644
> --- a/bfd/libbfd.c
> +++ b/bfd/libbfd.c
> @@ -1205,12 +1205,18 @@ _bfd_mmap_read_temporary (void **data_p, size_t *size_p,
> && (abfd->flags & BFD_PLUGIN) == 0);
> if (use_mmmap)
> {
> - data = _bfd_mmap_readonly_temporary (abfd, size, mmap_base,
> - size_p);
> - if (data == NULL || data == MAP_FAILED)
> - abort ();
> - *data_p = data;
> - return true;
> + void *mmaped = _bfd_mmap_readonly_temporary (abfd, size,
> + mmap_base,
> + size_p);
> + /* MAP_FAILED is returned when called from GDB on an object with
> + opncls_iovec. Use bfd_read in this case. */
> + if (mmaped != MAP_FAILED)
> + {
> + if (mmaped == NULL)
> + abort ();
> + *data_p = mmaped;
> + return true;
> + }
> }
> #endif
>
> --
> 2.44.0
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-04-04 22:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-04 13:52 [PATCH v2] bfd: Handle bmmap failure in _bfd_mmap_read_temporary H.J. Lu
2024-04-04 22:24 ` Alan Modra
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).