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/AM5728: C++ build reports error with stack variable defined in startup_ARMCA15.S used with GCC compiler.

Part Number: AM5728


Tool/software: Code Composer Studio

The G++ Linker reports an error that __stack is undefined when compiling the file  startup_ARMCA15.S  provided in CCS  when code is compiled using Linaro GCC compiler for A15 core. The C++ linker seems to be case sensitive as changing the __stack to __Stack seems to resolve the issue.

In order to reproduce the issue, create C++ project using instructions here:

Add startup_ARMCA15.S and linker command file and build the project. Examples project is attached:

Cpp_test.zip

Regards,

Rahul

  • Rahul,

    Thanks for sending the detailed test case. I was able to import your existing project and see the undefined __stack symbol error:

    build error said:

    'Invoking: Cross G++ Linker'
    arm-none-eabi-g++ -L"C:\ti\ccsv7\tools\compiler\gcc-arm-none-eabi-4_9-2015q3\lib" -mtune=cortex-a15 -marm -Dk2g02 -Darm0 -g -gdwarf-3 -gstrict-dwarf -Wall -mcpu=cortex-a15 -Wl,-Map,"test_k2g.map" -Wl,--defsym,ARM_CORE=1 -Wl,--defsym,STACKSIZE=0x10000 -Wl,--defsym,HEAPSIZE=0x400 -specs="nosys.specs" -o "Cpp_test" ./src/Cpp_test.o ./src/startup_ARMCA15.o
    c:/ccsv7_1_0/ccsv7/tools/compiler/gcc-arm-none-eabi-4_9-2015q3/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7-ar/thumb/crt0.o: In function `_start':
    (.text+0x58): undefined reference to `__stack'

    However, the fact you switched to an uppercase is somewhat baffling. The error in question is the inability to find the symbol __stack, which is defined as global in the <startup_ARMCA15.S> and initialized at line 179 of the linker script 66AK2Gxx.lds. 

    Therefore, looking at the linker line above one can tell the linker script is NOT included at all. To do this, simply add the option -T"../src/66AK2Gxx.lds" to the linker miscellaneous options as shown below.

    I really can't explain why the uppercase name is relevant, but I suspect something inside the nosys library defines it. 

    A few other interesting things I found in your project:

    - you are explicitly including libc on a c++ project

    - cout is being used with "nosys" specs. However, this may impact the code functionality as nosys lacks semihosting support. You should change it to "rdimon" for full support.

    Hope this helps,

    Rafael

  • Thanks Rafael. This resolved my issue. I was a little surprised that the linker was not generating this error with my C code but was throwing this error with the C++ code. I overlooked the fact that stack variable was initilialized in the .lds file. Thanks for pointing that out.

    for Semihosting support, I will add rdimon. This was just the first step in building a bigger C++ project for the A15 core so I will create a new thread if there is any other issues.