From 6725c1f15b98348e059130dd53346287e83fa0d1 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 13 Aug 2026 18:22:18 -0400 Subject: [PATCH] BLD: Force all internal extension symbols to be hidden Even though Meson defaults to hidden visibility, our bundled libraries like FreeType may themselves export their own symbols individually. So force all symbols other than the Python module initialization function to be hidden with a linker version script. By making symbols like `FT_Init_Freetype` local, it ensures that they cannot be resolved by other global versions, such as a system copy loaded beforehand. It also allows the linker to discard more sections for unused code, saving us approximately 6.6% in shared library space. --- src/hidden-symbols.map | 6 ++++++ src/meson.build | 10 ++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/hidden-symbols.map diff --git a/src/hidden-symbols.map b/src/hidden-symbols.map new file mode 100644 index 000000000000..bea858a839ff --- /dev/null +++ b/src/hidden-symbols.map @@ -0,0 +1,6 @@ +{ + global: + PyInit_*; + local: + *; +}; diff --git a/src/meson.build b/src/meson.build index 077b7f0353b6..bbbd48fff2f0 100644 --- a/src/meson.build +++ b/src/meson.build @@ -131,9 +131,19 @@ else new_preprocessor = [] endif +# Even though Meson defaults to hidden visibility, our bundled libraries like FreeType +# may themselves export their own symbols individually. So force all symbols other than +# the Python module initialization function to be hidden with a linker version script. +mapfile = 'hidden-symbols.map' +vflag = cc.get_supported_link_arguments([ + '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile) +]) + foreach ext, kwargs : extension_data additions = { 'cpp_args': [new_preprocessor] + kwargs.get('cpp_args', []), + 'link_args': [vflag] + kwargs.get('link_args', []), + 'link_depends': [mapfile] + kwargs.get('link_depends', []), } py3.extension_module( ext,