[PATCH] readelf: use fseeko for elf files >= 2 GiB on x86_64-mingw32
Brett Werling
bwerl.dev@gmail.com
Mon Nov 14 15:52:30 GMT 2022
On Mon, Nov 14, 2022 at 9:30 AM Jan Beulich <jbeulich@suse.com> wrote:
> On 14.11.2022 16:03, Brett Werling via Binutils wrote:
> > Switch all fseek calls to fseeko and cast the given offset as an off_t
> > accordingly. When building readelf for x86_64-mingw32, a long will only
> > be 32 bits wide. If the elf file in question is >= 2 GiB, that is
> > greater than the max long value, and therefore fseek will fail
> > indicating that the offset is negative.
> >
> > To work around this and support up to 4 GiB, we switch to using fseeko
> > and cast the unsigned long offsets as off_t values because the size of
> > off_t is 64 bits on x86_64-mingw32.
>
> Is fseeko() uniformly available on all platforms binutils can be built
> for? I'm afraid the answer is no, so at least you'd need to introduce
> some configure logic for this plus some abstraction.
>
> Jan
>
I think you are correct, this will need some conditional logic to be "safe"
to
include, and even then the casting to off_t would become a little more
complicated. I will look deeper into what can be done here.
I had also considered iterative calls on fseek() using longs and SEEK_CUR,
just ensuring that we don't blow past LONG_MAX. That didn't seem as
clean or efficient of a change, so I dropped it.
Brett
More information about the Binutils
mailing list