From 681a34cfe0847419ff7976b575681784a1885734 Mon Sep 17 00:00:00 2001 From: Liwei Ge Date: Wed, 30 Sep 2020 10:52:28 +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 | 69 ++++++++++++++++++++++++++++++++++++++ nfs-utils.spec | 10 +++++- 2 files changed, 78 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..e385d28 --- /dev/null +++ b/1001-nfs-utils-gcc10.patch @@ -0,0 +1,69 @@ +From 1eafe05616b4660fb15d106e06f0b3e18983708c Mon Sep 17 00:00:00 2001 +From: NeilBrown +Date: Fri, 7 Feb 2020 11:05:03 -0500 +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/mountd/v4root.c | 2 -- + utils/statd/statd.c | 1 + + utils/statd/statd.h | 2 +- + 5 files changed, 13 insertions(+), 8 deletions(-) + +diff --git a/utils/mountd/v4root.c b/utils/mountd/v4root.c +index d735dbf..dd9828e 100644 +--- a/utils/mountd/v4root.c ++++ b/utils/mountd/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..e4a1df4 100644 +--- a/utils/statd/statd.c ++++ b/utils/statd/statd.c +@@ -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 **); +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 + +-- +1.8.3.1 + diff --git a/nfs-utils.spec b/nfs-utils.spec index 345fa9f..ed44062 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: 46%{?dist} +Release: 46%{anolis_release}%{?dist} Epoch: 1 # group all 32bit related archs @@ -92,6 +93,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} @@ -360,6 +365,9 @@ fi %{_libdir}/libnfsidmap.so %changelog +* Thu Jan 20 2022 Weitao Zhou 2.3.3-46.0.1 +- use extern in header files when declaring global variables for compatible gcc10 build + * Wed Jul 28 2021 Steve Dickson 2.3.3-46 - mount.nfs: Fix the sloppy option processing (bz 1967883) -- Gitee From 155ba2fd01476c97ddec1883e46bddd9791d1627 Mon Sep 17 00:00:00 2001 From: Liwei Ge Date: Tue, 10 Nov 2020 04:49:45 -0500 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 | 70 +++++++++++++++++++ nfs-utils.spec | 3 + 2 files changed, 73 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..0d1973f --- /dev/null +++ b/1002-Allow-compilation-to-succeed-with-fno-common.patch @@ -0,0 +1,70 @@ +From 1eafe05616b4660fb15d106e06f0b3e18983708c Mon Sep 17 00:00:00 2001 +From: NeilBrown +Date: Fri, 7 Feb 2020 11:05:03 -0500 +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/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(-) + +diff --git a/utils/nfsdcld/cld-internal.h b/utils/nfsdcld/cld-internal.h +index 05f01be..cc283da 100644 +--- a/utils/nfsdcld/cld-internal.h ++++ b/utils/nfsdcld/cld-internal.h +@@ -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_ */ +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' }, +-- +1.8.3.1 + diff --git a/nfs-utils.spec b/nfs-utils.spec index ed44062..378b02b 100644 --- a/nfs-utils.spec +++ b/nfs-utils.spec @@ -95,6 +95,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} @@ -367,6 +369,7 @@ fi %changelog * Thu Jan 20 2022 Weitao Zhou 2.3.3-46.0.1 - use extern in header files when declaring global variables for compatible gcc10 build +- allow compilation to succeed with -fno-common * Wed Jul 28 2021 Steve Dickson 2.3.3-46 - mount.nfs: Fix the sloppy option processing (bz 1967883) -- Gitee