From 91266bcdbefe928eeb524cfa622f0077b3d18b71 Mon Sep 17 00:00:00 2001 From: Liwei Ge Date: Tue, 29 Sep 2020 13:18:56 +0800 Subject: [PATCH] Fix gcc10 -fno-common compile issue this change has given better compatible with gcc10 toolchain, should be maintained util upstream fixes 'multiple definition ...' warnings Default to -fno-common 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 refer url: https://gcc.gnu.org/gcc-10/porting_to.html Signed-off-by: Liwei Ge Signed-off-by: weitao zhou --- lldpad.spec | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lldpad.spec b/lldpad.spec index 0318062..f4d7252 100755 --- a/lldpad.spec +++ b/lldpad.spec @@ -1,3 +1,4 @@ +%define anolis_release .0.1 %global _default_patch_fuzz 2 # https://fedoraproject.org/wiki/Packaging:Guidelines#Compiler_flags @@ -7,7 +8,7 @@ Name: lldpad Version: 1.0.1 -Release: 16.git%{checkout}%{?dist} +Release: 16.git%{checkout}%{anolis_release}%{?dist} Summary: Intel LLDP Agent Group: System Environment/Daemons License: GPLv2 @@ -78,7 +79,7 @@ that use %{name}. %build ./bootstrap.sh -CFLAGS=${CFLAGS:-%optflags -Wno-error}; export CFLAGS; +CFLAGS=${CFLAGS:-%optflags -Wno-error -fcommon}; export CFLAGS; %configure --disable-static # fix the hardened build flags sed -i -e 's! \\\$compiler_flags !&\\\$CFLAGS \\\$LDFLAGS !' libtool @@ -117,6 +118,9 @@ rm -f %{buildroot}%{_libdir}/liblldp_clif.la %{_libdir}/liblldp_clif.so %changelog +* Thu Jan 20 2022 Weitao Zhou - 1.0.1-16.git036e314.0.1 +- Fix gcc10 -fno-common compile issue for compatible with gcc10 build + * Wed Aug 04 2021 Aaron Conole - 1.0.1-16.git036e314 - Update the changelog -- Gitee