From: Simon McVittie <smcv@debian.org>
Date: Mon, 10 Aug 2020 10:26:48 +0100
Subject: Avoid multiple definitions of some global variables

gcc 10 defaults to -fno-common, which means that the same global
variable being defined by multiple translation units (roughly, C source
files) causes a linking error. This is similar to the behaviour of
global functions, and C++'s "one-definition rule". The way to get a
global variable shared between translation units is to declare it as
extern (usually in a header file), and then ensure that exactly one
translation unit contains a definition.

Signed-off-by: Simon McVittie <smcv@debian.org>
Bug-Debian: https://bugs.debian.org/957237
Forwarded: no
---
 qcc.h         | 30 +++++++++++++++---------------
 qcc_pr_comp.c |  4 ++--
 qcc_pr_lex.c  |  2 +-
 qccmain.c     |  5 +++++
 4 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/qcc.h b/qcc.h
index 75b2b37..beffb28 100644
--- a/qcc.h
+++ b/qcc.h
@@ -282,7 +282,7 @@ extern hashtable_t globalstable, localstable;
 #endif
 
 #ifdef WRITEASM
-FILE *asmfile;
+extern FILE *asmfile;
 #endif
 //=============================================================================
 
@@ -837,23 +837,23 @@ extern int numtemps;
 
 typedef char PATHSTRING[MAX_DATA_PATH];
 
-PATHSTRING		*precache_sounds;
-int			*precache_sounds_block;
-int			*precache_sounds_used;
-int			numsounds;
+extern PATHSTRING		*precache_sounds;
+extern int			*precache_sounds_block;
+extern int			*precache_sounds_used;
+extern int			numsounds;
 
-PATHSTRING		*precache_textures;
-int			*precache_textures_block;
-int			numtextures;
+extern PATHSTRING		*precache_textures;
+extern int			*precache_textures_block;
+extern int			numtextures;
 
-PATHSTRING		*precache_models;
-int			*precache_models_block;
-int			*precache_models_used;
-int			nummodels;
+extern PATHSTRING		*precache_models;
+extern int			*precache_models_block;
+extern int			*precache_models_used;
+extern int			nummodels;
 
-PATHSTRING		*precache_files;
-int			*precache_files_block;
-int			numfiles;
+extern PATHSTRING		*precache_files;
+extern int			*precache_files_block;
+extern int			numfiles;
 
 int	QCC_CopyString (char *str);
 
diff --git a/qcc_pr_comp.c b/qcc_pr_comp.c
index cb7abd2..ada8a05 100644
--- a/qcc_pr_comp.c
+++ b/qcc_pr_comp.c
@@ -3731,7 +3731,7 @@ QCC_def_t *QCC_MakeVectorDef(float a, float b, float c)
 	return cn;
 }
 
-hashtable_t floatconstdefstable;
+extern hashtable_t floatconstdefstable;
 QCC_def_t *QCC_MakeFloatDef(float value)
 {
 	QCC_def_t	*cn;
@@ -3773,7 +3773,7 @@ QCC_def_t *QCC_MakeFloatDef(float value)
 	return cn;
 }
 
-hashtable_t stringconstdefstable;
+extern hashtable_t stringconstdefstable;
 QCC_def_t *QCC_MakeStringDef(char *value)
 {
 	QCC_def_t	*cn;
diff --git a/qcc_pr_lex.c b/qcc_pr_lex.c
index 6b442bc..0d4a37e 100644
--- a/qcc_pr_lex.c
+++ b/qcc_pr_lex.c
@@ -95,7 +95,7 @@ typedef struct qcc_includechunk_s {
 	int currentlinenumber;
 	CompilerConstant_t *cnst;
 } qcc_includechunk_t;
-qcc_includechunk_t *currentchunk;
+extern qcc_includechunk_t *currentchunk;
 void QCC_PR_IncludeChunkEx (char *data, pbool duplicate, char *filename, CompilerConstant_t *cnst)
 {
 	qcc_includechunk_t *chunk = qccHunkAlloc(sizeof(qcc_includechunk_t));
diff --git a/qccmain.c b/qccmain.c
index 48d1994..c051b65 100644
--- a/qccmain.c
+++ b/qccmain.c
@@ -14,6 +14,9 @@ extern int optres_test1;
 extern int optres_test2;
 
 int writeasm;
+#ifdef WRITEASM
+FILE *asmfile;
+#endif
 static pbool pr_werror;
 
 
@@ -74,6 +77,7 @@ int			numfielddefs;
 
 PATHSTRING		*precache_sounds;
 int			*precache_sounds_block;
+int			*precache_sounds_used;
 int			numsounds;
 
 PATHSTRING		*precache_textures;
@@ -82,6 +86,7 @@ int			numtextures;
 
 PATHSTRING		*precache_models;
 int			*precache_models_block;
+int			*precache_models_used;
 int			nummodels;
 
 PATHSTRING		*precache_files;
