From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 7086E3858428 for ; Fri, 3 Dec 2021 21:31:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7086E3858428 X-ASG-Debug-ID: 1638567070-0c856e2e4745bc80001-Lwtx7q Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id QFTr0qLlTmYE4ZEn (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 03 Dec 2021 16:31:10 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.localdomain (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) by smtp.ebox.ca (Postfix) with ESMTP id 4AF4C441B21; Fri, 3 Dec 2021 16:31:10 -0500 (EST) From: Simon Marchi X-Barracuda-RBL-IP: 192.222.157.6 X-Barracuda-Effective-Source-IP: 192-222-157-6.qc.cable.ebox.net[192.222.157.6] X-Barracuda-Apparent-Source-IP: 192.222.157.6 To: binutils@sourceware.org Cc: Simon Marchi Subject: [PATCH] bfd: fix -Wunused errors with clang 13+ Date: Fri, 3 Dec 2021 16:31:09 -0500 X-ASG-Orig-Subj: [PATCH] bfd: fix -Wunused errors with clang 13+ Message-Id: <20211203213109.1425822-1-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1638567070 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-BRTS-Status: 1 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 14344 X-Barracuda-Spam-Score: 0.50 X-Barracuda-Spam-Status: No, SCORE=0.50 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_RULE7568M X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.94384 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.50 BSF_RULE7568M Custom Rule 7568M X-Spam-Status: No, score=-15.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_QUARANTINE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Dec 2021 21:31:14 -0000 Clang 13 and 14 produce some -Wunused-but-set-{variable,parameter} for situations where gcc doesn't. In particular, when a variable is set and then used in a way to update its own value. For example, if `i` is only used in this way: int i = 2; i++; i = i + 1; gcc won't warn, but clang will. Fix all such errors found in an --enable-targets=all build. It would be important for somebody who knows what they're doing to just make sure that these variables can indeed be deleted, and that there a no cases where it's a bug, and the variable should actually be used. The first instance of this error fix by this patch is: CC elf32-score.lo /home/simark/src/binutils-gdb/bfd/elf32-score.c:450:11: error: variable 'relocation' set but not used [-Werror,-Wunused-but-set-variable] bfd_vma relocation; ^ Change-Id: I2f233ce20352645cf388aff3dfa08a651d21a6b6 --- bfd/ecofflink.c | 7 ------- bfd/elf-m10200.c | 6 ------ bfd/elf-m10300.c | 6 ------ bfd/elf32-bfin.c | 5 +---- bfd/elf32-cr16.c | 5 +---- bfd/elf32-lm32.c | 5 +---- bfd/elf32-microblaze.c | 14 -------------- bfd/elf32-nds32.c | 12 ++---------- bfd/elf32-nios2.c | 6 +----- bfd/elf32-score.c | 13 ++----------- bfd/elf32-score7.c | 11 +---------- bfd/elf64-ia64-vms.c | 6 ------ 12 files changed, 9 insertions(+), 87 deletions(-) diff --git a/bfd/ecofflink.c b/bfd/ecofflink.c index 9f72409d6b16..44cb1f3a5a68 100644 --- a/bfd/ecofflink.c +++ b/bfd/ecofflink.c @@ -2402,9 +2402,6 @@ _bfd_ecoff_locate_line (bfd *abfd, static bool ecoff_collect_shuffle (struct shuffle *l, bfd_byte *buff) { - unsigned long total; - - total = 0; for (; l != (struct shuffle *) NULL; l = l->next) { if (! l->filep) @@ -2416,7 +2413,6 @@ ecoff_collect_shuffle (struct shuffle *l, bfd_byte *buff) != l->size)) return false; } - total += l->size; buff += l->size; } @@ -2451,13 +2447,11 @@ _bfd_ecoff_get_accumulated_ss (void * handle, bfd_byte *buff) { struct accumulate *ainfo = (struct accumulate *) handle; struct string_hash_entry *sh; - unsigned long total; /* The string table is written out from the hash table if this is a final link. */ BFD_ASSERT (ainfo->ss == (struct shuffle *) NULL); *buff++ = '\0'; - total = 1; BFD_ASSERT (ainfo->ss_hash == NULL || ainfo->ss_hash->val == 1); for (sh = ainfo->ss_hash; sh != (struct string_hash_entry *) NULL; @@ -2467,7 +2461,6 @@ _bfd_ecoff_get_accumulated_ss (void * handle, bfd_byte *buff) len = strlen (sh->root.string); memcpy (buff, sh->root.string, len + 1); - total += len + 1; buff += len + 1; } diff --git a/bfd/elf-m10200.c b/bfd/elf-m10200.c index 9c1e4eb70fc5..9cca778e7db2 100644 --- a/bfd/elf-m10200.c +++ b/bfd/elf-m10200.c @@ -795,14 +795,8 @@ mn10200_elf_relax_section (bfd *abfd, if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10200_PCREL8) { Elf_Internal_Rela *nrel; - bfd_vma value = symval; unsigned char code; - /* Deal with pc-relative gunk. */ - value -= (sec->output_section->vma + sec->output_offset); - value -= (irel->r_offset + 1); - value += irel->r_addend; - /* Do nothing if this reloc is the last byte in the section. */ if (irel->r_offset == sec->size) continue; diff --git a/bfd/elf-m10300.c b/bfd/elf-m10300.c index fadd9ab0e82c..ab2c1304855b 100644 --- a/bfd/elf-m10300.c +++ b/bfd/elf-m10300.c @@ -3702,14 +3702,8 @@ mn10300_elf_relax_section (bfd *abfd, if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_PCREL8) { Elf_Internal_Rela *nrel; - bfd_vma value = symval; unsigned char code; - /* Deal with pc-relative gunk. */ - value -= (sec->output_section->vma + sec->output_offset); - value -= irel->r_offset; - value += irel->r_addend; - /* Do nothing if this reloc is the last byte in the section. */ if (irel->r_offset == sec->size) continue; diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c index 037da60ef74e..9cf0064447e1 100644 --- a/bfd/elf32-bfin.c +++ b/bfd/elf32-bfin.c @@ -4109,7 +4109,7 @@ _bfinfdpic_check_discarded_relocs (bfd *abfd, asection *sec, bool *changed) { Elf_Internal_Shdr *symtab_hdr; - struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; + struct elf_link_hash_entry **sym_hashes; Elf_Internal_Rela *rel, *erel; if ((sec->flags & SEC_RELOC) == 0 @@ -4118,9 +4118,6 @@ _bfinfdpic_check_discarded_relocs (bfd *abfd, asection *sec, symtab_hdr = &elf_tdata (abfd)->symtab_hdr; sym_hashes = elf_sym_hashes (abfd); - sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf32_External_Sym); - if (!elf_bad_symtab (abfd)) - sym_hashes_end -= symtab_hdr->sh_info; rel = elf_section_data (sec)->relocs; diff --git a/bfd/elf32-cr16.c b/bfd/elf32-cr16.c index 2a1c8be624e4..b23ff34c10aa 100644 --- a/bfd/elf32-cr16.c +++ b/bfd/elf32-cr16.c @@ -700,7 +700,7 @@ cr16_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec, { Elf_Internal_Shdr *symtab_hdr; Elf_Internal_Sym * isymbuf = NULL; - struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; + struct elf_link_hash_entry **sym_hashes; const Elf_Internal_Rela *rel; const Elf_Internal_Rela *rel_end; bfd * dynobj; @@ -717,9 +717,6 @@ cr16_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec, symtab_hdr = &elf_tdata (abfd)->symtab_hdr; sym_hashes = elf_sym_hashes (abfd); - sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym); - if (!elf_bad_symtab (abfd)) - sym_hashes_end -= symtab_hdr->sh_info; dynobj = elf_hash_table (info)->dynobj; local_got_offsets = elf_local_got_offsets (abfd); diff --git a/bfd/elf32-lm32.c b/bfd/elf32-lm32.c index be8d41632c17..779b6817dfd7 100644 --- a/bfd/elf32-lm32.c +++ b/bfd/elf32-lm32.c @@ -1120,7 +1120,7 @@ lm32_elf_check_relocs (bfd *abfd, const Elf_Internal_Rela *relocs) { Elf_Internal_Shdr *symtab_hdr; - struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; + struct elf_link_hash_entry **sym_hashes; const Elf_Internal_Rela *rel; const Elf_Internal_Rela *rel_end; struct elf_lm32_link_hash_table *htab; @@ -1131,9 +1131,6 @@ lm32_elf_check_relocs (bfd *abfd, symtab_hdr = &elf_tdata (abfd)->symtab_hdr; sym_hashes = elf_sym_hashes (abfd); - sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym); - if (!elf_bad_symtab (abfd)) - sym_hashes_end -= symtab_hdr->sh_info; htab = lm32_elf_hash_table (info); if (htab == NULL) diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c index d9c0d93a01a6..b05ee9bca2b1 100644 --- a/bfd/elf32-microblaze.c +++ b/bfd/elf32-microblaze.c @@ -2088,8 +2088,6 @@ microblaze_elf_relax_section (bfd *abfd, if (isym->st_shndx == shndx && (ELF32_ST_TYPE (isym->st_info) == STT_SECTION)) { - bfd_vma immediate; - if (ocontents == NULL) { if (elf_section_data (o)->this_hdr.contents != NULL) @@ -2112,15 +2110,7 @@ microblaze_elf_relax_section (bfd *abfd, elf_section_data (o)->this_hdr.contents = ocontents; } } - unsigned long instr_hi = bfd_get_32 (abfd, ocontents - + irelscan->r_offset); - unsigned long instr_lo = bfd_get_32 (abfd, ocontents - + irelscan->r_offset - + INST_WORD_SIZE); - immediate = (instr_hi & 0x0000ffff) << 16; - immediate |= (instr_lo & 0x0000ffff); offset = calc_fixup (irelscan->r_addend, 0, sec); - immediate -= offset; irelscan->r_addend -= offset; } } @@ -2326,7 +2316,6 @@ microblaze_elf_check_relocs (bfd * abfd, { Elf_Internal_Shdr * symtab_hdr; struct elf_link_hash_entry ** sym_hashes; - struct elf_link_hash_entry ** sym_hashes_end; const Elf_Internal_Rela * rel; const Elf_Internal_Rela * rel_end; struct elf32_mb_link_hash_table *htab; @@ -2341,9 +2330,6 @@ microblaze_elf_check_relocs (bfd * abfd, symtab_hdr = & elf_tdata (abfd)->symtab_hdr; sym_hashes = elf_sym_hashes (abfd); - sym_hashes_end = sym_hashes + symtab_hdr->sh_size / sizeof (Elf32_External_Sym); - if (!elf_bad_symtab (abfd)) - sym_hashes_end -= symtab_hdr->sh_info; rel_end = relocs + sec->reloc_count; diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c index 0aa7c9ee564c..5b43ca978035 100644 --- a/bfd/elf32-nds32.c +++ b/bfd/elf32-nds32.c @@ -6973,7 +6973,7 @@ nds32_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec, const Elf_Internal_Rela *relocs) { Elf_Internal_Shdr *symtab_hdr; - struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; + struct elf_link_hash_entry **sym_hashes; const Elf_Internal_Rela *rel; const Elf_Internal_Rela *rel_end; struct elf_link_hash_table *ehtab; @@ -6990,10 +6990,6 @@ nds32_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, symtab_hdr = &elf_tdata (abfd)->symtab_hdr; sym_hashes = elf_sym_hashes (abfd); - sym_hashes_end = - sym_hashes + symtab_hdr->sh_size / sizeof (Elf32_External_Sym); - if (!elf_bad_symtab (abfd)) - sym_hashes_end -= symtab_hdr->sh_info; ehtab = elf_hash_table (info); htab = nds32_elf_hash_table (info); @@ -13478,12 +13474,8 @@ nds32_elf_unify_tls_model (bfd *inbfd, asection *insec, bfd_byte *incontents, relax_group_list_t chain = { .id = -1, .next = NULL, .next_sibling = NULL }; Elf_Internal_Shdr *symtab_hdr = &elf_tdata (inbfd)->symtab_hdr; - struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; + struct elf_link_hash_entry **sym_hashes; sym_hashes = elf_sym_hashes (inbfd); - sym_hashes_end = - sym_hashes + symtab_hdr->sh_size / sizeof (Elf32_External_Sym); - if (!elf_bad_symtab (inbfd)) - sym_hashes_end -= symtab_hdr->sh_info; /* Reorder RELAX_GROUP when command line option '-r' is applied. */ if (bfd_link_relocatable (lnkinfo)) diff --git a/bfd/elf32-nios2.c b/bfd/elf32-nios2.c index 5fb2e5dddf6d..c1a450b61d6a 100644 --- a/bfd/elf32-nios2.c +++ b/bfd/elf32-nios2.c @@ -4676,7 +4676,7 @@ nios2_elf32_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec, const Elf_Internal_Rela *relocs) { Elf_Internal_Shdr *symtab_hdr; - struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; + struct elf_link_hash_entry **sym_hashes; const Elf_Internal_Rela *rel; const Elf_Internal_Rela *rel_end; struct elf32_nios2_link_hash_table *htab; @@ -4688,10 +4688,6 @@ nios2_elf32_check_relocs (bfd *abfd, struct bfd_link_info *info, symtab_hdr = &elf_tdata (abfd)->symtab_hdr; sym_hashes = elf_sym_hashes (abfd); - sym_hashes_end = (sym_hashes - + symtab_hdr->sh_size / sizeof (Elf32_External_Sym)); - if (!elf_bad_symtab (abfd)) - sym_hashes_end -= symtab_hdr->sh_info; local_got_refcounts = elf_local_got_refcounts (abfd); htab = elf32_nios2_hash_table (info); diff --git a/bfd/elf32-score.c b/bfd/elf32-score.c index e8a7e6388afb..cf2a3a43a848 100644 --- a/bfd/elf32-score.c +++ b/bfd/elf32-score.c @@ -440,23 +440,14 @@ score_elf_final_gp (bfd *output_bfd, static bfd_reloc_status_type score_elf_gprel15_with_gp (bfd *abfd, - asymbol *symbol, arelent *reloc_entry, asection *input_section, bool relocateable, void * data, bfd_vma gp ATTRIBUTE_UNUSED) { - bfd_vma relocation; unsigned long insn; - if (bfd_is_com_section (symbol->section)) - relocation = 0; - else - relocation = symbol->value; - - relocation += symbol->section->output_section->vma; - relocation += symbol->section->output_offset; if (reloc_entry->address > input_section->size) return bfd_reloc_outofrange; @@ -547,8 +538,8 @@ score_elf_gprel15_reloc (bfd *abfd, if (ret != bfd_reloc_ok) return ret; - return score_elf_gprel15_with_gp (abfd, symbol, reloc_entry, - input_section, relocateable, data, gp); + return score_elf_gprel15_with_gp (abfd, reloc_entry, + input_section, relocateable, data, gp); } /* Do a R_SCORE_GPREL32 relocation. This is a 32 bit value which must diff --git a/bfd/elf32-score7.c b/bfd/elf32-score7.c index 50d607de1561..b3eac5604825 100644 --- a/bfd/elf32-score7.c +++ b/bfd/elf32-score7.c @@ -340,23 +340,14 @@ score_elf_final_gp (bfd *output_bfd, static bfd_reloc_status_type score_elf_gprel15_with_gp (bfd *abfd, - asymbol *symbol, arelent *reloc_entry, asection *input_section, bool relocateable, void * data, bfd_vma gp ATTRIBUTE_UNUSED) { - bfd_vma relocation; unsigned long insn; - if (bfd_is_com_section (symbol->section)) - relocation = 0; - else - relocation = symbol->value; - - relocation += symbol->section->output_section->vma; - relocation += symbol->section->output_offset; if (reloc_entry->address > input_section->size) return bfd_reloc_outofrange; @@ -449,7 +440,7 @@ score_elf_gprel15_reloc (bfd *abfd, if (ret != bfd_reloc_ok) return ret; - return score_elf_gprel15_with_gp (abfd, symbol, reloc_entry, + return score_elf_gprel15_with_gp (abfd, reloc_entry, input_section, relocateable, data, gp); } diff --git a/bfd/elf64-ia64-vms.c b/bfd/elf64-ia64-vms.c index c72015b450c5..54645f00ce4f 100644 --- a/bfd/elf64-ia64-vms.c +++ b/bfd/elf64-ia64-vms.c @@ -2512,8 +2512,6 @@ allocate_dynrel_entries (struct elf64_ia64_dyn_sym_info *dyn_i, for (rent = dyn_i->reloc_entries; rent; rent = rent->next) { - int count = rent->count; - switch (rent->type) { case R_IA64_FPTR32LSB: @@ -2538,10 +2536,6 @@ allocate_dynrel_entries (struct elf64_ia64_dyn_sym_info *dyn_i, case R_IA64_IPLTLSB: if (!dynamic_symbol && !shared) continue; - /* Use two REL relocations for IPLT relocations - against local symbols. */ - if (!dynamic_symbol) - count *= 2; break; case R_IA64_DTPREL32LSB: case R_IA64_TPREL64LSB: -- 2.33.1