Blame SOURCES/gdb-rhbz1842691-corefile-mem-access-1of15.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 16:34:37 -0400
59b2e3
Subject: gdb-rhbz1842691-corefile-mem-access-1of15.patch
59b2e3
59b2e3
;; Remove hack for GDB which sets the section size to 0
59b2e3
;; Kevin Buettner, RH BZ 1842691
59b2e3
59b2e3
    Author: Kevin Buettner <kevinb@redhat.com>
59b2e3
59b2e3
    Remove hack for GDB which sets the section size to 0
59b2e3
59b2e3
    This commit removes a hack for GDB which was introduced in 2007.
59b2e3
    See:
59b2e3
59b2e3
        https://sourceware.org/ml/binutils/2007-08/msg00044.html
59b2e3
59b2e3
    That hack mostly allowed GDB's handling of core files to continue to
59b2e3
    work without any changes to GDB.
59b2e3
59b2e3
    The problem with setting the section size to zero is that GDB won't
59b2e3
    know how big that section is/was.  Often, this doesn't matter because
59b2e3
    the data in question are found in the exec file.  But it can happen
59b2e3
    that the section describes memory that had been allocated, but never
59b2e3
    written to.  In this instance, the contents of that memory region are
59b2e3
    not written to the core file.  Also, since the region in question was
59b2e3
    dynamically allocated, it won't appear in the exec file.  We don't
59b2e3
    want these regions to appear as inaccessible to GDB (since they *were*
59b2e3
    accessible when the process was live), so it's important that GDB know
59b2e3
    the size of the region.
59b2e3
59b2e3
    I've made changes to GDB which correctly handles this case.  When
59b2e3
    attempting to access memory, GDB will first consider core file data
59b2e3
    for which both SEC_ALLOC and SEC_HAS_CONTENTS is set.  Next, if that
59b2e3
    fails, GDB will attempt to find the data in the exec file.  Finally,
59b2e3
    if that also fails, GDB will attempt to access memory in the sections
59b2e3
    which are flagged as SEC_ALLOC, but not SEC_HAS_CONTENTS.
59b2e3
59b2e3
    bfd/ChangeLog:
59b2e3
59b2e3
        * elf.c (_bfd_elf_make_section_from_phdr): Remove hack for GDB.
59b2e3
59b2e3
diff --git a/bfd/elf.c b/bfd/elf.c
59b2e3
--- a/bfd/elf.c
59b2e3
+++ b/bfd/elf.c
59b2e3
@@ -3032,14 +3032,6 @@ _bfd_elf_make_section_from_phdr (bfd *abfd,
59b2e3
       newsect->alignment_power = bfd_log2 (align);
59b2e3
       if (hdr->p_type == PT_LOAD)
59b2e3
 	{
59b2e3
-	  /* Hack for gdb.  Segments that have not been modified do
59b2e3
-	     not have their contents written to a core file, on the
59b2e3
-	     assumption that a debugger can find the contents in the
59b2e3
-	     executable.  We flag this case by setting the fake
59b2e3
-	     section size to zero.  Note that "real" bss sections will
59b2e3
-	     always have their contents dumped to the core file.  */
59b2e3
-	  if (bfd_get_format (abfd) == bfd_core)
59b2e3
-	    newsect->size = 0;
59b2e3
 	  newsect->flags |= SEC_ALLOC;
59b2e3
 	  if (hdr->p_flags & PF_X)
59b2e3
 	    newsect->flags |= SEC_CODE;