c - ARMv5 上的 libsodium 段错误

标签 c arm libsodium

我可以在 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 :

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 and libnosys.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/

相关文章:

c - 尝试删除文件时获取权限被拒绝错误

java - 在 Android 应用程序中运行 C 代码 (Android Studio)

c - 通过 MacPorts 安装 gcc45 后,如何使用它在我的 Mac 上构建 C 语言?

c - ARM: GNU GCC LInker bss 部分对齐

这可以原子执行吗?

linux - 在哪里可以找到在 linux 2.6.21.5-cfs-v19 上运行的 arm 目标的 gdb

c - GPS 解析器功能不适用于新接收器

reactjs - 在 webpack 中包含 polyfills > 5 in CRA

Amazon Linux 2023 上的 php-sodium

java - 如何在 Windows 下通过 Java 使用 NaCl