Dear all:
I'am working on DS-5 Professional Edition: 5.28.1 wigth tool Arm Compiler6 DS-5 built-in.
Imported sample project startup_Cortex-R8. and modified main.c file with code like:
extern int g_TobeyTest;
void TobetTestFun(void)
{
g_TobeyTest = 0xffff;
while(1);
}
add option -flto for armclang; then add option -lto for armlink
but actually I don't invoke function TobetTestFun(), or use g_TobeyTest in the project.
AS i thought, with armclang -flto armlink --lto can help me remove symbol g_TobeyTest, but it doesn't work.
Can somebody help me solve it, thanks!!
================================================
below is project build log:
11:16:42 **** Build of configuration Debug for project startup_Cortex-R8 ****make all 'Building file: ../main.c''Invoking: Arm C Compiler 6'armclang --target=arm-arm-none-eabi -mcpu=cortex-r8 -O0 -w -flto -mthumb -MD -MP -c -o "main.o" "../main.c"'Finished building: ../main.c'' ''Building file: ../sorts.c''Invoking: Arm C Compiler 6'armclang --target=arm-arm-none-eabi -mcpu=cortex-r8 -O0 -w -flto -mthumb -MD -MP -c -o "sorts.o" "../sorts.c"'Finished building: ../sorts.c'' ''Building file: ../startup.s''Invoking: Arm Assembler 6'armclang --target=arm-arm-none-eabi -mcpu=cortex-r8 -marm -g -w -x assembler-with-cpp -c -o "startup.o" "../startup.s"'Finished building: ../startup.s'' ''Building target: ../startup_Cortex-R8.axf''Invoking: Arm Linker 6'armlink --entry=Start --scatter="M:\tobey\DS-5 Workspace\startup_Cortex-R8\VT3549_FW_MCU0.scat" --info=totals --info=inline --lto -o "../startup_Cortex-R8.axf" ./main.o ./sorts.o ./startup.o armclang.exe: warning: Your license for feature ulteval_armcompiler will expire in 14 days [-Wlicense-management]Error: L6218E: Undefined symbol g_TobeyTest (referred from main.o).Finished: 0 information, 0 warning and 1 error messages.
BR
TobeyTan
Hi Tobey,
I'm the Product Manager for Compilers, good to hear from you!
I think what's happening is this: the link happens in a number of stages. The linker will first try to resolve all symbols, and then it will to analyse the code to search for redundant paths that can be optimized away. In this instance it looks like the symbol resolution is failing, the extern variable isn't defined anywhere, so the linker can't resolve the variable use. With a failure to link, it's not getting to the redundant path search.
Link Time Optimization can be a very useful feature in a compiler, producing both performance gains and a removal of unused code. However, it is an optimization, and it needs buildable code. I think the way forward it to define the variable so that your code can build and link, then give LTO a try to see how it does.
Let me know how that turns out?
Paul.
The error in your code is the use of extern on the variable. If you remove it the code will build.
// don't put extern here: int g_TobeyTest; void TobetTestFun(void) { g_TobeyTest = 0xffff; while(1); }
You will see a message from the linker:
Removing main.o(.bss.g_TobeyTest), (4 bytes).
Thanks,
Jason