From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 97345 invoked by alias); 21 Apr 2016 03:32:01 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 97248 invoked by uid 89); 21 Apr 2016 03:31:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.0 required=5.0 tests=BAYES_20,KAM_LAZY_DOMAIN_SECURITY,NO_DNS_FOR_FROM,RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=ibfd, elf_hash_table, *ibfd, DYNAMIC X-HELO: mga02.intel.com Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 21 Apr 2016 03:31:53 +0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP; 20 Apr 2016 20:31:51 -0700 X-ExtLoop1: 1 Received: from gnu-6.sc.intel.com ([172.25.70.218]) by fmsmga002.fm.intel.com with ESMTP; 20 Apr 2016 20:31:50 -0700 Received: by gnu-6.sc.intel.com (Postfix, from userid 1000) id E2B7F200116; Wed, 20 Apr 2016 20:31:50 -0700 (PDT) Date: Thu, 21 Apr 2016 03:32:00 -0000 From: "H.J. Lu" To: binutils@sourceware.org Subject: [PATCH] Set dynobj to a normal input file if possible Message-ID: <20160421033150.GA24027@intel.com> Reply-To: "H.J. Lu" MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-SW-Source: 2016-04/txt/msg00353.txt.bz2 When check_relocs is called after gc-sections has run, _bfd_elf_link_create_dynstrtab may be called with an dynamic object and hash_table->dynobj may be NULL. We may not set dynobj, an input file holding linker created dynamic sections to the dynamic object, which has its own dynamic sections. We need to find a normal input file to hold linker created sections if possible. Otherwise ld will crash during LTO input rescan when linker created dynamic section overrides input dynamic section. Tested on x86-64. OK for master? H.J. * elflink.c (_bfd_elf_link_create_dynstrtab): Set dynobj to a normal input file if possible. --- bfd/elflink.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/bfd/elflink.c b/bfd/elflink.c index b432384..13233cb 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -204,7 +204,23 @@ _bfd_elf_link_create_dynstrtab (bfd *abfd, struct bfd_link_info *info) hash_table = elf_hash_table (info); if (hash_table->dynobj == NULL) - hash_table->dynobj = abfd; + { + /* We may not set dynobj, an input file holding linker created + dynamic sections to abfd, which may be a dynamic object with + its own dynamic sections. We need to find a normal input file + to hold linker created sections if possible. */ + if ((abfd->flags & (DYNAMIC | BFD_PLUGIN)) != 0) + { + bfd *ibfd; + for (ibfd = info->input_bfds; ibfd; ibfd = ibfd->link.next) + if ((ibfd->flags & (DYNAMIC | BFD_PLUGIN)) == 0) + { + abfd = ibfd; + break; + } + } + hash_table->dynobj = abfd; + } if (hash_table->dynstr == NULL) { -- 2.5.5