Skip to content

Commit 73cfc53

Browse files
ardbiesheuveljpoimboe
authored andcommitted
objtool: Fix C jump table annotations for Clang
A C jump table (such as the one used by the BPF interpreter) is a const global array of absolute code addresses, and this means that the actual values in the table may not be known until the kernel is booted (e.g., when using KASLR or when the kernel VA space is sized dynamically). When using PIE codegen, the compiler will default to placing such const global objects in .data.rel.ro (which is annotated as writable), rather than .rodata (which is annotated as read-only). As C jump tables are explicitly emitted into .rodata, this used to result in warnings for LoongArch builds (which uses PIE codegen for the entire kernel) like Warning: setting incorrect section attributes for .rodata..c_jump_table due to the fact that the explicitly specified .rodata section inherited the read-write annotation that the compiler uses for such objects when using PIE codegen. This warning was suppressed by explicitly adding the read-only annotation to the __attribute__((section(""))) string, by commit c5b1184 ("compiler.h: specify correct attribute for .rodata..c_jump_table") Unfortunately, this hack does not work on Clang's integrated assembler, which happily interprets the appended section type and permission specifiers as part of the section name, which therefore no longer matches the hard-coded pattern '.rodata..c_jump_table' that objtool expects, causing it to emit a warning kernel/bpf/core.o: warning: objtool: ___bpf_prog_run+0x20: sibling call from callable instruction with modified stack frame Work around this, by emitting C jump tables into .data.rel.ro instead, which is treated as .rodata by the linker script for all builds, not just PIE based ones. Fixes: c5b1184 ("compiler.h: specify correct attribute for .rodata..c_jump_table") Tested-by: Tiezhu Yang <yangtiezhu@loongson.cn> # on LoongArch Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Link: https://lore.kernel.org/r/20250221135704.431269-6-ardb+git@google.com Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
1 parent 68f3ea7 commit 73cfc53

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

include/linux/compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
110110
/* Unreachable code */
111111
#ifdef CONFIG_OBJTOOL
112112
/* Annotate a C jump table to allow objtool to follow the code flow */
113-
#define __annotate_jump_table __section(".rodata..c_jump_table,\"a\",@progbits #")
113+
#define __annotate_jump_table __section(".data.rel.ro.c_jump_table")
114114
#else /* !CONFIG_OBJTOOL */
115115
#define __annotate_jump_table
116116
#endif /* CONFIG_OBJTOOL */

tools/objtool/check.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,13 +2471,14 @@ static void mark_rodata(struct objtool_file *file)
24712471
*
24722472
* - .rodata: can contain GCC switch tables
24732473
* - .rodata.<func>: same, if -fdata-sections is being used
2474-
* - .rodata..c_jump_table: contains C annotated jump tables
2474+
* - .data.rel.ro.c_jump_table: contains C annotated jump tables
24752475
*
24762476
* .rodata.str1.* sections are ignored; they don't contain jump tables.
24772477
*/
24782478
for_each_sec(file, sec) {
2479-
if (!strncmp(sec->name, ".rodata", 7) &&
2480-
!strstr(sec->name, ".str1.")) {
2479+
if ((!strncmp(sec->name, ".rodata", 7) &&
2480+
!strstr(sec->name, ".str1.")) ||
2481+
!strncmp(sec->name, ".data.rel.ro", 12)) {
24812482
sec->rodata = true;
24822483
found = true;
24832484
}

tools/objtool/include/objtool/special.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <objtool/check.h>
1111
#include <objtool/elf.h>
1212

13-
#define C_JUMP_TABLE_SECTION ".rodata..c_jump_table"
13+
#define C_JUMP_TABLE_SECTION ".data.rel.ro.c_jump_table"
1414

1515
struct special_alt {
1616
struct list_head list;

0 commit comments

Comments
 (0)