tpm2_types.h: freestanding build support (WOLFTPM_NO_STD_HEADERS) and NO_RETRY/MAX_RETRIES config cleanup#549
Merged
Conversation
added 2 commits
July 10, 2026 11:51
The old block force-defined WOLFTPM_MAX_RETRIES=0 under WOLFTPM_NO_RETRY, which is dead (MAX_RETRIES is only read under #ifndef WOLFTPM_NO_RETRY), and silently swallowed the contradictory NO_RETRY + MAX_RETRIES>0 combo. Define the default first, then diagnose the conflict with #error. Keeping MAX_RETRIES defined before the check keeps it -Wundef-clean, including the NO_RETRY-without-MAX_RETRIES case.
Targets without a hosted C library cannot build wolfTPM today because tpm2_types.h unconditionally includes <stdint.h> and (in the standalone WOLFTPM2_NO_WOLFCRYPT path) <stdio.h>/<stdlib.h>/<string.h>. Guard those standard headers behind WOLFTPM_NO_STD_HEADERS so a freestanding target can supply the fixed-width types and mem/str functions via user_settings.h. No change for hosted builds (macro undefined). Platform delay/sleep headers (unistd/time) stay steered by the existing XTPM_WAIT/XSLEEP_MS hooks and their platform conditionals.
c0fea5d to
e087029
Compare
added 2 commits
July 10, 2026 12:10
Same freestanding contract as tpm2_types.h: a target with no hosted C library supplies its own I/O, so the bare <stdio.h> must be guarded too.
Builds the standalone (WOLFTPM2_NO_WOLFCRYPT) library under -nostdinc with types supplied via user_settings.h, so a regression that pulls a standard header back in fails CI. Uses ./configure + make (CFLAGS carries -nostdinc).
dgarske
approved these changes
Jul 10, 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.
Two small, independent build-configuration cleanups in
wolftpm/tpm2_types.h. No functional change for existing hosted builds.1. Support freestanding builds —
WOLFTPM_NO_STD_HEADERSA target without a hosted C standard library currently cannot build wolfTPM:
tpm2_types.hunconditionally includes<stdint.h>, and in the standaloneWOLFTPM2_NO_WOLFCRYPTpath also<stdio.h>/<stdlib.h>/<string.h>. A-nostdinc/ freestanding compile fails at the first include.Guard the standard type/libc headers behind
WOLFTPM_NO_STD_HEADERS. When defined, the target supplies the fixed-width integer types and the mem/str functions (used via theX*wrappers) throughuser_settings.hinstead. Platform delay/sleep headers (unistd.h/time.h) are unchanged — they remain steered by the existingXTPM_WAIT/XSLEEP_MShooks and their platform conditionals.2. Error on conflicting
WOLFTPM_NO_RETRY+WOLFTPM_MAX_RETRIES-DWOLFTPM_NO_RETRY -DWOLFTPM_MAX_RETRIES=N(N > 0) is contradictory: compile the retry mechanism out and retry N times. The old block silently#undefd the user'sMAX_RETRIESand forced 0, so the build ignored an explicit flag with no diagnostic.#undef-ing a caller-supplied command-line macro is also fragile.Define the default first, then
#erroron the actual conflict. Ordering the default before the check keeps it-Wundef-clean, including theNO_RETRY-without-MAX_RETRIEScase.Testing
make(with--enable-swtpm), including unit tests: builds clean, no regression.wolftpm/tpm2_types.hcompiles under-nostdincwith-DWOLFTPM_NO_STD_HEADERS -DWOLFTPM2_NO_WOLFCRYPTand types supplied viauser_settings.h— no standard header reached.-Wundef -Werror; the contradictory combo now fails with a clear#error.