1OUTPUT_FORMAT("elf%BITS%-littleriscv") 2/* 3 * LK linker script for multi segment binaries. 4 * In this case the read only portion of the binary lives in read only 5 * memory, usually in ROM at a lower address. 6 * Data and BSS live in a higher memory address and initial data is 7 * copied from rom during initialization. 8 */ 9PHDRS 10{ 11 code PT_LOAD FLAGS(5); /* PF_R|PF_X */ 12 rodata PT_LOAD FLAGS(4); /* PF_R */ 13 data PT_LOAD FLAGS(6); /* PF_R|PF_W */ 14} 15 16ENTRY(_start) 17SECTIONS 18{ 19 . = %ROMBASE%; 20 21 _start = .; 22 __rom_start = .; 23 24 /* text/read-only data */ 25 /* set the load address to physical MEMBASE */ 26 .text : { 27 KEEP(*(.text.boot)) 28 *(.text .text*) 29 *(.gnu.linkonce.t.*) 30 } :code 31 32 . = ALIGN(CONSTANT(MAXPAGESIZE)); 33 34 .rodata : { 35 __rodata_start = .; 36 *(.rodata .rodata.* .gnu.linkonce.r.*) 37 } :rodata 38 39 /* trick to force any extra sections to be emitted here */ 40 . = .; 41 42 __rodata_end = .; 43 __rom_end = . ; 44 . = ALIGN(CONSTANT(MAXPAGESIZE)); 45 __data_start_rom = .; 46 47 /* insert a dummy section that is used to anchor the following data segment */ 48 .dummy_post_rodata : { } 49 50 /* in two segment binaries, the data starts at the bottom of ram (MEMBASE) 51 * bump us forward to the start of ram 52 */ 53 . = %MEMBASE%; 54 55 .data : AT ( ADDR (.dummy_post_rodata) ) { 56 __data_start = .; 57 *(.data .data.* .gnu.linkonce.d.*) 58 __ctor_list = .; 59 KEEP(*(.ctors .init_array)) 60 __ctor_end = .; 61 __dtor_list = .; 62 KEEP(*(.dtors .fini_array)) 63 __dtor_end = .; 64 *(.got*) 65 *(.dynamic) 66 } :data 67 68 /* Try to put sdata and sbss near each other by putting sdata at the end of the data segment 69 * and sbss at the start of the bss segment. This maximizes reach of things referenced off of 70 * the global pointer. */ 71 .sdata : { 72 __global_pointer$ = . + (4K / 2); 73 /* Question: should we put srodata here on multi seg binaries? */ 74 *(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata .srodata.*) 75 *(.sdata .sdata.* .gnu.linkonce.s.*) 76 } 77 78 . = ALIGN(%BITS% / 8); 79 __data_end = .; 80 __bss_start = .; 81 82 .sbss : { 83 *(.dynsbss) 84 *(.sbss .sbss.* .gnu.linkonce.sb.*) 85 *(.scommon) 86 } 87 88 /* uninitialized data (in same segment as writable data) */ 89 .bss : { 90 /* regular bss */ 91 *(.bss .bss.*) 92 *(.gnu.linkonce.b.*) 93 } 94 95 . = ALIGN(%BITS% / 8); 96 __bss_end = .; 97 98 /* Align the end to ensure anything after the kernel ends up on its own pages */ 99 . = ALIGN(CONSTANT(MAXPAGESIZE)); 100 _end = .; 101 102 . = %MEMBASE% + %MEMSIZE%; 103 _end_of_ram = .; 104 105 /* Strip unnecessary stuff */ 106 /DISCARD/ : { *(.comment .note .eh_frame) } 107} 108 109