5.4.4 Runtime Startup Code Files

The runtime startup code is contained in multiple modules, to support architectural differences between device families. Some of the runtime code is built from source code when you build your program; in other cases, prebuilt modules are linked in to provided the appropriate functionality.

The crt0.o runtime object module is built from source code contained in crt0.S and is used for both C and C++ programs. A copy of this source file is located in each available device family pack (DFP) and is built when you use the -mdfp option. If this option is not used, the source file shipped with the compiler is built. If you need to see a copy of this source file, unzip the pic32m-libs.zip file located at <install-directory>/pic32-libs/. The source code can be found at pic32m-libs/libpic32/startup/crt0.S. If you build a project and do not specify a processor, no startup code is linked in with the program. This module contains the code that is executed at the very beginning of the C runtime startup sequence.

The crti.o and crtn.o modules also perform actions at runtime startup for C++ programs. They are located in the <install-directory>/pic32mx/lib/ directory. They contain routines to run before main() (contained in .init sections) and after main() (contained in .fini sections) respectively. The sections within these modules must be linked in a specific order after sections defined in the crt0 code. The crtbegin.o and crtend.o modules contain code that handles static constructors and destructors, and are located in the <install-directory>/lib/gcc/pic32mx/<gcc-version>/ directory.