Skip to content

tpm2_types.h: freestanding build support (WOLFTPM_NO_STD_HEADERS) and NO_RETRY/MAX_RETRIES config cleanup#549

Merged
dgarske merged 4 commits into
wolfSSL:masterfrom
tmael:freestanding-build-config
Jul 10, 2026
Merged

tpm2_types.h: freestanding build support (WOLFTPM_NO_STD_HEADERS) and NO_RETRY/MAX_RETRIES config cleanup#549
dgarske merged 4 commits into
wolfSSL:masterfrom
tmael:freestanding-build-config

Conversation

@tmael

@tmael tmael commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

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_HEADERS

A target without a hosted C standard library currently cannot build wolfTPM: tpm2_types.h unconditionally includes <stdint.h>, and in the standalone WOLFTPM2_NO_WOLFCRYPT path 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 the X* wrappers) through user_settings.h instead. Platform delay/sleep headers (unistd.h/time.h) are unchanged — they remain steered by the existing XTPM_WAIT / XSLEEP_MS hooks 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's MAX_RETRIES and 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 #error on the actual conflict. Ordering the default before the check keeps it -Wundef-clean, including the NO_RETRY-without-MAX_RETRIES case.

Testing

  • Default make (with --enable-swtpm), including unit tests: builds clean, no regression.
  • Freestanding: wolftpm/tpm2_types.h compiles under -nostdinc with -DWOLFTPM_NO_STD_HEADERS -DWOLFTPM2_NO_WOLFCRYPT and types supplied via user_settings.h — no standard header reached.
  • Retry macros exercised across all permutations under -Wundef -Werror; the contradictory combo now fails with a clear #error.

@tmael tmael requested a review from dgarske July 10, 2026 18:46
Tesfa Mael 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.
@tmael tmael force-pushed the freestanding-build-config branch from c0fea5d to e087029 Compare July 10, 2026 18:52

@dgarske dgarske left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you! I'd like a new GitHub CI build for this WOLFTPM_NO_STD_HEADERS. Can you add it @tmael ?

Tesfa Mael 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 dgarske self-requested a review July 10, 2026 19:46
@dgarske dgarske merged commit f2d8330 into wolfSSL:master Jul 10, 2026
197 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.

3 participants