This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

NDK with Exceptions?

Hi,

I'm using CCS C/C++ Compiler v7.2.1, SYS/BIOS 6.31.4.27, and NDK 2.20.4.26, building for a C6670.

I was having dificulty getting a code project working using NDK. However I had previously been able to get IP comms going OK.

It appears to be something to do with the fact that I had turned on Exception handling in the C++ compiler options (--exceptions) for my CPP source files and then linked against the _eh core library. I say this because when I removed the code that actually used exceptions, and recompiled my code without --exceptions, and the exception handling core library, the code started working as intended.

The error seen was very reproducable but very wierd. It seemed to crash out with a stack overflow while trying to allocate memory. There is room on the heap, and other allocations had worked ok. I had 8kB reserved for my stack, which should be more than enough for what was (visibly) going on the stack. Plus, as I say I rebuilt my project without exceptions (the only change) and it all seems to work OK.

I haven't done anything to attempt to prove this as yet. I was thinking of compiling the hello world MCSDK example in C++ with exceptions and see if it crashes out. But before I started doing anything like that I thought I'd ask the question to see if anyone knows anything about it.

As a final question, during my digging into trying to find out why it was crashing out, can anyone tell me why SPRU523g, the NDK User Guide, section 3.4.1 states "The NDK assumes there is some L2 cache. If the DSP is configured to all internal memory with nothing left for L2 cache, the NDK drivers will not function properly". Surely with the use of the OSAL type functions, implemented in the MCSDK examples with the resourcemgr.c source file, these control what caching mode(s) are used? Is there any other reference to caching elsewhere in the NDK? Is this just a comment more relating to older versions on the NDK on older architecture?

 

  • Hi Simon Locke,

    I've never seen this problem before.  All of our testing is done with C programs, not C++.

    I took a quick look at the --exeptions flag.  It states the following in the compliler guide (spru187S.pdf):

    "For exceptions to work correctly, all C++ files in the application must be compiled with the --exceptions
    option, regardless of whether exceptions occur in a particular file. Mixing exception-enabled object files
    and libraries with object files and libraries that do not have exceptions enabled can lead to undefined
    behavior
    "

    Can you please verify that you have compiled *all* of your application's C++ files using the --exceptions flag?

    It certainly sounds like you are seeing "undefined behavior" so I wanted to just make sure of that you did that.

    (I'm also hoping that this doesn't mean that the NDK itself would need to be recompiled, but I don't think so because does not have any C++ files).

    Simon Locke said:
    As a final question, during my digging into trying to find out why it was crashing out, can anyone tell me why SPRU523g, the NDK User Guide, section 3.4.1 states "The NDK assumes there is some L2 cache. If the DSP is configured to all internal memory with nothing left for L2 cache, the NDK drivers will not function properly". Surely with the use of the OSAL type functions, implemented in the MCSDK examples with the resourcemgr.c source file, these control what caching mode(s) are used? Is there any other reference to caching elsewhere in the NDK? Is this just a comment more relating to older versions on the NDK on older architecture?

    I think this may be outdated.  Looking at the driver for evmOMAPL138, the only thing we could see is that the CPPI table may be defined in L2 instead of the dedicated 8K of memory on the CPPI itself:

    /**
     *  \defgroup   Descriptor memory selection Flags
     *
     * @{
     */
    #define EMAC_DESC_BASE_L2          0x00001
    /**< Use L2 as Descriptor memory                                            */
    #define EMAC_DESC_BASE_CPPI        0x00002
    /**< Use CPPI RAM as desriptor memory                                       */

    typically most applications wouldn't use the "L2" flag, so if you're compiling your app with that it's probably safe.

    Steve

  • Hi Steve,

    Yes I had observed the note about making sure that all the CPP files are compiled with the --exceptions flag. Consequently I had checked and double checked that they all had the flag enabled, because as you rightly pointed out, I was seeing somewhat undefined behaviour. But then again, the NDK is not CPP, and if you pass a .c file into cl6x with the --exceptions set it spits an error saying that is invalid for C. So clearly, it is not possible to compile the NDK code itself for exceptions. However I was experiencing a very odd problem.

    For now it is not an issue. I was planning on using RapidXML (http://rapidxml.sourceforge.net/) as an XML parser, but it relies on exceptions. I shall attempt to find some time to try a couple of things like building a simple CPP project with exceptions and see if that works and then try adding NDK with a socket open and bind. I wanted to post it up here so its recorded for people to see if anyone else some across it.

    And thats good to know that it does appear as though the doc comments with regard to L2 are a little out of date. We're using the C6670, rather than the OMAP, but I think the principle is the same.

    Simon.

  • I have observed, on C64+ platforms, that exception handling enabled needs larger task stack, in my case I have found 12K were sufficient. NDK by itself needs also larger stack, but without exceptions in my case 6K were enough, your 8K should be fine.

  • Hi trovter,

    Thats interesting that you think maybe I do need an even bigger stack. At some point I'll get back round to looking at this again. I'm currently working on another problem though, so thats taking precedence....

    Simon.