From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id E29663858024; Tue, 20 Sep 2022 23:38:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E29663858024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alan Modra To: bfd-cvs@sourceware.org Subject: [binutils-gdb] looping in alpha_vms_slurp_relocs X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: 7f99cbd91fcc8167bf0c3be369573df9052e5324 X-Git-Newrev: 8c8fa33c20ec0be7bfcaf7e1b605d37dca63733f Message-Id: <20220920233859.E29663858024@sourceware.org> Date: Tue, 20 Sep 2022 23:38:59 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Sep 2022 23:39:00 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D8c8fa33c20ec= 0be7bfcaf7e1b605d37dca63733f commit 8c8fa33c20ec0be7bfcaf7e1b605d37dca63733f Author: Alan Modra Date: Mon Sep 19 10:37:57 2022 +0930 looping in alpha_vms_slurp_relocs =20 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. =20 * 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: --- bfd/vms-alpha.c | 57 +++++++++++++++++++++++++++++++++--------------------= ---- 1 file changed, 33 insertions(+), 24 deletions(-) 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 =20 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; =20 /* Record input buffer. */ struct vms_rec_rd recrd; @@ -3380,7 +3381,8 @@ alpha_vms_write_exec (bfd *abfd) /* Place sections. */ for (sec =3D abfd->sections; sec; sec =3D sec->next) { - if (!(sec->flags & SEC_HAS_CONTENTS)) + if (!(sec->flags & SEC_HAS_CONTENTS) + || sec->contents =3D=3D NULL) continue; =20 eisd =3D 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; =20 - if (sec->size =3D=3D 0 || !(sec->flags & SEC_HAS_CONTENTS)) + if (sec->size =3D=3D 0 || !(sec->flags & SEC_HAS_CONTENTS) + || sec->contents =3D=3D NULL) continue; if (bfd_bwrite (sec->contents, sec->size, abfd) !=3D sec->size) return false; @@ -5122,15 +5125,14 @@ alpha_vms_slurp_relocs (bfd *abfd) vms_debug2 ((3, "alpha_vms_slurp_relocs\n")); =20 /* We slurp relocs only once, for all sections. */ - if (PRIV (reloc_done)) - return true; - PRIV (reloc_done) =3D true; + if (PRIV (reloc_done) !=3D 0) + return PRIV (reloc_done) =3D=3D 1; =20 if (alpha_vms_canonicalize_symtab (abfd, NULL) < 0) - return false; + goto fail; =20 if (bfd_seek (abfd, 0, SEEK_SET) !=3D 0) - return false; + goto fail; =20 while (1) { @@ -5151,6 +5153,8 @@ alpha_vms_slurp_relocs (bfd *abfd) =20 /* Skip non-ETIR records. */ type =3D _bfd_vms_get_object_record (abfd); + if (type < 0) + goto fail; if (type =3D=3D EOBJ__C_EEOM) break; if (type !=3D 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 =3D cur_psidx; vaddr =3D 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 =3D 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 =3D bfd_getl64 (ptr + 4); prev_cmd =3D 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 =3D 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 =3D 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 =3D 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 =3D 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; } =20 { @@ -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; } =20 if (PRIV (sections) =3D=3D NULL) - return false; + goto fail; sec =3D PRIV (sections)[cur_psect]; if (sec =3D=3D bfd_abs_section_ptr) { _bfd_error_handler (_("relocation for non-REL psect")); - return false; + goto fail; } =20 vms_sec =3D vms_section_data (sec); @@ -5376,7 +5380,7 @@ alpha_vms_slurp_relocs (bfd *abfd) sec->relocation =3D bfd_realloc_or_free (sec->relocation, vms_sec->reloc_max * sizeof (arelent)); if (sec->relocation =3D=3D NULL) - return false; + goto fail; } } reloc =3D &sec->relocation[sec->reloc_count]; @@ -5414,7 +5418,7 @@ alpha_vms_slurp_relocs (bfd *abfd) else if (cur_psidx >=3D 0) { if (PRIV (sections) =3D=3D NULL || cur_psidx >=3D (int) PRIV (section_co= unt)) - return false; + goto fail; reloc->sym_ptr_ptr =3D 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 =3D true\n")); - + PRIV (reloc_done) =3D 1; return true; + +fail: + PRIV (reloc_done) =3D -1; + return false; } =20 /* 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 *sec= tion) { - alpha_vms_slurp_relocs (abfd); + if (!alpha_vms_slurp_relocs (abfd)) + return -1; =20 return (section->reloc_count + 1L) * sizeof (arelent *); }