From 49469ec6b999510afa50403ec3cbad7a7d99fe99 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@cryptomilk.org>
Date: Mon, 17 Feb 2020 16:33:55 +0100
Subject: [PATCH 1/6] [release-0.4] nvim:eval: Fix enum declaration for
 ListLenSpecials

Instead of declaring an enum, this creates a global variable. As gcc10
uses -fno-common by default, global variables declared with the same
name more than once is not allowed anymore revealing this issue.

Each time this header is included, we define the enum name as a global
variable.

See also https://bugzilla.redhat.com/show_bug.cgi?id=1799680
---
 src/nvim/eval/typval.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/nvim/eval/typval.h b/src/nvim/eval/typval.h
index 0b04170cac6e..7163339ae076 100644
--- a/src/nvim/eval/typval.h
+++ b/src/nvim/eval/typval.h
@@ -33,7 +33,7 @@ typedef double float_T;
 enum { DO_NOT_FREE_CNT = (INT_MAX / 2) };
 
 /// Additional values for tv_list_alloc() len argument
-enum {
+enum ListLenSpecials {
   /// List length is not known in advance
   ///
   /// To be used when there is neither a way to know how many elements will be
@@ -49,7 +49,7 @@ enum {
   ///
   /// To be used when it looks impractical to determine list length.
   kListLenMayKnow = -3,
-} ListLenSpecials;
+};
 
 /// Maximal possible value of varnumber_T variable
 #define VARNUMBER_MAX INT64_MAX

From e1cc8e8e093f8e35601ef590609edbce9d4fa793 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@cryptomilk.org>
Date: Mon, 17 Feb 2020 17:17:37 +0100
Subject: [PATCH 2/6] [release-0.4] nvim:viml: Fix enum declaration of
 ExprParserFlags

Instead of declaring an enum, this creates a global variable. As gcc10
uses -fno-common by default, global variables declared with the same
name more than once is not allowed anymore revealing this issue.

Each time this header is included, we define the enum name as a global
variable.

See also https://bugzilla.redhat.com/show_bug.cgi?id=1799680
---
 src/nvim/viml/parser/expressions.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/nvim/viml/parser/expressions.h b/src/nvim/viml/parser/expressions.h
index 23e172da75b2..838a74227182 100644
--- a/src/nvim/viml/parser/expressions.h
+++ b/src/nvim/viml/parser/expressions.h
@@ -326,7 +326,7 @@ struct expr_ast_node {
   } data;
 };
 
