Reputation: 31
I'm trying to remove unused code with Keil ARM tools that use ARMCC compiler. I've previously used GCC based compilers for ARM and I could easily remove the unused code with:
-fdata-sections -ffunction-sections
For ARMCC i found similar flag
--split_sections
but it works only with functions and not with variables.
Is there any way to remove unused variables with ARMCC?
Edit:
For example giving the following library code:
lib.c :
static int veryBigArray[1000000UL];
int func1() { ... }
int func2() { memset(veryBigArray, 0, sizeof(veryBigArray); }
and my project code:
project.c:
int main(void)
{
func1();
}
I want to remove func2() and veryBigArray using compiler/linker optimizations.
Upvotes: 2
Views: 2330
Reputation: 11
In most cases, unused data can be removed with --remove as a linker option, when the data is in its own section. To place data in its own section, you may create another file or use the section attribute: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0375g/chr1359124982450.html
For example, if global data is used in only one function, and the function is defined but never used, then the data is automatically removed in armcc, without --remove.
I say "in most cases" because there are situations where the user tells the compiler to specifically not optimize it out.
Arm Compiler version 6, (armclang), does have -fdata-sections.
Upvotes: 1
Reputation: 31
The official answer that we received from ARM support is that currently (ARMCC v5.03 [Build 24]) there is no such option available in ARMCC compiler - They just never thought about such scenario.
Hopefully it will be added to future ARMCC versions.
Upvotes: 1