This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: ld/2218: Weak undefined symbol doesn't work properly with PIE


On Mon, Feb 20, 2006 at 12:09:10PM -0800, H. J. Lu wrote:
> On Tue, Feb 21, 2006 at 11:24:24AM +1030, Alan Modra wrote:
> > On Sun, Feb 19, 2006 at 07:31:58PM -0800, H. J. Lu wrote:
> > > On Tue, Feb 21, 2006 at 10:35:47AM +1030, Alan Modra wrote:
> > > > On Sun, Feb 19, 2006 at 06:10:01PM -0800, H. J. Lu wrote:
> > > > > Do you have a patch for ia64?
> > > > 
> > > > Nope.  I was leaving that to you.
> > > 
> > > I don't understand why we should do the same thing over and over in
> > > so many backends. A target hook should reduce the code duplication if
> > > a few targets want to do it differently.
> > 
> > Show me the code.  I will not approve a target hook that does worse than
> > a backend implementation.  ie. that makes symbols dynamic unnecessarily.
> > 
> 
> I am checking this patch to test weak undefined data. I will
> fix ia64 backend.
> 
> 

Due to the complexity of ia64 backend, it is better to handle weak
undefined symbol in _bfd_elf_fix_symbol_flags for ia64.


H.J.
----
2006-02-20  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/2218
	* elf-bfd.h (elf_backend_data): Add elf_backend_fixup_symbol.
	(_bfd_elf_link_hash_fixup_symbol): New.

	* elflink.c (_bfd_elf_link_hash_fixup_symbol): New.
	(_bfd_elf_fix_symbol_flags): Call elf_backend_fixup_symbol if
	it isn't NULL.

	* elfxx-ia64.c (elf_backend_fixup_symbol): Defined.

	* elfxx-target.h (elf_backend_fixup_symbol): New.
	(elfNN_bed): Initialize elf_backend_fixup_symbol.

--- bfd/elf-bfd.h.ia64	2006-01-20 08:53:55.000000000 -0800
+++ bfd/elf-bfd.h	2006-02-20 18:06:49.000000000 -0800
@@ -883,6 +883,11 @@ struct elf_backend_data
   void (*elf_backend_hide_symbol)
     (struct bfd_link_info *, struct elf_link_hash_entry *, bfd_boolean);
 
+  /* A function to do additional symbol fixup, called by
+     _bfd_elf_fix_symbol_flags.  */
+  bfd_boolean (*elf_backend_fixup_symbol)
+    (struct bfd_link_info *, struct elf_link_hash_entry *);
+
   /* Merge the backend specific symbol attribute.  */
   void (*elf_backend_merge_symbol_attribute)
     (struct elf_link_hash_entry *, const Elf_Internal_Sym *, bfd_boolean,
@@ -1476,6 +1481,8 @@ extern void _bfd_elf_link_hash_copy_indi
    struct elf_link_hash_entry *);
 extern void _bfd_elf_link_hash_hide_symbol
   (struct bfd_link_info *, struct elf_link_hash_entry *, bfd_boolean);
