Skip to content

Commit eefb53b

Browse files
committed
kallsyms: increase maximum kernel symbol length to 512
Rust symbols can become quite long due to namespacing introduced by modules, types, traits, generics, etc. For instance, for: pub mod my_module { pub struct MyType; pub struct MyGenericType<T>(T); pub trait MyTrait { fn my_method() -> u32; } impl MyTrait for MyGenericType<MyType> { fn my_method() -> u32 { 42 } } } generates a symbol of length 96 when using the upcoming v0 mangling scheme: _RNvXNtCshGpAVYOtgW1_7example9my_moduleINtB2_13MyGenericTypeNtB2_6MyTypeENtB2_7MyTrait9my_method At the moment, Rust symbols may reach up to 300 in length. Setting 512 as the maximum seems like a reasonable choice to keep some headroom. Co-developed-by: Alex Gaynor <[email protected]> Signed-off-by: Alex Gaynor <[email protected]> Co-developed-by: Geoffrey Thomas <[email protected]> Signed-off-by: Geoffrey Thomas <[email protected]> Co-developed-by: Finn Behrens <[email protected]> Signed-off-by: Finn Behrens <[email protected]> Co-developed-by: Adam Bratschi-Kaye <[email protected]> Signed-off-by: Adam Bratschi-Kaye <[email protected]> Co-developed-by: Wedson Almeida Filho <[email protected]> Signed-off-by: Wedson Almeida Filho <[email protected]> Signed-off-by: Miguel Ojeda <[email protected]>
1 parent f4dd317 commit eefb53b

File tree

7 files changed

+8
-8
lines changed

7 files changed

+8
-8
lines changed

include/linux/kallsyms.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include <asm/sections.h>
1616

17-
#define KSYM_NAME_LEN 128
17+
#define KSYM_NAME_LEN 512
1818
#define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \
1919
2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1)
2020

kernel/livepatch/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static int klp_resolve_symbols(Elf64_Shdr *sechdrs, const char *strtab,
213213
* we use the smallest/strictest upper bound possible (56, based on
214214
* the current definition of MODULE_NAME_LEN) to prevent overflows.
215215
*/
216-
BUILD_BUG_ON(MODULE_NAME_LEN < 56 || KSYM_NAME_LEN != 128);
216+
BUILD_BUG_ON(MODULE_NAME_LEN < 56 || KSYM_NAME_LEN != 512);
217217

218218
relas = (Elf_Rela *) relasec->sh_addr;
219219
/* For each rela in this klp relocation section */
@@ -227,7 +227,7 @@ static int klp_resolve_symbols(Elf64_Shdr *sechdrs, const char *strtab,
227227

228228
/* Format: .klp.sym.sym_objname.sym_name,sympos */
229229
cnt = sscanf(strtab + sym->st_name,
230-
".klp.sym.%55[^.].%127[^,],%lu",
230+
".klp.sym.%55[^.].%511[^,],%lu",
231231
sym_objname, sym_name, &sympos);
232232
if (cnt != 3) {
233233
pr_err("symbol %s has an incorrectly formatted name\n",

scripts/kallsyms.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
2929

30-
#define KSYM_NAME_LEN 128
30+
#define KSYM_NAME_LEN 512
3131

3232
struct sym_entry {
3333
unsigned long long addr;

tools/include/linux/kallsyms.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <stdio.h>
77
#include <unistd.h>
88

9-
#define KSYM_NAME_LEN 128
9+
#define KSYM_NAME_LEN 512
1010

1111
struct module;
1212

tools/include/linux/lockdep.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static inline int debug_locks_off(void)
4747

4848
#define task_pid_nr(tsk) ((tsk)->pid)
4949

50-
#define KSYM_NAME_LEN 128
50+
#define KSYM_NAME_LEN 512
5151
#define printk(...) dprintf(STDOUT_FILENO, __VA_ARGS__)
5252
#define pr_err(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
5353
#define pr_warn pr_err

tools/lib/perf/include/perf/event.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct perf_record_throttle {
9595
};
9696

9797
#ifndef KSYM_NAME_LEN
98-
#define KSYM_NAME_LEN 256
98+
#define KSYM_NAME_LEN 512
9999
#endif
100100

101101
struct perf_record_ksymbol {

tools/lib/symbol/kallsyms.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <linux/types.h>
88

99
#ifndef KSYM_NAME_LEN
10-
#define KSYM_NAME_LEN 256
10+
#define KSYM_NAME_LEN 512
1111
#endif
1212

1313
static inline u8 kallsyms2elf_binding(char type)

0 commit comments

Comments
 (0)