From patchwork Wed Jun 27 20:42:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 28086 Received: (qmail 24580 invoked by alias); 27 Jun 2018 20:42:44 -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 22842 invoked by uid 89); 27 Jun 2018 20:42:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=macos, macOS, Hx-languages-length:1957 X-HELO: gateway21.websitewelcome.com Received: from gateway21.websitewelcome.com (HELO gateway21.websitewelcome.com) (192.185.45.212) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 27 Jun 2018 20:42:42 +0000 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway21.websitewelcome.com (Postfix) with ESMTP id 655E2400C865F for ; Wed, 27 Jun 2018 15:42:40 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id YHGZfJV3xaSeyYHGnfz8q6; Wed, 27 Jun 2018 15:42:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version :Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=AWTiOimWSvAPb8rhmz67a/k7+ma26YER1omfzbtxepM=; b=NHsZftzoBc2bMYdKRmdtcC7jNx i/oSA64Fl+H37tBNPx2dgFu2m8AMJQ89UQzMnGR7gVgevD7ejhduh1jXpWpy+2zco8IIjx7ekaKAD MoeyuFhEcMDJGKQ2sEarUJyqK; Received: from 75-166-79-120.hlrn.qwest.net ([75.166.79.120]:38270 helo=pokyo.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fYHGY-0032Vr-TF; Wed, 27 Jun 2018 15:42:14 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [FYI] Fix crash in machoread.c Date: Wed, 27 Jun 2018 14:42:11 -0600 Message-Id: <20180627204211.18963-1-tom@tromey.com> "./gdb ./gdb" was crashing for me on macOS. Investigating showed that macho_symfile_read was crashing because "symbol_table" was being freed too soon. This was introduced by my earlier patch to change macho_symfile_read to use a std::vector. Tested on macOS 10.13.5 using "./gdb ./gdb". This should un-break various already existing tests (testsuite/gdb.gdb at least), so no new test case. I'm checking this in as obvious. gdb/ChangeLog 2018-06-27 Tom Tromey * machoread.c (macho_symfile_read): Define "symbol_table" earlier. --- gdb/ChangeLog | 4 ++++ gdb/machoread.c | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index be45bc31fa2..a125b72e420 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2018-06-27 Tom Tromey + + * machoread.c (macho_symfile_read): Define "symbol_table" earlier. + 2018-06-27 Simon Marchi * gdb-gdb.py.in: Format using autopep8. diff --git a/gdb/machoread.c b/gdb/machoread.c index 4c1d4f0bfa7..07e1cdaf4f8 100644 --- a/gdb/machoread.c +++ b/gdb/machoread.c @@ -793,6 +793,9 @@ macho_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) bfd *abfd = objfile->obfd; long storage_needed; std::vector oso_vector; + /* We have to hold on to the symbol table until the call to + macho_symfile_read_all_oso at the end of this function. */ + gdb::def_vector symbol_table; /* Get symbols from the symbol table only if the file is an executable. The symbol table of object files is not relocated and is expected to @@ -812,8 +815,7 @@ macho_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) { long symcount; - gdb::def_vector symbol_table (storage_needed - / sizeof (asymbol *)); + symbol_table.resize (storage_needed / sizeof (asymbol *)); minimal_symbol_reader reader (objfile);