Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 27 Dec 1998 11:15:21 -0500
From:      "Kaleb S. KEITHLEY" <kaleb@ics.com>
To:        hackers@FreeBSD.ORG, bug-gnu-utils@gnu.org
Subject:   ld (bfd): wrong function names for ELF shared library DT_{INIT,FINI}
Message-ID:  <36865D18.1CFBAE39@ics.com>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.

--------------ABD322CFF6D5DF3F54BC7E
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

The ELF specification says that the names of the DT_{INIT,FINI}
functions in shared libraries are named .init() and .fini(), not _init()
and _fini().

Perhaps someone thought this it would be more convenient to use _init()
and _fini() instead of the correct names because C and C++ don't allow a
leading '.' in tokens, and I agree that compiling to assembly, passing
sed over the assembly, and then running the assembler to generate a .o
file with the right function names is a bit more work; but it's not that
onerous, especially when you automate it in a Makefile.

There are four reasons that I can think of to use the right names: 

1) following the published spec is just the right thing to do.

2) someone might expect to find the functions by their spec'd names.

3) using the '_' prefix intrudes on the library's normal reserved
namespace. If I didn't know better I might wonder why my library
function named _init() was being called at the wrong time and more than
once.

4) it simplifies third party software development by allowing reuse of
generic rulesets rather than have to invent separate rulesets for
systems like Linux, *BSD, or other systems that have replaced the system
tools with the GNU tools.

See the print editions of the System V ABI (where ELF is defined) or 
http://www.sco.com/developer/gabi/ch4.sheader.html#special_sections for
more information.

For convenience, I've attached a small patch that fixes ld to look for
the functions by the proper specified names.

--
Kaleb

--------------ABD322CFF6D5DF3F54BC7E
Content-Type: text/plain; charset=us-ascii; name="ld.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="ld.patch"

*** binutils-2.9.1/bfd/elflink.h.orig	Sun Dec 27 08:21:32 1998
--- binutils-2.9.1/bfd/elflink.h	Sun Dec 27 08:53:38 1998
***************
*** 2335,2341 ****
        /* Add some entries to the .dynamic section.  We fill in some of the
  	 values later, in elf_bfd_final_link, but we must add the entries
  	 now so that we know the final size of the .dynamic section.  */
!       h =  elf_link_hash_lookup (elf_hash_table (info), "_init", false,
  				false, false);
        if (h != NULL
  	  && (h->elf_link_hash_flags & (ELF_LINK_HASH_REF_REGULAR
--- 2335,2341 ----
        /* Add some entries to the .dynamic section.  We fill in some of the
  	 values later, in elf_bfd_final_link, but we must add the entries
  	 now so that we know the final size of the .dynamic section.  */
!       h =  elf_link_hash_lookup (elf_hash_table (info), ".init", false,
  				false, false);
        if (h != NULL
  	  && (h->elf_link_hash_flags & (ELF_LINK_HASH_REF_REGULAR
***************
*** 2344,2350 ****
  	  if (! elf_add_dynamic_entry (info, DT_INIT, 0))
  	    return false;
  	}
!       h =  elf_link_hash_lookup (elf_hash_table (info), "_fini", false,
  				 false, false);
        if (h != NULL
  	  && (h->elf_link_hash_flags & (ELF_LINK_HASH_REF_REGULAR
--- 2344,2350 ----
  	  if (! elf_add_dynamic_entry (info, DT_INIT, 0))
  	    return false;
  	}
!       h =  elf_link_hash_lookup (elf_hash_table (info), ".fini", false,
  				 false, false);
        if (h != NULL
  	  && (h->elf_link_hash_flags & (ELF_LINK_HASH_REF_REGULAR
***************
*** 3900,3909 ****
                   magic _init and _fini symbols.  This is pretty ugly,
                   but we are compatible.  */
  	    case DT_INIT:
! 	      name = "_init";
  	      goto get_sym;
  	    case DT_FINI:
! 	      name = "_fini";
  	    get_sym:
  	      {
  		struct elf_link_hash_entry *h;
--- 3900,3909 ----
                   magic _init and _fini symbols.  This is pretty ugly,
                   but we are compatible.  */
  	    case DT_INIT:
! 	      name = ".init";
  	      goto get_sym;
  	    case DT_FINI:
! 	      name = ".fini";
  	    get_sym:
  	      {
  		struct elf_link_hash_entry *h;

--------------ABD322CFF6D5DF3F54BC7E--


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?36865D18.1CFBAE39>