From 638dceb7e13b83ec4ccc17b985abcb76f13d62fb Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Wed, 3 Oct 2018 16:17:41 +0100 Subject: [PATCH 1/4] Change file scoping of test helpers.function Dependent on configured options, not all of the helper functions were being used, which was leading to warning of unused functions with Clang. To avoid any complex compile time options, or adding more logic to generate_test_code.py to screen out unused functions, those functions which were provoking the warning were changed to remove static, remove them from file scope, and expose them to the linker. --- tests/suites/helpers.function | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/suites/helpers.function b/tests/suites/helpers.function index eef41c79a..10125c34a 100644 --- a/tests/suites/helpers.function +++ b/tests/suites/helpers.function @@ -128,6 +128,14 @@ test_info; /*----------------------------------------------------------------------------*/ /* Helper Functions */ +void test_fail( const char *test, int line_no, const char* filename ) +{ + test_info.failed = 1; + test_info.test = test; + test_info.line_no = line_no; + test_info.filename = filename; +} + #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) static int redirect_output( FILE** out_stream, const char* path ) { @@ -170,7 +178,7 @@ static void close_output( FILE* out_stream ) } #endif /* __unix__ || __APPLE__ __MACH__ */ -static int unhexify( unsigned char *obuf, const char *ibuf ) +int unhexify( unsigned char *obuf, const char *ibuf ) { unsigned char c, c2; int len = strlen( ibuf ) / 2; @@ -204,7 +212,7 @@ static int unhexify( unsigned char *obuf, const char *ibuf ) return len; } -static void hexify( unsigned char *obuf, const unsigned char *ibuf, int len ) +void hexify( unsigned char *obuf, const unsigned char *ibuf, int len ) { unsigned char l, h; @@ -258,7 +266,7 @@ static unsigned char *zero_alloc( size_t len ) * * For convenience, dies if allocation fails. */ -static unsigned char *unhexify_alloc( const char *ibuf, size_t *olen ) +unsigned char *unhexify_alloc( const char *ibuf, size_t *olen ) { unsigned char *obuf; @@ -309,7 +317,7 @@ static int rnd_std_rand( void *rng_state, unsigned char *output, size_t len ) * * rng_state shall be NULL. */ -static int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len ) +int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len ) { if( rng_state != NULL ) rng_state = NULL; @@ -336,7 +344,7 @@ typedef struct * * After the buffer is empty it will return rand(); */ -static int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len ) +int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len ) { rnd_buf_info *info = (rnd_buf_info *) rng_state; size_t use_len; @@ -382,7 +390,7 @@ typedef struct * * rng_state shall be a pointer to a rnd_pseudo_info structure. */ -static int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len ) +int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len ) { rnd_pseudo_info *info = (rnd_pseudo_info *) rng_state; uint32_t i, *k, sum, delta=0x9E3779B9; From 032e3e215d5796394d14957052667a66ba301a39 Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Thu, 4 Oct 2018 12:26:55 +0100 Subject: [PATCH 2/4] Enable more compiler warnings in tests/Makefile tests/Makefile had some unused warnings disabled unnecessarily, which test-ref-configs.pl was turning back on. We don't need to disable these warnings so I'm turning them back on. --- tests/Makefile | 2 +- tests/suites/helpers.function | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index d85617fdc..839fd5ebf 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -3,7 +3,7 @@ # To compile with PKCS11: add "-lpkcs11-helper" to LDFLAGS CFLAGS ?= -O2 -WARNING_CFLAGS ?= -Wall -W -Wdeclaration-after-statement -Wno-unused-function -Wno-unused-value +WARNING_CFLAGS ?= -Wall -W -Wdeclaration-after-statement -Wunused LDFLAGS ?= LOCAL_CFLAGS = $(WARNING_CFLAGS) -I../include -D_FILE_OFFSET_BITS=64 diff --git a/tests/suites/helpers.function b/tests/suites/helpers.function index 10125c34a..1255714d4 100644 --- a/tests/suites/helpers.function +++ b/tests/suites/helpers.function @@ -424,10 +424,3 @@ int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len ) return( 0 ); } -static void test_fail( const char *test, int line_no, const char* filename ) -{ - test_info.failed = 1; - test_info.test = test; - test_info.line_no = line_no; - test_info.filename = filename; -} From 8f90278ef775af65a49266ff490b726eccbfb11e Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Fri, 28 Dec 2018 12:01:09 +0000 Subject: [PATCH 3/4] Add Changelog entry for clang test-ref-configs.pl fix --- ChangeLog | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index 661eb8251..4e69121d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ mbed TLS ChangeLog (Sorted per branch, date) += mbed TLS x.x.x branch released xxxx-xx-xx + +Bugfix + * Fix to allow test-ref-config.pl to build with Clang. Fixes #1628. + = mbed TLS 2.7.9 branch released 2018-12-21 Bugfix From 57f2f69ef49ac471a64486f2a3b500230c6b8d23 Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Thu, 18 Apr 2019 15:57:30 +0100 Subject: [PATCH 4/4] Clarify ChangeLog entry for fix to #1628 --- ChangeLog | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4e69121d0..30dc23f8f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,7 +3,8 @@ mbed TLS ChangeLog (Sorted per branch, date) = mbed TLS x.x.x branch released xxxx-xx-xx Bugfix - * Fix to allow test-ref-config.pl to build with Clang. Fixes #1628. + * Fix to allow building test suites with any warning that detects unused + functions. Fixes #1628. = mbed TLS 2.7.9 branch released 2018-12-21