From owner-freebsd-hackers Sun Dec 27 06:50:50 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id GAA29482 for freebsd-hackers-outgoing; Sun, 27 Dec 1998 06:50:50 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from ics.com (ics.com [140.186.40.192]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id GAA29477 for ; Sun, 27 Dec 1998 06:50:49 -0800 (PST) (envelope-from kaleb@ics.com) Received: from kaleb.keithley.belmont.ma.us (pmdialin3.ics.com [140.186.40.177]) by ics.com (8.9.0.Beta5/8.9.0.Beta5) with ESMTP id JAA12806; Sun, 27 Dec 1998 09:50:31 -0500 (EST) Received: from kaleb.keithley.belmont.ma.us (localhost [127.0.0.1]) by kaleb.keithley.belmont.ma.us (8.9.1/8.9.1) with SMTP id LAA11086; Sun, 27 Dec 1998 11:15:23 -0500 (EST) (envelope-from kaleb@ics.com) Message-ID: <36865D18.1CFBAE39@ics.com> Date: Sun, 27 Dec 1998 11:15:21 -0500 From: "Kaleb S. KEITHLEY" Organization: Integrated Computer Solutions X-Mailer: Mozilla 3.04Gold (X11; I; FreeBSD 3.0-RELEASE i386) MIME-Version: 1.0 To: hackers@FreeBSD.ORG, bug-gnu-utils@gnu.org Subject: ld (bfd): wrong function names for ELF shared library DT_{INIT,FINI} Content-Type: multipart/mixed; boundary="------------ABD322CFF6D5DF3F54BC7E" Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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