Allow compilation to succeed with -fno-common
Subsystems (2)
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
@@ -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
@@ -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
@@ -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
@@ -67,6 +67,7 @@ static struct option longopts[] = };extern void sm_prog_1 (struct svc_req *, registerSVCXPRT *); +stat_chge SM_stat_chge;#ifdef SIMULATIONS extern void simulator (int ,char **);
utils/statd/statd.h +1 -1
@@ -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
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
makeSigned-off-by NeilBrown <[email protected]>
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@@ -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@@ -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@@ -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@@ -67,6 +67,7 @@ static struct option longopts[] = };extern void sm_prog_1 (struct svc_req *, registerSVCXPRT *); +stat_chge SM_stat_chge;#ifdef SIMULATIONS extern void simulator (int ,char **);utils/statd/statd.h +1
-1@@ -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