libstdc++ for eCos ARM7
This is work-in-progress intended only for testing purposes.
Download binaries
Precompiled CygWin arm-elf toolchain is available for download here:
| POSIX multithreaded exception handling | gcc-arm-cygwin-3.4.3.zip |
Configuring eCos for use with libstdc++
eCos must be configured to be compatible with libstdc++. In other words, it needs the POSIX
compatibility layer. See test.ecm in example below.
Compiling eCos test program
$ ecosconfig new eb40a
$ ecosconfig import test.ecm
$ ecosconfig tree
$ arm-elf-g++ -Iinstall/include/ -g -Linstall/lib -Ttarget.ld hello.cxx -nostdlib -lstdc++
Background
eCos does not ship with STL support out of the box. However, these latest attempts
at getting libstdc++ to work have been fairly successful with a minimum of ugly hacks and tweaks.
The instructions below are based on
http://ecos.sourceware.org/build-toolchain.html.
C++ multithreaded exception handling
The toolchain above is compiled with POSIX multithreaded exception handling. This means that
multithreaded exceptions should work under eCos.
Building GCC
These instructions are incomplete. Consider them working
notes. Once all the problems have been solved,
a build script that can be used by mortals.
You should know how to compile a basic GCC toolchain before
attempting this.
- Download source for GCC(3.4.4), newlib(1.13.0) and binutils(2.16.1).
- Use eCos repository from CVS HEAD.
- Untar source code
$ tar -xjvf binutils-2.16.1.tar.bz2
$ tar -xjvf gcc-3.4.4.tar.bz2
$ tar -xjzf newlib-1.13.0.tar.gz
- Copy newlib & libgloss into GCC source dir
- Compile binutils
$ mkdir build
$ cd build
$ ../src/binutils-2.16.1/configure --target=arm-elf --prefix=`pwd`/../install
$ make
$ make install
$ cd ..
- Add the fresh binutils to the FRONT of the path
$ export PATH=`pwd`/install/bin:$PATH
- Create eCos header files
$ mkdir ecos
$ cd ecos
# eb40a is just an arbitary ARM7 target.
$ ecosconfig new eb40a default
$ ecosconfig add posix
$ ecosconfig add fileio
- Also change ecos.ecc to:
cdl_option CYGPKG_LIBC_I18N_NEWLIB_CTYPE {
user_value 1
};
- Build eCos headers:
$ ecosconfig tree
$ make headers
$ cd ..
- Build GCC
$ mkdir gccbuild
$ cd gccbuild
$ ../gcc-3.4.4/configure --target=arm-elf --prefix=`pwd`/../install --enable-languages=c,c++ --with-gnu-as --with-gnu-ld --with-newlib --enable-threads=posix --without-headers --enable-libstdcxx-allocator=malloc --enable-cstdio=stdio --disable-shared
$ make
$ make install
$ cd ..
- GCC will fail to compile libstdc++ as configured above, because it does not find the
POSIX pthreads include files. The solution is to replace
the newlib include files with the eCos include files when compiling libstdc++.
NB! Beware of multilib problems—for example, the below thumb. You must copy the eCos include files into
every multilib directory combination.
$ mkdir -p arm-elf/newlib/targ-include
# timestamp to stop newlib overwriting our files
$ cp -r ../ecos/install/include/* arm-elf/newlib/targ-include/
$ mkdir -p arm-elf/newlib/stmp-targ-include
$ mkdir -p arm-elf/thumb/newlib/targ-include
# timestamp to stop newlib overwriting our files
$ cp -r ../ecos/install/include/* arm-elf/thumb/newlib/targ-include/
$ mkdir -p arm-elf/thumb/newlib/stmp-targ-include
- More kludges:
- When compilation fails, modify arm-elf/thumb/libstdc++-v3/config.h &
arm-elf/libstdc++-v3/config.h: #undef HAVE_STRTOF
- _NEWLIB_VERSION have not been defined by the eCos include files and hence
testsuite_hooks.cc fails. Modify testsuite_hooks.cc and continue.
Future work
- Would it be possible to make a faux-newlib+libgloss module that
redirects to eCos instead of fudging the include files?
- Add mutex support to handle concurrency issues in libstdc++.
Tips