Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing libtool to load a duplicate function name from a shared library
    text
    copied!<p>I'm trying to create a 'debug' shared library (i.e., .so or .dll file) that calls another 'real' shared library that has the same C API as the debug library (in this case, to emulate the PKCS#11 API). However, I'm running into trouble where the link map of the debug library is colliding with that of the real library and causing the debug library to call its own functions instead of the corresponding functions in the real library. I found a solution to this problem by using the POSIX dlmopen command, but would like to understand if the same is possible using GNU's libtool.</p> <p>On my Solaris 10 system, the following code fails the assertion when a test application statically links to the debug library:</p> <pre><code>#include &lt;dlfcn.h&gt; int MyFunctionName() { int (*function_ptr)(); void *handle = dlopen("realsharedlibrary.so", RTDL_LAZY); *(void **)(&amp;function_ptr) = dlsym(handle, "MyFunctionName"); ASSERT(function_ptr != MyFunctionName); // Fails return (*function_ptr)(); } </code></pre> <p>In this case, I get a function pointer to the local 'MyFunctionName' (in the debug library) instead of MyFunctionName within the real shared library.</p> <p>I've discovered that it's possible to get around this problem by using the command 'dlmopen' instead of 'dlopen', and telling dlmopen to create a new link map (with the <code>LM_ID_NEWLM</code> parameter) when loading the real library:</p> <pre><code>int MyFunctionName() { int (*function_ptr)(); void *handle = dlmopen(LM_ID_NEWLM, "realsharedlibrary.so", RTDL_LAZY); *(void **)(&amp;function_ptr) = dlsym(handle, "MyFunctionName"); ASSERT(function_ptr != MyFunctionName); // succeeds return function_ptr(); // call real function } </code></pre> <p>Unfortunately, dlmopen does not seem to be included within libtool (i.e., I don't see an lt_dlmopen function in libtool).</p> <p>Is it possible to do the same thing using libtool commands -- that is, to create a new link map when loading the new library so that it doesn't collide with the link map of the debug library?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload