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.

Problem with TI's compiler /linker mapping different variables to the same memory location!!!!!!!



Using a TM4C1231H6PZI and CCS ver 6.1.0.00104 with Tivaware 2.1.1.71

I just discovered problem where the compiler is mapping a variable into another variable!  There are no warnings or errors from the compiler that this was happening and it took me 2 days to figure it out was going on!

When I declare the big float array Test_Results[]  inside the main, it puts the address of another global variable, timer_10uS into element 634 of Test_Results.

When I move the declaration of Test_Results[] outside of main, everything is fine.  timer_10uS is always declared outside of main.

What is going on?  Why doesn't the compiler/linker tell me somethings wrong?  Can I trust this compiler anymore?????????

See Screenshot......

  • When you say declare inside main do you mean like

    main()
    {
    int a[12];

    }

    If that is what you mean, then it's not a linker problem. The linker has no method to track function local variables.

    Some compilers will warn if you are placing large variables on the stack like you have. I don't know if TI's does.

    Why would you place that much on the stack in the first place?

    Robert
  • Yes that's what I was talking about. it was just for a temporary quick test to gather some data to paste into a spreadsheet.
    It still does it when the array is smaller 300 or so elements.
    Well now I know to not declare huge arrays or too many variables inside a function.
    In any case, shouldn't I get a message or warning from somewhere that there is a problem?
  • There will be no warning when you fill up the stack, at least I think so.

    This problem seems weird since it happens when the array is smaller than 300 elements. But I will leave that warning - the stack standard value usually is pretty small (512bytes I think). If you really need that much elements in a array increase the stack a bit, you should have RAM to spare for that
  • I guess I should have declared it as static and it would work.
  • Some compilers will issue a warning if you place a large amount of data on the stack. PC Lint can be set up to do that as well. I think there are some compilers that can track stack usage, PC Lint can as well. There are difficulties tracking stack usage once you involve library functions and tasking, and from what I've observed PC Lint manages those better. It's still not simple though.
    In order to tell there is a stack overflow the compiler must be able to determine all possible function sequences. This is a non trivial problem, especially when you involve libraries and other languages.

    Basically you, in most cases, have to make sure your stacks are sufficiently sized by some combination of analysis and measurement and providing extra margin.

    As far as making the variable static to avoid the problem, that will work but at the expense of destroying reentrancy and using up memory even when the function is not in the call chain.

    Robert
  • Vic Elias2 said:
    When I declare the big float array Test_Results[]  inside the main, it puts the address of another global variable, timer_10uS into element 634 of Test_Results.

    Are you able to provide a complete CCS project which demonstrates the problem, since the that will probably be required to investigate the problem.

    Also, which version of the TI ARM compiler are you using?