aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorKevin Buettner <kevinb@redhat.com>2020-06-11 18:58:49 -0700
committerKevin Buettner <kevinb@redhat.com>2020-07-22 12:42:31 -0700
commit5efb677960e786a7cfa3b5a53f15cc6656f33f02 (patch)
treef1aff157d20297eb39ed9c9679be06909f75a8df /bfd
parent94c265d790b88e691b9ea0173b7000a54a3eb0a0 (diff)
downloadbinutils-5efb677960e786a7cfa3b5a53f15cc6656f33f02.zip
binutils-5efb677960e786a7cfa3b5a53f15cc6656f33f02.tar.gz
binutils-5efb677960e786a7cfa3b5a53f15cc6656f33f02.tar.bz2
Update binary_get_section_contents to seek using section's file position
I have a patch for GDB which opens and reads from BFDs using the "binary" target. However, for it to work, we need to be able to get a section's contents based from the file position of that section. At the moment, reading a section's contents will always read from the start of the file regardless of where that section is located. While this was fine for the original use of the "binary" target, it won't work for my use case. This change shouldn't impact any existing callers due to the fact that the single .data section is initialized with a filepos of 0. bfd/ChangeLog: * binary.c (binary_get_section_contents): Seek using offset from section's file position.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog5
-rw-r--r--bfd/binary.c12
2 files changed, 11 insertions, 6 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index adbf6f3..5849c4e 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,10 @@
2020-07-22 Kevin Buettner <kevinb@redhat.com>
+ * binary.c (binary_get_section_contents): Seek using offset
+ from section's file position.
+
+2020-07-22 Kevin Buettner <kevinb@redhat.com>
+
* elf.c (_bfd_elf_make_section_from_phdr): Remove hack for GDB.
2020-07-22 Max Filippov <jcmvbkbc@gmail.com>
diff --git a/bfd/binary.c b/bfd/binary.c
index 999de0d..e872924 100644
--- a/bfd/binary.c
+++ b/bfd/binary.c
@@ -19,10 +19,10 @@
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
-/* This is a BFD backend which may be used to write binary objects.
- It may only be used for output, not input. The intention is that
- this may be used as an output format for objcopy in order to
- generate raw binary data.
+/* This is a BFD backend which may be used to read or write binary
+ objects. Historically, it was used as an output format for objcopy
+ in order to generate raw binary data, but is now used for other
+ purposes as well.
This is very simple. The only complication is that the real data
will start at some address X, and in some cases we will not want to
@@ -97,12 +97,12 @@ binary_object_p (bfd *abfd)
static bfd_boolean
binary_get_section_contents (bfd *abfd,
- asection *section ATTRIBUTE_UNUSED,
+ asection *section,
void * location,
file_ptr offset,
bfd_size_type count)
{
- if (bfd_seek (abfd, offset, SEEK_SET) != 0
+ if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0
|| bfd_bread (location, count, abfd) != count)
return FALSE;
return TRUE;