[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH v2 3/3] arch/*, build: Add support for clang compilation



In order to perform the compilation and linking with clang without warnings, 
the following flags must be removed:
-fno-tree-sra, -fms-extensions, -nostdinc, -fno-reorder-blocks, 
-mno-fp-ret-in-387. Functions such as have_clang,
have_gcc, clang_version_ge, error_if_clang_version_lt have been added to solve 
the problem.
With all of this we are able to rearrange the flags.
So, if there are flags that fail with clang, we can select them only for GCC 
compilation.
Also, we can introduce specific flags for clang.

Signed-off-by: Alice Suiu <alicesuiu17@xxxxxxxxx>
---
 Makefile                     |  2 +-
 Makefile.uk                  | 24 ++++++++++--------------
 arch/x86/x86_64/Makefile.uk  | 20 ++++++++------------
 support/build/Makefile.rules | 25 ++++++++++++++++++++++++-
 4 files changed, 43 insertions(+), 28 deletions(-)

diff --git a/Makefile b/Makefile
index d70b3fc..a98d34c 100644
--- a/Makefile
+++ b/Makefile
@@ -506,7 +506,7 @@ ifeq ("$(origin COMPILER)", "command line")
   CONFIG_COMPILER := $(COMPILER)
 endif
 ifndef CONFIG_COMPILER
-  CONFIG_COMPILER = gcc
+  CONFIG_COMPILER := gcc
 endif
 
 $(eval $(call verbose_include,$(CONFIG_UK_BASE)/arch/$(UK_FAMILY)/Compiler.uk))
diff --git a/Makefile.uk b/Makefile.uk
index dee9f35..e44f1fa 100644
--- a/Makefile.uk
+++ b/Makefile.uk
@@ -4,14 +4,16 @@
 #
 
################################################################################
 
-COMPFLAGS    += -nostdinc -nostdlib
+COMPFLAGS    += -nostdlib
+COMPFLAGS-$(call have_gcc) += -nostdinc
 COMPFLAGS    += -U __linux__ -U __FreeBSD__ -U __sun__
-COMPFLAGS    += -fno-stack-protector -fno-omit-frame-pointer -fno-tree-sra
+COMPFLAGS    += -fno-stack-protector -fno-omit-frame-pointer
+COMPFLAGS-$(call have_gcc) += -fno-tree-sra
 COMPFLAGS    += -Wall -Wextra
 
 # TODO: Remove -fms-extensions if not needed for our code (it was moved from 
Arm64 arch)
-CFLAGS       += -fms-extensions
-ASFLAGS      += -D__ASSEMBLY__
+CFLAGS-$(call have_gcc)        += -fms-extensions
+ASFLAGS                        += -D__ASSEMBLY__
 
 ASINCLUDES   += -I$(CONFIG_UK_BASE)/include
 CINCLUDES    += -I$(CONFIG_UK_BASE)/include
@@ -21,8 +23,10 @@ GOCINCLUDES  += -I$(CONFIG_UK_BASE)/include
 # Set the text and data sections to be readable and writable. Also,
 # do not page-align the data segment. If the output format supports
 # Unix style magic numbers, mark the output as OMAGIC.
-LIBLDFLAGS  += -nostdinc -nostdlib -Wl,--omagic -Wl,-r -Wl,-d 
-Wl,--build-id=none
-LDFLAGS     += -nostdinc -nostdlib -Wl,--omagic -Wl,--build-id=none
+LIBLDFLAGS                     += -nostdlib -Wl,--omagic -Wl,-r -Wl,-d 
-Wl,--build-id=none
+LIBLDFLAGS-$(call have_gcc)    += -nostdinc
+LDFLAGS                        += -nostdlib -Wl,--omagic -Wl,--build-id=none
+LDFLAGS-$(call have_gcc)       += -nostdinc
 
 COMPFLAGS-$(CONFIG_OPTIMIZE_NONE)         += -O0 -fno-optimize-sibling-calls 
-fno-tree-vectorize
 COMPFLAGS-$(CONFIG_OPTIMIZE_SIZE)         += -Os
@@ -55,11 +59,3 @@ M4FLAGS      += -DUK_VERSION=$(UK_VERSION).$(UK_SUBVERSION)
 COMPFLAGS-$(call gcc_version_ge,6,1)   += -no-pie
 LIBLDFLAGS-$(call gcc_version_ge,6,1)  += -no-pie
 LDFLAGS-$(call gcc_version_ge,6,1)     += -no-pie
-
-ifeq ($(CONFIG_COMPILER), clang)
-CFLAGS:=$(filter-out -fms-extensions,$(CFLAGS))
-COMPFLAGS:=$(filter-out -fno-tree-sra,$(COMPFLAGS))
-COMPFLAGS:=$(filter-out -nostdinc,$(COMPFLAGS))
-LIBLDFLAGS:=$(filter-out -nostdinc,$(LIBLDFLAGS))
-LDFLAGS:=$(filter-out -nostdinc,$(LDFLAGS))
-endif
\ No newline at end of file
diff --git a/arch/x86/x86_64/Makefile.uk b/arch/x86/x86_64/Makefile.uk
index 1bbe02c..ea1c817 100644
--- a/arch/x86/x86_64/Makefile.uk
+++ b/arch/x86/x86_64/Makefile.uk
@@ -1,7 +1,9 @@
-ARCHFLAGS     += -D__X86_64__
-ARCHFLAGS     += -m64 -mno-red-zone -fno-reorder-blocks 
-fno-asynchronous-unwind-tables
-ISR_ARCHFLAGS += -D__X86_64__
-ISR_ARCHFLAGS += -m64 -mno-red-zone -fno-reorder-blocks 
-fno-asynchronous-unwind-tables
+ARCHFLAGS                                      += -D__X86_64__
+ARCHFLAGS                                      += -m64 -mno-red-zone 
-fno-asynchronous-unwind-tables
+ARCHFLAGS-$(call have_gcc)                     += -fno-reorder-blocks
+ISR_ARCHFLAGS                                  += -D__X86_64__
+ISR_ARCHFLAGS                                  += -m64 -mno-red-zone 
-fno-asynchronous-unwind-tables
+ISR_ARCHFLAGS-$(call have_gcc)                 += -fno-reorder-blocks
 
 CINCLUDES   += -I$(CONFIG_UK_BASE)/arch/x86/x86_64/include
 ASINCLUDES  += -I$(CONFIG_UK_BASE)/arch/x86/x86_64/include
@@ -9,7 +11,8 @@ CXXINCLUDES += -I$(CONFIG_UK_BASE)/arch/x86/x86_64/include
 
 # compiler flags to prevent use of extended (FP, SSE, AVX) registers.
 # This is for files that contain trap/exception/interrupt handlers
-ISR_ARCHFLAGS += -mno-80387 -mno-fp-ret-in-387 -mno-mmx -mno-sse -mno-avx 
-mgeneral-regs-only
+ISR_ARCHFLAGS                                  += -mno-80387 -mno-mmx -mno-sse 
-mno-avx -mgeneral-regs-only
+ISR_ARCHFLAGS-$(call have_gcc)                 += -mno-fp-ret-in-387
 
 ARCHFLAGS-$(CONFIG_MARCH_X86_64_GENERIC)        += -mtune=generic
 ISR_ARCHFLAGS-$(CONFIG_MARCH_X86_64_GENERIC)    += -mtune=generic
@@ -41,10 +44,3 @@ ARCHFLAGS-$(CONFIG_MARCH_X86_64_BTVER1)         += 
-march=btver1
 ISR_ARCHFLAGS-$(CONFIG_MARCH_X86_64_BTVER1)     += -march=btver1
 ARCHFLAGS-$(CONFIG_MARCH_X86_64_BTVER2)         += -march=btver2
 ISR_ARCHFLAGS-$(CONFIG_MARCH_X86_64_BTVER2)     += -march=btver2
-
-
-ifeq ($(CONFIG_COMPILER), clang)
-ARCHFLAGS:=$(filter-out -fno-reorder-blocks,$(ARCHFLAGS))
-ISR_ARCHFLAGS:=$(filter-out -fno-reorder-blocks,$(ISR_ARCHFLAGS))
-ISR_ARCHFLAGS:=$(filter-out -mno-fp-ret-in-387,$(ISR_ARCHFLAGS))
-endif
\ No newline at end of file
diff --git a/support/build/Makefile.rules b/support/build/Makefile.rules
index af08f83..117fd5a 100644
--- a/support/build/Makefile.rules
+++ b/support/build/Makefile.rules
@@ -29,10 +29,20 @@ lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst 
D,d,$(subst E,e,$(subst F,f,$(s
 # upper case
 uc = $(subst a,A,$(subst b,B,$(subst c,C,$(subst d,D,$(subst e,E,$(subst 
f,F,$(subst g,G,$(subst h,H,$(subst i,I,$(subst j,J,$(subst k,K,$(subst 
l,L,$(subst m,M,$(subst n,N,$(subst o,O,$(subst p,P,$(subst q,Q,$(subst 
r,R,$(subst s,S,$(subst t,T,$(subst u,U,$(subst v,V,$(subst w,W,$(subst 
x,X,$(subst y,Y,$(subst z,Z,$(1)))))))))))))))))))))))))))
 
+# test if GCC is set as a compiler
+define have_gcc =
+$(shell if [ $(CC) = gcc ] ; then echo y ; else echo n ; fi)
+endef
+
+# test if CLANG is set as a compiler
+define have_clang =
+$(shell if [ $(CC) == clang ] ; then echo y ; else echo n ; fi)
+endef
+
 # test whether GCC version is greater than or equal to the minimum requirement
 # gcc_version_ge $gcc_major,$gcc_minor
 define gcc_version_ge =
-$(shell if [ $(CC_VER_MAJOR) -gt $(1) ] || ([ $(CC_VER_MAJOR) -eq $(1) ] && [ 
$(CC_VER_MINOR) -ge $(2) ]) ; then echo y ; fi)
+$(shell if [ $(call have_gcc) = y ] ; then if [ $(CC_VER_MAJOR) -gt $(1) ] || 
([ $(CC_VER_MAJOR) -eq $(1) ] && [ $(CC_VER_MINOR) -ge $(2) ]) ; then echo y ; 
fi ; else echo n ; fi)
 endef
 
 # print error and stop build when GCC version doesn't meet the minimum 
requirement
@@ -42,6 +52,19 @@ $(if $(call gcc_version_ge,$(1),$(2)),,\
      $(error Require GCC version >= $(1).$(2) found 
$(CC_VER_MAJOR).$(CC_VER_MINOR)))
 endef
 
+# test whether CLANG  version is greater than or equal to the minimum 
requirement
+# clang_version_ge $clang_major, $clang_minor
+define clang_version_ge =
+$(shell if [ $(call have_clang) = y ] ; then if [ $(CC_VER_MAJOR) -gt $(1) ] 
|| ([ $(CC_VER_MAJOR) -eq $(1) ] && [ $(CC_VER_MINOR) -ge $(2) ]) ; then echo y 
; fi ; else echo n ; fi)
+endef
+
+# print error and stop build when CLANG version doesn't meet the minimum 
requirement
+# error_if_clang_version_lt $clang_major,$clang_minor.
+define error_if_clang_version_lt =
+$(if $(call clang_version_ge,$(1),$(2)),,\
+     $(error Require CLANG version >= $(1).$(2) found 
$(CC_VER_MAJOR).$(CC_VER_MINOR)))
+endef
+
 
################################################################################
 #
 # Paths and Filenames
-- 
2.17.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.