This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

hiding of (global) C++ symbols in shared object


Hi,

sorry for crossposting to two lists. But I don't know to which it applies
most. I searched the archives but found nothing that really explained the
problem.

I have some C++ files, defining some classes, and of those I want to make
a shared library. No problem. But I also want to have control over what
symbols are exported by that library. Unfortunately g++ puts all symbols
from these classes into .globl linkage and the linker collects all these
symbols into the dynamic symbols section. Note that this includes _all_
symbols (constructors, destr., methods, everything) which are coming from
a class definition, no matter if they are private to one source file.

I know, there are the libtool flags '-export-symbols' and
'-export-symbols-regex', but they only exclude symbols from the normal
symbol table, not from the dynamic one. The reason is, that GNU ld's
--retain-symbols-file option also does not touch the dynsym table. As soon
as a symbol has global linkage in one object file it ends in dynsym.

Right now my "solution" to this is, that I first link all object files for
the shared lib into one relocatable object (ld -r), then use a modified
version of objcopy to localize all symbols which I want to hide, and then
link _that_ object into a shared lib.

My question now is, if there is a better way to do what I want,
esp. a way more independent from objcopy.

For those who wonder _why_ I want to do this: consider a plugin system,
whichs loads dynamic objects (defined in C++). Now if two plugins define
the same symbols (or e.g. the same templates, without them defined in a
common base library), and they are loaded together (I currently use
libltdl) all sorts of funny things can happen. The solution in former
times was to use C modules, which only define one extern function (like
_init_modulename). But with C++ I don't have the possibility to mark some
classes as "static" (in the sense private to one source file), templates
are even more difficult, and therefore I need to hide those symbols.


Ciao,
Michael.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]