This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: global objects order-of-construction & order-of-destruction
- From: "Rupert Wood" <me at rupey dot net>
- To: "'John Love-Jensen'" <eljay at adobe dot com>
- Cc: "'MSX to GCC'" <gcc-help at gcc dot gnu dot org>
- Date: Thu, 17 Aug 2006 18:02:59 +0100
- Subject: RE: global objects order-of-construction & order-of-destruction
- References: <C109E17C.148E9%eljay@adobe.com>
John Love-Jensen wrote:
> Hence, compiler error flag on global object? Or warning flag? Or
> some interesting use of nm and grep?
Not a very elegant solution, but at first glance global objects with
non-trivial constructors or destructors generate:
- a local symbol containing string
'__static_initialization_and_destruction'
- a .ctors segment
- a call to __cxa_atexit for the destructor
(on Linux at least) so you could nm your object files for the symbol names
and objdump -h to look for .ctors segments. I expect the last two will be
system dependent but the first one looks like it's common across all g++:
that string is defined as SSDF_IDENTIFIER in gcc/cp/decl2.c.
It's probably easy to add your own warning to G++ if you know where to look.
At first glance I'd say it'd be by the call to expand_static_init in
cp_finish_decl in gcc/cp/decl.c. But I'm out of my depth here really.
Rup.