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