noamhooper
asked on
How to prevent functions from being exported in a shared library
I have two static libraries which share function names and other symbols. I don't have the sources for the libraries so I thought of wrapping one of the libraries in a .so file. In win32 this works because I can control in a .def file which functions are exported from a dll. however which gcc/ld all functions are exported.
Is there a way to control which functions are exported from a shared library?
I read something about using a linker control script, but I haven't found a sample for such one...
Is there a way to control which functions are exported from a shared library?
I read something about using a linker control script, but I haven't found a sample for such one...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
noamhooper,
> is there a way to prevent exporting functions from an .so?
No, not directly. In ELF, you could define weak symbols - they're overwritten once another symbol with the same name and type is found. But I'm not sure if this works with shared libraries as well.
Do you want to versionize symbols? Like replacing existing symbols "on-the-fly" with newer ones, without the need to restart a program?
Stefan
> is there a way to prevent exporting functions from an .so?
No, not directly. In ELF, you could define weak symbols - they're overwritten once another symbol with the same name and type is found. But I'm not sure if this works with shared libraries as well.
Do you want to versionize symbols? Like replacing existing symbols "on-the-fly" with newer ones, without the need to restart a program?
Stefan
ASKER
Stefan,
What do you mean by versionize symbols? Will this solve problems at link time?
-noam
What do you mean by versionize symbols? Will this solve problems at link time?
-noam
ASKER
I have found the solution.
ld has the options to export only a few symbols which are listed in a seperate file:
--retain-symbols-file
To avoid overriding of symbols from other modules, it is needed to have binding only within the shared object, using the option:
-Bsymbolic
ld has the options to export only a few symbols which are listed in a seperate file:
--retain-symbols-file
To avoid overriding of symbols from other modules, it is needed to have binding only within the shared object, using the option:
-Bsymbolic
ASKER
In case I still want to keep the different implementations, is there a way to prevent exporting functions from an .so?