From: Simon McVittie Date: Fri, 22 Aug 2025 19:21:22 +0100 Subject: build: Export only the symbols that need to be exported On Windows, by default symbols are not exported from DLLs unless we explicitly ask for it (via `Q_EXPORT`), and by default symbols in the executable will not "interpose" in front of symbols of the same name in a DLL. However, on ELF platforms such as Linux, for historical reasons neither of these is true. Request more reasonable semantics. This is good for library size and performance, because every function call to an exported symbol needs to be done indirectly, in case some other module is interposing it. It is also good for correctness, because if we don't do this, a global variable in native-code game modules like `qagame.so` can be unexpectedly replaced with a global variable in the executable or in a different library that happens to have the same name, even if it has a different type (which in practice will lead to a crash). Bug: https://github.com/ioquake/ioq3/issues/765 Bug-Debian: https://bugs.debian.org/1111671 Forwarded: not-needed, done differently upstream in OAX --- Makefile | 1 + code/cgame/cg_main.c | 2 +- code/cgame/cg_syscalls.c | 2 +- code/game/g_main.c | 2 +- code/q3_ui/ui_main.c | 4 ++-- code/ui/ui_main.c | 2 +- code/ui/ui_syscalls.c | 2 +- 7 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 521ea75..df76d8c 100644 --- a/Makefile +++ b/Makefile @@ -227,6 +227,7 @@ ifneq (,$(findstring "$(PLATFORM)", "linux" "gnu_kfreebsd" "kfreebsd-gnu" "gnu") BASE_CFLAGS = -Wall -fno-strict-aliasing -Wimplicit -Wstrict-prototypes \ -pipe -DUSE_ICON $(SDL_CFLAGS) -DARCH_STRING=\\\"$(ARCH)\\\" + BASE_CFLAGS += -fvisibility=hidden ifeq ($(USE_OPENAL),1) BASE_CFLAGS += -DUSE_OPENAL diff --git a/code/cgame/cg_main.c b/code/cgame/cg_main.c index a271d29..deb2545 100644 --- a/code/cgame/cg_main.c +++ b/code/cgame/cg_main.c @@ -43,7 +43,7 @@ This is the only way control passes into the module. This must be the very first function compiled into the .q3vm file ================ */ -intptr_t vmMain( int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11 ) { +Q_EXPORT intptr_t vmMain( int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11 ) { switch ( command ) { case CG_INIT: diff --git a/code/cgame/cg_syscalls.c b/code/cgame/cg_syscalls.c index 4823d67..5e9d0e0 100644 --- a/code/cgame/cg_syscalls.c +++ b/code/cgame/cg_syscalls.c @@ -31,7 +31,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA static intptr_t (QDECL *syscall)( intptr_t arg, ... ) = (intptr_t (QDECL *)( intptr_t, ...))-1; -void dllEntry( intptr_t (QDECL *syscallptr)( intptr_t arg,... ) ) { +Q_EXPORT void dllEntry( intptr_t (QDECL *syscallptr)( intptr_t arg,... ) ) { syscall = syscallptr; } diff --git a/code/game/g_main.c b/code/game/g_main.c index 426973e..3f3d08f 100644 --- a/code/game/g_main.c +++ b/code/game/g_main.c @@ -418,7 +418,7 @@ This is the only way control passes into the module. This must be the very first function compiled into the .q3vm file ================ */ -intptr_t vmMain( int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11 ) { +Q_EXPORT intptr_t vmMain( int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11 ) { switch ( command ) { case GAME_INIT: G_InitGame( arg0, arg1, arg2 ); diff --git a/code/q3_ui/ui_main.c b/code/q3_ui/ui_main.c index c18bb6a..3960976 100644 --- a/code/q3_ui/ui_main.c +++ b/code/q3_ui/ui_main.c @@ -40,7 +40,7 @@ This is the only way control passes into the module. This must be the very first function compiled into the .qvm file ================ */ -intptr_t vmMain( int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11 ) { +Q_EXPORT intptr_t vmMain( int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11 ) { switch ( command ) { case UI_GETAPIVERSION: return UI_API_VERSION; @@ -327,4 +327,4 @@ void UI_UpdateCvars( void ) { void UI_SetDefaultCvar(const char* cvar, const char* value) { if(strlen(UI_Cvar_VariableString(cvar)) == 0) trap_Cvar_Set(cvar,value); -} \ No newline at end of file +} diff --git a/code/ui/ui_main.c b/code/ui/ui_main.c index fd5505a..fd03fb5 100644 --- a/code/ui/ui_main.c +++ b/code/ui/ui_main.c @@ -176,7 +176,7 @@ void _UI_KeyEvent( int key, qboolean down ); void _UI_MouseEvent( int dx, int dy ); void _UI_Refresh( int realtime ); qboolean _UI_IsFullscreen( void ); -intptr_t vmMain( int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11 ) { +Q_EXPORT intptr_t vmMain( int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11 ) { switch ( command ) { case UI_GETAPIVERSION: return UI_API_VERSION; diff --git a/code/ui/ui_syscalls.c b/code/ui/ui_syscalls.c index 77c14eb..3ebd480 100644 --- a/code/ui/ui_syscalls.c +++ b/code/ui/ui_syscalls.c @@ -30,7 +30,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA static intptr_t (QDECL *syscall)( intptr_t arg, ... ) = (intptr_t (QDECL *)( intptr_t, ...))-1; -void dllEntry( intptr_t (QDECL *syscallptr)( intptr_t arg,... ) ) { +Q_EXPORT void dllEntry( intptr_t (QDECL *syscallptr)( intptr_t arg,... ) ) { syscall = syscallptr; }