visibility and -Wl,--version-script
Mathieu Lacage
mathieu.lacage@gmail.com
Sat Jul 19 02:43:00 GMT 2008
hi,
Here is below some test code I wrote to attempt to understand how I
could use -Wl,--version-script. Obviously, it does not work (just
download, untar and make).
http://www-sop.inria.fr/members/Mathieu.Lacage/test-visib.tar.gz
For those who don't want to download this tarball, what I am doing is
first build a shared library with this header:
void A (void);
class Test
{
public:
void Do (void);
};
Then, I build a main program:
#include "libtest.h"
int main (int argc, char *argv[])
{
Test a;
a.Do ();
A ();
}
The above is pretty straightforward but what I am doing is this:
mmathieu@mathieu-boulot:~/code/tmp/test-visib$ make
g++ -c -fpic -fvisibility=hidden -o libtest.o libtest.cc
g++ -shared -Wl,--version-script=libtest.so.map -o libtest.so libtest.o
g++ -c -o maintest.o maintest.cc
g++ -L. -ltest -o maintest maintest.o
maintest.o: In function `main':
maintest.cc:(.text+0x18): undefined reference to `Test::Do()'
maintest.cc:(.text+0x1d): undefined reference to `A()'
collect2: ld returned 1 exit status
make: *** [maintest] Error 1
mathieu@mathieu-boulot:~/code/tmp/test-visib$
The intent of the above build commands is to build the libtest.so
library in a way which avoids any indirections through the GOT and PLT
to call functions internally and to specify the set of public
functions I want to export to user programs with libtest.so.map
defined as:
{
global:
extern "C++" {
Test*;
A*;
};
local: *;
};
So, what I expected the --version-script option to do is to generate a
set of of GOT/PLT entries which give access to the underlying hidden
symbols. It seems, however, that what this option does is merely
filter out from the set of existing GOT/PLT entries the ones which
should appear in the final symbol table.
The question, then, is whether or not what I am trying to do is
possible without having to define a large set of symbol aliases (I am
not even sure how to define a set of aliases for a class) which define
different visibility attributes for the original symbol and for the
alias symbol. The crux of the issue here is that what I am trying to
do is to make my library not use the GOT/PLT for any internal function
calls but to allow client programs to access all of the libraries'
public functions through the GOT/PLT. I understand that what I want to
do is likely to break some of the fine print of the C++ standard but,
I think I can live with that so, is there a way to do this ?
any help would be welcome,
Mathieu
--
Mathieu Lacage <mathieu.lacage@gmail.com>
More information about the Gcc-help
mailing list