编译android版本binutils工具
准备
编译环境:ubuntu 20.04.2
编译器版本:ndk-24.0.8215888
binutils版本: 2.33.1
1. 生成android standline toolchain工具包shell_tool.sh
# Create an arm64 API 26 libc++ toolchain.
$ANDROID_NDK/build/tools/make_standalone_toolchain.py \
--arch arm64 \
--api 26 \
--install-dir=`pwd`/aarch64-linux-android-toolchain
执行
sh shell_tool.sh
2. 配置编译工具的环境变量shell_env.sh 内容如下:
# Add the standalone toolchain to the search path.
export PATH=$PATH:`pwd`/aarch64-linux-android-toolchain/bin
# Tell configure what tools to use.
target_host=aarch64-linux-android
export AR=$target_host-ar
export AS=$target_host-clang
export CC=$target_host-clang
export CXX=$target_host-clang++
export LD=$target_host-ld
export STRIP=$target_host-strip
# Tell configure what flags Android requires.
export CFLAGS="-fPIE -fPIC -Wno-error -Wno-null-pointer-arithmetic"
export LDFLAGS="-pie"
执行
source shell_env.sh
3. 下载binutils源码
wget https://mirror.csclub.uwaterloo.ca/gnu/binutils/binutils-2.33.1.tar.xz
tar -xvf binutils-2.33.1.tar.xz
4. 编译binutils
./configure --host=aarch64-linux-android --prefix=`pwd`/install
make -j10 && make
5. 拷贝到android执行ld试用
adb push `pwd`/install /data/local/tmp/
adb shell
cd /data/local/tmp
./ld clang++