riscv: Optimize gp-relative linker relaxation

Changes compiler options and the linker script to group most small data
objects together in a new .small section, and point __global_pointer$ at
.small so that nearly all objects can be referenced via gp.

Signed-off-by: Stefan O'Rear <sorear@fastmail.com>
This commit is contained in:
Stefan O'Rear
2020-07-24 19:52:06 -04:00
committed by Kent McLeod
parent d31f76c813
commit 89e5774292
2 changed files with 11 additions and 6 deletions

View File

@@ -286,7 +286,12 @@ elseif(KernelArchARM)
endif()
elseif(KernelArchRiscV)
KernelCommonFlags(-mcmodel=medany)
# Group "small" data objects together in a small-data section so they can
# be referenced using gp-relative addressing. The exact value of
# small-data-limit is not crucial but it should be lowered if .small
# exceeds 4KiB.
#
KernelCommonFlags(-mcmodel=medany -msmall-data-limit=1024)
else()
message(FATAL_ERROR "unknown KernelArch '${KernelArch}'")

View File

@@ -48,12 +48,13 @@ SECTIONS
/* Start of data section */
_sdata = .;
.sdata : {
.small : {
/* Small data that should be accessed relative to gp. ld has trouble
with the relaxation if they are not in a single section. */
__global_pointer$ = . + 0x800;
*(.sdata*)
}
.srodata : {
*(.srodata*)
*(.sdata*)
*(.sbss)
}
.rodata . : AT(ADDR(.rodata) - KERNEL_OFFSET)
@@ -71,7 +72,6 @@ SECTIONS
{
*(.bss)
*(COMMON) /* fallback in case '-fno-common' is not used */
*(.sbss)
/* 4k breakpoint stack */
_breakpoint_stack_bottom = .;