On Mon, Nov 6, 2017 at 2:37 PM, Christian Kellermann <ck...@pestilenz.org>
wrote:
>
> While porting a smalltalk VM to OpenBSD I came across this peculiar
> quirk and I don't quite understand what's going on.
>
> This VM does its FFI calls through dlopen'ing and dlsym'ing the
> symbols in question. This seems to work fine for all kinds of
> functions. However it fails with libc's "environ" symbol.
>

libc's environ symbol is only used in static links; in dynamic links it's
overridden by ld.so's definition.  This is also the case for the dl*
symbols themselves (as well as the internal __progname symbol that you
should avoid: use getprogname() instead).

So, instead of doing this:

>         handle = dlopen("libc.so", RTLD_NOW|RTLD_GLOBAL);
>

I think you should just pass dlsym() the fake RTLD_DEFAULT handle.  Is
there a particular reason you're not using that, or maybe RTLD_NEXT, right
now?

...

> Where does the semantic of dlsym differ from OpenBSD and Linux?


It's more about the exact placement of the symbol definitions.  Putting
them in ld.so lets them be initialized very early, before initialization
code in libraries that don't depend on libc (which is the common case to
permit operation across version bumps).

Philip Guenther

Reply via email to