1.9 -ffunction-sections

Generates one ELF section for each function in the source file.

Output sections are named with the same name as the function that generates the section, but with a .text. prefix.

Note

If you want to place specific data items or structures in separate sections, mark them individually with __attribute__((section("name"))).

Restrictions

This option reduces the potential for sharing addresses, data, and string literals between functions. Consequently, it might increase code size slightly for some functions.

Example

int function1(int x)
{
  return x+1;
}

int function2(int x)
{
  return x+2;
}
Compiling this code with -ffunction-sections produces:
armclang --target=arm-arm-none-eabi -march=armv8-a -ffunction-sections -S -O3 -o- main.c
				
...				
    .section    .text.function1,"ax",%progbits
    .globl      function1
    .p2align    2
    .type       function1,%function
function1:                              @ @function1
    .fnstart
@ BB#0:
    add         r0, r0, #1
    bx          lr
.Lfunc_end0:
    .size	  function1, .Lfunc_end0-function1
    .cantunwind
    .fnend

    .section    .text.function2,"ax",%progbits
    .globl	 function2
    .p2align    2
    .type	  function2,%function
function2:                              @ @function2
    .fnstart
@ BB#0:
    add	    r0, r0, #2
    bx	     lr
.Lfunc_end1:
    .size       function2, .Lfunc_end1-function2
    .cantunwind
    .fnend
...
Related reference
3.15 __attribute__((section("name"))) function attribute
Non-ConfidentialPDF file icon PDF versionARM DUI0774E
Copyright © 2014-2016 ARM. All rights reserved.