[Xcb] hidden-visibility and library size

Jamey Sharp jamey at minilop.net
Wed Dec 28 12:45:23 PST 2005

On Tue, Dec 27, 2005 at 09:05:20PM -0800, Josh Triplett wrote:
> Jamey Sharp wrote:
> > I think setting visibility hidden by default is the wrong choice here.
> > Instead of setting any compile flags or touching any public header
> > files, just fix xcbint.h so that everything there is marked either
> > hidden or internal.
> I tend to disagree.  Hidden by default means that if you forget to mark
> something as visible, it stays hidden, meaning that it is far easier to
> unintentionally make a symbol hidden than to unintentionally make a
> symbol visible.  The consequence of an unintentionally hidden symbol is
> easy to notice (since applications will fail to compile), and the fix is
> simply to make it visible, which doesn't affect library backward
> compatibility.  The consequence of an unintentionally visible symbol is
> hard to notice (and might not be noticed until people start using it),
> and the fix causes a backward-incompatible change to the library.  I
> think we should have symbols hidden by default, and mark the public API
> as non-hidden.

What do you think of using the visibility pragma instead, and marking
all of xcbint.h hidden or internal that way? We already use GCC warnings
to check that all functions either are static or have a prototype
somewhere, which guarantees that the functions that need hidden
visibility are all present in xcbint.h.

Anyway I'm not sure I agree with your assessment. Visibility doesn't
work on most compilers in use today anyway, so its value for giving
people compiler errors is pretty limited, and failure to set default
visibility may well not be noticed quickly leading to surprises later.
(I'm still using GCC 3.4.5 most of the time, for example, so I'm
unlikely to notice bugs here.)

In contrast, by definition, the public API for a C library is exactly
the declarations in header files installed on the system, and if some
idiot goes to the trouble of installing xcbint.h themselves or copying
an internal prototype into their program, they deserve whatever they
get. I don't think the internal API needs any more protection than that.

In short, I think visibility is only useful as an optimization. Any
policy like "hidden by default" that makes it harder to produce a
library that operates correctly, just for the sake of an optimization,
is wrong.

Am I missing something?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.freedesktop.org/archives/xcb/attachments/20051228/cfd49c6c/attachment.pgp

More information about the Xcb mailing list