[RFC/PATCH] Fix `bfd_{get,set}_*' macros

Doug Evans dje@google.com
Thu May 3 13:17:00 GMT 2012

On Wed, May 2, 2012 at 9:19 PM, Sergio Durigan Junior
<sergiodj@redhat.com> wrote:
> Hi,
> As a part of an effort to enable `-Wunused-variable' on GDB build
> system, I would like to propose this "fix" to the following macros
> declared in bfd-in2.h:
>  bfd_get_section_name
>  bfd_get_section_vma
>  bfd_get_section_lma
>  bfd_get_section_alignment
>  bfd_section_name
>  bfd_section_size
>  bfd_get_section_flags
>  bfd_get_section_userdata
> Those macros don't need the first argument (`bfd'), but they still
> require it.  However, you can pass anything there and GCC won't complain
> about it, because the argument is unused after all.  So, while fixing
> GDB to support -Wunused-variable, I saw that there was a declaration of
> a `bfd *', which is used as a first argument to those macros.  GCC
> started to complain about it (unused argument).  There were two paths
> that I could follow:
> 1) Delete the declaration of `bfd *', so this:
>   bfd *abfd = objfile->abfd;
>   bfd_get_section_name (abfd, sec);
> Would become:
>   bfd_get_section_name (objfile->abfd, sec);
> or
> 2) Fix the macros, so that they use the first argument in a safe way
> like `(void) bfd', thus silencing GCC warnings.
> After having tried the first option, Pedro asked me to actually fix the
> macros, so here is the patch to do this, along with small fixes through
> the code in order to adapt it.  I am labeling this patch as RFC because
> I'm not sure I fixed the code in the right way.  It wasn't clear to me
> which `bfd' to use in each situation, so I used my best judgement (which
> may not be good).
> As you will notice, I did not changed every bfd_*_section_* macro
> because some of them are used as lvalue (left side of assignment).
> I regtested the patch on Fedora 16 x86_64 with GDB, without
> regressions.  Ok to apply?

I never liked these macros, it's like they had two "this" arguments.

How much more work would it be to actually remove the bfd argument?

More information about the Binutils mailing list