目录
perf 交叉编译
perf 源码在linux内核源码里面,目录: /linux-4.19.232/tools/perf ,下载对应linux内核源码即可找到perf源码,使用源码交叉编译。
uname -r #查询arm内核版本
4.19.232
官网下载对应版本内核源码
https://ftp.sjtu.edu.cn/sites/ftp.kernel.org/pub/linux/kernel/
https://mirror.bjtu.edu.cn/kernel/linux/kernel/
交叉编译工具链配置参考:
export CXX=/home/tom/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-g++
export CC=/home/tom/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc
export AR=/home/tom/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc-ar
export LD=/home/tom/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-ld
export AS=/home/tom/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-as
export RANLIB=/home/tom/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-ranlib
export ARCH=arm
perf交叉编译
perf基本特性依赖zlib和elfutils,elfutils编译生成的动态库用于符号解析,没有的话perf只能看到热点函数地址。
交叉编译zlib
下载zlib-1.2.3.tar.gz
http://www.zlib.net/
tar xvf zlib-1.2.3.tar.gz
cd zlib-1.2.3/
export CC=/home/tom/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc
mkdir build
./configure --prefix=/home/tom/perf/zlib-1.2.3/build
make -j4
make install
交叉编译 elfutils
下载 elfutils-0.170.tar.bz2
https://www.linuxfromscratch.org/blfs/view/8.1/general/elfutils.html
tar xvf elfutils-0.170.tar.bz2
cd elfutils-0.170/
mkdir build
export CC=/home/tom/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc
export LDFLAGS=-L/home/tom/perf/zlib-1.2.3/build/lib
export CPPFLAGS=-I/home/tom/perf/zlib-1.2.3/build/include
export LIBS=-lz
./configure --host=arm-linux --prefix=/home/tom/perf/elfutils-0.170/build
make
报错解决:
报错: [-Werror=missing-attributes]
查找报错.c文件所在文件夹里的Makefile文件,删除里面的 -Werror ,例如:
$(if $($(*F)_no_Werror),,-Werror) \
# 修改为
$(if $($(*F)_no_Werror),,) \
报错: WARNING: TEXTREL found in ‘libdw.so’
找到对应文件夹里的Makefile文件
textrel_found = $(textrel_msg); exit 1
# 修改为
textrel_found = $(textrel_msg)
make install
生成动态库: libasm.so 、libdw.so、 libelf.so。
将build/lib目录生成的相关动态库拷贝到交叉编译工具链的libc下,将build/include目录下头文件拷贝到交叉编译工具链libc同级的include目录下。
交叉编译 perf
tar xvf linux-4.19.232.tar.gz
cd linux-4.19.232/tools/perf/
vim Makefile
# 文件最前面加入
export CXX=/home/tom/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-g++
export CC=/home/tom/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc
export AR=/home/tom/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc-ar
export LD=/home/tom/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-ld
export AS=/home/tom/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-as
export RANLIB=/home/tom/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-ranlib
# 该命令可能无效
export EXTLIBS =--static -lelf -lebl -L/home/tom/perf/zlib-1.2.3/build/lib -L/home/tom/perf/elfutils-0.170/build/lib
export ARCH=arm
export CROSS_COMPILE=arm-linux-
make
在当前目录生成可执行文件 perf ,拷贝到arm板子上运行, elfutils 编译生成的3个动态库也拷贝过去,使用export设置环境变量。
报错处理:
如果有把告警当成错误的情况,找到Makefile文件里的-Werror并注释掉。
Makefile.config,注释掉 CFLAGS += -Werror 和 CXXFLAGS += -Werror
multiple definition of runtime'; multiple definition of
end’;
multiple definition of `start
报错,查看源码发现有两个.c文件(futex-hash.c,futex-lock-pi.c)定义了同名的结构体,把其中一个文件里的名字修改一下即可,比如runtime修改为runtime1.
undefined reference to arm_spe_pmu_default_config undefined reference to
arm_spe_recording_init
明明有定义还是报这个错误,不是重要的函数,找到调用的地方注释掉。
arch/arm/tests/regs_load.S:58: Error: operand 1 must be an integer register – mov pc,lr
这个报错涉及到汇编,看不懂不要紧,修改构建文件不编译这个文件。
/linux-4.19.232/tools/perf/arch/arm/tests/Build,注释掉 libperf-y += regs_load.o
/linux-4.19.232/tools/perf/arch/arm64/tests/Build,注释掉 libperf-y += regs_load.o
还会报找不到 perf_regs_load ,在源码里把调用的地方注释掉。
perf看不到函数符号
make时会检测特性: Auto-detecting system features
符号解析由 libelf 功能完成,如果内核检出该功能为off状态,则perf看不到函数符号,只有地址。
上面编译 elfutils 成功后把库文件和头文件拷贝到工具链相应目录,如果检测不到,可能是没有拷贝正确。
内核检测特性是使用test测试文件,查看内核源码perf同级目录的build/feature文件夹,里面有大量测试文件,找到 test-libelf.make.output 文件,这里保存了检测 libelf 功能的日志,根据报错日志排查问题。
perf 使用
# 查看指定进程的热点函数,加选项-g生成热点函数调用栈
./perf top -p 3593
# 生成火焰图
./perf record -F 180 -p 3593 -g -- sleep 120
# 当前目录生成 perf.data 文件
libconfig 交叉编译
cd libconfig-1.7.3/
export CC=/opt/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-gcc
export CXX=/opt/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-g++
export AR=/opt/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-ar
export LD=/opt/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-ld
export AS=/opt/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-as
export RANLIB=/opt/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-ranlib
./configure --host=arm-linux-gnueabi --prefix=/opt/libconfig
make -j
sudo make install
openssl 交叉编译
下载
https://www.openssl.org/source/old/1.0.2/index.html
openssl-1.0.2k.tar.gz
tar xvf openssl-1.0.2k.tar.gz
cd openssl-1.0.2k
mkdir install
sudo ./config no-asm shared no-async --prefix=$(pwd)/install --cross-compile-prefix=/opt/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-
make -j
make install
报错:libncurses.so.5: cannot open shared object file
sudo apt install libncurses5
libpcap 交叉编译
libpcap-1.10.1.tar.gz
tar xvf libpcap-1.10.1.tar.gz
cd libpcap-1.10.1
export CC=/home/tom/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-gcc
export CXX=/home/tom/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-g++
export AR=/home/tom/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-ar
export LD=/home/tom/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-ld
export AS=/home/tom/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-as
export RANLIB=/home/tom/gcc-arm-linux-gnueabi/bin/arm-linux-gnueabihf-ranlib
./configure --host=arm-linux-gnueabi --prefix=/opt/libpcap
报错:configure: error: Neither flex nor lex was found
sudo apt-get install flex
报错:configure: error: Neither bison, byacc, nor yacc was found
sudo apt-get update
sudo apt-get install bison
统信、龙芯等平台编译
QT交叉编译
编译QT源码
下载源码包:https://download.qt.io/archive/qt/
qt-everywhere-src-5.12.8.tar.xz
tar xvf qt-everywhere-src-5.12.8.tar.xz
cd /home/tom/work/src/qt-everywhere-src-5.12.8
#配置
./configure -prefix /home/tom/work/qt5.12.8 \
-confirm-license \
-release \
-opensource \
-v
#编译
make -j4
make install
cd /home/tom/work/qt5.12.8/bin
./qmake --version
编译QtCreator
下载源码包:https://download.qt.io/archive/qtcreator/4.11/4.11.2/
qt-creator-opensource-src-4.11.2.tar.gz
tar xvf qt-creator-opensource-src-4.11.2.tar.gz
cd /home/tom/work/src/qt-creator-opensource-src-4.11.2/
export PATH=/home/tom/work/qt5.12.8/bin:$PATH
qmake -version
qmake
make -j4
cd bin
./qtcreator
报错解决
error: alsa/asoundlib.h: No such file or directory #include <alsa/asoundlib.h>
sudo apt-get install libasound2-dev
cast from ‘QTJSC::JSCell*’ to ‘int32_t’ {aka ‘int’} loses precision [-fpermissive]
qtscript/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSValue.h
把int32_t改为int64_t就可以了
target architecture was not detected as supported by double-conversion
报错的文件为qtbase/src/3rdparty/double-conversion/include/double-conversion/utils.h
在defined(__mips__) ||后添加宏defined(__loongarch__)
编译ssl
git clone https://github.com/openssl/openssl.git
./config --prefix=/home/admin/tom/deplib/openssl/build
make -j4
make install
编译libsrtp(2.3.0版本)
git clone https://github.com/cisco/libsrtp.git
error: cannot guess build type; you must specify one
./configure --build=loongarch64-unknown-linux
make -j4
srtp_create创建失败,不支持部分加密选项,重新编译
./configure --build=loongarch64-unknown-linux --enable-openssl --with-openssl-dir=/home/admin/tom/deplib/openssl/build --prefix=/home/admin/tom/deplib/libsrtp-2.3.0/build
编译libyuv
git clone https://github.com/lemenkov/libyuv.git
cd libyuv/
sudo apt-get install cmake
mkdir arm_libyuv
mkdir build
cd build
cmake ../ -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/admin/tom/deplib/libyuv/arm_libyuv
make -j4
make install
libopus编译
http://www.opus-codec.org/
下载:opus-1.4.tar.gz
mkdir build
/configure --build=loongarch64-unknown-linux --prefix=/home/admin/tom/deplib/opus-1.4/build
make -j4
make install
libopenh264编译
git clone https://github.com/cisco/openh264.git
make OS=linux
libusrsctp编译
git clone https://github.com/sctplab/usrsctp.git
./bootstrap
mkdir build
./configure --build=loongarch64-unknown-linux --prefix=/home/admin/tom/deplib/usrsctp/build
make -j4
make install
Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR
apt-get install libssl-dev
libsioclient编译
下载:
https://www.cnblogs.com/kn-zheng/p/17749207.html
https://github.com/socketio/socket.io-client-cpp/releases
socket.io-client-cpp-3.0.0.tar.gz
cd socket.io-client-cpp-3.0.0/lib
https://github.com/chriskohlhoff/asio/tags?after=asio-1-18-2
asio-asio-1-18-1.tar.gz
git clone https://github.com/Tencent/rapidjson.git
git clone https://github.com/zaphoyd/websocketpp.git
https://github.com/catchorg/Catch2/tags?after=v2.13.8
Catch2-2.13.4.tar.gz
cd ..
mkdir build
cd build
cmake ..
make -j4
编译gdb
sudo apt install gdb #如果能直接安装,不需要自己编译
wget http://ftp.gnu.org/gnu/gdb/gdb-12.1.tar.gz
cd gdb-12.1
mkdir build
cd build
../configure --prefix=/usr --target=loongarch64-unknown-linux-gnu
make -j4
sudo make install
WARNING: ‘makeinfo’ is missing on your system
sudo apt-get install texinfo
error: GMP is missing or unusable
sudo apt-get install libgmp-dev
x264编译
mkdir build
./configure --enable-static --enable-shared --prefix=/home/admin/tom/deplib_so/x264-snapshot-20191024-2245-stable/build --enable-pic
configure: error: cannot guess build type; you must specify one
修改config.guess,在mips:Linux:: | mips64:Linux::)前添加
loongarch*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
ffmpeg编译
x264和ffmpeg编译过程参考:Qt+ubuntu+ffmpeg环境搭建,ffmpeg库的编译与调用
./configure --build=loongarch64-unknown-linux --enable-shared --enable-nonfree --enable-gpl --enable-pthreads --enable-libx264 --prefix=/home/admin/tom/ffmpeg_so/ffmpeg-4.0.6/build –extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib