Merge pull request #7775 from daverodgman/version_features_codesize

Shorten encoding of version features
This commit is contained in:
Gilles Peskine 2023-06-15 14:56:00 +02:00 committed by GitHub
commit 0fe0c0cf10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View file

@ -44,6 +44,12 @@ int mbedtls_version_check_feature(const char *feature)
return -1; return -1;
} }
if (strncmp(feature, "MBEDTLS_", 8)) {
return -1;
}
feature += 8;
while (*idx != NULL) { while (*idx != NULL) {
if (!strcmp(*idx, feature)) { if (!strcmp(*idx, feature)) {
return 0; return 0;

View file

@ -66,11 +66,14 @@ while (my $line = <CONFIG_H>)
$in_section = 0; $in_section = 0;
next; next;
} }
# Strip leading MBEDTLS_ to save binary size
my ($define) = $line =~ /#define (\w+)/; my ($mbedtls_prefix, $define) = $line =~ /#define (MBEDTLS_)?(\w+)/;
$feature_defines .= "#if defined(${define})\n"; if (!$mbedtls_prefix) {
$feature_defines .= " \"${define}\",\n"; die "Feature does not start with 'MBEDTLS_': $line\n";
$feature_defines .= "#endif /* ${define} */\n"; }
$feature_defines .= "#if defined(MBEDTLS_${define})\n";
$feature_defines .= " \"${define}\", //no-check-names\n";
$feature_defines .= "#endif /* MBEDTLS_${define} */\n";
} }
if (!$in_section) { if (!$in_section) {