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

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