[uClinux-dev] C++ code size problem

Van Rafelghem, Dominique VanRafelghemD at intheairnet.com
Fri Mar 21 12:51:04 EST 2003


Hi, 

I am currently writing some code to check out uClinux on a ColdFire
processor.  The test platform I am using is the Motorola M5272C3 demo board.
I am using the uClinux-dist-20030305.tar.gz kernel and the
m68k-elf-tools-20030314.  One change I've made to the uClinux configuration
is to allow wide characters as I was getting compilation problems with my
C++ code when I didn't have wide characters turned on in the uClibc
configuration.

I wrote a simple C++ programs that instantiates a class and uses an STL
vector container class.  The code size jumps tremendously when I include the
STL stuff.  But when I add a cout statement using the iostreams header file
the code size of my application jumps from ~ 100 kbytes to ~400 kbytes.
This is a huge jump in code size and unfortunately I can't run this on the
demo board as it crashes complaining that it doesn't have enough memory.

The following is a my build script that I am using to build the application:
# script start
m68k-elf-g++ -m5307 -DCONFIG_COLDFIRE -Os -g -fomit-frame-pointer -m5307
-DCONFIG_COLDFIRE  -Dlinux -D__linux__ -Dunix -D__uClinux__ -DEMBED \
-I/home/VanRafelghemD/uClinux-20030305/uClinux-dist/lib/uClibc/include \
-I/home/VanRafelghemD/uClinux-20030305/uClinux-dist/lib/libm \
-I/home/VanRafelghemD/uClinux-20030305/uClinux-dist/lib/libcrypt_old \
-I/home/VanRafelghemD/uClinux-20030305/uClinux-dist -fno-builtin -msep-data
\
-I/home/VanRafelghemD/uClinux-20030305/uClinux-dist/linux-2.4.x/include
-c -o testapp.o testapp.cpp

m68k-elf-strip --strip-debug testapp.o

m68k-elf-g++ -m5307 -DCONFIG_COLDFIRE -Os -g -fomit-frame-pointer -m5307
-DCONFIG_COLDFIRE  -Dlinux -D__linux__ -Dunix -D__uClinux__ -DEMBED \
-I/home/VanRafelghemD/uClinux-20030305/uClinux-dist/lib/uClibc/include \
-I/home/VanRafelghemD/uClinux-20030305/uClinux-dist/lib/libm \
-I/home/VanRafelghemD/uClinux-20030305/uClinux-dist/lib/libcrypt_old \
-I/home/VanRafelghemD/uClinux-20030305/uClinux-dist \
-fno-builtin -msep-data
-I/home/VanRafelghemD/uClinux-20030305/uClinux-dist/linux-2.4.x/include \
-mapcs-26 -Wl,-elf2flt -Wl,-move-rodata -nostartfiles
/home/VanRafelghemD/uClinux-20030305/uClinux-dist/lib/uClibc/lib/crt0.o \
-o testapp testapp.o -lc -lgcc
#script end

This is the code I am compiling:

// start C++ code
//#include <iostream>
#include <vector>
#include <stdio.h>

using namespace std;


class Test
{
	public:
		Test(int TestNo);
		int storeTestNo(void);
		~Test();
	private:
		std::vector<int> v;
		int m_TestNo;
};

Test::Test(int TestNo) : m_TestNo(TestNo)
{
	printf("Test no %d, constructed\n", m_TestNo);
	v.reserve(80);
}

Test::~Test()
{
	printf("Test no %d, destroyed\n", m_TestNo);
}

int Test::storeTestNo(void)
{
	v.push_back(m_TestNo);
	printf("Test no %d stored in v\n", m_TestNo);
	return v.size();
}

int main(void)
{
	Test * Testp = new Test(1);
	int size = Testp->storeTestNo();
	printf("vector size is %d\n", size);
//	cout << "cool" << endl;
	delete Testp;
}

// end C++ code

This code snippet has the cout and iostream header file commented out.  As
is this application will be ~100 kbytes which is huge for what it does.  But
when you remove the comments from the iostream header and the cout statement
the code size jumps to 400 kbytes.  When I compile the same code on my linux
box using gcc the code size of the non-cout file is 25 kbytes, with cout the
code size is 26 kbytes.  Does anyone have any idea why the m68k-elf-g++ code
is so large and is there any way to reduce this code size?  Any help with
this would be greatly appreciated.

Dominique
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.uclinux.org/pipermail/uclinux-dev/attachments/20030321/d05fcac1/attachment.html>


More information about the uClinux-dev mailing list