Find the answer to your Linux question:
Results 1 to 6 of 6
Hi all, I am using Linux OS ... my application XYZ uses shared libraries libA.so, and libB.so. When application XYZ is started .... the libA.so and libB.so are loaded automatically ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2010
    Posts
    5

    Shared libraries auto load when app starts up


    Hi all,
    I am using Linux OS ... my application XYZ uses shared libraries libA.so, and libB.so.

    When application XYZ is started .... the libA.so and libB.so are loaded automatically (given that the env variable LD_LIBRARY_PATH is properly set) ...

    If I want to validate the integrity of these libs before they are loaded, how am I going to do about that?

    I understand that if I explicitly call dlopen in my C/C++ app, I can write wrappter to the dlopen to validate the libraries before calling the actual dlopen ...
    But in the case of auto loading shared libraries at startup time, do I need to do anything with kernel for this purpose or how can I do this?

    Thanks,

    Dang

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,393
    Not so easy with C. Not so hard w/ C++ where you can execute code in your initialization blocks before main() is called. Define in a header something like this:
    Code:
    // Inline function.
    bool validate_libs()
    {
        // Validate libraries here
        if (!valid_libs)
        {
            ::abort();
        }
        return true;
    }
    
    bool libs_are_valid = validate_libs();
    This should be one of the first headers your application code sees so the validation gets priority in initialization.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Oct 2010
    Posts
    5
    Thanks,

    Will the inline function be called before all dependent shared libraries loaded ?


    I will give it a try ....

    Thanks,
    Dang

    ========================

    I gave it a try .. and it did load the shared libraries before calling the inline functions ...
    I need to validate the libraries before they are loaded to memory ... Is that correct
    the loading of the shared libraries to memory handled by the Kernel ?

    Thanks

    Dang
    Last edited by uonedang71; 11-09-2010 at 03:43 PM.

  4. #4
    Just Joined!
    Join Date
    Dec 2009
    Location
    California
    Posts
    98
    Why do you need to validate them?
    If it's for some sort of security reason, then I would suggest you compile your binary staticly and avoid shared libraries all together.

  5. #5
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,393
    Quote Originally Posted by abarclay View Post
    Why do you need to validate them?
    If it's for some sort of security reason, then I would suggest you compile your binary staticly and avoid shared libraries all together.
    I would agree with this, to statically link your applications. After all, it is likely that the validation code requires something in the system shared libraries at least, so that they still have to be loaded first. I'm not sure, but there may be a way to delay loading of certain shared libraries until they are actually needed. I've not needed to do this myself, so I cannot say for sure it is possible.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  6. #6
    Just Joined!
    Join Date
    Oct 2010
    Posts
    5
    Thanks folks,

    I would probably compile these libraries statically ...

    Thanks

    Dang

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •