Skip to content

Compile the CRC32C software fallback unconditionally (fixes NULL crc_impl on ARM) - #1349

Closed
Pranav-error wants to merge 1 commit into
pgmoneta:mainfrom
Pranav-error:fix-crc-impl-arm
Closed

Pranav-error wants to merge 1 commit into
pgmoneta:mainfrom
Pranav-error:fix-crc-impl-arm

Conversation

@Pranav-error

Copy link
Copy Markdown
Collaborator

Fixes #1346.

`pgmoneta_crc_init()`'s body, and the software CRC32C implementation it
falls back to, were both wrapped in `#ifdef HAVE_CRC32_SSE42` -- an
x86-only compiler-flag check. On any platform without it (ARM64, most
notably), `crc_init()` is a no-op, `crc_impl` stays `NULL`, and
`pgmoneta_create_crc32c_buffer()` calls through it unconditionally.

The software implementation is a plain lookup-table CRC with no SSE4.2
dependency, so it doesn't need to be gated at all. This moves it (and
the fallback assignment in `crc_init()`) outside the SSE42-only guard;
only the actual hardware-accelerated path stays conditional on
`HAVE_CRC32_SSE42` + a runtime `cpu_supports_sse42()` check.

Verified live on macOS/arm64: `pgmoneta-cli verify` crashed with
`SIGSEGV` at address 0 every time, inside
`get_controlfile_by_exact_path() -> pgmoneta_create_crc32c_buffer()`
(the first CRC check hit when reading a backup's `pg_control`). After
this fix, the same verify run completes successfully.

This was specifically what blocked PR #1316's `test_cli_verify` from
reaching the page-checksum logic it's meant to exercise -- with this
fix (and #1348) applied, that test now passes end-to-end for the first
time.

pgmoneta_crc_init() had its entire body wrapped in
#ifdef HAVE_CRC32_SSE42, an x86-only macro. The software fallback
implementation, pgmoneta_crc32c_software(), was also defined inside
that same guard, so on any platform without HAVE_CRC32_SSE42 (ARM64
in particular) neither implementation is compiled, crc_init() is a
no-op, and the crc_impl function pointer is left NULL. Every call to
pgmoneta_create_crc32c_buffer() then branches through a NULL function
pointer.

The software implementation has no SSE4.2 dependency at all -- it's a
plain lookup-table CRC -- so it belongs outside the SSE42-only guard.
Only the actual SSE4.2 hardware path stays gated on
HAVE_CRC32_SSE42 + runtime cpu_supports_sse42().

Found and verified live on macOS/arm64: pgmoneta-cli verify crashed
every time with a SIGSEGV at address 0 inside
get_controlfile_by_exact_path() -> pgmoneta_read_control_data(), which
is the first thing that calls pgmoneta_create_crc32c_buffer() during
backup verification. This was specifically what blocked PR pgmoneta#1316's
test_cli_verify from ever completing on this platform; after this fix
it passes.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 4, 2026 10:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Pranav-error

Copy link
Copy Markdown
Collaborator Author

The `build-linux (clang, Debug, 14)` check failure here is a pre-existing CI environment flake, not caused by this change -- it fails in the "Install Dependencies" step itself, before any build starts:

```
Error: nothing provides libarchive(x86-64) = 3.7.7-11.el10_2 needed by libarchive-devel-3.7.7-11.el10_2.x86_64 from appstream
```

A package-mirror version mismatch in the base image. The same step fails the same way on `main` directly (e.g. run 36739031490, 2026-09-30), unrelated to any PR. I don't have rights to re-run the job on this repo -- happy to push an empty commit to retrigger if that's preferred, otherwise a maintainer re-run should clear it.

@jesperpedersen

Copy link
Copy Markdown
Member

Rebased and merged.

Thanks for your contribution !

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.

crc_impl is never initialized on non-x86 platforms, causing a NULL function pointer call in pgmoneta_create_crc32c_buffer()

3 participants