mirror of https://github.com/ARMmbed/mbed-os.git
Minimal-printf: Fix wrapping of printf functions for the ARM compiler
As the ARM compiler is in GNU compatible mode, it defines __GNU__ which (based on pre-processor condition in mbed_printf_implentation.h) causes the printf functions to be wrapped using _wrap_* instead of $Sub$$*. This commit modifies the pre-processor conditions to check for __GNUC__last in order to correctly substitute the printf functions depending on the toolchain in use. It also gets rid of $Super$$* substitution as it is not needed. $Super$$ is used to identify the original unpatched functions. Missing substitutions for ARM compiler internal optimized "printfs" are also added.pull/12238/head
parent
dc6320239b
commit
3b59f6ce4d
|
@ -66,14 +66,14 @@ 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)
|
||||
{
|
||||
va_list arguments;
|
||||
va_start(arguments, format);
|
||||
int result = mbed_minimal_formatted_string(buffer, LONG_MAX, format, arguments, stdout);
|
||||
va_end(arguments);
|
||||
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stdout);
|
||||
}
|
||||
|
||||
return result;
|
||||
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)
|
||||
|
@ -81,6 +81,21 @@ int $Sub$$__2vsnprintf(char *buffer, size_t length, const char *format, va_list
|
|||
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(NULL, LONG_MAX, format, arguments, stream);
|
||||
va_end(arguments);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int $Sub$$__2vfprintf(FILE *stream, const char *format, va_list arguments)
|
||||
{
|
||||
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the built-in functions which the linker is unable to prune with dummy stubs
|
||||
* that take up less space.
|
||||
|
|
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue