diff options
author | Alan Modra <amodra@gmail.com> | 2018-06-05 22:31:23 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2018-06-05 22:39:12 +0930 |
commit | 5c4ce239a3ab9263163a0fe8e7487b39a41c43d1 (patch) | |
tree | 06ed8a716b69752023557e18efc2a994fa9ceb88 /bfd/coffcode.h | |
parent | 27b0767593284f97384b3597ebd211164f8c8b47 (diff) | |
download | binutils-5c4ce239a3ab9263163a0fe8e7487b39a41c43d1.zip binutils-5c4ce239a3ab9263163a0fe8e7487b39a41c43d1.tar.gz binutils-5c4ce239a3ab9263163a0fe8e7487b39a41c43d1.tar.bz2 |
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.
Diffstat (limited to 'bfd/coffcode.h')
-rw-r--r-- | bfd/coffcode.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/bfd/coffcode.h b/bfd/coffcode.h index 2ca3205..11c22ab 100644 --- a/bfd/coffcode.h +++ b/bfd/coffcode.h @@ -4265,6 +4265,9 @@ coff_slurp_line_table (bfd *abfd, asection *asect) bfd_boolean have_func; bfd_boolean ret = TRUE; + if (asect->lineno_count == 0) + return TRUE; + BFD_ASSERT (asect->lineno == NULL); if (asect->lineno_count > asect->size) |