mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC PATCH 0/4] Add jump table support for objtool on LoongArch
@ 2024-07-12  9:15 Tiezhu Yang
  2024-07-12  9:15 ` [RFC PATCH 1/4] objtool: Check local label in find_jump_table() Tiezhu Yang
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Tiezhu Yang @ 2024-07-12  9:15 UTC (permalink / raw)
  To: Josh Poimboeuf, Peter Zijlstra, Huacai Chen
  Cc: Xi Ruoyao, loongarch, linux-kernel

This RFC version is based on Linux 6.10-rc7, there are no detailed
commit messages for each patch for now and the code are relatively
clear and simple.

This series is tested with the latest upstream gcc applied with patch
"LoongArch: Add support to annotate tablejump" [1] which adds a new
section discard.tablejump_annotate to record the jump info, it makes
life much easier, special thanks to Ruoyao.

I will address all the review comments and update the commit messages
after the merge window.

[1] https://inbox.sourceware.org/gcc-patches/20240711114415.4420-1-xry111@xry111.site/

Tiezhu Yang (4):
  objtool: Check local label in find_jump_table()
  objtool: Check various types in add_jump_table()
  objtool/LoongArch: Add support for jump table
  LoongArch: Remove -fno-jump-tables for objtool

 arch/loongarch/Kconfig                 |  8 +++-
 arch/loongarch/Makefile                |  6 +--
 tools/objtool/arch/loongarch/special.c | 54 +++++++++++++++++++++++++-
 tools/objtool/check.c                  | 36 +++++++++++++++--
 4 files changed, 94 insertions(+), 10 deletions(-)

-- 
2.42.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [RFC PATCH 1/4] objtool: Check local label in find_jump_table()
  2024-07-12  9:15 [RFC PATCH 0/4] Add jump table support for objtool on LoongArch Tiezhu Yang
@ 2024-07-12  9:15 ` Tiezhu Yang
  2024-07-12  9:15 ` [RFC PATCH 2/4] objtool: Check various types in add_jump_table() Tiezhu Yang
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Tiezhu Yang @ 2024-07-12  9:15 UTC (permalink / raw)
  To: Josh Poimboeuf, Peter Zijlstra, Huacai Chen
  Cc: Xi Ruoyao, loongarch, linux-kernel

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 tools/objtool/check.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 0a33d9195b7a..c89c0d8c35d7 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2085,6 +2085,7 @@ static struct reloc *find_jump_table(struct objtool_file *file,
 {
 	struct reloc *table_reloc;
 	struct instruction *dest_insn, *orig_insn = insn;
+	unsigned long offset;
 
 	/*
 	 * Backward search using the @first_jump_src links, these help avoid
@@ -2108,7 +2109,18 @@ static struct reloc *find_jump_table(struct objtool_file *file,
 		table_reloc = arch_find_switch_table(file, insn);
 		if (!table_reloc)
 			continue;
-		dest_insn = find_insn(file, table_reloc->sym->sec, reloc_addend(table_reloc));
+
+		if (table_reloc->sym->type == STT_SECTION) {
+			offset = reloc_addend(table_reloc);
+		} else if (table_reloc->sym->local_label) {
+			offset = table_reloc->sym->offset;
+		} else {
+			WARN("unexpected relocation symbol type in %s: %d",
+			     table_reloc->sec->name, table_reloc->sym->type);
+			return NULL;
+		}
+
+		dest_insn = find_insn(file, table_reloc->sym->sec, offset);
 		if (!dest_insn || !insn_func(dest_insn) || insn_func(dest_insn)->pfunc != func)
 			continue;
 
-- 
2.42.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [RFC PATCH 2/4] objtool: Check various types in add_jump_table()
  2024-07-12  9:15 [RFC PATCH 0/4] Add jump table support for objtool on LoongArch Tiezhu Yang
  2024-07-12  9:15 ` [RFC PATCH 1/4] objtool: Check local label in find_jump_table() Tiezhu Yang
