1/*
2 * Copyright (c) 2006-2023, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Date           Author       Notes
7 * 2017-5-30      bernard      first version
8 */
9
10#include "rtconfig.h"
11
12OUTPUT_FORMAT("elf64-littleaarch64", "elf64-littleaarch64", "elf64-littleaarch64")
13OUTPUT_ARCH(aarch64)
14
15#ifndef ARCH_TEXT_OFFSET
16#define ARCH_TEXT_OFFSET 0x200000   /* We always boot in address where is 2MB aligned */
17#endif
18
19#ifndef ARCH_RAM_OFFSET
20#define ARCH_RAM_OFFSET 0
21#endif
22
23PHDRS
24{
25    text PT_LOAD FLAGS(5);   /* PF_R(4) | PF_X(1) = 0x5 (RX) */
26    data PT_LOAD FLAGS(6);   /* PF_R(4) | PF_W(2) = 0x6 (RW) */
27    stack PT_LOAD FLAGS(6);  /* PF_R | PF_W */
28}
29
30SECTIONS
31{
32    _text_offset = ARCH_TEXT_OFFSET;
33
34#ifdef RT_USING_SMART
35    . = KERNEL_VADDR_START + _text_offset;
36#else
37    . = ARCH_RAM_OFFSET + _text_offset;
38#endif
39
40    .text :
41    {
42        PROVIDE(__text_start = .);
43
44        KEEP(*(.text.entrypoint))       /* The entry point */
45        *(.vectors)
46        *(.text)                        /* remaining code */
47        *(.text.*)                      /* remaining code */
48
49        *(.rodata)                      /* read-only data (constants) */
50        *(.rodata*)
51        *(.glue_7)
52        *(.glue_7t)
53        *(.gnu.linkonce.t*)
54
55        /* section information for utest */
56        . = ALIGN(8);
57        PROVIDE(__rt_utest_tc_tab_start = .);
58        KEEP(*(UtestTcTab))
59        PROVIDE(__rt_utest_tc_tab_end = .);
60
61        /* section information for finsh shell */
62        . = ALIGN(8);
63        PROVIDE(__fsymtab_start = .);
64        KEEP(*(FSymTab))
65        PROVIDE(__fsymtab_end = .);
66        . = ALIGN(8);
67        PROVIDE(__vsymtab_start = .);
68        KEEP(*(VSymTab))
69        PROVIDE(__vsymtab_end = .);
70        . = ALIGN(8);
71
72        /* section information for modules */
73        . = ALIGN(8);
74        PROVIDE(__rtmsymtab_start = .);
75        KEEP(*(RTMSymTab))
76        PROVIDE(__rtmsymtab_end = .);
77
78        /* section information for initialization */
79        . = ALIGN(8);
80        PROVIDE(__rt_init_start = .);
81        KEEP(*(SORT(.rti_fn*)))
82        PROVIDE(__rt_init_end = .);
83
84        /* section information for rt_ofw. */
85        . = ALIGN(16);
86        PROVIDE(__rt_ofw_data_start = .);
87        KEEP(*(SORT(.rt_ofw_data.*)))
88        PROVIDE(__rt_ofw_data_end = .);
89        . = ALIGN(16);
90
91        /* section information for usb usbh_class_info */
92        . = ALIGN(4);
93        __usbh_class_info_start__ = .;
94        KEEP(*(.usbh_class_info))
95        . = ALIGN(4);
96        __usbh_class_info_end__ = .;
97
98        PROVIDE(__text_end = .);
99    } :text
100
101    .eh_frame_hdr :
102    {
103        *(.eh_frame_hdr)
104        *(.eh_frame_entry)
105    }
106    .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }
107
108    . = ALIGN(8);
109    .data :
110    {
111        *(.data)
112        *(.data.*)
113
114        *(.data1)
115        *(.data1.*)
116
117        . = ALIGN(16);
118        _gp = ABSOLUTE(.);     /* Base of small data */
119
120        *(.sdata)
121        *(.sdata.*)
122        *(.rel.local)
123    } :data
124
125    . = ALIGN(8);
126    .ctors :
127    {
128        PROVIDE(__ctors_start__ = .);
129        /* new GCC version uses .init_array */
130        KEEP(*(SORT(.init_array.*)))
131        KEEP(*(.init_array))
132        PROVIDE(__ctors_end__ = .);
133    }
134
135    .dtors :
136    {
137        PROVIDE(__dtors_start__ = .);
138        KEEP(*(SORT(.dtors.*)))
139        KEEP(*(.dtors))
140        PROVIDE(__dtors_end__ = .);
141    }
142
143    . = ALIGN(16);
144    .bss :
145    {
146        /*
147         * We need some free space to page or cpu stack, move .bss.noclean.*
148         * to optimize size.
149         */
150        PROVIDE(__bss_noclean_start = .);
151        *(.bss.noclean.*)
152        PROVIDE(__bss_noclean_end = .);
153        . = ALIGN(8);
154        PROVIDE(__bss_start = .);
155        *(.bss)
156        *(.bss.*)
157        *(.dynbss)
158        *(COMMON)
159        . = ALIGN(8);
160        PROVIDE(__bss_end = .);
161    }
162
163    /*
164     * We should make the bootloader know the size of memory we need,
165     * so we MUST calc the image's size with section '.bss'.
166     */
167    _end = .;
168
169    /* Stabs debugging sections.  */
170    .stab          0 : { *(.stab) }
171    .stabstr       0 : { *(.stabstr) }
172    .stab.excl     0 : { *(.stab.excl) }
173    .stab.exclstr  0 : { *(.stab.exclstr) }
174    .stab.index    0 : { *(.stab.index) }
175    .stab.indexstr 0 : { *(.stab.indexstr) }
176    .comment       0 : { *(.comment) }
177    /* DWARF debug sections.
178     * Symbols in the DWARF debugging sections are relative to the beginning
179     * of the section so we begin them at 0.  */
180    /* DWARF 1 */
181    .debug          0 : { *(.debug) }
182    .line           0 : { *(.line) }
183    /* GNU DWARF 1 extensions */
184    .debug_srcinfo  0 : { *(.debug_srcinfo) }
185    .debug_sfnames  0 : { *(.debug_sfnames) }
186    /* DWARF 1.1 and DWARF 2 */
187    .debug_aranges  0 : { *(.debug_aranges) }
188    .debug_pubnames 0 : { *(.debug_pubnames) }
189    /* DWARF 2 */
190    .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
191    .debug_abbrev   0 : { *(.debug_abbrev) }
192    .debug_line     0 : { *(.debug_line) }
193    .debug_frame    0 : { *(.debug_frame) }
194    .debug_str      0 : { *(.debug_str) }
195    .debug_loc      0 : { *(.debug_loc) }
196    .debug_macinfo  0 : { *(.debug_macinfo) }
197    /* SGI/MIPS DWARF 2 extensions */
198    .debug_weaknames 0 : { *(.debug_weaknames) }
199    .debug_funcnames 0 : { *(.debug_funcnames) }
200    .debug_typenames 0 : { *(.debug_typenames) }
201    .debug_varnames  0 : { *(.debug_varnames) }
202
203    __data_size = SIZEOF(.data);
204    __bss_size = SIZEOF(.bss);
205}
206