This is the mail archive of the binutils@sourceware.cygnus.com 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]

Question about ELF linker semantics



When confronted with the following situation:

  o environ is a weak symbol, equivalent to _environ
  o _environ is defined in libc.so
  o _environ is referenced in crt1.o

the IRIX6 linker does not emit an entry for "environ" in the dynamic
symbol table in the main executable.  However, the GNU linker wants to
do so:

The reason is this code in elflink.h:elf_adjust_dynamic_symbol. If
this test holds, we bail and do not create a dynamic symbol table
entry.  However, it does not hold in this case because
`h->weakdef->dynindx' is not -1.  It probably doesn't matter, but I'm
curious as to what the GNU linker logic is supposed to be doing here?

There's an extended comment below this code that is perhaps trying to
explain the situation, but I couldn't make my (perhaps flawed)
understanding of that comment apply to this issue.

  /* If this symbol does not require a PLT entry, and it is not
     defined by a dynamic object, or is not referenced by a regular
     object, ignore it.  We do have to handle a weak defined symbol,
     even if no regular object refers to it, if we decided to add it
     to the dynamic symbol table.  FIXME: Do we normally need to worry
     about symbols which are defined by one dynamic object and
     referenced by another one?  */
  if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) == 0
      && ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
	  || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
	  || ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0
	      && (h->weakdef == NULL || h->weakdef->dynindx == -1))))
    {
      h->plt.offset = (bfd_vma) -1;
      return true;
    }


--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

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