From 90dfc21f6bb9e85abe3ede11f94b1aa217ec712a Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Wed, 14 Jun 2023 17:06:53 +0100 Subject: [PATCH] Shorten encoding of version features Signed-off-by: Dave Rodgman --- scripts/data_files/version_features.fmt | 6 ++++++ scripts/generate_features.pl | 11 +++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/scripts/data_files/version_features.fmt b/scripts/data_files/version_features.fmt index d3217a1910..0e40597601 100644 --- a/scripts/data_files/version_features.fmt +++ b/scripts/data_files/version_features.fmt @@ -44,6 +44,12 @@ int mbedtls_version_check_feature(const char *feature) return -1; } + if (strncmp(feature, "MBEDTLS_", 8)) { + return -1; + } + + feature += 8; + while (*idx != NULL) { if (!strcmp(*idx, feature)) { return 0; diff --git a/scripts/generate_features.pl b/scripts/generate_features.pl index b99c637c5b..f6809513c4 100755 --- a/scripts/generate_features.pl +++ b/scripts/generate_features.pl @@ -66,11 +66,14 @@ while (my $line = ) $in_section = 0; next; } - - my ($define) = $line =~ /#define (\w+)/; - $feature_defines .= "#if defined(${define})\n"; + # Strip leading MBEDTLS_ to save binary size + my ($mbedtls_prefix, $define) = $line =~ /#define (MBEDTLS_)?(\w+)/; + if (!$mbedtls_prefix) { + die "Feature does not start with 'MBEDTLS_': $line\n"; + } + $feature_defines .= "#if defined(MBEDTLS_${define})\n"; $feature_defines .= " \"${define}\",\n"; - $feature_defines .= "#endif /* ${define} */\n"; + $feature_defines .= "#endif /* MBEDTLS_${define} */\n"; } if (!$in_section) {