MQX 4.1 and Newlib

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

MQX 4.1 and Newlib

1,582 Views
chrissolomon
Contributor III

Hi,

I am trying to migrate from EWL to Newlib for our product, so we can take advantage of the C++11 features.

I am tackling the transition together with the work to migrate from MQX 4.0.1 to 4.1.

We are using manually created make files and linker files, not using code warrior (although I have it just to generate example projects for reference).

I have MQX configured to build using the gcc_arm toolchain, and the libraries are building fine.

In my application code I have updated my linker file to provide the symbols required by comp.c, and newlib - so I have

__preinit_array_start, __preinit_array_end, __init_array_start, __init_array_end, the fini array, zero table and copy table etc.

For linking I have removed the include paths for EWL and added  -lrdimom -specs=rdimon.specs -specs=nano.specs

The code compiles, however in the toolchain_startup it crashes at the "atexit" call (and if that is commented out, at the __libc_init_array).

(Has no problem getting through the init_hardware and data_startup.)

I have checked the map file, and the functions are present, and I've looked through the source for newlib, and I don't believe I am trying to call malloc (which I guess would fail given there is no heap at that point).

Can anyone give me any advice, point me at some useful documentation or example code that would help me get my project going?

Feel free to ask for more information.

Thanks

Chris

Tags (2)
0 Kudos
Reply
7 Replies

1,049 Views
RadekS
NXP Employee
NXP Employee

Hi,

I looks like known issue with C++ global objects:

C++ startup is trying to register destructors of global objects so they can be invoked during exit() fn.
The C++ standard says that c++ should support at the least 32 objects. So there is an global array of 32 itemss.

If there is a more than 32 global objects, startup is trying to create new table by malloc(). All this happens before main() function.

In main function we run MQX which create memory pools.

So malloc call in startup crashes because we don’t have created pool.
MQX design does not fully support C++, we are working on fix.

In mean time, we would like to recommend you to do not use global objects.


Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,049 Views
virendrapatel
Contributor III

Hi,..

I am facing the same issue with MQX 4.1 and  newlib.

is this issue was fixed?

can anyone tell me how to use MQX 4.1.1 and newlib?

Thanks,

Virendra

0 Kudos
Reply

1,049 Views
RadekS
NXP Employee
NXP Employee

Unfortunately not

It is conceptual problem and it will not be fixed even in MQX 4.2.

If it is possible, please don’t use global objects.

I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

1,049 Views
virendrapatel
Contributor III

Thanks for the help!

Its is very difficult to remove all  the  global object from our code.

Is there any other indirect way to resolve this?

Thanks,

Virendra

0 Kudos
Reply

1,049 Views
RadekS
NXP Employee
NXP Employee

Unfortunately we didn't found and we do no know about any indirect way.

32 global objects is maximum.

I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

1,049 Views
soledad
NXP Employee
NXP Employee

Hello Chris,

Please check the below link and let me know if this helps! :smileywink:

Creating a new MQX project using GCC C++


Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

1,049 Views
chrissolomon
Contributor III

Hi Sol,

thanks for getting back to me. The document is interesting, but is specific to EWL (which I had working with MQX 4.0.1 already).

Can you tell me if using newlib with MQX is supported?

Thanks

Chris

0 Kudos
Reply