Flag to disable wchar support

Federico Terraneo fede.tft@hotmail.it
Tue Feb 23 19:45:00 GMT 2010


Jeff Johnston wrote:
>> Federico Terraneo wrote:
>>> Hi,
>>> I've been using newlib + libstdc++ for quite some time compiled with
>>> "--target=arm-elf", but I'm switching to "--target=arm-eabi" for
>>> better support of new Cortex M3 microcontrollers.
>>>
>>> However, this change caused a large code size increase in C++ code
>>> (see below), and the problem seems related to newlib.
>>> In practice, compiling newlib 1.18.0 with "--target=arm-eabi" causes
>>> the inclusion of some new functions to support wide charactes, like
>>> wprintf and wscanf (for the full list see below), and this triggers
>>> libstdc++ into including support for wide characters in iostream code,
>>> which is what causes the code size increase.
>>>
> 
> Newlib is a library of functions that are brought in if referenced.  The 
> ar displayed below is for libc.a.  The size of libc.a is meaningless for 
> a statically linked application.  You need to determine what library 
> functions are being brought in to the application and from where.  There 
> are some inter-library references (i.e. some library functions get 
> dragged in by others), but this will not change across the 
> configurations you have mentioned for the same newlib.
> 
> If libstdc++ for arm-eabi calls a wchar function and for arm-elf it 
> doesn't, that is not newlib's fault.

The code size increase is entirely in the functions/classes from 
libstdc++. The problem is that libstdc++'s configure script contains 
something like this:

if(C_standard_library_has_wchar_support)
{
   use full and large implementation for iostream
} else {
   use lightweight implementation for iostream
}

That's why the recent addition of wchar support in newlib results in 
code size increase for iostream code.

> 
>>> So I'm asking these two questions:
>>> 1) Is it "normal" that these additional functions are included only
>>> with "--target=arm-eabi" and not with "--target=arm-elf"?
> 
> No.  They are not under configuration triplet control.  If you use ELIX 
> level 3, you can remove some of them from the library.  I just noticed 
> there looks like a bug in the Makefile.am which includes a few ELIX 4 
> (also the default) items via additional objects regardless of the ELIX 
> level.
> 
> Places to look for configuration differences in newlib is the 
> configure.host file and in the libc/include/sys/config.h file.
> 

Thanks, that was what I needed to know.
Given that newlib does not have a way to disable those functions, I 
tried to solve the problem the other way around: find a configure option 
in libstdc++ to force-disable wchar support, and succeeded.
The option is called "--disable-wchar_t" and it can be passed to gcc's 
configure that will pass it on to libstdc++.

With this option added, code size is the same as before.
Problem fixed.



More information about the Newlib mailing list