ARM Technical Support Knowledge Articles

How do I write code portable between ARM Compiler 5 and ARM Compiler 6 for the __at sections?

Applies to: DS-5

Scenario

ARM Compiler 5 (armcc) supports the compiler-specific variable attribute __attribute__(at(address)). This attribute places a target variable in a dedicated section and put the section at a specific absolute address. However, ARM Compiler 6 (armclang) does not support this attribute.  

Therefore, how can I write code to implement the same functionality in ARM Compiler 6, while making the code portable between ARM Compiler 5 and ARM Compiler 6?  

Answer

The variable attribute __attribute__ (at(address)) is not supported in ARM Compiler 6. However, the linker (armlink) in ARM Compiler 6 still supports the placement of sections in the form of .ARM.__at_address. With the variable attribute __attribute__((section("name"))), you can implement the same function as the original __attribute__(at(address)).

Example: The following code places the variable at the absolute address 0x20004000 in both ARM Compiler 5 and ARM Compiler 6:

   // Place the variable at the address 0x20004000
   __attribute__((section(".ARM.__at_0x20004000")))  \
   unsigned int g_wDemo = 0x12345678;

NOTE: If you want to place only the target variable at a specific address without affecting its following variables, you must use the attribute on the same line with the variable definition. 

To make the example code portable between ARM Compiler 5 and ARM Compiler 6, perform the following steps:

  1. Define a macro.

   #define __AT(__ADDR)     __attribute__((section(".ARM.__at_" #__ADDR)))
   #define AT_ADDR(__ADDR)  __AT(__ADDR)

  2. Modify the example code.

   // Place the variable at the address 0x20004000
   AT_ADDR(0x20004000)  unsigned int g_wDemo = 0x12345678;

You can implement the macro correspondingly to improve the code portability between ARM Compilers and other third-party toolchains. 

Related information:

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential