From cd179d4a425a12087485b4f59e1aa834f989c3c8 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Tue, 12 Nov 2024 19:56:57 +0000 Subject: [PATCH] #14895: enable gp-rel in kernels --- tt_metal/hw/firmware/src/erisck.cc | 2 +- tt_metal/hw/toolchain/sections.ld | 2 ++ tt_metal/hw/toolchain/tmu-crt0k.S | 2 ++ tt_metal/jit_build/build.cpp | 6 ++++-- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tt_metal/hw/firmware/src/erisck.cc b/tt_metal/hw/firmware/src/erisck.cc index 54d9ab9b958..e98d2a444a7 100644 --- a/tt_metal/hw/firmware/src/erisck.cc +++ b/tt_metal/hw/firmware/src/erisck.cc @@ -23,7 +23,7 @@ CBInterface cb_interface[NUM_CIRCULAR_BUFFERS]; -void kernel_launch(uint32_t) { +extern "C" [[gnu::section(".start")]] void _start(uint32_t) { DeviceZoneScopedMainChildN("ERISC-KERNEL"); rtos_context_switch_ptr = (void (*)())RtosTable[0]; diff --git a/tt_metal/hw/toolchain/sections.ld b/tt_metal/hw/toolchain/sections.ld index 17162f235c8..457ac6fe99a 100644 --- a/tt_metal/hw/toolchain/sections.ld +++ b/tt_metal/hw/toolchain/sections.ld @@ -86,7 +86,9 @@ SECTIONS __kernel_init_local_l1_base = .; #endif +#if defined(TYPE_FIRMWARE) PROVIDE(__global_pointer$ = ORIGIN(REGION_DATA) + 0x7f0); +#endif .data DATA_START : ALIGN(4) { . = .; /* Force section emission. */ diff --git a/tt_metal/hw/toolchain/tmu-crt0k.S b/tt_metal/hw/toolchain/tmu-crt0k.S index 849e31eb199..1e2f5bc6939 100644 --- a/tt_metal/hw/toolchain/tmu-crt0k.S +++ b/tt_metal/hw/toolchain/tmu-crt0k.S @@ -4,5 +4,7 @@ _start: // kernel_launch is responsible for the rest of crt -- clear bss, copy data image, run global constructors + // Enable GPREL optimizations + .reloc _start, R_RISCV_NONE, __global_pointer$ tail _Z13kernel_launchm .size _start, .-_start diff --git a/tt_metal/jit_build/build.cpp b/tt_metal/jit_build/build.cpp index 7bff200cf7f..788daabcb07 100644 --- a/tt_metal/jit_build/build.cpp +++ b/tt_metal/jit_build/build.cpp @@ -188,7 +188,9 @@ void JitBuildState::finish_init() { this->link_objs_ += build_dir + "ncrisc-halt.o "; } } else { - this->link_objs_ += build_dir + "tmu-crt0k.o "; + if (this->target_name_ != "erisc") { + this->link_objs_ += build_dir + "tmu-crt0k.o "; + } } if (this->target_name_ == "brisc" or this->target_name_ == "idle_erisc") { this->link_objs_ += build_dir + "noc.o "; @@ -600,7 +602,7 @@ void JitBuildState::weaken(const string& log_file, const string& out_dir) const ll_api::ElfFile elf; elf.ReadImage(pathname_in); - static std::string_view const strong_names[] = {"__fw_export_*"}; + static std::string_view const strong_names[] = {"__fw_export_*", "__global_pointer$"}; elf.WeakenDataSymbols(strong_names); elf.WriteImage(pathname_out); }