C Cross Compiling Openssl for ARM64(Nanopi R2S)

Hi everyone, I'm having problem when cross compiling openssl from AMD64 to ARM64.

I've tried: pkg install aarch64-none-elf-gcc

./Configure BSD-generic32 --cross-compile-prefix=/usr/local/bin/aarch64-none-elf- shared --prefix=/usr/openssl-custom --openssldir=/usr/openssl-custom -Wl,-rpath=/usr/openssl-custom/lib

make install

the error stated that /usr/local/bin/aarch64-none-elf-cc: not found, and there is no aarch64-none-elf-cc in that directory.

However, the CC file can be found on aarch64 sysroot by running command as below:
pkg install aarch64-freebsd-sysroot


I've also tried this:
./Configure BSD-generic32 --sysroot=/usr/local/freebsd-sysroot/aarch64 -prefix=/usr/local/openssl-custom --openssldir=/opt/openssl-custom -Wl,-rpath=/user/local/openssl-custom/lib

make

And got error like as below:

Code:
ld: error: crypto/aes/aes_cbc.o is incompatible with /usr/local/freebsd-sysroot/aarch64/usr/lib/crti.o
ld: error: crypto/aes/aes_cfb.o is incompatible with /usr/local/freebsd-sysroot/aarch64/usr/lib/crti.o
ld: error: crypto/aes/aes_core.o is incompatible with /usr/local/freebsd-sysroot/aarch64/usr/lib/crti.o
ld: error: crypto/aes/aes_ecb.o is incompatible with /usr/local/freebsd-sysroot/aarch64/usr/lib/crti.o
ld: error: crypto/aes/aes_ige.o is incompatible with /usr/local/freebsd-sysroot/aarch64/usr/lib/crti.o
ld: error: crypto/aes/aes_misc.o is incompatible with /usr/local/freebsd-sysroot/aarch64/usr/lib/crti.o
ld: error: crypto/aes/aes_ofb.o is incompatible with /usr/local/freebsd-sysroot/aarch64/usr/lib/crti.o
ld: error: crypto/aes/aes_wrap.o is incompatible with /usr/local/freebsd-sysroot/aarch64/usr/lib/crti.o
ld: error: crypto/aria/aria.o is incompatible with /usr/local/freebsd-sysroot/aarch64/usr/lib/crti.o
ld: error: crypto/asn1/a_bitstr.o is incompatible with /usr/local/freebsd-sysroot/aarch64/usr/lib/crti.o
ld: error: crypto/asn1/a_d2i_fp.o is incompatible with /usr/local/freebsd-sysroot/aarch64/usr/lib/crti.o
ld: error: crypto/asn1/a_digest.o is incompatible with /usr/local/freebsd-sysroot/aarch64/usr/lib/crti.o
ld: error: crypto/asn1/a_dup.o is incompatible with /usr/local/freebsd-sysroot/aarch64/usr/lib/crti.o
ld: error: crypto/asn1/a_gentm.o is incompatible with /usr/local/freebsd-sysroot/aarch64/usr/lib/crti.o
ld: error: crypto/asn1/a_i2d_fp.o is incompatible with /usr/local/freebsd-sysroot/aarch64/usr/lib/crti.o
ld: error: crypto/asn1/a_int.o is incompatible with /usr/local/freebsd-sysroot/aarch64/usr/lib/crti.o
ld: error: crypto/asn1/a_mbstr.o is incompatible with /usr/local/freebsd-sysroot/aarch64/usr/lib/crti.o
ld: error: crypto/asn1/a_object.o is incompatible with /usr/local/freebsd-sysroot/aarch64/usr/lib/crti.o
ld: error: crypto/asn1/a_octet.o is incompatible with /usr/local/freebsd-sysroot/aarch64/usr/lib/crti.o
ld: error: crypto/asn1/a_print.o is incompatible with /usr/local/freebsd-sysroot/aarch64/usr/lib/crti.o
ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1

Please share with me your thought on where I might messed up or what the correct syntax for this, really appreciate your help and comment.
 
you compiled without -target (your compiled objects are probably for amd64)
Hi thanks for your reply, can you be more specific on where should I specify "-target"?
I have read multiple articles on how to cross compile arm, but it seems complicated for me to understand.

I noticed that when I run ./config on my ARM device as shown below(R2S_config.png) it stated that "Operating system: arm64-whatever-freebsd".
But, when I run the command as my first post, as shown below(AMD64.png) it didnt stated the operating system.
Can this be the culprit ?

Really appreciate your kind thought on this, thank you. Br.
 

Attachments

  • AMD64.PNG
    AMD64.PNG
    25.5 KB · Views: 164
  • R2S_config.PNG
    R2S_config.PNG
    5.3 KB · Views: 160
go to /usr/ports/security/openssl (on the amd box)
try
make CC="cc -target aarch64-freebsd-unknwon --sysroot=/usr/local/freebsd-sysroot/aarch64"
 
Thanks for your reply :)

