From 34fb5f2ee6e3c3b3a7c3cbc5032845fa736271a4 Mon Sep 17 00:00:00 2001 From: Liwei Ge Date: Sun, 27 Sep 2020 21:00:46 +0800 Subject: [PATCH] use extern in header files when declaring global variables this change has given better compatible with both gcc8 and gcc10 toolchain, should be maintained util upstream fixes 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: Mingyue Zhao Signed-off-by: weitao zhou --- ...on.h-avoid-redefinition-of-last_sele.patch | 41 +++++++++++++++++++ gpm.spec | 14 ++++++- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 1001-src-headers-daemon.h-avoid-redefinition-of-last_sele.patch diff --git a/1001-src-headers-daemon.h-avoid-redefinition-of-last_sele.patch b/1001-src-headers-daemon.h-avoid-redefinition-of-last_sele.patch new file mode 100644 index 0000000..9011890 --- /dev/null +++ b/1001-src-headers-daemon.h-avoid-redefinition-of-last_sele.patch @@ -0,0 +1,41 @@ +From f04f24dd5ca5c1c13608b144ab66e2ccd47f106a Mon Sep 17 00:00:00 2001 +From: Sergei Trofimovich +Date: Sun, 19 Jan 2020 19:53:41 +0000 +Subject: [PATCH] src/headers/daemon.h: avoid redefinition of + 'last_selection_time' + +Noticed build failure on gcc-10 as: + +``` +gcc -L/home/slyfox/dev/git/gpm/src -o gpm mice.o ... report.o tools.o -lm +ld: twiddler.o:gpm/src/headers/daemon.h:183: + multiple definition of `last_selection_time'; mice.o:gpm/src/headers/daemon.h:183: first defined here +ld: synaptics.o:git/gpm/src/headers/daemon.h:183: + multiple definition of `last_selection_time'; mice.o:git/gpm/src/headers/daemon.h:183: first defined here +``` + +gcc-10 will change the default from -fcommon to fno-common: +https://gcc.gnu.org/PR85678. + +The error also happens if CFLAGS=-fno-common passed explicitly. + +Signed-off-by: Sergei Trofimovich +--- + src/headers/daemon.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/headers/daemon.h b/src/headers/daemon.h +index a8936ad..24a1a97 100644 +--- a/src/headers/daemon.h ++++ b/src/headers/daemon.h +@@ -180,7 +180,7 @@ extern struct mouse_features mouse_table[3], + extern Gpm_Type mice[]; + extern Gpm_Type *repeated_type; + +-time_t last_selection_time; ++extern time_t last_selection_time; + + + +-- +1.8.3.1 diff --git a/gpm.spec b/gpm.spec index 9cfe207..674e808 100644 --- a/gpm.spec +++ b/gpm.spec @@ -1,7 +1,8 @@ +%define anolis_release .0.1 Summary: A mouse server for the Linux console Name: gpm Version: 1.20.7 -Release: 17%{?dist} +Release: 17%{anolis_release}%{?dist} License: GPLv2 and GPLv2+ with exceptions and GPLv3+ and Verbatim and Copyright only Group: System Environment/Daemons URL: http://www.nico.schottelius.org/software/gpm/ @@ -30,6 +31,13 @@ Patch10: gpm-1.20.7-sysmacros.patch # Include patch from upstream pull request: https://github.com/telmich/gpm/pull/20 Patch11: gpm-1.20.7-sigemptyset.patch #Patch7: gpm-1.20.6-capability.patch + + +# Begin: Anolis customized patches +# backport patch from https://github.com/telmich/gpm/commit/f04f24dd5ca5c1c13608b144ab66e2ccd47f106a +Patch1001: 1001-src-headers-daemon.h-avoid-redefinition-of-last_sele.patch +# End: Anolis customized patches + Requires(post): systemd systemd-sysv info Requires(preun): systemd info Requires(postun): systemd @@ -92,6 +100,7 @@ mouse support to text-based Linux applications. #%%patch7 -p1 -b .capability +%patch1001 -p1 %build ./autogen.sh %configure @@ -169,6 +178,9 @@ fi %{_libdir}/libgpm.a %changelog +* Thu Dec 09 2021 Weitao Zhou 1.20.7-17.0.1 +- use extern in header files when declaring global variables for compatible gcc10 build + * Mon Jan 18 2021 Jiri Kucera - 1.20.7-17 - Put autogen.sh to proper place Related: #1854555 -- Gitee