From owner-freebsd-current@FreeBSD.ORG Tue Nov 25 18:49:36 2003 Return-Path: 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 C611E16A4CE for ; Tue, 25 Nov 2003 18:49:36 -0800 (PST) Received: from ns1.xcllnt.net (209-128-86-226.bayarea.net [209.128.86.226]) by mx1.FreeBSD.org (Postfix) with ESMTP id C080343FB1 for ; Tue, 25 Nov 2003 18:49:34 -0800 (PST) (envelope-from marcel@xcllnt.net) Received: from dhcp01.pn.xcllnt.net (dhcp01.pn.xcllnt.net [192.168.4.201]) by ns1.xcllnt.net (8.12.9/8.12.9) with ESMTP id hAQ2nYEG039846; Tue, 25 Nov 2003 18:49:34 -0800 (PST) (envelope-from marcel@piii.pn.xcllnt.net) Received: from dhcp01.pn.xcllnt.net (localhost [127.0.0.1]) hAQ2nXWx007798; Tue, 25 Nov 2003 18:49:33 -0800 (PST) (envelope-from marcel@dhcp01.pn.xcllnt.net) Received: (from marcel@localhost) by dhcp01.pn.xcllnt.net (8.12.10/8.12.10/Submit) id hAQ2nWmc007797; Tue, 25 Nov 2003 18:49:32 -0800 (PST) (envelope-from marcel) Date: Tue, 25 Nov 2003 18:49:28 -0800 From: Marcel Moolenaar To: Terry Lambert Message-ID: <20031126024927.GA7743@dhcp01.pn.xcllnt.net> References: <3FC40572.142D4334@mindspring.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3FC40572.142D4334@mindspring.com> User-Agent: Mutt/1.5.4i cc: "E.B. Dreger" cc: current@freebsd.org Subject: Re: rtld + static linking X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Nov 2003 02:49:36 -0000 On Tue, Nov 25, 2003 at 05:44:18PM -0800, Terry Lambert wrote: > "E.B. Dreger" wrote: > > After watching the recent shared/dynamic threads, and reading the > > archives from five or six years ago, I have a question... > > > > Dynamic linking works by the kernel running the dynamic linker, > > which loads shared objects and fixes the symbol tables, yes? > > No. > > Dynamic linking works because the crt0 mmap's the /usr/libexec/ld.so > file as executable, and then points known stub offsets into it. No. Dynamic linking works because the kernel loads and runs the dynamic linker when it sees that the executable defines an interpeter. > > Is there some reason that a statically-linked program couldn't > > include some "ld-elf.a" type of intelligence? Would that be > > necessary and sufficient to allow statically-linked programs to > > load shared objects? > > Yes, and yes. No, and no. A complete executable (i.e. staticly linked) does not export any symbols, or at least not in the same way a shared executable and shared libraries do. If I try to dynamicly link libbar into a complete executable foo and libbar depends on libc, then there's no guarantee that all the required bits from libc are in foo, nor is there any guarantee that the bits are actually visible or even accessable (no linkage table). Dynamicly loading libc for use by libbar can work, but it's not guaranteed. One failure mode is suddenly having two instances of a common variable instead of one. Another is the clobbering of data caused reinitializations. So, the problem of dynamic linking a shared library into a static process is non-trivial and probably cannot be solved genericly. Under restricted and controlled conditions you can make it work. I would call it the ability to have plugins, not the ability to load dynamic libraries. -- Marcel Moolenaar USPA: A-39004 marcel@xcllnt.net