@ 2024-07-12  9:15 ` Tiezhu Yang
  2024-07-12  9:15 ` [RFC PATCH 3/4] objtool/LoongArch: Add support for jump table Tiezhu Yang
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Tiezhu Yang @ 2024-07-12  9:15 UTC (permalink / raw)
  To: Josh Poimboeuf, Peter Zijlstra, Huacai Chen
  Cc: Xi Ruoyao, loongarch, linux-kernel

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 tools/objtool/check.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index c89c0d8c35d7..6fa4100206d0 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2027,6 +2027,7 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn,
 	unsigned int prev_offset = 0;
 	struct reloc *reloc = table;
 	struct alternative *alt;
+	unsigned long offset;
 
 	/*
 	 * Each @reloc is a switch table relocation which points to the target
@@ -2042,12 +2043,27 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn,
 		if (prev_offset && reloc_offset(reloc) != prev_offset + 8)
 			break;
 
+		if (reloc->sym->type == STT_SECTION) {
+			offset = reloc_addend(reloc);
+		} else if (reloc->sym->local_label) {
+			offset = reloc->sym->offset;
+		} else if (reloc->sym->type == STT_FUNC) {
+			offset = reloc->sym->offset;
+		} else if (reloc->sym->type == STT_OBJECT) {
+			offset = reloc->sym->offset;
+		} else if (reloc->sym->type == STT_NOTYPE) {
+			offset = reloc->sym->offset;
+		} else {
+			WARN("unexpected relocation symbol type in %s: %d",
+			     table->sec->name, reloc->sym->type);
+			return -1;
+		}
+
 		/* Detect function pointers from contiguous objects: */
-		if (reloc->sym->sec == pfunc->sec &&
-		    reloc_addend(reloc) == pfunc->offset)
+		if (reloc->sym->sec == pfunc->sec && offset == pfunc->offset)
 			break;
 
-		dest_insn = find_insn(file, reloc->sym->sec, reloc_addend(reloc));
+		dest_insn = find_insn(file, reloc->sym->sec, offset);
 		if (!dest_insn)
 			break;
 
-- 
2.42.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [RFC PATCH 3/4] objtool/LoongArch: Add support for jump table
  2024-07-12  9:15 [RFC PATCH 0/4] Add jump table support for objtool on LoongArch Tiezhu Yang
  2024-07-12  9:15 ` [RFC PATCH 1/4] objtool: Check local label in find_jump_table() Tiezhu Yang
  2024-07-12  9:15 ` [RFC PATCH 2/4] objtool: Check various types in add_jump_table() Tiezhu Yang
