On 25 June 2015 at 17:00, Yuxin Ren wrote: > Hi, > > I have read the docs about how to port the libstdc++ and I know more > about it now. > But in the docs, it does not talk much about the thread/mutex stuff. > My system has thread and locking support, so how can I change the > library to use our own mechanism? You don't change the library, you provide a gthread interface. > I find gcc uses some gthread_* stuff. How does gthread_* functions > interact with libsupc++ and libgcc? gthr.h is a wrapper layer that provides a common API similar to Pthreads. If you want to support C++ threading (which is not essential, you could configure your GCC with --disable-threads) then you need to provide a gthr.h header using your OS's synchronization primitives. Then most of libstdc++ should just work. See the comments in libgcc/gthr.h for what is needed. > I have two more questions. > 1. Does libsupc++ have dependency on other parts of gcc? And can I > make libsupc++ a standalone library? It depends on libgcc for stack unwinding, and libc for things like malloc. You can't really make it much more standalone. You might also need to port libatomic for your architecture, if it isn't supported already. > 2. The entire libstdc++ library is too huge for me now. I only need a > few classes in the STL. Can I only port only a few classes in > libstdc++? You don't need to port them, most of them are entirely platform independent. Nothing in std::vector depends on the OS, for example. You only need to port the locale stuff (which might not be necessary if you use e.g. newlib for your C library) and some atomics stuff (which isn't needed if you disable threading or if you implement the __atomic compiler built-ins for your target). A year ago support for a new target was added to libstdc++ and these are the only files that changed: * acinclude.m4 (*-*-dragonfly*): New target. * configure: Regenerate. * configure.host (*-*-dragonfly*): New target. * config/locale/dragonfly/c_locale.cc: New. * config/locale/dragonfly/ctype_members.cc: New. * config/os/bsd/dragonfly/ctype_base.h: New. * config/os/bsd/dragonfly/ctype_configure_char.cc: New. * config/os/bsd/dragonfly/ctype_inline.h: New. * config/os/bsd/dragonfly/os_defines.h: New. Admittedly the OS (Dragonfly BSD) was very similar to some existing targets, but in theory you shouldn't need to change many more files than that. (There were also other changes needed in libgcc and other parts of the compiler.)