前言全局说明
一、说明
环境:
ubuntu 18.04
二、下载源码:
官网:
https://openssl-library.org
源码下载:
https://openssl-library.org/source/old/1.0.0/index.html
下载,指定版本:
https://github.com/openssl/openssl/releases/download/OpenSSL_1_0_0s/openssl-1.0.0s.tar.gz
三、依赖环境
3.1 ubunut
sudo apt-get -y install
四、编译
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 编译
./Configure linux-armv4 no-asm shared no-async
执行成功部分截图
make -j4
或
make -j$(nproc)
-j4 用4个线程编译
$(nproc)获取CPU线程数
4.3 编译结果
ll .libs/
执行成功部分截图
五、错误记录
5.1 工具链名报错
making all in crypto...
making all in ssl...
making all in engines...
making all in apps...
make[1]: 警告: jobserver 不可用: 正使用 -j1。添加 “+” 到父 make 的规则。
make[1]: 警告: jobserver 不可用: 正使用 -j1。添加 “+” 到父 make 的规则。
make[1]: 警告: jobserver 不可用: 正使用 -j1。添加 “+” 到父 make 的规则。
make[1]: 进入目录“/home/qt/build_source_all/libs_so/openssl_1.0/openssl-1.0.0s/engines”
arm-openwrt-linux-arm-openwrt-linux-gcc -I../include -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DTERMIO -DTERMIO -O3 -Wall -DOPENSSL_BN_ASM_MONT -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DAES_ASM -c -o e_4758cca.o e_4758cca.c
make[1]: arm-openwrt-linux-arm-openwrt-linux-gcc: Command not found
<内置>: recipe for target 'e_4758cca.o' failed
make[1]: *** [e_4758cca.o] Error 127
解决方法1:
打开源码下 Makefile 把 CC=后面的 $(CROSS_COMPILE) 删掉
解决方法2:
生效环境
export target_host=arm-openwrt-linux
export CROSS_COMPILE=${target_host}-
加入参数
--cross-compile-prefix=${target_host}-
注意:是${target_host}值,不是 ${CROSS_COMPILE}-
5.2 找不到 termio.h
make[2]: 进入目录“/home/qt/build_source_all/libs_so/openssl_1.0/openssl-1.0.0s/crypto/ui”
arm-openwrt-linux-gcc -I.. -I../.. -I../asn1 -I../evp -I../../include -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -O3 -Wall -c -o ui_err.o ui_err.c
arm-openwrt-linux-gcc -I.. -I../.. -I../asn1 -I../evp -I../../include -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -O3 -Wall -c -o ui_lib.o ui_lib.c
arm-openwrt-linux-gcc -I.. -I../.. -I../asn1 -I../evp -I../../include -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -O3 -Wall -c -o ui_openssl.o ui_openssl.c
ui_openssl.c:230:11: fatal error: termio.h: No such file or directory# include <termio.h>^~~~~~~~~~
compilation terminated.
<内置>: recipe for target 'ui_openssl.o' failed
make[2]: *** [ui_openssl.o] Error 1
解决方法1:
打开源码下 Makefile 把 -DTERMIO 参数删除.
解决方法2:
从别的工具链下载 termio.h 放到工具链 include 目录
解决方法3:
搜索工具链,找到 termios.h 软连接到 termio.h
ln -s termios.h termio.h
5.3 没有找到工具链
/usr/bin/perl ../util/mkbuildinf.pl "arm-openwrt-linux-gcc -I. -I.. -I../include -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DTERMIO -O3 -Wall" "linux-armv4" >buildinf.h
arm-openwrt-linux-gcc -I. -I.. -I../include -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DTERMIO -O3 -Wall -c -o cryptlib.o cryptlib.c
make[1]: arm-openwrt-linux-gcc: Command not found
<内置>: recipe for target 'cryptlib.o' failed
make[1]: *** [cryptlib.o] Error 127
解决方法:
export PATH=$PATH:工具链的bin路径
将工具链绝对路径加入PATH,或直接在 --cross-compile-prefix 时直接绝对路径
5.4 编译tty_orig错误
PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DTERMIO -O3 -Wall -c -o ui_openssl.o ui_openssl.c
arm-openwrt-linux-gcc: warning: environment variable 'STAGING_DIR' not defined
ui_openssl.c: In function 'noecho_console':
ui_openssl.c:531:43: error: invalid application of 'sizeof' to incomplete type 'struct termio'memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig));^
ui_openssl.c:532:12: error: invalid use of undefined type 'struct termio'tty_new.TTY_FLAGS &= ~ECHO;^
ui_openssl.c: In function 'echo_console':
ui_openssl.c:555:43: error: invalid application of 'sizeof' to incomplete type 'struct termio'memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig));^
ui_openssl.c:556:12: error: invalid use of undefined type 'struct termio'tty_new.TTY_FLAGS |= ECHO;^
ui_openssl.c: At top level:
ui_openssl.c:299:19: error: storage size of 'tty_orig' isn't knownstatic TTY_STRUCT tty_orig, tty_new;^~~~~~~~
ui_openssl.c:299:29: error: storage size of 'tty_new' isn't knownstatic TTY_STRUCT tty_orig, tty_new;^~~~~~~
<内置>: recipe for target 'ui_openssl.o' failed
make[2]: *** [ui_openssl.o] Error 1
解决方法:
创建 STAGING_DIR 变量
export STAGING_DIR=""
5.5
解决方法:
免责声明:本号所涉及内容仅供安全研究与教学使用,如出现其他风险,后果自负。
参考、来源:
https://blog.csdn.net/ty3219/article/details/77717478
https://blog.csdn.net/duapple/article/details/107095657 (sed 替换错误)
https://blog.csdn.net/2301_77171572/article/details/144667457 (4.2)
https://blog.csdn.net/2004v2004/article/details/145864280
https://blog.csdn.net/zhiyuan2021/article/details/126757516