You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

编译5.15.0内核后perf安装失败:init_disassemble_info参数不足

解决自行编译5.15.0内核后Perf工具的安装问题

问题原因分析

你遇到的源码编译Perf报错,本质是5.15.0版本内核的Perf代码依赖的libbfd接口,和Ubuntu18.04默认的2.30版本libbfd不兼容。高版本内核的init_disassemble_info调用需要更多参数,而旧版libbfd不支持,即使加NO_LIBBFD=1也可能因为编译缓存或未彻底禁用相关依赖导致报错。


分步解决方案

方案1:彻底禁用libbfd依赖编译Perf

如果不需要Perf的反汇编注释功能,可以彻底禁用libbfd相关依赖,步骤如下:

  • 进入内核源码的tools/perf目录:
    cd /path/to/your/linux-5.15.0/tools/perf
    
  • 清理之前的编译缓存:
    make clean
    
  • 用以下参数重新编译,同时禁用libbfd和其他可能冲突的依赖:
    make NO_LIBBFD=1 NO_LIBELF=1 NO_DWARF=1
    
  • 编译完成后安装Perf:
    make install
    

方案2:升级系统libbfd版本(推荐,保留Perf完整功能)

如果需要Perf的反汇编等完整功能,建议升级libbfd到兼容版本:

  • 从源码编译安装高版本的binutils(包含libbfd),比如2.38版本(和5.15内核兼容性较好):
    1. 下载binutils源码:
      wget https://ftp.gnu.org/gnu/binutils/binutils-2.38.tar.xz
      tar -xf binutils-2.38.tar.xz
      cd binutils-2.38
      
    2. 配置编译选项,指定安装路径(避免覆盖系统默认版本):
      ./configure --prefix=/usr/local/binutils --disable-werror
      
    3. 编译并安装:
      make -j$(nproc)
      sudo make install
      
    4. 让Perf编译时优先使用新安装的libbfd:
      cd /path/to/your/linux-5.15.0/tools/perf
      make clean
      make CFLAGS="-I/usr/local/binutils/include" LDFLAGS="-L/usr/local/binutils/lib"
      sudo make install
      

方案3:修改Perf源码适配旧版libbfd(可选)

如果不想升级binutils,可以修改Perf源码中util/annotate.c的函数调用,适配旧版libbfd的参数格式:

  • 打开util/annotate.c文件,找到symbol__disassemble_bpf函数里的init_disassemble_info调用,将参数调整为旧版libbfd支持的格式:
    旧版libbfd的init_disassemble_info原型为:
    void init_disassemble_info (disassemble_info *info, FILE *stream,
                                fprintf_ftype fprintf_func);
    
    删除代码中多余的参数,只保留前三个,示例调整后:
    init_disassemble_info(&info, stdout, (fprintf_ftype) fprintf);
    
  • 修改后保存,重新编译Perf:
    make
    sudo make install
    

内容的提问来源于stack exchange,提问作者citrusyi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 18:40:10