需求点:客户不接受docker部署,服务编译环境无法和客户环境对齐,需要找到办法兼容
方案:mock整套ld/so,不依赖客户环境的基础组件
1. 正常编译,编译后拷贝整套so
#!/bin/bash ABS_PATH=`pwd` echo "start copy system runtime libs, right path: ${ABS_PATH}" ldd_output=$(ldd ../exec) echo "$ldd_output" | while read -r line; do fields=($(echo "$line" | awk '{print $NF, $(NF-1)}')) if [ "${#fields[@]}" -eq 2 ] && [ -e "${fields[1]}" ] && [[ "${fields[1]}" != "/rtc_transcode"* ]] ; then echo "cp valid so: [${fields[1]}] to [output/lib]" cp ${fields[1]} ../output/lib fi done cp ../local_record_deps/patchelf ../output/bin/ chmod 777 ../output/lib/*
2. 发行版 patchelf 作为辅助产物打包,运行前更改ld为编译环境的ld
/output/bin/patchelf --set-interpreter /output/lib/ld-linux-x86-64.so.2 /output/bin/toutiao.videoarch.rtc_transcode
更改前 root@n37-009-198:/data00/build# readelf -aW a.out | grep -iE "interpreter" [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2] 更改后 [root@c211b21fb421 bin]# readelf -aW ./exec | grep -iE "interpreter" [Requesting program interpreter: /output/lib/ld-linux-x86-64.so.2]
3. 优化
仅首次运行需要调整
标签:bin,ld,interpreter,二进制,fields,发行版,linux,output From: https://www.cnblogs.com/zeolim/p/18422888