Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 19 Oct 2014 18:01:18 -0500
From:      Matthew Grooms <mgrooms@shrew.net>
To:        freebsd-current@freebsd.org
Subject:   Re: Compiling Xen on FreeBSD using clang ...
Message-ID:  <544442BE.3060908@shrew.net>
In-Reply-To: <alpine.BSF.2.11.1410191954250.74981@m.saper.info>
References:  <5443E7FC.8020605@shrew.net> <alpine.BSF.2.11.1410191954250.74981@m.saper.info>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------010202060407000707050506
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

On 10/19/2014 3:03 PM, Marcin Cieslak wrote:
>
> On Sun, 19 Oct 2014, Matthew Grooms wrote:
>
[...]
>
> I have recently managed to compile Xen (4.5 unstable from git master) using
> few patches in the source code (I posted them to xen-devel@, most of them
> are almost the same as some earlier work by Julien Grall).
>

Hi Marcin,

I pulled in a few patches that were posted on the xen-devel list to get 
things to compile. Attached was the subset that I needed to get Xen 4.5 
to build with the clang 3.4.1 ( with seabios disabled ).

> I have used clang version 3.5.0 (trunk) from ports just for the .code16
> support, other than that clang 3.4.1 was fine.
>

Do you have a link to your patch set? I sifted through the ones posted 
by Julien and I probably saw most of yours as well. My goal was to get 
as much as possible to compile with the existing system compiler so I 
didn't try 3.5.0. Maybe that's a better bet.

> Xen kernel compiled this way even boots successfully and starts Debian
> dom0.
>

I was able to boot a FreeBSD PVH dom0 based on Rogers instructions. 
Pretty amazing that it all works with a GENERIC kernel. Was mostly 
focusing on getting the compile clean enough for a port/pkg of the final 
4.5 release.

[mgrooms@xen2 ~]$ uname -a
FreeBSD xen2.shrew.lab 11.0-CURRENT FreeBSD 11.0-CURRENT #0 
a50212f(pvh_dom0_v7): Sun Oct 19 09:57:23 CDT 2014 
root@xen2.shrew.lab:/usr/obj/usr/src/sys/GENERIC  amd64
[root@xen2 ~]# xl list
Name                                        ID   Mem VCPUs      State 
Time(s)
Domain-0                                     0  1024     2     r----- 
   7.1

> This command was used to compile with 3.4.1 (without hvmloader):
> env CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib gmake clang=y
> CC=clang-devel HOSTCC=clang-devel CONFIG_SEABIOS=y CONFIG_HVMLOADER=n
> SEABIOS_PATH=$HOME/qemu/bios.bin-1.7.5 CONFIG_QEMU=n "$@"
>

Thanks for that. I hope the Xen devs can get the yajl and signed int 
patches committed. Those were the only C level code changes I ran into 
and would clean up the build significantly for clang users. Tho only 
other knit was the ...

register unsigned long sp asm("rsp");

... assembly but maybe that compiles with 3.5 as well?

http://llvm.org/bugs/show_bug.cgi?id=11255

Everything else was build level compiler flag fiddling.

-Matthew

--------------010202060407000707050506
Content-Type: text/plain; charset=windows-1252;
 name="clang2.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="clang2.diff"

diff --git a/Config.mk b/Config.mk
index 6324237..0cd3553 100644
--- a/Config.mk
+++ b/Config.mk
@@ -36,10 +36,13 @@ CONFIG_$(XEN_OS) := y
 SHELL     ?= /bin/sh
 
 # Tools to run on system hosting the build
-HOSTCC      = gcc
+HOSTCC      = cc
 HOSTCFLAGS  = -Wall -Werror -Wstrict-prototypes -O2 -fomit-frame-pointer
 HOSTCFLAGS += -fno-strict-aliasing
 
+# Clang specific
+HOSTCFLAGS += -Wno-ignored-attributes
+
 DISTDIR     ?= $(XEN_ROOT)/dist
 DESTDIR     ?= /
 
@@ -54,7 +57,6 @@ else
 gcc := n
 endif
 
-
 include $(XEN_ROOT)/config/$(XEN_OS).mk
 include $(XEN_ROOT)/config/$(XEN_TARGET_ARCH).mk
 
@@ -193,6 +195,7 @@ CFLAGS += -Wall -Wstrict-prototypes
 # and is over-zealous with the printf format lint
 # and is a bit too fierce about unused return values
 CFLAGS-$(clang) += -Wno-parentheses -Wno-format -Wno-unused-value
+CFLAGS-$(clang) += -Wno-ignored-attributes -Qunused-arguments
 
 $(call cc-option-add,HOSTCFLAGS,HOSTCC,-Wdeclaration-after-statement)
 $(call cc-option-add,CFLAGS,CC,-Wdeclaration-after-statement)
diff --git a/tools/Rules.mk b/tools/Rules.mk
index 87a56dc..ab47f54 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -17,6 +17,10 @@ XEN_LIBXENSTAT     = $(XEN_ROOT)/tools/xenstat/libxenstat/src
 XEN_BLKTAP2        = $(XEN_ROOT)/tools/blktap2
 XEN_LIBVCHAN       = $(XEN_ROOT)/tools/libvchan
 
+CFLAGS-$(clang) += -Wno-ignored-attributes -Wno-header-guard
+CFLAGS-$(clang) += -no-integrated-as
+CFLAGS-$(clang) += -DYAJL_MAJOR=2
+
 CFLAGS_xeninclude = -I$(XEN_INCLUDE)
 
 XENSTORE_XENSTORED ?= y
@@ -70,6 +74,10 @@ CFLAGS_libxenlight = -I$(XEN_XENLIGHT) $(CFLAGS_libxenctrl) $(CFLAGS_xeninclude)
 LDLIBS_libxenlight = $(XEN_XENLIGHT)/libxenlight$(libextension) $(SHLIB_libxenctrl) $(SHLIB_libxenstore) $(SHLIB_libblktapctl)
 SHLIB_libxenlight  = -Wl,-rpath-link=$(XEN_XENLIGHT)
 
+CFLAGS_libxenlight += -I/usr/local/include
+CFLAGS_libxenlight += -Wno-format-nonliteral
+LDFLAGS_libxenlight += -L/usr/local/lib
+
 CFLAGS += -D__XEN_TOOLS__
 
 # Get gcc to generate the dependencies for us.
diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index df08c8a..a68f15a 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -12,7 +12,7 @@ XLUMAJOR = 4.3
 XLUMINOR = 0
 
 CFLAGS += -Werror -Wno-format-zero-length -Wmissing-declarations \
-	-Wno-declaration-after-statement -Wformat-nonliteral
+	-Wno-declaration-after-statement
 CFLAGS += -I. -fPIC
 
 ifeq ($(CONFIG_Linux),y)
@@ -25,6 +25,7 @@ ifeq ($(CONFIG_REMUS_NETBUF),y)
 LIBXL_LIBS += $(LIBNL3_LIBS)
 endif
 
+CFLAGS_LIBXL = $(CFLAGS_libxenlight)
 CFLAGS_LIBXL += $(CFLAGS_libxenctrl)
 CFLAGS_LIBXL += $(CFLAGS_libxenguest)
 CFLAGS_LIBXL += $(CFLAGS_libxenstore)
@@ -37,7 +38,7 @@ CFLAGS_LIBXL += -Wshadow
 LIBXL_LIBS-$(CONFIG_ARM) += -lfdt
 
 CFLAGS += $(PTHREAD_CFLAGS)