+extern bfd_boolean _bfd_elf_link_hash_fixup_symbol
+  (struct bfd_link_info *, struct elf_link_hash_entry *);
 extern bfd_boolean _bfd_elf_link_hash_table_init
   (struct elf_link_hash_table *, bfd *,
    struct bfd_hash_entry *(*)
--- bfd/elflink.c.ia64	2006-02-20 10:40:52.000000000 -0800
+++ bfd/elflink.c	2006-02-20 18:07:31.000000000 -0800
@@ -2187,6 +2187,20 @@ _bfd_elf_link_output_relocs (bfd *output
   return TRUE;
 }
 
+/* Make weak undefined symbols in PIE dynamic.  */
+
+bfd_boolean
+_bfd_elf_link_hash_fixup_symbol (struct bfd_link_info *info,
+				 struct elf_link_hash_entry *h)
+{
+  if (info->pie
+      && h->dynindx == -1
+      && h->root.type == bfd_link_hash_undefweak)
+    return bfd_elf_link_record_dynamic_symbol (info, h);
+
+  return TRUE;
+}
+
 /* Fix up the flags for a symbol.  This handles various cases which
    can only be fixed after all the input files are seen.  This is
    currently called by both adjust_dynamic_symbol and
@@ -2197,6 +2211,8 @@ bfd_boolean
 _bfd_elf_fix_symbol_flags (struct elf_link_hash_entry *h,
 			   struct elf_info_failed *eif)
 {
+  const struct elf_backend_data *bed = NULL;
+
   /* If this symbol was mentioned in a non-ELF file, try to set
      DEF_REGULAR and REF_REGULAR correctly.  This is the only way to
      permit a non-ELF file to correctly refer to a symbol defined in
@@ -2255,6 +2271,15 @@ _bfd_elf_fix_symbol_flags (struct elf_li
 	h->def_regular = 1;
     }
 
+  /* Backend specific symbol fixup.  */
+  if (elf_hash_table (eif->info)->dynobj)
+    {
+      bed = get_elf_backend_data (elf_hash_table (eif->info)->dynobj);
+      if (bed->elf_backend_fixup_symbol
+	  && !(*bed->elf_backend_fixup_symbol) (eif->info, h))
+	return FALSE;
+    }
+
   /* If this is a final link, and the symbol was defined as a common
      symbol in a regular object file, and there was no definition in
      any dynamic object, then the linker will have allocated space for
@@ -2280,11 +2305,8 @@ _bfd_elf_fix_symbol_flags (struct elf_li
 	  || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
       && h->def_regular)
     {
-      const struct elf_backend_data *bed;
       bfd_boolean force_local;
 
-      bed = get_elf_backend_data (elf_hash_table (eif->info)->dynobj);
-
       force_local = (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
 		     || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN);
       (*bed->elf_backend_hide_symbol) (eif->info, h, force_local);
@@ -2323,12 +2345,8 @@ _bfd_elf_fix_symbol_flags (struct elf_li
       if (weakdef->def_regular)
 	h->u.weakdef = NULL;
       else
-	{
-	  const struct elf_backend_data *bed;
-
-	  bed = get_elf_backend_data (elf_hash_table (eif->info)->dynobj);
-	  (*bed->elf_backend_copy_indirect_symbol) (eif->info, weakdef, h);
-	}
+	(*bed->elf_backend_copy_indirect_symbol) (eif->info, weakdef,
+						  h);
     }
 
   return TRUE;
--- bfd/elfxx-ia64.c.ia64	2006-02-06 13:58:53.000000000 -0800
+++ bfd/elfxx-ia64.c	2006-02-20 18:09:25.000000000 -0800
@@ -5305,6 +5305,7 @@ elfNN_hpux_backend_symbol_processing (bf
 #define elf_backend_want_dynbss		0
 #define elf_backend_copy_indirect_symbol elfNN_ia64_hash_copy_indirect
 #define elf_backend_hide_symbol		elfNN_ia64_hash_hide_symbol
+#define elf_backend_fixup_symbol	_bfd_elf_link_hash_fixup_symbol
 #define elf_backend_reloc_type_class	elfNN_ia64_reloc_type_class
 #define elf_backend_rela_normal		1
 #define elf_backend_special_sections	elfNN_ia64_special_sections
--- bfd/elfxx-target.h.ia64	2006-01-20 08:53:57.000000000 -0800
+++ bfd/elfxx-target.h	2006-02-20 17:58:20.000000000 -0800
@@ -420,6 +420,9 @@
 #ifndef elf_backend_hide_symbol
 #define elf_backend_hide_symbol		_bfd_elf_link_hash_hide_symbol
 #endif
+#ifndef elf_backend_fixup_symbol
+#define elf_backend_fixup_symbol		NULL	
+#endif
 #ifndef elf_backend_merge_symbol_attribute
 #define elf_backend_merge_symbol_attribute	NULL
 #endif
@@ -598,6 +601,7 @@ static const struct elf_backend_data elf
   elf_backend_output_arch_syms,
   elf_backend_copy_indirect_symbol,
   elf_backend_hide_symbol,
+  elf_backend_fixup_symbol,
   elf_backend_merge_symbol_attribute,
   elf_backend_ignore_undef_symbol,
   elf_backend_emit_relocs,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]