Reducing the Startup Code Size for C Programs - 2022.1 English

Vitis Unified Software Platform Documentation: Embedded Software Development (UG1400)

Document ID
UG1400
Release Date
2022-04-26
Version
2022.1 English
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:
  1. 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.
  2. 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.

  3. 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.
  4. Add the -nostartfiles switch to the compiler. Add the -B directory switch if you have chosen to assemble the files in a particular folder.
  5. 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.