xref: /linux/arch/riscv/kernel/vmlinux.lds.S (revision 0e685c3e7158d35626d6d76b9f859eae806d87fa)
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (C) 2012 Regents of the University of California
4 * Copyright (C) 2017 SiFive
5 */
6
7#define RO_EXCEPTION_TABLE_ALIGN	4
8#define RUNTIME_DISCARD_EXIT
9
10#ifdef CONFIG_XIP_KERNEL
11#include "vmlinux-xip.lds.S"
12#else
13
14#include <asm/pgtable.h>
15#define LOAD_OFFSET KERNEL_LINK_ADDR
16
17#include <asm/vmlinux.lds.h>
18#include <asm/page.h>
19#include <asm/cache.h>
20#include <asm/thread_info.h>
21#include <asm/set_memory.h>
22#include "image-vars.h"
23
24#include <linux/sizes.h>
25OUTPUT_ARCH(riscv)
26ENTRY(_start)
27
28jiffies = jiffies_64;
29
30PECOFF_SECTION_ALIGNMENT = 0x1000;
31PECOFF_FILE_ALIGNMENT = 0x200;
32
33SECTIONS
34{
35	/* Beginning of code and text segment */
36	. = LOAD_OFFSET;
37	_start = .;
38	HEAD_TEXT_SECTION
39	. = ALIGN(PAGE_SIZE);
40
41	.text : {
42		_text = .;
43		_stext = .;
44		TEXT_TEXT
45		SCHED_TEXT
46		LOCK_TEXT
47		KPROBES_TEXT
48		ENTRY_TEXT
49		IRQENTRY_TEXT
50		SOFTIRQENTRY_TEXT
51		_etext = .;
52	}
53
54	. = ALIGN(SECTION_ALIGN);
55	__init_begin = .;
56	__init_text_begin = .;
57	.init.text : AT(ADDR(.init.text) - LOAD_OFFSET) ALIGN(SECTION_ALIGN) { \
58		_sinittext = .;						\
59		INIT_TEXT						\
60		_einittext = .;						\
61	}
62
63	. = ALIGN(8);
64	__soc_early_init_table : {
65		__soc_early_init_table_start = .;
66		KEEP(*(__soc_early_init_table))
67		__soc_early_init_table_end = .;
68	}
69	__soc_builtin_dtb_table : {
70		__soc_builtin_dtb_table_start = .;
71		KEEP(*(__soc_builtin_dtb_table))
72		__soc_builtin_dtb_table_end = .;
73	}
74	/* we have to discard exit text and such at runtime, not link time */
75	.exit.text :
76	{
77		EXIT_TEXT
78	}
79
80	__init_text_end = .;
81	. = ALIGN(SECTION_ALIGN);
82#ifdef CONFIG_EFI
83	. = ALIGN(PECOFF_SECTION_ALIGNMENT);
84	__pecoff_text_end = .;
85#endif
86	/* Start of init data section */
87	__init_data_begin = .;
88	INIT_DATA_SECTION(16)
89	.init.bss : {
90		*(.init.bss)	/* from the EFI stub */
91	}
92	.exit.data :
93	{
94		EXIT_DATA
95	}
96	PERCPU_SECTION(L1_CACHE_BYTES)
97
98	.rel.dyn : {
99		*(.rel.dyn*)
100	}
101
102	.rela.dyn : {
103		*(.rela*)
104	}
105
106	__init_data_end = .;
107
108	. = ALIGN(8);
109	.alternative : {
110		__alt_start = .;
111		*(.alternative)
112		__alt_end = .;
113	}
114	__init_end = .;
115
116	/* Start of data section */
117	_sdata = .;
118	RO_DATA(SECTION_ALIGN)
119	.srodata : {
120		*(.srodata*)
121	}
122
123	. = ALIGN(SECTION_ALIGN);
124	_data = .;
125
126	RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
127	.sdata : {
128		__global_pointer$ = . + 0x800;
129		*(.sdata*)
130	}
131
132#ifdef CONFIG_EFI
133	.pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
134	__pecoff_data_raw_size = ABSOLUTE(. - __pecoff_text_end);
135#endif
136
137	/* End of data section */
138	_edata = .;
139
140	BSS_SECTION(PAGE_SIZE, PAGE_SIZE, 0)
141
142#ifdef CONFIG_EFI
143	. = ALIGN(PECOFF_SECTION_ALIGNMENT);
144	__pecoff_data_virt_size = ABSOLUTE(. - __pecoff_text_end);
145#endif
146	_end = .;
147
148	STABS_DEBUG
149	DWARF_DEBUG
150	ELF_DETAILS
151	.riscv.attributes 0 : { *(.riscv.attributes) }
152
153	DISCARDS
154}
155#endif /* CONFIG_XIP_KERNEL */
156