Skip to content

Support building on platforms without vendored assembly (OPENSSL_NO_ASM fallback, powerpc64le) - #450

Open
colemancda wants to merge 2 commits into
apple:mainfrom
colemancda:linux-no-asm-fallback
Open

Support building on platforms without vendored assembly (OPENSSL_NO_ASM fallback, powerpc64le)#450
colemancda wants to merge 2 commits into
apple:mainfrom
colemancda:linux-no-asm-fallback

Conversation

@colemancda

Copy link
Copy Markdown

Allow swift-crypto to build on Linux architectures that have no vendored BoringSSL assembly, and restore target detection for powerpc64le.

Checklist

  • I've run tests to see all new and existing tests pass
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary

Motivation:

The CMake build only defines platform sources for x86_64 and arm64 (plus their Windows variants); every other architecture — 32-bit ARM, i686, powerpc64le, RISC-V, MIPS — hits a hard message(FATAL_ERROR "platform sources are not defined here ...") with no way to opt into a portable build, even though BoringSSL fully supports a pure-C configuration via OPENSSL_NO_ASM (the assembly is only an optimization guarded by !defined(OPENSSL_NO_ASM)).

Additionally, upstream BoringSSL removed powerpc64le from its target detection, so on ppc64le neither OPENSSL_32_BIT nor OPENSSL_64_BIT gets defined and every header fails with:

CCryptoBoringSSL_bn.h:173:2: error: "Must define either OPENSSL_32_BIT or OPENSSL_64_BIT"

The comment above that #error explicitly says the portable C code works on any standard 32/64-bit two's-complement little-endian architecture and invites carrying a local patch for such targets — powerpc64le qualifies.

We hit both issues cross-compiling swift-crypto with CMake for embedded Linux targets (Buildroot) across armv5/armv6/armv7/i686/aarch64/x86_64/ppc64le; with these two changes the full matrix builds and the Crypto module passes a runtime smoke test (SHA256.hash) on the non-asm architectures.

Modifications:

  • Sources/CCryptoBoringSSL/CMakeLists.txt: replace the FATAL_ERROR fallback branch with target_compile_definitions(CCryptoBoringSSL PRIVATE OPENSSL_NO_ASM). Platforms that do have vendored assembly are unaffected.
  • Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_target.h: add a __powerpc64__ + little-endian branch defining OPENSSL_64_BIT. Since this file is vendored, the change is carried as scripts/patch-4-powerpc64le-target.patch and applied by scripts/vendor-boringssl.sh (alongside the existing patch-1/2) so it survives re-vendoring. OPENSSL_PPC64LE is deliberately not defined so no stale arch-specific code paths are enabled; the generic C implementation is used together with OPENSSL_NO_ASM.

Result:

The CMake build succeeds on Linux architectures without vendored assembly (32-bit ARM, i686, powerpc64le, ...) using BoringSSL's supported pure-C configuration, instead of failing at configure time. x86_64 and arm64 continue to build their vendored assembly exactly as before. The powerpc64le detection fix also benefits SwiftPM builds on that architecture.

The CMake build only defines platform sources for x86_64 and arm64 (plus
their Windows variants); every other architecture hits a hard
message(FATAL_ERROR) with no way to opt into a portable build.

Replace the fatal error with the pure-C BoringSSL configuration by
defining OPENSSL_NO_ASM for the CCryptoBoringSSL target. This is a
supported BoringSSL build mode: the C implementations are always
compiled and the assembly is only an optimization guarded by
!defined(OPENSSL_NO_ASM). Platforms that do have vendored assembly are
unaffected.
Upstream BoringSSL removed ppc64le support, so on powerpc64le neither
OPENSSL_32_BIT nor OPENSSL_64_BIT gets defined and every header fails
with:

  CCryptoBoringSSL_bn.h: error: "Must define either OPENSSL_32_BIT or
  OPENSSL_64_BIT"

powerpc64le is a standard 64-bit two's-complement little-endian
architecture, which is exactly what the portable C code supports per the
comment above that #error. Add a detection branch defining
OPENSSL_64_BIT, carried as scripts/patch-4-powerpc64le-target.patch and
applied by vendor-boringssl.sh so it survives re-vendoring.
OPENSSL_PPC64LE is deliberately not defined so no stale arch-specific
code paths are enabled; the generic C implementation is used together
with OPENSSL_NO_ASM.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant