From d8da19fbdedd5852592fbba18a7348e3f09500e6 Mon Sep 17 00:00:00 2001 From: Youling Tang Date: Sat, 25 Feb 2023 15:52:56 +0800 Subject: LoongArch: Add support for kernel relocation This config allows to compile kernel as PIE and to relocate it at any virtual address at runtime: this paves the way to KASLR. Runtime relocation is possible since relocation metadata are embedded into the kernel. Signed-off-by: Youling Tang Signed-off-by: Xi Ruoyao # Use arch_initcall Signed-off-by: Jinyang He # Provide la_abs relocation code Signed-off-by: Huacai Chen --- arch/loongarch/include/asm/asmmacro.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'arch/loongarch/include/asm/asmmacro.h') diff --git a/arch/loongarch/include/asm/asmmacro.h b/arch/loongarch/include/asm/asmmacro.h index cdc9935d5554..c51a1b43acb4 100644 --- a/arch/loongarch/include/asm/asmmacro.h +++ b/arch/loongarch/include/asm/asmmacro.h @@ -275,7 +275,20 @@ .endm .macro la_abs reg, sym +#ifndef CONFIG_RELOCATABLE la.abs \reg, \sym +#else + 766: + lu12i.w \reg, 0 + ori \reg, \reg, 0 + lu32i.d \reg, 0 + lu52i.d \reg, \reg, 0 + .pushsection ".la_abs", "aw", %progbits + 768: + .dword 768b-766b + .dword \sym + .popsection +#endif .endm #endif /* _ASM_ASMMACRO_H */ -- cgit v1.2.3