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