Files
lk/arch/riscv/linker-onesegment.ld
Travis Geiselbrecht 8869020ae2 [arch][riscv] fix bug with gcc 10.2 & binutils 2.35 with section padding
In a two segment binary was previously trying to use MAXPAGESIZE set to 4
to cram the sections in very tight for embedded. This seemed to with this
toolchain cause the linker to get confused and sometimes appear to stuff in
an extra 4 bytes in the output file, thus misaligning the data segment.

It's possible it's still a bug on my side in the linker, but setting
max_page_size to 8 seems to work around it for now. Possible there's some
implicit 64bit aligning slipped in a stage somewhere in binutils thats
causing it to get confused. Either way, 8 byte alignment is no large loss
here.
2020-12-09 01:59:16 -08: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) }
}