@ 2024-07-12  9:15 ` Tiezhu Yang
  2024-07-12  9:15 ` [RFC PATCH 4/4] LoongArch: Remove -fno-jump-tables for objtool Tiezhu Yang
  2024-07-12 10:19 ` [RFC PATCH 0/4] Add jump table support for objtool on LoongArch Jinyang He
  4 siblings, 0 replies; 12+ messages in thread
From: Tiezhu Yang @ 2024-07-12  9:15 UTC (permalink / raw)
  To: Josh Poimboeuf, Peter Zijlstra, Huacai Chen
  Cc: Xi Ruoyao, loongarch, linux-kernel

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 tools/objtool/arch/loongarch/special.c | 54 +++++++++++++++++++++++++-
 1 file changed, 53 insertions(+), 1 deletion(-)

diff --git a/tools/objtool/arch/loongarch/special.c b/tools/objtool/arch/loongarch/special.c
index 9bba1e9318e0..3e08ad3a507c 100644
--- a/tools/objtool/arch/loongarch/special.c
+++ b/tools/objtool/arch/loongarch/special.c
@@ -1,5 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
+#include <string.h>
+
 #include <objtool/special.h>
+#include <objtool/warn.h>
 
 bool arch_support_alt_relocation(struct special_alt *special_alt,
 				 struct instruction *insn,
@@ -8,8 +11,57 @@ bool arch_support_alt_relocation(struct special_alt *special_alt,
 	return false;
 }
 
+static struct reloc *find_reloc_by_tablejump_annotate(struct objtool_file *file,
+						      struct instruction *insn)
+{
+	struct section *rsec;
+	struct reloc *reloc;
+	unsigned long offset;
+
+	rsec = find_section_by_name(file->elf, ".rela.discard.tablejump_annotate");
+	if (!rsec)
+		return NULL;
+
+	for_each_reloc(rsec, reloc) {
+		if (reloc->sym->sec->rodata)
+			continue;
+
+		if (strcmp(insn->sec->name, reloc->sym->sec->name))
+			continue;
+
+		offset = reloc->sym->offset;
+		if (insn->offset == offset) {
+			reloc++;
+			return reloc;
+		}
+	}
+
+	return NULL;
+}
+
 struct reloc *arch_find_switch_table(struct objtool_file *file,
 				     struct instruction *insn)
 {
-	return NULL;
+	struct reloc *annotate_reloc;
+	struct reloc *rodata_reloc;
+	struct section *table_sec;
+	unsigned long table_offset;
+
+	annotate_reloc = find_reloc_by_tablejump_annotate(file, insn);
+	if (!annotate_reloc)
+		return NULL;
+
+	table_sec = annotate_reloc->sym->sec;
+	table_offset = annotate_reloc->sym->offset;
+
+	/*
+	 * Each table entry has a rela associated with it.  The rela
+	 * should reference text in the same function as the original
+	 * instruction.
+	 */
+	rodata_reloc = find_reloc_by_dest(file->elf, table_sec, table_offset);
+	if (!rodata_reloc)
+		return NULL;
+
+	return rodata_reloc;
 }
-- 
2.42.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [RFC PATCH 4/4] LoongArch: Remove -fno-jump-tables for objtool
  2024-07-12  9:15 [RFC PATCH 0/4] Add jump table support for objtool on LoongArch Tiezhu Yang
                   ` (2 preceding siblings ...)
  2024-07-12  9:15 ` [RFC PATCH 3/4] objtool/LoongArch: Add support for jump table Tiezhu Yang
@ 2024-07-12  9:15 ` Tiezhu Yang
  2024-07-12  9:40   ` Huacai Chen
  2024-07-12  9:49   ` Xi Ruoyao
  2024-07-12 10:19 ` [RFC PATCH 0/4] Add jump table support for objtool on LoongArch Jinyang He
  4 siblings, 2 replies; 12+ messages in thread
From: Tiezhu Yang @ 2024-07-12  9:15 UTC (permalink / raw)
  To: Josh Poimboeuf, Peter Zijlstra, Huacai Chen
  Cc: Xi Ruoyao, loongarch, linux-kernel

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 arch/loongarch/Kconfig  | 8 +++++++-
 arch/loongarch/Makefile | 6 ++----
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
index ddc042895d01..57f28450a2ed 100644
--- a/arch/loongarch/Kconfig
+++ b/arch/loongarch/Kconfig
@@ -143,7 +143,7 @@ config LOONGARCH
 	select HAVE_LIVEPATCH
 	select HAVE_MOD_ARCH_SPECIFIC
 	select HAVE_NMI
-	select HAVE_OBJTOOL if AS_HAS_EXPLICIT_RELOCS && AS_HAS_THIN_ADD_SUB && !CC_IS_CLANG
+	select HAVE_OBJTOOL if TOOLCHAIN_SUPPORTS_OBJTOOL && !CC_IS_CLANG
 	select HAVE_PCI
 	select HAVE_PERF_EVENTS
 	select HAVE_PERF_REGS
@@ -276,6 +276,12 @@ config AS_HAS_LBT_EXTENSION
 config AS_HAS_LVZ_EXTENSION
 	def_bool $(as-instr,hvcl 0)
 
+config CC_HAS_ANNOTATE_TABLEJUMP
+	def_bool $(cc-option,-mannotate-tablejump)
+
+config TOOLCHAIN_SUPPORTS_OBJTOOL
+	def_bool AS_HAS_EXPLICIT_RELOCS && AS_HAS_THIN_ADD_SUB && CC_HAS_ANNOTATE_TABLEJUMP
+
 menu "Kernel type and options"
 
 source "kernel/Kconfig.hz"
diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile
index 8674e7e24c4a..186c75c80daa 100644
--- a/arch/loongarch/Makefile
+++ b/arch/loongarch/Makefile
@@ -99,10 +99,8 @@ KBUILD_AFLAGS			+= $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno
 KBUILD_CFLAGS			+= $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno-relax)
 KBUILD_AFLAGS			+= $(call cc-option,-mthin-add-sub) $(call cc-option,-Wa$(comma)-mthin-add-sub)
 KBUILD_CFLAGS			+= $(call cc-option,-mthin-add-sub) $(call cc-option,-Wa$(comma)-mthin-add-sub)
-
-ifdef CONFIG_OBJTOOL
-KBUILD_CFLAGS			+= -fno-jump-tables
-endif
+KBUILD_AFLAGS			+= $(call cc-option,-mannotate-tablejump) $(call cc-option,-Wa$(comma)-mannotate-tablejump)
+KBUILD_CFLAGS			+= $(call cc-option,-mannotate-tablejump) $(call cc-option,-Wa$(comma)-mannotate-tablejump)
 
 KBUILD_RUSTFLAGS		+= --target=loongarch64-unknown-none-softfloat
 KBUILD_RUSTFLAGS_MODULE		+= -Crelocation-model=pic
-- 
2.42.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC PATCH 4/4] LoongArch: Remove -fno-jump-tables for objtool
  2024-07-12  9:15 ` [RFC PATCH 4/4] LoongArch: Remove -fno-jump-tables for objtool Tiezhu Yang
