From patchwork Mon Jun 16 13:51:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 1510 Received: (qmail 18620 invoked by alias); 16 Jun 2014 13:51:07 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 18606 invoked by uid 89); 16 Jun 2014 13:51:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 16 Jun 2014 13:51:05 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5GDp3Jm014910 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 16 Jun 2014 09:51:04 -0400 Received: from barimba (ovpn-113-103.phx2.redhat.com [10.3.113.103]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s5GDp1C8004189 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Mon, 16 Jun 2014 09:51:02 -0400 From: Tom Tromey To: Jan Kratochvil Cc: Pedro Alves , gdb-patches@sourceware.org Subject: Re: ASAN crash regression [Re: [PATCH 2/2] move the demangled_names_hash into the per-BFD] References: <1376512619-3211-1-git-send-email-tromey@redhat.com> <1376512619-3211-3-git-send-email-tromey@redhat.com> <521CEA9F.9070003@redhat.com> <87li24khkn.fsf@fleche.redhat.com> <20140615074238.GA27553@host2.jankratochvil.net> Date: Mon, 16 Jun 2014 07:51:01 -0600 In-Reply-To: <20140615074238.GA27553@host2.jankratochvil.net> (Jan Kratochvil's message of "Sun, 15 Jun 2014 09:42:38 +0200") Message-ID: <87r42pkloa.fsf@fleche.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Jan> ./configure ... -fsanitize=address Jan> echo 'void f(){}main(){}'|gcc -x c++ - -g;ASAN_OPTIONS=symbolize=1 ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer ./gdb -batch a.out -ex 'file a.out' Readily seen with valgrind as well. Here's my proposed fix. Tom commit 3a93a67ad0ea3495f67c9708673345b73de2d806 Author: Tom Tromey Date: Mon Jun 16 03:17:19 2014 -0600 fix memory errors with demangled name hash This fixes a regression that Jan pointed out. The bug is that some names were allocated by dwarf2read on the objfile obstack, but then passed to SYMBOL_SET_NAMES with copy_name=0. This violates the invariant that the names must have a lifetime tied to the lifetime of the BFD. The fix is to allocate names on the per-BFD obstack. I looked at all callers, direct or indirect, of SYMBOL_SET_NAMES that pass copy_name=0. Note that only the ELF and DWARF readers do this; other symbol readers were never updated (and perhaps cannot be, depending on the details of the formats). This is why the patch is relatively small. Built and regtested on x86-64 Fedora 20. 2014-06-16 Tom Tromey * dwarf2read.c (fixup_go_packaging, dwarf2_compute_name) (dwarf2_physname, read_partial_die) (guess_partial_die_structure_name, fixup_partial_die) (guess_full_die_structure_name, anonymous_struct_prefix) (dwarf2_name): Use per-BFD obstack. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a999390..c773e7b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,13 @@ 2014-06-16 Tom Tromey + * dwarf2read.c (fixup_go_packaging, dwarf2_compute_name) + (dwarf2_physname, read_partial_die) + (guess_partial_die_structure_name, fixup_partial_die) + (guess_full_die_structure_name, anonymous_struct_prefix) + (dwarf2_name): Use per-BFD obstack. + +2014-06-16 Tom Tromey + * minsyms.h (prim_record_minimal_symbol) (prim_record_minimal_symbol_and_info): Update comments. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 3e441dc..bd6e547 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -7745,9 +7745,10 @@ fixup_go_packaging (struct dwarf2_cu *cu) if (package_name != NULL) { struct objfile *objfile = cu->objfile; - const char *saved_package_name = obstack_copy0 (&objfile->objfile_obstack, - package_name, - strlen (package_name)); + const char *saved_package_name + = obstack_copy0 (&objfile->per_bfd->storage_obstack, + package_name, + strlen (package_name)); struct type *type = init_type (TYPE_CODE_MODULE, 0, 0, saved_package_name, objfile); struct symbol *sym; @@ -8365,6 +8366,8 @@ dwarf2_compute_name (const char *name, long length; const char *prefix; struct ui_file *buf; + char *intermediate_name; + const char *canonical_name = NULL; prefix = determine_prefix (die, cu); buf = mem_fileopen (); @@ -8541,19 +8544,25 @@ dwarf2_compute_name (const char *name, } } - name = ui_file_obsavestring (buf, &objfile->objfile_obstack, - &length); + intermediate_name = ui_file_xstrdup (buf, &length); ui_file_delete (buf); if (cu->language == language_cplus) - { - const char *cname - = dwarf2_canonicalize_name (name, cu, - &objfile->objfile_obstack); + canonical_name + = dwarf2_canonicalize_name (intermediate_name, cu, + &objfile->per_bfd->storage_obstack); + + /* If we only computed INTERMEDIATE_NAME, or if + INTERMEDIATE_NAME is already canonical, then we need to + copy it to the appropriate obstack. */ + if (canonical_name == NULL || canonical_name == intermediate_name) + name = obstack_copy0 (&objfile->per_bfd->storage_obstack, + intermediate_name, + strlen (intermediate_name)); + else + name = canonical_name; - if (cname != NULL) - name = cname; - } + xfree (intermediate_name); } } @@ -8562,7 +8571,7 @@ dwarf2_compute_name (const char *name, /* Return the fully qualified name of DIE, based on its DW_AT_name. If scope qualifiers are appropriate they will be added. The result - will be allocated on the objfile_obstack, or NULL if the DIE does + will be allocated on the storage_obstack, or NULL if the DIE does not have a name. NAME may either be from a previous call to dwarf2_name or NULL. @@ -8677,7 +8686,8 @@ dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu) retval = canon; if (need_copy) - retval = obstack_copy0 (&objfile->objfile_obstack, retval, strlen (retval)); + retval = obstack_copy0 (&objfile->per_bfd->storage_obstack, + retval, strlen (retval)); do_cleanups (back_to); return retval; @@ -15508,7 +15518,7 @@ read_partial_die (const struct die_reader_specs *reader, default: part_die->name = dwarf2_canonicalize_name (DW_STRING (&attr), cu, - &objfile->objfile_obstack); + &objfile->per_bfd->storage_obstack); break; } break; @@ -15793,7 +15803,7 @@ guess_partial_die_structure_name (struct partial_die_info *struct_pdi, if (actual_class_name != NULL) { struct_pdi->name - = obstack_copy0 (&cu->objfile->objfile_obstack, + = obstack_copy0 (&cu->objfile->per_bfd->storage_obstack, actual_class_name, strlen (actual_class_name)); xfree (actual_class_name); @@ -15879,8 +15889,9 @@ fixup_partial_die (struct partial_die_info *part_die, else base = demangled; - part_die->name = obstack_copy0 (&cu->objfile->objfile_obstack, - base, strlen (base)); + part_die->name + = obstack_copy0 (&cu->objfile->per_bfd->storage_obstack, + base, strlen (base)); xfree (demangled); } } @@ -18557,7 +18568,7 @@ guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu) && actual_name[actual_name_len - die_name_len - 1] == ':') name = - obstack_copy0 (&cu->objfile->objfile_obstack, + obstack_copy0 (&cu->objfile->per_bfd->storage_obstack, actual_name, actual_name_len - die_name_len - 2); } @@ -18603,7 +18614,7 @@ anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu) if (base == NULL || base == DW_STRING (attr) || base[-1] != ':') return ""; - return obstack_copy0 (&cu->objfile->objfile_obstack, + return obstack_copy0 (&cu->objfile->per_bfd->storage_obstack, DW_STRING (attr), &base[-1] - DW_STRING (attr)); } @@ -18943,8 +18954,9 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) char *base; /* FIXME: we already did this for the partial symbol... */ - DW_STRING (attr) = obstack_copy0 (&cu->objfile->objfile_obstack, - demangled, strlen (demangled)); + DW_STRING (attr) + = obstack_copy0 (&cu->objfile->per_bfd->storage_obstack, + demangled, strlen (demangled)); DW_STRING_IS_CANONICAL (attr) = 1; xfree (demangled); @@ -18967,7 +18979,7 @@ dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) { DW_STRING (attr) = dwarf2_canonicalize_name (DW_STRING (attr), cu, - &cu->objfile->objfile_obstack); + &cu->objfile->per_bfd->storage_obstack); DW_STRING_IS_CANONICAL (attr) = 1; } return DW_STRING (attr);