Skip to content

Commit d14bd22

Browse files
committed
loader: Export core symbols only.
1 parent 7ac7285 commit d14bd22

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/loader/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ if(WIN32)
3535
set(openxr_loader_RESOURCE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/loader.rc)
3636
endif()
3737

38+
if(NOT MSVC)
39+
set(CMAKE_C_VISIBILITY_PRESET hidden)
40+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
41+
endif()
42+
3843
# List of all files externally generated outside of the loader that the loader
3944
# needs to build with.
4045
SET(LOADER_EXTERNAL_GEN_FILES
@@ -188,6 +193,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
188193
target_compile_options(openxr_loader
189194
PRIVATE -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wpointer-arith
190195
PRIVATE -fno-strict-aliasing -fno-builtin-memcmp "$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>"
196+
-ffunction-sections -fdata-sections
191197
)
192198
# For GCC version 7.1 or greater, we need to disable the implicit fallthrough warning since
193199
# there's no consistent way to satisfy all compilers until they all accept the C++17 standard

src/loader/loader_platform.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#define LOADER_EXPORT __attribute__((visibility("default")))
3232
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
3333
#define LOADER_EXPORT __attribute__((visibility("default")))
34+
#elif defined(_WIN32) && defined(XRAPI_DLL_EXPORT)
35+
#define LOADER_EXPORT __declspec(dllexport)
3436
#else
3537
#define LOADER_EXPORT
3638
#endif

src/scripts/loader_source_generator.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def beginFile(self, genOpts):
126126
preamble += '#include "openxr/openxr_platform.h"\n\n'
127127
preamble += '#include "loader_interfaces.h"\n\n'
128128
preamble += '#include "loader_instance.hpp"\n\n'
129+
preamble += '#include "loader_platform.hpp"\n\n'
129130

130131
elif self.genOpts.filename == 'xr_generated_loader.cpp':
131132
preamble += '#include "xr_generated_loader.hpp"\n\n'
@@ -208,6 +209,11 @@ def outputLoaderManualFuncs(self):
208209
# Use the Cdecl directly from the XML
209210
func_proto = cur_cmd.cdecl
210211

212+
# Export only core functions
213+
if self.isCoreExtensionName(cur_cmd.ext_name):
214+
func_proto = func_proto.replace(
215+
"XRAPI_ATTR", "LOADER_EXPORT XRAPI_ATTR")
216+
211217
# Output the standard API form of the command
212218
manual_funcs += func_proto
213219
manual_funcs += '\n'
@@ -487,8 +493,14 @@ def outputLoaderGeneratedFuncs(self):
487493

488494
if cur_cmd.protect_value:
489495
generated_funcs += '#if %s\n' % cur_cmd.protect_string
496+
decl = cur_cmd.cdecl.replace(";", " XRLOADER_ABI_TRY {\n")
497+
498+
# Export only core functions
499+
if self.isCoreExtensionName(cur_cmd.ext_name):
500+
decl = decl.replace(
501+
"XRAPI_ATTR", "LOADER_EXPORT XRAPI_ATTR")
490502

491-
generated_funcs += cur_cmd.cdecl.replace(";", " XRLOADER_ABI_TRY {\n")
503+
generated_funcs += decl
492504
generated_funcs += tramp_variable_defines
493505

494506
# If this is not core, but an extension, check to make sure the extension is enabled.

0 commit comments

Comments
 (0)