I just realized the implications of mapping in variables, not just functions. That's not guaranteed to work. There may be funky linker options to force variables to be exported, but I almost never see that done. Usually, you only export functions.
What people usually do is just keep a function around, which returns a pointer to all your relevant variables.
Something like this:
Then you load get_everything from your library, and call it to get pointers to all that shared data.
This sort of dynamic loading should be portable across not just linux but some other systems as well...
Last edited by Corona688; 03-28-2012 at 01:22 PM..
I used gdb on x64. (don't bother with the formatting about the code samples below, they are different in my code)
What I do is I first try to get my hands on a string in the so :
Quote:
const char decorator[] = "\x65\x65\x65\0";
After this, I need to use this to generate the name of the next symbol I need to load from the shared object:
With gdb I realized that the decorator previously retrieved via address from the so, I actualy get some garbage address, and not the one I need. I can't do a print on the decorator from the gdb because it tells me that the address is out of bounds.
Any clue about this ?
EDIT:
Somehow, I found some weird behavior.
Currently, I have a platform independent function for loading a library:
The code above is in library.c, the declaration for the function is in library.h.
In util.c I include library.h, and open the so using the function above.
Somehow, if I lose the function, and simply dump the dlopen where I need it, it works fine on x64 as well.
Apparently, now I also have to determine the reason for this behavior, since it is not acceptable to duplicate the code (I am calling util_load_library in several places)
Last edited by Maelstrom; 03-29-2012 at 12:56 PM..
Make absolutely sure that this function is declared everywhere you're using it. Including the right header is no longer optional when dealing with 64-bit systems.
In 32-bit x86, you can get away with passing a pointer to undeclared externals because the assumed integer parameters are big enough to hold a pointer.
In 64-bit x86, integers are still 32-bits, but pointers are 64! It will still assume the parameters are 32-bit integers, and mutilate the 64-bit pointer into fitting in the 32-bit variable, causing crashes or weird misbehavior.
Even worse problems are when you have the function declared two ways in different places; for instance having one parameter be a long in one file, and just an int in another. This works in 32-bit because int and long are the same size, but in 64, long is suddenly 64-bits, and the parameters get mangled again. This can be very hard to track down because, unlike undefined externals, it's not a compiler error, it's a linker problem, and the linker has no way to warn you about it.
1) because SHM is RAM; suddenly corruption is possible, and you have to initialize things.
2) shm is persistent. If you're insufficiently clever in setting things up, you can get junk from before or 'permission denied'.
3) Not as convenient as "give me variable x and let the system handle what's shared or not".
Last edited by Corona688; 03-30-2012 at 09:02 PM..
Hello,
I am new to programming shared objects and I was hoping someone could tell me if what I want to do is possible, or else lead me in the right direction.
I have a main program that contains an abstract base class. I also have a subclass that I'm compiling as a shared object. The subclass... (13 Replies)
Hi,
I would like to create a shared object ( .so).
This shared object
1. uses the functions from a library.
2. Also it should be able to use the global variable in an app
To achieve this what should I do ? 1) To use the functions in the library should I give the -ld option while... (1 Reply)
Hello,
While running a c++ shared object on AIX I am facing below error -
rtld: 0712-001 Symbol __ct__3ETDFv was referenced
from module /bancs/aml/lib/libmonitor.so(), but a runtime definition
of the symbol was not found.
rtld: 0712-001 Symbol etd_insert__3ETDFv was... (3 Replies)
Hi all,
I am developing an application with two components. One "c" binary and one "C++" shared object.
While execution, the shared object crashes out and core dump is created whenever "new" is executed. But if i use malloc this will work perfectly.
I tried to use dbx. Below given was... (1 Reply)
Hi,
I have created a shared object (abc.so) which has a function sum(int a, int b).
Is there any way to load the "abc.so" and use the sum function using shell script..
thanks in advance (2 Replies)
Hi All,
I have a problem with the shared objects setup in AIX. We have a customized shell written by the developers over here. When i issue a MQ Series command (mqsilist) it is giving the error as . All the commands making use of this libImbCmdLib.a.so is failing. But when executed in normal... (1 Reply)
Hi
I have a multithreaded daemon(server) which will accept connections from various clients and sends back results to them.
In order to serve my daemon clients, it has to establish a TCP connection to another server(vendor supplied which is listening on a specific TCP port) and gets the... (11 Replies)
Hi,
When using shared objects on AIX 4.3 i am getting runtime problems.
I have a small sample program which links to a shared object libray, oracle and system related libraries.
At runtime it fails (gives segmentation fault and coredump ) in one proc file when executing login statement.
But... (0 Replies)
Hi All,
I created the share object file using
gcc -shared -fpic mypp.cpp -o myp.so
but, pls tell me how to link this .so file to my client program.
Thanks (0 Replies)
Hi,
I have been trying to create a sharef object on my HP UX 11 machine
(HP-UX <myhostname> B.11.00 A 9000/879 ...... two-user license)
to create the shared object first I am creating the object file using
cc -Aa -c +z dyn.c
(I use -Aa and +z as per HP's manual on linkers ) to create the... (0 Replies)