Files
lk/arch/riscv/linker-onesegment.ld
Lei Wen 145e9a0d27 [arch] fix link script not include global array init
Using wild match init_array* to include global array init ctor

Before:

 10 .ctors             00000040 ffff0000001e6b80 00000000401e6b80 DATA
 11 .dtors             00000000 ffff0000001e6bc0 00000000401e6bc0 DATA
 12 .got               00000060 ffff0000001e6bc0 00000000401e6bc0 DATA
 13 .init_array.1      00000470 ffff0000001e6c20 00000000401e6c20
 14 .fini_array.1      00000470 ffff0000001e7090 00000000401e7090
 15 .dummy_post_data   00000000 ffff0000001e7500 00000000401e7500 DATA
 16 .bss               00009460 ffff0000001e8000 00000000401e8000 BSS

After:

 10 .ctors             000004b0 ffff0000001e6b80 00000000401e6b80 DATA
 11 .dtors             00000470 ffff0000001e7030 00000000401e7030
 12 .got               00000060 ffff0000001e74a0 00000000401e74a0 DATA
 13 .dummy_post_data   00000000 ffff0000001e7500 00000000401e7500 DATA
 14 .bss               00009460 ffff0000001e8000 00000000401e8000 BSS

Signed-off-by: Lei Wen <leiwen@asrmicro.com>
2025-09-29 22:40:41 -07:00

96 lines
2.2 KiB
Plaintext

OUTPUT_FORMAT("elf%BITS%-littleriscv")
/*
* LK linker script for single segment binaries.
*/
PHDRS
{
code PT_LOAD FLAGS(5); /* PF_R|PF_X */
rodata PT_LOAD FLAGS(4); /* PF_R */
data PT_LOAD FLAGS(6); /* PF_R|PF_W */
}
ENTRY(_start)
SECTIONS
{
. = %KERNEL_BASE% + %KERNEL_LOAD_OFFSET%;
_start = .;
__rom_start = .;
/* text/read-only data */
/* set the load address to physical MEMBASE */
.text : AT(%MEMBASE% + %KERNEL_LOAD_OFFSET%) {
KEEP(*(.text.boot))
*(.text .text*)
*(.gnu.linkonce.t.*)
} :code
. = ALIGN(CONSTANT(MAXPAGESIZE));
.rodata : {
__rodata_start = .;
*(.rodata .rodata.* .gnu.linkonce.r.*)
} :rodata
/* trick to force any extra sections to be emitted here */
. = .;
__rodata_end = .;
__rom_end = . ;
. = ALIGN(CONSTANT(MAXPAGESIZE));
__data_start_rom = .;
.data : {
__data_start = .;
*(.data .data.* .gnu.linkonce.d.*)
__ctor_list = .;
KEEP(*(.ctors .init_array*))
__ctor_end = .;
__dtor_list = .;
KEEP(*(.dtors .fini_array*))
__dtor_end = .;
*(.got*)
*(.dynamic)
} :data
/* Try to put sdata and sbss near each other by putting sdata at the end of the data segment
* and sbss at the start of the bss segment. This maximizes reach of things referenced off of
* the global pointer. */
.sdata : {
__global_pointer$ = . + (4K / 2);
*(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata .srodata.*)
*(.sdata .sdata.* .gnu.linkonce.s.*)
}
. = ALIGN(%BITS% / 8);
__data_end = .;
__bss_start = .;
.sbss : {
*(.dynsbss)
*(.sbss .sbss.* .gnu.linkonce.sb.*)
*(.scommon)
}
/* uninitialized data (in same segment as writable data) */
.bss : {
/* regular bss */
*(.bss .bss.*)
*(.gnu.linkonce.b.*)
}
. = ALIGN(%BITS% / 8);
__bss_end = .;
/* Align the end to ensure anything after the kernel ends up on its own pages */
. = ALIGN(CONSTANT(MAXPAGESIZE));
_end = .;
. = %KERNEL_BASE% + %MEMSIZE%;
_end_of_ram = .;
/* Strip unnecessary stuff */
/DISCARD/ : { *(.comment .note .eh_frame) }
}