diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2016-07-18 21:00:00 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2016-07-19 09:58:01 +0100 |
commit | ace667e59aede65c400381f1cff704b61e8ccb0b (patch) | |
tree | 4927878f2378cf375fc8c642623d65a5a54c3870 /ld/plugin.c | |
parent | 59f48f5a45d2300da401f1fccab31ba436217469 (diff) | |
download | gdb-ace667e59aede65c400381f1cff704b61e8ccb0b.zip gdb-ace667e59aede65c400381f1cff704b61e8ccb0b.tar.gz gdb-ace667e59aede65c400381f1cff704b61e8ccb0b.tar.bz2 |
ld: Restore file offset after a plugin fails to claim a file
When using the plugin interface to claim an input file the claim method
from (possible) many plugins can be called on an input file. If these
claim methods read content from the input file then the file offset
stored in the underlying file descriptor will change.
As we share a file descriptor between the plugin interface (created with
dup in ld/plugin.c:plugin_object_p) and the input bfd object, then any
changes to the file offset in the file descriptor will effect the bfd
object. Also, as the changes to the file offset did not originate from
calls through the bfd interface, but instead came from the plugin
directly, then the bfd will not be aware that the file offset has
changed. This is a problem as the bfd library caches the file offset.
If the plugin decides not to claim an input file then, currently, we
leave the bfd in a state where the actual file offset is out of sync
with the cached file offset.
This problem came to light after a recent commit
7d0b9ebc1e0079271a7c7737b53bc026525eab64 (Don't include libbfd.h outside
of bfd, part 6) however, I don't believe that commit actual introduces
the bug, it just exposed the existing issue.
This commit solves the problem by backing up and restoring the file
offset for the file descriptor of the input file. The restore is only
done if the plugin does not claim the input file, as it is in this case
that the bfd library might be used again to try and identify the
unclaimed file.
ld/ChangeLog:
* plugin.c (plugin_call_claim_file): Restore the file offset after
an unsuccessful attempt to claim a file.
* testplug.c (bytes_to_read_before_claim): New global.
(record_read_length): New function, sets new global
bytes_to_read_before_claim.
(parse_option): Handle 'read:<NUMBER>' option.
(onclaim_file): Read file content before checking for claim.
* testsuite/ld-plugin/plugin-30.d: New file.
* testsuite/ld-plugin/plugin.exp: Add new test.
Diffstat (limited to 'ld/plugin.c')
-rw-r--r-- | ld/plugin.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/ld/plugin.c b/ld/plugin.c index ffa0dd3..36094dd 100644 --- a/ld/plugin.c +++ b/ld/plugin.c @@ -1049,9 +1049,14 @@ plugin_call_claim_file (const struct ld_plugin_input_file *file, int *claimed) { if (curplug->claim_file_handler) { + off_t cur_offset; enum ld_plugin_status rv; + called_plugin = curplug; + cur_offset = lseek (file->fd, 0, SEEK_CUR); rv = (*curplug->claim_file_handler) (file, claimed); + if (!*claimed) + lseek (file->fd, cur_offset, SEEK_SET); called_plugin = NULL; if (rv != LDPS_OK) set_plugin_error (curplug->name); |