1/* Script for -pie */
2/* Copyright (C) 2014-2021 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("elf32-littlearm", "elf32-bigarm",
7	      "elf32-littlearm")
8OUTPUT_ARCH(arm)
9ENTRY(_start)
10SEARCH_DIR("=/aarch64-none-linux-gnu/lib"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib");
11SECTIONS
12{
13  /* Read-only sections, merged into text segment: */
14  PROVIDE (__executable_start = SEGMENT_START("text-segment", 0)); . = SEGMENT_START("text-segment", 0) + SIZEOF_HEADERS;
15  .interp         : { *(.interp) }
16  .note.gnu.build-id  : { *(.note.gnu.build-id) }
17  .hash           : { *(.hash) }
18  .gnu.hash       : { *(.gnu.hash) }
19  .dynsym         : { *(.dynsym) }
20  .dynstr         : { *(.dynstr) }
21  .gnu.version    : { *(.gnu.version) }
22  .gnu.version_d  : { *(.gnu.version_d) }
23  .gnu.version_r  : { *(.gnu.version_r) }
24  .rel.init       : { *(.rel.init) }
25  .rela.init      : { *(.rela.init) }
26  .rel.text       : { *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) }
27  .rela.text      : { *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) }
28  .rel.fini       : { *(.rel.fini) }
29  .rela.fini      : { *(.rela.fini) }
30  .rel.rodata     : { *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) }
31  .rela.rodata    : { *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) }
32  .rel.data.rel.ro   : { *(.rel.data.rel.ro .rel.data.rel.ro.* .rel.gnu.linkonce.d.rel.ro.*) }
33  .rela.data.rel.ro   : { *(.rela.data.rel.ro .rela.data.rel.ro.* .rela.gnu.linkonce.d.rel.ro.*) }
34  .rel.data       : { *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) }
35  .rela.data      : { *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) }
36  .rel.tdata	  : { *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) }
37  .rela.tdata	  : { *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) }
38  .rel.tbss	  : { *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) }
39  .rela.tbss	  : { *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) }
40  .rel.ctors      : { *(.rel.ctors) }
41  .rela.ctors     : { *(.rela.ctors) }
42  .rel.dtors      : { *(.rel.dtors) }
43  .rela.dtors     : { *(.rela.dtors) }
44  .rel.got        : { *(.rel.got) }
45  .rela.got       : { *(.rela.got) }
46  .rel.bss        : { *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) }
47  .rela.bss       : { *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) }
48  .rel.iplt       :
49    {
50      *(.rel.iplt)
51    }
52  .rela.iplt      :
53    {
54      *(.rela.iplt)
55    }
56  .rel.plt        :
57    {
58      *(.rel.plt)
59    }
60  .rela.plt       :
61    {
62      *(.rela.plt)
63    }
64  .init           :
65  {
66    KEEP (*(SORT_NONE(.init)))
67  }
68  .plt            : { *(.plt) }
69  .iplt           : { *(.iplt) }
70  .text           :
71  {
72    *(.text.unlikely .text.*_unlikely .text.unlikely.*)
73    *(.text.exit .text.exit.*)
74    *(.text.startup .text.startup.*)
75    *(.text.hot .text.hot.*)
76    *(SORT(.text.sorted.*))
77    *(.text .stub .text.* .gnu.linkonce.t.*)
78    /* .gnu.warning sections are handled specially by elf.em.  */
79    *(.gnu.warning)
80    *(.glue_7t) *(.glue_7) *(.vfp11_veneer) *(.v4_bx)
81  }
82  .fini           :
83  {
84    KEEP (*(SORT_NONE(.fini)))
85  }
86  PROVIDE (__etext = .);
87  PROVIDE (_etext = .);
88  PROVIDE (etext = .);
89  .rodata         : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
90  .rodata1        : { *(.rodata1) }
91  .ARM.extab   : { *(.ARM.extab* .gnu.linkonce.armextab.*) }
92  .ARM.exidx   :
93    {
94      PROVIDE_HIDDEN (__exidx_start = .);
95      *(.ARM.exidx* .gnu.linkonce.armexidx.*)
96      PROVIDE_HIDDEN (__exidx_end = .);
97    }
98  .eh_frame_hdr   : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
99  .eh_frame       : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
100  .gcc_except_table   : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
101  .gnu_extab   : ONLY_IF_RO { *(.gnu_extab*) }
102  /* These sections are generated by the Sun/Oracle C++ compiler.  */
103  .exception_ranges   : ONLY_IF_RO { *(.exception_ranges*) }
104  /* Adjust the address for the data segment.  We want to adjust up to
105     the same address within the page on the next page up.  */
106  . = ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1));
107  /* Exception handling  */
108  .eh_frame       : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
109  .gnu_extab      : ONLY_IF_RW { *(.gnu_extab) }
110  .gcc_except_table   : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
111  .exception_ranges   : ONLY_IF_RW { *(.exception_ranges*) }
112  /* Thread Local Storage sections  */
113  .tdata	  :
114   {
115     PROVIDE_HIDDEN (__tdata_start = .);
116     *(.tdata .tdata.* .gnu.linkonce.td.*)
117   }
118  .tbss		  : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
119  .preinit_array    :
120  {
121    PROVIDE_HIDDEN (__preinit_array_start = .);
122    KEEP (*(.preinit_array))
123    PROVIDE_HIDDEN (__preinit_array_end = .);
124  }
125  .init_array    :
126  {
127    PROVIDE_HIDDEN (__init_array_start = .);
128    KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
129    KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
130    PROVIDE_HIDDEN (__init_array_end = .);
131  }
132  .fini_array    :
133  {
134    PROVIDE_HIDDEN (__fini_array_start = .);
135    KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
136    KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
137    PROVIDE_HIDDEN (__fini_array_end = .);
138  }
139  .ctors          :
140  {
141    /* gcc uses crtbegin.o to find the start of
142       the constructors, so we make sure it is
143       first.  Because this is a wildcard, it
144       doesn't matter if the user does not
145       actually link against crtbegin.o; the
146       linker won't look for a file to match a
147       wildcard.  The wildcard also means that it
148       doesn't matter which directory crtbegin.o
149       is in.  */
150    KEEP (*crtbegin.o(.ctors))
151    KEEP (*crtbegin?.o(.ctors))
152    /* We don't want to include the .ctor section from
153       the crtend.o file until after the sorted ctors.
154       The .ctor section from the crtend file contains the
155       end of ctors marker and it must be last */
156    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
157    KEEP (*(SORT(.ctors.*)))
158    KEEP (*(.ctors))
159  }
160  .dtors          :
161  {
162    KEEP (*crtbegin.o(.dtors))
163    KEEP (*crtbegin?.o(.dtors))
164    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
165    KEEP (*(SORT(.dtors.*)))
166    KEEP (*(.dtors))
167  }
168  .jcr            : { KEEP (*(.jcr)) }
169  .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
170  .dynamic        : { *(.dynamic) }
171  .got            : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) }
172  .data           :
173  {
174    __data_start = .;
175    *(.data .data.* .gnu.linkonce.d.*)
176    SORT(CONSTRUCTORS)
177  }
178  .data1          : { *(.data1) }
179  _edata = .; PROVIDE (edata = .);
180  /* This section contains data that is initialized during load,
181     but not during the application's initialization sequence.  */
182  .persistent :
183  {
184    . = ALIGN(32 / 8);
185    PROVIDE (__persistent_start = .);
186    *(.persistent .persistent.* .gnu.linkonce.p.*)
187    . = ALIGN(32 / 8);
188    PROVIDE (__persistent_end = .);
189  }
190  . = .;
191  __bss_start = .;
192  __bss_start__ = .;
193  .bss            :
194  {
195   *(.dynbss)
196   *(.bss .bss.* .gnu.linkonce.b.*)
197   *(COMMON)
198   /* Align here to ensure that the .bss section occupies space up to
199      _end.  Align after .bss to ensure correct alignment even if the
200      .bss section disappears because there are no input sections.
201      FIXME: Why do we need it? When there is no .bss section, we do not
202      pad the .data section.  */
203   . = ALIGN(. != 0 ? 32 / 8 : 1);
204  }
205  _bss_end__ = .; __bss_end__ = .;
206  /* This section contains data that is not initialized during load,
207     or during the application's initialization sequence.  */
208  .noinit (NOLOAD) :
209  {
210    . = ALIGN(32 / 8);
211    PROVIDE (__noinit_start = .);
212    *(.noinit .noinit.* .gnu.linkonce.n.*)
213    . = ALIGN(32 / 8);
214    PROVIDE (__noinit_end = .);
215  }
216  . = ALIGN(32 / 8);
217  . = SEGMENT_START("ldata-segment", .);
218  . = ALIGN(32 / 8);
219  __end__ = .;
220  _end = .; PROVIDE (end = .);
221  .stack         0x80000 :
222  {
223    _stack = .;
224    *(.stack)
225  }
226  /* Stabs debugging sections.  */
227  .stab          0 : { *(.stab) }
228  .stabstr       0 : { *(.stabstr) }
229  .stab.excl     0 : { *(.stab.excl) }
230  .stab.exclstr  0 : { *(.stab.exclstr) }
231  .stab.index    0 : { *(.stab.index) }
232  .stab.indexstr 0 : { *(.stab.indexstr) }
233  .comment       0 : { *(.comment) }
234  .gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
235  /* DWARF debug sections.
236     Symbols in the DWARF debugging sections are relative to the beginning
237     of the section so we begin them at 0.  */
238  /* DWARF 1.  */
239  .debug          0 : { *(.debug) }
240  .line           0 : { *(.line) }
241  /* GNU DWARF 1 extensions.  */
242  .debug_srcinfo  0 : { *(.debug_srcinfo) }
243  .debug_sfnames  0 : { *(.debug_sfnames) }
244  /* DWARF 1.1 and DWARF 2.  */
245  .debug_aranges  0 : { *(.debug_aranges) }
246  .debug_pubnames 0 : { *(.debug_pubnames) }
247  /* DWARF 2.  */
248  .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
249  .debug_abbrev   0 : { *(.debug_abbrev) }
250  .debug_line     0 : { *(.debug_line .debug_line.* .debug_line_end) }
251  .debug_frame    0 : { *(.debug_frame) }
252  .debug_str      0 : { *(.debug_str) }
253  .debug_loc      0 : { *(.debug_loc) }
254  .debug_macinfo  0 : { *(.debug_macinfo) }
255  /* SGI/MIPS DWARF 2 extensions.  */
256  .debug_weaknames 0 : { *(.debug_weaknames) }
257  .debug_funcnames 0 : { *(.debug_funcnames) }
258  .debug_typenames 0 : { *(.debug_typenames) }
259  .debug_varnames  0 : { *(.debug_varnames) }
260  /* DWARF 3.  */
261  .debug_pubtypes 0 : { *(.debug_pubtypes) }
262  .debug_ranges   0 : { *(.debug_ranges) }
263  /* DWARF 5.  */
264  .debug_addr     0 : { *(.debug_addr) }
265  .debug_line_str 0 : { *(.debug_line_str) }
266  .debug_loclists 0 : { *(.debug_loclists) }
267  .debug_macro    0 : { *(.debug_macro) }
268  .debug_names    0 : { *(.debug_names) }
269  .debug_rnglists 0 : { *(.debug_rnglists) }
270  .debug_str_offsets 0 : { *(.debug_str_offsets) }
271  .debug_sup      0 : { *(.debug_sup) }
272  .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }
273  .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }
274  /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
275}
276