[PATCH 0/1] bfd, binutils, gas: Mark unused variables

Tsukasa OI research_trasio@irq.a4lg.com
Thu Sep 15 03:09:26 GMT 2022


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



More information about the Binutils mailing list