Page 1 of 3

Looking for help with my C++ thread class

Posted: Tue Apr 12, 2011 3:22 am
by JetForMe
Hi. I've posted a bit about this before. Basically, I have a template C++ class wrapping ChibiOS threads. It works well on AVR, but has issues on ARM. I've written up a blog post with code and explanations here:

http://blog.roderickmann.org/2011/04/using-templates-to-statically-allocate-thread-working-area-in-chibios/

I'm hoping someone can make some suggestions of other things to consider. Thanks!

Re: Looking for help with my C++ thread class

Posted: Tue Apr 12, 2011 9:40 am
by JetForMe
I've figured it out. It's not a problem with my code at all. Instead, constructors for statically-allocated (global) objects are not getting called. I suspect the problem lies somewhere in crt0.s, or perhaps in the linker script, not really sure.

Giovanni, you're the most likely person to know what's going on. You can see a clear explanation here, in the "Update" section near the beginning of the post: http://blog.roderickmann.org/2011/04/using-templates-to-statically-allocate-thread-working-area-in-chibios/

Re: Looking for help with my C++ thread class

Posted: Tue Apr 12, 2011 11:34 am
by Giovanni
Give me a little time to read it all, anyway you are correct, the current crt0.s does not currently invoke static constructors.

Giovanni

Re: Looking for help with my C++ thread class

Posted: Tue Apr 12, 2011 6:19 pm
by JetForMe
Thanks, Giovanni. Note that you need not read the whole thing. The update section just shows the result of the ctors not getting called. The rest is a distraction from that issue.

I did a little googling on the matter. The spec only requires that a given file static constructor be called before any other function in that file is called. The easiest thing, I think, is to just call them all in crt0.s, but you may find something else.

Hopefully it's just a simple matter of inserting a single call to a compiler-generated routine.

Thanks!

Re: Looking for help with my C++ thread class

Posted: Tue Apr 12, 2011 6:30 pm
by Giovanni
crt0.s is the proper place for this, I'll try to add the feature in 2.3.2.

Giovanni

Re: Looking for help with my C++ thread class

Posted: Tue Apr 12, 2011 6:53 pm
by JetForMe
Thanks, Giovanni. Any timeframe for the release? If it's not a matter of days, do you know how I can modify my local crt0.s to add this support? Thanks!

Re: Looking for help with my C++ thread class

Posted: Tue Apr 12, 2011 7:11 pm
by Giovanni
Sorry I can't promise, releases are usually done in 2-3 weeks intervals.

Changes will involve the startup file and the linker script for sure, I don't know exactly until I will examine the problem.

Giovanni

Re: Looking for help with my C++ thread class

Posted: Tue Apr 12, 2011 7:41 pm
by JetForMe
Okay. I think I can work around the problem for now. Thanks.

Re: Looking for help with my C++ thread class

Posted: Sun Apr 17, 2011 7:30 pm
by Giovanni
Hi,

The version currently on the repository fixes the problem for the Cortex-Mx port. It will be released as 2.3.2 sometime next week.

Giovanni

Re: Looking for help with my C++ thread class

Posted: Mon Apr 18, 2011 2:22 am
by JetForMe
That's good news! I tried looking for the changes you made, but it wasn't entirely clear what you did (plus, the repo browser didn't want to show me the checkin comments (i.e.: http://chibios.svn.sourceforge.net/view ... c?view=log).

I look forward to the update!