Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 18 Aug 1997 08:27:47 -0700
From:      "Jordan K. Hubbard" <jkh@FreeBSD.ORG>
To:        hackers@FreeBSD.ORG
Subject:   [Fwd: Re: Please Help Me Understand dlopen()]
Message-ID:  <33F869F3.446B9B3D@FreeBSD.org>

next in thread | raw e-mail | index | archive | help
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 <hafner@pccog4.forwiss.tu-muenchen.de>
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: <s9n90xz1x88.fsf@pccog4.forwiss.tu-muenchen.de>
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 <jkh@FreeBSD.org> 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
     <A href=http://www.forwiss.tu-muenchen.de/~hafner/>*CLICK*</A>;
 The best observation I can make is that the BSD Daemon logo is _much_
 cooler than that Penguin :-)                       (Donald Whiteside)

--------------59E2B60015FB7483794BDF32--




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?33F869F3.446B9B3D>