I'm using armclang compiler Product: Professional Component: ARM Compiler 6.16
There are unused functions which are linked in the final application. There functions are coming from a library which is linked to final application, but not called in application.
How to remove these unused functions from final image ?
ARM Linker does this automatically. You have to specify if you want to keep symbols/functions. Did you check the cross reference if there is no hidden usage?
The below are the options used for compilation,
armclang --target=arm-arm-none-eabi -mcpu=cortex-m7 -Wall -Wextra -Werror -Wno-error=unused-variable -Wno-error=unused-function -Wno-error=unused-parameter -fdiagnostics-absolute-paths -Wno-unused-command-line-argument -Wno-error=unused-private-field -mcpu=cortex-m7 --target=arm-arm-none-eabi -mno-unaligned-access -fno-builtin -c -O3 -fno-fine-grained-bitfield-accesses -o main.o -c main.c
armlink --scatter=test.sct --map --callgraph --datacompressor=off --no_remove --entry=Reset_Handler --symbols --no_scanlib main.o out/bin/main.axf --list=out/bin/main.map
The linker has --no_remove specified, which disables this feature.
I recommend also adding --info unused to the linker command line.
Tried removing --no_remove from linker options but no change in final image, still it conatins unused functions.
Tried lisiting --info unused in linker options, but no prints of removing unused code.
The smallest entity that can be removed is an ELF section. Are these unused functions in the same section as a used function?
The fromelf (with -c) utility can help you decipher this if you are unsure.
It shows there are 13 sections using fromelf -c. This includes code section, data rw, stack,
Is the "unused" code in the same section as "used" code? If so, then the linker cannot remove it.