前言全局说明
编译 libc.so
一、说明
环境:
CentOS Linux 7 (Core)
Kernel 3.10.0-1127.el7.x86_64 on an x86_64
二、下载源码:
官网:
http://ftp.gnu.org
源码下载:
http://ftp.gnu.org/gnu/libc/
历史版本:
http://ftp.gnu.org/gnu/libc/
下载,指定版本:
http://ftp.gnu.org/gnu/libc/glibc-2.27.tar.gz
https://mirrors.aliyun.com/gnu/glibc/glibc-2.27.tar.gz?spm=a2c6h.25603864.0.0.74814df6Penqkg&file=glibc-2.27.tar.gz
https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz
三、依赖环境
3.1 CentOS
yum groupinstall "Development Tools"
yum install -y gcc zlib zlib-devel libffi libffi-devel
yum install -y readline-devel
yum install -y openssl-devel openssl11 openssl11-devel
yum install -y zlib-devel
四、编译
4.1 生效编译环境
export toolchain_BIN=你的编译工具链路径/bin## Set toolchain 
export PATH=$toolchain_BIN:$PATH
export target_host=aarch64-linux-gnu (修改成你的编译工具名,bin目录里的)
export CROSS_COMPILE=${target_host}# export ARCH=arm
export ARCH=arm64export AR=${CROSS_COMPILE}-ar
export AS=${CROSS_COMPILE}-as
export CC=${CROSS_COMPILE}-gcc
export CXX=${CROSS_COMPILE}-g++
export LD=${CROSS_COMPILE}-ld
export NM=${CROSS_COMPILE}-nm
export OBJDUMP=${CROSS_COMPILE}-objdump
export STRIP=${CROSS_COMPILE}-strip
4.2 生成 Makefile
# 创建临时文件
$ mkdir build && cd build
$ ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
执行成功部分截图
4.3 开始编译
4.3.1 全速编译,使用CPU全部核心
make -j $(nproc)
4.3.2 -j4 用4个线程编译
make -j4
4.3.2 单线程编译,慢
make
4.4 安装so
make install
不需要执行 make install ,因为so是放到嵌入设备的,不是放到当前编译环境的。
4.5 编译结果
ll .libs/
执行成功部分截图
4.6 查看文件架构
file libssl.so.1.1
file libcrypto.so.1.1
五、错误收集:
5.1.1 错误
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: cannot find -lm
5.1.2 解决方法:
yum install -y glibc-static
5.2.1 错误
checking for python3... no
5.2.2 解决方法:
#只是将python3.11的安装包下载到 /root目录下
cd /root#下载最新的软件安装包
wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tgz#解压缩安装包
tar -xzf Python-3.11.0.tgz#安装源码编译需要的编译环境
yum install -y gcc zlib zlib-devel libffi libffi-devel#可以解决后期出现的方向键、删除键乱码问题,这里提前避免。
yum install -y readline-devel#安装openssl11,后期的pip3安装网络相关模块需要用到ssl模块。
yum install -y openssl-devel openssl11 openssl11-devel#设置编译FLAG,以便使用最新的openssl库
export CFLAGS=$(pkg-config --cflags openssl11)
export LDFLAGS=$(pkg-config --libs openssl11)#进入刚解压缩的目录
cd /root/Python-3.11.0#指定python3的安装目录为 /usr/python 并使用ssl模块,指定目录好处是
#后期删除此文件夹就可以完全删除软件了。
./configure --prefix=/usr/python311 --with-ssl# 编译
make#就是源码编译并安装了,时间会持续几分钟。
make install#指定链接,此后我们系统的任何地方输入python3就是我们安装的
#这个最新版python3了
ln -s /usr/python311/bin/python3 /usr/bin/python3
ln -s /usr/python311/bin/pip3 /usr/bin/pip3
5.3.1 错误
config.log
/usr/bin/ld: cannot find -lssl
/usr/bin/ld: cannot find -lcrypto
5.3.2 解决方法:
yum install openssl-devel
5.4.1 错误
/tmp/ccyxxUtW.s:11: Error: unknown .loc sub-directive `view'
/tmp/ccyxxUtW.s:11: Error: junk at end of line, first unrecognized character is `-'
/tmp/ccyxxUtW.s:13: Error: unknown .loc sub-directive `view'
/tmp/ccyxxUtW.s:13: Error: unknown pseudo-op: `.lvu1'
/tmp/ccyxxUtW.s:14: Error: unknown .loc sub-directive `view'
/tmp/ccyxxUtW.s:14: Error: unknown pseudo-op: `.lvu2'
/tmp/ccyxxUtW.s:15: Error: unknown .loc sub-directive `view'
/tmp/ccyxxUtW.s:15: Error: unknown pseudo-op: `.lvu3'
5.4.2 解决方法:
当你在编译代码时遇到 error: unknown .loc sub-directive 'view' 错误,这通常是由于 GCC 版本过高或不兼容所导致的。
5.5.1 错误
conftest.cpp:37:2: error: #error __cxa_thread_atexit_impl not supported#error __cxa_thread_atexit_impl not supported
5.5.2 解决方法:
尝试降低gcc版本
5.6.1 错误
configure:6445: gcc -B/usr/bin/ -o conftest -g -O2   conftest.c -lcap   >&5
/usr/bin/ld: cannot find -lcap
collect2: error: ld returned 1 exit status
5.6.2 解决方法:
yum install libcap-devel
5.7.1 错误
configure:6395: gcc -B/usr/bin/ -o conftest -g -O2   conftest.c -laudit   >&5
/usr/bin/ld: cannot find -laudit
collect2: error: ld returned 1 exit status
5.7.2 解决方法:
yum install libaudit-devel
5.8.1 错误
5.8.2 解决方法:
免责声明:本号所涉及内容仅供安全研究与教学使用,如出现其他风险,后果自负。
参考、来源:
https://blog.csdn.net/nilm61/article/details/134266633
https://blog.csdn.net/m0_52640673/article/details/126682567 (5.1.2)
https://zhuanlan.zhihu.com/p/590965831 (5.2.2)
https://blog.csdn.net/weixin_34320159/article/details/92935438 (5.3.2)
https://cn.bing.com/search?q=Error%3A+unknown+.loc+sub-directive+`view'&form=ANNTH1&refig=6904879508d346b2945e72cac191b69a&pc=U531 (5.4.2)
https://blog.csdn.net/nilm61/article/details/134266633 (查询系统中glib成的版本)