We have this strange prototype at work which is based upon an avionics simulator, written in C and running on Linux. The original simulator provides all the functionality of the avionics operating system and gives the avionics applications access to the system through an API. Each individual application is loaded in memory as a shared object using dlopen().
Now, the prototype, which adds certain features to the original simulator, is to be used as a testing platform of some software functions used by the aircraft. For the sake of the test, some operating system calls are to be controlled in a "deterministic" way, thus redefining these O.S. functions in the loaded application.
The problem with this is, that the shared-object of the application contains symbols with the same name and signature as some system functions in the simulator. In spite of my experiments using LD_PRELOAD and different flags on dlopen, I always get the simulator functions to execute instead of those in the shared object (the application). Because there are a couple hundreds of tests redefining different symbols each time, recompiling the simulator is not an option.
Here is an example of the problem:
main.c: the simulator code, it has the "real" OS system functions.
Code: Select all
#include <stdio.h>
#include <dlfcn.h>
void duplicate() {
printf("This is the first (hard coded) function\n");
}
int main() {
dlopen("appTest.so",RTLD_NOW|RTLD_LOCAL); //flags do not seem to change the behavior
duplicate();
return 0;
}
Code: Select all
#include <stdio.h>
void duplicate() {
printf("this is the Application dynamic library!!! :)\n");
}Code: Select all
$ gcc -Wall -shared appTest.c -o appTest.so
$ gcc -Wall main.c -ldl
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
$ export LD_PRELOAD=appTest.so
$ ./a.out
This is the first (hard coded) function
Any explanation/help/suggestion will be greatly appreciated....
(I'm using gcc (GCC) 3.4.4 20050721 and Linux 2.6.9-22.ELsmp)
Cheers!



