[FFmpeg-devel] Visibility implementation
Uoti Urpala
uoti.urpala
Wed Jul 30 04:45:36 CEST 2008
The attached patch adds visibility information for lots of symbols in
libavcodec. I used the following macros to mark visibility:
HIDDEN
Used in a declaration or definition to indicate that the symbol is
internal to the currently compiled library.
extern HIDDEN int libavcodec_internal_int;
HIDDEN void libavcodec_internal_function(void);
START_HIDDEN_VISIBILITY_SECTION
END_VISIBILITY_SECTION
Declarations and definitions between these 2 macros have hidden
visibility by default.
EXTERNALLY_VISIBLE
Used in a declaration/definition between the above 2 macros to indicate
that some symbol should NOT have hidden visibility, but should behave as
normal.
These macros are defined in libavutil/internal.h. Currently they're
defined unconditionally; a compiler check should be added for production
code. Some other names for the macros could also be used.
Visibility information matters in 2 cases: when a symbol is defined (to
make the compiler place it in the correct section) and when any other
code accesses it (knowing that a symbol has hidden visibility helps
avoid the overhead of -fPIC). If a declaration which marks the symbol
hidden is visible then it is not necessary to indicate the visibility
information again where the symbol is defined. So in most cases marking
the declarations in internal headers hidden is enough (if the file
defining the symbol and all files using it include the header). Most of
the patch is adding START_HIDDEN_VISIBILITY_SECTION at the start and
END_VISIBILITY_SECTION at the end of various internal headers.
If some .c file has a global definition which does not appear in a
public header, and another file has its own internal declaration for
that symbol, then it's necessary to mark those hidden separately. See
ff_flac_compute_autocorr for an example of this in the patch.
When adding START_HIDDEN_VISIBILITY_SECTION/END_VISIBILITY_SECTION in
headers one thing to watch out for is to make sure you don't put it
around #include statements. Other headers included between those macros
would also use hidden visibility by default, which would likely lead to
breakage.
The following symbols were used outside libavcodec and caused
compilation errors when everything in their corresponding headers was
declared hidden: ff_cropTbl (used in vhook), ff_frame_rate_tab,
ff_mpa_decode_header, ff_mpa_bitrate_tab, ff_mpa_freq_tab,
ff_find_start_code (used in libavformat). I added the EXTERNALLY_VISIBLE
macro to their definitions to turn them back to publicly available
outside the library.
In my test compilation this patch lowered the amount of public symbols
in libavcodec.so that are exported for use by external programs from
1100 to 378 (counted with "nm -D libavcodec.so | grep -c '^[^ ]'"). Even
though I didn't add HIDDEN macros to the various xxx_decoder,
xxx_encoder etc definitions referring to them as external hidden symbols
in allcodecs.o seems to be enough to prevent the linker from making them
publicly available in the final library.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: visibility.patch
Type: text/x-patch
Size: 21283 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080730/0540eace/attachment.bin>
More information about the ffmpeg-devel
mailing list