Keil Logo

ARM: HOW TO RETAIN DATA IN OBJECT FILE


Information in this article applies to:

  • MDK-ARM 4.10 and above

QUESTION

How do I keep data in my output image regardless of whether they are referenced or not like a constant version number or checksum?

SOLUTION

Append the USED attribute to your constant. Please refer to the example below:

        unsigned const int checksum __attribute__((used)) = 0x12345678;

The same attribute can also be used for static function to avoid removal from the object file.

NOTE

Static variables marked as used are emitted to a single section, in the order they are declared. Please refer to the following example:

  static char a1;   /* at offset 0 */
  static int  b1;   /* at offset 4 */
  static char c1;   /* this will be placed at offset 1 to exploit the gap  */

  /* these ones will not only be kept but also not reordered */
  static char a2 __attribute__((used));   /* at offset 0 */
  static int  b2 __attribute__((used));   /* at offset 4 */
  static char c2 __attribute__((used));   /* at offset 8 */

You can specify the section that variables are placed in using __attribute__((section)).

MORE INFORMATION

SEE ALSO

Last Reviewed: Wednesday, January 25, 2017


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.