linux-stable/tools/perf/util/llvm-utils.h
Wang Nan 4cea3a9cb3 perf tools: Call clang to compile C source to object code
This is the core patch for supporting eBPF on-the-fly compiling, does
the following work:

 1. Search clang compiler using search_program().

 2. Run command template defined in llvm-bpf-cmd-template option in
    [llvm] config section using read_from_pipe(). Patch of clang and
    source code path is injected into shell command using environment
    variable using force_set_env().

  Commiter notice:

  When building with DEBUG=1 we get a compiler error that gets fixed with
  the same approach described in commit b236512280:

    perf kmem: Fix compiler warning about may be accessing uninitialized variable

    The last argument to strtok_r doesn't need to be initialized, its
    just a placeholder to make this routine reentrant, but gcc doesn't know
    about that and complains, breaking the build, fix it by setting it to
    NULL.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Alexei Starovoitov <ast@plumgrid.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Ahern <dsahern@gmail.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kaixu Xia <xiakaixu@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/n/1436445342-1402-14-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-08-07 10:16:59 -03:00

39 lines
1.1 KiB
C

/*
* Copyright (C) 2015, Wang Nan <wangnan0@huawei.com>
* Copyright (C) 2015, Huawei Inc.
*/
#ifndef __LLVM_UTILS_H
#define __LLVM_UTILS_H
#include "debug.h"
struct llvm_param {
/* Path of clang executable */
const char *clang_path;
/*
* Template of clang bpf compiling. 5 env variables
* can be used:
* $CLANG_EXEC: Path to clang.
* $CLANG_OPTIONS: Extra options to clang.
* $KERNEL_INC_OPTIONS: Kernel include directories.
* $WORKING_DIR: Kernel source directory.
* $CLANG_SOURCE: Source file to be compiled.
*/
const char *clang_bpf_cmd_template;
/* Will be filled in $CLANG_OPTIONS */
const char *clang_opt;
/* Where to find kbuild system */
const char *kbuild_dir;
/*
* Arguments passed to make, like 'ARCH=arm' if doing cross
* compiling. Should not be used for dynamic compiling.
*/
const char *kbuild_opts;
};
extern struct llvm_param llvm_param;
extern int perf_llvm_config(const char *var, const char *value);
extern int llvm__compile_bpf(const char *path, void **p_obj_buf,
size_t *p_obj_buf_sz);
#endif