[PATCH v1 5/6] LoongArch: Define specified arch_prepare_goto()

Tiezhu Yang posted 6 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH v1 5/6] LoongArch: Define specified arch_prepare_goto()
Posted by Tiezhu Yang 1 month, 1 week ago
In order to figure out the address of goto table by interpreting the
LoongArch machine code, define specified arch_prepare_goto() to insert
the relocation information of goto table address, then it can find the
destination address of the table jump instruction.

Suggested-by: Xi Ruoyao <xry111@xry111.site>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 arch/loongarch/Kconfig                |  1 +
 arch/loongarch/include/asm/compiler.h | 13 +++++++++++++
 2 files changed, 14 insertions(+)
 create mode 100644 arch/loongarch/include/asm/compiler.h

diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
index 49ed776cb253..9eed0bde678f 100644
--- a/arch/loongarch/Kconfig
+++ b/arch/loongarch/Kconfig
@@ -106,6 +106,7 @@ config LOONGARCH
 	select GPIOLIB
 	select HAS_IOPORT
 	select HAVE_ARCH_AUDITSYSCALL
+	select HAVE_ARCH_COMPILER_H
 	select HAVE_ARCH_JUMP_LABEL
 	select HAVE_ARCH_JUMP_LABEL_RELATIVE
 	select HAVE_ARCH_KASAN
diff --git a/arch/loongarch/include/asm/compiler.h b/arch/loongarch/include/asm/compiler.h
new file mode 100644
index 000000000000..424268a92c40
--- /dev/null
+++ b/arch/loongarch/include/asm/compiler.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2024 Loongson Technology Corporation Limited
+ */
+#ifndef _ASM_COMPILER_H
+#define _ASM_COMPILER_H
+
+#ifndef CONFIG_BPF_JIT_ALWAYS_ON
+#define arch_prepare_goto() \
+	asm volatile(".reloc\t., R_LARCH_NONE, %0" : : "i" (jumptable))
+#endif
+
+#endif /* _ASM_COMPILER_H */
-- 
2.42.0