blob: 3a8ae32ab0653dc924425c9bf2bbb5785d2e4f2b [file] [log] [blame]
Ben Cheng7823f2a2014-04-08 14:53:42 -07001/* Script for -pie -z combreloc -z now -z relro: position independent executable, combine & sort relocs */
Rong Xue1a8a482015-04-08 12:48:42 -07002/* Copyright (C) 2014 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. */
Ben Cheng7823f2a2014-04-08 14:53:42 -07006OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64",
7 "elf64-littleaarch64")
8OUTPUT_ARCH(aarch64)
9ENTRY(_start)
Ben Cheng7823f2a2014-04-08 14:53:42 -070010SECTIONS
11{
12 /* Read-only sections, merged into text segment: */
Ben Cheng79781f52014-05-19 10:33:46 -070013 PROVIDE (__executable_start = 0); . = 0 + SIZEOF_HEADERS;
Ben Cheng7823f2a2014-04-08 14:53:42 -070014 .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.bss .rela.bss.* .rela.gnu.linkonce.b.*)
36 *(.rela.ifunc)
37 }
38 .rela.plt :
39 {
40 *(.rela.plt)
41 PROVIDE_HIDDEN (__rela_iplt_start = .);
42 *(.rela.iplt)
43 PROVIDE_HIDDEN (__rela_iplt_end = .);
44 }
45 .init :
46 {
47 KEEP (*(SORT_NONE(.init)))
48 } =0
49 .plt : ALIGN(16) { *(.plt) *(.iplt) }
50 .text :
51 {
52 *(.text.unlikely .text.*_unlikely .text.unlikely.*)
53 *(.text.exit .text.exit.*)
54 *(.text.startup .text.startup.*)
55 *(.text.hot .text.hot.*)
56 *(.text .stub .text.* .gnu.linkonce.t.*)
57 /* .gnu.warning sections are handled specially by elf32.em. */
58 *(.gnu.warning)
59 } =0
60 .fini :
61 {
62 KEEP (*(SORT_NONE(.fini)))
63 } =0
64 PROVIDE (__etext = .);
65 PROVIDE (_etext = .);
66 PROVIDE (etext = .);
67 .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
68 .rodata1 : { *(.rodata1) }
69 .eh_frame_hdr : { *(.eh_frame_hdr) }
70 .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }
71 .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table
72 .gcc_except_table.*) }
73 /* These sections are generated by the Sun/Oracle C++ compiler. */
74 .exception_ranges : ONLY_IF_RO { *(.exception_ranges
75 .exception_ranges*) }
Ben Cheng79781f52014-05-19 10:33:46 -070076 /* Adjust the address for the data segment. For 32 bits we want to align
77 at exactly a page boundary to make life easier for apriori. */
Ben Cheng7823f2a2014-04-08 14:53:42 -070078 . = ALIGN (CONSTANT (MAXPAGESIZE)) - ((CONSTANT (MAXPAGESIZE) - .) & (CONSTANT (MAXPAGESIZE) - 1)); . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
79 /* Exception handling */
80 .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }
81 .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
82 .exception_ranges : ONLY_IF_RW { *(.exception_ranges .exception_ranges*) }
83 /* Thread Local Storage sections */
84 .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }
85 .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
Ben Cheng79781f52014-05-19 10:33:46 -070086 /* Ensure the __preinit_array_start label is properly aligned. We
87 could instead move the label definition inside the section, but
88 the linker would then create the section even if it turns out to
89 be empty, which isn't pretty. */
Rong Xua1f277f2014-09-05 13:42:16 -070090 . = ALIGN(64 / 8);
Ben Cheng79781f52014-05-19 10:33:46 -070091 PROVIDE_HIDDEN (__preinit_array_start = .);
Ben Cheng7823f2a2014-04-08 14:53:42 -070092 .preinit_array :
93 {
Ben Cheng7823f2a2014-04-08 14:53:42 -070094 KEEP (*(.preinit_array))
Ben Cheng7823f2a2014-04-08 14:53:42 -070095 }
Ben Cheng79781f52014-05-19 10:33:46 -070096 PROVIDE_HIDDEN (__preinit_array_end = .);
97 PROVIDE_HIDDEN (__init_array_start = .);
Ben Cheng7823f2a2014-04-08 14:53:42 -070098 .init_array :
99 {
Ben Cheng79781f52014-05-19 10:33:46 -0700100 KEEP (*crtbegin*.o(.init_array))
Ben Cheng7823f2a2014-04-08 14:53:42 -0700101 KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
Ben Cheng79781f52014-05-19 10:33:46 -0700102 KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin*.o *crtend.o *crtend*.o ) .ctors))
Ben Cheng7823f2a2014-04-08 14:53:42 -0700103 }
Ben Cheng79781f52014-05-19 10:33:46 -0700104 PROVIDE_HIDDEN (__init_array_end = .);
105 PROVIDE_HIDDEN (__fini_array_start = .);
Ben Cheng7823f2a2014-04-08 14:53:42 -0700106 .fini_array :
107 {
Ben Cheng79781f52014-05-19 10:33:46 -0700108 KEEP (*crtbegin*.o(.fini_array))
Ben Cheng7823f2a2014-04-08 14:53:42 -0700109 KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
Ben Cheng79781f52014-05-19 10:33:46 -0700110 KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin*.o *crtend.o *crtend*.o ) .dtors))
Ben Cheng7823f2a2014-04-08 14:53:42 -0700111 }
Ben Cheng79781f52014-05-19 10:33:46 -0700112 PROVIDE_HIDDEN (__fini_array_end = .);
Ben Cheng7823f2a2014-04-08 14:53:42 -0700113 .ctors :
114 {
115 /* gcc uses crtbegin.o to find the start of
116 the constructors, so we make sure it is
117 first. Because this is a wildcard, it
118 doesn't matter if the user does not
119 actually link against crtbegin.o; the
120 linker won't look for a file to match a
121 wildcard. The wildcard also means that it
122 doesn't matter which directory crtbegin.o
123 is in. */
124 KEEP (*crtbegin.o(.ctors))
Ben Cheng79781f52014-05-19 10:33:46 -0700125 KEEP (*crtbegin*.o(.ctors))
Ben Cheng7823f2a2014-04-08 14:53:42 -0700126 /* We don't want to include the .ctor section from
127 the crtend.o file until after the sorted ctors.
128 The .ctor section from the crtend file contains the
129 end of ctors marker and it must be last */
Ben Cheng79781f52014-05-19 10:33:46 -0700130 KEEP (*(EXCLUDE_FILE (*crtend.o *crtend*.o ) .ctors))
Ben Cheng7823f2a2014-04-08 14:53:42 -0700131 KEEP (*(SORT(.ctors.*)))
132 KEEP (*(.ctors))
133 }
134 .dtors :
135 {
136 KEEP (*crtbegin.o(.dtors))
Ben Cheng79781f52014-05-19 10:33:46 -0700137 KEEP (*crtbegin*.o(.dtors))
138 KEEP (*(EXCLUDE_FILE (*crtend.o *crtend*.o ) .dtors))
Ben Cheng7823f2a2014-04-08 14:53:42 -0700139 KEEP (*(SORT(.dtors.*)))
140 KEEP (*(.dtors))
141 }
142 .jcr : { KEEP (*(.jcr)) }
143 .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
144 .dynamic : { *(.dynamic) }
145 .got : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) }
146 . = DATA_SEGMENT_RELRO_END (0, .);
147 .data :
148 {
149 PROVIDE (__data_start = .);
150 *(.data .data.* .gnu.linkonce.d.*)
151 SORT(CONSTRUCTORS)
152 }
153 .data1 : { *(.data1) }
154 _edata = .; PROVIDE (edata = .);
155 . = .;
156 __bss_start = .;
157 __bss_start__ = .;
158 .bss :
159 {
160 *(.dynbss)
161 *(.bss .bss.* .gnu.linkonce.b.*)
162 *(COMMON)
163 /* Align here to ensure that the .bss section occupies space up to
164 _end. Align after .bss to ensure correct alignment even if the
Ben Cheng79781f52014-05-19 10:33:46 -0700165 .bss section disappears because there are no input sections. */
166 . = ALIGN(64 / 8);
Ben Cheng7823f2a2014-04-08 14:53:42 -0700167 }
168 _bss_end__ = . ; __bss_end__ = . ;
169 . = ALIGN(64 / 8);
170 . = SEGMENT_START("ldata-segment", .);
171 . = ALIGN(64 / 8);
172 __end__ = . ;
Ben Cheng79781f52014-05-19 10:33:46 -0700173 _end = .;
174 _bss_end__ = . ; __bss_end__ = . ; __end__ = . ;
175 PROVIDE (end = .);
Ben Cheng7823f2a2014-04-08 14:53:42 -0700176 . = DATA_SEGMENT_END (.);
177 /* Stabs debugging sections. */
178 .stab 0 : { *(.stab) }
179 .stabstr 0 : { *(.stabstr) }
180 .stab.excl 0 : { *(.stab.excl) }
181 .stab.exclstr 0 : { *(.stab.exclstr) }
182 .stab.index 0 : { *(.stab.index) }
183 .stab.indexstr 0 : { *(.stab.indexstr) }
184 .comment 0 : { *(.comment) }
185 /* DWARF debug sections.
186 Symbols in the DWARF debugging sections are relative to the beginning
187 of the section so we begin them at 0. */
188 /* DWARF 1 */
189 .debug 0 : { *(.debug) }
190 .line 0 : { *(.line) }
191 /* GNU DWARF 1 extensions */
192 .debug_srcinfo 0 : { *(.debug_srcinfo) }
193 .debug_sfnames 0 : { *(.debug_sfnames) }
194 /* DWARF 1.1 and DWARF 2 */
195 .debug_aranges 0 : { *(.debug_aranges) }
196 .debug_pubnames 0 : { *(.debug_pubnames) }
197 /* DWARF 2 */
198 .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
199 .debug_abbrev 0 : { *(.debug_abbrev) }
200 .debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end ) }
201 .debug_frame 0 : { *(.debug_frame) }
202 .debug_str 0 : { *(.debug_str) }
203 .debug_loc 0 : { *(.debug_loc) }
204 .debug_macinfo 0 : { *(.debug_macinfo) }
205 /* SGI/MIPS DWARF 2 extensions */
206 .debug_weaknames 0 : { *(.debug_weaknames) }
207 .debug_funcnames 0 : { *(.debug_funcnames) }
208 .debug_typenames 0 : { *(.debug_typenames) }
209 .debug_varnames 0 : { *(.debug_varnames) }
210 /* DWARF 3 */
211 .debug_pubtypes 0 : { *(.debug_pubtypes) }
212 .debug_ranges 0 : { *(.debug_ranges) }
213 /* DWARF Extension. */
214 .debug_macro 0 : { *(.debug_macro) }
215 .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }
216 .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }
Ben Cheng79781f52014-05-19 10:33:46 -0700217 /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) *(.mdebug.*) }
Ben Cheng7823f2a2014-04-08 14:53:42 -0700218}