Tornado Reference : Tornado Utilities

munch

NAME

munch - extract initializers and finalizers from C++ object modules

SYNOPSIS

wtxtcl $WIND_BASE/host/src/hutils/munch.tcl [-asm arch]

DESCRIPTION

This tool produces data structures used to call constructors and destructors for static objects. It is used when compiling C++ modules.

Given an ordered list of C++ object modules, munch produces a C program containing Ctors/Dtors arrays where the initialization order is the one promised below.

The modules should be ordered on the command line so that a.o is to the left of b.o if any initializers that appear in a.o but in no module to the right of a.o should be called before any initializers in b.o. Notice that each initializer is called only once (in its rightmost position) even though it may appear in more than one module. Finalizers are run in the reverse order.

If you are using a GNU compiler you should invoke munch with the -asm flag. This causes munch to output assembly directives which can be compiled without any special flags. On the other hand, if you do not supply the -asm flag the compiler may have to be coerced into accepting non-standard characters in identifiers (such as $). On GNU compilers this is achieved with the -fdollars-in-identifiers option.

EXAMPLES

Consider a project consisting of two C++ modules, user1.o and user2.o, linked with a user library myLib.a and a vxWorks library (say libMC68040gnuvx.a). Then the ctors file can be generated using:

Windows

nm68k partialImage.o partialUserImage.o user1.o user2.o \
      | wtxtcl %WIND_BASE%\host\src\hutils\munch.tcl -asm 68k > ctdt.c

UNIX

nm68k partialImage.o partialUserImage.o user1.o user2.o \
      | wtxtcl $WIND_BASE/host/src/hutils/munch.tcl -asm 68k > ctdt.c
Here partialUserImage.o is the result of linking user1.o and user2.o against myLib.a and partialImage.o is the result of linking partialUserImage.o against libMC68040gnuvx.a.

This will ensure that the VxWorks library is initialized before the user library which in turn is initialized before any of the project modules. The latter are initialized in the order they appear on the command line.

The following commands will compile "hello.cpp", then munch "hello.o", resulting in the munched file "hello.out", suitable for loading by the Tornado module loader:

Windows

   cc68k -I%WIND_BASE%\target\h -DCPU=MC68020 -nostdinc -fno-builtin -c hello.cpp
   nm68k hello.o | wtxtcl %WIND_BASE%\host\src\hutils\munch.tcl -asm 68k > ctdt.c
   cc68k -c ctdt.c
   ld68k -r -o hello.out hello.o ctdt.o

UNIX

  cc68k -I$WIND_BASE/target/h -DCPU=MC68020 -nostdinc -fno-builtin -c hello.cpp
  nm68k hello.o | wtxtcl $WIND_BASE/host/src/hutils/munch.tcl -asm 68k > ctdt.c
  cc68k -c ctdt.c
  ld68k -r -o hello.out hello.o ctdt.o

SEE ALSO

munch