1

I can use libsodium 1.0.7 just fine in Ubuntu but there seems to be some issue when trying to cross-compile the libsodium library to an armv5 architecture (armv5tejl-unknown-linux-gnueabihf). I have used ./configure --host=armv5tejl-unknown-linux-gnueabihf and then make DESTDIR=/home/myself/ARM/.

All files are generated fine (headers and static & shared library files) and I can compile and link a small test C-program which then generates a segmentation fault when it's executed on my ARMv5 target (toolchain and all is fine, everything else I compile & link not using libsodium runs perfectly fine on my ARM machine):

#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.
}

I have also tried the official cross-compile for ARM instructions at https://download.libsodium.org/doc/installation/index.html but configure fails due to a missing nosys.specs file. Is there somewhere I can download this (I have goggled it and it seems that it has to be specifically generated for the libsodium package)?

Trevor
  • 1,111
  • 2
  • 18
  • 30
Tias
  • 19
  • 2
  • 1
    Just to be sure, you should show the `#include`s as well so to make your example self-contained. Maybe the problem is there? – 5gon12eder Dec 11 '15 at 18:25
  • Hi ! You're completely right, here are the includes : #include #include #include #include "sodium.h" The same simple source compiles and executes in the host machine (Ubuntu 15) with sodium built for Ubuntu) but not in the target ARMv5 system (with the sodium library files built for the ARMv5 system) – Tias Dec 11 '15 at 20:30
  • Please edit your question instead of posting the code as comments. – 5gon12eder Dec 11 '15 at 20:34
  • Sorry 'bout that. Though I was just making a normal reply. – Tias Dec 11 '15 at 22:29
  • How did you come about "armv5tejl-unknown-linux-gnueabihf" being the correct option for your target? – unixsmurf Dec 12 '15 at 21:20
  • 1
    Hi !Please close this topic, I managed to solve it with some help here : https://github.com/jedisct1/libsodium/issues/331 – Tias Dec 13 '15 at 00:03
  • Well that was never the problem :) It's the toolchain that was delivered with the target system that I am developing my SW for. Cheers ! – Tias Dec 13 '15 at 01:11

1 Answers1

0

I managed to solve it with some help here : github.com/jedisct1/libsodium/issues/331 – Tias

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)
Armali
  • 18,255
  • 14
  • 57
  • 171