diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2021-12-03 16:31:09 -0500 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2021-12-14 08:47:48 -0500 |
commit | 9bc8e54b1f1c281c7a4ecf49a4e9300e334beb0a (patch) | |
tree | a14d07055ccb22a4858f58147c5492ca55460425 | |
parent | 78d4da9ae0d3447f28274a00b278f58ca7d8d1b2 (diff) | |
download | gdb-9bc8e54b1f1c281c7a4ecf49a4e9300e334beb0a.zip gdb-9bc8e54b1f1c281c7a4ecf49a4e9300e334beb0a.tar.gz gdb-9bc8e54b1f1c281c7a4ecf49a4e9300e334beb0a.tar.bz2 |
bfd: fix -Wunused errors with clang 13+
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
-rw-r--r-- | bfd/ecofflink.c | 7 | ||||
-rw-r--r-- | bfd/elf-m10200.c | 6 | ||||
-rw-r--r-- | bfd/elf-m10300.c | 6 | ||||
-rw-r--r-- | bfd/elf32-bfin.c | 5 | ||||
-rw-r--r-- | bfd/elf32-cr16.c | 5 | ||||
-rw-r--r-- | bfd/elf32-lm32.c | 5 | ||||
-rw-r--r-- | bfd/elf32-microblaze.c | 14 | ||||
-rw-r--r-- | bfd/elf32-nds32.c | 12 | ||||
-rw-r--r-- | bfd/elf32-nios2.c | 6 | ||||
-rw-r--r-- | bfd/elf32-score.c | 13 | ||||
-rw-r--r-- | bfd/elf32-score7.c | 11 | ||||
-rw-r--r-- | bfd/elf64-ia64-vms.c | 6 |
12 files changed, 9 insertions, 87 deletions
diff --git a/bfd/ecofflink.c b/bfd/ecofflink.c index 9f72409..44cb1f3 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 9c1e4eb..9cca778 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 fadd9ab..ab2c130 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 037da60..9cf0064 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 2a1c8be..b23ff34 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 be8d416..779b681 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 d9c0d93..b05ee9b 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 0aa7c9e..5b43ca9 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 5fb2e5d..c1a450b 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 e8a7e63..cf2a3a4 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 50d607d..b3eac56 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 c72015b..54645f0 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: |