1# Linker Script for National Semiconductor's CRX-ELF32. 2 3# The next line should be uncommented if it is desired to link 4# without libstart.o and directly enter main. 5 6# ENTRY=_main 7 8test -z "$ENTRY" && ENTRY=_start 9cat <<EOF 10 11/* Example Linker Script for linking NS CRX elf32 files. */ 12 13/* The next line forces the entry point (${ENTRY} in this script) 14 to be entered in the output file as an undefined symbol. 15 It is needed in case the entry point is not called explicitly 16 (which is the usual case) AND is in an archive. */ 17 18OUTPUT_FORMAT("${OUTPUT_FORMAT}") 19OUTPUT_ARCH(${ARCH}) 20EXTERN(${ENTRY}) 21ENTRY(${ENTRY}) 22 23/* Define memory regions. */ 24MEMORY 25{ 26 rom : ORIGIN = 0x2, LENGTH = 3M 27 ram : ORIGIN = 4M, LENGTH = 10M 28} 29 30/* Many sections come in three flavours. There is the 'real' section, 31 like ".data". Then there are the per-procedure or per-variable 32 sections, generated by -ffunction-sections and -fdata-sections in GCC, 33 and useful for --gc-sections, which for a variable "foo" might be 34 ".data.foo". Then there are the linkonce sections, for which the linker 35 eliminates duplicates, which are named like ".gnu.linkonce.d.foo". 36 The exact correspondences are: 37 38 Section Linkonce section 39 .text .gnu.linkonce.t.foo 40 .rdata .gnu.linkonce.r.foo 41 .data .gnu.linkonce.d.foo 42 .bss .gnu.linkonce.b.foo 43 .debug_info .gnu.linkonce.wi.foo */ 44 45SECTIONS 46{ 47 .init : 48 { 49 __INIT_START = .; 50 KEEP (*(.init)) 51 __INIT_END = .; 52 } > rom 53 54 .fini : 55 { 56 __FINI_START = .; 57 KEEP (*(.fini)) 58 __FINI_END = .; 59 } > rom 60 61 .jcr : 62 { 63 KEEP (*(.jcr)) 64 } > rom 65 66 .text : 67 { 68 __TEXT_START = .; 69 *(.text) *(.text.*) *(.gnu.linkonce.t.*) 70 __TEXT_END = .; 71 } > rom 72 73 .rdata : 74 { 75 __RDATA_START = .; 76 *(.rdata_4) *(.rdata_2) *(.rdata_1) *(.rdata.*) *(.gnu.linkonce.r.*) *(.rodata.*) 77 __RDATA_END = .; 78 } > rom 79 80 .ctor ALIGN(4) : 81 { 82 __CTOR_START = .; 83 /* The compiler uses crtbegin.o to find the start 84 of the constructors, so we make sure it is 85 first. Because this is a wildcard, it 86 doesn't matter if the user does not 87 actually link against crtbegin.o; the 88 linker won't look for a file to match a 89 wildcard. The wildcard also means that it 90 doesn't matter which directory crtbegin.o 91 is in. */ 92 93 KEEP (*crtbegin*.o(.ctors)) 94 95 /* We don't want to include the .ctor section from 96 the crtend.o file until after the sorted ctors. 97 The .ctor section from the crtend file contains the 98 end of ctors marker and it must be last */ 99 100 KEEP (*(EXCLUDE_FILE (*crtend*.o) .ctors)) 101 KEEP (*(SORT(.ctors.*))) 102 KEEP (*(.ctors)) 103 __CTOR_END = .; 104 } > rom 105 106 .dtor ALIGN(4) : 107 { 108 __DTOR_START = .; 109 KEEP (*crtbegin*.o(.dtors)) 110 KEEP (*(EXCLUDE_FILE (*crtend*.o) .dtors)) 111 KEEP (*(SORT(.dtors.*))) 112 KEEP (*(.dtors)) 113 __DTOR_END = .; 114 } > rom 115 116 .data : 117 { 118 __DATA_START = .; 119 *(.data_4) *(.data_2) *(.data_1) *(.data) *(.data.*) *(.gnu.linkonce.d.*) 120 __DATA_END = .; 121 } > ram AT > rom 122 123 .bss (NOLOAD) : 124 { 125 __BSS_START = .; 126 *(.bss_4) *(.bss_2) *(.bss_1) *(.bss) *(COMMON) *(.bss.*) *(.gnu.linkonce.b.*) 127 __BSS_END = .; 128 } > ram 129 130/* You may change the sizes of the following sections to fit the actual 131 size your program requires. 132 133 The heap and stack are aligned to the bus width, as a speed optimization 134 for accessing data located there. */ 135 136 .heap : 137 { 138 . = ALIGN(4); 139 __HEAP_START = .; 140 . += 0x2000; __HEAP_MAX = .; 141 } > ram 142 143 .stack : 144 { 145 . = ALIGN(4); 146 . += 0x6000; 147 __STACK_START = .; 148 } > ram 149 150 .istack : 151 { 152 . = ALIGN(4); 153 . += 0x100; 154 __ISTACK_START = .; 155 } > ram 156 157 .comment 0 : { *(.comment) } 158 159 /* DWARF debug sections. 160 Symbols in the DWARF debugging sections are relative to the beginning 161 of the section so we begin them at 0. */ 162 163 .debug_aranges 0 : { *(.debug_aranges) } 164 .debug_pubnames 0 : { *(.debug_pubnames) } 165 .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } 166 .debug_abbrev 0 : { *(.debug_abbrev) } 167 .debug_line 0 : { *(.debug_line) } 168 .debug_frame 0 : { *(.debug_frame) } 169 .debug_str 0 : { *(.debug_str) } 170 .debug_loc 0 : { *(.debug_loc) } 171 .debug_macinfo 0 : { *(.debug_macinfo) } 172} 173 174__DATA_IMAGE_START = LOADADDR(.data); 175EOF 176