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
This commit is contained in:
Simon Marchi 2021-12-03 16:31:09 -05:00
parent 78d4da9ae0
commit 9bc8e54b1f
12 changed files with 9 additions and 87 deletions

View file

@ -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;
}

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -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)

View file

@ -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;

View file

@ -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))

View file

@ -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);

View file

@ -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

View file

@ -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);
}

View file

@ -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: