]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
objtool/LoongArch: Get table size correctly if LTO is enabled
authorTiezhu Yang <yangtiezhu@loongson.cn>
Wed, 20 Aug 2025 14:23:15 +0000 (22:23 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Wed, 20 Aug 2025 14:23:15 +0000 (22:23 +0800)
When compiling with LLVM and CONFIG_LTO_CLANG is set, there exist many
objtool warnings "sibling call from callable instruction with modified
stack frame".

For this special case, the related object file shows that there is no
generated relocation section '.rela.discard.tablejump_annotate' for the
table jump instruction jirl, thus objtool can not know that what is the
actual destination address.

It needs to do something on the LLVM side to make sure that there is the
relocation section '.rela.discard.tablejump_annotate' if LTO is enabled,
but in order to maintain compatibility for the current LLVM compiler,
this can be done in the kernel Makefile for now. Ensure it is aware of
linker with LTO, '--loongarch-annotate-tablejump' needs to be passed via
'-mllvm' to ld.lld.

Before doing the above changes, it should handle the special case of the
relocation section '.rela.discard.tablejump_annotate' to get the correct
table size first, otherwise there are many objtool warnings and errors
if LTO is enabled.

There are many different rodata for each function if LTO is enabled, it
is necessary to enhance get_rodata_table_size_by_table_annotate().

Fixes: b95f852d3af2 ("objtool/LoongArch: Add support for switch table")
Closes: https://lore.kernel.org/loongarch/20250731175655.GA1455142@ax162/
Reported-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
tools/objtool/arch/loongarch/special.c

index e39f86d97002b9d6188eb8b7f273e913782d679d..a80b75f7b061f76ec789ef7a9f8c63f4aa6a7d9f 100644 (file)
@@ -27,6 +27,7 @@ static void get_rodata_table_size_by_table_annotate(struct objtool_file *file,
        struct table_info *next_table;
        unsigned long tmp_insn_offset;
        unsigned long tmp_rodata_offset;
+       bool is_valid_list = false;
 
        rsec = find_section_by_name(file->elf, ".rela.discard.tablejump_annotate");
        if (!rsec)
@@ -35,6 +36,12 @@ static void get_rodata_table_size_by_table_annotate(struct objtool_file *file,
        INIT_LIST_HEAD(&table_list);
 
        for_each_reloc(rsec, reloc) {
+               if (reloc->sym->sec->rodata)
+                       continue;
+
+               if (strcmp(insn->sec->name, reloc->sym->sec->name))
+                       continue;
+
                orig_table = malloc(sizeof(struct table_info));
                if (!orig_table) {
                        WARN("malloc failed");
@@ -49,6 +56,22 @@ static void get_rodata_table_size_by_table_annotate(struct objtool_file *file,
 
                if (reloc_idx(reloc) + 1 == sec_num_entries(rsec))
                        break;
+
+               if (strcmp(insn->sec->name, (reloc + 1)->sym->sec->name)) {
+                       list_for_each_entry(orig_table, &table_list, jump_info) {
+                               if (orig_table->insn_offset == insn->offset) {
+                                       is_valid_list = true;
+                                       break;
+                               }
+                       }
+
+                       if (!is_valid_list) {
+                               list_del_init(&table_list);
+                               continue;
+                       }
+
+                       break;
+               }
        }
 
        list_for_each_entry(orig_table, &table_list, jump_info) {