mesonbuild / mesonbuild/wrapdb

OpenSSL cross compile with macOS build and arm host

Open
#830 18 comments 0 reactions 0 assignees View on GitHub
Dominant language
Meson
Stars
118
Forks
298
Avg merge
2d 2h
Merged PRs (30d)
24

Description

Greetings,

I was playing with meson because it seemed fast. I compiled OpenSSL in 7.5 seconds as the wrapdb subproject compared to 5:11 seconds for regular build. This inspired me to try to cross compile to 32 bit ARM linux host/target using macOS M1 as the build box.

At first I tried linaro/arm embedded toolchains, but neither support macOS to arm-linux, just macOS to baremetal arm-none. Okay, so what about clang?

cross-file.txt
```
[binaries]
c = 'clang'
cpp = 'clang++'
ar = 'ar'
strip = 'strip'
as = 'as'

[build_machine]
system = 'darwin'
cpu_family = 'aarch64'
cpu = 'aarch64'

[host_machine]
system = 'linux'
cpu = 'arm'
cpu_family = 'arm'
endian = 'little'
```

build.meson
```
project('tutorial', 'c', default_options : ['c_std=c11', 'cpp_std=c++11'])
ssl = subproject('openssl')
executable('demo', 'main.c')
```

I had to clear the `openssl_libraries` `atomic` entry in `/subprojects/openssl-3.0.7/generated-config/archs/linux-armv4/asm/meson.build`. Couldn't figure out how to override it at the top level meson file or the cross-file.
```
openssl_libraries = [
'dl',
# 'atomic',
]
```

We get to the point where it can't handle the assembly.
```
test_build % meson compile -C builddir/
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /opt/homebrew/bin/ninja -C /private/tmp/test_build/builddir
ninja: Entering directory `/private/tmp/test_build/builddir'
[898/970] Compiling C object subprojects/openssl-3.0.7/libcrypto.so.p/generated-config_archs_linux-armv4_asm_crypto_bn_armv4-gf2m.S.o
FAILED: subprojects/openssl-3.0.7/libcrypto.so.p/generated-config_archs_linux-armv4_asm_crypto_bn_armv4-gf2m.S.o
clang -Isubprojects/openssl-3.0.7/libcrypto.so.p -Isubprojects/openssl-3.0.7 -I../subprojects/openssl-3.0.7 -I../subprojects/openssl-3.0.7/include -I../subprojects/openssl-3.0.7/crypto -I../subprojects/openssl-3.0.7/crypto/modes -I../subprojects/openssl-3.0.7/crypto/ec/curve448 -I../subprojects/openssl-3.0.7/crypto/ec/curve448/arch_32 -I../subprojects/openssl-3.0.7/providers/common/include -I../subprojects/openssl-3.0.7/providers/implementations/include -Isubprojects/openssl-3.0.7/generated-config/archs/linux-armv4/asm -I../subprojects/openssl-3.0.7/generated-config/archs/linux-armv4/asm -I../subprojects/openssl-3.0.7/generated-config/archs/linux-armv4/asm/include -I../subprojects/openssl-3.0.7/generated-config/archs/linux-armv4/asm/crypto -I../subprojects/openssl-3.0.7/generated-config/archs/linux-armv4/asm/providers/common/include -fcolor-diagnostics -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -O0 -g -fPIC -pthread -Wno-missing-field-initializers -DOPENSSL_NO_HW '-DOPENSSLDIR="/etc/ssl"' '-DENGINESDIR="/dev/null"' '-DMODULESDIR="/dev/null"' -DOPENSSL_USE_NODELETE -DOPENSSL_BUILDING_OPENSSL -DAES_ASM -DBSAES_ASM -DECP_NISTZ256_ASM -DGHASH_ASM -DKECCAK1600_ASM -DOPENSSL_BN_ASM_GF2m -DOPENSSL_BN_ASM_MONT -DOPENSSL_CPUID_OBJ -DPOLY1305_ASM -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DOPENSSL_PIC -Wa,--noexecstack -MD -MQ subprojects/openssl-3.0.7/libcrypto.so.p/generated-config_archs_linux-armv4_asm_crypto_bn_armv4-gf2m.S.o -MF subprojects/openssl-3.0.7/libcrypto.so.p/generated-config_archs_linux-armv4_asm_crypto_bn_armv4-gf2m.S.o.d -o subprojects/openssl-3.0.7/libcrypto.so.p/generated-config_archs_linux-armv4_asm_crypto_bn_armv4-gf2m.S.o -c ../subprojects/openssl-3.0.7/generated-config/archs/linux-armv4/asm/crypto/bn/armv4-gf2m.S
../subprojects/openssl-3.0.7/generated-config/archs/linux-armv4/asm/crypto/bn/armv4-gf2m.S:7:1: error: unknown directive
.code 32
^
../subprojects/openssl-3.0.7/generated-config/archs/linux-armv4/asm/crypto/bn/armv4-gf2m.S:11:1: error: unknown directive
.type mul_1x1_ialu,%function
^
```

So it appears to be neglecting the `clang` cross compile requirements: `'--target=arm-linux-gnu', '-mfloat-abi=hard'`

When I re-run the above failed compile command with the target and mfloat defined, it succeeds. I tried appending these as c_args to the executable without luck.

How do I get this to compile?

Cheers,
Joe

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with cross-file.txt and build.meson, then inspect the generated OpenSSL files under subprojects/openssl-3.0.7/generated-config/archs/linux-armv4/asm. Reproduce the failed meson compile command and compare it with the version using --target=arm-linux-gnu and -mfloat-abi=hard. Done means the ARM assembly compiles through the Meson configuration without manual edits to generated files.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
build-system, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.