diff mbox

Enable compiling with gcc tracing

Message ID 20170329181602.1107-1-eggi.innovations@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Felix Schmoll March 29, 2017, 6:16 p.m. UTC
Make minimal adjustments in order to enable the compilation of the
xen source-code with gcc-6's -fsanitize-coverage=trace-pc option.

Due to a bug in Xen's build-system the flag for the compiler has
to be handed in via the command line, i.e. for compiling one would
use:

	make CC=<path to gcc-6>

This is an experimental patch as in a final version you would not
want all files to be compiled with this option by default.

Signed-off-by: Felix Schmoll <eggi.innovations@gmail.com>
---
 xen/Rules.mk                | 1 +
 xen/common/kernel.c         | 2 ++
 xen/include/xen/hypercall.h | 2 ++
 3 files changed, 5 insertions(+)

Comments

Wei Liu March 29, 2017, 6:22 p.m. UTC | #1
On Wed, Mar 29, 2017 at 08:16:02PM +0200, Felix Schmoll wrote:
> Make minimal adjustments in order to enable the compilation of the
> xen source-code with gcc-6's -fsanitize-coverage=trace-pc option.
> 
> Due to a bug in Xen's build-system the flag for the compiler has
> to be handed in via the command line, i.e. for compiling one would
> use:
> 
> 	make CC=<path to gcc-6>
> 
> This is an experimental patch as in a final version you would not
> want all files to be compiled with this option by default.
> 
> Signed-off-by: Felix Schmoll <eggi.innovations@gmail.com>

Have you tried booting Xen with this patch applied and trace-pc enabled?

> ---
>  xen/Rules.mk                | 1 +
>  xen/common/kernel.c         | 2 ++
>  xen/include/xen/hypercall.h | 2 ++
>  3 files changed, 5 insertions(+)
> 
> diff --git a/xen/Rules.mk b/xen/Rules.mk
> index 77bcd44922..254cc4381e 100644
> --- a/xen/Rules.mk
> +++ b/xen/Rules.mk
> @@ -46,6 +46,7 @@ else
>  CFLAGS += -O2 -fomit-frame-pointer
>  endif
>  
> +CFLAGS += -fsanitize-coverage=trace-pc
>  CFLAGS += -nostdinc -fno-builtin -fno-common
>  CFLAGS += -Werror -Wredundant-decls -Wno-pointer-arith
>  CFLAGS += -pipe -g -D__XEN__ -include $(BASEDIR)/include/xen/config.h
> diff --git a/xen/common/kernel.c b/xen/common/kernel.c
> index 84618715dc..77b22effb3 100644
> --- a/xen/common/kernel.c
> +++ b/xen/common/kernel.c
> @@ -238,6 +238,8 @@ void __init do_initcalls(void)
>  
>  # define DO(fn) long do_##fn
>  
> +void __sanitizer_cov_trace_pc(void) { return; }
> +

IIRC this is going to recurse until stack overflows, right?

What I actually want you to do is to add a new file and hook it up in
the build system.

And maybe if you feel like it, start looking at actually putting
something inside the trace_pc function.

Hint, you can get hold of PC with  __builtin_return_address(0).

>  #endif
>  
>  /*
> diff --git a/xen/include/xen/hypercall.h b/xen/include/xen/hypercall.h
> index cc99aea57d..12517b5e90 100644
> --- a/xen/include/xen/hypercall.h
> +++ b/xen/include/xen/hypercall.h
> @@ -19,6 +19,8 @@
>  #include <asm/hypercall.h>
>  #include <xsm/xsm.h>
>  
> +extern void __sanitizer_cov_trace_pc(void);
> +
>  extern long
>  do_sched_op(
>      int cmd,
> -- 
> 2.11.0
>
diff mbox

Patch

diff --git a/xen/Rules.mk b/xen/Rules.mk
index 77bcd44922..254cc4381e 100644
--- a/xen/Rules.mk
+++ b/xen/Rules.mk
@@ -46,6 +46,7 @@  else
 CFLAGS += -O2 -fomit-frame-pointer
 endif
 
+CFLAGS += -fsanitize-coverage=trace-pc
 CFLAGS += -nostdinc -fno-builtin -fno-common
 CFLAGS += -Werror -Wredundant-decls -Wno-pointer-arith
 CFLAGS += -pipe -g -D__XEN__ -include $(BASEDIR)/include/xen/config.h
diff --git a/xen/common/kernel.c b/xen/common/kernel.c
index 84618715dc..77b22effb3 100644
--- a/xen/common/kernel.c
+++ b/xen/common/kernel.c
@@ -238,6 +238,8 @@  void __init do_initcalls(void)
 
 # define DO(fn) long do_##fn
 
+void __sanitizer_cov_trace_pc(void) { return; }
+
 #endif
 
 /*
diff --git a/xen/include/xen/hypercall.h b/xen/include/xen/hypercall.h
index cc99aea57d..12517b5e90 100644
--- a/xen/include/xen/hypercall.h
+++ b/xen/include/xen/hypercall.h
@@ -19,6 +19,8 @@ 
 #include <asm/hypercall.h>
 #include <xsm/xsm.h>
 
+extern void __sanitizer_cov_trace_pc(void);
+
 extern long
 do_sched_op(
     int cmd,