openssl 的编译(linux、Ubuntu) 和 交叉编译(arm、Hi3531A)的问题分析、解决

简介: openssl 的编译(linux、Ubuntu) 和 交叉编译(arm、Hi3531A)的问题分析、解决

一、编译环境及准备材料

1、编译环境:

1.1、Ubuntu环境 - ubuntu 14.04.1

$ uname -a
Linux ubuntu 4.4.0-128-generic #154~14.04.1-Ubuntu SMP Fri May 25 14:58:51 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

1.2、交叉编译

$ arm-hisiv100nptl-linux-gcc -v
Using built-in specs.
Target: arm-hisiv100-linux-uclibcgnueabi
Configured with: ../gcc-4.4-2010q1/configure --host=i486-linux-gnu --build=i486-linux-gnu --target=arm-hisiv100-linux-uclibcgnueabi 
--prefix=/home/sying/uclibc_h3/hisiv100_finalnptl_src/hisiv100_src/install/arm-hisiv100-linux 
...
...
Thread model: posix
gcc version 4.4.1 (Hisilicon_v100(gcc4.4-290+uclibc_0.9.32.1+eabi+linuxpthread)) 

2、openssl 源码

openssl 官网源码下载

openssl有提供旧版本源码下载,我这里下载的是 openssl-1.1.0l.tar.gz


二、Ubuntu下编译openssl

在Ubuntu下编译,没有遇到报错的地方,只需要配置好输出目录即可。

将源码压缩包/home/samba/openssl/ 目录后,解压并创建 ssl_result_ubuntu 用来存放编译结果,进入源码目录执行 config 文件生成Makefile,用 --prefix 来指定openssl的安装目录,然后直接编译,过程如下:

ubuntu:/home/samba/openssl$ tar zxf openssl-1.1.0l.tar.gz 
ubuntu:/home/samba/openssl$ mkdir ssl_result_ubuntu
ubuntu:/home/samba/openssl$ cd openssl-1.1.0l/
ubuntu:/home/samba/openssl/openssl-1.1.0l$ ./config --prefix=/home/samba/openssl/ssl_result_ubuntu
ubuntu:/home/samba/openssl/openssl-1.1.0l$ make
ubuntu:/home/samba/openssl/openssl-1.1.0l$ make install
ubuntu:/home/samba/openssl/openssl-1.1.0l$ ls ../ssl_result_ubuntu/
bin  include  lib  share  ssl

三、交叉编译 openssl

1、配置、编译

交叉编译过程中出现比较多问题,问题集中在执行 config 生成 Makefile 的过程中,下面列出问题及解决方案。

将源码压缩包/home/samba/openssl/ 目录后,解压并创建 ssl_result_3531A 用来存放编译结果,进入源码目录执行 config 文件生成Makefile,用 --prefix 来指定 openssl 的安装目录,然后再使用 --cross-compile-prefix 来指定交叉编译工具前缀,接着编译出现错误,过程如下:

ubuntu:/home/samba/openssl$ tar zxf openssl-1.1.0l.tar.gz 
ubuntu:/home/samba/openssl$ mkdir ssl_result_3531A
ubuntu:/home/samba/openssl$ cd openssl-1.1.0l/
ubuntu:/home/samba/openssl/openssl-1.1.0l$ ./config --prefix=/home/samba/openssl/ssl_result_3531A --cross-compile-prefix=arm-hisiv100nptl-linux-
ubuntu:/home/samba/openssl/openssl-1.1.0l$ make
...
PIC -DOPENSSL_USE_NODELETE -c -o crypto/aes/aes-x86_64.o crypto/aes/aes-x86_64.s
crypto/aes/aes-x86_64.s: Assembler messages:
crypto/aes/aes-x86_64.s:2: Error: unrecognized symbol type ""
crypto/aes/aes-x86_64.s:3: Error: alignment too large: 15 assumed
crypto/aes/aes-x86_64.s:5: Error: bad instruction `xorl 0(%r15),%eax'
crypto/aes/aes-x86_64.s:6: Error: bad instruction `xorl 4(%r15),%ebx'
crypto/aes/aes-x86_64.s:7: Error: bad instruction `xorl 8(%r15),%ecx'
...

2、分析问题,加 no-asm 配置选项

问题分析:从错误打印看到,错误出现在编译 .s 文件(汇编文件)时,且后面还打印了汇编代码。原来 openssl 在编译时会默认使用汇编代码来加速编译过程,但只针对 x86平台,而 x86平台 的汇编代码和 arm平台 的汇编代码是不同的,所以会报错。

解决方案:执行 config 时,加上 no-asm 表示不使用汇编代码加速编译。

继续编译:重新生成 Makefiel,重新编译,出现错误,过程如下:

ubuntu:/home/samba/openssl/openssl-1.1.0l$ ./config no-asm --prefix=/home/samba/openssl/ssl_result_3531A --cross-compile-prefix=arm-hisiv100nptl-linux-
ubuntu:/home/samba/openssl/openssl-1.1.0l$ make clean && make 
省略无关打印...
F crypto/aes/aes_cbc.d.tmp -MT crypto/aes/aes_cbc.o -c -o crypto/aes/aes_cbc.o crypto/aes/aes_cbc.c
cc1: error: unrecognized command line option "-m64"
make[1]: *** [crypto/aes/aes_cbc.o] Error 1
省略无关打印...

3、分析问题,删除 Makefile 的 -m64

问题分析:错误打印表示 "-m64" 无法识别。查资料得知,-m64是x86 64位应用编译选项,m64选项设置int为32 bits及long指针为64 bits,为AMD的x86 64架构生成代码。所以,在arm平台无法支持。

解决方案:删除 Makefile 的两处 -m64,可以使用下面命令删除,也可以打开Makefile,搜索删除。

sed -i 's/-m64//' Makefile

继续编译:修改 Makefile 后,重新编译,出现错误如下:

./libcrypto.so: undefined reference to `getcontext'
./libcrypto.so: undefined reference to `setcontext'
./libcrypto.so: undefined reference to `makecontext'

