This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Constructor ordering for memory pools vs. stdio
- From: Barry Wealand <barry dot wealand at lmco dot com>
- To: eCos Discussion <ecos-discuss at ecos dot sourceware dot org>
- Cc: "Mills, Ted" <ted dot mills at lmco dot com>
- Date: Tue, 08 Nov 2005 14:15:22 +0000
- Subject: [ECOS] Constructor ordering for memory pools vs. stdio
Hello -
We're using eCos 2.0 with a MIPS-like target. We're building eCos with
GCC 4.0.0 (in case that matters). In an effort to locate a problem with
memory getting trashed, I built a couple of applications against a
kernel with assertions enabled. Now, when these apps are executed, an
assertion failure occurs very quickly:
<5> stream.cxx[585] Cyg_ErrNo Cyg_StdioStream::write Stream object is
not a valid stream!
Working backward from there, the problem comes about because
Cyg_StdioStream::initialize() does not finish and place the expected
value in "magic_validity_word". Walking through the code with GDB, I
see that the constructor call, Cyg_StdioStream::Cyg_StdioStream(),
invokes a member constructor to set up an internal memory buffer. This
constructor fails due to malloc() returning NULL. On further
inspection, the memory pool upon which malloc depends has not yet been
set up. And, indeed, looking at the constructor table in section
.ctors, and with the understanding that cyg_hal_invoke_constructors()
works through this table from higher memory addresses down to lower
memory addresses, it seems that the constructor call for the memory pool
comes later than the constructor call that sets up the stdio streams.
And yet, I see (in malloc.cxx) that
CYGBLD_ATTRIB_INIT_BEFORE(CYG_INIT_LIBC) is being used to (seemingly)
specify that the memory pool constructor gets called before the libc
constructors (which presumably includes the stdio constructors). On the
surface, anyway, this seems to be a contradiction.
Am I missing something here? Should the memory pool constructor be
getting called before the stream constructor?
Thanks for your help!
Barry Wealand
barry.wealand@lmco.com
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss