disabling API

I have a C++ application running as a daemon in background and listens on socket and does client/server stuff.
The application has bunch of user API being called.  The applications needs libraries (.so) which is pointed by LD_LIBRARY_PATH

Is there a way I can disable a specific API from being run (What I mean is when it tries to ivoke API A, it should just ignore it from running and look into any .so files). Trying to find some performace issue with an API
learningunixAsked:
Who is Participating?
 
phoffricConnect With a Mentor Commented:
Could you create your own testing .so library and load the symbols from them to hide the desired official .so library files? You would want to adjust LD_LIBRARY_PATH. On some systems, the command would be like:

$ export LD_LIBRARY_PATH=yourNewTestLibraryPath:$LD_LIBRARY_PATH

From one of the earlier links I posted, the comment was:
"If the runtime-loader decides to use LD_LIBRARY_PATH (or SHLIB_PATH), then it loads the lib from where it finds it, according the search order. If the lib is already in memory (with that path) it will be used from there."
       http://www.experts-exchange.com/Programming/System/Unix_-_Posix/Q_20668206.html#a8857120

This is one way to hide (or choose) an existing library. Take a look at the question - 10 developers needing their own library versions.
0
 
phoffricCommented:
It has been awhile since doing this. IIRC, you can define your own stub having the API that you wish to disable from the library. In the make file, you place this module having the stub before the library. Then since the API is already being used, then the library version will not be extracted IIRC.
0
 
TomasPCommented:
which API? Are you calling a function or is it being called by one of the library functions?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
learningunixAuthor Commented:
Its my own user defined API not the system API

what changed do I need in makefile
0
 
phoffricCommented:
If it's your own API, then why not have temporarily for your performance tests:

#ifdef DISABLE_API
     write your own stub here
#else
    the real API function
#endif

Then rebuild your library using the -DDISABLE_API compiler flag to define the macro.

(This library name can be different by adding the _disable to the original name).

Then your makefile can have to programs defined, one with the original library, and one with the _disable library used instead.
0
 
learningunixAuthor Commented:
When I say user API what I mean i include the path in LD_LIBRARY_PATH which has bunch of *.so files.
the APT that I call in my program is actually somewhere in one of the .so libraries.

I don't want to comment out the API in my program as I'll have to do in 100 places, instead make with some option such that when API is called in my program, it simply ignores it instead of looking in .so files and executing it

With this, I am not sure how the changes you recommended will work?

0
 
phoffricCommented:
No way should you modify 100 places where you call the function.

>> when API is called in my program, it simply ignores it
When you say "ignores it", I thought you meant to replace the particular function in question with, say, a do-nothing stub function. The function has to exist somewhere in the build or you have an undefined reference.

The approach in http:#35345333 meant to just modify the one or more functions in the library(ies) - renaming the library(ies) so as not to lose the original. Then for building the test program, you would use the new library names having the do-nothing functions, instead of the old library names.

In the first post http:#35345023 instead of modifying your own libraries, you just keep them in the build to the right of the .o modules. In one of these modules, you define the do-nothing functions. Since the symbols are now defined and used for the build, IIRC, make will not extract the original functions from the libraries. This assumes that the .o module is to the left of the library name, since order matters.
0
 
TomasPCommented:
If you don't want to modify source then in the make file make the inclusion of a "do nothing" version of your library be linked rather than the functional version. You can control the inclusion with build time arguments. This is how debug vs release works
0
 
learningunixAuthor Commented:
Well, I don't have the access to libraries *.so files. I am using the libraries,
When I make an API call in my program it calls the libraries on .so (which i can't change)

I thought there is a way how I can build my code by means of which it can ignore some API calls which are in .so files

sorry if i am confusing you.
0
 
TomasPCommented:
Do you know the api signatures of the APIs you want to replace? If so, build a .a with function stubs with the same signatures and conditionally link your .a file in instead of the .so.
0
 
learningunixAuthor Commented:
that's a nice hack ;)
0
 
learningunixAuthor Commented:
thx. will try it
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.