You copied the Doc URL to your clipboard.

-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 -o- main.c
				
...				
        .section        .text.function1,"ax",%progbits
        .globl  function1
        .align  2
        .type   function1,%function
function1:                              @ @function1
        .fnstart
@ BB#0:
        .pad    #8
        sub     sp, sp, #8
        mov     r1, r0
        str     r0, [sp, #4]
        add     r0, r0, #1
        str     r1, [sp]                @ 4-byte Spill
        add     sp, sp, #8
        bx      lr
.Lfunc_end0:
        .size   function1, .Lfunc_end0-function1
        .cantunwind
        .fnend

        .section        .text.function2,"ax",%progbits
        .globl  function2
        .align  2
        .type   function2,%function
function2:                              @ @function2
        .fnstart
@ BB#0:
        .pad    #8
        sub     sp, sp, #8
        mov     r1, r0
        str     r0, [sp, #4]
        add     r0, r0, #2
        str     r1, [sp]                @ 4-byte Spill
        add     sp, sp, #8
        bx      lr
.Lfunc_end1:
        .size   function2, .Lfunc_end1-function2
        .cantunwind
        .fnend
...