[lug] Reverse LD_PRELOAD?

Zan Lynx zlynx at acm.org
Mon Jul 9 14:38:39 MDT 2018


On 07/09/2018 02:32 PM, stimits at comcast.net wrote:
> Hi,
>  
> I just thinking perhaps there is some simple trick to avoid or blacklist
> a library for just a single application for testing in a way similar to
> using LD_PRELOAD to force a given library path. So for example I have an
> OpenCL library and although I do not want to remove the file for the
> rest of the system I'd to do something similar to:
> LD_NEVER_LOAD=/lib64/libOpenCL.so.1.0.0 ./my_application
>  
> Anyone here know of a convenient method to do this for just this one
> application?

Your idea would only work for libraries opened with dlopen. Libraries
linked at build time would just fail to start.

I haven't tested this or anything, but maybe try
    ln -s /dev/null /tmp/libOpenCL.so.1.0.0
    LD_LIBRARY_PATH=/tmp ./my_application

Other than that, my only other idea is to create a copy of the library
directory (or a snapshot, or an overlay mount) and remove the library.
Then run your application in a namespace with the directory mounted in
place of /lib64.

-- 
                Knowledge is Power -- Power Corrupts
                        Study Hard -- Be Evil


More information about the LUG mailing list