Page 1 of 1

Shared variables (between ELF executables)

Posted: Wed Mar 22, 2006 5:21 am
by sam:_14332
Hello!

I want a variable to be shared between several ELF executables in the same process image - e.g. different .so files and the program executable.

And I don't want the value of the variable to be just copied between the executables (this is currently what happens for me) - i want all references to the variable in all executables to be dynamically linked against the same memory-location in one of the .so file.

What is the soulution? Some command-line argument to ls? Some change in the linker script? Something with the __attribute__ stuff?

Please HELP (thank you)!

Re:Shared variables (between ELF executables)

Posted: Wed Mar 22, 2006 5:51 am
by Candy
I would say that it requires you to explicitly use some shared resource, instead of telling the linker something. You could try making a shared library (don't think this usually works, but might have an ld flag that does that for you) or using shmem (shared memory, for exactly this purpose).