1/* Script for -z combreloc: combine and sort reloc sections */ 2/* Copyright (C) 2014-2017 Free Software Foundation, Inc. 3 * Copying and distribution of this script, with or without modification, 4 * are permitted in any medium without royalty provided the copyright 5 * notice and this notice are preserved. */ 6OUTPUT_FORMAT("elf64-littleriscv", "elf64-littleriscv", "elf64-littleriscv") 7OUTPUT_ARCH(riscv) 8 9ENTRY(_start) 10SECTIONS 11{ 12 . = 0x80000000 + SIZEOF_HEADERS; 13 14 .interp : { *(.interp) } 15 .note.gnu.build-id : { *(.note.gnu.build-id) } 16 .hash : { *(.hash) } 17 .gnu.hash : { *(.gnu.hash) } 18 .dynsym : { *(.dynsym) } 19 .dynstr : { *(.dynstr) } 20 .gnu.version : { *(.gnu.version) } 21 .gnu.version_d : { *(.gnu.version_d) } 22 .gnu.version_r : { *(.gnu.version_r) } 23 .rela.dyn : 24 { 25 *(.rela.init) 26 *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) 27 *(.rela.fini) 28 *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) 29 *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) 30 *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) 31 *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) 32 *(.rela.ctors) 33 *(.rela.dtors) 34 *(.rela.got) 35 *(.rela.sdata .rela.sdata.* .rela.gnu.linkonce.s.*) 36 *(.rela.sbss .rela.sbss.* .rela.gnu.linkonce.sb.*) 37 *(.rela.sdata2 .rela.sdata2.* .rela.gnu.linkonce.s2.*) 38 *(.rela.sbss2 .rela.sbss2.* .rela.gnu.linkonce.sb2.*) 39 *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) 40 PROVIDE_HIDDEN (__rela_iplt_start = .); 41 *(.rela.iplt) 42 PROVIDE_HIDDEN (__rela_iplt_end = .); 43 } 44 .rela.plt : 45 { 46 *(.rela.plt) 47 } 48 .init : 49 { 50 KEEP (*(SORT_NONE(.init))) 51 } 52 .plt : { *(.plt) } 53 .iplt : { *(.iplt) } 54 .text : 55 { 56 *(.text.unlikely .text.*_unlikely .text.unlikely.*) 57 *(.text.exit .text.exit.*) 58 *(.text.startup .text.startup.*) 59 *(.text.hot .text.hot.*) 60 *(.text .stub .text.* .gnu.linkonce.t.*) 61 /* .gnu.warning sections are handled specially by elf32.em. */ 62 *(.gnu.warning) 63 } 64 .fini : 65 { 66 KEEP (*(SORT_NONE(.fini))) 67 } 68 PROVIDE (__etext = .); 69 PROVIDE (_etext = .); 70 PROVIDE (etext = .); 71 .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } 72 .rodata1 : { *(.rodata1) } 73 .sdata2 : 74 { 75 *(.sdata2 .sdata2.* .gnu.linkonce.s2.*) 76 } 77 .sbss2 : { *(.sbss2 .sbss2.* .gnu.linkonce.sb2.*) } 78 .eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) } 79 .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) } 80 .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table 81 .gcc_except_table.*) } 82 .gnu_extab : ONLY_IF_RO { *(.gnu_extab*) } 83 /* Adjust the address for the data segment. We want to adjust up to 84 * the same address within the page on the next page up. */ 85 . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE)); 86 /* Exception handling */ 87 .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) } 88 .gnu_extab : ONLY_IF_RW { *(.gnu_extab) } 89 .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } 90 .exception_ranges : ONLY_IF_RW { *(.exception_ranges .exception_ranges*) } 91 /* Thread Local Storage sections */ 92 .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } 93 .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } 94 .preinit_array : 95 { 96 PROVIDE_HIDDEN (__preinit_array_start = .); 97 KEEP (*(.preinit_array)) 98 PROVIDE_HIDDEN (__preinit_array_end = .); 99 } 100 .init_array : 101 { 102 PROVIDE_HIDDEN (__init_array_start = .); 103 KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) 104 KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors)) 105 PROVIDE_HIDDEN (__init_array_end = .); 106 } 107 .fini_array : 108 { 109 PROVIDE_HIDDEN (__fini_array_start = .); 110 KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*))) 111 KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors)) 112 PROVIDE_HIDDEN (__fini_array_end = .); 113 } 114 .ctors : 115 { 116 /* gcc uses crtbegin.o to find the start of 117 * the constructors, so we make sure it is 118 * first. Because this is a wildcard, it 119 * doesn't matter if the user does not 120 * actually link against crtbegin.o; the 121 * linker won't look for a file to match a 122 * wildcard. The wildcard also means that it 123 * doesn't matter which directory crtbegin.o 124 * is in. */ 125 KEEP (*crtbegin.o(.ctors)) 126 KEEP (*crtbegin?.o(.ctors)) 127 /* We don't want to include the .ctor section from 128 * the crtend.o file until after the sorted ctors. 129 * The .ctor section from the crtend file contains the 130 * end of ctors marker and it must be last */ 131 KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) 132 KEEP (*(SORT(.ctors.*))) 133 KEEP (*(.ctors)) 134 } 135 .dtors : 136 { 137 KEEP (*crtbegin.o(.dtors)) 138 KEEP (*crtbegin?.o(.dtors)) 139 KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) 140 KEEP (*(SORT(.dtors.*))) 141 KEEP (*(.dtors)) 142 } 143 .jcr : { KEEP (*(.jcr)) } 144 .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) } 145 .dynamic : { *(.dynamic) } 146 . = DATA_SEGMENT_RELRO_END (0, .); 147 .data : 148 { 149 *(.data .data.* .gnu.linkonce.d.*) 150 SORT(CONSTRUCTORS) 151 } 152 .data1 : { *(.data1) } 153 .got : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) } 154 /* We want the small data sections together, so single-instruction offsets 155 * can access them all, and initialized data all before uninitialized, so 156 * we can shorten the on-disk segment size. */ 157 .sdata : 158 { 159 __global_pointer$ = . + 0x800; 160 *(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata .srodata.*) 161 *(.sdata .sdata.* .gnu.linkonce.s.*) 162 } 163 _edata = .; PROVIDE (edata = .); 164 . = .; 165 __bss_start = .; 166 .sbss : 167 { 168 *(.dynsbss) 169 *(.sbss .sbss.* .gnu.linkonce.sb.*) 170 *(.scommon) 171 } 172 .bss : 173 { 174 *(.dynbss) 175 *(.bss .bss.* .gnu.linkonce.b.*) 176 *(COMMON) 177 /* Align here to ensure that the .bss section occupies space up to 178 * _end. Align after .bss to ensure correct alignment even if the 179 * .bss section disappears because there are no input sections. 180 * FIXME: Why do we need it? When there is no .bss section, we don't 181 * pad the .data section. */ 182 . = ALIGN(. != 0 ? 64 / 8 : 1); 183 } 184 . = ALIGN(64 / 8); 185 . = SEGMENT_START("ldata-segment", .); 186 . = ALIGN(64 / 8); 187 _end = .; PROVIDE (end = .); 188 . = DATA_SEGMENT_END (.); 189 /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) } 190} 191