Application crashes during constructor/array initialization

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Application crashes during constructor/array initialization

2,662 Views
larry_bochenko
Contributor I

I am creating a "C" application for the MK60DN512VMD10 running MQX 4.1.

I cloned the MQX BSP using the BSP Wizard and modified it for my custom hardware.  Sample projects were included in the cloning process.  I can run "Hello World" with no issues.  However, my application immediately dies on startup hitting "__boot_exception()".

I can follow "__boot" to "toolchain_startup()" to "__thumb_startup()" to "__call_static_initializers()" to "__init_cpp()".  "__CTOR_LIST__" is identical to "__CTOR_END__" so no constructors are initialized.  "__preinit_array_start" is identical to "__preinit_array_end" so no work there.  However, there is an entry in "__init_array_start/__init_array_end" that is pointing into ".text 0x000006cc 0x94 c:/freescale/cw mcu v10.6/cross_tools/arm-none-eabi-gcc-4_7_3/bin/../lib/gcc/arm-none-eabi/4.7.3/crtbegin.o".  The call to "(*constructor)()" then goes off the rails.

Neither "BSPCFG_ENABLE_CPP" nor "MQX_ENABLE_CPP" are defined in my BSP project header, "mqx_cnfg.h" or any other project file.  So, why is this initialization even taking place.

Thanks in advance!

0 Kudos
2 Replies

1,271 Views
rockjonn
Contributor I

The initialization of constructors in a C application can occur even if the BSPCFG_ENABLE_CPP and MQX_ENABLE_CPP flags are not explicitly defined in the project files. This is because the initialization of constructors is typically handled by the C runtime startup code provided by the toolchain.

The initialization process is part of the C++ language specification, and it ensures that global and static objects with constructors are properly initialized before the program execution begins. The toolchain's startup code includes the necessary initialization routines to handle this process.

In your specific case, the entry in the __init_array_start/__init_array_end section pointing to crtbegin.o indicates that the C runtime initialization code is located in the crtbegin.o object file, which is part of the toolchain's runtime library. This file contains the necessary code to initialize static objects with constructors.

The fact that the application is encountering an exception at startup (__boot_exception()) suggests that there may be an issue with the initialization process or a problem with the specific object or constructor being called. To diagnose and resolve this issue, it would be helpful to examine the specific code and data in the crtbegin.o file, as well as any other relevant code or configuration files in your application.

Additionally, reviewing the linker script (mqx.ld) and the build settings related to the linker and startup code in your project may provide further insights into the initialization process and help identify any potential configuration or linking issues.

It's also worth noting that consulting the documentation or support resources provided by the toolchain vendor, as well as seeking assistance from the community or forums dedicated to your specific toolchain and hardware platform, can be beneficial in troubleshooting and resolving issues related to startup and initialization in the MQX environment.

0 Kudos

2,622 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Larry:

You can check the user_config.h file if macro BSPCFG_ENABLE_CPP or MQX_ENABLE_CPP are defined.

Please also check the .  project settings C/C++ Language and check "Force C++ compilation".

 

Regards

Daniel

 

 

0 Kudos