[PATCH] readelf: use fseeko64 or fseeko if possible
Brett Werling
bwerl.dev@gmail.com
Thu Nov 17 14:09:05 GMT 2022
> There shouldn't be a need for the FSEEK_OFF_TYPE cast. Casts always
> make me question the code, and indeed in this case you have a whole
> lot of unsigned long variables and struct fields that will need to be
> wider in order to support large archives. Also, functions like
> offset_from_vma will need changing.
>
> > if (reason)
> > @@ -6262,8 +6273,8 @@ the .dynamic section is not the same as the dynamic segment\n"));
> > if (segment->p_offset >= filedata->file_size
> > || segment->p_filesz > filedata->file_size - segment->p_offset
> > || segment->p_filesz - 1 >= (size_t) -2
> > - || fseek (filedata->handle,
> > - filedata->archive_file_offset + (long) segment->p_offset,
> > + || FSEEK_FUNC (filedata->handle,
> > + (FSEEK_OFF_TYPE)filedata->archive_file_offset + (long) segment->p_offset,
> > SEEK_SET))
>
> and the (long) also should go. I'm happy enough with the patch as-is,
> except please remove all those FSEEK_OFF_TYPE casts. Further fixes
> can be done in followup patches.
>
> --
> Alan Modra
> Australia Development Lab, IBM
I tend to agree in that I don't particularly like the casts myself. To be
honest, I only had them in there to try and ensure the math between the
"offset" operands was being done on an off64_t or off_t and try to avoid
the chance of a long. I have no problem removing them and I assume the
resulting code will be functionally equivalent. New patch incoming
shortly.
If others watching this change feel strongly enough that this needs to be
part of a wider effort, please indicate so and I will let this patch lie.
I mostly wanted to avoid having to carry it forward locally in my
particular use case.
Brett
More information about the Binutils
mailing list