From: Razvan Deaconescu Date: Fri, 3 Feb 2023 11:41:38 +0000 (+0200) Subject: lib/nolibc: Add -ffreestanding flag X-Git-Tag: RELEASE-0.13.0~17 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=d7f598242afd95dceab42983d8d616885e618cbf;p=unikraft%2Funikraft.git lib/nolibc: Add -ffreestanding flag GCC optimizes the use of `memcmp()` if the `-ffreestanding` flag is missing. In the current configuration, the flag is missing for GCC <= 9. The resulting optimization causes in an infinite loop for `lib/nolibc`. This commit fixes the issue by adding the `-ffreestanding` flag for `lib/nolibc`, irrespective of the GCC version. GitHub-Fixes: #728 Signed-off-by: Razvan Deaconescu Reviewed-by: Maria Sfiraiala Reviewed-by: Eduard Vintilă Reviewed-by: Marco Schlumpp Approved-by: Marc Rittinghaus Tested-by: Unikraft CI GitHub-Closes: #740 --- diff --git a/Makefile.uk b/Makefile.uk index 668dca7aa..c8025cd54 100644 --- a/Makefile.uk +++ b/Makefile.uk @@ -91,7 +91,7 @@ M4FLAGS += -DUK_VERSION=$(UK_VERSION).$(UK_SUBVERSION) COMPFLAGS-$(call gcc_version_ge,6,1) += -fno-PIC LDFLAGS-$(call gcc_version_ge,6,1) += -no-pie ifeq ($(call gcc_version_ge,10,0),y) -COMPFLAGS-y += -fhosted -ffreestanding -fno-tree-loop-distribute-patterns +COMPFLAGS-y += -fhosted -fno-tree-loop-distribute-patterns LIBLDFLAGS-$(CONFIG_OPTIMIZE_LTO) += -flinker-output=nolto-rel LDFLAGS-$(CONFIG_OPTIMIZE_LTO) += -flinker-output=nolto-rel endif diff --git a/lib/nolibc/Makefile.uk b/lib/nolibc/Makefile.uk index 94bea8e37..3efeba4bf 100644 --- a/lib/nolibc/Makefile.uk +++ b/lib/nolibc/Makefile.uk @@ -18,6 +18,8 @@ LIBNOLIBC_NO_BUILTINS += -fno-builtin-vsscanf CFLAGS-$(CONFIG_LIBNOLIBC) += $(LIBNOLIBC_NO_BUILTINS) CXXFLAGS-$(CONFIG_LIBNOLIBC) += $(LIBNOLIBC_NO_BUILTINS) +LIBNOLIBC_CFLAGS-y += -ffreestanding + LIBNOLIBC_GLOBAL_INCLUDES-y += -I$(LIBNOLIBC_BASE)/include LIBNOLIBC_GLOBAL_INCLUDES-y += -I$(LIBNOLIBC_BASE)/arch/$(ARCH) LIBNOLIBC_GLOBAL_INCLUDES-y += -I$(LIBNOLIBC_BASE)/musl-imported/include