[Gc] Hiding internal symbols in shared object
ivmai at mail.ru
Fri May 1 02:46:54 PDT 2009
Unlike DLL, in Unix DSO all non-static symbols are exported by default. With GCC v4+ it's possible to specify non-default visibility (hidden or internal). Exporting API-only symbols shrinks libgc.so size by 10-15% (and may have some code optimization benefits).
The proposed solution is, in breaf, to define GC_API as extern __attribute__ ((visibility("default"))) (for gcc v4+) if we are building DSO and use gcc "-fvisibility=hidden" option (this option is available in gcc v4+ and changes the visibility for symbols with unspecified visibility to hidden) together with -shared -DGC_BUILD -DGC_DLL.
The proposed patch in major does:
- define GC_API for non-Win32 DSO (shared object library) targets (only if gcc v4+);
- add info about GC_BUILD and GC_DLL for non-Win32 targets;
- add GC_API/GC_CALL decl modifiers to GC_memalign() in mallocx.c and add GC_memalign() proto to gc.h (GC_memalign() is available on Win32);
- add GC_API decl modifier (without GC_CALL) to the wrapped pthread_create/join/detach/sigmask() and dlopen() in gc_pthread_redirects.h, pthread_support.c and gc_dlopen.c;
- mark extern "C" symbols with GC_API in new_gc_alloc.h;
- add GC_API/GC_CALL decl modifiers to GC_incr_bytes_allocd/freed() in mallocx.c (used in new_gc_alloc.h).
The patch also does (misc things):
- fix some typos in Makefile.direct comments;
- update Makefile.direct comments for USE_MMAP, USE_MUNMAP, THREAD_LOCAL_ALLOC, PARALLEL_MARK, STATIC;
- add info about DONT_USE_USER32_DLL macro to Makefile.direct;
- refine GC_dump() comment in gc.h;
- remove redundant "ifdef" guards before "undef" (since it's always safe to undefine a symbol which is not yet defined) in gc_pthread_redirects.h;
- missing GC_incr_mem_freed(words) is replaced with existing GC_incr_bytes_freed(bytes) in new_gc_alloc.h (but GC_generic_malloc_words_small() is still missing);
- remove GC_memalign() proto in test.c;
- GC_memalign() is used for Win32 too in test.c;
- GC_DLL is handled for non-Win32 targets (since GC_print_stats is not exported from DSO/DLL) in test.c.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 15333 bytes
Desc: not available
Url : https://napali.hpl.hp.com/pipermail/gc/attachments/20090501/b29b81b2/diff75.obj
More information about the Gc