Re: GCOV coverage on BPF program

Yonghong Song

On Tue, Jun 19, 2018 at 7:54 AM, William Tu <u9012063@...> wrote:

I'm trying to run coverage tests on my bpf program and it compiles fails.
I guess BPF does not support '--coverage' flags?
This will not work.
'-coverage' flag will introduce some additional global functions called
by the program, e.g., __llvm_gcov_init, __llvm_gcov_flush, etc.
global memset functions are
called from one of these functions, global variable __llvm_gcov_ctr is
also introduced.

New clang compiler is much more tolerant on global functions in order
to support function calls in bpf bytecode.

Even if you compile successfully, you may not load the program as
the program compiled with '-coverage' will reference to some
global variables where the loader cannot resolve.

root@boxes:~/ovs# clang-4.0 -Wstrict-prototypes -Wall -Wextra
-Wno-sign-compare -Wpointer-arith -Wformat -Wformat-security
-Wswitch-enum -Wunused-parameter -Wbad-function-cast -Wcast-align
-Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes
-Wmissing-field-initializers -fno-strict-aliasing -Wswitch-bool
-Wlogical-not-parentheses -Wsizeof-array-argument --coverage
-D__NR_CPUS__=4 -O2 -Wall -Werror -emit-llvm -I./include -I./include
-Wno-error=pointer-arith -I/include/uapi/ -c bpf/datapath.c -o - |
llc-4.0 -march=bpf -filetype=obj -o bpf/datapath.o
LLVM ERROR: Cannot select: 0x8b2e90: ch,glue = BPFISD::CALL 0x8b2f60,
TargetExternalSymbol:i64'memset', Register:i64 %R1, Register:i64 %R2,
Register:i64 %R3, 0x8b2f60:1
0x8b2ef8: i64 = TargetExternalSymbol'memset'
0x8b3168: i64 = Register %R1
0x8b3098: i64 = Register %R2
0x8b2fc8: i64 = Register %R3
0x8b2f60: ch,glue = CopyToReg 0x8b3030, Register:i64 %R3,
Constant:i64<1408>, 0x8b3030:1
0x8b2fc8: i64 = Register %R3
0x8b3308: i64 = Constant<1408>
0x8b3030: ch,glue = CopyToReg 0x8b3100, Register:i64 %R2,
Constant:i64<0>, 0x8b3100:1
0x8b3098: i64 = Register %R2
0x8b3238: i64 = Constant<0>
0x8b3100: ch,glue = CopyToReg 0x8b31d0, Register:i64 %R1, 0x73f0f8
0x8b3168: i64 = Register %R1
0x73f0f8: i64 = BPFISD::Wrapper TargetGlobalAddress:i64<[176 x
i64]* @__llvm_gcov_ctr> 0
0x8b2cb8: i64 = TargetGlobalAddress<[176 x i64]* @__llvm_gcov_ctr> 0
In function: __llvm_gcov_flush


Join to automatically receive all group messages.