If your application has stringent
requirements on code size for C programs, it is recommended to eliminate all sources of
overhead. The following describes reducing the overhead of invoking C++ constructor or
destructor code in a C program that does not require that code. It is possible 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. If your bootstrapping and profiling is on your application, 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 */ nopand
brlid r15, __fini /* Invoke language cleanup functions */ nopThis avoids referencing the extra code usually pulled in for constructor and destructor handling, reducing code size.
- Compile the files into .o files and place them in a directory of your choice. You can also include the files 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.