title: GCC ignores __attribute__((section("CCMRAM"))). How to fix?
body: <p>I am trying to use core-coupled memory (CCMRAM) of my cortex-m4 (STM32F407). It works fine with Keil MDK-ARM but gcc-arm-none-eabi ignores <code>__attribute__((section(&quot;CCMRAM&quot;)))</code>.</p>
  <pre><code> #define configTOTAL_HEAP_SIZE 1000*1024
   #define region1_HEAP_SIZE  (40*1024)
   #define region2_HEAP_SIZE  (configTOTAL_HEAP_SIZE - region1_HEAP_SIZE)
  
   static uint8_t ucHeap1[ region1_HEAP_SIZE ]  __attribute__((section(&quot;CCMRAM&quot;)));
   static uint8_t ucHeap2[ region2_HEAP_SIZE ];
   const HeapRegion_t xHeapRegions[] =
   {
       { ucHeap1, sizeof(ucHeap1) },
       { ucHeap2, sizeof(ucHeap2) },
       { NULL, 0 } /* Terminates the array. */
   };
  </code></pre>
  <p>Manual <a href="https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes" rel="nofollow noreferrer">https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes</a></p>
  <p>According to manual I also tried to initialize <code>ucHeap1</code></p>
  <pre><code> static uint8_t ucHeap1[ region1_HEAP_SIZE ]  __attribute__((section(&quot;CCMRAM&quot;))) = {0};
  </code></pre>
  <p>But does no effect.</p>
  <p>Map-file contains nothing about <code>ucHeap1</code>. GCC compiles with no warnings about attribute. But fail to link because of:</p>
  <pre><code>arm-none-eabi/bin/ld: avds.elf section `.bss' will not fit in region `RAM'
  arm-none-eabi/bin/ld: region `RAM' overflowed by 55032 bytes
  </code></pre>
  <p>These 55032 should be allocated in CCMRAM. But it tries to use RAM.
  Please help me to understand what to do to make it work.</p>
  <p>Linker script:</p>
  <pre><code>ENTRY(Reset_Handler)
  _estack = 0x20000000 + 128K - 1;
  _Min_Heap_Size = 0;
  _Min_Stack_Size = 0x200;
  MEMORY
  {
    FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 1024K
    RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 128K
    CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K
  }
  SECTIONS
  {
    .isr_vector :
    {
      . = ALIGN(4);
      KEEP(*(.isr_vector))
      . = ALIGN(4);
    } &gt;FLASH
    .text :
    {
      . = ALIGN(4);
      *(.text)
      *(.text*)
      *(.glue_7)
      *(.glue_7t)
      *(.eh_frame)
      KEEP (*(.init))
      KEEP (*(.fini))
      . = ALIGN(4);
      _etext = .;
    } &gt;FLASH
    .rodata :
    {
      . = ALIGN(4);
      *(.rodata)
      *(.rodata*)
      . = ALIGN(4);
    } &gt;FLASH
    .ARM.extab   : { *(.ARM.extab* .gnu.linkonce.armextab.*) } &gt;FLASH
    .ARM : {
      __exidx_start = .;
      *(.ARM.exidx*)
      __exidx_end = .;
    } &gt;FLASH
    .preinit_array     :
    {
      PROVIDE_HIDDEN (__preinit_array_start = .);
      KEEP (*(.preinit_array*))
      PROVIDE_HIDDEN (__preinit_array_end = .);
    } &gt;FLASH
    .init_array :
    {
      PROVIDE_HIDDEN (__init_array_start = .);
      KEEP (*(SORT(.init_array.*)))
      KEEP (*(.init_array*))
      PROVIDE_HIDDEN (__init_array_end = .);
    } &gt;FLASH
    .fini_array :
    {
      PROVIDE_HIDDEN (__fini_array_start = .);
      KEEP (*(SORT(.fini_array.*)))
      KEEP (*(.fini_array*))
      PROVIDE_HIDDEN (__fini_array_end = .);
    } &gt;FLASH
    _sidata = LOADADDR(.data);
    .data : 
    {
      . = ALIGN(4);
      _sdata = .;
      *(.data)
      *(.data*)
      . = ALIGN(4);
      _edata = .;
    } &gt;RAM AT&gt; FLASH
    _siccmram = LOADADDR(.ccmram);
    .ccmram :
    {    . = ALIGN(4);
      _sccmram = .;
      *(.ccmram)
      *(.ccmram*)
      . = ALIGN(4);
      _eccmram = .;
    } &gt;CCMRAM AT&gt; FLASH
    . = ALIGN(4);
    .bss :
    {
      _sbss = .;
      __bss_start__ = _sbss;
      *(.bss)
      *(.bss*)
      *(COMMON)
      . = ALIGN(4);
      _ebss = .;
      __bss_end__ = _ebss;
    } &gt;RAM
    ._user_heap_stack :
    {
      . = ALIGN(4);
      PROVIDE ( end = . );
      PROVIDE ( _end = . );
      . = . + _Min_Heap_Size;
      . = . + _Min_Stack_Size;
      . = ALIGN(4);
    } &gt;RAM
    /DISCARD/ :
    {
      libc.a ( * )
      libm.a ( * )
      libgcc.a ( * )
    }
    .ARM.attributes 0 : { *(.ARM.attributes) }
  }
  </code></pre>