Search code examples
ceclipsegnuldnxp-microcontroller

How to implement custom output section in GNU LD?


I'm trying to figure out how to define a custom output section in my application's LD file. So far, this is what I've come up with...

MEMORY
{
  ...
  m_my_custom_section (RW)  : ORIGIN = 0x00002400, LENGTH = 0x00000400
  ...
}

SECTIONS
{
  ...
  .my_custom_section :
  {
    . = ALIGN(4);
    KEEP(*(.my_custom_section))
    . = ALIGN(4);
  } > m_my_custom_section
  ...
}

Unfortunately, that's where I'm stuck. I'm unsure how to specify which parts of my code I want assigned to that section when the application links. Any help would be great. :)


Solution

  • I believe I found the answer here in @Mike Kinghan's comment:

    In Standard C or C++ there are no syntactic means to define sections. Section definition normally is entirely the compiler's business. A compiler may have non-standard extensions that let you assign an object to a named section. For GCC see the documentation of __attribute__ ((section ("<section-name>"))) in Common Variable Attributes and Common Function Attributes Such extensions are for specialized purposes.