5.3.5.1 How Do I Stop A Function From Being Removed?

Apply the attribute keep to a function to prevent the linker from removing it with --gc-sections, even when the function is unused. See the following section on keep of this user’s guide:

Function Attributes