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
extern void test2(void); void __attribute__((visibility("hidden"))) test1(void) { test2(); //__attribute__((visiblity("internal"))) }
extern void test1(void); void __attribute__((visibility("hidden"))) test2(void) { test1(); }
void test3(void) { test2(); }
test.so : test1.c test2.c Makefile gcc -Wl,-x -shared -o $@ test1.c test2.c strip -x $@ objdump -t $@ | grep "test[123]"
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
On Mon, 17 May 2004 04:05:51 +0200, Guido Draheim wrote:
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.
Ah, thanks. I did actually try __attribute__((visibility("hidden"))) but it still left symbols in the .symtab - of course if you strip the binary as well, this disappears too.
Yay! Now everyone's happy! Group hug everyone!
/was a tenny bit worried about losing commercial intrest because we simply use ELF executables.
--- Mike Hearn mike@navi.cx wrote:
On Mon, 17 May 2004 04:05:51 +0200, Guido Draheim wrote:
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.
Ah, thanks. I did actually try __attribute__((visibility("hidden"))) but it still left symbols in the .symtab - of course if you strip the binary as well, this disappears too.
Mike Hearn wrote:
On Mon, 17 May 2004 04:05:51 +0200, Guido Draheim wrote:
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.
Ah, thanks. I did actually try __attribute__((visibility("hidden"))) but it still left symbols in the .symtab - of course if you strip the binary as well, this disappears too.
Yepp, it's kinda peculiar to need both -Wl,-x and strip -x, dunno why either.
Btw, since my mail was quoted on WWN I just had a chance to reread the stuff and I noted immediatly there're lots'a little errors in it. Funny. Although nothing misleading, let me atleast adjust for these two before someone else puts in: - yes, ELF stands really for Executable and Linker Format. Originally designed to cover the needs of all the flavours of object files, library and executables, it has become such a success among unix systems because of its enormous flexibility. - the visibility __attribute__ *is* present since 3.1/3.2 cycle but the commandline -fvisibility options are not. They are gcc 3.4 additions afaics - s/a gcc'zilla 15000 (my examples were tested with gcc 3.2.2 before sending them to the list)
cheers, -- guido http://google.de/search?q=guidod