From patchwork Sun Aug 30 23:17:55 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 142489 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 33CE54BA2E1C for ; Sun, 30 Aug 2026 23:18:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 33CE54BA2E1C Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=SS5+LIZp X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by sourceware.org (Postfix) with ESMTPS id A4CC34BA2E16 for ; Sun, 30 Aug 2026 23:18:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A4CC34BA2E16 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A4CC34BA2E16 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1030 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788131880; cv=none; b=RtxJO+AeEhZQoywu0W3+I/G7shTeIm33s40skSYCL0l+kq9vYXvr4AMgFtTP/6O5rm/BOazJfb2tHtXiCaoYmR9l/YT3PIE07vRG/Ml/U0VOAVpp3+BNkwu6HsdCTbMv1ePqpBEmlnKdQkFrAVUsuRlulkm+kVm+bgxzX67utww= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788131880; c=relaxed/simple; bh=bkkuThxbNAsEwYGkZlupeN4KeKuy5dHLuQ1SQ1MFx/E=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=oLO3FoKsO3vU241hIqafHjZ1nF4NMo/mrf0M9kAgpLA3qd+4GGhUaoeErQCigXn3GGkZOaC/PHvu5jOI0+r5Ol1/zs8oHoCPxLHUgfd3PMwylpkaJ71xeLUBr+2z6dIK6vWXxB5+mMMjoC8FHSSw4dMkeavGC459eYtFmvzp9JE= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=SS5+LIZp DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A4CC34BA2E16 Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-38dfe910e9dso3297327a91.3 for ; Sun, 30 Aug 2026 16:18:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788131880; x=1788736680; darn=sourceware.org; h=content-disposition:content-type:mime-version:message-id:subject:to :from:date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=n6OwShSpNa8Cb5ktI7n/u94qlyPEXsP4z1MHQngErv0=; b=SS5+LIZp5eHQ1h9ndFomN/jW2LB3EylbPqdmqiwAgGNjGvkFdhEA7UjpJkDuUKnpyK O+Ru5Hd9UhAnjrm2rDJM5hTKtRH/3k6xcT14yfMcQIT94ylKDe8WkKSH7AXgJMG8Eimi zLjnjrtCBhbOnhb0N87mB+oVzQQJRLV87Bf4p0TY8/k8Wt8e5Z3I32uO2wq2r5bKhJCI O1m/R9QjqAMi5vPrJrhBNE/Gg5zmbj3xVI74t54h/Er9ZuFUqclloHAlfaMJBwLLHoaW fJKktarQ6quCZwnwZcRjjEIQBs+0o3OZiDwWrHLr7Xz51ERB0DxgwtDUsiBQBH+UZzuB wOzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788131880; x=1788736680; h=content-disposition:content-type:mime-version:message-id:subject:to :from:date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=n6OwShSpNa8Cb5ktI7n/u94qlyPEXsP4z1MHQngErv0=; b=nnWNevBtmK65+QjwGfqj8xa3wkoOrdMXuFV6A9r8Cr8hHGebuIfvMX7tndTvuahXSz WbfxhHMBjtmQgqhNo0cBQMwWqI85ZvEglokoMt2pjuwrX7Rg/i2DiHLUqGEf7m6hGdDf R7EJDIpU2Fh+N8b9WPn4HP3enyobwL3jmaIo9Gk9mbcjlv3eErKdLaf47MrzdWcNzZOv iFkkjn1MCVYYC9iSNqXnko1W6KQOInEjw58VkxO0/N0KEUDXe+TP/fWQRDLg6iy1Hxju pQsa08vXbwRBF77Wwx0O4PYl/3gDrBhe0VpvDQsqrp27ZO+Qtrrfk6qQNtAsG42j9j+w BbPA== X-Gm-Message-State: AFuF++kvudplURSMV9uD81XZZNStUjr6eJ9j8U6TuDeuACRJ+zJS3bXh jGdufnZ4LmGyZCeZaVewaY7a/qTkeaeEJRvB0eyjEQFWMXdw0SSt7lbzthnNkg== X-Gm-Gg: AYBFou3oSpUPrjsBrN9sV2dtk7dVv1M37BJwSHjrS9qJINPbZR7j1nQaA3UOmNOsE9r 18yhJjAYwL/fQqkjI5xNlS6FHN5QWuTh87Ubt3zrBRyMec33HDeOrtbpkgBoehpOCoduiczlWxR A2/41NMVRmNX1B3ZytwaFhUJPSyv1ft+mrM/XLiMNVbTCQLxCFTUIt7hB3LhiAiVmbwpBzMzZwS Aj4P2amNG+33BXi9rSNY3Tt4Km8Ftt0Jh3ZN4zSJ/OFubfSiCTTivgu1iKnz0QN9GxUh5YvBddT GPG/Y/HMeS1Z0/D2uI59sRUhe5SKl6vXKn9Z0Vdr8bMLCZ7XjHhRA+24OCGt6dxbJ/JkwNvCLWI UuMhoXaDpD8hBHyM1v5dJYO6XtGDPgiVYwDXvKzeZMMnees4NaXuhKJfl9S6l1G4/ABTYOjf92f 8GqcjdEqXkirTf7RPtHk7Roqq1JDJvtaJxfDFbMQMkcgsPoPw2LR0ysZ1X1uc0/W7CDRneIkM= X-Received: by 2002:a17:90b:2e48:b0:398:9be8:ea65 with SMTP id 98e67ed59e1d1-398f2c61bbbmr613003a91.18.1788131879342; Sun, 30 Aug 2026 16:17:59 -0700 (PDT) Received: from squeak.grove.modra.org ([58.96.106.158]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-396dda7aaaasm13220681a91.6.2026.08.30.16.17.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Aug 2026 16:17:58 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id EB773114196D; Mon, 31 Aug 2026 08:47:55 +0930 (ACST) Date: Mon, 31 Aug 2026 08:47:55 +0930 From: Alan Modra To: binutils@sourceware.org Subject: remove some assumptions about dynobj Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3029.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org A number of backends assume that if dynobj is non-NULL then some dynamic sections must have been created. That isn't the case if dynobj is set without a create_dynamic_sections call, for instance, if dynobj were set to the stub bfd as ppc64 does early in linking. This patch fixes those assumptions, and tidies some code a little. * elf-m10300.c (_bfd_mn10300_elf_finish_dynamic_sections): Move assertions after dynamic_sections_created test. Test for sgot existence. * elf32-cr16.c (_bfd_cr16_elf_finish_dynamic_sections): Likewise. * elf32-cris.c (elf_cris_finish_dynamic_sections): Likewise. * elf32-m68k.c (elf_m68k_finish_dynamic_sections): Likewise. * elf32-vax.c (elf_vax_finish_dynamic_sections): Likewise. * elf32-bfin.c (elf32_bfinfdpic_late_size_sections): Check that bfinfdpic_relocs_info is non-NULL before htab_traverse on same. (elf32_bfinfdpic_finish_dynamic_sections): Delay finding sdyn until after dynamic_section_created test. (bfin_finish_dynamic_sections): Likewise. * elf32-lm32.c (lm32_elf_late_size_sections): Check that lm32fdpic_fixup32_section exists. * elf32-m32c.c (m32c_elf_finish_dynamic_sections): Don't test dynobj, test splt directly. (m32c_elf_early_size_sections): Likewise. * elf32-rl78.c (rl78_elf_finish_dynamic_sections): Likewise. (rl78_elf_early_size_sections): Likewise. * elf32-xstormy16.c (xstormy16_elf_early_size_sections): Likewise. (xstormy16_elf_finish_dynamic_sections): Likewise. * elf32-score.c (score_elf_got_info): Don't assert. Test for sgot existence. * elf32-score7.c (score_elf_got_info): Likewise. * elf64-hppa.c (elf64_hppa_late_size_sections): Don't create __text_seg or __data_seg dynamic symbols unless dynamic_sections_created. diff --git a/bfd/elf-m10300.c b/bfd/elf-m10300.c index 05f2a9811e3..332b294e1e2 100644 --- a/bfd/elf-m10300.c +++ b/bfd/elf-m10300.c @@ -5344,16 +5344,15 @@ _bfd_mn10300_elf_finish_dynamic_sections (struct bfd_link_info *info, dynobj = htab->root.dynobj; sgot = htab->root.sgotplt; - BFD_ASSERT (sgot != NULL); sdyn = bfd_get_linker_section (dynobj, ".dynamic"); - if (elf_hash_table (info)->dynamic_sections_created) + if (htab->root.dynamic_sections_created) { asection * splt; Elf32_External_Dyn * dyncon; Elf32_External_Dyn * dynconend; - BFD_ASSERT (sdyn != NULL); + BFD_ASSERT (sdyn != NULL && sgot != NULL); dyncon = (Elf32_External_Dyn *) sdyn->contents; dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); @@ -5424,7 +5423,7 @@ _bfd_mn10300_elf_finish_dynamic_sections (struct bfd_link_info *info, } /* Fill in the first three entries in the global offset table. */ - if (sgot->size > 0) + if (sgot != NULL && sgot->size > 0) { if (sdyn == NULL) bfd_put_32 (info->output_bfd, 0, sgot->contents); @@ -5434,9 +5433,9 @@ _bfd_mn10300_elf_finish_dynamic_sections (struct bfd_link_info *info, sgot->contents); bfd_put_32 (info->output_bfd, 0, sgot->contents + 4); bfd_put_32 (info->output_bfd, 0, sgot->contents + 8); - } - elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; + elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; + } return true; } diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c index 38546621864..c4d9389a04a 100644 --- a/bfd/elf32-bfin.c +++ b/bfd/elf32-bfin.c @@ -4038,7 +4038,6 @@ elf32_bfinfdpic_late_size_sections (struct bfd_link_info *info) struct elf_link_hash_table *htab; bfd *dynobj; asection *s; - struct _bfinfdpic_dynamic_got_plt_info gpinfo; htab = elf_hash_table (info); dynobj = htab->dynobj; @@ -4058,28 +4057,33 @@ elf32_bfinfdpic_late_size_sections (struct bfd_link_info *info) } } - memset (&gpinfo, 0, sizeof (gpinfo)); - gpinfo.g.info = info; - - for (;;) + if (bfinfdpic_relocs_info (info)) { - htab_t relocs = bfinfdpic_relocs_info (info); + struct _bfinfdpic_dynamic_got_plt_info gpinfo; + memset (&gpinfo, 0, sizeof (gpinfo)); + gpinfo.g.info = info; - htab_traverse (relocs, _bfinfdpic_resolve_final_relocs_info, &relocs); + for (;;) + { + htab_t relocs = bfinfdpic_relocs_info (info); - if (relocs == bfinfdpic_relocs_info (info)) - break; - } + htab_traverse (relocs, _bfinfdpic_resolve_final_relocs_info, &relocs); + + if (relocs == bfinfdpic_relocs_info (info)) + break; + } - htab_traverse (bfinfdpic_relocs_info (info), _bfinfdpic_count_got_plt_entries, - &gpinfo.g); + htab_traverse (bfinfdpic_relocs_info (info), + _bfinfdpic_count_got_plt_entries, &gpinfo.g); - /* Allocate space to save the summary information, we're going to - use it if we're doing relaxations. */ - bfinfdpic_dynamic_got_plt_info (info) = bfd_alloc (dynobj, sizeof (gpinfo.g)); + /* Allocate space to save the summary information, we're going to + use it if we're doing relaxations. */ + bfinfdpic_dynamic_got_plt_info (info) = bfd_alloc (dynobj, + sizeof (gpinfo.g)); - if (!_bfinfdpic_size_got_plt (info->output_bfd, &gpinfo)) - return false; + if (!_bfinfdpic_size_got_plt (info->output_bfd, &gpinfo)) + return false; + } s = bfd_get_linker_section (dynobj, ".dynbss"); if (s && s->size == 0) @@ -4218,11 +4222,6 @@ static bool elf32_bfinfdpic_finish_dynamic_sections (struct bfd_link_info *info, bfd_byte *buf ATTRIBUTE_UNUSED) { - bfd *dynobj; - asection *sdyn; - - dynobj = elf_hash_table (info)->dynobj; - if (bfinfdpic_got_section (info)) { BFD_ASSERT (bfinfdpic_gotrel_section (info)->size @@ -4262,12 +4261,11 @@ elf32_bfinfdpic_finish_dynamic_sections (struct bfd_link_info *info, * sizeof (Elf32_External_Rel))); } - sdyn = bfd_get_linker_section (dynobj, ".dynamic"); - if (elf_hash_table (info)->dynamic_sections_created) { - Elf32_External_Dyn * dyncon; - Elf32_External_Dyn * dynconend; + bfd *dynobj = elf_hash_table (info)->dynobj; + asection *sdyn = bfd_get_linker_section (dynobj, ".dynamic"); + Elf32_External_Dyn *dyncon, *dynconend; BFD_ASSERT (sdyn != NULL); @@ -4866,15 +4864,10 @@ static bool bfin_finish_dynamic_sections (struct bfd_link_info *info, bfd_byte *buf ATTRIBUTE_UNUSED) { - bfd *dynobj; - asection *sdyn; - - dynobj = elf_hash_table (info)->dynobj; - - sdyn = bfd_get_linker_section (dynobj, ".dynamic"); - if (elf_hash_table (info)->dynamic_sections_created) { + bfd *dynobj = elf_hash_table (info)->dynobj; + asection *sdyn = bfd_get_linker_section (dynobj, ".dynamic"); Elf32_External_Dyn *dyncon, *dynconend; BFD_ASSERT (sdyn != NULL); diff --git a/bfd/elf32-cr16.c b/bfd/elf32-cr16.c index 8e827afe3a3..1a8a3b28180 100644 --- a/bfd/elf32-cr16.c +++ b/bfd/elf32-cr16.c @@ -2589,9 +2589,7 @@ _bfd_cr16_elf_finish_dynamic_sections (struct bfd_link_info *info, asection * sdyn; dynobj = elf_hash_table (info)->dynobj; - sgot = elf_hash_table (info)->sgotplt; - BFD_ASSERT (sgot != NULL); sdyn = bfd_get_linker_section (dynobj, ".dynamic"); if (elf_hash_table (info)->dynamic_sections_created) @@ -2599,7 +2597,7 @@ _bfd_cr16_elf_finish_dynamic_sections (struct bfd_link_info *info, Elf32_External_Dyn * dyncon; Elf32_External_Dyn * dynconend; - BFD_ASSERT (sdyn != NULL); + BFD_ASSERT (sdyn != NULL && sgot != NULL); dyncon = (Elf32_External_Dyn *) sdyn->contents; dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); @@ -2638,7 +2636,7 @@ _bfd_cr16_elf_finish_dynamic_sections (struct bfd_link_info *info, } /* Fill in the first three entries in the global offset table. */ - if (sgot->size > 0) + if (sgot != NULL && sgot->size > 0) { if (sdyn == NULL) bfd_put_32 (info->output_bfd, 0, sgot->contents); @@ -2646,9 +2644,9 @@ _bfd_cr16_elf_finish_dynamic_sections (struct bfd_link_info *info, bfd_put_32 (info->output_bfd, sdyn->output_section->vma + sdyn->output_offset, sgot->contents); - } - elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; + elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; + } return true; } diff --git a/bfd/elf32-cris.c b/bfd/elf32-cris.c index 1df98bd55aa..938f3bc7bbb 100644 --- a/bfd/elf32-cris.c +++ b/bfd/elf32-cris.c @@ -2317,9 +2317,7 @@ elf_cris_finish_dynamic_sections (struct bfd_link_info *info, asection *sdyn; dynobj = elf_hash_table (info)->dynobj; - sgot = elf_hash_table (info)->sgotplt; - BFD_ASSERT (sgot != NULL); sdyn = bfd_get_linker_section (dynobj, ".dynamic"); if (elf_hash_table (info)->dynamic_sections_created) @@ -2328,7 +2326,7 @@ elf_cris_finish_dynamic_sections (struct bfd_link_info *info, Elf32_External_Dyn *dyncon, *dynconend; splt = elf_hash_table (info)->splt; - BFD_ASSERT (splt != NULL && sdyn != NULL); + BFD_ASSERT (splt != NULL && sdyn != NULL && sgot != NULL); dyncon = (Elf32_External_Dyn *) sdyn->contents; dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); @@ -2416,7 +2414,7 @@ elf_cris_finish_dynamic_sections (struct bfd_link_info *info, } /* Fill in the first three entries in the global offset table. */ - if (sgot->size > 0) + if (sgot != NULL && sgot->size > 0) { if (sdyn == NULL) bfd_put_32 (info->output_bfd, 0, sgot->contents); @@ -2426,9 +2424,9 @@ elf_cris_finish_dynamic_sections (struct bfd_link_info *info, sgot->contents); bfd_put_32 (info->output_bfd, 0, sgot->contents + 4); bfd_put_32 (info->output_bfd, 0, sgot->contents + 8); - } - elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; + elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; + } return true; } diff --git a/bfd/elf32-lm32.c b/bfd/elf32-lm32.c index 72a021b7d12..b9768952e19 100644 --- a/bfd/elf32-lm32.c +++ b/bfd/elf32-lm32.c @@ -2084,7 +2084,8 @@ lm32_elf_late_size_sections (struct bfd_link_info *info) return false; /* Allocate .rofixup section. */ - if (IS_FDPIC (info->output_bfd)) + if (IS_FDPIC (info->output_bfd) + && lm32fdpic_fixup32_section (info) != NULL) { struct weak_symbol_list *list_start = NULL, *list_end = NULL; int rgot_weak_count = 0; diff --git a/bfd/elf32-m32c.c b/bfd/elf32-m32c.c index 7fcf8216a3f..fbe9eb2978a 100644 --- a/bfd/elf32-m32c.c +++ b/bfd/elf32-m32c.c @@ -762,7 +762,7 @@ m32c_elf_finish_dynamic_sections (struct bfd_link_info *info, /* As an extra sanity check, verify that all plt entries have been filled in. */ - if (dynobj != NULL && splt != NULL) + if (splt != NULL) { bfd_byte *contents = splt->contents; unsigned int i, size = splt->size; @@ -779,24 +779,20 @@ m32c_elf_finish_dynamic_sections (struct bfd_link_info *info, static bool m32c_elf_early_size_sections (struct bfd_link_info *info) { - bfd *dynobj; asection *splt; if (bfd_link_relocatable (info)) return true; - dynobj = elf_hash_table (info)->dynobj; - if (dynobj == NULL) - return true; - splt = elf_hash_table (info)->splt; - BFD_ASSERT (splt != NULL); - - splt->contents = (bfd_byte *) bfd_zalloc (dynobj, splt->size); - if (splt->contents == NULL) - return false; - splt->alloced = 1; - + if (splt != NULL) + { + bfd *dynobj = elf_hash_table (info)->dynobj; + splt->contents = bfd_zalloc (dynobj, splt->size); + if (splt->contents == NULL) + return false; + splt->alloced = 1; + } return true; } diff --git a/bfd/elf32-m68k.c b/bfd/elf32-m68k.c index b50a7706a85..1bc72c7ae42 100644 --- a/bfd/elf32-m68k.c +++ b/bfd/elf32-m68k.c @@ -4278,9 +4278,7 @@ elf_m68k_finish_dynamic_sections (struct bfd_link_info *info, asection *sdyn; dynobj = elf_hash_table (info)->dynobj; - sgot = elf_hash_table (info)->sgotplt; - BFD_ASSERT (sgot != NULL); sdyn = bfd_get_linker_section (dynobj, ".dynamic"); if (elf_hash_table (info)->dynamic_sections_created) @@ -4289,7 +4287,7 @@ elf_m68k_finish_dynamic_sections (struct bfd_link_info *info, Elf32_External_Dyn *dyncon, *dynconend; splt = elf_hash_table (info)->splt; - BFD_ASSERT (splt != NULL && sdyn != NULL); + BFD_ASSERT (splt != NULL && sdyn != NULL && sgot != NULL); dyncon = (Elf32_External_Dyn *) sdyn->contents; dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); @@ -4347,7 +4345,7 @@ elf_m68k_finish_dynamic_sections (struct bfd_link_info *info, } /* Fill in the first three entries in the global offset table. */ - if (sgot->size > 0) + if (sgot != NULL && sgot->size > 0) { if (sdyn == NULL) bfd_put_32 (info->output_bfd, 0, sgot->contents); @@ -4357,9 +4355,9 @@ elf_m68k_finish_dynamic_sections (struct bfd_link_info *info, sgot->contents); bfd_put_32 (info->output_bfd, 0, sgot->contents + 4); bfd_put_32 (info->output_bfd, 0, sgot->contents + 8); - } - elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; + elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; + } return true; } diff --git a/bfd/elf32-rl78.c b/bfd/elf32-rl78.c index 9a3e2f22707..8ce087ef28b 100644 --- a/bfd/elf32-rl78.c +++ b/bfd/elf32-rl78.c @@ -1444,7 +1444,7 @@ rl78_elf_finish_dynamic_sections (struct bfd_link_info *info, dynobj = elf_hash_table (info)->dynobj; splt = elf_hash_table (info)->splt; - if (dynobj != NULL && splt != NULL) + if (splt != NULL) { bfd_byte *contents = splt->contents; unsigned int i, size = splt->size; @@ -1462,24 +1462,20 @@ rl78_elf_finish_dynamic_sections (struct bfd_link_info *info, static bool rl78_elf_early_size_sections (struct bfd_link_info *info) { - bfd *dynobj; asection *splt; if (bfd_link_relocatable (info)) return true; - dynobj = elf_hash_table (info)->dynobj; - if (dynobj == NULL) - return true; - splt = elf_hash_table (info)->splt; - BFD_ASSERT (splt != NULL); - - splt->contents = (bfd_byte *) bfd_zalloc (dynobj, splt->size); - if (splt->contents == NULL) - return false; - splt->alloced = 1; - + if (splt != NULL) + { + bfd *dynobj = elf_hash_table (info)->dynobj; + splt->contents = bfd_zalloc (dynobj, splt->size); + if (splt->contents == NULL) + return false; + splt->alloced = 1; + } return true; } diff --git a/bfd/elf32-score.c b/bfd/elf32-score.c index dca6333e710..227e7ca245c 100644 --- a/bfd/elf32-score.c +++ b/bfd/elf32-score.c @@ -1100,13 +1100,13 @@ score_elf_got_info (bfd *abfd, asection **sgotp) struct score_got_info *g; sgot = score_elf_got_section (abfd, true); - BFD_ASSERT (sgot != NULL); - BFD_ASSERT (elf_section_data (sgot) != NULL); - g = score_elf_section_data (sgot)->u.got_info; - BFD_ASSERT (g != NULL); - if (sgotp) *sgotp = sgot; + + g = NULL; + if (sgot != NULL) + g = score_elf_section_data (sgot)->u.got_info; + return g; } @@ -3206,7 +3206,6 @@ s3_bfd_score_elf_early_size_sections (struct bfd_link_info *info) dynobj = elf_hash_table (info)->dynobj; if (dynobj == NULL) - /* Relocatable links don't have it. */ return true; g = score_elf_got_info (dynobj, &s); diff --git a/bfd/elf32-score7.c b/bfd/elf32-score7.c index 16378cddc30..6b8f0ae2ea6 100644 --- a/bfd/elf32-score7.c +++ b/bfd/elf32-score7.c @@ -984,13 +984,13 @@ score_elf_got_info (bfd *abfd, asection **sgotp) struct score_got_info *g; sgot = score_elf_got_section (abfd, true); - BFD_ASSERT (sgot != NULL); - BFD_ASSERT (elf_section_data (sgot) != NULL); - g = score_elf_section_data (sgot)->u.got_info; - BFD_ASSERT (g != NULL); - if (sgotp) *sgotp = sgot; + + g = NULL; + if (sgot != NULL) + g = score_elf_section_data (sgot)->u.got_info; + return g; } @@ -3010,7 +3010,6 @@ s7_bfd_score_elf_early_size_sections (struct bfd_link_info *info) dynobj = elf_hash_table (info)->dynobj; if (dynobj == NULL) - /* Relocatable links don't have it. */ return true; g = score_elf_got_info (dynobj, &s); diff --git a/bfd/elf32-vax.c b/bfd/elf32-vax.c index 8e5a5275428..3a302ddce9a 100644 --- a/bfd/elf32-vax.c +++ b/bfd/elf32-vax.c @@ -1729,9 +1729,7 @@ elf_vax_finish_dynamic_sections (struct bfd_link_info *info, asection *sdyn; dynobj = elf_hash_table (info)->dynobj; - sgot = elf_hash_table (info)->sgotplt; - BFD_ASSERT (sgot != NULL); sdyn = bfd_get_linker_section (dynobj, ".dynamic"); if (elf_hash_table (info)->dynamic_sections_created) @@ -1740,7 +1738,7 @@ elf_vax_finish_dynamic_sections (struct bfd_link_info *info, Elf32_External_Dyn *dyncon, *dynconend; splt = elf_hash_table (info)->splt; - BFD_ASSERT (splt != NULL && sdyn != NULL); + BFD_ASSERT (splt != NULL && sdyn != NULL && sgot != NULL); dyncon = (Elf32_External_Dyn *) sdyn->contents; dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); @@ -1794,7 +1792,7 @@ elf_vax_finish_dynamic_sections (struct bfd_link_info *info, } /* Fill in the first three entries in the global offset table. */ - if (sgot->size > 0) + if (sgot != NULL && sgot->size > 0) { if (sdyn == NULL) bfd_put_32 (info->output_bfd, 0, sgot->contents); @@ -1804,10 +1802,10 @@ elf_vax_finish_dynamic_sections (struct bfd_link_info *info, sgot->contents); bfd_put_32 (info->output_bfd, 0, sgot->contents + 4); bfd_put_32 (info->output_bfd, 0, sgot->contents + 8); - } - if (elf_section_data (sgot->output_section) != NULL) - elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; + if (elf_section_data (sgot->output_section) != NULL) + elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; + } return true; } diff --git a/bfd/elf32-xstormy16.c b/bfd/elf32-xstormy16.c index 07270b8b66f..e7b05058f9d 100644 --- a/bfd/elf32-xstormy16.c +++ b/bfd/elf32-xstormy16.c @@ -713,24 +713,20 @@ xstormy16_elf_relax_section (bfd *dynobj, static bool xstormy16_elf_early_size_sections (struct bfd_link_info *info) { - bfd *dynobj; asection *splt; if (bfd_link_relocatable (info)) return true; - dynobj = elf_hash_table (info)->dynobj; - if (dynobj == NULL) - return true; - splt = elf_hash_table (info)->splt; - BFD_ASSERT (splt != NULL); - - splt->contents = bfd_zalloc (dynobj, splt->size); - if (splt->contents == NULL) - return false; - splt->alloced = 1; - + if (splt != NULL) + { + bfd *dynobj = elf_hash_table (info)->dynobj; + splt->contents = bfd_zalloc (dynobj, splt->size); + if (splt->contents == NULL) + return false; + splt->alloced = 1; + } return true; } @@ -970,7 +966,7 @@ xstormy16_elf_finish_dynamic_sections (struct bfd_link_info *info, /* As an extra sanity check, verify that all plt entries have been filled in. */ - if (dynobj != NULL && splt != NULL) + if (splt != NULL) { bfd_byte *contents = splt->contents; unsigned int i, size = splt->size; diff --git a/bfd/elf64-hppa.c b/bfd/elf64-hppa.c index 0a14e2f1adc..e57a56f242b 100644 --- a/bfd/elf64-hppa.c +++ b/bfd/elf64-hppa.c @@ -1804,7 +1804,7 @@ elf64_hppa_late_size_sections (struct bfd_link_info *info) } /* Add __text_seg section symbol to dynamic table. */ - if (!hppa_info->text_hash_entry) + if (hppa_info->root.dynamic_sections_created && !hppa_info->text_hash_entry) { asection *s; @@ -1833,7 +1833,7 @@ elf64_hppa_late_size_sections (struct bfd_link_info *info) } /* Add __data_seg section symbol to dynamic table. */ - if (!hppa_info->data_hash_entry) + if (hppa_info->root.dynamic_sections_created && !hppa_info->data_hash_entry) { asection *s;