-LDFLAGS += $(PTHREAD_LDFLAGS)
+LDFLAGS += $(PTHREAD_LDFLAGS) $(LDFLAGS_libxenlight)
 LIBXL_LIBS += $(PTHREAD_LIBS)
 LIBXL_LIBS += $(LIBXL_LIBS-y)
 
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 7ed601e..ba66a66 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1773,7 +1773,7 @@ libxl__json_map_node *libxl__json_map_node_get(const libxl__json_object *o,
 _hidden const libxl__json_object *libxl__json_map_get(const char *key,
                                           const libxl__json_object *o,
                                           libxl__json_node_type expected_type);
-_hidden yajl_status libxl__json_object_to_yajl_gen(libxl__gc *gc_opt,
+_hidden yajl_gen_status libxl__json_object_to_yajl_gen(libxl__gc *gc_opt,
                                                    yajl_gen hand,
                                                    libxl__json_object *param);
 _hidden void libxl__json_object_free(libxl__gc *gc_opt,
diff --git a/tools/libxl/libxl_json.c b/tools/libxl/libxl_json.c
index ceb014a..6f64be9 100644
--- a/tools/libxl/libxl_json.c
+++ b/tools/libxl/libxl_json.c
@@ -610,12 +610,12 @@ const libxl__json_object *libxl__json_map_get(const char *key,
     return NULL;
 }
 
-yajl_status libxl__json_object_to_yajl_gen(libxl__gc *gc,
+yajl_gen_status libxl__json_object_to_yajl_gen(libxl__gc *gc,
                                            yajl_gen hand,
                                            libxl__json_object *obj)
 {
     int idx = 0;
-    yajl_status rc;
+    yajl_gen_status rc;
 
     switch (obj->type) {
     case JSON_NULL:
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 988ee28..61eda4c 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -3360,7 +3360,7 @@ static void list_domains(int verbose, int context, int claim, int numa,
     printf("\n");
     for (i = 0; i < nb_domain; i++) {
         char *domname;
-        unsigned shutdown_reason;
+        int shutdown_reason;
         domname = libxl_domid_to_name(ctx, info[i].domid);
         shutdown_reason = info[i].shutdown ? info[i].shutdown_reason : 0;
         printf("%-40s %5d %5lu %5d     %c%c%c%c%c%c  %8.1f",
@@ -4908,7 +4908,7 @@ static void output_xeninfo(void)
         return;
     }
 
-    if ((sched = libxl_get_scheduler(ctx)) < 0) {
+    if ((int)(sched = libxl_get_scheduler(ctx)) < 0) {
         fprintf(stderr, "get_scheduler sysctl failed.\n");
         return;
     }
@@ -6913,7 +6913,7 @@ int main_cpupoolcreate(int argc, char **argv)
             goto out_cfg;
         }
     } else {
-        if ((sched = libxl_get_scheduler(ctx)) < 0) {
+        if ((int)(sched = libxl_get_scheduler(ctx)) < 0) {
             fprintf(stderr, "get_scheduler sysctl failed.\n");
             goto out_cfg;
         }
diff --git a/xen/Rules.mk b/xen/Rules.mk
index a97405c..85b1eb3 100644
--- a/xen/Rules.mk
+++ b/xen/Rules.mk
@@ -74,8 +74,12 @@ endif
 
 AFLAGS-y                += -D__ASSEMBLY__ -include $(BASEDIR)/include/xen/config.h
 
+# Clang complains without these
+CFLAGS-$(clang)	        += -Wno-unused-function -Wno-initializer-overrides
+
 # Clang's built-in assembler can't handle .code16/.code32/.code64 yet
 AFLAGS-$(clang)         += -no-integrated-as
+CFLAGS-$(clang)         += -no-integrated-as -v
 
 ALL_OBJS := $(ALL_OBJS-y)
 
diff --git a/xen/include/asm-x86/current.h b/xen/include/asm-x86/current.h
index b95fd79..f884493 100644
--- a/xen/include/asm-x86/current.h
+++ b/xen/include/asm-x86/current.h
@@ -27,6 +27,8 @@ static inline struct cpu_info *get_cpu_info(void)
 {
     register unsigned long sp asm("rsp");
 
+    asm("" : "=r" (sp));
+
     return (struct cpu_info *)((sp & ~(STACK_SIZE-1)) + STACK_SIZE) - 1;
 }
 

--------------010202060407000707050506--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?544442BE.3060908>