* [PATCH 0/1] bfd, binutils, gas: Mark unused variables @ 2022-09-15 3:09 Tsukasa OI 2022-09-15 3:09 ` [PATCH 1/1] " Tsukasa OI 2022-09-15 4:17 ` [PATCH 0/1] " Tsukasa OI 0 siblings, 2 replies; 14+ messages in thread From: Tsukasa OI @ 2022-09-15 3:09 UTC (permalink / raw) To: Tsukasa OI, Nick Clifton, Ian Lance Taylor, Nelson Chu; +Cc: binutils Hello, [Common Background: Building GNU Binutils / GDB with Clang 15.0.0] I'm now testing to build GNU Binutils / GDB with latest Clang (15.0.0) and found some errors by default (when Binutils / GDB is not configured with "--disable-werror"). While the best compiler to build GNU Binutils / GDB is GNU GCC, testing other compilers are helpful to discover underlying problems and modernize Binutils / GDB, even if building entire Binutils / GDB with the latest Clang is unrealistic. To be sure, I'm not going to finish "porting for Clang". I will take low-hanging fruits and... 1. make building with Clang easier and/or 2. fix code issues (or non-issues) discovered as Clang warnings. I made four patchsets in which, applying them all makes it possible to build GNU Binutils / GDB with Clang (without help of --disable-werrors) for many (but not all) targets including i386 and RISC-V with Ubuntu 22.04 LTS (x86_64) host. At least, I think they fix all (at minimum, most of) arch- independent parts which prevents building with the latest version of Clang. This is the one of them. [About this Patchset] Clang generates a warning on "written but not read thereafter" varibles ("-Wset-but-unused-variable"), making the build failure. We could just remove practically unused variables but instead I chose to keep it but with ATTRIBUTE_UNUSED. This is because the most of such variables may have possible uses in the future. ATTRIBUTE_UNUSED (__attribute__((unused))) marks a variable *possibly unused* and suppresses warnings about "written but not read thereafter" or just "unused" variables. Note that it only means a variable is "possibly unused". Even if a variable with this attribute is "used", it's completely safe (removing the attribute when a variable is started to be used is definitely better, though). Thanks, Tsukasa Tsukasa OI (1): bfd, binutils, gas: Mark unused variables bfd/elf32-lm32.c | 5 +---- bfd/elf32-nds32.c | 4 +--- bfd/mmo.c | 7 +------ binutils/windmc.c | 5 ++--- gas/config/tc-riscv.c | 4 +--- ld/pe-dll.c | 11 ++++------- 6 files changed, 10 insertions(+), 26 deletions(-) base-commit: fe39ffdc202f04397f31557f17170b40bc42b77a -- 2.34.1 ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/1] bfd, binutils, gas: Mark unused variables 2022-09-15 3:09 [PATCH 0/1] bfd, binutils, gas: Mark unused variables Tsukasa OI @ 2022-09-15 3:09 ` Tsukasa OI 2022-09-15 4:17 ` [PATCH 0/1] " Tsukasa OI 1 sibling, 0 replies; 14+ messages in thread From: Tsukasa OI @ 2022-09-15 3:09 UTC (permalink / raw) To: Tsukasa OI, Nick Clifton, Ian Lance Taylor, Nelson Chu; +Cc: binutils 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). bfd/ChangeLog: * elf32-lm32.c (lm32_elf_size_dynamic_sections): Mark unused rgot_count variable. * elf32-nds32.c (elf32_nds32_unify_relax_group): Mark unused count variable. * mmo.c (mmo_scan): Mark unused lineno variable. binutils/ChangeLog: * windmc.c (write_rc): Mark unused i variable. gas/ChangeLog: * config/tc-riscv.c (riscv_ip): Mark unused argnum variable. ld/ChangeLog: * pe-dll.c (generate_reloc): Mark unused bi and page_count variables. --- bfd/elf32-lm32.c | 5 +---- bfd/elf32-nds32.c | 4 +--- bfd/mmo.c | 7 +------ binutils/windmc.c | 5 ++--- gas/config/tc-riscv.c | 4 +--- ld/pe-dll.c | 11 ++++------- 6 files changed, 10 insertions(+), 26 deletions(-) diff --git a/bfd/elf32-lm32.c b/bfd/elf32-lm32.c index 4830ab21dfa..b57188b0f35 100644 --- a/bfd/elf32-lm32.c +++ b/bfd/elf32-lm32.c @@ -2067,7 +2067,7 @@ lm32_elf_size_dynamic_sections (bfd *output_bfd, struct weak_symbol_list *list_start = NULL, *list_end = NULL; int rgot_weak_count = 0; int r32_count = 0; - int rgot_count = 0; + int rgot_count ATTRIBUTE_UNUSED = 0; /* Look for deleted sections. */ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) { @@ -2115,9 +2115,6 @@ lm32_elf_size_dynamic_sections (bfd *output_bfd, case R_LM32_32: r32_count++; break; - case R_LM32_16_GOT: - rgot_count++; - break; } } } diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c index 82c20592d6d..cb20c034781 100644 --- a/bfd/elf32-nds32.c +++ b/bfd/elf32-nds32.c @@ -13460,7 +13460,7 @@ elf32_nds32_unify_relax_group (bfd *abfd, asection *asec) Elf_Internal_Rela *relocs = NULL; enum elf_nds32_reloc_type rtype; struct section_id_list_t *node = NULL; - int count = 0; + int count ATTRIBUTE_UNUSED = 0; do { @@ -13499,8 +13499,6 @@ elf32_nds32_unify_relax_group (bfd *abfd, asection *asec) /* Change it. */ rel->r_addend += relax_group_ptr->bias; - /* Debugging count. */ - count++; } } while (false); diff --git a/bfd/mmo.c b/bfd/mmo.c index fd92a346bc7..57647139d40 100644 --- a/bfd/mmo.c +++ b/bfd/mmo.c @@ -1602,7 +1602,7 @@ static bool mmo_scan (bfd *abfd) { unsigned int i; - unsigned int lineno = 1; + unsigned int lineno ATTRIBUTE_UNUSED = 1; bool error = false; bfd_vma vma = 0; asection *sec = NULL; @@ -1671,7 +1671,6 @@ mmo_scan (bfd *abfd) goto error_return; } vma += 4; - lineno++; break; case LOP_LOC: @@ -1905,12 +1904,9 @@ mmo_scan (bfd *abfd) goto error_return; } - lineno = 0; break; case LOP_LINE: - /* Set line number. */ - lineno = y * 256 + z; /* FIXME: Create a sequence of mmo-specific line number entries for each section, then translate into canonical format. */ @@ -2087,7 +2083,6 @@ mmo_scan (bfd *abfd) } vma += 4; vma &= ~3; - lineno++; } } diff --git a/binutils/windmc.c b/binutils/windmc.c index b47da91f1bb..f8a04c9b619 100644 --- a/binutils/windmc.c +++ b/binutils/windmc.c @@ -765,7 +765,8 @@ static void write_rc (FILE *fp) { mc_node_lang *n; - int i, l; + int l; + int i ATTRIBUTE_UNUSED; fprintf (fp, "/* Do not edit this file manually.\n" @@ -773,12 +774,10 @@ write_rc (FILE *fp) if (! mc_nodes_lang_count) return; n = NULL; - i = 0; for (l = 0; l < mc_nodes_lang_count; l++) { if (n && n->lang == mc_nodes_lang[l]->lang) continue; - ++i; n = mc_nodes_lang[l]; fprintf (fp, "\n// Country: %s\n// Language: %s\n#pragma code_page(%u)\n", n->lang->lang_info.country, n->lang->lang_info.name, diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c index df2e201fb74..d8bf6c07f51 100644 --- 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"; @@ -2341,7 +2341,6 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr, error.msg = _("illegal operands"); error.missing_ext = NULL; create_insn (ip, insn); - argnum = 1; imm_expr->X_op = O_absent; *imm_reloc = BFD_RELOC_UNUSED; @@ -2859,7 +2858,6 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr, break; /* end RVV */ case ',': - ++argnum; if (*asarg++ == *oparg) continue; asarg--; diff --git a/ld/pe-dll.c b/ld/pe-dll.c index 92c33f528c8..77d8d387772 100644 --- 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; @@ -1525,8 +1526,7 @@ generate_reloc (bfd *abfd, struct bfd_link_info *info) reloc_data = xmalloc (total_relocs * sizeof (reloc_data_type)); total_relocs = 0; - bi = 0; - for (bi = 0, b = info->input_bfds; b; bi++, b = b->link.next) + for (b = info->input_bfds; b; b = b->link.next) { arelent **relocs; int relsize, nrelocs; @@ -1721,7 +1721,6 @@ generate_reloc (bfd *abfd, struct bfd_link_info *info) sec_page = (bfd_vma) -1; reloc_sz = 0; page_ptr = (bfd_vma) -1; - page_count = 0; for (i = 0; i < total_relocs; i++) { @@ -1740,7 +1739,6 @@ generate_reloc (bfd *abfd, struct bfd_link_info *info) page_ptr = reloc_sz; reloc_sz += 8; sec_page = this_page; - page_count = 0; } bfd_put_16 (abfd, (rva & 0xfff) + (reloc_data[i].type << 12), @@ -1753,7 +1751,6 @@ generate_reloc (bfd *abfd, struct bfd_link_info *info) reloc_sz += 2; } - page_count++; } while (reloc_sz & 3) -- 2.34.1 ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 0/1] bfd, binutils, gas: Mark unused variables 2022-09-15 3:09 [PATCH 0/1] bfd, binutils, gas: Mark unused variables Tsukasa OI 2022-09-15 3:09 ` [PATCH 1/1] " Tsukasa OI @ 2022-09-15 4:17 ` Tsukasa OI 2022-09-15 4:17 ` [PATCH 1/1] " Tsukasa OI 2022-09-15 12:46 ` [PATCH v3 0/1] bfd, binutils, gas: Remove/mark " Tsukasa OI 1 sibling, 2 replies; 14+ messages in thread From: Tsukasa OI @ 2022-09-15 4:17 UTC (permalink / raw) To: Tsukasa OI, Nick Clifton, Ian Lance Taylor, Nelson Chu; +Cc: binutils I'm really sorry! PATCH v1: <https://sourceware.org/pipermail/binutils/2022-September/122865.html> was broken because it was contaminated by an alternative solution (just removing the variables) and this patch removed all "unused" variable updates. I should have noticed when I saw line counts. Thanks, Tsukasa Tsukasa OI (1): bfd, binutils, gas: Mark unused variables bfd/elf32-lm32.c | 2 +- bfd/elf32-nds32.c | 2 +- bfd/mmo.c | 2 +- binutils/windmc.c | 3 ++- gas/config/tc-riscv.c | 2 +- ld/pe-dll.c | 5 +++-- 6 files changed, 9 insertions(+), 7 deletions(-) base-commit: fe39ffdc202f04397f31557f17170b40bc42b77a -- 2.34.1 ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/1] bfd, binutils, gas: Mark unused variables 2022-09-15 4:17 ` [PATCH 0/1] " Tsukasa OI @ 2022-09-15 4:17 ` Tsukasa OI 2022-09-15 7:29 ` Jan Beulich 2022-09-15 12:46 ` [PATCH v3 0/1] bfd, binutils, gas: Remove/mark " Tsukasa OI 1 sibling, 1 reply; 14+ messages in thread From: Tsukasa OI @ 2022-09-15 4:17 UTC (permalink / raw) To: Tsukasa OI, Nick Clifton, Ian Lance Taylor, Nelson Chu; +Cc: binutils 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). bfd/ChangeLog: * elf32-lm32.c (lm32_elf_size_dynamic_sections): Mark unused rgot_count variable. * elf32-nds32.c (elf32_nds32_unify_relax_group): Mark unused count variable. * mmo.c (mmo_scan): Mark unused lineno variable. binutils/ChangeLog: * windmc.c (write_rc): Mark unused i variable. gas/ChangeLog: * config/tc-riscv.c (riscv_ip): Mark unused argnum variable. ld/ChangeLog: * pe-dll.c (generate_reloc): Mark unused bi and page_count variables. --- bfd/elf32-lm32.c | 2 +- bfd/elf32-nds32.c | 2 +- bfd/mmo.c | 2 +- binutils/windmc.c | 3 ++- gas/config/tc-riscv.c | 2 +- ld/pe-dll.c | 5 +++-- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bfd/elf32-lm32.c b/bfd/elf32-lm32.c index 4830ab21dfa..64b3edef466 100644 --- a/bfd/elf32-lm32.c +++ b/bfd/elf32-lm32.c @@ -2067,7 +2067,7 @@ lm32_elf_size_dynamic_sections (bfd *output_bfd, struct weak_symbol_list *list_start = NULL, *list_end = NULL; int rgot_weak_count = 0; int r32_count = 0; - int rgot_count = 0; + int rgot_count ATTRIBUTE_UNUSED = 0; /* Look for deleted sections. */ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) { diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c index 82c20592d6d..5d2eb62ffe3 100644 --- a/bfd/elf32-nds32.c +++ b/bfd/elf32-nds32.c @@ -13460,7 +13460,7 @@ elf32_nds32_unify_relax_group (bfd *abfd, asection *asec) Elf_Internal_Rela *relocs = NULL; enum elf_nds32_reloc_type rtype; struct section_id_list_t *node = NULL; - int count = 0; + int count ATTRIBUTE_UNUSED = 0; do { diff --git a/bfd/mmo.c b/bfd/mmo.c index fd92a346bc7..ddcdd35a15f 100644 --- a/bfd/mmo.c +++ b/bfd/mmo.c @@ -1602,7 +1602,7 @@ static bool mmo_scan (bfd *abfd) { unsigned int i; - unsigned int lineno = 1; + unsigned int lineno ATTRIBUTE_UNUSED = 1; bool error = false; bfd_vma vma = 0; asection *sec = NULL; diff --git a/binutils/windmc.c b/binutils/windmc.c index b47da91f1bb..9cb30c0ddfd 100644 --- a/binutils/windmc.c +++ b/binutils/windmc.c @@ -765,7 +765,8 @@ static void write_rc (FILE *fp) { mc_node_lang *n; - int i, l; + int l; + int i ATTRIBUTE_UNUSED; fprintf (fp, "/* Do not edit this file manually.\n" diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c index df2e201fb74..509cd2ed624 100644 --- 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"; diff --git a/ld/pe-dll.c b/ld/pe-dll.c index 92c33f528c8..ae7f3d8328c 100644 --- 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; -- 2.34.1 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/1] bfd, binutils, gas: Mark unused variables 2022-09-15 4:17 ` [PATCH 1/1] " Tsukasa OI @ 2022-09-15 7:29 ` Jan Beulich 2022-09-15 8:25 ` Tsukasa OI 0 siblings, 1 reply; 14+ messages in thread From: Jan Beulich @ 2022-09-15 7:29 UTC (permalink / raw) To: Tsukasa OI; +Cc: binutils, Nick Clifton, Ian Lance Taylor, Nelson Chu 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 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/1] bfd, binutils, gas: Mark unused variables 2022-09-15 7:29 ` Jan Beulich @ 2022-09-15 8:25 ` Tsukasa OI 2022-09-15 23:10 ` Hans-Peter Nilsson 0 siblings, 1 reply; 14+ messages in thread From: Tsukasa OI @ 2022-09-15 8:25 UTC (permalink / raw) To: Jan Beulich; +Cc: binutils 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 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/1] bfd, binutils, gas: Mark unused variables 2022-09-15 8:25 ` Tsukasa OI @ 2022-09-15 23:10 ` Hans-Peter Nilsson 0 siblings, 0 replies; 14+ messages in thread From: Hans-Peter Nilsson @ 2022-09-15 23:10 UTC (permalink / raw) To: Tsukasa OI; +Cc: Jan Beulich, binutils On Thu, 15 Sep 2022, Tsukasa OI via Binutils wrote: > 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). > 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 agree with your assessment regarding mmo.c. :) The mmo.c change (marking the variable as unused) is fine, thanks. brgds, H-P ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v3 0/1] bfd, binutils, gas: Remove/mark unused variables 2022-09-15 4:17 ` [PATCH 0/1] " Tsukasa OI 2022-09-15 4:17 ` [PATCH 1/1] " Tsukasa OI @ 2022-09-15 12:46 ` Tsukasa OI 2022-09-15 12:46 ` [PATCH v3 1/1] " Tsukasa OI 1 sibling, 1 reply; 14+ messages in thread From: Tsukasa OI @ 2022-09-15 12:46 UTC (permalink / raw) To: Tsukasa OI, Nick Clifton, Jan Beulich; +Cc: binutils Hello, PATCH v1: <https://sourceware.org/pipermail/binutils/2022-September/122865.html> PATCH v2: <https://sourceware.org/pipermail/binutils/2022-September/122873.html> It "removes" unused variables in bfd, binutils and gas. [Changes: v2 -> v3] - Actually removed some but not all variables (instead of adding ATTRIBUTE_UNUSED) Thanks, Tsukasa Tsukasa OI (1): bfd, binutils, gas: Remove/mark unused variables bfd/elf32-lm32.c | 2 +- bfd/elf32-nds32.c | 3 --- bfd/mmo.c | 2 +- binutils/windmc.c | 4 +--- gas/config/tc-riscv.c | 3 --- ld/pe-dll.c | 9 ++------- 6 files changed, 5 insertions(+), 18 deletions(-) base-commit: fe39ffdc202f04397f31557f17170b40bc42b77a -- 2.34.1 ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v3 1/1] bfd, binutils, gas: Remove/mark unused variables 2022-09-15 12:46 ` [PATCH v3 0/1] bfd, binutils, gas: Remove/mark " Tsukasa OI @ 2022-09-15 12:46 ` Tsukasa OI 2022-09-15 12:58 ` Jan Beulich 2022-09-20 12:50 ` Nick Clifton 0 siblings, 2 replies; 14+ messages in thread From: Tsukasa OI @ 2022-09-15 12:46 UTC (permalink / raw) To: Tsukasa OI, Nick Clifton, Jan Beulich; +Cc: binutils 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 adds ATTRIBUTE_UNUSED attribute to some of them, which means they are *possibly* unused (can be used but no warnings occur when unused) and removes others. bfd/ChangeLog: * elf32-lm32.c (lm32_elf_size_dynamic_sections): Mark unused rgot_count variable. * elf32-nds32.c (elf32_nds32_unify_relax_group): Remove unused count variable. * mmo.c (mmo_scan): Mark unused lineno variable. binutils/ChangeLog: * windmc.c (write_rc): Remove unused i variable. gas/ChangeLog: * config/tc-riscv.c (riscv_ip): Remove unused argnum variable. ld/ChangeLog: * pe-dll.c (generate_reloc): Remove unused bi and page_count variables. --- bfd/elf32-lm32.c | 2 +- bfd/elf32-nds32.c | 3 --- bfd/mmo.c | 2 +- binutils/windmc.c | 4 +--- gas/config/tc-riscv.c | 3 --- ld/pe-dll.c | 9 ++------- 6 files changed, 5 insertions(+), 18 deletions(-) diff --git a/bfd/elf32-lm32.c b/bfd/elf32-lm32.c index 4830ab21dfa..64b3edef466 100644 --- a/bfd/elf32-lm32.c +++ b/bfd/elf32-lm32.c @@ -2067,7 +2067,7 @@ lm32_elf_size_dynamic_sections (bfd *output_bfd, struct weak_symbol_list *list_start = NULL, *list_end = NULL; int rgot_weak_count = 0; int r32_count = 0; - int rgot_count = 0; + int rgot_count ATTRIBUTE_UNUSED = 0; /* Look for deleted sections. */ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) { diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c index 82c20592d6d..35e0302ed74 100644 --- a/bfd/elf32-nds32.c +++ b/bfd/elf32-nds32.c @@ -13460,7 +13460,6 @@ elf32_nds32_unify_relax_group (bfd *abfd, asection *asec) Elf_Internal_Rela *relocs = NULL; enum elf_nds32_reloc_type rtype; struct section_id_list_t *node = NULL; - int count = 0; do { @@ -13499,8 +13498,6 @@ elf32_nds32_unify_relax_group (bfd *abfd, asection *asec) /* Change it. */ rel->r_addend += relax_group_ptr->bias; - /* Debugging count. */ - count++; } } while (false); diff --git a/bfd/mmo.c b/bfd/mmo.c index fd92a346bc7..ddcdd35a15f 100644 --- a/bfd/mmo.c +++ b/bfd/mmo.c @@ -1602,7 +1602,7 @@ static bool mmo_scan (bfd *abfd) { unsigned int i; - unsigned int lineno = 1; + unsigned int lineno ATTRIBUTE_UNUSED = 1; bool error = false; bfd_vma vma = 0; asection *sec = NULL; diff --git a/binutils/windmc.c b/binutils/windmc.c index b47da91f1bb..9a22e4991fb 100644 --- a/binutils/windmc.c +++ b/binutils/windmc.c @@ -765,7 +765,7 @@ static void write_rc (FILE *fp) { mc_node_lang *n; - int i, l; + int l; fprintf (fp, "/* Do not edit this file manually.\n" @@ -773,12 +773,10 @@ write_rc (FILE *fp) if (! mc_nodes_lang_count) return; n = NULL; - i = 0; for (l = 0; l < mc_nodes_lang_count; l++) { if (n && n->lang == mc_nodes_lang[l]->lang) continue; - ++i; n = mc_nodes_lang[l]; fprintf (fp, "\n// Country: %s\n// Language: %s\n#pragma code_page(%u)\n", n->lang->lang_info.country, n->lang->lang_info.name, diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c index df2e201fb74..2f5ee18e451 100644 --- a/gas/config/tc-riscv.c +++ b/gas/config/tc-riscv.c @@ -2303,7 +2303,6 @@ 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; const struct percent_op_match *p; struct riscv_ip_error error; error.msg = "unrecognized opcode"; @@ -2341,7 +2340,6 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr, error.msg = _("illegal operands"); error.missing_ext = NULL; create_insn (ip, insn); - argnum = 1; imm_expr->X_op = O_absent; *imm_reloc = BFD_RELOC_UNUSED; @@ -2859,7 +2857,6 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr, break; /* end RVV */ case ',': - ++argnum; if (*asarg++ == *oparg) continue; asarg--; diff --git a/ld/pe-dll.c b/ld/pe-dll.c index 92c33f528c8..338e2def83c 100644 --- a/ld/pe-dll.c +++ b/ld/pe-dll.c @@ -1510,8 +1510,7 @@ 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 *b; struct bfd_section *s; @@ -1525,8 +1524,7 @@ generate_reloc (bfd *abfd, struct bfd_link_info *info) reloc_data = xmalloc (total_relocs * sizeof (reloc_data_type)); total_relocs = 0; - bi = 0; - for (bi = 0, b = info->input_bfds; b; bi++, b = b->link.next) + for (b = info->input_bfds; b; b = b->link.next) { arelent **relocs; int relsize, nrelocs; @@ -1721,7 +1719,6 @@ generate_reloc (bfd *abfd, struct bfd_link_info *info) sec_page = (bfd_vma) -1; reloc_sz = 0; page_ptr = (bfd_vma) -1; - page_count = 0; for (i = 0; i < total_relocs; i++) { @@ -1740,7 +1737,6 @@ generate_reloc (bfd *abfd, struct bfd_link_info *info) page_ptr = reloc_sz; reloc_sz += 8; sec_page = this_page; - page_count = 0; } bfd_put_16 (abfd, (rva & 0xfff) + (reloc_data[i].type << 12), @@ -1753,7 +1749,6 @@ generate_reloc (bfd *abfd, struct bfd_link_info *info) reloc_sz += 2; } - page_count++; } while (reloc_sz & 3) -- 2.34.1 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v3 1/1] bfd, binutils, gas: Remove/mark unused variables 2022-09-15 12:46 ` [PATCH v3 1/1] " Tsukasa OI @ 2022-09-15 12:58 ` Jan Beulich 2022-09-20 12:50 ` Nick Clifton 1 sibling, 0 replies; 14+ messages in thread From: Jan Beulich @ 2022-09-15 12:58 UTC (permalink / raw) To: Tsukasa OI; +Cc: binutils, Nick Clifton On 15.09.2022 14:46, Tsukasa OI 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 adds ATTRIBUTE_UNUSED attribute to some of them, which means > they are *possibly* unused (can be used but no warnings occur when > unused) and removes others. Okay. Thanks, Jan ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v3 1/1] bfd, binutils, gas: Remove/mark unused variables 2022-09-15 12:46 ` [PATCH v3 1/1] " Tsukasa OI 2022-09-15 12:58 ` Jan Beulich @ 2022-09-20 12:50 ` Nick Clifton 2022-09-21 5:54 ` Tsukasa OI 1 sibling, 1 reply; 14+ messages in thread From: Nick Clifton @ 2022-09-20 12:50 UTC (permalink / raw) To: Tsukasa OI, Jan Beulich; +Cc: binutils Hi Tsukasa, > bfd/ChangeLog: > > * elf32-lm32.c (lm32_elf_size_dynamic_sections): Mark unused > rgot_count variable. > * elf32-nds32.c (elf32_nds32_unify_relax_group): Remove unused > count variable. > * mmo.c (mmo_scan): Mark unused lineno variable. > > binutils/ChangeLog: > > * windmc.c (write_rc): Remove unused i variable. > > gas/ChangeLog: > > * config/tc-riscv.c (riscv_ip): Remove unused argnum variable. > > ld/ChangeLog: > > * pe-dll.c (generate_reloc): Remove unused bi and page_count > variables. Patch approved - please apply. Cheers Nick ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v3 1/1] bfd, binutils, gas: Remove/mark unused variables 2022-09-20 12:50 ` Nick Clifton @ 2022-09-21 5:54 ` Tsukasa OI 2022-09-21 6:15 ` Jan Beulich 2022-09-21 9:55 ` Nick Clifton 0 siblings, 2 replies; 14+ messages in thread From: Tsukasa OI @ 2022-09-21 5:54 UTC (permalink / raw) To: Nick Clifton, Jan Beulich; +Cc: binutils On 2022/09/20 21:50, Nick Clifton wrote: > Hi Tsukasa, > >> bfd/ChangeLog: >> >> * elf32-lm32.c (lm32_elf_size_dynamic_sections): Mark unused >> rgot_count variable. >> * elf32-nds32.c (elf32_nds32_unify_relax_group): Remove unused >> count variable. >> * mmo.c (mmo_scan): Mark unused lineno variable. >> >> binutils/ChangeLog: >> >> * windmc.c (write_rc): Remove unused i variable. >> >> gas/ChangeLog: >> >> * config/tc-riscv.c (riscv_ip): Remove unused argnum variable. >> >> ld/ChangeLog: >> >> * pe-dll.c (generate_reloc): Remove unused bi and page_count >> variables. > > Patch approved - please apply. > > Cheers > Nick > Nick and Jan, I sincerely apologize that I thought previous "okay" mail from Jan, a maintainer: <https://sourceware.org/pipermail/binutils/2022-September/122890.html> as an "approval" and applied this patch already. I will not merge the patch again unless the word "approve" is used explicitly. I am really sorry. Regards, Tsukasa ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v3 1/1] bfd, binutils, gas: Remove/mark unused variables 2022-09-21 5:54 ` Tsukasa OI @ 2022-09-21 6:15 ` Jan Beulich 2022-09-21 9:55 ` Nick Clifton 1 sibling, 0 replies; 14+ messages in thread From: Jan Beulich @ 2022-09-21 6:15 UTC (permalink / raw) To: Tsukasa OI; +Cc: binutils, Nick Clifton On 21.09.2022 07:54, Tsukasa OI wrote: > On 2022/09/20 21:50, Nick Clifton wrote: >> Hi Tsukasa, >> >>> bfd/ChangeLog: >>> >>> * elf32-lm32.c (lm32_elf_size_dynamic_sections): Mark unused >>> rgot_count variable. >>> * elf32-nds32.c (elf32_nds32_unify_relax_group): Remove unused >>> count variable. >>> * mmo.c (mmo_scan): Mark unused lineno variable. >>> >>> binutils/ChangeLog: >>> >>> * windmc.c (write_rc): Remove unused i variable. >>> >>> gas/ChangeLog: >>> >>> * config/tc-riscv.c (riscv_ip): Remove unused argnum variable. >>> >>> ld/ChangeLog: >>> >>> * pe-dll.c (generate_reloc): Remove unused bi and page_count >>> variables. >> >> Patch approved - please apply. >> >> Cheers >> Nick >> > > Nick and Jan, > > I sincerely apologize that I thought previous "okay" mail from Jan, a > maintainer: > <https://sourceware.org/pipermail/binutils/2022-September/122890.html> > as an "approval" and applied this patch already. No, you were right in doing so and - Nick, please correct me if I'm wrong - I might guess that Nick simply overlooked that I did give an okay already. > I will not merge the patch again unless the word "approve" is used > explicitly. I am really sorry. Hence also no need for this. Jan ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v3 1/1] bfd, binutils, gas: Remove/mark unused variables 2022-09-21 5:54 ` Tsukasa OI 2022-09-21 6:15 ` Jan Beulich @ 2022-09-21 9:55 ` Nick Clifton 1 sibling, 0 replies; 14+ messages in thread From: Nick Clifton @ 2022-09-21 9:55 UTC (permalink / raw) To: Tsukasa OI, Jan Beulich; +Cc: binutils Hi Tsukasa, > Nick and Jan, > > I sincerely apologize that I thought previous "okay" mail from Jan, a > maintainer: > <https://sourceware.org/pipermail/binutils/2022-September/122890.html> > as an "approval" and applied this patch already. > > I will not merge the patch again unless the word "approve" is used > explicitly. I am really sorry. No - you were correct. Jan's "okay" was an approval. And I should have noticed that and not sent my "approved" email, so I apologise for the confusion. Cheers Nick ^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2022-09-21 9:55 UTC | newest] Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-09-15 3:09 [PATCH 0/1] bfd, binutils, gas: Mark unused variables Tsukasa OI 2022-09-15 3:09 ` [PATCH 1/1] " Tsukasa OI 2022-09-15 4:17 ` [PATCH 0/1] " Tsukasa OI 2022-09-15 4:17 ` [PATCH 1/1] " Tsukasa OI 2022-09-15 7:29 ` Jan Beulich 2022-09-15 8:25 ` Tsukasa OI 2022-09-15 23:10 ` Hans-Peter Nilsson 2022-09-15 12:46 ` [PATCH v3 0/1] bfd, binutils, gas: Remove/mark " Tsukasa OI 2022-09-15 12:46 ` [PATCH v3 1/1] " Tsukasa OI 2022-09-15 12:58 ` Jan Beulich 2022-09-20 12:50 ` Nick Clifton 2022-09-21 5:54 ` Tsukasa OI 2022-09-21 6:15 ` Jan Beulich 2022-09-21 9:55 ` Nick Clifton
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).