RE: global objects order-of-construction & order-of-destruction

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux