14
14
#include "config.h"
15
15
#include "util.h"
16
16
#include <sys/wait.h>
17
+ #include <subcmd/exec-cmd.h>
17
18
18
19
#define CLANG_BPF_CMD_DEFAULT_TEMPLATE \
19
20
"$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\
20
21
"-DLINUX_VERSION_CODE=$LINUX_VERSION_CODE " \
21
- "$CLANG_OPTIONS $KERNEL_INC_OPTIONS " \
22
+ "$CLANG_OPTIONS $KERNEL_INC_OPTIONS $PERF_BPF_INC_OPTIONS " \
22
23
"-Wno-unused-value -Wno-pointer-sign " \
23
24
"-working-directory $WORKING_DIR " \
24
25
"-c \"$CLANG_SOURCE\" -target bpf -O2 -o -"
@@ -212,7 +213,7 @@ version_notice(void)
212
213
" \t\thttp://llvm.org/apt\n\n"
213
214
" \tIf you are using old version of clang, change 'clang-bpf-cmd-template'\n"
214
215
" \toption in [llvm] section of ~/.perfconfig to:\n\n"
215
- " \t \"$CLANG_EXEC $CLANG_OPTIONS $KERNEL_INC_OPTIONS \\\n"
216
+ " \t \"$CLANG_EXEC $CLANG_OPTIONS $KERNEL_INC_OPTIONS $PERF_BPF_INC_OPTIONS \\\n"
216
217
" \t -working-directory $WORKING_DIR -c $CLANG_SOURCE \\\n"
217
218
" \t -emit-llvm -o - | /path/to/llc -march=bpf -filetype=obj -o -\"\n"
218
219
" \t(Replace /path/to/llc with path to your llc)\n\n"
@@ -431,9 +432,11 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
431
432
const char * clang_opt = llvm_param .clang_opt ;
432
433
char clang_path [PATH_MAX ], abspath [PATH_MAX ], nr_cpus_avail_str [64 ];
433
434
char serr [STRERR_BUFSIZE ];
434
- char * kbuild_dir = NULL , * kbuild_include_opts = NULL ;
435
+ char * kbuild_dir = NULL , * kbuild_include_opts = NULL ,
436
+ * perf_bpf_include_opts = NULL ;
435
437
const char * template = llvm_param .clang_bpf_cmd_template ;
436
- char * command_echo , * command_out ;
438
+ char * command_echo = NULL , * command_out ;
439
+ char * perf_include_dir = system_path (PERF_INCLUDE_DIR );
437
440
438
441
if (path [0 ] != '-' && realpath (path , abspath ) == NULL ) {
439
442
err = errno ;
@@ -471,12 +474,14 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
471
474
472
475
snprintf (linux_version_code_str , sizeof (linux_version_code_str ),
473
476
"0x%x" , kernel_version );
474
-
477
+ if (asprintf (& perf_bpf_include_opts , "-I%s/bpf" , perf_include_dir ) < 0 )
478
+ goto errout ;
475
479
force_set_env ("NR_CPUS" , nr_cpus_avail_str );
476
480
force_set_env ("LINUX_VERSION_CODE" , linux_version_code_str );
477
481
force_set_env ("CLANG_EXEC" , clang_path );
478
482
force_set_env ("CLANG_OPTIONS" , clang_opt );
479
483
force_set_env ("KERNEL_INC_OPTIONS" , kbuild_include_opts );
484
+ force_set_env ("PERF_BPF_INC_OPTIONS" , perf_bpf_include_opts );
480
485
force_set_env ("WORKING_DIR" , kbuild_dir ? : "." );
481
486
482
487
/*
@@ -512,6 +517,8 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
512
517
free (command_out );
513
518
free (kbuild_dir );
514
519
free (kbuild_include_opts );
520
+ free (perf_bpf_include_opts );
521
+ free (perf_include_dir );
515
522
516
523
if (!p_obj_buf )
517
524
free (obj_buf );
@@ -526,6 +533,8 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
526
533
free (kbuild_dir );
527
534
free (kbuild_include_opts );
528
535
free (obj_buf );
536
+ free (perf_bpf_include_opts );
537
+ free (perf_include_dir );
529
538
if (p_obj_buf )
530
539
* p_obj_buf = NULL ;
531
540
if (p_obj_buf_sz )
0 commit comments