From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 68712 invoked by alias); 21 Feb 2017 22:58:12 -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 68702 invoked by uid 89); 21 Feb 2017 22:58:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.0 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,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-pg0-f67.google.com Received: from mail-pg0-f67.google.com (HELO mail-pg0-f67.google.com) (74.125.83.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 21 Feb 2017 22:58:01 +0000 Received: by mail-pg0-f67.google.com with SMTP id s67so9821619pgb.1 for ; Tue, 21 Feb 2017 14:58:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=odEKevcEW/XMHFaU9PSGRLQvXvjYZs9MVH0s5hNUBSg=; b=OEPM8dYbXMW2B0L6UQzAva1CDavV/x0HeuOhQ8QM9cqOEGfvQqlAmyGZLMtuTcQilh 8Uhj/NW/o11k/UTAGGByr6RjECiBWy0j/923dYFX9iMMONAgMZR85Br2R+9HyG78q+lq gmo1wlc0gjRudguDrQDeuzkUODsN5p/EmK8AGadcu10rqKzIwGK4BVpmlLEYTNYA13gg ZsP3hFdXpr5aHDykecnthGpiWOK6j1q49LghnpYdJPfsOEJjxh+1yZR2lMmGoaik0ORk 5pM9xsUf57JpnujS414g2UV7hGDEX1VY28wR3v2pLbNMvOsj3cDT3/8iSU088so8X9vZ 6qrg== X-Gm-Message-State: AMke39kAFGw1zPUgcU9gz+sqisHzlciwyDtf1bhKsWOO8lk0NOdcV8ZgXlrcNf7EsYIg9A== X-Received: by 10.98.72.88 with SMTP id v85mr35960798pfa.54.1487717880124; Tue, 21 Feb 2017 14:58:00 -0800 (PST) Received: from bubble.grove.modra.org (CPE-58-160-71-80.tyqh2.lon.bigpond.net.au. [58.160.71.80]) by smtp.gmail.com with ESMTPSA id l69sm11788472pfc.76.2017.02.21.14.57.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Feb 2017 14:57:59 -0800 (PST) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 1147DC3166; Wed, 22 Feb 2017 09:27:56 +1030 (ACDT) Date: Tue, 21 Feb 2017 22:58:00 -0000 From: Alan Modra To: binutils@sourceware.org Subject: PowerPC ld segfault on script discarding dynamic sections Message-ID: <20170221225755.GD14945@bubble.grove.modra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes X-SW-Source: 2017-02/txt/msg00223.txt.bz2 Found when running the gold testsuite on an Ubuntu system where gcc defaults to -pie, on attempting to link gold/memory_test. bfd/ * elf64-ppc.c (ppc64_elf_finish_dynamic_sections): Don't segfault on .got or .plt output section being discarded by script. * elf32-ppc.c (ppc_elf_finish_dynamic_sections): Likewise. Move vxworks splt temp. gold/ * powerpc.cc (Target_powerpc::make_iplt_section): Check that output_section exists before attempting add_output_section_data. (Target_powerpc::make_brlt_section): Likewise. diff --git a/bfd/ChangeLog b/bfd/ChangeLog index ac3f160..cf5c41b 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,10 @@ +2017-02-22 Alan Modra + + * elf64-ppc.c (ppc64_elf_finish_dynamic_sections): Don't segfault + on .got or .plt output section being discarded by script. + * elf32-ppc.c (ppc_elf_finish_dynamic_sections): Likewise. Move + vxworks splt temp. + 2017-02-21 Alan Modra * elf64-alpha.c (elf64_alpha_size_dynamic_sections): Only emit diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c index 30998b1..d821935 100644 --- a/bfd/elf32-ppc.c +++ b/bfd/elf32-ppc.c @@ -10418,7 +10418,6 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) { asection *sdyn; - asection *splt; struct ppc_elf_link_hash_table *htab; bfd_vma got; bfd *dynobj; @@ -10431,10 +10430,6 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd, htab = ppc_elf_hash_table (info); dynobj = htab->elf.dynobj; sdyn = bfd_get_linker_section (dynobj, ".dynamic"); - if (htab->is_vxworks) - splt = htab->elf.splt; - else - splt = NULL; got = 0; if (htab->elf.hgot != NULL) @@ -10489,7 +10484,8 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd, } } - if (htab->elf.sgot != NULL) + if (htab->elf.sgot != NULL + && htab->elf.sgot->output_section != bfd_abs_section_ptr) { if (htab->elf.hgot->root.u.def.section == htab->elf.sgot || htab->elf.hgot->root.u.def.section == htab->elf.sgotplt) @@ -10531,8 +10527,12 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd, } /* Fill in the first entry in the VxWorks procedure linkage table. */ - if (splt && splt->size > 0) + if (htab->is_vxworks + && htab->elf.splt != NULL + && htab->elf.splt->size != 0 + && htab->elf.splt->output_section != bfd_abs_section_ptr) { + asection *splt = htab->elf.splt; /* Use the right PLT. */ const bfd_vma *plt_entry = (bfd_link_pic (info) ? ppc_elf_vxworks_pic_plt0_entry diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c index 56b94f9..4d90e0a 100644 --- a/bfd/elf64-ppc.c +++ b/bfd/elf64-ppc.c @@ -15603,7 +15603,8 @@ ppc64_elf_finish_dynamic_sections (bfd *output_bfd, } } - if (htab->elf.sgot != NULL && htab->elf.sgot->size != 0) + if (htab->elf.sgot != NULL && htab->elf.sgot->size != 0 + && htab->elf.sgot->output_section != bfd_abs_section_ptr) { /* Fill in the first entry in the global offset table. We use it to hold the link-time TOCbase. */ @@ -15615,7 +15616,8 @@ ppc64_elf_finish_dynamic_sections (bfd *output_bfd, elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize = 8; } - if (htab->elf.splt != NULL && htab->elf.splt->size != 0) + if (htab->elf.splt != NULL && htab->elf.splt->size != 0 + && htab->elf.splt->output_section != bfd_abs_section_ptr) { /* Set .plt entry size. */ elf_section_data (htab->elf.splt->output_section)->this_hdr.sh_entsize diff --git a/gold/ChangeLog b/gold/ChangeLog index 3f41834..4e1fb95 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,9 @@ +2017-02-22 Alan Modra + + * powerpc.cc (Target_powerpc::make_iplt_section): Check that + output_section exists before attempting add_output_section_data. + (Target_powerpc::make_brlt_section): Likewise. + 2017-02-15 Vladimir Radosavljevic * mips.cc (Target_mips::Scan::get_reference_flags): Remove diff --git a/gold/powerpc.cc b/gold/powerpc.cc index 4abfcec..1477a10 100644 --- a/gold/powerpc.cc +++ b/gold/powerpc.cc @@ -3608,11 +3608,13 @@ Target_powerpc::make_iplt_section(Symbol_table* symtab, this->make_plt_section(symtab, layout); Reloc_section* iplt_rel = new Reloc_section(false); - this->rela_dyn_->output_section()->add_output_section_data(iplt_rel); + if (this->rela_dyn_->output_section()) + this->rela_dyn_->output_section()->add_output_section_data(iplt_rel); this->iplt_ = new Output_data_plt_powerpc(this, iplt_rel, "** IPLT"); - this->plt_->output_section()->add_output_section_data(this->iplt_); + if (this->plt_->output_section()) + this->plt_->output_section()->add_output_section_data(this->iplt_); } } @@ -3708,14 +3710,16 @@ Target_powerpc::make_brlt_section(Layout* layout) { // When PIC we can't fill in .branch_lt (like .plt it can be // a bss style section) but must initialise at runtime via - // dynamic relocats. + // dynamic relocations. this->rela_dyn_section(layout); brlt_rel = new Reloc_section(false); - this->rela_dyn_->output_section()->add_output_section_data(brlt_rel); + if (this->rela_dyn_->output_section()) + this->rela_dyn_->output_section() + ->add_output_section_data(brlt_rel); } this->brlt_section_ = new Output_data_brlt_powerpc(this, brlt_rel); - if (this->plt_ && is_pic) + if (this->plt_ && is_pic && this->plt_->output_section()) this->plt_->output_section() ->add_output_section_data(this->brlt_section_); else -- Alan Modra Australia Development Lab, IBM