Skip to content

BTF ​

BTF 的组件名称为 btf, 相关内核选项为

ini
# Kernel hacking
# -> Compile-time checks and compiler options
# -> Compile the kernel with debug info
CONFIG_DEBUG_INFO=y

# Kernel hacking
# -> Compile-time checks and compiler options
# -> Compile the kernel with debug info
# -> Generate BTF typeinfo
CONFIG_DEBUG_INFO_BTF=y

CONFIG_DEBUG_INFO_BTF_MODULES=y

检查工具为

bash
#!/bin/bash

source ./kernel_config_utils.sh
source ./bpf_utils.sh

btf_check() {
    local is_error=false
    if ! kernel_config_check CONFIG_DEBUG_INFO; then
        is_error=true
    fi
    if ! kernel_config_check CONFIG_DEBUG_INFO_BTF; then
        is_error=true
    fi
    if ! kernel_config_check CONFIG_DEBUG_INFO_BTF_MODULES; then
        is_error=true
    fi
    if [ "$is_error" == "true" ]; then
        return 1
    fi

    return 0
}

内核选项 DEBUG_INFO_BTF_MODULES 在 Linux v5.11 中引入, 相关提交号为 5f9ae91f7c0dbbc4195e2a6c8eedcaeb5b9e4cbb.