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

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