This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
smaller ramsize for newlib-nano builds
- From: "Jaap de Wolff" <info at jasoon dot nl>
- To: <newlib at sourceware dot org>
- Date: Wed, 31 Jan 2018 17:50:27 +0100
- Subject: smaller ramsize for newlib-nano builds
- Authentication-results: sourceware.org; auth=none
Hello,
I am working with embedded systems with have very limited ram resources.
As known current version of the newlib-nano build uses 364 bytes of ram for
__global_locale
When configured with
CFLAGS_FOR_TARGET='-Os -ffunction-sections -fdata-sections
-D_NANO_NO_GLOBAL_LOCALE'
and the following modification below I was able to move __global_locale to
rom.
I realize that MB_CAPABLE must be off for this modification, but are there
other implications?
Jaap
====================================== start of modification
=======================================================
diff -Nuar newlib.nor/newlib/libc/locale/locale.c
newlib/newlib/libc/locale/locale.c
--- newlib.nor/newlib/libc/locale/locale.c 2017-03-14
21:30:33.000000000 +0100
+++ newlib/newlib/libc/locale/locale.c 2018-01-31 13:32:25.580898000 +0100
@@ -255,7 +255,11 @@
};
#endif /* _MB_CAPABLE */
+#ifdef _NANO_CONST_GLOBAL_LOCALE
+const struct __locale_t __global_locale =
+#else
struct __locale_t __global_locale =
+#endif
{
{ "C", "C", DEFAULT_LOCALE, "C", "C", "C", "C", },
#ifdef __CYGWIN__
diff -Nuar newlib.nor/newlib/libc/locale/setlocale.h
newlib/newlib/libc/locale/setlocale.h
--- newlib.nor/newlib/libc/locale/setlocale.h 2016-11-28
19:32:45.000000000 +0100
+++ newlib/newlib/libc/locale/setlocale.h 2018-01-31
14:31:39.760898000 +0100
@@ -206,10 +206,18 @@
/* In POSIX terms the global locale is the process-wide locale. Use this
function to always refer to the global locale. */
+#ifdef _NANO_CONST_GLOBAL_LOCALE
+_ELIDABLE_INLINE const struct __locale_t *
+#else
_ELIDABLE_INLINE struct __locale_t *
+#endif
__get_global_locale ()
{
+#ifdef _NANO_CONST_GLOBAL_LOCALE
+ extern const struct __locale_t __global_locale;
+#else
extern struct __locale_t __global_locale;
+#endif
return &__global_locale;
}
====================================== end of modification
=======================================================