Skip to content

Commit 50060ee

Browse files
committed
Add gnu_symbol_visibility: 'hidden' option to .so compilation
1 parent 6bb6639 commit 50060ee

File tree

6 files changed

+18
-33
lines changed

6 files changed

+18
-33
lines changed

β€Žsrc/godot/hazmat/gdptrs.pxd.j2β€Ž

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,22 @@ from .gdextension_interface cimport *
88

99

1010
cdef extern from * nogil:
11-
# Global variables defined in `pythonscript_gdextension_ptrs.c`
12-
# Given `libpythonscript.so` is responsible for initializing the Python
13-
# interpreter, we are guanteed `pythonscript_gdapi` symbol is always
14-
# resolved and set to a non-null value \o/
1511
"""
1612
#include <godot/gdextension_interface.h>
1713
#ifdef _WIN32
1814
# define DLL_IMPORT __declspec(dllimport)
1915
#else
20-
# define DLL_IMPORT
16+
# define DLL_IMPORT __attribute__((visibility("default")))
2117
#endif
18+
"""
19+
20+
21+
cdef extern from * nogil:
22+
# Global variables defined in `pythonscript_gdextension_ptrs.c`
23+
# Given `libpythonscript.so` is responsible for initializing the Python
24+
# interpreter, we are guanteed `pythonscript_gdapi` symbol is always
25+
# resolved and set to a non-null value \o/
26+
"""
2227
DLL_IMPORT extern GDExtensionInterfaceGetProcAddress pythonscript_gdptr_get_proc_address;
2328
DLL_IMPORT extern GDExtensionClassLibraryPtr pythonscript_gdptr_library;
2429
"""
@@ -28,12 +33,6 @@ cdef extern from * nogil:
2833

2934
cdef extern from * nogil:
3035
"""
31-
#include <godot/gdextension_interface.h>
32-
#ifdef _WIN32
33-
# define DLL_IMPORT __declspec(dllimport)
34-
#else
35-
# define DLL_IMPORT
36-
#endif
3736
DLL_IMPORT extern void (*pythonscript_gdptr_get_godot_version)(GDExtensionGodotVersion *r_godot_version);
3837
DLL_IMPORT extern void *(*pythonscript_gdptr_mem_alloc)(size_t p_bytes);
3938
DLL_IMPORT extern void *(*pythonscript_gdptr_mem_realloc)(void *p_ptr, size_t p_bytes);
@@ -343,12 +342,6 @@ cdef extern from * nogil:
343342
# Godot variant from/into Python object conversions
344343
cdef extern from * nogil:
345344
"""
346-
#include <godot/gdextension_interface.h>
347-
#ifdef _WIN32
348-
# define DLL_IMPORT __declspec(dllimport)
349-
#else
350-
# define DLL_IMPORT
351-
#endif
352345
DLL_IMPORT extern GDExtensionTypeFromVariantConstructorFunc pythonscript_gdptr_object_from_variant;
353346
DLL_IMPORT extern GDExtensionVariantFromTypeConstructorFunc pythonscript_gdptr_object_into_variant;
354347
DLL_IMPORT extern GDExtensionTypeFromVariantConstructorFunc pythonscript_gdptr_bool_from_variant;
@@ -373,12 +366,6 @@ cdef extern from * nogil:
373366
# {{ builtin.original_name }}
374367
cdef extern from * nogil:
375368
"""
376-
#include <godot/gdextension_interface.h>
377-
#ifdef _WIN32
378-
# define DLL_IMPORT __declspec(dllimport)
379-
#else
380-
# define DLL_IMPORT
381-
#endif
382369
{% for c in builtin.constructors %}
383370
DLL_IMPORT extern GDExtensionPtrConstructor pythonscript_gdptr_{{ builtin.snake_name }}_constructor_{{ c.index }};
384371
{% endfor %}
@@ -443,12 +430,6 @@ cdef extern from * nogil:
443430
# Utility functions
444431
cdef extern from * nogil:
445432
"""
446-
#include <godot/gdextension_interface.h>
447-
#ifdef _WIN32
448-
# define DLL_IMPORT __declspec(dllimport)
449-
#else
450-
# define DLL_IMPORT
451-
#endif
452433
{% for utility in api.utility_functions %}
453434
DLL_IMPORT extern GDExtensionPtrUtilityFunction pythonscript_gdptr_utility_{{ utility.original_name }};
454435
{% endfor %}

β€Žsrc/godot/hazmat/meson.buildβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ endif
7373
shared_library(
7474
'extension_class',
7575
c_extension_class,
76+
gnu_symbol_visibility: 'hidden', # Used by both clang & gcc (see https://gcc.gnu.org/wiki/Visibility)
7677
dependencies : [dep_godot, dep_python, dep_pythonscript],
7778
install_rpath: extension_class_rpath, # To find libpython
7879
name_prefix: python_native_module_name_prefix,

β€Žsrc/godot/meson.buildβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ shared_library(
128128
'builtins',
129129
cbuiltins,
130130
c_args: builtins_c_args,
131+
gnu_symbol_visibility: 'hidden', # Used by both clang & gcc (see https://gcc.gnu.org/wiki/Visibility)
131132
dependencies : [dep_godot, dep_python, dep_pythonscript],
132133
install_rpath: builtins_rpath, # To find libpython
133134
name_prefix: python_native_module_name_prefix,
@@ -189,6 +190,7 @@ shared_library(
189190
'classes',
190191
cclasses,
191192
c_args: classes_c_args,
193+
gnu_symbol_visibility: 'hidden', # Used by both clang & gcc (see https://gcc.gnu.org/wiki/Visibility)
192194
dependencies : [dep_godot, dep_python, dep_pythonscript],
193195
install_rpath: classes_rpath, # To find libpython
194196
name_prefix: python_native_module_name_prefix,

β€Žsrc/meson.buildβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ lib_pythonscript = shared_library(
286286
'pythonscript',
287287
['pythonscript.c', c_pythonscript_gdextension_ptrs, c_pythonscript],
288288
c_args: lib__pythonscript_c_args,
289+
gnu_symbol_visibility: 'hidden', # Used by both clang & gcc (see https://gcc.gnu.org/wiki/Visibility)
289290
dependencies: [dep_godot, dep_python],
290291
install_rpath: lib_pythonscript_rpath, # To find libpython
291292
install: true,

β€Žsrc/pythonscript.cβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
# define DLL_EXPORT __declspec(dllexport)
2121
# define DLL_IMPORT __declspec(dllimport)
2222
#else
23-
# define DLL_EXPORT
24-
# define DLL_IMPORT
23+
# define DLL_EXPORT __attribute__((visibility("default")))
24+
# define DLL_IMPORT __attribute__((visibility("default")))
2525
#endif
2626

2727
#ifdef __linux__

β€Žsrc/pythonscript_gdextension_ptrs.c.j2β€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# define DLL_EXPORT __declspec(dllexport)
55
# define DLL_IMPORT __declspec(dllimport)
66
#else
7-
# define DLL_EXPORT
8-
# define DLL_IMPORT
7+
# define DLL_EXPORT __attribute__((visibility("default")))
8+
# define DLL_IMPORT __attribute__((visibility("default")))
99
#endif
1010

1111

0 commit comments

Comments
Β (0)