4、分析问题,加 no-async 配置选项,编译通过

问题分析:查资料得知,这个错误是编译时缺少 ucontext 库(ucontext提供的四个函数getcontext、setcontext、makecontext、swapcontext、可以在一个进程中实现用户级的线程切换)。海思3531A平台的交叉编译工具没有提供GNU C的 ucontext 库,所以出错。

解决方案:执行 config 时,加上 no-async,不使用 ucontext 库

继续编译:加上 no-async,重新生成Makefile,编译通过,过程如下:

ubuntu:/home/samba/openssl/openssl-1.1.0l$ ./config no-asm no-async --prefix=/home/samba/openssl/ssl_result_3531A --cross-compile-prefix=arm-hisiv100nptl-linux-
ubuntu:/home/samba/openssl/openssl-1.1.0l$ sed -i 's/-m64//' Makefile
ubuntu:/home/samba/openssl/openssl-1.1.0l$ make clean && make && make install
ubuntu:/home/samba/openssl/openssl-1.1.0l$ ls ../ssl_result_3531A/
bin  include  lib  share  ssl

到此,编译完成,在指定的安装目录下,生成了对应的头文件和库文件。

另外,关于 openssl 的配置选项 no-asm、no-async,在上文已经讲清楚了,而对其他配置选项感兴趣的可以查看 openssl编译参数选项

如果文章能解决你的问题,留个赞让我知道一下 ^_^

目录
相关文章
|
15天前
|
Linux C语言 C++
Linux 下centos 查看 -std这个编译时命令 是否支持 C17
Linux 下centos 查看 -std这个编译时命令 是否支持 C17
18 2
|
2月前
|
Ubuntu Linux Go
ubuntu linux (20.04) 源码编译cryptopp库 - apt版本过旧
ubuntu linux (20.04) 源码编译cryptopp库 - apt版本过旧
30 1
|
25天前
|
Linux 编译器 C语言
编译Linux内核:基础、重要性和交叉编译方法
Linux内核作为操作系统的心脏,负责管理计算机的硬件资源,同时也是运行所有其他程序的基础。理解如何编译Linux内核对于系统管理员、开发者乃至高级用户来说都是一项极其宝贵的技能。本文将介绍编译Linux内核的基本知识、编译的重要性、具体步骤以及交叉编译的概念。
55 0
|
26天前
|
Ubuntu 编译器 C语言
蓝易云 - ubuntu上安装boost库为SOMEIP的X86和ARM下编译做准备(编译两种版本)
以上就是在Ubuntu上安装Boost库并为SOME/IP的X86和ARM架构编译做准备的全部步骤。
33 0
|
1月前
|
Linux 编译器 C++
Linux centOS 编译C/C++
Linux centOS 编译C/C++
|
1月前
|
Ubuntu Windows
ubuntu 安装vnc_vnc4server arm架构
ubuntu 安装vnc_vnc4server arm架构
18 0
|
2月前
|
NoSQL Ubuntu Linux
【操作系统】实验三 编译 Linux 内核
【操作系统】实验三 编译 Linux 内核
74 1
|
2月前
|
存储 Ubuntu Linux
xenomai3+linux构建linux实时操作系统-基于X86_64和arm
Xenomai是一个实时性解决方案,通过在Linux上添加实时内核Cobalt来增强实时性能。它有三个主要部分:libcobalt(用户空间实时库)、Cobalt(内核空间实时内核)和硬件架构特定层(ipipe-core或dovetail)。ipipe-core适用于Linux 5.4以下版本,而dovetail用于5.4及以上版本。本文介绍了在X86 Ubuntu环境下,如何编译Xenomai内核,搭建应用环境,包括配置、编译、安装和实时性测试。对于其他硬件架构,如ARM和ARM64,步骤类似。文章还提到了Xenomai与Linux内核版本的兼容性和实时性测试结果。
71 0
xenomai3+linux构建linux实时操作系统-基于X86_64和arm
|
2月前
|
存储 Ubuntu 网络协议
从Ubuntu-base构建ubuntu rootfs系统(以x86_64和arm为例)
本文介绍了基于Ubuntu-base构建自定义Linux系统的过程,适合嵌入式设备。Ubuntu-base是最小文件系统,包含软件包管理器,可以从Ubuntu源轻松安装软件。文章详细阐述了构建步骤,包括准备宿主系统(确保使用与目标系统相同架构的Ubuntu系统)、创建和挂载分区、配置Ubuntu源、设置DNS、添加用户配置、进入chroot环境以及安装软件(如内核、X-window系统等)。对于arm架构,还提供了通过qemu在X86_64系统上构建arm rootfs的方法。整个过程强调了定制和灵活性,适合对Linux系统有深入了解的开发者。
258 0
|
3天前
|
Ubuntu Linux
在Linux (Ubuntu 16) 下安装LabVIEW
在Linux (Ubuntu 16) 下安装LabVIEW
16 0