@ 2024-07-12  9:40   ` Huacai Chen
  2024-07-15 10:32     ` Tiezhu Yang
  2024-07-12  9:49   ` Xi Ruoyao
  1 sibling, 1 reply; 12+ messages in thread
From: Huacai Chen @ 2024-07-12  9:40 UTC (permalink / raw)
  To: Tiezhu Yang
  Cc: Josh Poimboeuf, Peter Zijlstra, Xi Ruoyao, loongarch, linux-kernel

Hi, Tiezhu,

On Fri, Jul 12, 2024 at 5:15 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> ---
>  arch/loongarch/Kconfig  | 8 +++++++-
>  arch/loongarch/Makefile | 6 ++----
>  2 files changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
> index ddc042895d01..57f28450a2ed 100644
> --- a/arch/loongarch/Kconfig
> +++ b/arch/loongarch/Kconfig
> @@ -143,7 +143,7 @@ config LOONGARCH
>         select HAVE_LIVEPATCH
>         select HAVE_MOD_ARCH_SPECIFIC
>         select HAVE_NMI
> -       select HAVE_OBJTOOL if AS_HAS_EXPLICIT_RELOCS && AS_HAS_THIN_ADD_SUB && !CC_IS_CLANG
> +       select HAVE_OBJTOOL if TOOLCHAIN_SUPPORTS_OBJTOOL && !CC_IS_CLANG
>         select HAVE_PCI
>         select HAVE_PERF_EVENTS
>         select HAVE_PERF_REGS
> @@ -276,6 +276,12 @@ config AS_HAS_LBT_EXTENSION
>  config AS_HAS_LVZ_EXTENSION
>         def_bool $(as-instr,hvcl 0)
>
> +config CC_HAS_ANNOTATE_TABLEJUMP
> +       def_bool $(cc-option,-mannotate-tablejump)
> +
> +config TOOLCHAIN_SUPPORTS_OBJTOOL
> +       def_bool AS_HAS_EXPLICIT_RELOCS && AS_HAS_THIN_ADD_SUB && CC_HAS_ANNOTATE_TABLEJUMP
Can AS_HAS_THIN_ADD_SUB be removed now?

Huacai

> +
>  menu "Kernel type and options"
>
>  source "kernel/Kconfig.hz"
> diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile
> index 8674e7e24c4a..186c75c80daa 100644
> --- a/arch/loongarch/Makefile
> +++ b/arch/loongarch/Makefile
> @@ -99,10 +99,8 @@ KBUILD_AFLAGS                        += $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno
>  KBUILD_CFLAGS                  += $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno-relax)
>  KBUILD_AFLAGS                  += $(call cc-option,-mthin-add-sub) $(call cc-option,-Wa$(comma)-mthin-add-sub)
>  KBUILD_CFLAGS                  += $(call cc-option,-mthin-add-sub) $(call cc-option,-Wa$(comma)-mthin-add-sub)
> -
> -ifdef CONFIG_OBJTOOL
> -KBUILD_CFLAGS                  += -fno-jump-tables
> -endif
> +KBUILD_AFLAGS                  += $(call cc-option,-mannotate-tablejump) $(call cc-option,-Wa$(comma)-mannotate-tablejump)
> +KBUILD_CFLAGS                  += $(call cc-option,-mannotate-tablejump) $(call cc-option,-Wa$(comma)-mannotate-tablejump)
>
>  KBUILD_RUSTFLAGS               += --target=loongarch64-unknown-none-softfloat
>  KBUILD_RUSTFLAGS_MODULE                += -Crelocation-model=pic
> --
> 2.42.0
>
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC PATCH 4/4] LoongArch: Remove -fno-jump-tables for objtool
  2024-07-12  9:15 ` [RFC PATCH 4/4] LoongArch: Remove -fno-jump-tables for objtool Tiezhu Yang
  2024-07-12  9:40   ` Huacai Chen
@ 2024-07-12  9:49   ` Xi Ruoyao
  2024-07-13  9:10     ` Xi Ruoyao
  1 sibling, 1 reply; 12+ messages in thread
From: Xi Ruoyao @ 2024-07-12  9:49 UTC (permalink / raw)
  To: Tiezhu Yang, Josh Poimboeuf, Peter Zijlstra, Huacai Chen
  Cc: loongarch, linux-kernel

On Fri, 2024-07-12 at 17:15 +0800, Tiezhu Yang wrote:
> -ifdef CONFIG_OBJTOOL
> -KBUILD_CFLAGS			+= -fno-jump-tables
> -endif
> +KBUILD_AFLAGS			+= $(call cc-option,-mannotate-tablejump) $(call cc-option,-Wa$(comma)-mannotate-tablejump)
> +KBUILD_CFLAGS			+= $(call cc-option,-mannotate-tablejump) $(call cc-option,-Wa$(comma)-mannotate-tablejump)

KBUILD_AFLAGS isn't needed, and $(call cc-option,-Wa$(comma)-mannotate-
tablejump) will always expand to nothing because the assembler does not
have -mannotate-tablejump.

The assembler never creates a jump table itself.

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC PATCH 0/4] Add jump table support for objtool on LoongArch
  2024-07-12  9:15 [RFC PATCH 0/4] Add jump table support for objtool on LoongArch Tiezhu Yang
                   ` (3 preceding siblings ...)
  2024-07-12  9:15 ` [RFC PATCH 4/4] LoongArch: Remove -fno-jump-tables for objtool Tiezhu Yang
@ 2024-07-12 10:19 ` Jinyang He
  2024-07-15  9:56   ` Tiezhu Yang
  4 siblings, 1 reply; 12+ messages in thread
From: Jinyang He @ 2024-07-12 10:19 UTC (permalink / raw)
  To: Tiezhu Yang, Josh Poimboeuf, Peter Zijlstra, Huacai Chen
  Cc: Xi Ruoyao, loongarch, linux-kernel

Are we always avoid our problems?

1, When text section not support "R_LARCH_32_PCREL", update compiler
    to add AS_HAS_THIN_ADD_SUB.
2, When not support jump-table, use "-fno-jump-tables" to avoid it,
    (and now update compiler to add CC_HAS_ANNOTATE_TABLEJUMP).
3, When not support relax, use "-mno-relax" to avoid it.
4, When some where in asm can be backtraced but generate warning,
    use STACK_FRAME_NON_STANDARD to avoid it.
5, When the goto-table cannot be handled (I guess the Ruoyao's
    patch cannot handle goto table), use CONFIG_BPF_JIT_ALWAYS_ON
    to avoid compile ___bpf_prog_run.
6, And other $fp warnings not be solved in clang. Do we only care gcc?

So how to do in the future if compilers have other changed? Do we
need update compilers (both gcc and clang) again and again? Why
not just update objtool codes to solves these problems? As many
RISC arch not support directly find jump table, can we support
more generic ways to find it?


On 2024-07-12 17:15, Tiezhu Yang wrote:
> This RFC version is based on Linux 6.10-rc7, there are no detailed
> commit messages for each patch for now and the code are relatively
> clear and simple.
>
> This series is tested with the latest upstream gcc applied with patch
> "LoongArch: Add support to annotate tablejump" [1] which adds a new
> section discard.tablejump_annotate to record the jump info, it makes
> life much easier, special thanks to Ruoyao.
>
> I will address all the review comments and update the commit messages
> after the merge window.
>
> [1] https://inbox.sourceware.org/gcc-patches/20240711114415.4420-1-xry111@xry111.site/
>
> Tiezhu Yang (4):
>    objtool: Check local label in find_jump_table()
>    objtool: Check various types in add_jump_table()
>    objtool/LoongArch: Add support for jump table
>    LoongArch: Remove -fno-jump-tables for objtool
>
>   arch/loongarch/Kconfig                 |  8 +++-
>   arch/loongarch/Makefile                |  6 +--
>   tools/objtool/arch/loongarch/special.c | 54 +++++++++++++++++++++++++-
>   tools/objtool/check.c                  | 36 +++++++++++++++--
>   4 files changed, 94 insertions(+), 10 deletions(-)
>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC PATCH 4/4] LoongArch: Remove -fno-jump-tables for objtool
  2024-07-12  9:49   ` Xi Ruoyao
@ 2024-07-13  9:10     ` Xi Ruoyao
  2024-07-15 10:35       ` Tiezhu Yang
  0 siblings, 1 reply; 12+ messages in thread
From: Xi Ruoyao @ 2024-07-13  9:10 UTC (permalink / raw)
  To: Tiezhu Yang, Josh Poimboeuf, Peter Zijlstra, Huacai Chen
  Cc: loongarch, linux-kernel

On Fri, 2024-07-12 at 17:49 +0800, Xi Ruoyao wrote:
> On Fri, 2024-07-12 at 17:15 +0800, Tiezhu Yang wrote:
> > -ifdef CONFIG_OBJTOOL
> > -KBUILD_CFLAGS			+= -fno-jump-tables
> > -endif
> > +KBUILD_AFLAGS			+= $(call cc-option,-mannotate-tablejump) $(call cc-option,-Wa$(comma)-mannotate-tablejump)
> > +KBUILD_CFLAGS			+= $(call cc-option,-mannotate-tablejump) $(call cc-option,-Wa$(comma)-mannotate-tablejump)
> 
> KBUILD_AFLAGS isn't needed, and $(call cc-option,-Wa$(comma)-mannotate-
> tablejump) will always expand to nothing because the assembler does not
> have -mannotate-tablejump.
> 
> The assembler never creates a jump table itself.

BTW have you discussed with Lulu about the -mannotate-tablejump patch? 
I guess maybe an intra-Loongson discussion would be helpful.

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC PATCH 0/4] Add jump table support for objtool on LoongArch
  2024-07-12 10:19 ` [RFC PATCH 0/4] Add jump table support for objtool on LoongArch Jinyang He
@ 2024-07-15  9:56   ` Tiezhu Yang
  0 siblings, 0 replies; 12+ messages in thread
From: Tiezhu Yang @ 2024-07-15  9:56 UTC (permalink / raw)
  To: Jinyang He, Josh Poimboeuf, Peter Zijlstra, Huacai Chen
  Cc: Xi Ruoyao, loongarch, linux-kernel

On 07/12/2024 06:19 PM, Jinyang He wrote:
> Are we always avoid our problems?
>
> 1, When text section not support "R_LARCH_32_PCREL", update compiler
>    to add AS_HAS_THIN_ADD_SUB.
> 2, When not support jump-table, use "-fno-jump-tables" to avoid it,
>    (and now update compiler to add CC_HAS_ANNOTATE_TABLEJUMP).
> 3, When not support relax, use "-mno-relax" to avoid it.
> 4, When some where in asm can be backtraced but generate warning,
>    use STACK_FRAME_NON_STANDARD to avoid it.
> 5, When the goto-table cannot be handled (I guess the Ruoyao's
>    patch cannot handle goto table), use CONFIG_BPF_JIT_ALWAYS_ON
>    to avoid compile ___bpf_prog_run.
> 6, And other $fp warnings not be solved in clang. Do we only care gcc?
>
> So how to do in the future if compilers have other changed? Do we
> need update compilers (both gcc and clang) again and again? Why
> not just update objtool codes to solves these problems? As many
> RISC arch not support directly find jump table, can we support
> more generic ways to find it?

This is a choose and balance. In principle, I want to make the kernel
code clear and simple to enhance the readability and maintainability,
I do not want to modify too much architecture independent code of the
objtool framework, I just want to implement the architecture specific
function.

As the gcc patch "LoongArch: Add support to annotate tablejump" said,
the objtool program needs to analysis the control flow of each .o file
generated by compiler toolchain, if a jump table is used, objtool has
to correlate the jump instruction with the table, on x86 it's simple:
a relocation entry natrually correlates them because one instruction is
used for table-based jump, but on an RISC machine objtool would have to
reconstruct the data flow if it must find out the correlation on its own,
so emit an additional section to store the correlation info as pairs of
addresses, each pair contains the address of a jump instruction (jr) and
the address of the jump table. This is very trivial to implement in GCC.

For jump table support of objtool on LoongArch, it makes life much easier
with the gcc changes. As far as I can see, the remain issues (goto table
in ___bpf_prog_run() and jump table in assemble code) are only related
with kernel and can be solved with kernel changes.

Thanks,
Tiezhu


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC PATCH 4/4] LoongArch: Remove -fno-jump-tables for objtool
  2024-07-12  9:40   ` Huacai Chen
@ 2024-07-15 10:32     ` Tiezhu Yang
  0 siblings, 0 replies; 12+ messages in thread
From: Tiezhu Yang @ 2024-07-15 10:32 UTC (permalink / raw)
  To: Huacai Chen
  Cc: Josh Poimboeuf, Peter Zijlstra, Xi Ruoyao, loongarch, linux-kernel

On 07/12/2024 05:40 PM, Huacai Chen wrote:
> Hi, Tiezhu,
>
> On Fri, Jul 12, 2024 at 5:15 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>>
>> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
>> ---
>>  arch/loongarch/Kconfig  | 8 +++++++-
>>  arch/loongarch/Makefile | 6 ++----
>>  2 files changed, 9 insertions(+), 5 deletions(-)
>>
>> diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
>> index ddc042895d01..57f28450a2ed 100644
>> --- a/arch/loongarch/Kconfig
>> +++ b/arch/loongarch/Kconfig
>> @@ -143,7 +143,7 @@ config LOONGARCH
>>         select HAVE_LIVEPATCH
>>         select HAVE_MOD_ARCH_SPECIFIC
>>         select HAVE_NMI
>> -       select HAVE_OBJTOOL if AS_HAS_EXPLICIT_RELOCS && AS_HAS_THIN_ADD_SUB && !CC_IS_CLANG
>> +       select HAVE_OBJTOOL if TOOLCHAIN_SUPPORTS_OBJTOOL && !CC_IS_CLANG
>>         select HAVE_PCI
>>         select HAVE_PERF_EVENTS
>>         select HAVE_PERF_REGS
>> @@ -276,6 +276,12 @@ config AS_HAS_LBT_EXTENSION
>>  config AS_HAS_LVZ_EXTENSION
>>         def_bool $(as-instr,hvcl 0)
>>
>> +config CC_HAS_ANNOTATE_TABLEJUMP
>> +       def_bool $(cc-option,-mannotate-tablejump)
>> +
>> +config TOOLCHAIN_SUPPORTS_OBJTOOL
>> +       def_bool AS_HAS_EXPLICIT_RELOCS && AS_HAS_THIN_ADD_SUB && CC_HAS_ANNOTATE_TABLEJUMP
> Can AS_HAS_THIN_ADD_SUB be removed now?

If the following patch can be accepted, then objtool will not rely
on AS_HAS_THIN_ADD_SUB, I will try to send this patch again.

objtool: Add skipped member in struct reloc
https://lore.kernel.org/loongarch/1690272910-11869-6-git-send-email-yangtiezhu@loongson.cn/

Thanks,
Tiezhu


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC PATCH 4/4] LoongArch: Remove -fno-jump-tables for objtool
  2024-07-13  9:10     ` Xi Ruoyao
@ 2024-07-15 10:35       ` Tiezhu Yang
  0 siblings, 0 replies; 12+ messages in thread
From: Tiezhu Yang @ 2024-07-15 10:35 UTC (permalink / raw)
  To: Xi Ruoyao, Josh Poimboeuf, Peter Zijlstra, Huacai Chen
  Cc: loongarch, linux-kernel

On 07/13/2024 05:10 PM, Xi Ruoyao wrote:
> On Fri, 2024-07-12 at 17:49 +0800, Xi Ruoyao wrote:
>> On Fri, 2024-07-12 at 17:15 +0800, Tiezhu Yang wrote:
>>> -ifdef CONFIG_OBJTOOL
>>> -KBUILD_CFLAGS			+= -fno-jump-tables
>>> -endif
>>> +KBUILD_AFLAGS			+= $(call cc-option,-mannotate-tablejump) $(call cc-option,-Wa$(comma)-mannotate-tablejump)
>>> +KBUILD_CFLAGS			+= $(call cc-option,-mannotate-tablejump) $(call cc-option,-Wa$(comma)-mannotate-tablejump)
>>
>> KBUILD_AFLAGS isn't needed, and $(call cc-option,-Wa$(comma)-mannotate-
>> tablejump) will always expand to nothing because the assembler does not
>> have -mannotate-tablejump.
>>
>> The assembler never creates a jump table itself.

Thanks, you are right, I will modify it in the formal v1 series.

> BTW have you discussed with Lulu about the -mannotate-tablejump patch?
> I guess maybe an intra-Loongson discussion would be helpful.

Yes, I have discussed with Loongson compiler team some days ago
and will discuss more to reach an agreement in the next few days.

Thanks,
Tiezhu


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-07-15 10:35 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-12  9:15 [RFC PATCH 0/4] Add jump table support for objtool on LoongArch Tiezhu Yang
2024-07-12  9:15 ` [RFC PATCH 1/4] objtool: Check local label in find_jump_table() Tiezhu Yang
2024-07-12  9:15 ` [RFC PATCH 2/4] objtool: Check various types in add_jump_table() Tiezhu Yang
2024-07-12  9:15 ` [RFC PATCH 3/4] objtool/LoongArch: Add support for jump table Tiezhu Yang
2024-07-12  9:15 ` [RFC PATCH 4/4] LoongArch: Remove -fno-jump-tables for objtool Tiezhu Yang
2024-07-12  9:40   ` Huacai Chen
2024-07-15 10:32     ` Tiezhu Yang
2024-07-12  9:49   ` Xi Ruoyao
2024-07-13  9:10     ` Xi Ruoyao
2024-07-15 10:35       ` Tiezhu Yang
2024-07-12 10:19 ` [RFC PATCH 0/4] Add jump table support for objtool on LoongArch Jinyang He
2024-07-15  9:56   ` Tiezhu Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®