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

Eli Schwartz eschwartz at archlinux.org
Tue Dec 29 03:47:49 UTC 2020


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.

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.

-- 
Eli Schwartz
Bug Wrangler and Trusted User

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.archlinux.org/pipermail/pacman-dev/attachments/20201228/985537c3/attachment.sig>


More information about the pacman-dev mailing list