From c00bd2a6fb8bd1070b70174bb1b664cec3c79b0e Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 16 Dec 2025 21:11:44 +0100 Subject: [PATCH] THREADING autodetection: only check the crypto config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When running the preprocessor to determine whether pthread is enabled, only use TF-PSA-Crypto include paths. Don't use the rest of `LOCAL_CFLAGS`, including Mbed TLS include paths, which aren't really useful here. This will simplify later refactorings, because it simplifies a dependency chain [crypto paths] → `LOCAL_CFLAGS` → `THREADING` → `LOCAL_LDFLAGS` into just [crypto paths] → `THREADING` → `LOCAL_LDFLAGS`. Signed-off-by: Gilles Peskine --- scripts/common.make | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/scripts/common.make b/scripts/common.make index dc9e148ee3..ee120a8ae8 100644 --- a/scripts/common.make +++ b/scripts/common.make @@ -79,23 +79,23 @@ ifdef WINDOWS WINDOWS_BUILD=1 endif -## Usage: $(call remove_enabled_options,PREPROCESSOR_INPUT) +## Usage: $(call remove_enabled_options_crypto,PREPROCESSOR_INPUT) ## Remove the preprocessor symbols that are set in the current configuration ## from PREPROCESSOR_INPUT. Also normalize whitespace. ## Example: -## $(call remove_enabled_options,MBEDTLS_FOO MBEDTLS_BAR) +## $(call remove_enabled_options_crypto,MBEDTLS_FOO MBEDTLS_BAR) ## This expands to an empty string "" if MBEDTLS_FOO and MBEDTLS_BAR are both -## enabled, to "MBEDTLS_FOO" if MBEDTLS_BAR is enabled but MBEDTLS_FOO is -## disabled, etc. +## enabled in the TF-PSA-Crypto configuration, to "MBEDTLS_FOO" if +## MBEDTLS_BAR is enabled but MBEDTLS_FOO is disabled, etc. ## ## This only works with a Unix-like shell environment (Bourne/POSIX-style shell ## and standard commands) and a Unix-like compiler (supporting -E). In ## other environments, the output is likely to be empty. -define remove_enabled_options +define remove_enabled_options_crypto $(strip $(shell exec 2>/dev/null; - { echo '#include '; echo $(1); } | - $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -E - | + { echo '#include '; echo $(1); } | + $(CC) $(TF_PSA_CRYPTO_LIBRARY_PUBLIC_INCLUDE) $(CFLAGS) -E - | tail -n 1 )) endef @@ -117,21 +117,24 @@ ifdef WINDOWS_BUILD ifdef SHARED SHARED_SUFFIX=.$(DLEXT) endif - else # Not building for Windows DLEXT ?= so EXEXT= SHARED_SUFFIX= +endif + +ifndef WINDOWS_BUILD ifeq ($(THREADING),) # Auto-detect configurations with pthread. # If the call to remove_enabled_options returns "control", the symbols # are confirmed set and we link with pthread. # If the auto-detection fails, the result of the call is empty and # we keep THREADING undefined. - ifeq (control,$(call remove_enabled_options,control MBEDTLS_THREADING_C MBEDTLS_THREADING_PTHREAD)) + ifeq (control,$(call remove_enabled_options_crypto,control MBEDTLS_THREADING_C MBEDTLS_THREADING_PTHREAD)) THREADING := pthread endif endif + #$(info THREADING = $(THREADING)) ifeq ($(THREADING),pthread) LOCAL_LDFLAGS += -lpthread