From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24840 invoked by alias); 20 Jun 2007 18:23:20 -0000 Received: (qmail 24829 invoked by uid 22791); 20 Jun 2007 18:23:19 -0000 X-Spam-Check-By: sourceware.org Received: from smtp116.sbc.mail.sp1.yahoo.com (HELO smtp116.sbc.mail.sp1.yahoo.com) (69.147.64.89) by sourceware.org (qpsmtpd/0.31) with SMTP; Wed, 20 Jun 2007 18:23:17 +0000 Received: (qmail 34060 invoked from network); 20 Jun 2007 18:23:10 -0000 Received: from unknown (HELO lucon.org) (hjjean@sbcglobal.net@76.202.77.159 with login) by smtp116.sbc.mail.sp1.yahoo.com with SMTP; 20 Jun 2007 18:23:09 -0000 X-YMail-OSG: GMTzWCwVM1kdVxZRWmVsqk3TX.5V3HV_XVbIqdrwQEag1F6DJf.SyPR_TVwtWL0cWeY9Z4LHvwAMdxfkahcfh5vBCAr1fjoI1Jiv3JwaiYT1mzngrw-- Received: by lucon.org (Postfix, from userid 500) id CDF3946EEA9; Wed, 20 Jun 2007 11:23:08 -0700 (PDT) Date: Wed, 20 Jun 2007 18:23:00 -0000 From: "H. J. Lu" To: GDB Subject: PATCH: Set SEC_NEVER_LOAD when clearing SEC_LOAD for gcore Message-ID: <20070620182308.GA7859@lucon.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.3i Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-06/txt/msg00397.txt.bz2 http://sources.redhat.com/bugzilla/show_bug.cgi?id=4606 is a gdb bug. When gcore_create_callback clears SEC_LOAD, it does't set SEC_NEVER_LOAD nor clear SEC_HAS_CONTENTS. elf_fake_sections has if (this_hdr->sh_type == SHT_NULL) { if ((asect->flags & SEC_GROUP) != 0) this_hdr->sh_type = SHT_GROUP; else if ((asect->flags & SEC_ALLOC) != 0 && (((asect->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0) || (asect->flags & SEC_NEVER_LOAD) != 0)) this_hdr->sh_type = SHT_NOBITS; else this_hdr->sh_type = SHT_PROGBITS; } As the result, this_hdr->sh_type is set to SHT_PROGBITS while SEC_LOAD is cleared. When Alan made this change: - if ((flags & SEC_LOAD) != 0) + if (this_hdr->sh_type != SHT_NOBITS) in assign_file_positions_for_load_sections, gcore no longer works correctly. This patch sets SEC_NEVER_LOAD when clearing SEC_LOAD. It restores the old behavior and reduces the size of core file significantly. I tested it on both Linux/x86-64 and Linux/ia64. On Linux/ia64, I got -rw-r--r-- 1 hjl hjl 349400 Jun 20 10:54 core.new -rw-r--r-- 1 hjl hjl 3003608 Jun 19 17:28 core.old On Linux/x86-64, I got -rw-r--r-- 1 hjl hjl 195848 Jun 20 11:10 core.new -rw-r--r-- 1 hjl hjl 1531144 Jun 20 11:21 core.old BTW, bfd_make_section_anyway_with_flags is preferred over bfd_make_section_anyway and bfd_set_section_flags. H.J. --- 2007-06-20 H.J. Lu PR 4606 * gcore.c (gcore_command): Use bfd_make_section_anyway_with_flags instead of bfd_make_section_anyway. (gcore_create_callback): Likewise. Also set SEC_NEVER_LOAD when clearing SEC_LOAD. --- gdb/gcore.c.gcore 2007-06-19 08:44:04.000000000 -0700 +++ gdb/gcore.c 2007-06-20 11:09:43.000000000 -0700 @@ -88,14 +88,15 @@ gcore_command (char *args, int from_tty) /* Create the note section. */ if (note_data != NULL && note_size != 0) { - note_sec = bfd_make_section_anyway (obfd, "note0"); + note_sec = bfd_make_section_anyway_with_flags (obfd, "note0", + SEC_HAS_CONTENTS + | SEC_READONLY + | SEC_ALLOC); if (note_sec == NULL) error (_("Failed to create 'note' section for corefile: %s"), bfd_errmsg (bfd_get_error ())); bfd_set_section_vma (obfd, note_sec, 0); - bfd_set_section_flags (obfd, note_sec, - SEC_HAS_CONTENTS | SEC_READONLY | SEC_ALLOC); bfd_set_section_alignment (obfd, note_sec, 0); bfd_set_section_size (obfd, note_sec, note_size); } @@ -359,6 +360,7 @@ gcore_create_callback (CORE_ADDR vaddr, && !(bfd_get_file_flags (abfd) & BFD_IN_MEMORY)) { flags &= ~SEC_LOAD; + flags |= SEC_NEVER_LOAD; goto keep; /* break out of two nested for loops */ } } @@ -372,7 +374,7 @@ gcore_create_callback (CORE_ADDR vaddr, else flags |= SEC_DATA; - osec = bfd_make_section_anyway (obfd, "load"); + osec = bfd_make_section_anyway_with_flags (obfd, "load", flags); if (osec == NULL) { warning (_("Couldn't make gcore segment: %s"), @@ -389,7 +391,6 @@ gcore_create_callback (CORE_ADDR vaddr, bfd_set_section_size (obfd, osec, size); bfd_set_section_vma (obfd, osec, vaddr); bfd_section_lma (obfd, osec) = 0; /* ??? bfd_set_section_lma? */ - bfd_set_section_flags (obfd, osec, flags); return 0; }