blob: 7157dcb430e55abd6868cc5c1c8d245b0e7313c7 [file] [log] [blame]
# Copyright 2022 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This template uses the kernel vmlinux (from sysroot) to generate:
# 1. vmlinux.h source that BPFs skeletons build against. Placed in
# vmlinux_out_dir.
# 2. vmlinux.full.btf object that can optionally be used to generate tailored
# min CO-RE BTF objects. Placed in btf_out_dir.
template("generate_vmlinux") {
forward_variables_from(invoker,
[
"btf_out_dir",
"vmlinux_out_dir",
])
out_header = "${root_gen_dir}/${vmlinux_out_dir}/vmlinux.h"
out_btf = "${root_gen_dir}/${btf_out_dir}/vmlinux.full.btf"
action(target_name) {
outputs = [ out_header ]
script = "//secagentd/tools/generate-ebpf.py"
args = [
"gen_vmlinux",
"--sysroot=${sysroot}",
"--out_header=${out_header}",
"--out_btf=${out_btf}",
]
}
}
# This template compiles a C program to target the Linux BPF VM and then
# generates C code to load and interact with the BPF application.
# Also optionally generates a min CO-RE BTF iff called with a non-empty
# btf_inout_dir. The btf_inout_dir must contain a vmlinux.full.btf.
# Generated C code will be placed in bpf_skeleton_out_dir. Generated min CO-RE
# BTF (if requested) will be placed in btf_inout_dir.
template("generate_ebpf_skeletons") {
forward_variables_from(invoker,
[
"bpf_skeleton_out_dir",
"btf_inout_dir",
"defines",
"deps",
])
h_dir = "${root_gen_dir}/${bpf_skeleton_out_dir}"
# TODO(b/243425981): create a new clang wrapper for BPF targets.
# For now BUILD_CC must be used since CC will try to specify target
# a second time.
clang_compiler = getenv("BUILD_CC")
arch = getenv("ARCH")
action_foreach(target_name) {
out_header = "${h_dir}/skeleton_{{source_name_part}}.h"
sources = invoker.sources
outputs = [ out_header ]
script = "//secagentd/tools/generate-ebpf.py"
args = [
"gen_skel",
"--out_header=${out_header}",
"--source={{source}}",
"--clang=${clang_compiler}",
"--arch=${arch}",
"--sysroot=${sysroot}",
"--include",
"${platform2_root}",
"${root_gen_dir}",
]
if (defined(defines)) {
foreach(define, defines) {
args += [ "--defines=" + define ]
}
}
if (btf_inout_dir != "") {
out_min_btf =
"${root_gen_dir}/${btf_inout_dir}/{{source_name_part}}.min.btf"
vmlinux_btf = "${root_gen_dir}/${btf_inout_dir}/vmlinux.full.btf"
args += [
"--out_min_btf=${out_min_btf}",
"--vmlinux_btf=${vmlinux_btf}",
]
outputs += [ out_min_btf ]
}
}
}