ld: MEMORY

1 
1 3.7 MEMORY Command
1 ==================
1 
1 The linker's default configuration permits allocation of all available
1 memory.  You can override this by using the 'MEMORY' command.
1 
1    The 'MEMORY' command describes the location and size of blocks of
1 memory in the target.  You can use it to describe which memory regions
1 may be used by the linker, and which memory regions it must avoid.  You
1 can then assign sections to particular memory regions.  The linker will
1 set section addresses based on the memory regions, and will warn about
1 regions that become too full.  The linker will not shuffle sections
1 around to fit into the available regions.
1 
1    A linker script may contain many uses of the 'MEMORY' command,
1 however, all memory blocks defined are treated as if they were specified
1 inside a single 'MEMORY' command.  The syntax for 'MEMORY' is:
1      MEMORY
1        {
1          NAME [(ATTR)] : ORIGIN = ORIGIN, LENGTH = LEN
1          ...
1        }
1 
1    The NAME is a name used in the linker script to refer to the region.
1 The region name has no meaning outside of the linker script.  Region
1 names are stored in a separate name space, and will not conflict with
1 symbol names, file names, or section names.  Each memory region must
1 have a distinct name within the 'MEMORY' command.  However you can add
11 later alias names to existing memory regions with the ⇒
 REGION_ALIAS command.
1 
1    The ATTR string is an optional list of attributes that specify
1 whether to use a particular memory region for an input section which is
11 not explicitly mapped in the linker script.  As described in ⇒
 SECTIONS, if you do not specify an output section for some input
1 section, the linker will create an output section with the same name as
1 the input section.  If you define region attributes, the linker will use
1 them to select the memory region for the output section that it creates.
1 
1    The ATTR string must consist only of the following characters:
1 'R'
1      Read-only section
1 'W'
1      Read/write section
1 'X'
1      Executable section
1 'A'
1      Allocatable section
1 'I'
1      Initialized section
1 'L'
1      Same as 'I'
1 '!'
1      Invert the sense of any of the attributes that follow
1 
1    If a unmapped section matches any of the listed attributes other than
1 '!', it will be placed in the memory region.  The '!' attribute reverses
1 this test, so that an unmapped section will be placed in the memory
1 region only if it does not match any of the listed attributes.
1 
1    The ORIGIN is an numerical expression for the start address of the
1 memory region.  The expression must evaluate to a constant and it cannot
1 involve any symbols.  The keyword 'ORIGIN' may be abbreviated to 'org'
1 or 'o' (but not, for example, 'ORG').
1 
1    The LEN is an expression for the size in bytes of the memory region.
1 As with the ORIGIN expression, the expression must be numerical only and
1 must evaluate to a constant.  The keyword 'LENGTH' may be abbreviated to
1 'len' or 'l'.
1 
1    In the following example, we specify that there are two memory
1 regions available for allocation: one starting at '0' for 256 kilobytes,
1 and the other starting at '0x40000000' for four megabytes.  The linker
1 will place into the 'rom' memory region every section which is not
1 explicitly mapped into a memory region, and is either read-only or
1 executable.  The linker will place other sections which are not
1 explicitly mapped into a memory region into the 'ram' memory region.
1 
1      MEMORY
1        {
1          rom (rx)  : ORIGIN = 0, LENGTH = 256K
1          ram (!rx) : org = 0x40000000, l = 4M
1        }
1 
1    Once you define a memory region, you can direct the linker to place
1 specific output sections into that memory region by using the '>REGION'
1 output section attribute.  For example, if you have a memory region
1 named 'mem', you would use '>mem' in the output section definition.
1 ⇒Output Section Region.  If no address was specified for the
1 output section, the linker will set the address to the next available
1 address within the memory region.  If the combined output sections
1 directed to a memory region are too large for the region, the linker
1 will issue an error message.
1 
1    It is possible to access the origin and length of a memory in an
1 expression via the 'ORIGIN(MEMORY)' and 'LENGTH(MEMORY)' functions:
1 
1        _fstack = ORIGIN(ram) + LENGTH(ram) - 4;
1