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 commitc5b1184dec
("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:c5b1184dec
("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>
43 lines
1,000 B
C
43 lines
1,000 B
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* Copyright (C) 2015 Josh Poimboeuf <jpoimboe@redhat.com>
|
|
*/
|
|
|
|
#ifndef _SPECIAL_H
|
|
#define _SPECIAL_H
|
|
|
|
#include <stdbool.h>
|
|
#include <objtool/check.h>
|
|
#include <objtool/elf.h>
|
|
|
|
#define C_JUMP_TABLE_SECTION ".data.rel.ro.c_jump_table"
|
|
|
|
struct special_alt {
|
|
struct list_head list;
|
|
|
|
bool group;
|
|
bool skip_orig;
|
|
bool skip_alt;
|
|
bool jump_or_nop;
|
|
u8 key_addend;
|
|
|
|
struct section *orig_sec;
|
|
unsigned long orig_off;
|
|
|
|
struct section *new_sec;
|
|
unsigned long new_off;
|
|
|
|
unsigned int orig_len, new_len; /* group only */
|
|
};
|
|
|
|
int special_get_alts(struct elf *elf, struct list_head *alts);
|
|
|
|
void arch_handle_alternative(unsigned short feature, struct special_alt *alt);
|
|
|
|
bool arch_support_alt_relocation(struct special_alt *special_alt,
|
|
struct instruction *insn,
|
|
struct reloc *reloc);
|
|
struct reloc *arch_find_switch_table(struct objtool_file *file,
|
|
struct instruction *insn,
|
|
unsigned long *table_size);
|
|
#endif /* _SPECIAL_H */
|