我可以在 Ubuntu 中很好地使用 libsodium 1.0.7,但是在尝试将 libsodium 库交叉编译为 armv5 架构时似乎存在一些问题 (armv5tejl-unknown-linux-gnueabihf
) .
我使用了 ./configure --host=armv5tejl-unknown-linux-gnueabihf
然后 make DESTDIR=/home/myself/ARM/
。
所有文件都生成良好( header 和静态和共享库文件),我可以编译和链接一个小的测试 C 程序,然后在我的 ARMv5 目标上执行时生成一个段错误(工具链和一切都很好,一切否则我编译和链接不使用 libsodium 在我的 ARM 机器上运行得很好):
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sodium.h"
int main()
{
printf("sodium_init()=%d\n",sodium_init()); // Fine, = 0
unsigned char pbk[crypto_box_PUBLICKEYBYTES];
unsigned char sbk[crypto_box_SECRETKEYBYTES];
crypto_box_keypair(pbk,sbk); // <-- Segmentation fault.
}
我还在 https://download.libsodium.org/doc/installation/index.html 尝试了 ARM 指令的官方交叉编译。但由于缺少 nosys.specs
文件,配置失败。有没有什么地方可以下载这个(我已经用 goggle 了,它似乎必须专门为 libsodium 包生成)?
最佳答案
我在这里借助一些帮助设法解决了它:github.com/jedisct1/libsodium/issues/331 –提亚斯
Right, I finally managed to make it run on my ARMv5 target by doing the following, many thanks for pointing me to the ARM toolchain that contained the nosys.spec & libnosys.a files :
- Downloaded ARM toolchain
gcc-arm-none-eabi-4_9-2015q3-20150921-linux.tar.bz2
from https://launchpad.net/gcc-arm-embedded- Downloaded
libsodium-1.0.7
from https://download.libsodium.org/libsodium/releases/Note: This is for making a static
libsodium.a
Example below assuming home folder =
/home/user
tar xvjf gcc-arm-none-eabi-4_9-2015q3-20150921-linux.tar.bz2 tar xvzf libsodium-1.0.7.tar.gz cp ./gcc-arm-none-eabi-4_9-2015q3/arm-none-eabi/lib/nosys.spec ./libsodium-1.0.7/ cp ./gcc-arm-none-eabi-4_9-2015q3/arm-none-eabi/lib/libnosys.a ./libsodium-1.0.7/
Folder gcc-arm-none-eabi-4_9-can be deleted at this point.
cd ./libsodium-1.0.7/ mkdir ARMv5 export LDFLAGS='-static -g --specs=nosys.specs -L/home/user/libsodium-1.0.7/ -lnosys -lc' ./configure --host=armv5tejl-unknown-linux-gnueabihf --enable-static --prefix=/home/user/libsodium-1.0.7/ARMv5/ make DESTDIR=/home/user/libsodium-1.0.7/ARMv5/
Key discoveries for me :
- Hint from jedisct1 where to get the ARM toolchain containing both the
nosys.spec
andlibnosys.a
files.- Found out to add linker flag
-lc
to make libsodium with libc (contaning__libc_start_main
,abort
,__libc_csu_fini
and__libc_csu_init
)
关于c - ARMv5 上的 libsodium 段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34229830/