From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by sourceware.org (Postfix) with ESMTPS id 01E97385800A for ; Mon, 6 Mar 2023 03:31:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 01E97385800A 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-pl1-x631.google.com with SMTP id p6so8879425plf.0 for ; Sun, 05 Mar 2023 19:31:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678073473; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=Bd7EUrvD8fFc7j95TwLwcBp3WcslyM3CQXV+NmPJPqQ=; b=RmvFohdturFosR6SJICg2ixDeRVW5OPbDUTEq3B3Z4rUUHrtwSO0ZhjnoINfBY8WvE CuQ0PvvZYLhxLnDGGz9w3MR750fMOf+FFohY5YWzC7omUJgpofiE1rCEqG+Jxls2irqy a/eE1SH/omqdHSGv1zjytXKWdHZ0OV1jmMj7xYf14Ac8rWMUNubPtYBu/Ljjb2775qBU ViFoxmU1+JrmDnTNz6SNwv56qYuY2XQy/3MiMkvMPFKo0wEJ8wsso9bD3uK+hj6xYocS 0kr1e2YSZQvMPPc/s9kEJMs7mV86NlbO7hnIRR0FliBlNGQNgJFBaVWWGKvtDTvoEp5P 114g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678073473; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Bd7EUrvD8fFc7j95TwLwcBp3WcslyM3CQXV+NmPJPqQ=; b=DemGoJ/Xxn0gLt0U2uLZXUYuCrcg5TQGPPaGYUAGFGN6NSeZC3k3uaNx7B8U7uxuB6 FTBIVjjZt7iVnXElaMNs3qZz+f4a/ZpKnhEPR5sHSAoVcFDkU2wviRiXPhpUTeFhkM9p smTSPFneyGf/dDlf+3SmEEdt5N6LDmhExw8ZyKgavhZ+TTjv9+fsbOtQcVvHYPFxn/ap q/2FV4xSFwnqriTgLRc1F18MaUqTTkWzgM8s5UH3tCzP5xiQPcCv2DFAkej7is86xoES 2A69Zd4gHiEFIgd4Q257QV6lkHAJpPrF9zQKkClPMT3v5KIBczjvr/e5xFnRtKGbcDec vmBw== X-Gm-Message-State: AO0yUKUPci9suIVKJdpeG1oaSQIJjPIg8ANM4fccljnxCLKA4Hiynuto eFGHSepMjgoIeOYX/bYg6DcE2gSYSQs= X-Google-Smtp-Source: AK7set+HpkqKNhdszkMTEgQxmENMRx5cFlrz6ydLYxVAu8zY1AzNsalTPPZzHI6chy4XUtOkU0GnMg== X-Received: by 2002:a05:6a20:2a12:b0:cc:e0fb:a835 with SMTP id e18-20020a056a202a1200b000cce0fba835mr8640311pzh.47.1678073472794; Sun, 05 Mar 2023 19:31:12 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:706e:b31e:8824:abae]) by smtp.gmail.com with ESMTPSA id e15-20020a63e00f000000b004cd2eebc551sm5019351pgh.62.2023.03.05.19.31.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Mar 2023 19:31:12 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 2DB711142C90; Mon, 6 Mar 2023 14:01:10 +1030 (ACDT) Date: Mon, 6 Mar 2023 14:01:10 +1030 From: Alan Modra To: binutils@sourceware.org Subject: Downgrade objdump fatal errors to non-fatal Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3034.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: * objdump.c (slurp_symtab): Replace bfd_fatal calls with calls to my_bfd_nonfatal. (slurp_dynamic_symtab, disassemble_section): Likewise. (disassemble_data): Replace fatal call with non_fatal call, and set exit_status. Don't error on non-existent dynamic relocs. Don't call bfd_fatal on bfd_canonicalize_dynamic_reloc error. (dump_ctf, dump_section_sframe): Replace bfd_fatal calls with calls to my_bfd_nonfatal and clean up memory. (dump_relocs_in_section): Don't call bfd_fatal on errors. (dump_dynamic_relocs): Likewise. (display_any_bfd): Make archive nesting too depp non_fatal. diff --git a/binutils/objdump.c b/binutils/objdump.c index c895221c679..97532bed97c 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -1002,16 +1002,20 @@ slurp_symtab (bfd *abfd) { non_fatal (_("failed to read symbol table from: %s"), bfd_get_filename (abfd)); - bfd_fatal (_("error message was")); + my_bfd_nonfatal (_("error message was")); } - if (storage == 0) + if (storage <= 0) return NULL; asymbol **sy = (asymbol **) xmalloc (storage); symcount = bfd_canonicalize_symtab (abfd, sy); if (symcount < 0) - bfd_fatal (bfd_get_filename (abfd)); + { + my_bfd_nonfatal (bfd_get_filename (abfd)); + free (sy); + sy = NULL; + } return sy; } @@ -1031,16 +1035,20 @@ slurp_dynamic_symtab (bfd *abfd) return NULL; } - bfd_fatal (bfd_get_filename (abfd)); + my_bfd_nonfatal (bfd_get_filename (abfd)); } - if (storage == 0) + if (storage <= 0) return NULL; asymbol **sy = (asymbol **) xmalloc (storage); dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy); if (dynsymcount < 0) - bfd_fatal (bfd_get_filename (abfd)); + { + my_bfd_nonfatal (bfd_get_filename (abfd)); + free (sy); + sy = NULL; + } return sy; } @@ -3747,17 +3755,23 @@ disassemble_section (bfd *abfd, asection *section, void *inf) relsize = bfd_get_reloc_upper_bound (abfd, section); if (relsize < 0) - bfd_fatal (bfd_get_filename (abfd)); + my_bfd_nonfatal (bfd_get_filename (abfd)); if (relsize > 0) { - rel_ppstart = rel_pp = (arelent **) xmalloc (relsize); + rel_pp = (arelent **) xmalloc (relsize); rel_count = bfd_canonicalize_reloc (abfd, section, rel_pp, syms); if (rel_count < 0) - bfd_fatal (bfd_get_filename (abfd)); - - /* Sort the relocs by address. */ - qsort (rel_pp, rel_count, sizeof (arelent *), compare_relocs); + { + my_bfd_nonfatal (bfd_get_filename (abfd)); + free (rel_pp); + rel_pp = NULL; + rel_count = 0; + } + else if (rel_count > 1) + /* Sort the relocs by address. */ + qsort (rel_pp, rel_count, sizeof (arelent *), compare_relocs); + rel_ppstart = rel_pp; } } } @@ -4103,9 +4117,12 @@ disassemble_data (bfd *abfd) const bfd_arch_info_type *inf = bfd_scan_arch (machine); if (inf == NULL) - fatal (_("can't use supplied machine %s"), machine); - - abfd->arch_info = inf; + { + non_fatal (_("can't use supplied machine %s"), machine); + exit_status = 1; + } + else + abfd->arch_info = inf; } if (endian != BFD_ENDIAN_UNKNOWN) @@ -4156,20 +4173,22 @@ disassemble_data (bfd *abfd) /* Pre-load the dynamic relocs as we may need them during the disassembly. */ long relsize = bfd_get_dynamic_reloc_upper_bound (abfd); - if (relsize < 0 && dump_dynamic_reloc_info) - bfd_fatal (bfd_get_filename (abfd)); - if (relsize > 0) { disasm_info.dynrelbuf = (arelent **) xmalloc (relsize); disasm_info.dynrelcount = bfd_canonicalize_dynamic_reloc (abfd, disasm_info.dynrelbuf, dynsyms); if (disasm_info.dynrelcount < 0) - bfd_fatal (bfd_get_filename (abfd)); - - /* Sort the relocs by address. */ - qsort (disasm_info.dynrelbuf, disasm_info.dynrelcount, sizeof (arelent *), - compare_relocs); + { + my_bfd_nonfatal (bfd_get_filename (abfd)); + free (disasm_info.dynrelbuf); + disasm_info.dynrelbuf = NULL; + disasm_info.dynrelcount = 0; + } + else if (disasm_info.dynrelcount > 1) + /* Sort the relocs by address. */ + qsort (disasm_info.dynrelbuf, disasm_info.dynrelcount, + sizeof (arelent *), compare_relocs); } disasm_info.symtab = sorted_syms; @@ -4789,7 +4808,10 @@ dump_ctf (bfd *abfd, const char *sect_name, const char *parent_name) sec = read_section (abfd, sect_name, &ctfdata); if (sec == NULL) - bfd_fatal (bfd_get_filename (abfd)); + { + my_bfd_nonfatal (bfd_get_filename (abfd)); + return; + } /* Load the CTF file and dump it. Preload the parent dict, since it will need to be imported into every child in turn. */ @@ -4799,14 +4821,19 @@ dump_ctf (bfd *abfd, const char *sect_name, const char *parent_name) { dump_ctf_errs (NULL); non_fatal (_("CTF open failure: %s"), ctf_errmsg (err)); - bfd_fatal (bfd_get_filename (abfd)); + my_bfd_nonfatal (bfd_get_filename (abfd)); + free (ctfdata); + return; } if ((parent = ctf_dict_open (ctfa, parent_name, &err)) == NULL) { dump_ctf_errs (NULL); non_fatal (_("CTF open failure: %s"), ctf_errmsg (err)); - bfd_fatal (bfd_get_filename (abfd)); + my_bfd_nonfatal (bfd_get_filename (abfd)); + ctf_close (ctfa); + free (ctfdata); + return; } printf (_("Contents of CTF section %s:\n"), sanitize_string (sect_name)); @@ -4817,7 +4844,7 @@ dump_ctf (bfd *abfd, const char *sect_name, const char *parent_name) { dump_ctf_errs (NULL); non_fatal (_("CTF archive member open failure: %s"), ctf_errmsg (err)); - bfd_fatal (bfd_get_filename (abfd)); + my_bfd_nonfatal (bfd_get_filename (abfd)); } ctf_dict_close (parent); ctf_close (ctfa); @@ -4845,7 +4872,10 @@ dump_section_sframe (bfd *abfd ATTRIBUTE_UNUSED, sec = read_section (abfd, sect_name, &sframe_data); if (sec == NULL) - bfd_fatal (bfd_get_filename (abfd)); + { + my_bfd_nonfatal (bfd_get_filename (abfd)); + return; + } sf_size = bfd_section_size (sec); sf_vma = bfd_section_vma (sec); @@ -4853,8 +4883,9 @@ dump_section_sframe (bfd *abfd ATTRIBUTE_UNUSED, sfd_ctx = sframe_decode ((const char*)sframe_data, sf_size, &err); if (!sfd_ctx) { + my_bfd_nonfatal (bfd_get_filename (abfd)); free (sframe_data); - bfd_fatal (bfd_get_filename (abfd)); + return; } printf (_("Contents of the SFrame section %s:"), @@ -4862,8 +4893,8 @@ dump_section_sframe (bfd *abfd ATTRIBUTE_UNUSED, /* Dump the contents as text. */ dump_sframe (sfd_ctx, sf_vma); - free (sframe_data); sframe_decoder_free (&sfd_ctx); + free (sframe_data); } @@ -5334,7 +5365,7 @@ dump_relocs_in_section (bfd *abfd, asection *section, void *dummy ATTRIBUTE_UNUSED) { - arelent **relpp = NULL; + arelent **relpp; long relcount; long relsize; @@ -5355,7 +5386,10 @@ dump_relocs_in_section (bfd *abfd, } if (relsize < 0) - relcount = relsize; + { + relpp = NULL; + relcount = relsize; + } else { relpp = (arelent **) xmalloc (relsize); @@ -5367,7 +5401,7 @@ dump_relocs_in_section (bfd *abfd, printf ("\n"); non_fatal (_("failed to read relocs in: %s"), sanitize_string (bfd_get_filename (abfd))); - bfd_fatal (_("error message was")); + my_bfd_nonfatal (_("error message was")); } else if (relcount == 0) printf (" (none)\n\n"); @@ -5394,30 +5428,42 @@ dump_dynamic_relocs (bfd *abfd) long relcount; relsize = bfd_get_dynamic_reloc_upper_bound (abfd); - if (relsize < 0) - bfd_fatal (bfd_get_filename (abfd)); printf ("DYNAMIC RELOCATION RECORDS"); if (relsize == 0) - printf (" (none)\n\n"); + { + printf (" (none)\n\n"); + return; + } + + if (relsize < 0) + { + relpp = NULL; + relcount = relsize; + } else { relpp = (arelent **) xmalloc (relsize); relcount = bfd_canonicalize_dynamic_reloc (abfd, relpp, dynsyms); + } - if (relcount < 0) - bfd_fatal (bfd_get_filename (abfd)); - else if (relcount == 0) - printf (" (none)\n\n"); - else - { - printf ("\n"); - dump_reloc_set (abfd, NULL, relpp, relcount); - printf ("\n\n"); - } - free (relpp); + if (relcount < 0) + { + printf ("\n"); + non_fatal (_("failed to read relocs in: %s"), + sanitize_string (bfd_get_filename (abfd))); + my_bfd_nonfatal (_("error message was")); } + else if (relcount == 0) + printf (" (none)\n\n"); + else + { + printf ("\n"); + dump_reloc_set (abfd, NULL, relpp, relcount); + printf ("\n\n"); + } + free (relpp); } /* Creates a table of paths, to search for source files. */ @@ -5743,7 +5789,8 @@ display_any_bfd (bfd *file, int level) { /* Prevent corrupted files from spinning us into an infinite loop. 100 is an arbitrary heuristic. */ - fatal (_("Archive nesting is too deep")); + non_fatal (_("Archive nesting is too deep")); + exit_status = 1; return; } else -- Alan Modra Australia Development Lab, IBM