[PATCH 1/1] bfd, binutils, gas: Mark unused variables
Tsukasa OI
research_trasio@irq.a4lg.com
Thu Sep 15 08:25:32 GMT 2022
On 2022/09/15 16:29, Jan Beulich wrote:
> On 15.09.2022 06:17, Tsukasa OI via Binutils wrote:
>> Clang generates a warning on unused (technically, written but not read
>> thereafter) variables. By the default configuration (with "-Werror"), it
>> causes a build failure (unless "--disable-werror" is specified).
>>
>> This commit, instead of just removing those variables, adds
>> ATTRIBUTE_UNUSED attribute to them, which means they are *possibly* unused
>> (can be used but no warnings occur when unused).
>
> May I ask why you chose to do so? I can see such a variable being consumed
> inside an #ifdef, but being declared unconditionally as a reason, but
> (looking just at code I'm a little familiar with) ...
>
>> --- a/gas/config/tc-riscv.c
>> +++ b/gas/config/tc-riscv.c
>> @@ -2303,7 +2303,7 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
>> char save_c = 0;
>> struct riscv_opcode *insn;
>> unsigned int regno;
>> - int argnum;
>> + int argnum ATTRIBUTE_UNUSED;
>> const struct percent_op_match *p;
>> struct riscv_ip_error error;
>> error.msg = "unrecognized opcode";
>> --- a/ld/pe-dll.c
>> +++ b/ld/pe-dll.c
>> @@ -1510,8 +1510,9 @@ generate_reloc (bfd *abfd, struct bfd_link_info *info)
>> int total_relocs = 0;
>> int i;
>> bfd_vma sec_page = (bfd_vma) -1;
>> - bfd_vma page_ptr, page_count;
>> - int bi;
>> + bfd_vma page_ptr;
>> + bfd_vma page_count ATTRIBUTE_UNUSED;
>> + int bi ATTRIBUTE_UNUSED;
>> bfd *b;
>> struct bfd_section *s;
>>
>
> ... in both of these cases there's truly no reading of the values,
> so I don't see why they would need maintaining.
>
> Jan
>
Possibly because I'm a coward? ... I'm kidding but I must admit that I
didn't take a time to review their actual uses and chose not to break
someone's job (knowing that "someone" may not exist anymore).
bfd/elf32-lm32.c:
It seems unused rgot_count is a part of an unimplemented feature.
I want to keep this variable. Existence of this variable was the
first reason for me to keep "unused" variables.
bfd/mmo.c:
Likewise (though that "an unimplemented feature" is never
implemented for over 10 years).
I want to keep this variable (but may change my mind in the future).
binutils/windmc.c:
For this simple function, recovering i variable is very easy.
It seems it's also a debug artifact from the earliest days.
Removing is an option.
gas/tc-riscv.c:
I first thought it's a part of an unimplemented feature and to help
implementing assembler something... but it seems unused from the
start (possibly an artifact on the first contribution?).
Removing is an option.
ld/pe-dll.c:
I reviewed thoroughly and concluded that, despite that they may have
a debugging use, keeping this state over 20 years seems too long.
Removing is an option.
bfd/elf32-nds32.c:
The first time this variables is added, someone was clearly
debugging their code and it may be an artifact, too. Unlike RISC-V,
it's not an artifact from the first NDS port and it was added
in 2018. Recovering this variable is not hard but...
Removing is ... possibly an option?
I think I can remove unused variables from those files:
* binutils/windmc.c
* gas/tc-riscv.c
* ld/pe-dll.c
bfd/elf32-nds32.c is a candidate of unused variable removal.
For bfd/elf32-lm32.c and bfd/mmo.c, I will choose to keep unused
variables for now. If those variables are still unused in like 2030, I
will change my mind.
I'll at least remove unused variables on three files I shown above (and
possibly on bfd/elf32-nds32.c) and resubmit that patch.
Thanks,
Tsukasa
More information about the Binutils
mailing list