bogus elf32-sh-symbian.c code

Alan Modra amodra@gmail.com
Sat Mar 23 10:23:00 GMT 2013


I was looking at changing the interface to _bfd_elf_merge_symbol
yesterday, and noticed it wasn't static.  Odd, I thought, why would
any target need to use this particular function?  On looking, I see
elf32-sh-symbian.c uses it, and it's being called on a new symbol, so
there isn't anything to merge!  In fact, at the time this code was
contributed, bfd_elf_link_mark_dynamic_symbol didn't exist and
_bfd_elf_merge_symbol did nothing except create the new symbol.
Except that it isn't really supposed to create new symbols all by
itself, and misses setting up a few things, in this case u.undef.abfd.
The  correct function to call is _bfd_generic_link_add_one_symbol.

I have no idea why the following code was there.
-	      /* Allow the symbol to become local if necessary.  */
-	      if (new_hash->dynindx == -1)
-		new_hash->def_regular = 1;
dynindx will always be -1 as it's a new symbol, thus the test was
redundant.  Also it is quite odd to set def_regular on a
bfd_link_hash_undefined sym, so I've removed it.  Nick, do you recall
anything about this code?

	* elf-bfd.h (_bfd_elf_merge_symbol): Delete declaration.
	* elflink.c (_bfd_elf_merge_symbol): Make static.
	* elf32-sh-symbian.c (sh_symbian_relocate_section): Don't call
	_bfd_elf_merge_symbol, call _bfd_generic_link_add_one_symbol.

Index: bfd/elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.366
diff -u -p -r1.366 elf-bfd.h
--- bfd/elf-bfd.h	8 Mar 2013 17:13:30 -0000	1.366
+++ bfd/elf-bfd.h	23 Mar 2013 07:46:48 -0000
@@ -1993,12 +1993,6 @@ extern bfd_boolean _bfd_elf_eh_frame_pre
 extern bfd_boolean _bfd_elf_maybe_strip_eh_frame_hdr
   (struct bfd_link_info *);
 
-extern bfd_boolean _bfd_elf_merge_symbol
-  (bfd *, struct bfd_link_info *, const char *, Elf_Internal_Sym *,
-   asection **, bfd_vma *, bfd_boolean *, unsigned int *,
-   struct elf_link_hash_entry **, bfd_boolean *,
-   bfd_boolean *, bfd_boolean *, bfd_boolean *);
-
 extern bfd_boolean _bfd_elf_hash_symbol (struct elf_link_hash_entry *);
 
 extern long _bfd_elf_link_lookup_local_dynindx
Index: bfd/elf32-sh-symbian.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-sh-symbian.c,v
retrieving revision 1.17
diff -u -p -r1.17 elf32-sh-symbian.c
--- bfd/elf32-sh-symbian.c	10 Jan 2013 20:03:53 -0000	1.17
+++ bfd/elf32-sh-symbian.c	23 Mar 2013 07:46:48 -0000
@@ -470,51 +470,36 @@ sh_symbian_relocate_section (bfd *      
 	      continue;
 	    }
 
-	  new_hash = elf_link_hash_lookup (hash_table, ptr->new_name, FALSE, FALSE, TRUE);
-
+	  new_hash = elf_link_hash_lookup (hash_table, ptr->new_name,
+					   FALSE, FALSE, TRUE);
 	  /* If we could not find the symbol then it is a new, undefined symbol.
 	     Symbian want this behaviour - ie they want to be able to rename the
 	     reference in a reloc from one undefined symbol to another, new and
 	     undefined symbol.  So we create that symbol here.  */
 	  if (new_hash == NULL)
 	    {
-	      asection *                     psec = bfd_und_section_ptr;
-	      Elf_Internal_Sym               new_sym;
-	      bfd_vma                        new_value = 0;
-	      bfd_boolean                    skip;
-	      bfd_boolean                    override;
-	      bfd_boolean                    type_change_ok;
-	      bfd_boolean                    size_change_ok;
-
-	      new_sym.st_value = 0;
-	      new_sym.st_size  = 0;
-	      new_sym.st_name  = -1;
-	      new_sym.st_info  = ELF_ST_INFO (STB_GLOBAL, STT_FUNC);
-	      new_sym.st_other = ELF_ST_VISIBILITY (STV_DEFAULT);
-	      new_sym.st_shndx = SHN_UNDEF;
-	      new_sym.st_target_internal = 0;
-
-	      if (! _bfd_elf_merge_symbol (input_bfd, info,
-					   ptr->new_name, & new_sym,
-					   & psec, & new_value, NULL,
-					   NULL, & new_hash, & skip,
-					   & override, & type_change_ok,
-					   & size_change_ok))
+	      struct bfd_link_hash_entry *bh = NULL;
+	      bfd_boolean collect = get_elf_backend_data (input_bfd)->collect;
+	      if (_bfd_generic_link_add_one_symbol (info, input_bfd,
+						    ptr->new_name, BSF_GLOBAL,
+						    bfd_und_section_ptr, 0,
+						    NULL, FALSE, collect,
+						    &bh))
 		{
-		  _bfd_error_handler (_("%B: Failed to add renamed symbol %s"),
-				      input_bfd, ptr->new_name);
-		  continue;
-		}
-	      /* XXX - should we check psec, skip, override etc ?  */
+		  new_hash = (struct elf_link_hash_entry *) bh;
+		  new_hash->type = STT_FUNC;
+		  new_hash->non_elf = 0;
 
-	      new_hash->root.type = bfd_link_hash_undefined;
-
-	      /* Allow the symbol to become local if necessary.  */
-	      if (new_hash->dynindx == -1)
-		new_hash->def_regular = 1;
+		  if (SYMBIAN_DEBUG)
+		    fprintf (stderr, "Created new symbol %s\n", ptr->new_name);
+		}
+	    }
 
-	      if (SYMBIAN_DEBUG)
-		fprintf (stderr, "Created new symbol %s\n", ptr->new_name);
+	  if (new_hash == NULL)
+	    {
+	      _bfd_error_handler (_("%B: Failed to add renamed symbol %s"),
+				  input_bfd, ptr->new_name);
+	      continue;
 	    }
 
 	  /* Convert the new_hash value into a index into the table of symbol hashes.  */
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.476
diff -u -p -r1.476 elflink.c
--- bfd/elflink.c	22 Mar 2013 23:35:55 -0000	1.476
+++ bfd/elflink.c	23 Mar 2013 07:46:48 -0000
@@ -907,7 +907,7 @@ elf_merge_st_other (bfd *abfd, struct el
    change.  We set POLD_ALIGNMENT if an old common symbol in a dynamic
    object is overridden by a regular object.  */
 
-bfd_boolean
+static bfd_boolean
 _bfd_elf_merge_symbol (bfd *abfd,
 		       struct bfd_link_info *info,
 		       const char *name,

-- 
Alan Modra
Australia Development Lab, IBM



More information about the Binutils mailing list