Affecting dynamic library load path programmatically on solaris - Unix

This is a discussion on Affecting dynamic library load path programmatically on solaris - Unix ; Hi! Is there a way to programmatically affect the load path that dlopen uses on solaris? On windows there's SetDllDirectory, but so far I haven't found anything like that for solaris. The problem I'm facing is that I need to ...

+ Reply to Thread
Results 1 to 9 of 9

Thread: Affecting dynamic library load path programmatically on solaris

  1. Affecting dynamic library load path programmatically on solaris

    Hi!

    Is there a way to programmatically affect the load path that dlopen uses
    on solaris? On windows there's SetDllDirectory, but so far I haven't found
    anything like that for solaris.

    The problem I'm facing is that I need to programmatically load one of
    two dynamic libraries using dlopen + dlsym. The problem is that they
    require a different dynamic library load path (i.e. LD_LIBRARY_PATH to be
    set differently when launching the program). Setting the LD_LIBRARY_PATH
    differently according to what command line options are given is obviously
    very awkward for the user, so I'd like to do this programmatically.

    The libraries in question are libjvm.so for sun client and server jvm.
    AFAIK this problem only occurs on solaris (it has not come up on windows,
    linux or os-x).




    ::Antti::



  2. Re: Affecting dynamic library load path programmatically on solaris

    On Aug 10, 9:21 pm, "Antti Karanta"
    wrote:
    > Hi!
    >
    > Is there a way to programmatically affect the load path that dlopen uses
    > on solaris? On windows there's SetDllDirectory, but so far I haven't found
    > anything like that for solaris.
    >
    > The problem I'm facing is that I need to programmatically load one of
    > two dynamic libraries using dlopen + dlsym. The problem is that they
    > require a different dynamic library load path (i.e. LD_LIBRARY_PATH to be
    > set differently when launching the program). Setting the LD_LIBRARY_PATH
    > differently according to what command line options are given is obviously
    > very awkward for the user, so I'd like to do this programmatically.


    Why not just use setenv()/putenv() to alter LD_LIBRARY_PATH within
    your program before calling dlopen?

  3. Re: Affecting dynamic library load path programmatically on solaris

    On Mon, 11 Aug 2008 09:48:56 +0300, wrote:

    > Why not just use setenv()/putenv() to alter LD_LIBRARY_PATH within
    > your program before calling dlopen?


    Sounds obvious now that you mention it, thanks. I'd rather use something
    dlopen specific, but I suppose if I change the value back after loading
    the library it does not matter that much.


    ::Antti::


  4. Re: Affecting dynamic library load path programmatically on solaris

    On Aug 11, 12:21 am, "Antti Karanta"
    wrote:
    > On Mon, 11 Aug 2008 09:48:56 +0300, wrote:
    > > Why not just use setenv()/putenv() to alter LD_LIBRARY_PATH within
    > > your program before calling dlopen?

    >
    > Sounds obvious now that you mention it, thanks. I'd rather use something
    > dlopen specific, but I suppose if I change the value back after loading
    > the library it does not matter that much.


    I agree it's not the cleanest, but it looks like that is the only way
    to set the search path. You could also search for the library
    yourself and pass the full path to dlopen().

  5. Re: Affecting dynamic library load path programmatically on solaris

    fjblurt@yahoo.com writes:

    > On Aug 10, 9:21 pm, "Antti Karanta"
    > wrote:


    >> The problem I'm facing is that I need to programmatically load one of
    >> two dynamic libraries using dlopen + dlsym.


    You do realize that you can dlopen("/full/path/to/desired/library.so", ...),
    or dlopen("relative/path/to/desired/library.so", ...),
    and the loader will load *exactly* the library you asked it to?

    > Why not just use setenv()/putenv() to alter LD_LIBRARY_PATH within
    > your program before calling dlopen?


    I have not tested this, but suspect that this would be entirely
    pointless: both Linux and Solaris runtime loaders evaluate LD_*
    environment variables once (very early in process startup). After
    that, you can modify LD_LIBRARY_PATH all you want, and will not
    change anything.

    Note that Java re-exec()s itself after setting LD_LIBRARY_PATH the
    way it likes.

    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

  6. Re: Affecting dynamic library load path programmatically on solaris

    On Mon, 11 Aug 2008 20:59:26 +0300, wrote:

    > You could also search for the library yourself and pass the full path
    > to dlopen().


    I already do that - I pass the full path to the library I load to
    dlopen. The issue is the libraries the library I load depends on. The only
    way I can affect where they are loaded from is by modifying the dl search
    path.



    ::Antti::


  7. Re: Affecting dynamic library load path programmatically on solaris

    On Tue, 12 Aug 2008 05:18:23 +0300, Paul Pluzhnikov
    wrote:

    > You do realize that you can dlopen("/full/path/to/desired/library.so",
    > ...),
    > or dlopen("relative/path/to/desired/library.so", ...),
    > and the loader will load *exactly* the library you asked it to?


    Yes, I realize that. Like I said in another reply message, the issue is
    not the library I'm loading (which I already load w/ full path to get
    exactly the one I want), but the libraries it depends on.


    >> Why not just use setenv()/putenv() to alter LD_LIBRARY_PATH within
    >> your program before calling dlopen?

    >
    > I have not tested this, but suspect that this would be entirely
    > pointless: both Linux and Solaris runtime loaders evaluate LD_*
    > environment variables once (very early in process startup). After
    > that, you can modify LD_LIBRARY_PATH all you want, and will not
    > change anything.


    Darn. I had almost got that implemented. Back to the drawing board...


    > Note that Java re-exec()s itself after setting LD_LIBRARY_PATH the
    > way it likes.


    I suspected something like this. This seems an awkward way to do it, but
    I guess I have to go the same route if there's no other way...



    ::Antti::



  8. Re: Affecting dynamic library load path programmatically on solaris

    "Antti Karanta" writes:

    >> You do realize that you can
    >> dlopen("/full/path/to/desired/library.so", ...),
    >> or dlopen("relative/path/to/desired/library.so", ...),
    >> and the loader will load *exactly* the library you asked it to?

    >
    > Yes, I realize that. Like I said in another reply message, the
    > issue is not the library I'm loading (which I already load w/ full
    > path to get exactly the one I want), but the libraries it depends
    > on.


    You can dlopen("/path/to/desired/libjvm.so", ...) before loading
    the library that depends on it. When the loader discovers that your
    libfoo.so depends on libjvm.so, it will not attempt to search for
    libjvm.so if there is already an instance loaded in memory.

    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

  9. Re: Affecting dynamic library load path programmatically on solaris

    On Tue, 12 Aug 2008 18:02:36 +0300, Paul Pluzhnikov
    wrote:

    > You can dlopen("/path/to/desired/libjvm.so", ...) before loading
    > the library that depends on it. When the loader discovers that your
    > libfoo.so depends on libjvm.so, it will not attempt to search for
    > libjvm.so if there is already an instance loaded in memory.


    My explanation was a bit unclear - I'm loading libjvm.so and the dynlibs
    it depends on are the issue. But I guess I could try to load everything
    libjvm.so depends on before trying to load it itself, so your idea is
    still applicable.

    Thanks.



    ::Antti::



+ Reply to Thread