Date: Thu, 13 Nov 2008 00:14:56 -0800 From: Jeremy Chadwick <koitsu@FreeBSD.org> To: Markus Hoenicka <markus.hoenicka@mhoenicka.de> Cc: freebsd-questions@FreeBSD.org Subject: Re: dlsym can't use handle returned by dlopen? Message-ID: <20081113081456.GA14564@icarus.home.lan> In-Reply-To: <20081113090021.less3h5iwwsgwsg4@webmail.df.eu> References: <18715.28127.306511.577084@yeti.mininet> <20081113042912.GA10018@icarus.home.lan> <20081113090021.less3h5iwwsgwsg4@webmail.df.eu>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Nov 13, 2008 at 09:00:21AM +0100, Markus Hoenicka wrote: > Quoting Jeremy Chadwick <koitsu@FreeBSD.org>: > >> I know that the .so's you're loading with dlopen() need to be built a >> specific way/with certain arguments, otherwise they won't work (I >> believe what I saw was dlsym() returning NULL). My symbol names were >> getting stomped on, and there was a compiler flag that addressed that. > > Is that a BSD-specific problem? As mentioned previously, I don't run > into trouble on other platforms. Is there any documentation available > which tells me how to build a dlopen()'able object in a portable way? I wouldn't classify is as a problem in any way, and I cannot imagine it's specific to BSD; I'm much more inclined to believe it's specific to gcc. When I looked at the resulting symbol names using nm or objdump, certain characters were prepended to them. There's a gcc or ld flag which disables this behaviour. I'll have to dig around to remind myself what it is. Once I read about it, it made perfect sense. Again, if you want me to write some code and provide some output of what I'm talking about, I can do so. >>> function_pointer = dlsym(RTLD_DEFAULT, "function_name"); >>> >>> Why is that? Or rather: what am I doing wrong? >> >> This code right here is *completely* wrong. RTLD_DEFAULT is a mode bit >> for dlopen(). I'm willing to bet a strict set of warnings would > > Citing the FreeBSD dlsym(3) man page: > > "If dlsym is called with the special handle RTLD_DEFAULT, the search > for the symbol follows the algorithm used for resolving undefined symbols > when objects are loaded." > > You probably had RTLD_LAZY and RTLD_NOW in mind which are dlopen() > flags. BTW RTLD_NEXT works just as well instead of RTLD_DEFAULT. You are right -- I missed that part of the man page, and I was most definitely thinking of RTLD_LAZY and RTLD_NOW. I cannot explain the behaviour using dlsym(RTLD_DEFAULT, ...). -- | Jeremy Chadwick jdc at parodius.com | | Parodius Networking http://www.parodius.com/ | | UNIX Systems Administrator Mountain View, CA, USA | | Making life hard for others since 1977. PGP: 4BD6C0CB |
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20081113081456.GA14564>