Skip to contentSkip to conversation

Enable compiling with gcc tracing

PATCH In review Felix Schmoll 2 participants 5 messages Mar 29, 2017 – Mar 31, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Enable compiling with gcc tracing

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.

---
 xen/Rules.mk                | 1 +
 xen/common/kernel.c         | 2 ++
 xen/include/xen/hypercall.h | 2 ++
 3 files changed, 5 insertions(+)
xen/Rules.mk +1 -0
index 77bcd44922..254cc4381e 100644
@@ -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
xen/common/kernel.c +2 -0
index 84618715dc..77b22effb3 100644
@@ -238,6 +238,8 @@ void __init do_initcalls(void)
 
 # define DO(fn) long do_##fn
 
+void __sanitizer_cov_trace_pc(void) { return; }
+
 #endif
 
 /*
xen/include/xen/hypercall.h +2 -0
index cc99aea57d..12517b5e90 100644
@@ -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,
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw
Quoted 7 lines · Felix Schmoll

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:

Quoted 6 lines

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.

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

Quoted 23 lines
---
 xen/Rules.mk                | 1 +
 xen/common/kernel.c         | 2 ++
 xen/include/xen/hypercall.h | 2 ++
 3 files changed, 5 insertions(+)
xen/Rules.mk +1 -0
index 77bcd44922..254cc4381e 100644
@@ -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
xen/common/kernel.c +0 -0
index 84618715dc..77b22effb3 100644

xen/common/kernel.c void __init do_initcalls(void) · line 242

Quoted 5 lines
xen/common/kernel.c +2 -0
@@ -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).

Quoted 19 lines
xen/common/kernel.c +0 -0
 #endif
 
 /*
xen/include/xen/hypercall.h +2 -0
index cc99aea57d..12517b5e90 100644
@@ -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,
Signature · 1 line
2.11.0

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw

PATCH 1/1 Enable compiling with gcc tracing

In reply to Felix Schmoll

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.

---
 xen/Rules.mk                | 9 ++++++++-
 xen/include/xen/hypercall.h | 1 +
 xen/include/xen/my_tracer.h | 6 ++++++
 xen/my_tracer.c             | 1 +
 4 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 xen/include/xen/my_tracer.h
 create mode 100644 xen/my_tracer.c
xen/Rules.mk +8 -1
index 77bcd44922..14de50d540 100644
@@ -33,7 +33,9 @@ override TARGET_ARCH     := $(shell echo $(XEN_TARGET_ARCH) | \
 
 TARGET := $(BASEDIR)/xen
 
+
 # Note that link order matters!
+ALL_OBJS-y               += $(BASEDIR)/my_tracer.o
 ALL_OBJS-y               += $(BASEDIR)/common/built_in.o
 ALL_OBJS-y               += $(BASEDIR)/drivers/built_in.o
 ALL_OBJS-y               += $(BASEDIR)/xsm/built_in.o
@@ -46,6 +48,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
@@ -171,7 +174,11 @@ _clean_%/: FORCE
 	$(MAKE) -f $(BASEDIR)/Rules.mk -C $* clean
 
 %.o: %.c Makefile
-	$(CC) $(CFLAGS) -c $< -o $@
+	if [ $@ != $(BASEDIR)/my_tracer.o ]; \
+	  then $(CC) $(CFLAGS) -c $< -o $@; \
+	else \
+          $(CC) -include $(BASEDIR)/include/xen/my_tracer.h -c $(BASEDIR)/my_tracer.c -o $(BASEDIR)/my_tracer.o; \
+    	fi
 
 %.o: %.S Makefile
 	$(CC) $(AFLAGS) -c $< -o $@
xen/include/xen/hypercall.h +1 -0
index cc99aea57d..ec19e1c80f 100644
@@ -5,6 +5,7 @@
 #ifndef __XEN_HYPERCALL_H__
 #define __XEN_HYPERCALL_H__
 
+#include <xen/my_tracer.h>
 #include <xen/types.h>
 #include <xen/time.h>
 #include <public/xen.h>
xen/include/xen/my_tracer.h new file +6 -0
new file mode 100644
index 0000000000..7081e60f34
@@ -0,0 +1,6 @@
+#ifndef _TRACE_H_
+#define _TRACE_H_
+
+void __sanitizer_cov_trace_pc(void);
+
+#endif
xen/my_tracer.c new file +1 -0
new file mode 100644
index 0000000000..2a2f8053f8
@@ -0,0 +1 @@
+void __sanitizer_cov_trace_pc(void) { return; }
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#3 lore raw

Cool. I think Xen should boot with this.

You've successfully finished what I asked for. Now you can divert your energy to polish your application. :-)

Quoted 9 lines · Felix Schmoll

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>

OOI, how can I reproduce the bug you met?

If you mean it doesn't work with:

CC=XXX make

it is expected.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw

2017-03-30 17:46 GMT+02:00 Wei Liu <[email protected]>:

Quoted 16 lines

Cool. I think Xen should boot with this.

You've successfully finished what I asked for. Now you can divert your energy to polish your application. :-)

Quoted 9 lines · Felix Schmoll

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>

Quoted 8 lines

OOI, how can I reproduce the bug you met?

If you mean it doesn't work with:

CC=XXX make

it is expected.

Yeah, this is what I meant.

I recalled having read on some archived mailing list that it was a bug, but whatever.

Felix

Quoted 3 lines

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel