From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 45DDD3858C74 for ; Tue, 20 Sep 2022 23:37:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 45DDD3858C74 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-x42d.google.com with SMTP id c198so4174907pfc.13 for ; Tue, 20 Sep 2022 16:37:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date; bh=Mqr3W+oPLpS81ueJr6p48wXQiOoesL197NiXJK5xGvA=; b=BT2KLZ88leQmiHD9CuEsk8uctG3TJLrPFAoDT1OQP+DFxYzdjJUGDeL7VK3ZUoQYMa e9Mf0TfQ5o/WHuJU3QsihanyVSdXBN/PF7WtHYvbS+Uqyt1UqaaNV8mj84SF4IqjarEX OJGzZVrqKglUamKnMEWHR9xb9hvVYEHogR4rA3D12LmIpO32nbddQ7fFfMgj5OhvVo/5 yAoowCs7nLB+QhVOlxOTioHhFmJrY8HgjPdCM8YbdWlbKelXWeUgKQY+rPVZqjldmjP+ ddu/iuH5231Dd6kO0Na1FHahyqtN+L8Vcghf1EiVvbLvoQrkFchMfaYFVdPyNETaXVN/ u2UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date; bh=Mqr3W+oPLpS81ueJr6p48wXQiOoesL197NiXJK5xGvA=; b=k/A9J9NOxWEiao83qcSW0t4Q3lhiRG6DwBn6odDB51W3VLdOpDa6OraUuFYVLJzOQ3 KYdoG5d7lP03KcAdsd68FMZPXgaSmn8OC+xjesndy8kIGQ4hpKHdWXfh0oAVRbuj3TK0 xRgf/dRZ2qL35J2oasIJQOAdOXa10APuYQEol95wXRjENl/3Sugb9/3fbt8ctkZ9PgPX OmKqyf47n4XXzwEAZ5TffFXYDGuWviuzv1Tp25LRn2JQXQmMiCWzGRPMR8sRXGpj89uh b7OD2W+wh+6BsE3IfynW0zm5S+CLdNJU3iJNoYMGXdwnOMkSQNwh7RzS/mtMAD2Q6/Ha Ry9w== X-Gm-Message-State: ACrzQf3iR3YiI9/CVk2r6uLeWU0Tue6bFzf/cXM4mX/dT5nGk4NMoV0K QcFbtmn/ouyalnauMUo7dNeROO1ZYrw= X-Google-Smtp-Source: AMsMyM7DCdrGs6CkVShoP5UyeHzPXMESNbi0JGqHf1ZYDq+lzAKEfarPPKIDGcgW9fzhuWVz3HX/CA== X-Received: by 2002:a63:ff59:0:b0:439:db5:5da9 with SMTP id s25-20020a63ff59000000b004390db55da9mr21836061pgk.88.1663717067051; Tue, 20 Sep 2022 16:37:47 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:3f0c:11f4:6dfb:f9d9]) by smtp.gmail.com with ESMTPSA id b67-20020a621b46000000b0053e22c7f135sm483873pfb.141.2022.09.20.16.37.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 16:37:46 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id C06591140ABA; Wed, 21 Sep 2022 09:07:43 +0930 (ACST) Date: Wed, 21 Sep 2022 09:07:43 +0930 From: Alan Modra To: binutils@sourceware.org Subject: looping in alpha_vms_slurp_relocs Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3035.8 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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: The direct cause for the looping was failing to test for error return from _bfd_vms_get_object_record inside a while(1) loop. Fix that. Also record status of first alpha_vms_slurp_relocs call and return that for all subsequent calls. (The object format has one set of relocation records for all sections.) If the first call fails, all others should too. * vms-alpha.c (struct vms_private_data_struct): Make reloc_done a tri-state int. (alpha_vms_slurp_relocs): Set reloc_done to 1 on success, -1 on failure. Return that status on subsequent calls. Check _bfd_vms_get_object_record return status. (alpha_vms_get_reloc_upper_bound): Return status from alpha_vms_slurp_relocs. (alpha_vms_write_exec): Exclude sections with contents NULL due to previous errors from layout, and don't try to write them. diff --git a/bfd/vms-alpha.c b/bfd/vms-alpha.c index 9db476363ee..9531953bb6d 100644 --- a/bfd/vms-alpha.c +++ b/bfd/vms-alpha.c @@ -266,8 +266,9 @@ struct module struct vms_private_data_struct { - /* If true, relocs have been read. */ - bool reloc_done; + /* If 1, relocs have been read successfully, if 0 they have yet to be + read, if -1 reading relocs failed. */ + int reloc_done; /* Record input buffer. */ struct vms_rec_rd recrd; @@ -3380,7 +3381,8 @@ alpha_vms_write_exec (bfd *abfd) /* Place sections. */ for (sec = abfd->sections; sec; sec = sec->next) { - if (!(sec->flags & SEC_HAS_CONTENTS)) + if (!(sec->flags & SEC_HAS_CONTENTS) + || sec->contents == NULL) continue; eisd = vms_section_data (sec)->eisd; @@ -3460,7 +3462,8 @@ alpha_vms_write_exec (bfd *abfd) unsigned char blk[VMS_BLOCK_SIZE]; bfd_size_type len; - if (sec->size == 0 || !(sec->flags & SEC_HAS_CONTENTS)) + if (sec->size == 0 || !(sec->flags & SEC_HAS_CONTENTS) + || sec->contents == NULL) continue; if (bfd_bwrite (sec->contents, sec->size, abfd) != sec->size) return false; @@ -5122,15 +5125,14 @@ alpha_vms_slurp_relocs (bfd *abfd) vms_debug2 ((3, "alpha_vms_slurp_relocs\n")); /* We slurp relocs only once, for all sections. */ - if (PRIV (reloc_done)) - return true; - PRIV (reloc_done) = true; + if (PRIV (reloc_done) != 0) + return PRIV (reloc_done) == 1; if (alpha_vms_canonicalize_symtab (abfd, NULL) < 0) - return false; + goto fail; if (bfd_seek (abfd, 0, SEEK_SET) != 0) - return false; + goto fail; while (1) { @@ -5151,6 +5153,8 @@ alpha_vms_slurp_relocs (bfd *abfd) /* Skip non-ETIR records. */ type = _bfd_vms_get_object_record (abfd); + if (type < 0) + goto fail; if (type == EOBJ__C_EEOM) break; if (type != EOBJ__C_ETIR) @@ -5192,7 +5196,7 @@ alpha_vms_slurp_relocs (bfd *abfd) /* xgettext:c-format */ (_("unknown reloc %s + %s"), _bfd_vms_etir_name (prev_cmd), _bfd_vms_etir_name (cmd)); - return false; + goto fail; } cur_psect = cur_psidx; vaddr = cur_addend; @@ -5210,7 +5214,7 @@ alpha_vms_slurp_relocs (bfd *abfd) /* xgettext:c-format */ (_("unknown reloc %s + %s"), _bfd_vms_etir_name (cmd), _bfd_vms_etir_name (ETIR__C_STA_LW)); - return false; + goto fail; } } cur_addend = bfd_getl32 (ptr + 4); @@ -5225,7 +5229,7 @@ alpha_vms_slurp_relocs (bfd *abfd) /* xgettext:c-format */ (_("unknown reloc %s + %s"), _bfd_vms_etir_name (cmd), _bfd_vms_etir_name (ETIR__C_STA_QW)); - return false; + goto fail; } cur_addend = bfd_getl64 (ptr + 4); prev_cmd = cmd; @@ -5242,7 +5246,7 @@ alpha_vms_slurp_relocs (bfd *abfd) _bfd_error_handler (_("unknown reloc %s + %s"), _bfd_vms_etir_name (prev_cmd), _bfd_vms_etir_name (ETIR__C_STO_LW)); - return false; + goto fail; } reloc_code = BFD_RELOC_32; break; @@ -5255,7 +5259,7 @@ alpha_vms_slurp_relocs (bfd *abfd) _bfd_error_handler (_("unknown reloc %s + %s"), _bfd_vms_etir_name (prev_cmd), _bfd_vms_etir_name (ETIR__C_STO_QW)); - return false; + goto fail; } reloc_code = BFD_RELOC_64; break; @@ -5267,7 +5271,7 @@ alpha_vms_slurp_relocs (bfd *abfd) _bfd_error_handler (_("unknown reloc %s + %s"), _bfd_vms_etir_name (prev_cmd), _bfd_vms_etir_name (ETIR__C_STO_OFF)); - return false; + goto fail; } reloc_code = BFD_RELOC_64; break; @@ -5280,7 +5284,7 @@ alpha_vms_slurp_relocs (bfd *abfd) _bfd_error_handler (_("unknown reloc %s + %s"), _bfd_vms_etir_name (prev_cmd), _bfd_vms_etir_name (ETIR__C_OPR_ADD)); - return false; + goto fail; } prev_cmd = ETIR__C_OPR_ADD; continue; @@ -5334,7 +5338,7 @@ alpha_vms_slurp_relocs (bfd *abfd) default: _bfd_error_handler (_("unknown reloc %s"), _bfd_vms_etir_name (cmd)); - return false; + goto fail; } { @@ -5347,16 +5351,16 @@ alpha_vms_slurp_relocs (bfd *abfd) if (cur_psect < 0 || cur_psect > (int)PRIV (section_count)) { _bfd_error_handler (_("invalid section index in ETIR")); - return false; + goto fail; } if (PRIV (sections) == NULL) - return false; + goto fail; sec = PRIV (sections)[cur_psect]; if (sec == bfd_abs_section_ptr) { _bfd_error_handler (_("relocation for non-REL psect")); - return false; + goto fail; } vms_sec = vms_section_data (sec); @@ -5376,7 +5380,7 @@ alpha_vms_slurp_relocs (bfd *abfd) sec->relocation = bfd_realloc_or_free (sec->relocation, vms_sec->reloc_max * sizeof (arelent)); if (sec->relocation == NULL) - return false; + goto fail; } } reloc = &sec->relocation[sec->reloc_count]; @@ -5414,7 +5418,7 @@ alpha_vms_slurp_relocs (bfd *abfd) else if (cur_psidx >= 0) { if (PRIV (sections) == NULL || cur_psidx >= (int) PRIV (section_count)) - return false; + goto fail; reloc->sym_ptr_ptr = PRIV (sections)[cur_psidx]->symbol_ptr_ptr; } @@ -5438,8 +5442,12 @@ alpha_vms_slurp_relocs (bfd *abfd) } } vms_debug2 ((3, "alpha_vms_slurp_relocs: result = true\n")); - + PRIV (reloc_done) = 1; return true; + +fail: + PRIV (reloc_done) = -1; + return false; } /* Return the number of bytes required to store the relocation @@ -5448,7 +5456,8 @@ alpha_vms_slurp_relocs (bfd *abfd) static long alpha_vms_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED, asection *section) { - alpha_vms_slurp_relocs (abfd); + if (!alpha_vms_slurp_relocs (abfd)) + return -1; return (section->reloc_count + 1L) * sizeof (arelent *); } -- Alan Modra Australia Development Lab, IBM