先参考 https://blog.csdn.net/weixin_43966269/article/details/86711880 完成第一步。
是perf能在开发板上正常运行,在进行如下操作。
1、交叉编译elfutils
参考:
https://blog.csdn.net/liushi558/article/details/53380444
下载路径
https://kojipkgs.fedoraproject.org/packages/elfutils/
1)配置
./configure --host=aarch64-linux --prefix=/opt/libelf CC=aarch64-linux-gcc
2)修改Makefile
vi backends/Makefile 更改, 删除有关i386, x86_64的条目,如下:
原来 libebl_pic = libebl_i386_pic.a libebl_sh_pic.a libebl_x86_64_pic.a \ libebl_ia64_pic.a libebl_alpha_pic.a libebl_arm_pic.a \ libebl_sparc_pic.a libebl_ppc_pic.a libebl_ppc64_pic.a \ libebl_s390_pic.a 删除后 libebl_pic = libebl_sh_pic.a \ libebl_ia64_pic.a libebl_alpha_pic.a libebl_arm_pic.a \ libebl_sparc_pic.a libebl_ppc_pic.a libebl_ppc64_pic.a \ libebl_s390_pic.a 如下进行注释 noinst_LIBRARIES = $(libebl_pic) noinst_DATA = $(libebl_pic:_pic.a=.so) libelf = ../libelf/libelf.so #libelf = ../libelf/libelf.a libdw = ../libdw/libdw.so #libdw = ../libdw/libdw.a #i386_SRCS = i386_init.c i386_symbol.c i386_corenote.c i386_cfi.c \ # i386_retval.c i386_regs.c i386_auxv.c i386_syscall.c #cpu_i386 = ../libcpu/libcpu_i386.a #libebl_i386_pic_a_SOURCES = $(i386_SRCS) #am_libebl_i386_pic_a_OBJECTS = $(i386_SRCS:.c=.os) sh_SRCS = sh_init.c sh_symbol.c sh_corenote.c sh_regs.c sh_retval.c libebl_sh_pic_a_SOURCES = $(sh_SRCS) am_libebl_sh_pic_a_OBJECTS = $(sh_SRCS:.c=.os) #x86_64_SRCS = x86_64_init.c x86_64_symbol.c x86_64_corenote.c x86_64_cfi.c \ #x86_64_retval.c x86_64_regs.c i386_auxv.c x86_64_syscall.c #cpu_x86_64 = ../libcpu/libcpu_x86_64.a #libebl_x86_64_pic_a_SOURCES = $(x86_64_SRCS) #am_libebl_x86_64_pic_a_OBJECTS = $(x86_64_SRCS:.c=.os) #libebl_i386.so: $(cpu_i386) #libebl_x86_64.so: $(cpu_x86_64)
3)编译&安装
make
make install
2、编译perf
export PATH= P A T H : PATH: PATH:CROSS_COMPILE_DIR
make clean
make CROSS_COMPILE=aarch64-linux- ARCH=arm64 LIBDW_DIR=/opt/libelf/ CFLAGS+=-I/opt/libelf/include perf
会出现如下错误:
mkdir -p . make --no-print-directory -C perf O= subdir= BUILD:
Doing ‘make -j4’ parallel buildAuto-detecting system features:
… dwarf: [OFF ]
… glibc: [ on ]
… gtk2: [ OFF ]
… libaudit: [ OFF ]
… libbfd: [ OFF ]
… libelf: [ on ]
… libnuma: [ OFF ]
… numa_num_possible_cpus: [ OFF ]
… libperl: [ OFF ]
… libpython: [ OFF ]
… libslang: [ OFF ]
… libunwind: [ OFF ]
… libdw-dwarf-unwind: [ OFF ]
… zlib: [ on ]
… lzma: [ OFF ]
… get_cpuid: [ OFF ]
… bpf: [ on ]config/Makefile:275: No libdw.h found or old libdw.h found or elfutils
is older than 0.138, disables dwarf support. Please install new
elfutils-devel/libdw-dev config/Makefile:333: No libunwind found.
Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR
config/Makefile:351: Disabling post unwind, no support found.
config/Makefile:392: No libaudit.h found, disables ‘trace’ tool,
please install audit-libs-devel or libaudit-dev config/Makefile:407:
slang not found, disables TUI support. Please install slang-devel or
libslang-dev config/Makefile:421: GTK2 not found, disables GTK2
support. Please install gtk2-devel or libgtk2.0-dev
config/Makefile:467: Missing perl devel files. Disabling perl
scripting support, please install perl-ExtUtils-Embed/libperl-dev
config/Makefile:498: No ‘python-config’ tool was found: disables
Python support - please install python-devel/python-dev
config/Makefile:571: No bfd.h/libbfd found, please install
binutils-dev[el]/zlib-static/libiberty-dev to gain symbol demangling
config/Makefile:600: No liblzma found, disables xz kernel module
decompression, please install xz-devel/liblzma-dev
config/Makefile:613: No numa.h found, disables ‘perf bench numa mem’
benchmark, please install numactl-devel/libnuma-devel/libnuma-dev CC
util/abspath.o CC fd/array.o CC event-parse.o LD
fd/libapi-in.o CC fs/fs.o CC util/alias.o CC
fs/tracing_path.oAuto-detecting system features:
… libelf: [on ]
… bpf: [ on ]CC util/annotate.o CC libbpf.o LD
fs/libapi-in.o CC cpu.o In file included from
util/sort.h:11:0,
from util/annotate.c:12: util/symbol.h:19:20: fatal error: libelf.h: No such file or directory #include <libelf.h>
^ compilation terminated. mv: cannot stat ‘util/.annotate.o.tmp’: No such file or directory
/home/lp-pc/Desktop/AIO-3399J-svn/repository/AIO-buildroot/kernel/tools/build/Makefile.build:87:
recipe for target ‘util/annotate.o’ failed make[4]: ***
[util/annotate.o] Error 1
/home/lp-pc/Desktop/AIO-3399J-svn/repository/AIO-buildroot/kernel/tools/build/Makefile.build:126:
recipe for target ‘util’ failed make[3]: *** [util] Error 2
Makefile.perf:406: recipe for target ‘libperf-in.o’ failed make[2]:
*** [libperf-in.o] Error 2 make[2]: *** Waiting for unfinished jobs… CC event-plugin.o LD libapi-in.o CC
trace-seq.o AR libapi.a CC parse-filter.o CC
parse-utils.o CC bpf.o CC kbuffer-parse.o LD
libbpf-in.o LINK libbpf.a LD libtraceevent-in.o LINK
libtraceevent.a Makefile:68: recipe for target ‘all’ failed make[1]:
*** [all] Error 2 Makefile:69: recipe for target ‘perf’ failed make: *** [perf] Error 2
libelf头文件和库已经指定了,但错误是找不到libelf.h。经过对Makefile分析发现是dwarf: [OFF ]影响导致的。
dwarf需要 build/feature 下编译 test-dwarf.bin
注:不知道为什么在整体编译时有些参数不能传给build里的Makefile,待后续解析
cd build/feature
make CFLAGS="-Wbad-function-cast -Wdeclaration-after-statement -Wformat-security -Wformat-y2k -Winit-self -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wno-system-headers -Wold-style-definition -Wpacked -Wredundant-decls -Wshadow -Wstrict-aliasing=3 -Wstrict-prototypes -Wswitch-default -Wswitch-enum -Wundef -Wwrite-strings -Wformat -DHAVE_PERF_REGS_SUPPORT -O6 -fno-omit-frame-pointer -ggdb3 -funwind-tables -Wall -Wextra -std=gnu99 -I/opt/libelf/include -L/opt/libelf/lib -ldw -lelf" LDFLAGS="-Wl,-z,noexecstack " CROSS_COMPILE=aarch64-linux- test-dwarf.bin
然后在退到tools目录重新进行编译即可生成perf
在将/opt/libelf 目录拷贝到开发板上即可运行perf