LCF Porting

Key points to note while porting CodeWarrior (CW) Linker Command File (LCF) to GCC Linker Script File or GCC Linker Description (LD) File.

  1. LCF comments start with #. Use C style (/* */) comments in case of LD file.

    Example:

    CW LCF: #Default linker command file.

    GCC LD: /*Default linker command file.*/

  2. Access flags (RWX) are same between CW LCF and GCC LD. However GCC LD supports more access flags.

    CW LCF:

    MEMORY { segmentName (accessFlags) : ORIGIN = address, LENGTH = length [> fileName] } segment_1 (RWX): ORIGIN = 0x80001000, LENGTH = 0x19000 [>filename] is not compliant with GNU syntax

    GCC LD:

    MEMORY { segmentName [(attr)] : ORIGIN = address, LENGTH = length ... }
  3. AFTER(m_text) does not work with GCC LD.
  4. KEEP_SECTION : CW LCF command 'KEEP_SECTION' is supported outside 'SECTIONS'. GCC LD equivalent command is 'KEEP'. However this should be used inside 'SECTIONS' directive.

    Example:

    CW LCF: KEEP_SECTION { .vectortable } GCC LD: SECTIONS { .interrupts : { __vector_table = .; KEEP (*(.vectortable)) . = ALIGN (0x4); } > m_interrupts }
  5. GCC LD file should have section name and ':' separated by a space.

    Example:

    CW LCF: .app_text: GCC LD: .app_text : { }
  6. Add * (.text*) and * (.rodata*) in .app_text in case of GCC LD.

    Example:

    .app_text : { . = ALIGN(0x4) ; * (.init) * (.text) * (.text*) . = ALIGN(0x8) ; * (.rodata) * (.rodata*) . = ALIGN(0x4) ; ___ROM_AT = .; } > m_text
  7. Remove ALIGNALL command as it is not supported in GCC LD.
  8. In case of GCC LD, allow a space between '.' And '=' in case of '.= ALIGN'.

    Example:

    CW LCF: . = ALIGN(0x4); GCCC LD: .= ALIGN(0x4);
  9. >> is not supported in GCC LD.

    Example:

    CW LCF: .bss : { } >> m_data GCC LD: .bss : { } > m_data
  10. WRITEW command should be replaced by LONG .

    Example:

    CW LCF: WRITEW(0); GCC LD: LONG(0);
  11. ARM.extab section in CW LCF should be ported to GCC LD.

    Example:

    CW LCF: *(.ARM.extab) . = ALIGN(0x4) ; __exception_table_start__ = .; EXCEPTION __exception_table_end__ = .; . = ALIGN(0x4) ; GCC LD: __exidx_start = .; *(.ARM.exidx*) __exidx_end = .;
  12. Remove STATICINIT in case of GCC LD.
  13. Define segment for sections like .ctors, .dtors, .preinit_array, init_array, .fini_array, in GCC LD.

    Example:

    .ctors : { __CTOR_LIST__ = .; KEEP (*crtbegin.o(.ctors)) KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors)) KEEP (*(SORT(.ctors.*))) KEEP (*(.ctors)) __CTOR_END__ = .; } > m_text .dtors : { __DTOR_LIST__ = .; KEEP (*crtbegin.o(.dtors)) KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors)) KEEP (*(SORT(.dtors.*))) KEEP (*(.dtors)) __DTOR_END__ = .; } > m_text .preinit_array : { PROVIDE_HIDDEN (__preinit_array_start = .); KEEP (*(.preinit_array*)) PROVIDE_HIDDEN (__preinit_array_end = .); } > m_text .init_array : { PROVIDE_HIDDEN (__init_array_start = .); KEEP (*(SORT(.init_array.*))) KEEP (*(.init_array*)) PROVIDE_HIDDEN (__init_array_end = .); } > m_text .fini_array : { PROVIDE_HIDDEN (__fini_array_start = .); KEEP (*(SORT(.fini_array.*))) KEEP (*(.fini_array*)) PROVIDE_HIDDEN (__fini_array_end = .); ___ROM_AT = .; } > m_text
  14. INCLUDE filename

    CW LCF:

    .my_text{ INCLUDE filename }>my_text

    GCC LD:

    Equivalent syntax in GCC LD,

    INPUT(file, file, ...) INPUT(file file ...)

    Command line options to include binary file [default section as .data.]

    Note: Binary filename: data.raw, Format: binary
    1. Create a stationary project.
    2. Go to Properties > C/C++Build > Settings > ARM Ltd. Windows GCC C Linker > Miscellaneous > Other flags
    3. Add the following options. -Wl,-b,binary,"C:/data.raw",-b,elf32-littlearm

      This makes linker to treat data.raw as raw binary and resume to elf32-littlearm for subsequent objects.

      The final elf will contain the following symbols for the sources to manipulate the data:

      _binary_C___data_raw_start _binary_C___data_raw_end _binary_C__data_raw_size

      The default linker section will be .data.

    To place the raw data in a specified linker section, define the section in the Linker command file.
    1. Define the following section.
      
      MEMORY{
      
      ..
      
      m_srecord     (RX) : ORIGIN = 0x0000C000, LENGTH = 0x00004000/*define its memory segment*/
      
      }
      
      TARGET(binary)/* specify the file format of binary file */
      
      INPUT (data.raw)/* provide the file name */
      
      OUTPUT_FORMAT(default)/* restore the out file format */
      
      /* Define output sections */
      
      SECTIONS
      
      {
      
      
      .srecord :
      
        {
      
          
      
       data.raw (.data)
      
          . = ALIGN (0x4);
      
        } > m_srecord
      
      .text:
      
      {
      
      ..
      
      }>m_text
      
      
      
      }
      
      
    2. Add the path of the file added in the previous step to ARM Ltd. GCC C Linker->Libraries->Library search path (-L)
      Figure 1. ARM Ltd. GCC C Linker->Libraries->Library search path (-L)
      ARM Ltd. GCC C Linker->Libraries->Library search path (-L)

INCLUDE filename is also supported in GCC LD but for a different purpose INCLUDE filename Include the linker script filename at this point. The file will be searched for in the current directory, and in any directory specified with the '-L' option. You can nest calls to INCLUDE up to 10 levels deep. You can place INCLUDE directives at the top level, in MEMORY or SECTIONS commands, or in output section descriptions.