Shared variables (between ELF executables)

Programming, for all ages and all languages.
Post Reply
sam:_14332

Shared variables (between ELF executables)

Post 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)!
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Shared variables (between ELF executables)

Post 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).
Post Reply