Skip to content

Commit 8c7681d

Browse files
ojedaintel-lab-lkp
authored andcommitted
kallsyms: Support "big" kernel symbols (2-byte lengths)
Rust symbols can become quite long due to namespacing introduced by modules, types, traits, generics, etc. Increasing to 255 is not enough in some cases, and therefore we need to introduce 2-byte lengths to the symbol table. We call these "big" symbols. In order to avoid increasing all lengths to 2 bytes (since most of them only require 1 byte, including many Rust ones), we use length zero to mark "big" symbols in the table. 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 d5c09ff commit 8c7681d

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

kernel/kallsyms.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ static unsigned int kallsyms_expand_symbol(unsigned int off,
7373
*/
7474
off += len + 1;
7575

76+
/* If zero, it is a "big" symbol, so a two byte length follows. */
77+
if (len == 0) {
78+
len = (data[0] << 8) | data[1];
79+
data += 2;
80+
off += len + 2;
81+
}
82+
7683
/*
7784
* For every byte on the compressed symbol data, copy the table
7885
* entry for that byte.

scripts/kallsyms.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,37 @@ static void write_src(void)
470470
if ((i & 0xFF) == 0)
471471
markers[i >> 8] = off;
472472

473-
printf("\t.byte 0x%02x", table[i]->len);
473+
/*
474+
* There cannot be any symbol of length zero -- we use that
475+
* to mark a "big" symbol (and it doesn't make sense anyway).
476+
*/
477+
if (table[i]->len == 0) {
478+
fprintf(stderr, "kallsyms failure: "
479+
"unexpected zero symbol length\n");
480+
exit(EXIT_FAILURE);
481+
}
482+
483+
/* Only lengths that fit in up to two bytes are supported. */
484+
if (table[i]->len > 0xFFFF) {
485+
fprintf(stderr, "kallsyms failure: "
486+
"unexpected huge symbol length\n");
487+
exit(EXIT_FAILURE);
488+
}
489+
490+
if (table[i]->len <= 0xFF) {
491+
/* Most symbols use a single byte for the length. */
492+
printf("\t.byte 0x%02x", table[i]->len);
493+
off += table[i]->len + 1;
494+
} else {
495+
/* "Big" symbols use a zero and then two bytes. */
496+
printf("\t.byte 0x00, 0x%02x, 0x%02x",
497+
(table[i]->len >> 8) & 0xFF,
498+
table[i]->len & 0xFF);
499+
off += table[i]->len + 3;
500+
}
474501
for (k = 0; k < table[i]->len; k++)
475502
printf(", 0x%02x", table[i]->sym[k]);
476503
printf("\n");
477-
478-
off += table[i]->len + 1;
479504
}
480505
printf("\n");
481506

0 commit comments

Comments
 (0)