PATCH: ld/2218: Weak undefined symbol doesn't work properly with PIE
H. J. Lu
hjl@lucon.org
Sat Feb 18 16:01:00 GMT 2006
On Fri, Feb 17, 2006 at 06:46:56AM -0800, H. J. Lu wrote:
> 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.
>
>
I added the h->ref_regular check. It may not be strictly necessary
since it isn't easy to generate an unreferenced weak undefined
symbol :-(.
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-17 07:39:52.000000000 -0800
+++ bfd/elflink.c 2006-02-17 07:44:40.000000000 -0800
@@ -2255,6 +2255,17 @@ _bfd_elf_fix_symbol_flags (struct elf_li
h->def_regular = 1;
}
+ /* A referenced weak undefined symbol in PIE has to be dynamic. */
+ if (eif->info->pie
+ && h->dynindx == -1
+ && h->ref_regular
+ && 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 +6454,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:
More information about the Binutils
mailing list