diff options
author | Alan Modra <amodra@gmail.com> | 2023-04-11 22:11:26 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2023-04-12 09:40:13 +0930 |
commit | f656f9c77c27298c71f0c864d3e8a095a55cb594 (patch) | |
tree | 6f549bb43a9eb11bdcb49e1471f16033d5b98149 /bfd/cache.c | |
parent | dff05c9c82fd877cfba432e0f4f82b41bd0f5257 (diff) | |
download | gdb-f656f9c77c27298c71f0c864d3e8a095a55cb594.zip gdb-f656f9c77c27298c71f0c864d3e8a095a55cb594.tar.gz gdb-f656f9c77c27298c71f0c864d3e8a095a55cb594.tar.bz2 |
pe_ILF_object_p and bfd_check_format_matches
If pe_ILF_object_p succeeds, pe_ILF_build_a_bfd will have changed the
bfd from being file backed to in-memory. This can have unfortunate
results for targets checked by bfd_check_format_matches after that
point as they will be matching against the created in-memory image
rather than the file. bfd_preserve_restore also has a problem if it
flips the BFD_IN_MEMORY flag, because the flag affects iostream
meaning and should be set if using _bfd_memory_iovec. To fix these
problems, save and restore iostream and iovec along with flags, and
modify bfd_reinit to make the bfd file backed again. Restoring the
iovec and iostream allows the hack in bfd_reinit keeping BFD_IN_MEMORY
(part of BFD_FLAGS_SAVED) to be removed.
One more detail: If restoring from file backed to in-memory then the
bfd needs to be forcibly removed from the cache lru list, since after
the bfd becomes in-memory a bfd_close will delete the bfd's memory
leaving the lru list pointing into freed memory.
* cache.c (bfd_cache_init): Clear BFD_CLOSED_BY_CACHE here..
(bfd_cache_lookup_worker): ..rather than here.
(bfd_cache_close): Comment.
* format.c (struct bfd_preserve): Add iovec and iostream fields.
(bfd_preserve_save): Save them..
(bfd_preserve_restore): ..and restore them, calling
bfd_cache_close if the iovec differs.
(bfd_reinit): Add preserve param. If the bfd has been flipped
to in-memory, reopen the file. Restore flags.
* peicode.h (pe_ILF_cleanup): New function.
(pe_ILF_object_p): Return it.
* bfd.c (BFD_FLAGS_SAVED): Delete.
* bfd-in2.h: Regenerate.
Diffstat (limited to 'bfd/cache.c')
-rw-r--r-- | bfd/cache.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/bfd/cache.c b/bfd/cache.c index ab36c85..3b91cce 100644 --- a/bfd/cache.c +++ b/bfd/cache.c @@ -266,10 +266,7 @@ bfd_cache_lookup_worker (bfd *abfd, enum cache_flag flag) && !(flag & CACHE_NO_SEEK_ERROR)) bfd_set_error (bfd_error_system_call); else - { - abfd->flags &= ~BFD_CLOSED_BY_CACHE; - return (FILE *) abfd->iostream; - } + return (FILE *) abfd->iostream; /* xgettext:c-format */ _bfd_error_handler (_("reopening %pB: %s"), @@ -506,6 +503,7 @@ bfd_cache_init (bfd *abfd) } abfd->iovec = &cache_iovec; insert (abfd); + abfd->flags &= ~BFD_CLOSED_BY_CACHE; ++open_files; return true; } @@ -528,6 +526,7 @@ DESCRIPTION bool bfd_cache_close (bfd *abfd) { + /* Don't remove this test. bfd_reinit depends on it. */ if (abfd->iovec != &cache_iovec) return true; |