8.11.1 Address Variable Attribute

The address(addr) attribute specifies an absolute virtual address for the variable. This attribute can be used in conjunction with a section attribute.

Note: For a data variable on a target device without an L1 cache, the address is typically in the range [0xA0000000,0xA00FFFFC], as defined in the linker script as the kseg1_data_mem region. For data variables on a target feature an L1 data cache, the address is typically in the range [0x80000000,0x800FFFFC] as defined in the linker script as the kseg0_data_mem region. Take special care to use the correct kseg region for your device or more than one variable might be allocated to the same physical address.
The address attribute can be used to start a group of variables at a specific address:
  int foo __attribute__((section("mysection"),address(0xA0001000)));
  int bar __attribute__((section("mysection")));
  int baz __attribute__((section("mysection")));

Keep in mind that the compiler performs no error checking on the specified address. The section will be located at the specified address regardless of the memory-region ranges listed in the linker script or the actual ranges on the target device. This application code is responsible for ensuring that the address is valid for the target device and application.

Also, be aware that variables attributed with an absolute address are not accessed via GP-relative addressing. This means that they may be more expensive to access than non-address attributed variables.

Sections used to hold objects placed at an absolute address will use a name .address.N.decl, where N is the address and decl is the name of the declaration.

In addition, to make effective use of absolute sections and the best-fit allocator, standard program-memory and data-memory sections should not be mapped in the linker script. The built-in linker script does not map most standard sections such as the .text, .data, .bss, or .ramfunc section. By not mapping these sections in the linker script, we allow these sections to be allocated using the best-fit allocator rather than the sequential allocator. Sections that are unmapped in the linker script can flow around absolute sections whereas sections that are linker-script mapped are grouped together and allocated sequentially, potentially causing conflicts with absolute sections.

Finally, note that “small” data and bss (.sdata, .sbss, etc.) sections are still mapped in the built-in default linker script. This is because “small” data variables must be grouped together so that they are within range of the more efficient GP-relative addressing mode. To avoid conflict with these linker-script mapped sections, choose high addresses for your absolute-address variables.

Note: In almost all cases, you will want to combine the address attribute with the space attribute to indicate code or data with space(prog) or space(data), respectively. Also, see the description for the attribute space.