llvm-utils.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com>
  3. * Copyright (C) 2015, Huawei Inc.
  4. */
  5. #ifndef __LLVM_UTILS_H
  6. #define __LLVM_UTILS_H
  7. #include "debug.h"
  8. struct llvm_param {
  9. /* Path of clang executable */
  10. const char *clang_path;
  11. /*
  12. * Template of clang bpf compiling. 5 env variables
  13. * can be used:
  14. * $CLANG_EXEC: Path to clang.
  15. * $CLANG_OPTIONS: Extra options to clang.
  16. * $KERNEL_INC_OPTIONS: Kernel include directories.
  17. * $WORKING_DIR: Kernel source directory.
  18. * $CLANG_SOURCE: Source file to be compiled.
  19. */
  20. const char *clang_bpf_cmd_template;
  21. /* Will be filled in $CLANG_OPTIONS */
  22. const char *clang_opt;
  23. /* Where to find kbuild system */
  24. const char *kbuild_dir;
  25. /*
  26. * Arguments passed to make, like 'ARCH=arm' if doing cross
  27. * compiling. Should not be used for dynamic compiling.
  28. */
  29. const char *kbuild_opts;
  30. /*
  31. * Default is false. If set to true, write compiling result
  32. * to object file.
  33. */
  34. bool dump_obj;
  35. /*
  36. * Default is false. If one of the above fields is set by user
  37. * explicitly then user_set_llvm is set to true. This is used
  38. * for perf test. If user doesn't set anything in .perfconfig
  39. * and clang is not found, don't trigger llvm test.
  40. */
  41. bool user_set_param;
  42. };
  43. extern struct llvm_param llvm_param;
  44. int perf_llvm_config(const char *var, const char *value);
  45. int llvm__compile_bpf(const char *path, void **p_obj_buf, size_t *p_obj_buf_sz);
  46. /* This function is for test__llvm() use only */
  47. int llvm__search_clang(void);
  48. #endif