14.1.2.11 keep

The keep attribute will prevent the linker from removing the function with the ELF linker option --gc-sections, even if it is unused.

in C:

void __attribute__((keep)) foo(void);

in Assembly:

  .section *,code,keep
  .global _foo
_foo:
  return