[PATCH] BFD/ELF: Correct a `remove' global shadowing error for pre-4.8 GCC

Maciej W. Rozycki macro@mips.com
Mon Jul 9 20:31:00 GMT 2018


Remove `-Wshadow' compilation errors:

cc1: warnings being treated as errors
.../bfd/elflink.c: In function 'bfd_elf_final_link':
.../bfd/elflink.c:11722: error: declaration of 'remove' shadows a global declaration
/usr/include/stdio.h:154: error: shadowed declaration is here

which for versions of GCC before 4.8 prevent support for ELF targets
from being built.  See also GCC PR c/53066.

	bfd/
	* elflink.c (bfd_elf_final_link): Rename `remove' local variable 
	to `remove_section'.
---
Hi Alan,

> Setting SEC_EXCLUDE for empty .gnu.attributes is too late in the link
> process for the linker to remove the section.  That must be done in
> bfd_elf_final_link, as we do for removed group sections.
> 
> 	* elflink.c (bfd_elf_final_link): Remove zero size .gnu.attributes
> 	sections.

 This broke building for all ELF targets with GCC 4.4.  OK to apply?

  Maciej
---
 bfd/elflink.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

binutils-bfd-elf-final-link-remove-section.diff
Index: binutils/bfd/elflink.c
===================================================================
--- binutils.orig/bfd/elflink.c	2018-07-09 18:07:03.000000000 +0100
+++ binutils/bfd/elflink.c	2018-07-09 20:43:52.665368387 +0100
@@ -11719,7 +11719,7 @@ bfd_elf_final_link (bfd *abfd, struct bf
   std_attrs_section = get_elf_backend_data (abfd)->obj_attrs_section;
   for (o = abfd->sections; o != NULL; o = o->next)
     {
-      bfd_boolean remove = FALSE;
+      bfd_boolean remove_section = FALSE;
 
       if ((std_attrs_section && strcmp (o->name, std_attrs_section) == 0)
 	  || strcmp (o->name, ".gnu.attributes") == 0)
@@ -11743,14 +11743,14 @@ bfd_elf_final_link (bfd *abfd, struct bf
 	  if (attr_size)
 	    attr_section = o;
 	  else
-	    remove = TRUE;
+	    remove_section = TRUE;
 	}
       else if ((o->flags & SEC_GROUP) != 0 && o->size == 0)
 	{
 	  /* Remove empty group section from linker output.  */
-	  remove = TRUE;
+	  remove_section = TRUE;
 	}
-      if (remove)
+      if (remove_section)
 	{
 	  o->flags |= SEC_EXCLUDE;
 	  bfd_section_list_remove (abfd, o);



More information about the Binutils mailing list