-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
compilation error when using MBEDTLS_PLATFORM_CALLOC_MACRO and MBEDTLS_PLATFORM_C #1642
Comments
ARM Internal Ref: IOTSSL-2312 |
Where does
come from? It says it's platform.c L54 but this line instead is:
@RonEld Can you clarify and show how to reproduce this? The current steps to reproduce have a typo, and I cannot guess what was originally meant. |
@hanno-arm, I'm not OP but I have run into the same issue. Also, void * (*mbedtls_calloc)( size_t, size_t ) = MBEDTLS_PLATFORM_STD_CALLOC; is from an older version of mbedtls. The problem is this: #if defined(MBEDTLS_PLATFORM_FREE_MACRO) &&\
( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
#error "MBEDTLS_PLATFORM_FREE_MACRO defined, but not all prerequisites"
#endif
#if defined(MBEDTLS_PLATFORM_CALLOC_MACRO) &&\
( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
#error "MBEDTLS_PLATFORM_CALLOC_MACRO defined, but not all prerequisites"
#endif So if you do this, in platform.h this does what you expect: #define mbedtls_free MBEDTLS_PLATFORM_FREE_MACRO
#define mbedtls_calloc MBEDTLS_PLATFORM_CALLOC_MACRO But in platform.c, you do not get what you expect: static void * (*mbedtls_calloc_func)( size_t, size_t ) = MBEDTLS_PLATFORM_STD_CALLOC;
static void (*mbedtls_free_func)( void * ) = MBEDTLS_PLATFORM_STD_FREE;
void * mbedtls_calloc( size_t nmemb, size_t size )
{
return (*mbedtls_calloc_func)( nmemb, size );
}
void mbedtls_free( void * ptr )
{
(*mbedtls_free_func)( ptr );
}
int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
void (*free_func)( void * ) )
{
mbedtls_calloc_func = calloc_func;
mbedtls_free_func = free_func;
return( 0 );
} and therein lies the conflict. You get a macro, yet the functions are still there, you get previous declaration errors and redeclared errors. So the steps to reproduce are try to use |
@upbeat27 Thanks for the detailed information and for pointing out the recent code change. In fact, the line in question was changed in 7decfe8, but I think the issue is agnostic to that. @upbeat27 @RonEld It seems that the code in /*
* By default mbed TLS uses the system-provided calloc() and free().
* This allows different allocators (self-implemented or provided) to be
* provided to the platform abstraction layer.
*
* Enabling MBEDTLS_PLATFORM_MEMORY without the
* MBEDTLS_PLATFORM_{FREE,CALLOC}_MACROs will provide
* "mbedtls_platform_set_calloc_free()" allowing you to set an alternative calloc() and
* free() function pointer at runtime.
*
* Enabling MBEDTLS_PLATFORM_MEMORY and specifying
* MBEDTLS_PLATFORM_{CALLOC,FREE}_MACROs will allow you to specify the
* alternate function at compile time.
*/ I will create a PR guarding the mentioned code in |
This commit removes the definition of the API function `mbedtls_platform_set_calloc_free()` from `library/platform.c` in case the macros `MBEDTLS_PLATFORM_CALLOC_MACRO` `MBEDTLS_PLATFORM_FREE_MACRO` for compile time configuration of calloc/free are set. This is in line with the corresponding header `mbedtls/platform.h` which declares `mbedtls_platform_set_calloc_free()` only if `MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO` are not defined. Fixes Mbed-TLS#1642.
This commit removes the definition of the API function `mbedtls_platform_set_calloc_free()` from `library/platform.c` in case the macros `MBEDTLS_PLATFORM_CALLOC_MACRO` `MBEDTLS_PLATFORM_FREE_MACRO` for compile time configuration of calloc/free are set. This is in line with the corresponding header `mbedtls/platform.h` which declares `mbedtls_platform_set_calloc_free()` only if `MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO` are not defined. Fixes Mbed-TLS#1642.
This commit removes the definition of the API function `mbedtls_platform_set_calloc_free()` from `library/platform.c` in case the macros `MBEDTLS_PLATFORM_CALLOC_MACRO` `MBEDTLS_PLATFORM_FREE_MACRO` for compile time configuration of calloc/free are set. This is in line with the corresponding header `mbedtls/platform.h` which declares `mbedtls_platform_set_calloc_free()` only if `MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO` are not defined. Fixes Mbed-TLS#1642.
Closing this issue, as the OP, @dhhome2006 submitted the same issue in #1706 |
Description
Rasied by Eric Tung by Email
Bug
OS
linux|windows|
mbed TLS build:
Version: development branch
Configuration: define
MBEDTLS_PLATFORM_CALLOC_MACRO
,MBEDTLS_PLATFORM_FREE_MACRO
andMBEDTLS_PLATFORM_C
Expected behavior
compilation to succeed
Actual behavior
compilation error:
Windows:
Linux:
Steps to reproduce
define
MBEDTLS_PLATFORM_CALLOC_MACRO
andMBEDTLS_PLATFORM_CALLOC_MACRO
as the default macros.*Although this is not the regular use, as platform calloc and free should be used when no platform calloc \ free are available, there shouldn't be a compilation error, or at least update documentation accordingly
The text was updated successfully, but these errors were encountered: