3.18 __attribute__((used)) function attribute

This function attribute informs the compiler that a static function is to be retained in the object file, even if it is unreferenced.

Functions marked with __attribute__((used)) can still be removed by linker unused section removal. To prevent the linker from removing these sections use the --keep armlink option, or use the --no_remove linker option to disable unused section elimination.


Static variables can also be marked as used, by using __attribute__((used)).


static int lose_this(int);
static int keep_this(int) __attribute__((used));     // retained in object file
static int keep_this_too(int) __attribute__((used)); // retained in object file
Non-ConfidentialPDF file icon PDF versionDUI0774J
Copyright © 2014–2017, 2019 Arm Limited or its affiliates. All rights reserved.