From ca32447d75cd8f21b9b6da831f0d709149d502f0 Mon Sep 17 00:00:00 2001 From: pangqing Date: Tue, 26 Apr 2022 17:07:07 +0800 Subject: [PATCH 1/2] [gcc10] use extern in header files when declaring global variables to fix gcc10 "multiple definitions" warning A common mistake in C is omitting extern when declaring a global variable in a header file. If the header is included by several files it results in multiple definitions of the same variable. In previous GCC versions this error is ignored. GCC 10 defaults to -fno-common, which means a linker error will now be reported. To fix this, use extern in header files when declaring global variables, and ensure each global is defined in exactly one C file. If tentative definitions of particular variables need to be placed in a common block, __attribute__((__common__)) can be used to force that behavior even in code compiled without -fcommon. As a workaround, legacy C code where all tentative definitions should be placed into a common block can be compiled with -fcommon. int x; // tentative definition - avoid in header files extern int y; // correct declaration in a header file this change has given better compatible with gcc10 toolchain, should be maintained util upstream fixes 'multiple definition ...' warnings Signed-off-by: weitao zhou --- 1001-nfs-utils-gcc10.patch | 68 ++++++++++++++++++++++++++++++++++++++ nfs-utils.spec | 10 +++++- 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 1001-nfs-utils-gcc10.patch diff --git a/1001-nfs-utils-gcc10.patch b/1001-nfs-utils-gcc10.patch new file mode 100644 index 0000000..609b063 --- /dev/null +++ b/1001-nfs-utils-gcc10.patch @@ -0,0 +1,68 @@ +From 80a9ea81f54fb6bd2147fa247cb06515990deb19 Mon Sep 17 00:00:00 2001 +From: NeilBrown +Date: Tue, 26 Apr 2022 16:53:23 +0800 +Subject: [PATCH] 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 +Signed-off-by: NeilBrown +Signed-off-by: Steve Dickson +--- + support/export/v4root.c | 2 -- + utils/statd/statd.c | 2 ++ + utils/statd/statd.h | 2 +- + 3 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/support/export/v4root.c b/support/export/v4root.c +index 4d33117..3654bd7 100644 +--- a/support/export/v4root.c ++++ b/support/export/v4root.c +@@ -28,8 +28,6 @@ + #include "v4root.h" + #include "pseudoflavors.h" + +-int v4root_needed; +- + static nfs_export pseudo_root = { + .m_next = NULL, + .m_client = NULL, +diff --git a/utils/statd/statd.c b/utils/statd/statd.c +index 8eef2ff..665b0fe 100644 +--- a/utils/statd/statd.c ++++ b/utils/statd/statd.c +@@ -68,6 +68,8 @@ 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 **); + #endif +diff --git a/utils/statd/statd.h b/utils/statd/statd.h +index 231ac7e..bb1fecb 100644 +--- a/utils/statd/statd.h ++++ b/utils/statd/statd.h +@@ -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 + +-- +2.18.4 + diff --git a/nfs-utils.spec b/nfs-utils.spec index f8fe8a2..3ab8c14 100644 --- a/nfs-utils.spec +++ b/nfs-utils.spec @@ -1,8 +1,9 @@ +%define anolis_release .0.1 Summary: NFS utilities and supporting clients and daemons for the kernel NFS server Name: nfs-utils URL: http://linux-nfs.org/ Version: 2.3.3 -Release: 50%{?dist} +Release: 50%{anolis_release}%{?dist} Epoch: 1 # group all 32bit related archs @@ -97,6 +98,10 @@ Patch102: nfs-utils-2.3.3-idmap-errmsg.patch Patch103: nfs-utils-2.3.1-systemd-gssproxy-restart.patch Patch104: nfs-utils-2.3.1-systemd-svcgssd-removed.patch +# Begin: Anolis customized patches +Patch1001: 1001-nfs-utils-gcc10.patch +# End: Anolis customized patches + Provides: exportfs = %{epoch}:%{version}-%{release} Provides: nfsstat = %{epoch}:%{version}-%{release} Provides: showmount = %{epoch}:%{version}-%{release} @@ -365,6 +370,9 @@ fi %{_libdir}/libnfsidmap.so %changelog +* Tue Apr 26 2022 Weitao Zhou 2.3.3-50.0.1 +- use extern in header files when declaring global variables for compatible gcc10 build + * Sat Feb 19 2022 Steve Dickson 2.3.3-50 - mount.nfs: Fix Typo auto negotiating code. (bz 1946346) -- Gitee From 215e4ab9da1b3c8dec964eb89fa0e9dbf6f0b119 Mon Sep 17 00:00:00 2001 From: pangqing Date: Tue, 26 Apr 2022 17:10:39 +0800 Subject: [PATCH 2/2] Allow compilation to succeed with -fno-common this change has given better compatible with both gcc8 and gcc10 toolchain, should be maintained util upstream fixes 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 Signed-off-by: Liwei Ge Signed-off-by: weitao zhou --- ...mpilation-to-succeed-with-fno-common.patch | 66 +++++++++++++++++++ nfs-utils.spec | 3 + 2 files changed, 69 insertions(+) create mode 100644 1002-Allow-compilation-to-succeed-with-fno-common.patch diff --git a/1002-Allow-compilation-to-succeed-with-fno-common.patch b/1002-Allow-compilation-to-succeed-with-fno-common.patch new file mode 100644 index 0000000..a9c7dc9 --- /dev/null +++ b/1002-Allow-compilation-to-succeed-with-fno-common.patch @@ -0,0 +1,66 @@ +From 050d33d0c81fe82d004fe75b25415232e110756e Mon Sep 17 00:00:00 2001 +From: NeilBrown +Date: Tue, 26 Apr 2022 17:02:57 +0800 +Subject: [PATCH] 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 + +Signed-off-by: NeilBrown +Signed-off-by: Steve Dickson +--- + utils/nfsdcld/cld-internal.h | 11 +++++------ + utils/nfsdcld/nfsdcld.c | 6 ++++++ + 2 files changed, 11 insertions(+), 6 deletions(-) + +diff --git a/utils/nfsdcld/cld-internal.h b/utils/nfsdcld/cld-internal.h +index 05f01be..e8216c9 100644 +--- a/utils/nfsdcld/cld-internal.h ++++ b/utils/nfsdcld/cld-internal.h +@@ -35,10 +35,9 @@ 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_ */ +diff --git a/utils/nfsdcld/nfsdcld.c b/utils/nfsdcld/nfsdcld.c +index 2ad1001..be65562 100644 +--- a/utils/nfsdcld/nfsdcld.c ++++ b/utils/nfsdcld/nfsdcld.c +@@ -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' }, +-- +2.18.4 + diff --git a/nfs-utils.spec b/nfs-utils.spec index 3ab8c14..14ae3a4 100644 --- a/nfs-utils.spec +++ b/nfs-utils.spec @@ -100,6 +100,8 @@ Patch104: nfs-utils-2.3.1-systemd-svcgssd-removed.patch # Begin: Anolis customized patches Patch1001: 1001-nfs-utils-gcc10.patch +# backport patch from upstream +Patch1002: 1002-Allow-compilation-to-succeed-with-fno-common.patch # End: Anolis customized patches Provides: exportfs = %{epoch}:%{version}-%{release} @@ -371,6 +373,7 @@ fi %changelog * Tue Apr 26 2022 Weitao Zhou 2.3.3-50.0.1 +- allow compilation to succeed with -fno-common - use extern in header files when declaring global variables for compatible gcc10 build * Sat Feb 19 2022 Steve Dickson 2.3.3-50 -- Gitee