At first when I run the command, I noticed that the operating system is set to am64-whatever-freebsd which I believed is my AMD box. It also stated that configuring openssl for BSD-86_64, shouldnt it be my target box ?

And after some time, the make stop and error as below:

Code:
===>  Configuring for openssl-1.1.1m_2,1
Operating system: amd64-whatever-freebsd
Configuring OpenSSL version 1.1.1m (0x101010dfL) for BSD-x86_64
Using os-specific seed configuration
Creating configdata.pm
Creating Makefile

**********************************************************************
***                                                                ***
***   OpenSSL has been successfully configured                     ***
***                                                                ***
***   If you encounter a problem while building, please open an    ***
***   issue on GitHub <[URL]https://github.com/openssl/openssl/issues[/URL]>  ***
***   and include the output from the following command:           ***
***                                                                ***
***       perl configdata.pm --dump                                ***
***                                                                ***
***   (If you are new to OpenSSL, you might want to consult the    ***
***   'Troubleshooting' section in the INSTALL file first)         ***
***                                                                ***
**********************************************************************

Code:
[root@Client_Site1 /usr/ports/security/openssl]# make CC="cc -target aarch64-unknown-freebsd --sysroot=/usr/local/freebsd-sysroot/aarch64"
===> Options unchanged
===>  Building for openssl-1.1.1m_2,1
/usr/bin/make depend && /usr/bin/make _all
cc -target aarch64-unknown-freebsd --sysroot=/usr/local/freebsd-sysroot/aarch64  -I. -Iinclude -fPIC -pthread -Wa,--noexecstack -Qunused-arguments -O2 -pipe  -fstack-protector-strong -fno-strict-aliasing -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DAESNI_ASM -DVPAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -DPOLY1305_ASM -DOPENSSLDIR="\"/usr/local/openssl\"" -DENGINESDIR="\"/usr/local/lib/engines-1.1\"" -D_THREAD_SAFE -D_REENTRANT -DNDEBUG  -MMD -MF crypto/bn/asm/x86_64-gcc.d.tmp -MT crypto/bn/asm/x86_64-gcc.o -c -o crypto/bn/asm/x86_64-gcc.o crypto/bn/asm/x86_64-gcc.c
crypto/bn/asm/x86_64-gcc.c:120:9: error: invalid output constraint '=a' in asm
        mul_add(rp[0], ap[0], w, c1);
        ^
crypto/bn/asm/x86_64-gcc.c:78:19: note: expanded from macro 'mul_add'
                : "=a"(low),"=d"(high)  \
                  ^
crypto/bn/asm/x86_64-gcc.c:120:9: error: invalid output constraint '+d' in asm
crypto/bn/asm/x86_64-gcc.c:82:31: note: expanded from macro 'mul_add'
                : "+r"(carry),"+d"(high)\
                              ^
crypto/bn/asm/x86_64-gcc.c:120:9: error: invalid output constraint '+d' in asm
crypto/bn/asm/x86_64-gcc.c:86:27: note: expanded from macro 'mul_add'
                : "+m"(r),"+d"(high)    \
                          ^
crypto/bn/asm/x86_64-gcc.c:121:9: error: invalid output constraint '=a' in asm
        mul_add(rp[1], ap[1], w, c1);
        ^
crypto/bn/asm/x86_64-gcc.c:78:19: note: expanded from macro 'mul_add'
                : "=a"(low),"=d"(high)  \
                  ^
crypto/bn/asm/x86_64-gcc.c:121:9: error: invalid output constraint '+d' in asm
crypto/bn/asm/x86_64-gcc.c:82:31: note: expanded from macro 'mul_add'
                : "+r"(carry),"+d"(high)\
                              ^
crypto/bn/asm/x86_64-gcc.c:121:9: error: invalid output constraint '+d' in asm
crypto/bn/asm/x86_64-gcc.c:86:27: note: expanded from macro 'mul_add'
                : "+m"(r),"+d"(high)    \
                          ^
crypto/bn/asm/x86_64-gcc.c:122:9: error: invalid output constraint '=a' in asm
        mul_add(rp[2], ap[2], w, c1);
        ^
crypto/bn/asm/x86_64-gcc.c:78:19: note: expanded from macro 'mul_add'
                : "=a"(low),"=d"(high)  \
                  ^
crypto/bn/asm/x86_64-gcc.c:122:9: error: invalid output constraint '+d' in asm
crypto/bn/asm/x86_64-gcc.c:82:31: note: expanded from macro 'mul_add'
                : "+r"(carry),"+d"(high)\
                              ^
crypto/bn/asm/x86_64-gcc.c:122:9: error: invalid output constraint '+d' in asm
crypto/bn/asm/x86_64-gcc.c:86:27: note: expanded from macro 'mul_add'
                : "+m"(r),"+d"(high)    \
                          ^
crypto/bn/asm/x86_64-gcc.c:123:9: error: invalid output constraint '=a' in asm
        mul_add(rp[3], ap[3], w, c1);
        ^
