From owner-freebsd-hackers Mon Aug 18 08:27:41 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id IAA27857 for hackers-outgoing; Mon, 18 Aug 1997 08:27:41 -0700 (PDT) Received: from time.cdrom.com (root@time.cdrom.com [204.216.27.226]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id IAA27851; Mon, 18 Aug 1997 08:27:36 -0700 (PDT) Received: from time.cdrom.com (jkh@localhost.cdrom.com [127.0.0.1]) by time.cdrom.com (8.8.6/8.6.9) with SMTP id IAA20005; Mon, 18 Aug 1997 08:27:47 -0700 (PDT) Message-ID: <33F869F3.446B9B3D@FreeBSD.org> Date: Mon, 18 Aug 1997 08:27:47 -0700 From: "Jordan K. Hubbard" Organization: Walnut Creek CDROM X-Mailer: Mozilla 3.01 (X11; I; FreeBSD 2.2-STABLE i386) MIME-Version: 1.0 To: hackers@FreeBSD.ORG Subject: [Fwd: Re: Please Help Me Understand dlopen()] Content-Type: multipart/mixed; boundary="------------59E2B60015FB7483794BDF32" Sender: owner-freebsd-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk This is a multi-part message in MIME format. --------------59E2B60015FB7483794BDF32 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hmmm - any comments, ld hackers? Jordan -- --------------59E2B60015FB7483794BDF32 Content-Type: message/news Content-Transfer-Encoding: 7bit Content-Disposition: inline Path: nntp2.ba.best.com!news1.best.com!nntprelay.mathworks.com!news.mathworks.com!fu-berlin.de!informatik.tu-muenchen.de!news From: Walter Hafner Newsgroups: comp.unix.bsd.freebsd.misc Subject: Re: Please Help Me Understand dlopen() Date: 18 Aug 1997 14:39:35 +0200 Organization: Technische Universitaet Muenchen, Germany Distribution: world Message-ID: References: <5stu4v$aio$1@vixen.cso.uiuc.edu> <33F29838.59E2B600@FreeBSD.org> <5svjcd$209@tooting.netapp.com> NNTP-Posting-Host: pccog4.forwiss.tu-muenchen.de X-Newsreader: Gnus v5.2.25/XEmacs 19.14 Xref: nntp2.ba.best.com comp.unix.bsd.freebsd.misc:48935 guy@netapp.com (Guy Harris) writes: > Jordan K. Hubbard wrote: > >2. You need to look for _hello rather than hello or you won't be able to > >find the symbol. > > That's a significant deficiency: > > 1) not all UNIX C compilers prepend an underscore to symbols (I > think it was originally done to work around the PDP-11 UNIX > assembler having symbols with the names of the registers and > opssibly the opcodes), so if you can't, in some UNIXes, do > > dlsym(handle, "hello") > > to find a pointer to the function "hello" in a > dynamically-loaded object, that makes it impossible to use > "dlsym()" portably - SunOS 5.5.1, which expects C compilers > not to prepend underscores and which supports "dlopen()", > will *not* remove the prepended underscore if the lookup > fails (i.e., the lookup of "_hello" will fail to find a > function "hello()"); > > 2) it's somewhat counterintuitive, as indicated by the fact that > Mr. Murphy didn't know he had to do it; > > 3) at least one of the UNIXes whose C compiler *does* prepend an > underscore and that supports "-ldl", namely SunOS 4.1[.x], > will, if a "dlsym()" lookup fails, retry the lookup with a > prepended underscore, it appears. > > The run-time linker should be changed to do what the SunOS 4.1[.x] > run-time linker does, allowing you to look for "hello" to find a > function "hello()". Hi! I bragged about just the same behaviour about 4 weeks ago. :-) The freeBSD dlsym() is - as far as I know - the only dlsym() implementation that doesn't search for _funktion() ... I also complained about dlopen() not searching LD_LIBRARY_PATH. One answer I got was the suggestion to implement it in the FreeBSD dl routines myself. Well, I could do it but that would be my first try on system programming ever. And I think it would significantly lower the high FreeBSD standards on code quality. :-) Instead I patched the dl code in our application. Our application ("HALCON") runs on Solaris, SunOS, HP/UX, IRIX, AIX, Ultrix, DEC Unix (OSF/1), Linux, FreeBSD, ... you name it. And now there is a very ugly "#ifdef __FreeBSD__" in the dl code. All other platforms show the expected behaviour. :-( -Walter -- Walter Hafner_____________________________ hafner@forwiss.tu-muenchen.de *CLICK* The best observation I can make is that the BSD Daemon logo is _much_ cooler than that Penguin :-) (Donald Whiteside) --------------59E2B60015FB7483794BDF32--