2

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.

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
Mark Luko
  • 31
  • 6
  • I think you need to be more specific. It looks like your code is used in multiple circumstances and when you link it, you want the unused code to be removed. Ie, having a compiler or tool warn you that something is not used by static analysis is not what you want? So conditional compiling or removing the variables is not the correct way to go? – artless noise Feb 12 '13 at 22:56
  • I have a generic library code shared between multiple projects. The library exposes multiple interface functions. These functions are also using internally static variables. My project uses small amount of the interface functions and I want to remove all the unused functions including the unused static variables. With --split_sections I can remove the functions but not the variables. Till now our company used GCC based compilers and we didn't need to include conditional compilation for this purpose. GCC could remove the unused code and data. I'm seeking for similar functionality from ARMCC – Mark Luko Feb 13 '13 at 05:55
  • 1
    This doesn't help? http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0474i/Cchhhghb.html – auselen Feb 13 '13 at 07:55
  • I would say that is an answer **auselen**. – artless noise Feb 13 '13 at 19:25
  • This doesn't help as it works only for FUNCTIONS. The unused code / data optimization is performed on SECTIONS by the linker. There is an option in ARMCC "--split_sections" that put each FUNCTION in different SECTION. The linker can perform later the unused code optimization for single FUNCTION as it each function resides in different SECTION. There is no such option for VARIABLES. In GCC there are separated options for FUNCTIONS and VARIABLES: "-fdata-sections -ffunction-sections". Please correct me if I'm misunderstanding something. – Mark Luko Feb 14 '13 at 10:57

2 Answers2

1

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.

Mark Luko
  • 31
  • 6
1

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.