]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit - bfd/bfd-in2.h
Tidy bfdio to consistenly use containing archive
authorAlan Modra <amodra@gmail.com>
Tue, 5 Jun 2018 13:01:23 +0000 (22:31 +0930)
committerAlan Modra <amodra@gmail.com>
Tue, 5 Jun 2018 13:09:12 +0000 (22:39 +0930)
commit5c4ce239a3ab9263163a0fe8e7487b39a41c43d1
tree06ed8a716b69752023557e18efc2a994fa9ceb88
parent27b0767593284f97384b3597ebd211164f8c8b47
Tidy bfdio to consistenly use containing archive

Archive element IO is performed on the file of the containing archive,
which leads to the BFD "where" field of archives and their elements
being out of sync with the real file position.  (We're talking
traditional archives here, not thin archives.)  The old bfd_seek code
recognized this by not attempting to optimize away seeks for
archives.  However, there was other code that could return bogus
results.  For example, cache.c limits the number of open files by
closing a file and remembering its state once the limit is reached.
If bfd_tell is called on an archive element when the containing
archive is closed, it will return an invalid file pointer.

It's possible to have a valid "where" field for archives by always
using and updating the containing archive BFD.  That's what this patch
does.  Note that cache.c used to find the containing archive BFD
anyway for the iostream, so we're not really doing extra work, just
transferring it up to the correct abstraction level.

The patch also gets rid of some hacks.  bfd_tell was called when
bfd_seek failed, in an attempt to correct "where".  That's got to be
papering over another problem, so that code has been removed.
bfd_read also had an "optimiziation" to return early when the number
of bytes was zero, and bfd_seek optimized calls that didn't move the
file pointer.  This was covering for a coff_slurp_line_table bug where
IO was attempted on a pe-dll BFD without an iovec.

* bfd.c (struct bfd): Update comment on "where" usage.
* bfdio.c (bfd_bwrite, bfd_stat): Use and update "iovec",
"iostream", and "where" from containing archive file.  Return
error on NULL iovec.
(bfd_bread): Similarly, and return error attempted out of
bounds archive element access.
(bfd_tell, bfd_flush): Use and update "iovec", "iostream", and
"where" from containing archive file.
(bfd_seek): Likewise.  Return error on NULL iovec.  Don't
attempt to optimize away seeks.  Don't paper over errors by
calling bfd_tell.
(bfd_get_mtime): Call bfd_stat rather than iovec->bstat.
(bfd_get_size): Likewise.
(bfd_mmap): Operate on and use iovec of containing archive
file.  Return error on NULL iovec.
* cache.c (bfd_cache_lookup_worker): Abort if working on
archive element bfd.
(cache_bread_1): Delete bfd parameter, add FILE* parameter.
Don't ignore zero byte reads.
(cache_bread): Look up FILE* in cache here.  Error on NULL
lookup.
(cache_bwrite): Rename "where" to "from".
(cache_bmmap): Don't handle archive elements.
* coffcode.h (coff_slurp_line_table): Exit early on zero
lineno count.
* bfd-in2.h: Regenerate.
bfd/ChangeLog
bfd/bfd-in2.h
bfd/bfd.c
bfd/bfdio.c
bfd/cache.c
bfd/coffcode.h