From patchwork Tue Sep 11 15:17:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 29309 Received: (qmail 54574 invoked by alias); 11 Sep 2018 15:17:22 -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 54553 invoked by uid 89); 11 Sep 2018 15:17:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-spam-relays-external:209.85.214.194, H*RU:209.85.214.194 X-HELO: mail-pl1-f194.google.com Received: from mail-pl1-f194.google.com (HELO mail-pl1-f194.google.com) (209.85.214.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Sep 2018 15:17:20 +0000 Received: by mail-pl1-f194.google.com with SMTP id t19-v6so11481399ply.13; Tue, 11 Sep 2018 08:17:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=B+NBQrzMBg3bceMlRGrGQnK9eBOhuYjRUS7HvyciGA4=; b=o7Rh/CbjKofgBGazjHoN7fX+dKcKwAXGuvN19lr1rmpzosnAPOCJA7YzlnlDC+aFiV 5Utuw3e3C8K+XKGSr1M4/yYyQ5x4vfeb4QLi7u2UC43Ulsv08e9hkjYzWzLPkEWA/Z2M wJ5EU6sGcB49kyILOBiOkYGx2UqU8HHc/63bXs6X4syX38F+FR6Nw3RQimjMgOdJLfZ3 BKXdy+4bk43Q0No3d4kjuF+aTubffD/h6BTKcln/LPnxZbSU7NhC7POEcjJtMNM4SQ6W n5smGYZHoFLn3M5WszO2o2BIAkAPqgeJJcf/iWOuzAr2AWHtQQmid4ircxp1YDb+srVs GQtQ== Return-Path: Received: from bubble.grove.modra.org ([58.175.241.133]) by smtp.gmail.com with ESMTPSA id g5-v6sm40016166pgn.73.2018.09.11.08.17.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Sep 2018 08:17:18 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id B5F1080782; Wed, 12 Sep 2018 00:47:14 +0930 (ACST) Date: Wed, 12 Sep 2018 00:47:14 +0930 From: Alan Modra To: binutils@sourceware.org Cc: gdb-patches@sourceware.org Subject: PR23425, unresolved symbol diagnostic Message-ID: <20180911151714.GH3174@bubble.grove.modra.org> References: <20180907195832.5423-1-hjl.tools@gmail.com> <20180911021757.GE3174@bubble.grove.modra.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) dwarf2.c code reasonably assumes that debug info is local to a file, an assumption now violated by gcc, resulting in "DWARF error: invalid abstract instance DIE ref" or wrong details when attempting to print linker error messages with file, function and line reported. This is because find_abstract_instance is only prepared to handle DW_FORM_ref_addr when the .debug_info section referenced is in the current file. When that isn't the case, relocations to access another file's .debug_info will typically be against a symbol defined at the start of that .debug_info section, plus an addend. Since the dwarf2.c code only considers the current file's debug info, that symbol will be undefined, resolving to zero. In effect the ref_addr will wrongly resolve to the current file's .debug_info. This patch avoids the problem by treating relocations in debug sections against undefined symbols in a similar manner to the way relocations against symbols defined in discarded sections are resolved. They result in a zero value (except in .debug_ranges) regardless of the addend. I think this should be OK for all the gdb uses of bfd_simple_get_relocated_section_contents or similar code in compile-object-load.c, but I won't commit this immediately to give gdb folk time to comment. PR 23425 * reloc.c (bfd_generic_get_relocated_section_contents): Zero reloc fields in debug sections when reloc is against an undefined symbol and called from bfd_simple_get_relocated_section_contents or similar. * dwarf2.c (find_abstract_instance): Return true for zero offset DW_FORM_ref_addr without returning values. diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c index 8fadb5c4b6..3b2885599e 100644 --- a/bfd/dwarf2.c +++ b/bfd/dwarf2.c @@ -2837,7 +2837,9 @@ find_abstract_instance (struct comp_unit * unit, info_ptr = unit->stash->info_ptr_memory; info_ptr_end = unit->stash->info_ptr_end; total = info_ptr_end - info_ptr; - if (!die_ref || die_ref >= total) + if (!die_ref) + return TRUE; + else if (die_ref >= total) { _bfd_error_handler (_("DWARF error: invalid abstract instance DIE ref")); diff --git a/bfd/reloc.c b/bfd/reloc.c index eba6091891..67457418e6 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -8259,7 +8259,18 @@ bfd_generic_get_relocated_section_contents (bfd *abfd, goto error_return; } - if (symbol->section && discarded_section (symbol->section)) + /* Zap reloc field when the symbol is from a discarded + section, ignoring any addend. Do the same when called + from bfd_simple_get_relocated_section_contents for + undefined symbols in debug sections. This is to keep + debug info reasonably sane, in particular so that + DW_FORM_ref_addr to another file's .debug_info isn't + confused with an offset into the current file's + .debug_info. */ + if ((symbol->section != NULL && discarded_section (symbol->section)) + || (symbol->section == bfd_und_section_ptr + && (input_section->flags & SEC_DEBUGGING) != 0 + && link_info->input_bfds == link_info->output_bfd)) { bfd_byte *p; static reloc_howto_type none_howto