CANN 6.0.1版本内置的HCC编译器中不包含glibc组件的相关功能,如果需要使用该功能,需要手动对glibc源码(2.28版本)进行安装。
glibc是GNU C库的一个版本,针对ARM平台进行了错误修复和增强。
本示例将安装glibc-2.28版本,会解压源码包到build_tools目录(需要手动新建)中,也可根据实际情况选择解压目录。示例构建目录结构如下(仅供参考),6.0.1为CANN软件版本号,请根据实际情况修改。
编译器所在路径(以root用户默认路径为例):/usr/local/Ascend/ascend-toolkit/6.0.1/toolkit/toolchain/hcc
hcc目录结构:
hcc //HCC编译器目录 ├── aarch64-target-linux-gnu ├── bin ├── include ├── lib ├── lib64 ├── libexec ├── sysroot //安装目标路径 └── build_tools //glibc下载代码存放地址,需要手动新建,可根据实际情况修改
以下步骤以root用户默认安装路径为例,请根据实际情况进行修改。
cd /usr/local/Ascend/ascend-toolkit/6.0.1/toolkit/toolchain/hcc mkdir -p ./sysroot/lib64/ mkdir -p ./sysroot/usr/lib64/
mkdir -p ./build_tools cd build_tools tar -xf glibc-2.28.tar.gz cd .. cp -f ./build_tools/glibc-2.28/include/gnu/stubs.h ./sysroot/usr/include/gnu
echo $(gcc -dumpmachine)
BUILD_EVN=$(gcc -dumpmachine) HOST_EVN=aarch64-target-linux-gnu
#创建临时安装文件夹 mkdir -p ./build/glibc-header pushd ./build/glibc-header #设置hcc编译器路径,同时配置configure文件 CC="/usr/local/Ascend/ascend-toolkit/6.0.1/toolkit/toolchain/hcc/bin/aarch64-target-linux-gnu-gcc -O2 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -s -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines -fPIC -mlittle-endian -march=armv8-a -DDONT_USE_DC" CXX="/usr/local/Ascend/ascend-toolkit/6.0.1/toolkit/toolchain/hcc/bin/aarch64-target-linux-gnu-g++ -O2 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -s -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines -fPIC -mlittle-endian -march=armv8-a -DDONT_USE_DC" ../../build_tools/glibc-2.28/configure --prefix=/usr --with-headers=/usr/local/Ascend/ascend-toolkit/6.0.1/toolkit/toolchain/hcc/sysroot/usr/include --build=$BUILD_EVN --host=$HOST_EVN --disable-profile --without-gd --without-cvs --disable-multi-arch --enable-add-ons libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes --enable-stack-protector=strong libc_cv_ssp=yes --enable-static-pie #执行make安装 make install-bootstrap-headers=yes install-headers install_root=/usr/local/Ascend/ascend-toolkit/6.0.1/toolkit/toolchain/hcc/sysroot make -j 120 csu/subdir_lib cp csu/crt1.o csu/crti.o csu/crtn.o ../../sysroot/usr/lib64/ ../../bin/aarch64-target-linux-gnu-gcc -O2 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -s -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines -fPIC -mlittle-endian -march=armv8-a -DDONT_USE_DC -o ../../sysroot/usr/lib64/libc.so -nostdlib -nostartfiles -shared -x c /dev/null popd
#创建临时安装文件夹 mkdir -p ./build/build-glibc pushd ./build/build-glibc #设置hcc编译器路径,同时配置configure文件 CC="/usr/local/Ascend/ascend-toolkit/6.0.1/toolkit/toolchain/hcc/bin/aarch64-target-linux-gnu-gcc -O2 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -s -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines -fPIC -mlittle-endian -march=armv8-a -DDONT_USE_DC" CXX="/usr/local/Ascend/ascend-toolkit/6.0.1/toolkit/toolchain/hcc/bin/aarch64-target-linux-gnu-g++ -O2 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -s -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines -fPIC -mlittle-endian -march=armv8-a -DDONT_USE_DC' LDFLAGS='-z relro -z now -z noexecstack -pie -s" ../../build_tools/glibc-2.28/configure --prefix=/usr --with-headers=/usr/local/Ascend/ascend-toolkit/6.0.1/toolkit/toolchain/hcc/sysroot/usr/include --build=$BUILD_EVN --host=$HOST_EVN --disable-profile --without-gd --enable-obsolete-rpc --without-cvs --with-__thread --with-tls --disable-multi-arch --enable-shared --with-fp --enable-add-ons libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes --libdir=/usr/lib64 --enable-stack-protector=strong libc_cv_ssp=yes --enable-static-pie #执行make安装 make -j 192 make install_root=/usr/local/Ascend/ascend-toolkit/6.0.1/toolkit/toolchain/hcc/sysroot slibdir=/lib64 rtlddir=/lib64 install popd
cp -r ./lib64/gcc/ ./sysroot/usr/lib64/ cp -r ./aarch64-target-linux-gnu/lib64/lib* ./sysroot/usr/lib64/ chmod 755 . -R chmod 644 ./sysroot/usr/lib64/libstdc++.so.6.0.24 -R chmod 644 ./sysroot/usr/lib64/libgcc_s.so.1 -R