mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-12-18 09:13:06 +00:00
d9f1cee286
Due to the two-instruction sequence needed to access arbitrary memory locations, the RISC-V linker aggressively optimises memory accesses and jumps at link-time. This is called "linker relaxation," and is discussed in this SiFive article <https://www.sifive.com/blog/all-aboard-part-3-linker-relaxation-in-riscv-toolchain>. One of the optimizations in place is to assume that the __global_pointer symbol is placed in the gp register. To quote the article: "...The magic __global_pointer$ symbol is defined to point 0x800 bytes past the start of the .sdata section. The 0x800 magic number allows signed 12-bit offsets from __global_pointer$ to address symbols at the start of the .sdata section. The linker assumes that if this symbol is defined, then the gp register contains that value, which it can then use to relax accesses to global symbols within that 12-bit range. The compiler treats the gp register as a constant so it doesn't need to be saved or restored, which means it is generally only written by _start, the ELF entry point." However, U-Boot instead keeps the global data pointer in gp. This causes memory accesses and jumps optimized to use the gp pointer to fail. To fix this problem, we undefine the __global_pointer symbol. Signed-off-by: Sean Anderson <seanga2@gmail.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Rick Chen <rick@andestech.com>
87 lines
1.2 KiB
Text
87 lines
1.2 KiB
Text
/* SPDX-License-Identifier: GPL-2.0+ */
|
|
/*
|
|
* Copyright (C) 2017 Andes Technology Corporation
|
|
* Rick Chen, Andes Technology Corporation <rick@andestech.com>
|
|
*/
|
|
|
|
OUTPUT_ARCH("riscv")
|
|
ENTRY(_start)
|
|
|
|
SECTIONS
|
|
{
|
|
. = ALIGN(4);
|
|
.text : {
|
|
arch/riscv/cpu/start.o (.text)
|
|
}
|
|
|
|
/* This needs to come before *(.text*) */
|
|
.efi_runtime : {
|
|
__efi_runtime_start = .;
|
|
*(.text.efi_runtime*)
|
|
*(.rodata.efi_runtime*)
|
|
*(.data.efi_runtime*)
|
|
__efi_runtime_stop = .;
|
|
}
|
|
|
|
.text_rest : {
|
|
*(.text*)
|
|
}
|
|
|
|
. = ALIGN(4);
|
|
.rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) }
|
|
|
|
. = ALIGN(4);
|
|
.data : {
|
|
*(.data*)
|
|
}
|
|
. = ALIGN(4);
|
|
|
|
.got : {
|
|
__got_start = .;
|
|
*(.got.plt) *(.got)
|
|
__got_end = .;
|
|
}
|
|
|
|
. = ALIGN(4);
|
|
|
|
.u_boot_list : {
|
|
KEEP(*(SORT(.u_boot_list*)));
|
|
}
|
|
|
|
. = ALIGN(4);
|
|
|
|
.efi_runtime_rel : {
|
|
__efi_runtime_rel_start = .;
|
|
*(.rel*.efi_runtime)
|
|
*(.rel*.efi_runtime.*)
|
|
__efi_runtime_rel_stop = .;
|
|
}
|
|
|
|
. = ALIGN(4);
|
|
|
|
/DISCARD/ : { *(.rela.plt*) }
|
|
.rela.dyn : {
|
|
__rel_dyn_start = .;
|
|
*(.rela*)
|
|
__rel_dyn_end = .;
|
|
}
|
|
|
|
. = ALIGN(4);
|
|
|
|
.dynsym : {
|
|
__dyn_sym_start = .;
|
|
*(.dynsym)
|
|
__dyn_sym_end = .;
|
|
}
|
|
|
|
. = ALIGN(4);
|
|
|
|
_end = .;
|
|
|
|
.bss : {
|
|
__bss_start = .;
|
|
*(.bss*)
|
|
. = ALIGN(8);
|
|
__bss_end = .;
|
|
}
|
|
}
|