[PATCH] bfd: Handle bmmap failure in _bfd_mmap_read_temporary

Alan Modra amodra@gmail.com
Thu Apr 4 07:15:36 GMT 2024


On Wed, Apr 03, 2024 at 03:37:44PM -0700, H.J. Lu wrote:
> 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:

Will this give an unused label warning when !USE_MMAP?  I'm sure you
can rewrite the patch without needing a label if you use another temp
rather than "data" inside the use_mmap block.  That would be a good
idea anyway as it saves anyone wondering whether the !final_link case
can have "data" non-NULL and thus malloc is not needed.

>        data = bfd_malloc (size);
>        if (data == NULL)
>  	return false;
> -- 
> 2.44.0

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list