Linux Perf
llvm-utils.c File Reference
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <linux/err.h>
#include "debug.h"
#include "llvm-utils.h"
#include "config.h"
#include "util.h"
#include <sys/wait.h>
#include <subcmd/exec-cmd.h>
Include dependency graph for llvm-utils.c:

Go to the source code of this file.

Macros

#define CLANG_BPF_CMD_DEFAULT_TEMPLATE
 
#define READ_SIZE   4096
 

Functions

int perf_llvm_config (const char *var, const char *value)
 
static int search_program (const char *def, const char *name, char *output)
 
static int read_from_pipe (const char *cmd, void **p_buf, size_t *p_read_sz)
 
static void force_set_env (const char *var, const char *value)
 
static void version_notice (void)
 
static int detect_kbuild_dir (char **kbuild_dir)
 
void llvm__get_kbuild_opts (char **kbuild_dir, char **kbuild_include_opts)
 
int llvm__get_nr_cpus (void)
 
void llvm__dump_obj (const char *path, void *obj_buf, size_t size)
 
int llvm__compile_bpf (const char *path, void **p_obj_buf, size_t *p_obj_buf_sz)
 
int llvm__search_clang (void)
 

Variables

struct llvm_param llvm_param
 
static const char * kinc_fetch_script
 

Macro Definition Documentation

◆ CLANG_BPF_CMD_DEFAULT_TEMPLATE

#define CLANG_BPF_CMD_DEFAULT_TEMPLATE
Value:
"$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\
"-DLINUX_VERSION_CODE=$LINUX_VERSION_CODE " \
"$CLANG_OPTIONS $KERNEL_INC_OPTIONS $PERF_BPF_INC_OPTIONS " \
"-Wno-unused-value -Wno-pointer-sign " \
"-working-directory $WORKING_DIR " \
"-c \"$CLANG_SOURCE\" -target bpf -O2 -o -"

Definition at line 19 of file llvm-utils.c.

◆ READ_SIZE

#define READ_SIZE   4096

Definition at line 104 of file llvm-utils.c.

Function Documentation

◆ detect_kbuild_dir()

static int detect_kbuild_dir ( char **  kbuild_dir)
static

Definition at line 223 of file llvm-utils.c.

Here is the call graph for this function:

◆ force_set_env()

static void force_set_env ( const char *  var,
const char *  value 
)
inlinestatic

Definition at line 191 of file llvm-utils.c.

◆ llvm__compile_bpf()

int llvm__compile_bpf ( const char *  path,
void **  p_obj_buf,
size_t *  p_obj_buf_sz 
)

Definition at line 424 of file llvm-utils.c.

Here is the call graph for this function:

◆ llvm__dump_obj()

void llvm__dump_obj ( const char *  path,
void *  obj_buf,
size_t  size 
)

Definition at line 389 of file llvm-utils.c.

Here is the call graph for this function:

◆ llvm__get_kbuild_opts()

void llvm__get_kbuild_opts ( char **  kbuild_dir,
char **  kbuild_include_opts 
)

Definition at line 291 of file llvm-utils.c.

Here is the call graph for this function:

◆ llvm__get_nr_cpus()

int llvm__get_nr_cpus ( void  )

Definition at line 371 of file llvm-utils.c.

◆ llvm__search_clang()

int llvm__search_clang ( void  )

Definition at line 545 of file llvm-utils.c.

Here is the call graph for this function:

◆ perf_llvm_config()

int perf_llvm_config ( const char *  var,
const char *  value 
)

Definition at line 36 of file llvm-utils.c.

Here is the call graph for this function:

◆ read_from_pipe()

static int read_from_pipe ( const char *  cmd,
void **  p_buf,
size_t *  p_read_sz 
)
static

Definition at line 106 of file llvm-utils.c.

Here is the call graph for this function:

◆ search_program()

static int search_program ( const char *  def,
const char *  name,
char *  output 
)
static

Definition at line 63 of file llvm-utils.c.

Here is the call graph for this function:

◆ version_notice()

static void version_notice ( void  )
static

Definition at line 203 of file llvm-utils.c.

Variable Documentation

◆ kinc_fetch_script

const char* kinc_fetch_script
static
Initial value:
=
"#!/usr/bin/env sh\n"
"if ! test -d \"$KBUILD_DIR\"\n"
"then\n"
" exit -1\n"
"fi\n"
"if ! test -f \"$KBUILD_DIR/include/generated/autoconf.h\"\n"
"then\n"
" exit -1\n"
"fi\n"
"TMPDIR=`mktemp -d`\n"
"if test -z \"$TMPDIR\"\n"
"then\n"
" exit -1\n"
"fi\n"
"cat << EOF > $TMPDIR/Makefile\n"
"obj-y := dummy.o\n"
"\\$(obj)/%.o: \\$(src)/%.c\n"
"\t@echo -n \"\\$(NOSTDINC_FLAGS) \\$(LINUXINCLUDE) \\$(EXTRA_CFLAGS)\"\n"
"EOF\n"
"touch $TMPDIR/dummy.c\n"
"make -s -C $KBUILD_DIR M=$TMPDIR $KBUILD_OPTS dummy.o 2>/dev/null\n"
"RET=$?\n"
"rm -rf $TMPDIR\n"
"exit $RET\n"

Definition at line 265 of file llvm-utils.c.

◆ llvm_param

Initial value:
= {
.clang_path = "clang",
.clang_bpf_cmd_template = CLANG_BPF_CMD_DEFAULT_TEMPLATE,
.clang_opt = NULL,
.kbuild_dir = NULL,
.kbuild_opts = NULL,
.user_set_param = false,
}
#define CLANG_BPF_CMD_DEFAULT_TEMPLATE
Definition: llvm-utils.c:19

Definition at line 27 of file llvm-utils.c.