From 570e54822c045f848cd3d9d9e317f965be0f6190 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 2 Jan 2024 18:11:10 +0100 Subject: [PATCH 1/4] Finish unifying LOCAL_CFLAGS fixup "Create common.make with LOCAL_CFLAGS and friends" The code wasn't what I had intended, although it was functionally equivalent. Make it more readable and more robust. Signed-off-by: Gilles Peskine --- programs/Makefile | 1 - scripts/common.make | 2 +- tests/Makefile | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/programs/Makefile b/programs/Makefile index 64f7cc1a32..50be1763e1 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -3,7 +3,6 @@ MBEDTLS_TEST_PATH = ../tests # code which is in the src/test_helpers subdirectory. MBEDTLS_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard ${MBEDTLS_TEST_PATH}/src/*.c ${MBEDTLS_TEST_PATH}/src/drivers/*.c)) -LOCAL_CFLAGS = $(WARNING_CFLAGS) -I$(MBEDTLS_TEST_PATH)/include -I../include -D_FILE_OFFSET_BITS=64 include ../scripts/common.make ifeq ($(shell uname -s),Linux) diff --git a/scripts/common.make b/scripts/common.make index 2f27d0ef52..b115076f89 100644 --- a/scripts/common.make +++ b/scripts/common.make @@ -5,7 +5,7 @@ WARNING_CFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral WARNING_CXXFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral LDFLAGS ?= -LOCAL_CFLAGS = $(WARNING_CFLAGS) -I../tests/include -I../include -D_FILE_OFFSET_BITS=64 +LOCAL_CFLAGS = $(WARNING_CFLAGS) -I$(MBEDTLS_TEST_PATH)/include -I../include -D_FILE_OFFSET_BITS=64 LOCAL_CXXFLAGS = $(WARNING_CXXFLAGS) -I../include -I../tests/include -D_FILE_OFFSET_BITS=64 LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} \ -L../library \ diff --git a/tests/Makefile b/tests/Makefile index 7a10af271c..848d3c499d 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,3 +1,4 @@ +MBEDTLS_TEST_PATH = . include ../scripts/common.make # Set this to -v to see the details of failing test cases @@ -109,7 +110,6 @@ BINARIES := $(addsuffix $(EXEXT),$(APPS)) all: $(BINARIES) -MBEDTLS_TEST_PATH = . MBEDTLS_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard ${MBEDTLS_TEST_PATH}/src/*.c ${MBEDTLS_TEST_PATH}/src/drivers/*.c)) MBEDTLS_TEST_OBJS += $(patsubst %.c,%.o,$(wildcard ${MBEDTLS_TEST_PATH}/src/test_helpers/*.c)) From 89391483390fbcf6ccabd00ac897e10564b52fa7 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 2 Jan 2024 18:14:00 +0100 Subject: [PATCH 2/4] Minor readability improvement Signed-off-by: Gilles Peskine --- programs/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/programs/Makefile b/programs/Makefile index 50be1763e1..4bf11062c6 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -1,8 +1,4 @@ MBEDTLS_TEST_PATH = ../tests -# Support code used by test programs and test builds, excluding TLS-specific -# code which is in the src/test_helpers subdirectory. -MBEDTLS_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard ${MBEDTLS_TEST_PATH}/src/*.c ${MBEDTLS_TEST_PATH}/src/drivers/*.c)) - include ../scripts/common.make ifeq ($(shell uname -s),Linux) @@ -11,6 +7,10 @@ else DLOPEN_LDFLAGS ?= endif +# Support code used by test programs and test builds, excluding TLS-specific +# code which is in the src/test_helpers subdirectory. +MBEDTLS_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard ${MBEDTLS_TEST_PATH}/src/*.c ${MBEDTLS_TEST_PATH}/src/drivers/*.c)) + DEP=${MBEDLIBS} ${MBEDTLS_TEST_OBJS} # Only build the dlopen test in shared library builds, and not when building From cd06a813c6a0ad4e19ce8cca88d4410b57389473 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 2 Jan 2024 18:14:40 +0100 Subject: [PATCH 3/4] Fix name in documentation fixup "Correct name and documentation of preprocessor symbol check function" Signed-off-by: Gilles Peskine --- scripts/common.make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/common.make b/scripts/common.make index b115076f89..e8d22cb748 100644 --- a/scripts/common.make +++ b/scripts/common.make @@ -35,7 +35,7 @@ endif ## Remove the preprocessor symbols that are set in the current configuration ## from PREPROCESSOR_INPUT. Also normalize whitespace. ## Example: -## $(call remove_set_options,MBEDTLS_FOO MBEDTLS_BAR) +## $(call remove_enabled_options,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. From 0ae58dd985c3b7c8473c3d969507fffa6f7b3a59 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 2 Jan 2024 23:11:24 +0100 Subject: [PATCH 4/4] Unify MBEDTLS_TEST_OBJS `$(MBEDTLS_TEST_OBJS)` included TLS-specific test support modules in `tests/Makefile` but not in `programs/Makefile`. This difference is not actually necessary. What is necessary is that all programs that use functions from TLS-specific test support modules are linked with those modules in addition to `-lmbedtls`, and programs that are not linked with `-lmbedtls` are not linked with TLS-specific test support modules. Since we always pass `-lmbedtls` when linking programs in `programs/Makefile`, we can link with the TLS-specific test support modules as well. This keeps things simpler. Signed-off-by: Gilles Peskine --- programs/Makefile | 4 ---- scripts/common.make | 12 ++++++++++++ tests/Makefile | 3 --- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/programs/Makefile b/programs/Makefile index 4bf11062c6..82c8569963 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -7,10 +7,6 @@ else DLOPEN_LDFLAGS ?= endif -# Support code used by test programs and test builds, excluding TLS-specific -# code which is in the src/test_helpers subdirectory. -MBEDTLS_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard ${MBEDTLS_TEST_PATH}/src/*.c ${MBEDTLS_TEST_PATH}/src/drivers/*.c)) - DEP=${MBEDLIBS} ${MBEDTLS_TEST_OBJS} # Only build the dlopen test in shared library builds, and not when building diff --git a/scripts/common.make b/scripts/common.make index e8d22cb748..6c95b42354 100644 --- a/scripts/common.make +++ b/scripts/common.make @@ -105,3 +105,15 @@ ifndef WINDOWS else for %f in ($(subst /,\,$(GENERATED_FILES))) if exist %f del /Q /F %f endif + +# Auxiliary modules used by tests and some sample programs +MBEDTLS_CORE_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard \ + ${MBEDTLS_TEST_PATH}/src/*.c \ + ${MBEDTLS_TEST_PATH}/src/drivers/*.c \ + )) +# Additional auxiliary modules for TLS testing +MBEDTLS_TLS_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard \ + ${MBEDTLS_TEST_PATH}/src/test_helpers/*.c \ + )) + +MBEDTLS_TEST_OBJS = $(MBEDTLS_CORE_TEST_OBJS) $(MBEDTLS_TLS_TEST_OBJS) diff --git a/tests/Makefile b/tests/Makefile index 848d3c499d..f82c267ac5 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -110,9 +110,6 @@ BINARIES := $(addsuffix $(EXEXT),$(APPS)) all: $(BINARIES) -MBEDTLS_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard ${MBEDTLS_TEST_PATH}/src/*.c ${MBEDTLS_TEST_PATH}/src/drivers/*.c)) -MBEDTLS_TEST_OBJS += $(patsubst %.c,%.o,$(wildcard ${MBEDTLS_TEST_PATH}/src/test_helpers/*.c)) - mbedtls_test: $(MBEDTLS_TEST_OBJS) TEST_OBJS_DEPS = $(wildcard include/test/*.h include/test/*/*.h)