From owner-freebsd-current Fri Nov 8 16:27:13 2002 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 38A1E37B401 for ; Fri, 8 Nov 2002 16:27:11 -0800 (PST) Received: from scaup.mail.pas.earthlink.net (scaup.mail.pas.earthlink.net [207.217.120.49]) by mx1.FreeBSD.org (Postfix) with ESMTP id B814643E75 for ; Fri, 8 Nov 2002 16:27:10 -0800 (PST) (envelope-from tlambert2@mindspring.com) Received: from pool0296.cvx40-bradley.dialup.earthlink.net ([216.244.43.41] helo=mindspring.com) by scaup.mail.pas.earthlink.net with esmtp (Exim 3.33 #1) id 18AJSs-0000wE-00; Fri, 08 Nov 2002 16:27:07 -0800 Message-ID: <3DCC5609.C21E3AA0@mindspring.com> Date: Fri, 08 Nov 2002 16:25:45 -0800 From: Terry Lambert X-Mailer: Mozilla 4.79 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Daniel Eischen Cc: "M. Warner Losh" , ataraxia@cox.net, current@FreeBSD.ORG Subject: Re: [PATCH] note the __sF change in src/UPDATING References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Daniel Eischen wrote: > I'm not even close to a shared library/linker expert, but > I thought there was a way to have something run when an > object file got loaded. From rtld(1): > > After all shared libraries have been successfully loaded, ld-elf.so.1 > proceeds to resolve external references from both the main program and > all objects loaded. A mechanism is provided for initialization routines > to be called on a per-object basis, giving a shared object an opportunity > to perform any extra set-up before execution of the program proper > begins. This is useful for C++ libraries that contain static construc- > tors. > > If you put __sF in it's own file with whatever is needed for > the above, won't that work? The key to this is "on a per object basis". You only get one .init section, and if you provide your own, then the generated one is ignored and not used. This only becomes a problem when you try to use Objective C or C++ code linked against the library, but at that point, it becomes a critical problem; example: static void _dl_init(void) __attribute__((section(".init"))); static void _dl_init(void) { char *argv [2] = { "./xxx", NULL }; __do_dynamic_link( argv); } This is code from my "libdlopen" that tries to work around the problem with the argv parameter not being passed down to the dynamic linker initialization. It uses the .init section, since the constructor code is not properly called with a non-void argument, and the constructor code is c++rt0 instead of crt0, so it's not universally called (an artifact of static linking). The "which is dangerous"/"which is stupid" messages are actually ld.so hacks, or other linker hacks to do with symbol resolution, rather than compile-time things -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message