diff --git a/lib/SConscript b/lib/SConscript index fb0473f8d..4e6171aba 100644 --- a/lib/SConscript +++ b/lib/SConscript @@ -43,6 +43,7 @@ libs = env.BuildModules( "ble_profile", "bit_lib", "datetime", + "ieee754_parse_wrap", ], ) diff --git a/lib/ieee754_parse_wrap/SConscript b/lib/ieee754_parse_wrap/SConscript new file mode 100644 index 000000000..dc60036e0 --- /dev/null +++ b/lib/ieee754_parse_wrap/SConscript @@ -0,0 +1,31 @@ +Import("env") + +wrapped_fn_list = [ + "strtof", + "strtod", +] + +for wrapped_fn in wrapped_fn_list: + env.Append( + LINKFLAGS=[ + "-Wl,--wrap," + wrapped_fn, + ] + ) + +env.Append( + SDK_HEADERS=[ + File("wrappers.h"), + ], + LINT_SOURCES=[ + Dir("."), + ], +) + +libenv = env.Clone(FW_LIB_NAME="ieee754_parse_wrap") +libenv.ApplyLibFlags() + +sources = libenv.GlobRecursive("*.c*", ".") + +lib = libenv.StaticLibrary("${FW_LIB_NAME}", sources) +libenv.Install("${LIB_DIST_DIR}", lib) +Return("lib") diff --git a/lib/ieee754_parse_wrap/wrappers.c b/lib/ieee754_parse_wrap/wrappers.c new file mode 100644 index 000000000..33bd38c35 --- /dev/null +++ b/lib/ieee754_parse_wrap/wrappers.c @@ -0,0 +1,14 @@ +#include "wrappers.h" + +// Based on the disassembly, providing NULL as `locale` is fine. +// The default `strtof` and `strtod` provided in the same libc_nano also just +// call these functions, but with an actual locale structure which was taking up +// lots of .data space (364 bytes). + +float __wrap_strtof(const char* in, char** tail) { + return strtof_l(in, tail, NULL); +} + +double __wrap_strtod(const char* in, char** tail) { + return strtod_l(in, tail, NULL); +} diff --git a/lib/ieee754_parse_wrap/wrappers.h b/lib/ieee754_parse_wrap/wrappers.h new file mode 100644 index 000000000..17e7acf83 --- /dev/null +++ b/lib/ieee754_parse_wrap/wrappers.h @@ -0,0 +1,14 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +float __wrap_strtof(const char* in, char** tail); +double __wrap_strtod(const char* in, char** tail); + +#ifdef __cplusplus +} +#endif diff --git a/targets/f18/api_symbols.csv b/targets/f18/api_symbols.csv index 583b3d87c..1d2d4e411 100644 --- a/targets/f18/api_symbols.csv +++ b/targets/f18/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,83.0,, +Version,+,82.2,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/bt/bt_service/bt_keys_storage.h,, Header,+,applications/services/cli/cli.h,, @@ -57,6 +57,7 @@ Header,+,lib/flipper_application/plugins/plugin_manager.h,, Header,+,lib/flipper_format/flipper_format.h,, Header,+,lib/flipper_format/flipper_format_i.h,, Header,+,lib/flipper_format/flipper_format_stream.h,, +Header,+,lib/ieee754_parse_wrap/wrappers.h,, Header,+,lib/libusb_stm32/inc/hid_usage_button.h,, Header,+,lib/libusb_stm32/inc/hid_usage_consumer.h,, Header,+,lib/libusb_stm32/inc/hid_usage_desktop.h,, @@ -382,6 +383,8 @@ Function,+,__wrap_putc,int,"int, FILE*" Function,+,__wrap_putchar,int,int Function,+,__wrap_puts,int,const char* Function,+,__wrap_snprintf,int,"char*, size_t, const char*, ..." +Function,+,__wrap_strtod,double,"const char*, char**" +Function,+,__wrap_strtof,float,"const char*, char**" Function,+,__wrap_ungetc,int,"int, FILE*" Function,+,__wrap_vsnprintf,int,"char*, size_t, const char*, va_list" Function,-,_asiprintf_r,int,"_reent*, char**, const char*, ..." diff --git a/targets/f18/target.json b/targets/f18/target.json index 3452c6707..1a8306596 100644 --- a/targets/f18/target.json +++ b/targets/f18/target.json @@ -36,7 +36,8 @@ "flipper18", "bit_lib", "toolbox", - "datetime" + "datetime", + "ieee754_parse_wrap" ], "excluded_sources": [ "furi_hal_infrared.c", diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv index c94a009ee..0d096c237 100755 --- a/targets/f7/api_symbols.csv +++ b/targets/f7/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,83.2,, +Version,+,82.2,, Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/bt/bt_service/bt_keys_storage.h,, @@ -62,6 +62,7 @@ Header,+,lib/flipper_format/flipper_format_stream.h,, Header,+,lib/ibutton/ibutton_key.h,, Header,+,lib/ibutton/ibutton_protocols.h,, Header,+,lib/ibutton/ibutton_worker.h,, +Header,+,lib/ieee754_parse_wrap/wrappers.h,, Header,+,lib/infrared/encoder_decoder/infrared.h,, Header,+,lib/infrared/worker/infrared_transmit.h,, Header,+,lib/infrared/worker/infrared_worker.h,, @@ -467,6 +468,8 @@ Function,+,__wrap_putc,int,"int, FILE*" Function,+,__wrap_putchar,int,int Function,+,__wrap_puts,int,const char* Function,+,__wrap_snprintf,int,"char*, size_t, const char*, ..." +Function,+,__wrap_strtod,double,"const char*, char**" +Function,+,__wrap_strtof,float,"const char*, char**" Function,+,__wrap_ungetc,int,"int, FILE*" Function,+,__wrap_vsnprintf,int,"char*, size_t, const char*, va_list" Function,-,_asiprintf_r,int,"_reent*, char**, const char*, ..." diff --git a/targets/f7/target.json b/targets/f7/target.json index f5b3cf3b6..911aa0822 100644 --- a/targets/f7/target.json +++ b/targets/f7/target.json @@ -50,6 +50,7 @@ "flipper7", "bit_lib", "toolbox", - "datetime" + "datetime", + "ieee754_parse_wrap" ] }