xref: /openbsd/sys/arch/riscv64/conf/kern.ldscript (revision 5dea098c)
1/*	$OpenBSD: kern.ldscript,v 1.4 2022/01/07 13:56:54 kevlo Exp $	*/
2
3OUTPUT_ARCH(riscv64)
4
5/* Define how we want our ELF binary to look like. */
6PHDRS
7{
8	text PT_LOAD;
9	rodata PT_LOAD FLAGS (4);
10	data PT_LOAD;
11	openbsd_randomize PT_OPENBSD_RANDOMIZE;
12}
13
14__ALIGN_SIZE = 0x200000;
15__kernel_base = @KERNEL_BASE_VIRT@;
16
17ENTRY(_start)
18SECTIONS
19{
20	. = __kernel_base;
21	PROVIDE (__text_start = .);
22	.text :
23	{
24		*(.text .text.*)
25		*(.stub)
26	} :text =0
27	PROVIDE (_etext = .);
28	PROVIDE (etext = .);
29
30	/* Move rodata to the next page, so we can nuke X and W bit on it */
31	. = ALIGN(__ALIGN_SIZE);
32	PROVIDE (__rodata_start = .);
33	.rodata :
34	{
35		*(.rodata .rodata.*)
36	} :rodata
37	.openbsd.randomdata :
38	{
39		*(.openbsd.randomdata)
40	} :openbsd_randomize :rodata
41	PROVIDE (_erodata = .);
42
43	/* Move .data to the next page, so we can add W bit on it */
44	. = ALIGN(__ALIGN_SIZE);
45	PROVIDE (__data_start = .);
46	.got :
47	{
48		*(.got .got.*)
49	} :data
50	.data :
51	{
52		*(.data .data.*)
53	} :data
54	.sdata :
55	{
56		*(.sdata .sdata.*)
57	} :data
58	PROVIDE (_edata = .);
59
60	. = ALIGN(8);
61	PROVIDE (__bss_start = .);
62	.sbss :
63	{
64		*(.dynsbss)
65		*(.sbss)
66		*(.sbss.*)
67		*(.scommon)
68	} :data
69	.bss :
70	{
71		*(.dynbss)
72		*(.bss)
73		*(.bss.*)
74		*(COMMON)
75		/* Align here to ensure that the .bss section occupies space up to
76		   _end.  Align after .bss to ensure correct alignment even if the
77		   .bss section disappears because there are no input sections.  */
78		. = ALIGN(8);
79	} :data
80	PROVIDE (_end = .);
81	PROVIDE (end = .);
82}
83