[FFmpeg-devel] Visibility implementation

Uoti Urpala uoti.urpala
Wed Jul 30 20:25:34 CEST 2008

On Wed, 2008-07-30 at 17:45 +0100, M?ns Rullg?rd wrote:
> Uoti Urpala wrote:
> > It makes the code faster when compiling with -fPIC, the question is only
> > whether or in which cases the speedup is significant. I'm not sure what
> > "alternatives" you're talking about.
> Using static libraries, building without -fPIC (where possible), building
> with -fPIC.

Static libraries are often not a good alternative for other reasons.
Using shared libraries compiled without -fPIC may or may not be a
reasonable alternative depending on the platform.

> > Code improvements are not the only benefit. Currently libavcodec.so
> > exports 1100 symbols for use by external programs, most of which it
> > shouldn't. The patch I posted cuts this to about one third, and
> > completing the visibility markup would make it fall further. That
> > difference exists whether the library is compiled with -fPIC or not.
> 1. Does it matter?

Yes somewhat. Perhaps not so much as to be worth doing a huge amount of
work, but adding two marker lines per header isn't that much work or
complication either.

> 2. Static libs still export all the stuff, so any namespace arguments
>    are irrelevant.

Not really. Static libs are a special enough use case that whatever
happens with them doesn't necessarily have much relevance to most use.

> 3. Selectively exporting symbols can be done more easily, and on more
>    platforms, with linker tricks.

I don't think it would be significantly easier. Adding two lines per
header isn't that complicated, and the special cases would need manual
handling in any other implementation too.

> >> > I know there are people
> >> > who find some kind of twisted pleasure in obfuscating perfectly good
> >> > code with non-standard hacks and directives, but I'm not one of them.
> >
> > Visibility is fairly standard library functionality nowadays.
> If by standard, you mean gcc, yes.

Fairly standard as in something normal to library developers;
concentrating on the compiler used to achieve it is misleading. Of
course most of library development and compilation on UNIX by far is
done with GCC. ICC supports the same syntax. On Windows Microsoft
compilers have their own syntax to express DLL visibility, and projects
supporting VC can map the same macros to that.

I think there's little reason to oppose visibility as a "nonstandard
compiler-specific feature" or anything like that. It's not a very old
feature (at least in active use) compared to the most basic stuff and so
there are still platforms without support for it - mainly those that see
little development but aren't quite dead yet - and the exact syntax for
it is not standardized. However it is already widely used and the usage
will become more standard with time.

More information about the ffmpeg-devel mailing list