| 1 |
From: Simon McVittie <[email protected]> |
| 2 |
Date: Mon, 10 Aug 2020 10:26:48 +0100 |
| 3 |
Subject: Avoid multiple definitions of some global variables |
| 4 |
|
| 5 |
gcc 10 defaults to -fno-common, which means that the same global |
| 6 |
variable being defined by multiple translation units (roughly, C source |
| 7 |
files) causes a linking error. This is similar to the behaviour of |
| 8 |
global functions, and C++'s "one-definition rule". The way to get a |
| 9 |
global variable shared between translation units is to declare it as |
| 10 |
extern (usually in a header file), and then ensure that exactly one |
| 11 |
translation unit contains a definition. |
| 12 |
|
| 13 |
Signed-off-by: Simon McVittie <[email protected]> |
| 14 |
Bug-Debian: https://bugs.debian.org/957237 |
| 15 |
Forwarded: no |
| 16 |
--- |
| 17 |
qcc.h | 2 ++ |
| 18 |
qcc_pr_comp.c | 2 -- |
| 19 |
2 files changed, 2 insertions(+), 2 deletions(-) |
| 20 |
|
| 21 |
diff --git a/qcc.h b/qcc.h |
| 22 |
index 41736bc..9579613 100644 |
| 23 |
--- a/qcc.h |
| 24 |
+++ b/qcc.h |
| 25 |
@@ -279,6 +279,8 @@ There are no ++ / -- operators, or operate/assign operators. |
| 26 |
#include "hash.h" |
| 27 |
extern hashtable_t compconstantstable; |
| 28 |
extern hashtable_t globalstable, localstable; |
| 29 |
+extern hashtable_t floatconstdefstable; |
| 30 |
+extern hashtable_t stringconstdefstable; |
| 31 |
#endif |
| 32 |
|
| 33 |
#ifdef WRITEASM |
| 34 |
diff --git a/qcc_pr_comp.c b/qcc_pr_comp.c |
| 35 |
index c0f91cb..40020f6 100644 |
| 36 |
--- a/qcc_pr_comp.c |
| 37 |
+++ b/qcc_pr_comp.c |
| 38 |
@@ -3731,7 +3731,6 @@ QCC_def_t *QCC_MakeVectorDef(float a, float b, float c) |
| 39 |
return cn; |
| 40 |
} |
| 41 |
|
| 42 |
-hashtable_t floatconstdefstable; |
| 43 |
QCC_def_t *QCC_MakeFloatDef(float value) |
| 44 |
{ |
| 45 |
QCC_def_t *cn; |
| 46 |
@@ -3773,7 +3772,6 @@ QCC_def_t *QCC_MakeFloatDef(float value) |
| 47 |
return cn; |
| 48 |
} |
| 49 |
|
| 50 |
-hashtable_t stringconstdefstable; |
| 51 |
QCC_def_t *QCC_MakeStringDef(char *value) |
| 52 |
{ |
| 53 |
QCC_def_t *cn; |