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 Fri, Feb 17, 2006 at 05:15:06PM +1030, Alan Modra wrote:
> On Thu, Feb 16, 2006 at 10:14:31PM -0800, H. J. Lu wrote:
> > On Fri, Feb 17, 2006 at 03:24:13PM +1030, Alan Modra wrote:
> > > You didn't answer my question.  I asked why you were patching that
> > > particular place to fix undefined weak symbols in PIEs.  See the patch
> > > I've just committed for powerpc64.
> > 
> > It is a generic ELF problem. Why does each backend have to handle it
> > separately?
> 
> Well, if you are clever you might be able to make a generic patch that
> handles undef weak in pie.  The right place to do it is after all
> symbols have been loaded.
> 

Thanks for the pointer. Here is the updated patch.


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

	PR ld/2218
	* elflink.c (_bfd_elf_fix_symbol_flags): Make weak undefined
	symbols in PIE dynamic.
	(elf_link_output_extsym): Mark a symbol in PIE hidden if
	it isn't defined in nor referenced by any dynamic object.

--- bfd/elflink.c.pie	2006-02-15 14:02:41.000000000 -0800
+++ bfd/elflink.c	2006-02-17 06:42:26.000000000 -0800
@@ -2255,6 +2255,16 @@ _bfd_elf_fix_symbol_flags (struct elf_li
 	h->def_regular = 1;
     }
 
+  /* Weak undefined symbols in PIE have to be dynamic.  */
+  if (eif->info->pie
+      && h->dynindx == -1
+      && h->root.type == bfd_link_hash_undefweak
+      && ! bfd_elf_link_record_dynamic_symbol (eif->info, h))
+    {
+      eif->failed = TRUE;
+      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
@@ -6443,6 +6453,15 @@ elf_link_output_extsym (struct elf_link_
   else
     sym.st_info = ELF_ST_INFO (STB_GLOBAL, h->type);
 
+  /* If we don't export all symbols into the dynamic symbol table, a
+     symbol in PIE, which isn't defined in nor referenced by any
+     dynamic object, has the hidden visibility.  */
+  if (finfo->info->pie
+      && !finfo->info->export_dynamic
+      && !h->def_dynamic
+      && !h->ref_dynamic)
+    sym.st_other = STV_HIDDEN | (h->other & ~ ELF_ST_VISIBILITY (-1));
+
   switch (h->root.type)
     {
     default:


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