Reducing the Startup Code Size for C Programs - 2025.2 English - UG1400

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

Document ID
UG1400
Release Date
2025-11-20
Version
2025.2 English
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:
  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. If your bootstrapping and profiling is on your application, 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 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.
  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.