kern: put rela in bss

NOTE: This saves ~0x4000 of space at the cost of crimes against the linker script.
This commit is contained in:
Michael Scire 2021-10-08 12:29:53 -07:00
parent fba962ef11
commit 960ba52a43
4 changed files with 25 additions and 19 deletions

View file

@ -207,13 +207,15 @@ namespace ams::kern::init::loader {
/* NOTE: Nintendo does this only on 10.0.0+ */
init_pt.PhysicallyRandomize(virtual_base_address + rx_offset, bss_end_offset - rx_offset, true);
/* Clear kernel .bss. */
std::memset(GetVoidPointer(virtual_base_address + bss_offset), 0, bss_end_offset - bss_offset);
/* Apply relocations to the kernel. */
const Elf::Dyn *kernel_dynamic = reinterpret_cast<const Elf::Dyn *>(GetInteger(virtual_base_address) + dynamic_offset);
Elf::ApplyRelocations(GetInteger(virtual_base_address), kernel_dynamic);
/* Clear kernel .bss. */
/* NOTE: The kernel does this before applying relocations, but we do it after. */
/* This allows us to place our relocations in space overlapping with .bss...and thereby reclaim the memory that would otherwise be wasted. */
std::memset(GetVoidPointer(virtual_base_address + bss_offset), 0, bss_end_offset - bss_offset);
/* Call the kernel's init array functions. */
/* NOTE: The kernel does this after reprotecting .rodata, but we do it before. */
/* This allows our global constructors to edit .rodata, which is valuable for editing the SVC tables to support older firmwares' ABIs. */