Reducing Program Size

One concern of developers of embedded systems is program size. Given the limitations on the amount of ROM available in typical embedded systems, it is desirable to make programs as small as possible. The Green Hills compiler allows you to create smaller executable files under certain conditions.

Removing Floating-Point Libraries

Large executable files can be the result of library routines which cause code related to floating point operations to be linked in. This can occur even if your program does not use floating point variables.

A prime example of this is the printf function. Since printf allows various formatting options for floating point values, which are the %f, %e, and %g switches, using printf causes floating point handling code to be loaded even if these particular options are not used. This may add considerable size to the executable program.

The -fnone switch to the driver is designed to avoid this problem. This switch means that the user program is not using floating point operations. This allows the driver to load special versions of printf and other library functions that do not use any floating point code.

The -fnone switch has two effects. The compiler will give a fatal error for any floating point constant and for any use of the reserved words float and double. This prevents any floating point value or operation from appearing in the C source code. At link time, the linker searches a special library which has non-floating point versions of library functions before searching the regular libraries. If any of these functions are used, the non-floating point versions are loaded in place of the floating point ones.

The compiler attempts to position certain program variables in order to minimize the space for padding between variables. Global and external variables are not eligible for this optimization because of the possibility that other modules may make assumptions about their order. Such variables are generally allocated in the order in which they are declared in the source file. However, static variables (both local to functions and of file scope) may be rearranged by the compiler in order to reduce padding space.

The compiler classifies these variables into three categories based on size: single byte variables, larger variables (which are the size of an integer register or less), and variables larger than an integer register. The variables from the first category are allocated, then the second, and the third. Collecting variables of similar sizes together reduces the need for padding.

You can increase opportunities for this optimization by liberal use of static variables wherever possible.

Specifying Program Start Address

The linker normally uses the address of the global symbol -start as the start address for the user program. The driver supports an option, -entry=sym, to specify an alternate start address.

For example, use the symbol newstart as the program start address with a command line:

% ccmcore -entry=newstart file.c

Previous

Next



Copyright © 1999, Green Hills Software. All rights reserved.