Key points to note while porting CodeWarrior (CW) Linker Command File (LCF) to GCC Linker Script File or GCC Linker Description (LD) File.
Example:
CW LCF: #Default linker command file.
GCC LD: /*Default linker command file.*/
CW LCF:
MEMORY { segmentName (accessFlags) : ORIGIN = address, LENGTH = length [> fileName] } segment_1 (RWX): ORIGIN = 0x80001000, LENGTH = 0x19000 [>filename] is not compliant with GNU syntaxGCC LD:
MEMORY { segmentName [(attr)] : ORIGIN = address, LENGTH = length ... }Example:
CW LCF: KEEP_SECTION { .vectortable } GCC LD: SECTIONS { .interrupts : { __vector_table = .; KEEP (*(.vectortable)) . = ALIGN (0x4); } > m_interrupts }Example:
CW LCF: .app_text: GCC LD: .app_text : { }Example:
.app_text : { . = ALIGN(0x4) ; * (.init) * (.text) * (.text*) . = ALIGN(0x8) ; * (.rodata) * (.rodata*) . = ALIGN(0x4) ; ___ROM_AT = .; } > m_textExample:
CW LCF: . = ALIGN(0x4); GCCC LD: .= ALIGN(0x4);Example:
CW LCF: .bss : { } >> m_data GCC LD: .bss : { } > m_dataExample:
CW LCF: WRITEW(0); GCC LD: LONG(0);Example:
CW LCF: *(.ARM.extab) . = ALIGN(0x4) ; __exception_table_start__ = .; EXCEPTION __exception_table_end__ = .; . = ALIGN(0x4) ; GCC LD: __exidx_start = .; *(.ARM.exidx*) __exidx_end = .;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_textCW LCF:
.my_text{ INCLUDE filename }>my_textGCC LD:
Equivalent syntax in GCC LD,
INPUT(file, file, ...) INPUT(file file ...)Command line options to include binary file [default section as .data.]
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_sizeThe default linker section will be .data.
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
}
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.