From patchwork Fri Oct 26 15:41:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 29909 Received: (qmail 7176 invoked by alias); 26 Oct 2018 15:41:10 -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 7167 invoked by uid 89); 26 Oct 2018 15:41:10 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.4 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=Hx-languages-length:2312, current_ui X-HELO: gateway36.websitewelcome.com Received: from gateway36.websitewelcome.com (HELO gateway36.websitewelcome.com) (192.185.192.36) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 26 Oct 2018 15:41:07 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway36.websitewelcome.com (Postfix) with ESMTP id A6CB5400D160F for ; Fri, 26 Oct 2018 09:48:42 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id G4EUgfnPCBcCXG4EUgtn08; Fri, 26 Oct 2018 10:41:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=cpbMBdhdkd8b+ZfwwRCK7mfeiOt/s1XBFXfEPO0SSCA=; b=Wn1lAfbDDC3OpB7cGcqZUOG3sv 2MG6+/l+bPh7oHNnj4B8tk4obzjtfK1dxCdruOpDp5cUxJG3DW3uNh5ba5XM1DNxQFk8sChC5WNus btxITblLlcO0mDEFU0kbeAL2p; Received: from 97-122-190-66.hlrn.qwest.net ([97.122.190.66]:43172 helo=pokyo) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gG4EU-004BIb-7l; Fri, 26 Oct 2018 10:41:06 -0500 From: Tom Tromey To: Tom Tromey Cc: Simon Marchi , "gdb-patches\@sourceware.org" Subject: Re: [PATCH] Check return value of bfd_init References: <20181025150340.28844-1-tom@tromey.com> <87efcehwlx.fsf@tromey.com> Date: Fri, 26 Oct 2018 09:41:05 -0600 In-Reply-To: <87efcehwlx.fsf@tromey.com> (Tom Tromey's message of "Thu, 25 Oct 2018 09:30:50 -0600") Message-ID: <875zxoiulq.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1.50 (gnu/linux) MIME-Version: 1.0 >>>>> "Tom" == Tom Tromey writes: Tom> Moving the call to bfd_init below the call to "new ui" makes it work. Like so. Tom commit 2d0b2f3697a1f289e843f047697f252bf653d4db Author: Tom Tromey Date: Thu Oct 25 09:00:52 2018 -0600 Check return value of bfd_init Alan recently added a way for BFD library users to check whether they were in fact loading a compatible version of BFD: https://sourceware.org/ml/binutils/2018-10/msg00198.html It seemed reasonable to me that gdb should do this check as well, in case someone is dynamically linking against BFD. Simon pointed out that an earlier version of the patch would cause a gdb crash if the test failed. This version works around this by lowering the call to bfd_init and adding a comment explaining where 'error' can safely be called in captured_main_1. gdb/ChangeLog 2018-10-25 Tom Tromey * main.c (captured_main_1): Check return value of bfd_init. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 61dc039d4fe..a90c2978185 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2018-10-25 Tom Tromey + + * main.c (captured_main_1): Check return value of bfd_init. + 2018-10-25 Andrew Burgess * python/py-function.c (convert_values_to_python): Return diff --git a/gdb/main.c b/gdb/main.c index 8709357e924..bf6a58180a0 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -506,7 +506,6 @@ captured_main_1 (struct captured_main_args *context) textdomain (PACKAGE); #endif - bfd_init (); notice_open_fds (); saved_command_line = (char *) xstrdup (""); @@ -517,12 +516,17 @@ captured_main_1 (struct captured_main_args *context) setvbuf (stderr, NULL, _IONBF, BUFSIZ); #endif + /* Note: `error' cannot be called before this point, because the + caller will crash when trying to print the exception. */ main_ui = new ui (stdin, stdout, stderr); current_ui = main_ui; gdb_stdtargerr = gdb_stderr; /* for moment */ gdb_stdtargin = gdb_stdin; /* for moment */ + if (bfd_init () == BFD_INIT_MAGIC) + error (_("fatal error: libbfd ABI mismatch")); + #ifdef __MINGW32__ /* On Windows, argv[0] is not necessarily set to absolute form when GDB is found along PATH, without which relocation doesn't work. */