Skip to content

Give test hook declarations C linkage - #256

Merged
Frauschi merged 2 commits into
wolfSSL:masterfrom
LinuxJedi:test-hook-c-linkage
Oct 19, 2026
Merged

Frauschi merged 2 commits into
wolfSSL:masterfrom
LinuxJedi:test-hook-c-linkage

Conversation

@LinuxJedi

Copy link
Copy Markdown
Member

wolfpkcs11/internal.h declares the DEBUG_WOLFPKCS11 test hooks inside an extern "C" block, so the library exports them with C linkage even when built as C++. Several tests declared the hooks they use with a plain extern instead. Built as C++ with --enable-debug, those declarations ask for mangled names the library does not export, so the tests fail to link. With g++ 14.2 on master:

undefined reference to `WP11_Test_RemoveObjectStale(unsigned long, unsigned long, unsigned long)'
undefined reference to `WP11_Slot_TokenKeyIsZero(unsigned long)'
undefined reference to `WP11_Test_FailTokenInit(int)'
undefined reference to `WP11_Test_StoreCloseFailAfter(int)'

CI never saw this because the cpp_build job does not use --enable-debug. The same issue was raised by Copilot on #255 for the test that PR adds.

Commits

Give test hook declarations C linkage

Wraps each hook declaration in the same extern "C" guard, in eight tests:

  • fail to link on master: destroy_stale_handle_test, logout_retire_test, logout_token_key_zero_test, token_reset_fail_test, token_store_test
  • TPM-only parts that would fail the same way: token_store_test (WP11_Test_StoreWriteFailAfter, WP11_Test_StoreWriteFailOnce, WP11_Test_TpmStoreShortBy), tpm_decode_bounds_test
  • already linked because they include internal.h, guarded for consistency: login_pin_state_test, object_policy_integrity_test

All 13 hooks are declared inside the extern "C" block in internal.h, so C linkage is right for every one.

Build the C++ CI job with debug enabled too

Adds cpp_debug_build to unit-test.yml: the cpp_build flags plus --enable-debug. The existing non-debug C++ job stays.

Testing

  • Replicated cpp_debug_build in Debian trixie with g++ 14.2 and wolfSSL master built with the build-workflow.yml flags. On master make fails to link with the errors above. On this branch make succeeds and make check passes (77 pass, 4 skip).
  • macOS with CC=clang++ --enable-debug: make check passes (77 pass, 4 skip). nm shows each test now references the unmangled hook, including the TPM-only declarations (compiled with WOLFPKCS11_TPM_STORE).
  • All eight files still compile as C with and without the TPM defines. Pre-commit hook make test passes on both commits.

wolfpkcs11/internal.h declares the DEBUG_WOLFPKCS11 test hooks inside
an extern "C" block, so the library exports them with C linkage even
when it is built as C++. Eight tests declared the hooks they use with
a plain extern instead. Built as C++ with --enable-debug, those
declarations ask for mangled names the library does not export, so
destroy_stale_handle_test, logout_retire_test,
logout_token_key_zero_test, token_reset_fail_test and token_store_test
failed to link, as did the TPM-only parts of token_store_test and
tpm_decode_bounds_test.

Wrap each declaration in the same extern "C" guard.
login_pin_state_test and object_policy_integrity_test include
internal.h, so theirs already linked; they get the guard for
consistency.
The cpp_build job builds as C++ without --enable-debug, so it never
compiles the debug-only test hooks or the parts of the tests that
declare them, and missing extern "C" guards went unnoticed. Add a
cpp_debug_build job with the same flags plus --enable-debug. With g++
14.2 it fails to link on master and passes on the previous commit.
Copilot AI balanced review requested due to automatic review settings October 16, 2026 10:59

Copilot AI left a comment

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.

🟢 Approval recommended

The linkage guards match the library declarations, preserve C compatibility, and add CI coverage for the affected configuration.

0 open findings

What changed in this PR

Fixes C++ debug test linking by matching test-hook declarations to the library’s C linkage.

Changes:

  • Adds conditional extern "C" guards in eight tests, preserving C compilation.
  • Adds C++ debug CI coverage alongside the existing non-debug job.
File Description
tests/​tpm_decode_bounds_test.c Guards the TPM decode hook.
tests/​token_store_test.c Guards storage failure hooks.
tests/​token_reset_fail_test.c Guards the token initialization hook.
tests/​object_policy_integrity_test.c Guards the storage exit hook.
tests/​logout_token_key_zero_test.c Guards the token-key inspection hook.
tests/​logout_retire_test.c Guards object lifecycle hooks.
tests/​login_pin_state_test.c Guards token inspection and PIN-check hooks.
tests/​destroy_stale_handle_test.c Guards the stale-handle removal hook.
.github/​workflows/​unit-test.yml Adds the C++ debug build job.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Frauschi
Frauschi merged commit 3059fff into wolfSSL:master Oct 19, 2026
92 checks passed
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.

4 participants