Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

module: Ignore RISC-V mapping symbols too

RISC-V has an extended form of mapping symbols that we use to encode
the ISA when it changes in the middle of an ELF. This trips up modpost
as a build failure, I haven't yet verified it yet but I believe the
kallsyms difference should result in stacks looking sane again.

Reported-by: Randy Dunlap <rdunlap@infradead.org>
Closes: https://lore.kernel.org/all/9d9e2902-5489-4bf0-d9cb-556c8e5d71c2@infradead.org/
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Reviewed-by: Randy Dunlap <rdunlap@infradead.org>
Tested-by: Randy Dunlap <rdunlap@infradead.org> # build-tested
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>

authored by

Palmer Dabbelt and committed by
Luis Chamberlain
c05780ef 06c2afb8

+13 -3
+11 -1
include/linux/module_symbol.h
··· 3 3 #define _LINUX_MODULE_SYMBOL_H 4 4 5 5 /* This ignores the intensely annoying "mapping symbols" found in ELF files. */ 6 - static inline int is_mapping_symbol(const char *str) 6 + static inline int is_mapping_symbol(const char *str, int is_riscv) 7 7 { 8 8 if (str[0] == '.' && str[1] == 'L') 9 9 return true; 10 10 if (str[0] == 'L' && str[1] == '0') 11 11 return true; 12 + /* 13 + * RISC-V defines various special symbols that start with "$".  The 14 + * mapping symbols, which exist to differentiate between incompatible 15 + * instruction encodings when disassembling, show up all over the place 16 + * and are generally not meant to be treated like other symbols.  So 17 + * just ignore any of the special symbols. 18 + */ 19 + if (is_riscv) 20 + return str[0] == '$'; 21 + 12 22 return str[0] == '$' && 13 23 (str[1] == 'a' || str[1] == 'd' || str[1] == 't' || str[1] == 'x') 14 24 && (str[2] == '\0' || str[2] == '.');
+1 -1
kernel/module/kallsyms.c
··· 289 289 * and inserted at a whim. 290 290 */ 291 291 if (*kallsyms_symbol_name(kallsyms, i) == '\0' || 292 - is_mapping_symbol(kallsyms_symbol_name(kallsyms, i))) 292 + is_mapping_symbol(kallsyms_symbol_name(kallsyms, i), IS_ENABLED(CONFIG_RISCV))) 293 293 continue; 294 294 295 295 if (thisval <= addr && thisval > bestval) {
+1 -1
scripts/mod/modpost.c
··· 1052 1052 1053 1053 if (!name || !strlen(name)) 1054 1054 return 0; 1055 - return !is_mapping_symbol(name); 1055 + return !is_mapping_symbol(name, elf->hdr->e_machine == EM_RISCV); 1056 1056 } 1057 1057 1058 1058 /* Look up the nearest symbol based on the section and the address */