[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250214125135.2172-1-yangtiezhu@loongson.cn>
Date: Fri, 14 Feb 2025 20:51:35 +0800
From: Tiezhu Yang <yangtiezhu@...ngson.cn>
To: Josh Poimboeuf <jpoimboe@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Huacai Chen <chenhuacai@...nel.org>
Cc: loongarch@...ts.linux.dev,
linux-kernel@...r.kernel.org
Subject: [PATCH] objtool: Rename ".rodata..c_jump_table" to "..rodata.c_jump_table"
Specify the attribute like ".rodata..c_jump_table,\"a\",@progbits #"
explicitly works for GCC, but this hack apparently doesn't work with
Clang, the generated section name is wrong, resulting in a warning
and missing ORC for x86. This is because there is only one arg for
section name in LLVM, even if the so called attribute is specified,
it will be recognized as a whole for section name, so it is not a
good way to specify the attribute for this section.
In the top Makefile, there is "-fno-PIE" build flag. For x86, there
is no "-fPIE" build flag in arch/x86/Makefile for 64 bit kernel. But
for LoongArch, there is "-fPIE" build flag in arch/loongarch/Makefile
to override "-fno-PIE" in top Makefile. After some test with GCC and
Clang on x86 and LoongArch, it shows that the generated "W" (writable)
attribute of the section ".rodata..c_jump_table" is related with the
compiler option "-fPIE", and then lead to the GNU assembler warning:
"setting incorrect section attributes for .rodata..c_jump_table".
Based on the above analysis, in order to avoid changing the behavior
of GNU assembler and silence the GNU assembler warning, it is better
to rename ".rodata..c_jump_table" to "..rodata.c_jump_table" without
section attribute, it works well with GCC and Clang, no GNU assembler
warning for GCC and the section name is normal for Clang.
Fixes: c5b1184decc8 ("compiler.h: specify correct attribute for .rodata..c_jump_table")
Signed-off-by: Tiezhu Yang <yangtiezhu@...ngson.cn>
---
This patch is based on tip/tip.git objtool/urgent branch:
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/log/?h=objtool/urgent
include/asm-generic/vmlinux.lds.h | 2 +-
include/linux/compiler.h | 2 +-
tools/objtool/check.c | 5 +++--
tools/objtool/include/objtool/special.h | 2 +-
4 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 54504013c749..91a7e824ed8b 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -457,7 +457,7 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
. = ALIGN((align)); \
.rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
__start_rodata = .; \
- *(.rodata) *(.rodata.*) \
+ *(.rodata) *(.rodata.*) *(..rodata.*) \
SCHED_DATA \
RO_AFTER_INIT_DATA /* Read only after init */ \
. = ALIGN(8); \
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index b087de2f3e94..3d013f1412e0 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -110,7 +110,7 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
/* Unreachable code */
#ifdef CONFIG_OBJTOOL
/* Annotate a C jump table to allow objtool to follow the code flow */
-#define __annotate_jump_table __section(".rodata..c_jump_table,\"a\",@progbits #")
+#define __annotate_jump_table __section("..rodata.c_jump_table")
#else /* !CONFIG_OBJTOOL */
#define __annotate_jump_table
#endif /* CONFIG_OBJTOOL */
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 497cb8dfb3eb..1398ffc20b16 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2471,12 +2471,13 @@ static void mark_rodata(struct objtool_file *file)
*
* - .rodata: can contain GCC switch tables
* - .rodata.<func>: same, if -fdata-sections is being used
- * - .rodata..c_jump_table: contains C annotated jump tables
+ * - ..rodata.c_jump_table: contains C annotated jump tables
*
* .rodata.str1.* sections are ignored; they don't contain jump tables.
*/
for_each_sec(file, sec) {
- if (!strncmp(sec->name, ".rodata", 7) &&
+ if ((!strncmp(sec->name, ".rodata", 7) ||
+ !strncmp(sec->name, "..rodata", 8)) &&
!strstr(sec->name, ".str1.")) {
sec->rodata = true;
found = true;
diff --git a/tools/objtool/include/objtool/special.h b/tools/objtool/include/objtool/special.h
index e7ee7ffccefd..34acf4ae5fab 100644
--- a/tools/objtool/include/objtool/special.h
+++ b/tools/objtool/include/objtool/special.h
@@ -10,7 +10,7 @@
#include <objtool/check.h>
#include <objtool/elf.h>
-#define C_JUMP_TABLE_SECTION ".rodata..c_jump_table"
+#define C_JUMP_TABLE_SECTION "..rodata.c_jump_table"
struct special_alt {
struct list_head list;
--
2.42.0
Powered by blists - more mailing lists