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.
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.
(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.
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.
Won't fix.