If your application has stringent requirements on code size for C programs, you might
want to eliminate all sources of overhead. This section describes how to reduce the
overhead of invoking the C++ constructor or destructor code in a C program that does not
require that code. You might be able to save approximately 220 bytes of code space by
making the following modifications:
- Follow the instructions for creating a custom copy of the startup files from the installation area, as described in the preceding sections. Specifically, copy over the particular versions of crtn.s and xcrtinit.s that suit your application. For example, if your application is being bootstrapped and profiled, copy crt2.s and pg-crtinit.s from the installation area.
- Modify pg-crtinit.s to remove the following
lines:
brlid r15, __init /* Invoke language initialization functions */ nop
and
brlid r15, __fini /* Invoke language cleanup functions */ nop
This avoids referencing the extra code usually pulled in for constructor and destructor handling, reducing code size.
- Compile these files into .o files and place them in a directory of your choice, or include them as a part of your application sources.
- Add the -nostartfiles switch to the compiler. Add the -B directory switch if you have chosen to assemble the files in a particular folder.
- Compile your application.
If your application is executing in a different mode, then you must pick the appropriate CRT files based on the description in Startup Files.