Flag to disable wchar support

Jeff Johnston jjohnstn@redhat.com
Mon Feb 22 21:26:00 GMT 2010


On 21/02/10 07:06 AM, Federico Terraneo wrote:
> Sorry to bother you, but got no answer on this, so I'm trying to ask the
> same question again. Hope it is allowed by the mailing list policy.
>

No problem.

> 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.

>> 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.

>> 2) Is there a way to disable wide character support?
>> I've tried "--disable-newlib-mb" but it didn't work.
>>

Have you confirmed that --disable-newlib-mb did not work?  If you look 
at the newlib.h header file you create in your build/arm-*/newlib 
directory, the value _MB_CAPABLE should be #undef'd out.  The option 
does not remove the wchar functions, it simply makes them smaller since 
they don't have to do any real work (e.g. converting from mb to wchar is 
simple if all characters are single-byte).  You can still reference the 
functions and if you do, the smaller versions get dragged in.

-- Jeff J.

>> For now I've temporarily fixed the problem by downgrading t
o newlib
>> 1.17.0 since it does not have these new functions and code size
>> returned at acceptable levels, but I'd like to stay up to date with
>> the latest newlib.
>>
>> -------------------------------------------------------
>>
>> An example program to show the difference in code size between arm-elf
>> and arm-eabi
>>
>> #include <iostream>
>> using namespace std;
>>
>> int main()
>> {
>> cout<<"Hello world"<<endl;
>> string line;
>> getline(cin,line);
>> cout<<line;
>> }
>>
>> arm-elf-g++ -mcpu=arm7tdmi -g -O0 -c arm_test.cpp
>> arm-elf-g++ -mcpu=arm7tdmi -o arm_test arm_test.o
>> arm-elf-size arm_test
>> text data bss dec hex filename
>> 368320 2648 3880 374848 5b840 arm_test
>>
>> arm-eabi-g++ -mcpu=arm7tdmi -g -O0 -c arm_test.cpp
>> arm-eabi-g++ -mcpu=arm7tdmi -o arm_test arm_test.o
>> arm-eabi-size arm_test
>> text data bss dec hex filename
>> 504292 2756 7468 514516 7d9d4 arm_test
>>
>> -------------------------------------------------------
>>
>> The list of functions that are present only when compiling with
>> "--target=arm-elf"
>>
>> $ arm-eabi-ar -t /opt/arm-eabi/arm-eabi/lib/libc.a | sort >
>> ~/libc-eabi.txt
>> $ arm-elf-ar -t /opt/arm-elf/arm-elf/lib/libc.a | sort > ~/libc-elf.txt
>> $ diff -U 0 libc-elf.txt libc-eabi.txt
>> --- libc-elf.txt 2010-02-07 11:22:50.000000000 +0100
>> +++ libc-eabi.txt 2010-02-07 11:22:41.000000000 +0100
>> @@ -99,0 +100 @@
>> +lib_a-fpurge.o
>> @@ -117,0 +119 @@
>> +lib_a-fwprintf.o
>> @@ -118,0 +121 @@
>> +lib_a-fwscanf.o
>> @@ -211,0 +215 @@
>> +lib_a-mbsnrtowcs.o
>> @@ -224,0 +229 @@
>> +lib_a-mkdirr.o
>> @@ -269,0 +275 @@
>> +lib_a-sb_charsets.o
>> @@ -283,0 +290 @@
>> +lib_a-sf_fpclassify.o
>> @@ -292,0 +300 @@
>> +lib_a-s_fpclassify.o
>> @@ -350,0 +359 @@
>> +lib_a-strtold.o
>> @@ -360,0 +370,2 @@
>> +lib_a-svfiwprintf.o
>> +lib_a-svfiwscanf.o
>> @@ -362,0 +374,2 @@
>> +lib_a-svfwprintf.o
>> +lib_a-svfwscanf.o
>> @@ -363,0 +377,2 @@
>> +lib_a-swprintf.o
>> +lib_a-swscanf.o
>> @@ -395 +409,0 @@
>> -lib_a-_tolower.o
>> @@ -397 +410,0 @@
>> -lib_a-_toupper.o
>> @@ -423,0 +437,2 @@
>> +lib_a-vfiwprintf.o
>> +lib_a-vfiwscanf.o
>> @@ -425,0 +441,2 @@
>> +lib_a-vfwprintf.o
>> +lib_a-vfwscanf.o
>> @@ -435,0 +453,4 @@
>> +lib_a-vswprintf.o
>> +lib_a-vswscanf.o
>> +lib_a-vwprintf.o
>> +lib_a-vwscanf.o
>> @@ -439,0 +461 @@
>> +lib_a-wcscasecmp.o
>> @@ -445,0 +468,2 @@
>> +lib_a-wcsdup.o
>> +lib_a-wcsftime.o
>> @@ -448,0 +473 @@
>> +lib_a-wcsncasecmp.o
>> @@ -452,0 +478 @@
>> +lib_a-wcsnrtombs.o
>> @@ -457,0 +484 @@
>> +lib_a-wcstod.o
>> @@ -458,0 +486 @@
>> +lib_a-wcstold.o
>> @@ -479,0 +508 @@
>> +lib_a-wprintf.o
>> @@ -480,0 +510 @@
>> +lib_a-wscanf.o
>>
>>
>>
>



More information about the Newlib mailing list