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.

CCS/AM6548: Issue GCC v7.2.1 aarch64 using varargs for AM65xx

Part Number: AM6548

Tool/software: Code Composer Studio

I post this issue in this forum because I don't know where else to post, sorry.

---

I have a AM6548-IDK and a small program for the A53 core.

Here I have the following 2 lines of code:

  UART_printf("d: %d\n", 100000);
  App_print(  "d: %d\n", 100000);

Here is the function App_print() :

void App_print(const char *format, ...)
{
  va_list vaArgPtr;

  va_start(vaArgPtr, format);
  UART_printf(format, vaArgPtr);
  va_end(vaArgPtr);
}

Now the vaargs in the App_print don't work, the forwarding of the variable arguments don't work.

The UART output is:

d: 100000
d: 1879506800

Up to now I spend a full day on this doing a lot of double-checks, vsnprintf, checking compiler options, searching gcc bugs via google etc.

Has anyone an idea?

Ruediger

  • Hi Ruediger,

    Do you use AM65x PSDK Linux, Linux-RT, RTOS or else?

    Regards,
    Pavel
  • I use AM65x TI-RTOS with processor_sdk_rtos_am65xx_5_02_00_10

    Compiler call and flags are
    "C:/ti/gcc-linaro-7.2.1-2017.11-i686-mingw32_aarch64-elf/bin/aarch64-elf-gcc.exe" -c -mcpu=cortex-a53+fp+simd -mtune=cortex-a53 -fno-exceptions -DAARCH64 -Dcore0 -DSOC_AM65XX -Dam6548 -Dam65xx_idk -I"C:/msol/src/multicarrier/mls_segcontroller/prj/prj_A53_main_test" -I"C:/ti/bios_6_75_01_05/packages/ti/posix/gcc" -I"C:/ti/gcc-linaro-7.2.1-2017.11-i686-mingw32_aarch64-elf/aarch64-elf/include" -I"C:/msol/src/multicarrier/mls_segcontroller/src" -I"C:/msol/src/multicarrier/mls_segcontroller/src/Include" -Og -g -gdwarf-3 -gstrict-dwarf -Wall -mabi=lp64 -mcmodel=large -mstrict-align -mfix-cortex-a53-835769 -mfix-cortex-a53-843419 -MMD -MP -MF"Diag/DiagPrint.d" -MT"Diag/DiagPrint.o" -std=c11 @"configPkg/compiler.opt" -o"Diag/DiagPrint.o" "C:/msol/src/multicarrier/mls_segcontroller/src/Diag/DiagPrint.c"

    Regards,
    Rüdiger
  • Hello Rudiger,
    I think you should use
    UART_printf(format, va_arg(vaArgPtr, int) );
    instead of just
    UART_printf(format, vaArgPtr);

    BR
    Michail
  • Hello Michail,
    of course this would work, but only in this special case where an 'int' is used as 2nd argument.

    But in fact my function App_print() shouldn't know with which arguments it has been called.
    App_print() must be generic regarding arguments, because I wanted to forward it to vsnprintf() but that didn't work either.
    I just reduced the problem to a very simple test case.

    So I wonder if this is a gcc compiler bug.
    I could paste the generated asm file if someone has experience with the Arm aarch64 procedure call rules.
    see also [http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055c/IHI0055C_beta_aapcs64.pdf] Appendix B

    Best regards,
    Rüdiger
  • Hello Rudiger,
    I see that you have more complicated case here. I am just mentioning how these are used normally (I mean va_start, va_arg and va_end must be used together in one session). The need of using va_arg to get value is also described in document that you mention.
    I think it is not a gcc bug in your case but rather respect to convention of usage.

    BR
    Michail
  • Hello Michail,

    I don't think that my usage is so uncommon.

    When you seach e.g. the AM65xx SDK for TIRTOS, you find the following functions doing exactly the same I did:

    • pdk_am65xx_1_0_3\packages\ti\csl\example\esm\esm_clk_loss_test_app\esm_clk_loss_app.c 
      ESMApp_consoleprintf(const char *pcString, ...)
    • pdk_am65xx_1_0_3\packages\ti\csl\example\mcan\mcanEvmLoopback\mcan_evm_loopback_app_main.c
      App_ConsolePrintf(const char *pcString, ...)
    • pdk_am65xx_1_0_3\packages\ti\csl\example\rti\rti_dwwdtest_app\rti_app_dwwd_v1.c
      RTIAppUtilsPrint (const char *pcString, ...)
    • pdk_am65xx_1_0_3\packages\ti\csl\test\mcanUt\testLib\st_mcanCommon.c
      App_ConsolePrintf(uint32_t type, uint32_t baseAddr, const char *pcString, ...)
    • pdk_am65xx_1_0_3\packages\ti\drv\cal\examples\cal_capture_test\src\CaptureCal_main.c
      App_print(const char *format, ...)
    • ... and many more 

    But I found no example which I could compile+run for the AM65xx-IDK

    In fact, forwarding varargs to vsnprintf() is very common. But this also doesn't work with the AM65xx: I get a memory exception.

    Regards,

    Rüdiger

  • Issue is solved: it was just a stack overflow.
    I used the default stack size of 2048 byte
    After increasing to 4096 byte, everything works fine, also the vsnprintf() usage

    Sorry for that, I just couldn't imaging that my so simple program needs >2k of stack.
    @Michail: thanks for your assistance
    Regards,
    Ruediger
  • Hi,
    good to hear that you resolve the issue.
    In fact 2048 bytes of stack are only 256 entries which is not so much for combined call/data stack so it is reasonable limitation

    BR
    Michail