kern/ldr: enable the use of relr for relocations

This commit is contained in:
Michael Scire
2024-09-01 22:27:48 -07:00
parent 423a05a1e9
commit 027e209073
6 changed files with 17 additions and 13 deletions

View File

@@ -14,6 +14,7 @@ SECTIONS
/* =========== CODE section =========== */
PROVIDE(__start__ = 0x0);
. = __start__;
__bin_start__ = .;
__code_start = . ;
.start :
@@ -159,6 +160,7 @@ SECTIONS
__bss_start__ = .;
.rela.dyn : { *(.rela.*) } :data
.relr.dyn : { *(.relr.*) } :data
.bss ADDR(.rela.dyn) (NOLOAD) : {
*(.dynbss)
@@ -169,6 +171,7 @@ SECTIONS
__bss_end__ = .;
__bin_end__ = .;
__end__ = ABSOLUTE(.);
/* ==================

View File

@@ -1,7 +1,7 @@
%rename link old_link
*link:
%(old_link) -T %:getenv(ATMOSPHERE_TOPDIR /kernel.ld) -pie --gc-sections -z text -z nodynamic-undefined-weak -nostdlib
%(old_link) -T %:getenv(ATMOSPHERE_TOPDIR /kernel.ld) -pie --gc-sections -z text -z nodynamic-undefined-weak -z pack-relative-relocs -nostdlib
*startfile:
crti%O%s crtbegin%O%s

View File

@@ -15,8 +15,8 @@
*/
#include <mesosphere.hpp>
extern "C" void _start();
extern "C" void __end__();
extern "C" void __bin_start__();
extern "C" void __bin_end__();
namespace ams::kern {
@@ -264,8 +264,8 @@ namespace ams::kern::init {
KMemoryLayout::GetPhysicalMemoryRegionTree().InsertDirectly(KernelPhysicalAddressSpaceBase, KernelPhysicalAddressSpaceBase + KernelPhysicalAddressSpaceSize - 1);
/* Save start and end for ease of use. */
const uintptr_t code_start_virt_addr = reinterpret_cast<uintptr_t>(_start);
const uintptr_t code_end_virt_addr = reinterpret_cast<uintptr_t>(__end__);
const uintptr_t code_start_virt_addr = reinterpret_cast<uintptr_t>(__bin_start__);
const uintptr_t code_end_virt_addr = reinterpret_cast<uintptr_t>(__bin_end__);
/* Setup the containing kernel region. */
constexpr size_t KernelRegionSize = 1_GB;