facebook的 atosl 是一个 可在linux 环境下运行的部分替代macOS上 atos
的工具,但facebook从2013年开始就不再维护这个项目了,官方介绍的编译方式现在也有一定的问题,一番摸索后终于编译通过,现将过程记录一下
Linux下编译
atosl
依赖 libdwarf 库,这个库原本是可以用apt-get直接安装的,但这个库一直在不断迭代,atosl
当时使用的 libdwarf
版本和最新的版本已经有很大的出入,有些方法已经被移除,导致 atosl
无法编译通过
wget https://github.com/facebookarchive/atosl/archive/refs/tags/1.1.tar.gz
tar zxvf 1.1.tar.gz
cd atosl-1.1
make
cc -Wall -Werror -O2 -DATOSL_VERSION=\"1.1\" -MM atosl.c > atosl.dep
cc -Wall -Werror -O2 -DATOSL_VERSION=\"1.1\" -o atosl.o -c atosl.c
cc -o atosl atosl.o -ldwarf -liberty
/usr/bin/ld: atosl.o: in function `parse_function_starts':
atosl.c:(.text+0xe37): undefined reference to `_dwarf_decode_u_leb128'
/usr/bin/ld: atosl.c:(.text+0xe8b): undefined reference to `_dwarf_decode_u_leb128'
collect2: error: ld returned 1 exit status
make: *** [Makefile:18: atosl] Error 1
解决办法:卸载当前已安装的libdwarf
, 再安装旧版,这里选用版本 https://github.com/davea42/libdwarf-code/archive/refs/tags/20130729.tar.gz
apt remove libdwarf-dev libdwarf1
wget https://github.com/davea42/libdwarf-code/archive/refs/tags/20130729.tar.gz
tar zxvf 20130729.tar.gz
cd libdwarf-code-20130729/libdwarf/
./configure
make
# 拷贝头文件
cp ./dwarf.h ./libdwarf.h /usr/local/include/
# 拷贝库文件
cp libdwarf.a /usr/local/lib/
再次编译 atosl
cd ~/atosl-1.1/
make clean
make && make install
root@debian:~/atosl-1.1# atosl --help
atosl 1.1
Usage: atosl -o|--dsym <FILENAME> [OPTIONS]... <ADDRESS>...
-o, --dsym=FILE file to find symbols in
-v, --verbose enable verbose (debug) messages
-l, --load_address=ADDRESS specify application load address
-A, --arch=ARCH specify architecture
-g, --globals lookup symbols using global section
-V, --version get current version
-h, --help this help
编译通过
macOS 下编译
安装libelf
brew install libelf
Warning: libelf has been deprecated because it is not maintained upstream!
==> Downloading https://mirrors.aliyun.com/homebrew/homebrew-bottles/libelf-0.8.13_1.arm64_monterey.bottle.tar.gz
Already downloaded: /Users/zy/Library/Caches/Homebrew/downloads/9261a6b93fffc5a1e840632eddb43d2d1e5dd684fb88454fedd0be2cf108d9a1--libelf-0.8.13_1.arm64_monterey.bottle.tar.gz
==> Pouring libelf-0.8.13_1.arm64_monterey.bottle.tar.gz
🍺 /opt/homebrew/Cellar/libelf/0.8.13_1: 13 files, 239.4KB
# 移动 libelf的头文件和库文件
sudo cp -r /opt/homebrew/Cellar/libelf/0.8.13_1/include/libelf /usr/local/include/
sudo cp /opt/homebrew/Cellar/libelf/0.8.13_1/lib/libelf.a /usr/local/lib/
安装libdwarf
wget https://github.com/davea42/libdwarf-code/archive/refs/tags/20130729.tar.gz
tar zxvf 20130729.tar.gz
cd libdwarf-code-20130729/libdwarf/
./configure
make
# 拷贝头文件
sudo cp ./dwarf.h ./libdwarf.h /usr/local/include/
# 拷贝库文件
sudo cp ./libdwarf.a /usr/local/lib/
安装libiberty
wget http://ftpmirror.gnu.org/binutils/binutils-2.24.tar.gz
tar zxvf binutils-2.24.tar.gz
cd binutils-2.24/libiberty/
./configure
make
# 移动库文件
sudo cp ./libiberty.a /usr/local/lib/
编译atosl
wget https://github.com/facebookarchive/atosl/archive/refs/tags/1.1.tar.gz
tar zxvf 1.1.tar.gz
cd atosl-1.1
make && make install
./atosl --help
atosl 1.1
Usage: atosl -o|--dsym <FILENAME> [OPTIONS]... <ADDRESS>...
-o, --dsym=FILE file to find symbols in
-v, --verbose enable verbose (debug) messages
-l, --load_address=ADDRESS specify application load address
-A, --arch=ARCH specify architecture
-g, --globals lookup symbols using global section
-V, --version get current version
-h, --help this help
完成