openssl交叉编译


下载

到https://www.openssl.org/source/下载最新openssl源代码。

或使用git直接下拉代码,并切换到最新release版.

此处我下载的是1.1.1系列的版本,这个版本支持到2023年9月11号

git clone https://gitee.com/mirrors/openssl.git

#找到最新版的release tag
git checkout -b openssl-1.1.1m OpenSSL_1_1_1m

解压

tar -zxvf openssl-1.1.1m.tar.gz

适配T40

创建make.sh在根目录

#!/bin/sh

CONFIG_OUTPUT=$(pwd)/install 
CROSS_TOOL_PREFIX=~/work/t40/mips-gcc720-glibc226/bin/mips-linux-uclibc-gnu-
CFLAGS1=-muclibc 
CFLAGS2=-march=mips32r2

./config no-asm no-async shared $CFLAGS1 $CFLAGS2 --prefix=$CONFIG_OUTPUT --cross-compile-prefix=$CROSS_TOOL_PREFIX
make clean
make 
make install
make distclean

config脚本参数说明:

  1. no-asm: 在交叉编译过程中不使用汇编代码代码加速编译过程.
  2. shared: 生成动态连接库。
  3. no-async: 交叉编译工具链没有提供GNU C的ucontext库时,就需要加上
  4. –prefix=: 安装路径,编译完成install后将有bin,lib,include等文件夹
  5. –cross-compile-prefix=: 交叉编译工具

同时也可以在INSTALL.md文档中可以看到相关解释

  no-asm
                   Do not use assembler code. This should be viewed as
                   debugging/trouble-shooting option rather than production.
                   On some platforms a small amount of assembler code may
                   still be used even with this option.

  no-async
                   Do not build support for async operations.
                   
  no-shared
                   Do not create shared libraries, only static ones.  See "Note
                   on shared libraries" below.
                   

常见问题

问题1

在T40平台,使用curl库封装的http client时,出现错误。

错误现象

* Trying 47.115.62.228:443...
* Connected to test.apicn.xmitech.net (47.115.62.228) port 443 (#0)
* ALPN, offering http/1.1
* error:0306E06C:bignum routines:BN_mod_inverse:no inverse
* Closing connection 0
curl_easy_perform() failed: SSL connect error

错误原因

经过一番查找,定位于通过config文件生成的Makefile中的PLATFORM值有问题了。由于编译选项中没有指定芯片架构,配置脚本在猜测时将芯片架构猜测为linux-x86_64。

#有问题的makefile
PLATFORM=linux-x86_64

解决方法

  1. openssl源代码的config文件拉到T40环境下运行
[root@Zeratul:sd]# ./config -h
Usage: config [options]
 -d     Build with debugging when possible.
 -t     Test mode, do not run the Configure perl script.
 -v     Verbose mode, show the exact Configure call that is being made.
 -h     This help.

Any other text will be passed to the Configure perl script.
See INSTALL for instructions.

Operating system: mips-whatever-linux2
You need Perl 5.
  1. 然后将得到的Operating system:值放在config中修改
# read the output of the embedded GuessOS
read GUESSOS
GUESSOS="mips-whatever-linux2"
echo Operating system: $GUESSOS
  1. 修完毕后,执行make.sh脚本即可。

问题2

错误现象

./libcrypto.so: warning: gethostbyname is obsolescent, use getnameinfo() instead.
./libcrypto.so: undefined reference to `getcontext'
./libcrypto.so: undefined reference to `setcontext'
./libcrypto.so: undefined reference to `makecontext'

错误原因

交叉编译工具链没有提供GNU C的ucontext库。

解决方法

在运行config脚本时添加 no-async选项。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM