forked from linuxkerneltravel/lmp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request linuxkerneltravel#764 from ziyangfu/develop
MagicEyes: [new feature] cross compile arm64 BPF programs in x64 platform
- Loading branch information
Showing
59 changed files
with
8,971 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,50 @@ | ||
# MagicEyes | ||
|
||
## 1. 简介 | ||
|
||
一款用于Linux内核的可观测性定制工具,覆盖CPU、内存、网络、文件、虚拟化等子系统。 | ||
|
||
母项目直达:[lmp](https://github.com/linuxkerneltravel/lmp) | ||
|
||
## 2. 架构 | ||
|
||
![basic_arch](./docs/introduction/images_dir/basic_arch.png) | ||
|
||
## 3. 目前已有的工具 | ||
|
||
- 文件系统部分 | ||
- [x] fs_watcher | ||
- [x] fs_watcher | ||
|
||
- 内存部分 | ||
- [x] mem_watcher | ||
- [x] mem_watcher | ||
|
||
- 网络部分 | ||
- [x] net_watcher | ||
- [x] net_watcher | ||
|
||
- CPU部分 | ||
- [x] cpu_watcher | ||
- [x] proc_image | ||
- [x] cpu_watcher | ||
- [x] proc_image | ||
|
||
- 虚拟化部分 | ||
- [x] kvm_watcher | ||
- [x] kvm_watcher | ||
|
||
- 系统诊断与调优 | ||
- [x] stack_analyzer | ||
- [x] stack_analyzer | ||
|
||
|
||
## 4. 编译安装 | ||
|
||
```bash | ||
git clone git clone --recurse-submodules <magic_eyes_address> | ||
git clone --recurse-submodules <magic_eyes_address> | ||
mkdir build && cd build | ||
# 编译所有工具 | ||
cmake -DBUILD_ALL=ON -D -DCMAKE_INSTALL_PREFIX=<install_dir> .. | ||
# 编译单独某个工具,如 fs_watcher | ||
# ------------------------------------------------------- | ||
# 若想要编译所有工具 | ||
cmake -DBUILD_ALL=ON -DCMAKE_INSTALL_PREFIX=<install_dir> .. | ||
# 若想要编译单独某个工具,如 fs_watcher | ||
cmake -DBUILD_FS_WATCHER=ON .. | ||
# 若想在x64平台交叉编译出arm64平台的程序(TARCH 即 target arch) | ||
cmake -DBUILD_ALL=ON -DTARCH=arm64 .. | ||
# ------------------------------------------------------- | ||
make | ||
make install | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,31 @@ | ||
ARM64平台交叉编译工具链 | ||
# ARM64平台交叉编译工具链 | ||
|
||
## How to install aarch64-linux-gnu- compilation tools for cross-compilation? | ||
|
||
1. install the Ubuntu toolchain gcc-aarch64-linux-gnu GNU C compiler for the arm64 architecture | ||
|
||
``` sudo apt-get install gcc-aarch64-linux-gnu ``` | ||
|
||
|
||
|
||
2. export the environment variable ARCH and CROSS_COMPILE | ||
|
||
``` export ARCH=arm64 && export CROSS_COMPILE=/usr/bin/aarch64-linux-gnu- ``` | ||
|
||
|
||
|
||
3. After done before installation, cmake will automatically detect the cross-compilation tools. | ||
|
||
|
||
|
||
|
||
## What is the arm64_linux_setup.cmake? | ||
|
||
This file is a cmake module used to set the arm64 cross-compilation environment in the cmake project. | ||
|
||
|
||
|
||
|
||
## What is the dependency directory? | ||
|
||
The dependency directory is used to store the dependent libraries for arm64 cross-compilation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
set(CMAKE_SYSTEM_NAME Linux) #设置目标系统名字 | ||
set(CMAKE_SYSTEM_PROCESSOR arm64) #设置目标处理器架构 | ||
|
||
#设置libbpf和bpftool的make编译选项 | ||
set(CROSS_COMPILE "aarch64-linux-gnu-") | ||
|
||
#检查交叉编译链是否存在于系统环境变量中,不存在报错结束 | ||
find_program(CMAKE_C_COMPILE_PATH NAMES ${CMAKE_C_COMPILER} PATHS $ENV{PATH}) | ||
find_program(CMAKE_CXX_COMPILE_PATH NAMES ${CMAKE_CXX_COMPILER} PATHS $ENV{PATH}) | ||
if(NOT CMAKE_C_COMPILE_PATH OR NOT CMAKE_CXX_COMPILE_PATH) | ||
message(FATAL_ERROR "Can't find aarch64 compiler, please add it to system environment variable!") | ||
endif() | ||
|
||
# 指定交叉编译链 | ||
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) | ||
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) | ||
message(STATUS "The C compiler identification is ${CMAKE_C_COMPILER} now") | ||
message(STATUS "The CXX compiler identification is ${CMAKE_CXX_COMPILER} now") | ||
|
||
set(CC ${CMAKE_C_COMPILER}) | ||
|
||
|
||
#引入libbpf的依赖库zlib, elf | ||
set(ZLIB_ARM64_DIR "${PROJECT_SOURCE_DIR}/platforms/aarch64/dependency/zlib-1.3.1/lib") | ||
set(ELF_ARM64_DIR "${PROJECT_SOURCE_DIR}/platforms/aarch64/dependency/elfutils-0.189/lib") | ||
set(ZLIB_SOURCE_DIR ${PROJECT_SOURCE_DIR}/platforms/aarch64/dependency/zlib-1.3.1/) | ||
set(ELF_SOURCE_DIR ${PROJECT_SOURCE_DIR}/platforms/aarch64/dependency/elfutils-0.189/) | ||
include_directories( | ||
${ZLIB_SOURCE_DIR}/include | ||
${ELF_SOURCE_DIR}/include) | ||
|
||
message(STATUS "Arm64 cross-compilation set-up run successfully") | ||
#bpf.c 使用clang编译,.c使用gcc编译 |
Binary file added
BIN
+33.8 KB
MagicEyes/platforms/aarch64/dependency/elfutils-0.189/bin/eu-addr2line
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+38.6 KB
MagicEyes/platforms/aarch64/dependency/elfutils-0.189/bin/eu-elfclassify
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+37.6 KB
MagicEyes/platforms/aarch64/dependency/elfutils-0.189/bin/eu-elfcompress
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+23.7 KB
MagicEyes/platforms/aarch64/dependency/elfutils-0.189/bin/eu-findtextrel
Binary file not shown.
132 changes: 132 additions & 0 deletions
132
MagicEyes/platforms/aarch64/dependency/elfutils-0.189/bin/eu-make-debug-archive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#!/bin/sh | ||
# | ||
# Script to make an offline archive for debugging with libdwfl-based tools. | ||
# | ||
# make-debug-archive ARCHIVE {options} | ||
# make-debug-archive --kernel [--force] [RELEASE] | ||
# | ||
# Valid options are those listed under 'Input selection options' | ||
# by running /home/jerry/Downloads/toolchain/elfutils-0.189/_install/bin/eu-unstrip --help. | ||
# | ||
# The archive installed by --kernel be used automatically by -K. | ||
# An offline archive can be used via -e in any tool that accepts those options. | ||
# | ||
|
||
UNSTRIP=${UNSTRIP:-/home/jerry/Downloads/toolchain/elfutils-0.189/_install/bin/eu-unstrip} | ||
AR=${AR:-/home/jerry/Downloads/toolchain/elfutils-0.189/_install/bin/eu-ar} | ||
SUDO=${SUDO:-/usr/bin/sudo} | ||
|
||
LS=/bin/ls | ||
RM=/bin/rm | ||
MV=/bin/mv | ||
MKDIR=/bin/mkdir | ||
XARGS=/usr/bin/xargs | ||
|
||
outdir=${TMPDIR:-/tmp}/debugar$$ | ||
|
||
usage() | ||
{ | ||
echo "Usage: $0 ARCHIVE {options}" | ||
echo " or: $0 --kernel [--sudo] [--force] [RELEASE]" | ||
echo | ||
echo "Valid options are listed under 'Input selection options'" | ||
echo "when running: $UNSTRIP --help" | ||
echo | ||
echo "The --kernel form updates the file used by -K if the" | ||
echo "kernel installation has changed, or always with --force." | ||
echo "With --sudo, touches the installed file via $SUDO." | ||
} | ||
|
||
fatal_usage() | ||
{ | ||
usage >&2 | ||
exit 2 | ||
} | ||
|
||
script_version() | ||
{ | ||
echo "`basename $0` (elfutils) 0.189" | ||
echo "Copyright (C) 2007 Red Hat, Inc." | ||
echo "This is free software; see the source for copying conditions." | ||
echo "There is NO warranty; not even for MERCHANTABILITY or" | ||
echo "FITNESS FOR A PARTICULAR PURPOSE." | ||
echo "Written by Roland McGrath." | ||
} | ||
|
||
sudo= | ||
kernel=no | ||
force_kernel=no | ||
while [ $# -gt 0 ]; do | ||
case "x$1" in | ||
x--help) usage; exit 0 ;; | ||
x--version) script_version; exit 0 ;; | ||
x--kernel) kernel=yes ;; | ||
x--force) force_kernel=yes ;; | ||
x--sudo) sudo=$SUDO ;; | ||
*) break ;; | ||
esac | ||
shift | ||
done | ||
|
||
if [ $kernel = no ] && [ $force_kernel = yes -o -n "$sudo" ]; then | ||
usage | ||
fi | ||
|
||
if [ $kernel = yes ]; then | ||
if [ $# -eq 0 ]; then | ||
release=`uname -r` | ||
elif [ $# -eq 1 ]; then | ||
release=$1 | ||
else | ||
fatal_usage | ||
fi | ||
|
||
dir=/usr/lib/debug/lib/modules/$release | ||
archive=$dir/debug.a | ||
dep=/lib/modules/$release/modules.dep | ||
|
||
if [ ! -d $dir ]; then | ||
echo >&2 "$0: $dir not installed" | ||
exit 1 | ||
fi | ||
|
||
# Without --force, bail if the kernel installation is not newer. | ||
# This file is normally touched by installing new kernels or modules. | ||
if [ $force_kernel = no -a "$archive" -nt "$dep" ]; then | ||
exit 0 | ||
fi | ||
|
||
# We have to kill the old one first, because our own -K would use it. | ||
[ ! -e "$archive" ] || $sudo $RM -f "$archive" || exit | ||
|
||
set "$archive" "-K$release" | ||
fi | ||
|
||
if [ $# -lt 2 ]; then | ||
fatal_usage | ||
fi | ||
|
||
archive="$1" | ||
shift | ||
|
||
case "$archive" in | ||
/*) ;; | ||
*) archive="`/bin/pwd`/$archive" ;; | ||
esac | ||
|
||
if [ -z "$sudo" ]; then | ||
new_archive="$archive.new" | ||
else | ||
new_archive="$outdir.a" | ||
fi | ||
|
||
$RM -f "$new_archive" || exit | ||
|
||
trap '$RM -rf "$outdir" "$new_archive"' 0 1 2 15 | ||
|
||
$MKDIR "$outdir" && | ||
$UNSTRIP -d "$outdir" -m -a -R "$@" && | ||
(cd "$outdir" && $LS | $XARGS $AR cq "$new_archive") && | ||
$sudo $MV -f "$new_archive" "$archive" | ||
|
||
exit |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.