Skip to content

Build OpenSSL from portable C sources where there is no assembly - #112863

Merged
alexey-milovidov merged 1 commit into
masterfrom
openssl-generic-no-asm-build
Aug 1, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
openssl-generic-no-asm-build

Conversation

@alexey-milovidov

Copy link
Copy Markdown
Member

contrib/openssl-cmake picks a PLATFORM_DIRECTORY and the AES/BN/SHA/... implementations from a per-architecture if/elseif chain. An architecture the chain does not know about matches nothing: no buildinf.h include directory, and not one of the crypto cores gets compiled. The build then runs all the way to the final link before failing on undefined OPENSSL_cleanse and friends, which says nothing about what is actually wrong.

This adds a no-asm arm that builds the portable C implementations - the same source set the Darwin arms already use, since those are no-asm builds too - against a hand-written generic buildinf.h, with the endianness taken from CMAKE_CXX_BYTE_ORDER. An unrecognized architecture now selects it by itself, so a new port gets a working (if slower) libcrypto instead of a link failure. Some targets, WebAssembly for one, have no assembler at all and can only build this way.

The same arm can be selected explicitly with -DOPENSSL_NO_ASM=1, which is how it was tested: an x86_64 build with that flag links no .s object at all, and SHA1/SHA256/SHA512/MD5/keccak256, AES-GCM and AES-CBC round trips and an HTTPS fetch through url() all give the same answers as the assembly build.

Default builds are unaffected - every architecture with a build description here takes the same arm as before.

Changelog category (leave one):

  • Build/Testing/Packaging Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

OpenSSL can now be built from its portable C sources on architectures that have no hand-written assembly in the build description, instead of failing at the final link with undefined symbols. The new OPENSSL_NO_ASM CMake option selects the same path explicitly.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

`contrib/openssl-cmake` picks a `PLATFORM_DIRECTORY` and the AES/BN/SHA/...
implementations from a per-architecture `if/elseif` chain. An architecture the
chain does not know about matches nothing: no `buildinf.h` include directory,
and not one of the crypto cores gets compiled. The build then runs all the way
to the final link before failing on undefined `OPENSSL_cleanse` and friends,
which says nothing about what is actually wrong.

Add a no-asm arm that builds the portable C implementations - the same source
set the Darwin arms already use, since those are no-asm builds too - against a
hand-written generic `buildinf.h`, with the endianness taken from
`CMAKE_CXX_BYTE_ORDER`. An unrecognized architecture now selects it by itself,
so a new port gets a working (if slower) libcrypto instead of a link failure.
Some targets, WebAssembly for one, have no assembler at all and can only build
this way.

The same arm can be selected explicitly with `-DOPENSSL_NO_ASM=1`, which is how
it was tested: an x86_64 build with that flag links no `.s` object at all, and
`SHA1`/`SHA256`/`SHA512`/`MD5`/`keccak256`, AES-GCM and AES-CBC round trips and
an HTTPS fetch through `url()` all give the same answers as the assembly build.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e67d8f6]

Summary: ✅


AI Review

Summary

This PR adds a generic OPENSSL_NO_ASM path in contrib/openssl-cmake so unknown architectures can fall back to the portable OpenSSL C sources instead of failing late at link time. The main issue is that the new mode only removes .s/.S files from the CMake source list; it does not define the upstream OPENSSL_NO_ASM preprocessor macro, so the "no-asm" configuration is still not actually the portable C configuration OpenSSL expects.

Findings

❌ Blockers

  • [contrib/openssl-cmake/CMakeLists.txt:52] The new OPENSSL_NO_ASM branch never adds -DOPENSSL_NO_ASM. In the pinned OpenSSL sources, that macro is what disables inline-assembly code paths in places such as include/crypto/modes.h, include/internal/constant_time.h, crypto/chacha/chacha_enc.c, and crypto/bn/bn_div.c. As written, -DOPENSSL_NO_ASM=1 still compiles asm-dependent code, so the new option does not implement the portable no-asm contract it advertises. Suggested fix: define OPENSSL_NO_ASM when this branch is selected, so the preprocessor guards line up with the CMake source selection.
Final Verdict

Changes requested. The new no-asm mode needs to define the upstream OPENSSL_NO_ASM macro; otherwise the feature is only partially wired and does not actually disable OpenSSL's asm-dependent code paths.

@clickhouse-gh clickhouse-gh Bot added pr-build Pull request with build/testing/packaging improvement submodule changed At least one submodule changed in this PR. labels Aug 1, 2026
set(OPENSSL_NO_ASM ON)
endif()

if(OPENSSL_NO_ASM)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new OPENSSL_NO_ASM mode never defines the upstream OPENSSL_NO_ASM preprocessor macro; it only swaps the source list. That means the "no-asm" build still takes inline-assembly paths in the pinned OpenSSL sources, e.g. include/crypto/modes.h, include/internal/constant_time.h, crypto/chacha/chacha_enc.c, and crypto/bn/bn_div.c, so -DOPENSSL_NO_ASM=1 does not actually give the portable C configuration this option promises. Please add -DOPENSSL_NO_ASM in this branch as well, otherwise the new flag remains incomplete and the "no assembler" target the PR description talks about is still exposed to asm-dependent code.

@thevar1able thevar1able self-assigned this Aug 1, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 1, 2026
Merged via the queue into master with commit 40cc783 Aug 1, 2026
179 checks passed
@alexey-milovidov
alexey-milovidov deleted the openssl-generic-no-asm-build branch August 1, 2026 14:07
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-build Pull request with build/testing/packaging improvement pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants