Skip to content

Commit c05780e

Browse files
palmer-dabbeltmcgrof
authored andcommitted
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>
1 parent 06c2afb commit c05780e

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

include/linux/module_symbol.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,22 @@
33
#define _LINUX_MODULE_SYMBOL_H
44

55
/* 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)
77
{
88
if (str[0] == '.' && str[1] == 'L')
99
return true;
1010
if (str[0] == 'L' && str[1] == '0')
1111
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+
1222
return str[0] == '$' &&
1323
(str[1] == 'a' || str[1] == 'd' || str[1] == 't' || str[1] == 'x')
1424
&& (str[2] == '\0' || str[2] == '.');

kernel/module/kallsyms.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ static const char *find_kallsyms_symbol(struct module *mod,
289289
* and inserted at a whim.
290290
*/
291291
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)))
293293
continue;
294294

295295
if (thisval <= addr && thisval > bestval) {

scripts/mod/modpost.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ static inline int is_valid_name(struct elf_info *elf, Elf_Sym *sym)
10521052

10531053
if (!name || !strlen(name))
10541054
return 0;
1055-
return !is_mapping_symbol(name);
1055+
return !is_mapping_symbol(name, elf->hdr->e_machine == EM_RISCV);
10561056
}
10571057

10581058
/* Look up the nearest symbol based on the section and the address */

0 commit comments

Comments
 (0)