-enum {
+enum ExprParserFlags {
   /// Allow multiple expressions in a row: e.g. for :echo
   ///
   /// Parser will still parse only one of them though.
@@ -345,7 +345,7 @@ enum {
   //     viml_expressions_parser.c, nvim_parse_expression() flags parsing
   //     alongside with its documentation and flag sets in check_parsing()
   //     function in expressions parser functional and unit tests.
-} ExprParserFlags;
+};
 
 /// AST error definition
 typedef struct {

From 047e36695f28deb10ba32ce17ffd4b7ff662f2a1 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@cryptomilk.org>
Date: Mon, 17 Feb 2020 16:36:21 +0100
Subject: [PATCH 3/6] [release-0.4] nvim: Fix enum declaration of RemapValues

Instead of declaring an enum, this creates a global variable. As gcc10
uses -fno-common by default, global variables declared with the same
name more than once is not allowed anymore revealing this issue.

Each time this header is included, we define the enum name as a global
variable.

See also https://bugzilla.redhat.com/show_bug.cgi?id=1799680
---
 src/nvim/getchar.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/nvim/getchar.h b/src/nvim/getchar.h
index 01f60ccf4945..f0b52079aad1 100644
--- a/src/nvim/getchar.h
+++ b/src/nvim/getchar.h
@@ -10,12 +10,12 @@
 /// Values for "noremap" argument of ins_typebuf()
 ///
 /// Also used for map->m_noremap and menu->noremap[].
-enum {
+enum RemapValues {
   REMAP_YES = 0,  ///< Allow remapping.
   REMAP_NONE = -1,  ///< No remapping.
   REMAP_SCRIPT = -2,  ///< Remap script-local mappings only.
   REMAP_SKIP = -3,  ///< No remapping for first char.
-} RemapValues;
+};
 
 // Argument for flush_buffers().
 typedef enum {

From 6b38b9e4c67c4fb6b9c7ddc57d0a21779974ce1f Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@cryptomilk.org>
Date: Mon, 17 Feb 2020 16:40:37 +0100
Subject: [PATCH 4/6] [release-0.4] nvim:msgpack: Correctly set up global
 ch_before_blocking_events

gcc10 builds with -fno-common by default. This mean you can't define
a global variable with the same name twice.

See also https://bugzilla.redhat.com/show_bug.cgi?id=1799680
---
 src/nvim/msgpack_rpc/channel.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/nvim/msgpack_rpc/channel.h b/src/nvim/msgpack_rpc/channel.h
index 9ff5abdc5f55..90e1c7d48b4c 100644
--- a/src/nvim/msgpack_rpc/channel.h
+++ b/src/nvim/msgpack_rpc/channel.h
@@ -15,7 +15,7 @@
 /// HACK: os/input.c drains this queue immediately before blocking for input.
 ///       Events on this queue are async-safe, but they need the resolved state
 ///       of os_inchar(), so they are processed "just-in-time".
-MultiQueue *ch_before_blocking_events;
+EXTERN MultiQueue *ch_before_blocking_events INIT(= NULL);
 
 
 #ifdef INCLUDE_GENERATED_DECLARATIONS

From 0493fa00fa12a071e3a577d4aaa62454f86cc566 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@cryptomilk.org>
Date: Mon, 17 Feb 2020 17:29:12 +0100
Subject: [PATCH 5/6] [release-0.4] nvim: Correctly setup global channels

As gcc10 uses -fno-common by default, global variables declared with the
same name more than once is not allowed anymore revealing this issue.

We need to define it as extern to access it.

See also https://bugzilla.redhat.com/show_bug.cgi?id=1799680
---
 src/nvim/channel.c | 1 -
 src/nvim/channel.h | 2 +-
 src/nvim/main.c    | 1 +
 3 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/nvim/channel.c b/src/nvim/channel.c
index f9102fa0e238..3b7ef8346eb7 100644
--- a/src/nvim/channel.c
+++ b/src/nvim/channel.c
@@ -15,7 +15,6 @@
 #include "nvim/ascii.h"
 
 static bool did_stdio = false;
-PMap(uint64_t) *channels = NULL;
 
 /// next free id for a job or rpc channel
 /// 1 is reserved for stdio channel
diff --git a/src/nvim/channel.h b/src/nvim/channel.h
index c733e276bef2..9d26852ce532 100644
--- a/src/nvim/channel.h
+++ b/src/nvim/channel.h
@@ -85,7 +85,7 @@ struct Channel {
   bool callback_scheduled;
 };
 
-EXTERN PMap(uint64_t) *channels;
+EXTERN PMap(uint64_t) *channels INIT(= NULL);
 
 #ifdef INCLUDE_GENERATED_DECLARATIONS
 # include "channel.h.generated.h"
diff --git a/src/nvim/main.c b/src/nvim/main.c
index 1e849e6f12af..40a0ec63277e 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -10,6 +10,7 @@
 #include <msgpack.h>
 
 #include "nvim/ascii.h"
+#include "nvim/channel.h"
 #include "nvim/vim.h"
 #include "nvim/main.h"
 #include "nvim/aucmd.h"

From faaf83a49eb489b66756e08ab9fd361aa44101e5 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@cryptomilk.org>
Date: Mon, 17 Feb 2020 18:04:01 +0100
Subject: [PATCH 6/6] [release-0.4] cmake: Check for -fno-common and use it if
 available

---
 CMakeLists.txt | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2a7586350977..b6dd57862b08 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -314,6 +314,11 @@ if(UNIX)
   endif()
 endif()
 
+check_c_compiler_flag(-fno-common HAVE_FNO_COMMON)
+if (HAVE_FNO_COMMON)
+  add_compile_options(-fno-common)
+endif()
+
 check_c_compiler_flag(-fdiagnostics-color=auto HAS_DIAG_COLOR_FLAG)
 if(HAS_DIAG_COLOR_FLAG)
   if(CMAKE_GENERATOR MATCHES "Ninja")
