symbol hiding - with gcc -fvisibility
Guido Draheim
guidod-2003- at gmx.de
Sun May 16 21:05:51 CDT 2004
sorry, just saw the note on WWN. I did hope that there would be someone
to point to the gcc visibility stuff already - but it seems that people are
more concerned to exchange their believes and politics rather showing
off some engineering stuff.
* preface:
it's not in the file format - it's in the tools.
The name ELF stands for Extensible Linker Format, it allows to invent all kind
of new sections, and expand the symbol table with many interesting attributes
that can be checked up by a toolchain. Well, "IF" the tools check for them.
* gcc -fvisibility
The gcc -fvisibility exists since 3.1 and is supported by binutils. If you read up
some web reports, it seems to have been invented for hiding stuff not quite
unlike what the original poster wanted. The icc supports all -fvisibility options
as well afair.
* the real problem
traditionally, one can kill local systems which are usable within one file only,
i.e. "static". Pretty 20year old unix stuff. The other symbols are referencable
outside (in .o) and the standard shard linker will put all of them into the
shared library symbol export table. - But now we want two different symbol
flavours, one exported to the same library, the others for the rest of the world.
Perhaps use a linker script to decide later about symbol visibility.
* example solution
gcc supports the universal attribute syntax, and it does now know about more
symbol flavours as to their visibility. Probably you want to have "hidden".
Attached are two simple test*.c files and a makefile. The final sharedlib
symbol table contains only test3 after stripping. - using a linker script instead
of in-source __attribute__ is left as an excercise to the reader.
* more hints
search freshmeat - there are ELF tools to staticlink, to obfuscate, and more.
It's all in the tools. There is only one problem with opensource: many programmers
do not need to hide symbols to the extreme, so they did not write such tools
so far. Not yet. There are some real ELF-educated people out there - hire one, and
let him write the tool you need. The ELF format is well-defined and simple enough
to allow everything and quite easily.
Do ut des.
-- cheers, guido http://google.de/search?q=guidod
-------------- next part --------------
extern void test2(void);
void __attribute__((visibility("hidden"))) test1(void) {
test2(); //__attribute__((visiblity("internal")))
}
-------------- next part --------------
extern void test1(void);
void __attribute__((visibility("hidden"))) test2(void) {
test1();
}
void test3(void) {
test2();
}
-------------- next part --------------
test.so : test1.c test2.c Makefile
gcc -Wl,-x -shared -o $@ test1.c test2.c
strip -x $@
objdump -t $@ | grep "test[123]"
-------------- next part --------------
gcc -Wl,-x -shared -o test.so test1.c test2.c
strip -x test.so
objdump -t test.so | grep "test[123]"
00000631 g F .text 0000000d test3
More information about the wine-devel
mailing list