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.

Compiler/MSP430F6779A: Possible 'C' Function call Stack Overflow and Compiler Implementation for sprintf and scanf and possible usage of _CIOBUF_ Linker Output Section

Part Number: MSP430F6779A

Tool/software: TI C/C++ Compiler

There is cryptic and incomplete information in TI Docs about the space the MSP430 Compiler/Linker reserves for section "_CIOBUF_" which, according to documentation, is used heavily for file i/o buffering between the MSP430 and the Host when the Debugger/Emulator is attached.  My application does not use File I/O and the application is running out of memory with potential C-Function stack frame exhaustion. The application does use sprintf and scanf heavily, and there is as note in the below TI doc that these functions "do not use the entire interface."

http://software-dl.ti.com/ccs/esd/documents/sdto_cgt_tips_for_using_printf.html#Getting_C_I.2FO_working_.2F_Troubleshooting

Quote from above "printf " exception: the *sprintf functions do not require the entire C I/O interface"  (What does this mean?  Do they need the _CIOBUF_? 

The linker is putting the buffer for 'C I/O', "_CIOBUF_" right next to stack, so I'm trying to also determine if either _CIOBUF_ is overwriting stack "_stack", or if stack is overwriting _CIOBUF_.  Also trying to determine if stack grows from _stack to __STACK_END_ or the reverse. 

From the map file I have:

00007c00  _stack

00009c00  __STACK_END                                
00002000  __STACK_SIZE          

Memory Dumps of _CIOBUF_ and _stack follow

###########################################


#################################


Tool/software: TI C/C++ Compiler

There is cryptic and incomplete information in TI Docs about the space the MSP430 Compiler/Linker reserves for section "_CIOBUF_" which, according to documentation, is used heavily for file i/o buffering between the MSP430 and the Host when the Debugger/Emulator is attached.  My application does not use File I/O and the application is running out of memory with potential C-Function stack frame exhaustion. The application does use sprintf and scanf heavily, and there is as note in the below TI doc that these functions "do not use the entire interface."

http://software-dl.ti.com/ccs/esd/documents/sdto_cgt_tips_for_using_printf.html#Getting_C_I.2FO_working_.2F_Troubleshooting

Quote from above "printf " exception: the *sprintf functions do not require the entire C I/O interface"  (What does this mean?  Do they need the _CIOBUF_? 

The linker is putting the buffer for 'C I/O', "_CIOBUF_" right next to stack, so I'm trying to also determine if either _CIOBUF_ is overwriting stack "_stack", or if stack is overwriting _CIOBUF_.  Also trying to determine if stack grows from _stack to __STACK_END_ or the reverse. 

From the map file I have:

00007c00  _stack

00009c00  __STACK_END                                
00002000  __STACK_SIZE          

  • Hi, Kip,

    I will check and feedback to you later. 

    Thanks, 

    Lixin 

  • I turn this post to c/c++ compiler team to help. 

    Thanks,

    Lixin 

  • Among the details of the implementation of the C I/O (C input and output) functions is a buffer named _CIOBUF_.  It is in a section named .cio.  All of this is intentionally not documented to end users, except that the .cio section must be allocated to read/write memory.  Other than that, there is no reason to worry with these implementation details.

    Kip Leitner said:
    The application does use sprintf and scanf heavily

    Do you mean sscanf instead of scanfsprintf and sscanf do not use _CIOBUF_, but scanf does.  For now, I presume you use sscanf and not scanf.  

    That being the case, I do not understand why your code needs _CIOBUF_.  Some other C I/O function must get called.  Here is one way to find that function.

    Install the cg_xml package.  Use the utility call_graph from it.  A typical invocation looks like ...

    C:\work>ofd430 -g -x executable_file.out | cg_xml_install_dir\bin\call_graph -i cg_xml_install_dir\ofd\ti_rts_indirect.txt -i cg_xml_install_dir\ofd\msp430_rts_indirect.txt > graph.txt

    (All the details of that command are explained later.)

    Search the text file graph.txt for a call to the function __TI_readmsg.  Then look up through the call graph until you see the name of an RTS function you recognize.  For instance, here is what it looks like when scanf (not sscanf) is called ...

    |  |  scanf : wcs = 570
    |  |  |  __TI_scanfi : wcs = 562
    |  |  |  |  _sget_conv : wcs = 20
    |  |  |  |  |  atoi : wcs = 6
    |  |  |  |  |  |  __mspabi_mpyi : wcs = 2
    |  |  |  |  |  strlen : wcs = 2
    |  |  |  |  _sproc_float : wcs = 70
    |  |  |  |  |  $abproc0 : wcs = 0
    |  |  |  |  |  _inpchar : wcs = 40
    |  |  |  |  |  |  fgetc : wcs = 38
    |  |  |  |  |  |  |  __TI_buff_read : wcs = 26
    |  |  |  |  |  |  |  |  __TI_doflush : wcs = 16
    |  |  |  |  |  |  |  |  |  write : wcs = 12
    |  |  |  |  |  |  |  |  |  |  HOSTwrite : wcs = 10
    |  |  |  |  |  |  |  |  |  |  |  __TI_readmsg : wcs = 2
    |  |  |  |  |  |  |  |  |  |  |  __TI_writemsg : wcs = 2

    Several layers are used to implement a function like scanf.  The functions __TI_readmsg and __TI_writemsg are the only ones that use _CIOBUF_.  

    Once you know which RTS function is being called, search your source for it.

    Here are the details of the invocation of call_graph ... The command ofd430 is part of the MSP430 compiler installation.  The name cg_xml_install_dir refers to where the cg_xml package is installed.  Change executable_file.out to the name of the final executable file produced by the linker.  The C I/O functions make a few indirect function calls, which present a problem for connecting the call graph.  That problem is overcome by supplying extra information about those indirect function calls with the -i file options.  Those files list out, for RTS functions which make indirect calls, all the functions that might be called.  The call graph makes the worst case presumption that all of them get called.  The command ofd430 is documented in the MSP430 assembly tools manual.  To see the documentation for the cg_xml package, load the file cg_xml_install_dir/index.htm into a web browser.  Click the link for call_graph.

    Kip Leitner said:
    trying to determine if stack grows from _stack to __STACK_END_ or the reverse.

    The reverse.  The stack grows from higher addresses to lower addresses.  In terms of symbols, from __STACK_END to _stack.  

    Thanks and regards,

    -George

  • George, you are correct -- I mean sprintf() and sscanf().  I will use the tool chain in the way you demonstrate to see if I have any functions that use C I/O.  I saw data once in the "C I/O" section in the CCS debugger studio, and was confused, so I filled the .cio section with a memory pattern and did a test run for several hours, and as you suggest, I did not see any changes (writes) to this memory region, so I'm thinking now that maybe none of my code is using _CIOBUF_ (is correct) but maybe I have a pointer bug, which is why during one test run I saw my application text string data in the _CIOBUF_ memory region.  Thank you for your expert help.  I'm running the scripts to build the stack usage and functional call chain patterns.

**Attention** This is a public forum