Skip to content

Minimal-printf: Fix wrapping of printf functions for the ARM compiler #12238

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

Merged
merged 1 commit into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions platform/source/minimal-printf/mbed_printf_armlink_overrides.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,34 @@ int $Sub$$__2snprintf(char *buffer, size_t length, const char *format, ...)
return result;
}

int $Sub$$__2vprintf(char *buffer, const char *format, ...)
int $Sub$$__2vprintf(const char *format, va_list arguments)
{
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stdout);
}

int $Sub$$__2vsprintf(char *buffer, const char *format, va_list arguments)
{
return mbed_minimal_formatted_string(buffer, LONG_MAX, format, arguments, NULL);
}

int $Sub$$__2vsnprintf(char *buffer, size_t length, const char *format, va_list arguments)
{
return mbed_minimal_formatted_string(buffer, length, format, arguments, NULL);
}

int $Sub$$__2fprintf(FILE *stream, const char *format, ...)
{
va_list arguments;
va_start(arguments, format);
int result = mbed_minimal_formatted_string(buffer, LONG_MAX, format, arguments, stdout);
int result = mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stream);
va_end(arguments);

return result;
}

int $Sub$$__2vsnprintf(char *buffer, size_t length, const char *format, va_list arguments)
int $Sub$$__2vfprintf(FILE *stream, const char *format, va_list arguments)
{
return mbed_minimal_formatted_string(buffer, length, format, arguments, NULL);
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stream);
}

/**
Expand Down
55 changes: 12 additions & 43 deletions platform/source/minimal-printf/mbed_printf_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,15 @@
#include <limits.h>


#if defined(__GNUC__) /* GCC */
#define SUPER_PRINTF __real_printf
#define SUB_PRINTF __wrap_printf
#define SUPER_SPRINTF __real_sprintf
#define SUB_SPRINTF __wrap_sprintf
#define SUPER_SNPRINTF __real_snprintf
#define SUB_SNPRINTF __wrap_snprintf
#define SUPER_VPRINTF __real_vprintf
#define SUB_VPRINTF __wrap_vprintf
#define SUPER_VSPRINTF __real_vsprintf
#define SUB_VSPRINTF __wrap_vsprintf
#define SUPER_VSNPRINTF __real_vsnprintf
#define SUB_VSNPRINTF __wrap_vsnprintf
#define SUPER_FPRINTF __real_fprintf
#define SUB_FPRINTF __wrap_fprintf
#define SUPER_VFPRINTF __real_vfprintf
#define SUB_VFPRINTF __wrap_vfprintf
#elif defined(TOOLCHAIN_ARM) /* ARMC5/ARMC6 */\
|| defined(__ICCARM__) /* IAR */
#define SUPER_PRINTF $Super$$printf
#define SUB_PRINTF $Sub$$printf
#define SUPER_SPRINTF $Super$$sprintf
#define SUB_SPRINTF $Sub$$sprintf
#define SUPER_SNPRINTF $Super$$snprintf
#define SUB_SNPRINTF $Sub$$snprintf
#define SUPER_VPRINTF $Super$$vprintf
#define SUB_VPRINTF $Sub$$vprintf
#define SUPER_VSPRINTF $Super$$vsprintf
#define SUB_VSPRINTF $Sub$$vsprintf
#define SUPER_VSNPRINTF $Super$$vsnprintf
#define SUB_VSNPRINTF $Sub$$vsnprintf
#define SUPER_FPRINTF $Super$$fprintf
#define SUB_FPRINTF $Sub$$fprintf
#define SUPER_VFPRINTF $Super$$vfprintf
#define SUB_VFPRINTF $Sub$$vfprintf
#if defined(__ARMCC_VERSION) || defined(__ICCARM__)
# define PREFIX(x) $Sub$$##x
#elif defined(__GNUC__)
# define PREFIX(x) __wrap_##x
#else
#warning "This compiler is not yet supported."
#endif

int SUB_PRINTF(const char *format, ...)
int PREFIX(printf)(const char *format, ...)
{
va_list arguments;
va_start(arguments, format);
Expand All @@ -70,7 +39,7 @@ int SUB_PRINTF(const char *format, ...)
return result;
}

int SUB_SPRINTF(char *buffer, const char *format, ...)
int PREFIX(sprintf)(char *buffer, const char *format, ...)
{
va_list arguments;
va_start(arguments, format);
Expand All @@ -80,7 +49,7 @@ int SUB_SPRINTF(char *buffer, const char *format, ...)
return result;
}

int SUB_SNPRINTF(char *buffer, size_t length, const char *format, ...)
int PREFIX(snprintf)(char *buffer, size_t length, const char *format, ...)
{
va_list arguments;
va_start(arguments, format);
Expand All @@ -90,22 +59,22 @@ int SUB_SNPRINTF(char *buffer, size_t length, const char *format, ...)
return result;
}

int SUB_VPRINTF(const char *format, va_list arguments)
int PREFIX(vprintf)(const char *format, va_list arguments)
{
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stdout);
}

int SUB_VSPRINTF(char *buffer, const char *format, va_list arguments)
int PREFIX(vsprintf)(char *buffer, const char *format, va_list arguments)
{
return mbed_minimal_formatted_string(buffer, LONG_MAX, format, arguments, NULL);
}

int SUB_VSNPRINTF(char *buffer, size_t length, const char *format, va_list arguments)
int PREFIX(vsnprintf)(char *buffer, size_t length, const char *format, va_list arguments)
{
return mbed_minimal_formatted_string(buffer, length, format, arguments, NULL);
}

int SUB_FPRINTF(FILE *stream, const char *format, ...)
int PREFIX(fprintf)(FILE *stream, const char *format, ...)
{
va_list arguments;
va_start(arguments, format);
Expand All @@ -115,7 +84,7 @@ int SUB_FPRINTF(FILE *stream, const char *format, ...)
return result;
}

int SUB_VFPRINTF(FILE *stream, const char *format, va_list arguments)
int PREFIX(vfprintf)(FILE *stream, const char *format, va_list arguments)
{
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stream);
}
Expand Down