[PATCH] Save/restore file offset while reading notes in core file
Alan Modra
amodra@gmail.com
Fri Mar 19 04:22:36 GMT 2021
On Thu, Mar 18, 2021 at 08:40:26AM -0700, Keith Seitz via Binutils wrote:
> * elfcore.h (_bfd_elf_core_find_build_id): Save and restore
> file offset when calling elf_read_notes.
Looks OK to me, but you could avoid the ftell with
/* Make sure ABFD returns to processing the program headers. */
if (bfd_seek (abfd, (file_ptr) (offset + i_ehdr.e_phoff
+ (i + 1) * sizeof (x_phdr)),
SEEK_SET) != 0)
goto fail;
Either way is fine.
> ---
> bfd/ChangeLog | 5 +++++
> bfd/elfcore.h | 10 ++++++++++
> 2 files changed, 15 insertions(+)
>
> diff --git a/bfd/elfcore.h b/bfd/elfcore.h
> index 3015e582ef0..d5d1555ac03 100644
> --- a/bfd/elfcore.h
> +++ b/bfd/elfcore.h
> @@ -408,8 +408,18 @@ NAME(_bfd_elf, core_find_build_id)
>
> if (i_phdr->p_type == PT_NOTE && i_phdr->p_filesz > 0)
> {
> + /* elf_read_notes will seek to the file offset of the
> + note segment. Save the current location in case
> + this program header contains multiple note segments. */
> + file_ptr origin = bfd_tell (abfd);
> +
> elf_read_notes (abfd, offset + i_phdr->p_offset,
> i_phdr->p_filesz, i_phdr->p_align);
> +
> + /* Make sure ABFD returns to processing the program
> + headers. */
> + if (bfd_seek (abfd, origin, SEEK_SET) != 0)
> + goto fail;
> if (abfd->build_id != NULL)
> return TRUE;
> }
> --
> 2.29.2
--
Alan Modra
Australia Development Lab, IBM
More information about the Binutils
mailing list