Bug 21679 - bfd_get_file_size should be cached for readonly file
Summary: bfd_get_file_size should be cached for readonly file
Status: RESOLVED WONTFIX
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.29
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-06-26 23:19 UTC by H.J. Lu
Modified: 2017-06-28 18:18 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2017-06-26 23:19:11 UTC
bfd_get_file_size may be called many times on the same input file with
many sections.  It should be cached to avoid calling fstat over and over
again.
Comment 1 Alan Modra 2017-06-27 02:13:47 UTC
Is there a good reason for bfd_get_file_size to be called before reading sections?  Only for archives, I'd guess.  For object files, you can just wait for the read to return a count less than expected.
Comment 2 H.J. Lu 2017-06-27 02:45:36 UTC
(In reply to Alan Modra from comment #1)
> Is there a good reason for bfd_get_file_size to be called before reading
> sections?  Only for archives, I'd guess.  For object files, you can just
> wait for the read to return a count less than expected.

For corrupted object files, the section offset and size may be incorrect.
The check is supposed to prevent reading beyond the end of file.  If it
can be done in a different way to avoid calling bfd_get_file_size, we
should change it.
Comment 3 Alan Modra 2017-06-27 04:10:59 UTC
My point is that you *can't* read beyond the end of an object file, unless it is inside an archive.  So you only need to check archives, and the archive check doesn't call fstat.
Comment 4 H.J. Lu 2017-06-28 18:18:01 UTC
Won't fix.