crypto/bn/asm/x86_64-gcc.c:78:19: note: expanded from macro 'mul_add'
                : "=a"(low),"=d"(high)  \
                  ^
crypto/bn/asm/x86_64-gcc.c:123:9: error: invalid output constraint '+d' in asm
crypto/bn/asm/x86_64-gcc.c:82:31: note: expanded from macro 'mul_add'
                : "+r"(carry),"+d"(high)\
                              ^
crypto/bn/asm/x86_64-gcc.c:123:9: error: invalid output constraint '+d' in asm
crypto/bn/asm/x86_64-gcc.c:86:27: note: expanded from macro 'mul_add'
                : "+m"(r),"+d"(high)    \
                          ^
crypto/bn/asm/x86_64-gcc.c:129:9: error: invalid output constraint '=a' in asm
        mul_add(rp[0], ap[0], w, c1);
        ^
crypto/bn/asm/x86_64-gcc.c:78:19: note: expanded from macro 'mul_add'
                : "=a"(low),"=d"(high)  \
                  ^
crypto/bn/asm/x86_64-gcc.c:129:9: error: invalid output constraint '+d' in asm
crypto/bn/asm/x86_64-gcc.c:82:31: note: expanded from macro 'mul_add'
                : "+r"(carry),"+d"(high)\
                              ^
crypto/bn/asm/x86_64-gcc.c:129:9: error: invalid output constraint '+d' in asm
crypto/bn/asm/x86_64-gcc.c:86:27: note: expanded from macro 'mul_add'
                : "+m"(r),"+d"(high)    \
                          ^
crypto/bn/asm/x86_64-gcc.c:132:9: error: invalid output constraint '=a' in asm
        mul_add(rp[1], ap[1], w, c1);
        ^
crypto/bn/asm/x86_64-gcc.c:78:19: note: expanded from macro 'mul_add'
                : "=a"(low),"=d"(high)  \
                  ^
crypto/bn/asm/x86_64-gcc.c:132:9: error: invalid output constraint '+d' in asm
crypto/bn/asm/x86_64-gcc.c:82:31: note: expanded from macro 'mul_add'
                : "+r"(carry),"+d"(high)\
                              ^
crypto/bn/asm/x86_64-gcc.c:132:9: error: invalid output constraint '+d' in asm
crypto/bn/asm/x86_64-gcc.c:86:27: note: expanded from macro 'mul_add'
                : "+m"(r),"+d"(high)    \
                          ^
crypto/bn/asm/x86_64-gcc.c:135:9: error: invalid output constraint '=a' in asm
        mul_add(rp[2], ap[2], w, c1);
        ^
crypto/bn/asm/x86_64-gcc.c:78:19: note: expanded from macro 'mul_add'
                : "=a"(low),"=d"(high)  \
                  ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
*** [crypto/bn/asm/x86_64-gcc.o] Error code 1

make[3]: stopped in /usr/ports/security/openssl/work/openssl-1.1.1m
1 error

make[3]: stopped in /usr/ports/security/openssl/work/openssl-1.1.1m
*** [all] Error code 2

make[2]: stopped in /usr/ports/security/openssl/work/openssl-1.1.1m
1 error

make[2]: stopped in /usr/ports/security/openssl/work/openssl-1.1.1m
===> Compilation failed unexpectedly.
Try to set MAKE_JOBS_UNSAFE=yes and rebuild before reporting the failure to
the maintainer.
*** Error code 1

Stop.
make[1]: stopped in /usr/ports/security/openssl
*** Error code 1

Stop.
make: stopped in /usr/ports/security/openssl
 
Hi, thanks for your help I managed to cross-compile it 👍:)👍

So here I summarized on how I managed to do it, so everyone can refer on how to achieve this:

Fyi. im cross compiling from am64 for aarch64.

1. install target sysroot(in my case I'm targetting aarch64):

Code:
pkg install aarch64-freebsd-sysroot

OPTIONAL(you can also extract your target sysroot by your self if you have access to the target arch by running command below):

Code:
mkdir ~/sysroot_aarch64
tar cf - /lib /usr/include /usr/lib /usr/local/lib /usr/local/include | bsdtar xvf - -C $HOME/sysroot_aarch64

you can find great article here on how to extract sysroot.

2. Download openssl source tar.
3. Extract openssl tar and go the directory of that openssl.
4. Define MACHINE arch:

Code:
export MACHINE=aarch64

5. Run Configure command:

./Configure BSD-generic32 --sysroot=/usr/local/freebsd-sysroot/aarch64 -prefix=/usr/local/openssl-custom --openssldir=/opt/openssl-custom -Wl,-rpath=/user/local/openssl-custom/lib

6. Run make command:

Code:
make CC="cc -target aarch64-unknown-freebsd --sysroot=/usr/local/freebsd-sysroot/aarch64"

I hope this can help anyone who have trouble in cross compiling openssl for arm. Cheers :beer: Br
 
Back
Top