Discussion:
[PATCH 3/3] Remove locale access for _REENT_SMALL
Anmin via newlib
2018-08-30 12:30:28 UTC
Permalink
From: Jaap de Wolff <info at jasoon dot nl>
Date: Fri, 16 Feb 2018 19:46:28 +0100
...
From: Corinna Vinschen <vinschen at redhat dot com>
Date: Mon, 19 Feb 2018 13:14:04 +0100
...I'd like to ask: Do you *really* want to get rid of __global_locale,
or are you just unhappy in terms of its size?  Note that I didn't
add any extra locale info to targets not defining __HAVE_LOCALE_INFO__....
Hi,
I'm using newlib-3.0.0 on an arm-none-eabi target
to build a very simple project (my/project/objs/str.o) with referring to <ctype.h>.

The linker map file says the objects are loaded because...
...
/opt/tool-chain/lib/gcc/arm-none-eabi/7.3.0/../../../../arm-none-eabi/lib/thumb/v8-m.main/libc.a(lib_a-locale.o)
                              ../my/project/objs/str.o (__locale_ctype_ptr)
/opt/tool-chain/lib/gcc/arm-none-eabi/7.3.0/../../../../arm-none-eabi/lib/thumb/v8-m.main/libc.a(lib_a-mbtowc_r.o)
                              /opt/tool-chain/lib/gcc/arm-none-eabi/7.3.0/../../../../arm-none-eabi/lib/thumb/v8-m.main/libc.a(lib_a-locale.o) (__ascii_mbtowc)
...
/opt/tool-chain/lib/gcc/arm-none-eabi/7.3.0/../../../../arm-none-eabi/lib/thumb/v8-m.main/libc.a(lib_a-wctomb_r.o)
                              /opt/tool-chain/lib/gcc/arm-none-eabi/7.3.0/../../../../arm-none-eabi/lib/thumb/v8-m.main/libc.a(lib_a-locale.o) (__ascii_wctomb)
/opt/tool-chain/lib/gcc/arm-none-eabi/7.3.0/../../../../arm-none-eabi/lib/thumb/v8-m.main/libc.a(lib_a-ctype_.o)
                              /opt/tool-chain/lib/gcc/arm-none-eabi/7.3.0/../../../../arm-none-eabi/lib/thumb/v8-m.main/libc.a(lib_a-locale.o) (_ctype_)
...
<


The very same project built to link with an old newlib have linked map file as
(supposedly an array of "ctype" property bitmaps)
...
/opt/tool-chain/lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/fpu/libc.a(lib_a-ctype_.o)
                              ../my/project/objs/str.o (__ctype_ptr__)
...
<

Is there any way, such as using "configure" options or defines while building newlib, or defining some macros when building project, to make my small and simple project (with "C" locale) not to link with those "locale" objects?

Thanks.

Best Regards,
Anmin Deng
Keith Packard
2018-08-31 03:41:51 UTC
Permalink
Post by Anmin via newlib
Is there any way, such as using "configure" options or defines while
building newlib, or defining some macros when building project, to
make my small and simple project (with "C" locale) not to link with
those "locale" objects?
I've got a long series of patches for newlib on arm-none-eabi that you
might be interested, and this is one of them.

diff --git a/newlib/libc/include/ctype.h b/newlib/libc/include/ctype.h
index f74b3499b..0e283afd6 100644
--- a/newlib/libc/include/ctype.h
+++ b/newlib/libc/include/ctype.h
@@ -66,7 +66,12 @@ extern int toascii_l (int __c, locale_t __l);
#define _X 0100
#define _B 0200

+#ifdef NEWLIB_DISABLE_LOCALE
+#define __locale_ctype_ptr() _ctype_
+#else
const char *__locale_ctype_ptr (void);
+#endif
+
# define __CTYPE_PTR (__locale_ctype_ptr ())

#ifndef __cplusplus

This doesn't actually set the NEWLIB_DISABLE_LOCALE define anywhere;
that's done in my 'meson' newlib configuration. You would have to hack
up something with CFLAGS to use this under autotools.

I'm still cleaning this series up before submitting the
upstream-relevant patches here, but if you want to take a look and see
what you think, the sources are available here:

https://salsa.debian.org/electronics-team/toolchains/newlib-nano

I've got a submission in the debian new queue for this, so it should
eventually be something you can just install.
--
-keith
Loading...