Skip to content

Commit 84f283a

Browse files
committed
BLD: ensure libnpymath and highway static libs use hidden visibility
The effect this has is that symbols don't get re-exported as public by Python extension modules that link with these shared libraries. E.g., building on macOS arm64 with Clang changes the set of exported symbols for `_multiarray_umath` from: ``` % dy2ld_info -exports build/numpy/_core/_multiarray_umath.cpython-39-darwin.so build/numpy/_core/_multiarray_umath.cpython-39-darwin.so [arm64]: -exports: offset symbol 0x00112BA4 _PyInit__multiarray_umath 0x001C955C _npy_spacingf 0x001C95F8 _npy_spacing ... <many more _npy symbols> ``` to: ``` build/numpy/_core/_multiarray_umath.cpython-311-darwin.so [arm64]: -exports: offset symbol 0x0010B8F8 _PyInit__multiarray_umath ``` This works for all compilers that support GNU-style `__attribute__((visibility("hidden"))`, which both GCC and Clang do. Note that the `libnpyrandom` static library is left alone here. Trying to change visibility there breaks a test for CFFI, because that test is accessing private symbols. This is clearly wrong, but explicitly documented at https://numpy.org/devdocs/reference/random/extending.html#cffi. So leaving that alone here. `libnpyrandom` isn't used by SciPy anymore and may well have zero users left, so it's not critical.
1 parent ab7649f commit 84f283a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

numpy/_core/meson.build

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ if use_highway
112112
],
113113
cpp_args: '-DTOOLCHAIN_MISS_ASM_HWCAP_H',
114114
include_directories: ['src/highway'],
115-
install: false
115+
install: false,
116+
gnu_symbol_visibility: 'hidden',
116117
)
117118
else
118119
highway_lib = []
@@ -561,6 +562,7 @@ npymath_lib = static_library('npymath',
561562
install_dir: np_dir / '_core/lib',
562563
name_prefix: name_prefix_staticlib,
563564
name_suffix: name_suffix_staticlib,
565+
gnu_symbol_visibility: 'hidden',
564566
)
565567

566568
dir_separator = '/'

0 commit comments

Comments
 (0)