Repository navigation
Give test hook declarations C linkage - #256
Merged
Merged
Conversation
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.
Contributor
There was a problem hiding this comment.
🟢 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
approved these changes
Oct 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
wolfpkcs11/internal.hdeclares theDEBUG_WOLFPKCS11test hooks inside anextern "C"block, so the library exports them with C linkage even when built as C++. Several tests declared the hooks they use with a plainexterninstead. 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:CI never saw this because the
cpp_buildjob 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:destroy_stale_handle_test,logout_retire_test,logout_token_key_zero_test,token_reset_fail_test,token_store_testtoken_store_test(WP11_Test_StoreWriteFailAfter,WP11_Test_StoreWriteFailOnce,WP11_Test_TpmStoreShortBy),tpm_decode_bounds_testinternal.h, guarded for consistency:login_pin_state_test,object_policy_integrity_testAll 13 hooks are declared inside the
extern "C"block ininternal.h, so C linkage is right for every one.Build the C++ CI job with debug enabled too
Adds
cpp_debug_buildtounit-test.yml: thecpp_buildflags plus--enable-debug. The existing non-debug C++ job stays.Testing
cpp_debug_buildin Debian trixie with g++ 14.2 and wolfSSL master built with thebuild-workflow.ymlflags. On mastermakefails to link with the errors above. On this branchmakesucceeds andmake checkpasses (77 pass, 4 skip).CC=clang++ --enable-debug:make checkpasses (77 pass, 4 skip).nmshows each test now references the unmangled hook, including the TPM-only declarations (compiled withWOLFPKCS11_TPM_STORE).make testpasses on both commits.