From 88c0b8a2d7b5cdb1b8197bc25317056e986436d1 Mon Sep 17 00:00:00 2001 From: Jacob Wang Date: Tue, 29 Sep 2020 16:50:16 +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: Jacob Wang Signed-off-by: Liwei Ge Signed-off-by: weitao zhou --- 1001-gcc-10-compatibility.patch | 94 +++++++++++++++++++++++++++++++++ syslinux.spec | 10 +++- 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 1001-gcc-10-compatibility.patch diff --git a/1001-gcc-10-compatibility.patch b/1001-gcc-10-compatibility.patch new file mode 100644 index 0000000..3bc49a3 --- /dev/null +++ b/1001-gcc-10-compatibility.patch @@ -0,0 +1,94 @@ +From: Lukas Schwaighofer +Date: Wed, 22 Jul 2020 15:54:20 +0200 +Subject: GCC-10 compatibility patch + +* Add `-fcommon` to most gcc invocations to allow duplicate definitions +* __builtin_strlen seems to fall back to calling strlen if the string in + question is not const and cannot be evaluated at compile time. Work + around the issue by supplying an inline function. The strlen function + was copied from com32/lib/strlen.c. +--- + dos/string.h | 11 ++++++++++- + mk/efi.mk | 1 + + mk/elf.mk | 1 + + mk/embedded.mk | 2 +- + mk/lib.mk | 2 +- + 5 files changed, 14 insertions(+), 3 deletions(-) + +diff --git a/dos/string.h b/dos/string.h +index f648de2..c4649f5 100644 +--- a/dos/string.h ++++ b/dos/string.h +@@ -5,12 +5,21 @@ + #ifndef _STRING_H + #define _STRING_H + ++#include ++ + /* Standard routines */ + #define memcpy(a,b,c) __builtin_memcpy(a,b,c) + #define memmove(a,b,c) __builtin_memmove(a,b,c) + #define memset(a,b,c) __builtin_memset(a,b,c) + #define strcpy(a,b) __builtin_strcpy(a,b) +-#define strlen(a) __builtin_strlen(a) ++ ++static inline size_t strlen(const char *s) ++{ ++ const char *ss = s; ++ while (*ss) ++ ss++; ++ return ss - s; ++} + + /* This only returns true or false */ + static inline int memcmp(const void *__m1, const void *__m2, unsigned int __n) +diff --git a/mk/efi.mk b/mk/efi.mk +index dc2b708..f1399e5 100644 +--- a/mk/efi.mk ++++ b/mk/efi.mk +@@ -32,6 +32,7 @@ FORMAT=efi-app-$(EFI_SUBARCH) + + CFLAGS = -I$(EFIINC) -I$(EFIINC)/$(EFI_SUBARCH) \ + -DEFI_FUNCTION_WRAPPER -fPIC -fshort-wchar -ffreestanding \ ++ -fcommon \ + -Wall -I$(com32)/include -I$(com32)/include/sys \ + -I$(core)/include -I$(core)/ $(ARCHOPT) \ + -I$(com32)/lib/ -I$(com32)/libutil/include -std=gnu99 \ +diff --git a/mk/elf.mk b/mk/elf.mk +index b46dbd0..dc265ce 100644 +--- a/mk/elf.mk ++++ b/mk/elf.mk +@@ -55,6 +55,7 @@ GPLINCLUDE = + endif + + CFLAGS = $(GCCOPT) $(GCCWARN) -W -Wall \ ++ -fcommon \ + -fomit-frame-pointer -D__COM32__ -D__FIRMWARE_$(FIRMWARE)__ -DDYNAMIC_MODULE \ + -nostdinc -iwithprefix include \ + -I$(com32)/libutil/include -I$(com32)/include \ +diff --git a/mk/embedded.mk b/mk/embedded.mk +index 488dc0f..fae13e2 100644 +--- a/mk/embedded.mk ++++ b/mk/embedded.mk +@@ -57,7 +57,7 @@ LIBGCC := $(shell $(CC) $(GCCOPT) --print-libgcc) + LD += -m elf_$(ARCH) + + # Note: use += for CFLAGS and SFLAGS in case something is set in MCONFIG.local +-CFLAGS += $(GCCOPT) -g $(GCCWARN) -Wno-sign-compare $(OPTFLAGS) $(INCLUDES) ++CFLAGS += $(GCCOPT) -g $(GCCWARN) -Wno-sign-compare -fcommon $(OPTFLAGS) $(INCLUDES) + SFLAGS += $(CFLAGS) -D__ASSEMBLY__ + + .SUFFIXES: .c .o .S .s .i .elf .com .bin .asm .lst .c32 .lss +diff --git a/mk/lib.mk b/mk/lib.mk +index f3fb07c..2ffea2d 100644 +--- a/mk/lib.mk ++++ b/mk/lib.mk +@@ -49,7 +49,7 @@ OPTFLAGS = -Os -march=$(MARCH) -falign-functions=0 -falign-jumps=0 \ + -falign-labels=0 -ffast-math -fomit-frame-pointer + WARNFLAGS = $(GCCWARN) -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Winline + +-CFLAGS = $(OPTFLAGS) $(REQFLAGS) $(WARNFLAGS) $(LIBFLAGS) ++CFLAGS = $(OPTFLAGS) $(REQFLAGS) -fcommon $(WARNFLAGS) $(LIBFLAGS) + + ifeq ($(FWCLASS),EFI) + CFLAGS += -mno-red-zone diff --git a/syslinux.spec b/syslinux.spec index 22a15a9..2cd8f66 100644 --- a/syslinux.spec +++ b/syslinux.spec @@ -1,4 +1,4 @@ -%define anolis_release .0.1 +%define anolis_release .0.2 %global buildarches %{ix86} x86_64 %ifnarch %{buildarches} %global debug_package %{nil} @@ -18,6 +18,11 @@ Patch0002: 0002-ext4-64bit-feature.patch Patch0003: 0003-extlinux-fix-missing-include-for-major-minor.patch Patch0004: 0004-Add-RPMOPTFLAGS-to-CFLAGS-for-some-stuff.patch +# Begin: Anolis customized patches +# Backport from debian to fix FTBFS on gcc10 +Patch1001: 1001-gcc-10-compatibility.patch +# End: Anolis customized patches + # this is to keep rpmbuild from thinking the .c32 / .com / .0 / memdisk files # in noarch packages are a reason to stop the build. %define _binaries_in_noarch_packages_terminate_build 0 @@ -267,6 +272,9 @@ fi %endif %changelog +* Mon Dec 13 2021 Weitao Zhou - 6.04-5.0.2 +- Fix gcc10 -fno-common compile issue for compatible with gcc10 build + * Wed Jun 17 2021 Liwei Ge - 6.04-5.0.1 - Enable nonlinux for x86 build -- Gitee