Skip to contentSkip to conversation

Allow compilation to succeed with -fno-common

PATCH In review NeilBrown 2 participants 2 messages Feb 5, 2020 – Feb 7, 2020

Subsystems (2)
lore
Share & tools
lore

NeilBrown

author
#0 lore raw

PATCH 1/1 Allow compilation to succeed with -fno-common

When compiled with -fno-common, global variables that are declared multple times cause an error. With -fcommon (the default), they are merged.

Declaring such variable multiple times is probably not a good idea, and is definitely not necessary.

This patch changes all the global variables defined in include files to be explicitly "extern", and where necessary, adds the variable declaration to a suitable .c file.

To test, run
CFLAGS=-fno-common ./configure
make

---
 utils/mountd/v4root.c        |  2 --
 utils/nfsdcld/cld-internal.h | 10 +++++-----
 utils/nfsdcld/nfsdcld.c      |  6 ++++++
 utils/statd/statd.c          |  1 +
 utils/statd/statd.h          |  2 +-
 5 files changed, 13 insertions(+), 8 deletions(-)
utils/mountd/v4root.c +0 -2
index d735dbfe192d..dd9828eb0c11 100644
@@ -28,8 +28,6 @@
 #include "v4root.h"
 #include "pseudoflavors.h"
 
-int v4root_needed;
-
 static nfs_export pseudo_root = {
 	.m_next = NULL,
 	.m_client = NULL,
utils/nfsdcld/cld-internal.h +5 -5
index 05f01be2105a..cc283dae9dbf 100644
@@ -35,10 +35,10 @@ struct cld_client {
 	} cl_u;
 };
 
-uint64_t current_epoch;
-uint64_t recovery_epoch;
-int first_time;
-int num_cltrack_records;
-int num_legacy_records;
+extern uint64_t current_epoch;
+extern uint64_t recovery_epoch;
+extern int first_time;
+extern int num_cltrack_records;
+extern int num_legacy_records;
 
 #endif /* _CLD_INTERNAL_H_ */
utils/nfsdcld/nfsdcld.c +6 -0
index 2ad1001988d2..be6556262504 100644
@@ -69,6 +69,12 @@ static int 		inotify_fd = -1;
 static struct event	pipedir_event;
 static bool old_kernel = false;
 
+uint64_t current_epoch;
+uint64_t recovery_epoch;
+int first_time;
+int num_cltrack_records;
+int num_legacy_records;
+
 static struct option longopts[] =
 {
 	{ "help", 0, NULL, 'h' },
utils/statd/statd.c +1 -0
index 8eef2ff24fe8..e4a1df43b73f 100644
@@ -67,6 +67,7 @@ static struct option longopts[] =
 };
 
 extern void sm_prog_1 (struct svc_req *, register SVCXPRT *);
+stat_chge	SM_stat_chge;
 
 #ifdef SIMULATIONS
 extern void simulator (int, char **);
utils/statd/statd.h +1 -1
index 231ac7e0764b..bb1fecbb6a51 100644
@@ -41,7 +41,7 @@ extern void	load_state(void);
 /*
  * Host status structure and macros.
  */
-stat_chge		SM_stat_chge;
+extern stat_chge	SM_stat_chge;
 #define MY_NAME		SM_stat_chge.mon_name
 #define MY_STATE	SM_stat_chge.state
 
Signature · 1 line
2.24.1
#1 lore raw
Quoted 12 lines · NeilBrown

When compiled with -fno-common, global variables that are declared multple times cause an error. With -fcommon (the default), they are merged.

Declaring such variable multiple times is probably not a good idea, and is definitely not necessary.

This patch changes all the global variables defined in include files to be explicitly "extern", and where necessary, adds the variable declaration to a suitable .c file.

Quoted 5 lines

To test, run
CFLAGS=-fno-common ./configure
make

Committed... (tag: nfs-utils-2-4-3-rc7)

Quoted 84 lines
---
 utils/mountd/v4root.c        |  2 --
 utils/nfsdcld/cld-internal.h | 10 +++++-----
 utils/nfsdcld/nfsdcld.c      |  6 ++++++
 utils/statd/statd.c          |  1 +
 utils/statd/statd.h          |  2 +-
 5 files changed, 13 insertions(+), 8 deletions(-)
utils/mountd/v4root.c +0 -2
index d735dbfe192d..dd9828eb0c11 100644
@@ -28,8 +28,6 @@
 #include "v4root.h"
 #include "pseudoflavors.h"
 
-int v4root_needed;
-
 static nfs_export pseudo_root = {
 	.m_next = NULL,
 	.m_client = NULL,
utils/nfsdcld/cld-internal.h +5 -5
index 05f01be2105a..cc283dae9dbf 100644
@@ -35,10 +35,10 @@ struct cld_client {
 	} cl_u;
 };
 
-uint64_t current_epoch;
-uint64_t recovery_epoch;
-int first_time;
-int num_cltrack_records;
-int num_legacy_records;
+extern uint64_t current_epoch;
+extern uint64_t recovery_epoch;
+extern int first_time;
+extern int num_cltrack_records;
+extern int num_legacy_records;
 
 #endif /* _CLD_INTERNAL_H_ */
utils/nfsdcld/nfsdcld.c +6 -0
index 2ad1001988d2..be6556262504 100644
@@ -69,6 +69,12 @@ static int 		inotify_fd = -1;
 static struct event	pipedir_event;
 static bool old_kernel = false;
 
+uint64_t current_epoch;
+uint64_t recovery_epoch;
+int first_time;
+int num_cltrack_records;
+int num_legacy_records;
+
 static struct option longopts[] =
 {
 	{ "help", 0, NULL, 'h' },
utils/statd/statd.c +1 -0
index 8eef2ff24fe8..e4a1df43b73f 100644
@@ -67,6 +67,7 @@ static struct option longopts[] =
 };
 
 extern void sm_prog_1 (struct svc_req *, register SVCXPRT *);
+stat_chge	SM_stat_chge;
 
 #ifdef SIMULATIONS
 extern void simulator (int, char **);
utils/statd/statd.h +1 -1
index 231ac7e0764b..bb1fecbb6a51 100644
@@ -41,7 +41,7 @@ extern void	load_state(void);
 /*
  * Host status structure and macros.
  */
-stat_chge		SM_stat_chge;
+extern stat_chge	SM_stat_chge;
 #define MY_NAME		SM_stat_chge.mon_name
 #define MY_STATE	SM_stat_chge.state