Blame SOURCES/gdb-rhbz1842691-corefile-mem-access-6of15.patch

be07d7
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
be07d7
From: Keith Seitz <keiths@redhat.com>
be07d7
Date: Mon, 27 Jul 2020 17:32:50 -0400
be07d7
Subject: gdb-rhbz1842691-corefile-mem-access-6of15.patch
be07d7
be07d7
;; Update binary_get_section_contents to seek using section's file position
be07d7
;; Kevin Buettner, RH BZ 1842961
be07d7
be07d7
   Author: Kevin Buettner <kevinb@redhat.com>
be07d7
   Date:   Thu Jun 11 18:58:49 2020 -0700
be07d7
be07d7
    Update binary_get_section_contents to seek using section's file position
be07d7
be07d7
    I have a patch for GDB which opens and reads from BFDs using the
be07d7
    "binary" target.  However, for it to work, we need to be able to get a
be07d7
    section's contents based from the file position of that section.
be07d7
be07d7
    At the moment, reading a section's contents will always read from the
be07d7
    start of the file regardless of where that section is located.  While
be07d7
    this was fine for the original use of the "binary" target, it won't
be07d7
    work for my use case.  This change shouldn't impact any existing
be07d7
    callers due to the fact that the single .data section is initialized
be07d7
    with a filepos of 0.
be07d7
be07d7
    bfd/ChangeLog:
be07d7
be07d7
    	* binary.c (binary_get_section_contents): Seek using offset
be07d7
    	from section's file position.
be07d7
be07d7
diff --git a/bfd/binary.c b/bfd/binary.c
be07d7
--- a/bfd/binary.c
be07d7
+++ b/bfd/binary.c
be07d7
@@ -19,10 +19,10 @@
be07d7
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
be07d7
    MA 02110-1301, USA.  */
be07d7
 
be07d7
-/* This is a BFD backend which may be used to write binary objects.
be07d7
-   It may only be used for output, not input.  The intention is that
be07d7
-   this may be used as an output format for objcopy in order to
be07d7
-   generate raw binary data.
be07d7
+/* This is a BFD backend which may be used to read or write binary
be07d7
+   objects.  Historically, it was used as an output format for objcopy
be07d7
+   in order to generate raw binary data, but is now used for other
be07d7
+   purposes as well.
be07d7
 
be07d7
    This is very simple.  The only complication is that the real data
be07d7
    will start at some address X, and in some cases we will not want to
be07d7
@@ -97,12 +97,12 @@ binary_object_p (bfd *abfd)
be07d7
 
be07d7
 static bfd_boolean
be07d7
 binary_get_section_contents (bfd *abfd,
be07d7
-			     asection *section ATTRIBUTE_UNUSED,
be07d7
+			     asection *section,
be07d7
 			     void * location,
be07d7
 			     file_ptr offset,
be07d7
 			     bfd_size_type count)
be07d7
 {
be07d7
-  if (bfd_seek (abfd, offset, SEEK_SET) != 0
be07d7
+  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0
be07d7
       || bfd_bread (location, count, abfd) != count)
be07d7
     return FALSE;
be07d7
   return TRUE;