Skip to content

Commit 3af4bec

Browse files
Avenger-285714palmer-dabbelt
authored andcommitted
riscv: KGDB: Do not inline arch_kgdb_breakpoint()
The arch_kgdb_breakpoint() function defines the kgdb_compiled_break symbol using inline assembly. There's a potential issue where the compiler might inline arch_kgdb_breakpoint(), which would then define the kgdb_compiled_break symbol multiple times, leading to fail to link vmlinux.o. This isn't merely a potential compilation problem. The intent here is to determine the global symbol address of kgdb_compiled_break, and if this function is inlined multiple times, it would logically be a grave error. Link: https://lore.kernel.org/all/4b4187c1-77e5-44b7-885f-d6826723dd9a@sifive.com/ Link: https://lore.kernel.org/all/5b0adf9b-2b22-43fe-ab74-68df94115b9a@ghiti.fr/ Link: https://lore.kernel.org/all/23693e7f-4fff-40f3-a437-e06d827278a5@ghiti.fr/ Fixes: fe89bd2 ("riscv: Add KGDB support") Co-developed-by: Huacai Chen <chenhuacai@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn> Signed-off-by: WangYuli <wangyuli@uniontech.com> Link: https://lore.kernel.org/r/F22359AFB6FF9FD8+20250411073222.56820-1-wangyuli@uniontech.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 0af2f6b commit 3af4bec

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

arch/riscv/include/asm/kgdb.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,9 @@
1919

2020
#ifndef __ASSEMBLY__
2121

22+
void arch_kgdb_breakpoint(void);
2223
extern unsigned long kgdb_compiled_break;
2324

24-
static inline void arch_kgdb_breakpoint(void)
25-
{
26-
asm(".global kgdb_compiled_break\n"
27-
".option norvc\n"
28-
"kgdb_compiled_break: ebreak\n"
29-
".option rvc\n");
30-
}
31-
3225
#endif /* !__ASSEMBLY__ */
3326

3427
#define DBG_REG_ZERO "zero"

arch/riscv/kernel/kgdb.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,14 @@ void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc)
254254
regs->epc = pc;
255255
}
256256

257+
noinline void arch_kgdb_breakpoint(void)
258+
{
259+
asm(".global kgdb_compiled_break\n"
260+
".option norvc\n"
261+
"kgdb_compiled_break: ebreak\n"
262+
".option rvc\n");
263+
}
264+
257265
void kgdb_arch_handle_qxfer_pkt(char *remcom_in_buffer,
258266
char *remcom_out_buffer)
259267
{

0 commit comments

Comments
 (0)