This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug gdb/23326] New: make_output_phdrs mishandles inaccessible sections


https://sourceware.org/bugzilla/show_bug.cgi?id=23326

            Bug ID: 23326
           Summary: make_output_phdrs mishandles inaccessible sections
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: timothywboddy at gmail dot com
  Target Milestone: ---

When make_output_phdrs is run it always sets the PF_R bit, regardless of
whether or not it should:

static void
make_output_phdrs (bfd *obfd, asection *osec, void *ignored)
{
  int p_flags = 0;
  int p_type = 0;

  /* FIXME: these constants may only be applicable for ELF.  */
  if (startswith (bfd_section_name (obfd, osec), "load"))
    p_type = PT_LOAD;
  else if (startswith (bfd_section_name (obfd, osec), "note"))
    p_type = PT_NOTE;
  else
    p_type = PT_NULL;

  p_flags |= PF_R;      /* Segment is readable.  */


This is wrong because most processes have some sections that are entirely
inaccessible (not readable, writable or executable).  Three common cases
include:

1) 4k page guards immediately prior to stack areas for pthreads
2) Regions of 2MB or 2MB-1k used to align the writable area for a shared
library
3) Heap tails for heaps used by glibc malloc, which on a 64-bit process
reserves 64MB per heap but typically marks only a very small prefix of the heap
as RW when the heap is created.  The remainder is marked as inaccessible, to
reserve the space if the heap should need to grow.

It is misleading to mark these as readable because it gives misinformation
about the actual state of the process as of the time the heap was created.  It
is wasteful in terms of disk space and time to create the core, particularly in
case (3) that such incorrectly marked sections actually have images written to
the core.

This is a regression but I haven't checked how recent it is.  Older versions of
gdb correctly handled inaccessible sections by writing phdrs for inaccessible
sections, with PF_R correctly turned off and no image in the core.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]