[pacman-dev] [PATCH 3/3] meson: use hidden symbol visiblity by default

Emil Velikov emil.l.velikov at gmail.com
Mon Jan 4 14:14:04 UTC 2021


On Tue, 29 Dec 2020 at 03:47, Eli Schwartz <eschwartz at archlinux.org> wrote:
>
> On 12/28/20 10:15 PM, Allan McRae wrote:
> > On 25/12/20 2:05 am, Emil Velikov wrote:
> >> On Thu, 24 Dec 2020 at 01:38, Eli Schwartz <eschwartz at archlinux.org> wrote:
> >>>
> >>> On 12/23/20 5:42 PM, Emil Velikov wrote:
> >>>> All the required public API is annotated with SYMEXPORT, so we can just
> >>>> add the meson notation, to hide all the symbols by default.
> >>>>
> >>>> Thus we no longer spill all the internal API into the global namespace.
> >>> Thanks for noticing this... it's a regression from autotools, which
> >>> contained in lib/libalpm/Makefile.am:
> >>>
> >>> if ENABLE_VISIBILITY_CC
> >>> if DARWIN
> >>> AM_CFLAGS += -fvisibility=hidden
> >>> else
> >>> AM_CFLAGS += -fvisibility=internal
> >>> endif
> >>> endif
> >>>
> >>>
> >>> I wonder if we had a good reason to use "internal" and if we should
> >>> continue to do so? IIUC it makes it slightly more optimized at the cost
> >>> of allowing pointers into private functions (e.g. callbacks) used by
> >>> other programs to segfault.
> >>>
> >> If the output of size&ls is any indication - there is little-to-no
> >> optimisation happening.
> >> The former produces the same numbers, while the latter claims that
> >> binaries built with "internal" are larger by 8 bytes (always).
> >>
> >> Fwiw the above snippet is the first time I've seen anyone using
> >> "internal", after staring at various projects for 5+ years.
> >> Can bring it back, simply not sure it brings much.
> >>
> >> Thanks
> >> Emil
> >>
> >> $ ls
> >> 812336 build-internal/libalpm.so.12.0.1
> >> 812328 build-hidden/libalpm.so.12.0.1
> >> 337176 build-internal/pacman
> >> 337168 build-hidden/pacman
> >>
> >> $ size
> >> 316708    3080     592  320380   4e37c build-internal/libalpm.so.12.0.1
> >> 316708    3080     592  320380   4e37c build-hidden/libalpm.so.12.0.1
> >> 155288    5040    5808  166136   288f8 build-internal/pacman
> >> 155288    5040    5808  166136   288f8 build-hidden/pacman
> >>
> >
> > It turns out, we have this:
> > #define SYMHIDDEN __attribute__((visibility("internal")))
> >
> > But we never flag any functions with this.  That would enable a compiler
> > to optimize for speed and not compatibility, in which case using
> > -fvisibility=internal would make a difference.
> >
> > I'm not sure if we removed any usage of that from the codebase, or if it
> > was never there...
>
> Hmm... only ever used on alpm_add_target (then _alpm_add_loadtarget) and
> removed in commit 7f7da2b5fc01f46d28236384540c7ecfdac16a63 which added
> the AM_CFLAGS instead and marked a bunch of symbols as SYMEXPORT.
>
Fwiw annotating the public API tends to be easier and quicker. So most
projects opt for that.

> But that define used to be for visibility("hidden"), then in commit
> 920b0d2049deb148efe89bfebda03d172b68c1f5 both the (unused) define and
> the AM_CFLAGS got switched to internal: "this allows for slightly better
> optimization".
>
> Which is about as vague as our knowledge today. "Supposedly better and
> probably works fine, but no one put out numbers on it".
>
> idk, "hidden" is probably just fine.
>
Another point wrt "internal":
Seems like CMake - fairly common and mature build system* - has a
wrapper for the "hidden" visibility but lacks one for "internal".

Thanks for the references, I'll use those in the commit message for v2
and add an extra patch on top, removing the unused SYMHIDDEN.

-Emil
* Not here to start a flame war about build-systems and/or their
quality. Each one sucks in its unique way :-P


More information about the pacman-dev mailing list