Skip to content

Commit 597bee0

Browse files
authored
Merge pull request #529 from nbdd0121/rust
kallsyms: use ULEB128 for big symbols
2 parents 0c07aeb + ce50901 commit 597bee0

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

kernel/kallsyms.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,20 @@ static unsigned int kallsyms_expand_symbol(unsigned int off,
6969
data = &kallsyms_names[off];
7070
len = *data;
7171
data++;
72+
off++;
73+
74+
/* If MSB is 1, it is a "big" symbol, so needs an additional byte. */
75+
if ((len & 0x80) != 0) {
76+
len = (len & 0x7F) | (*data << 7);
77+
data++;
78+
off++;
79+
}
7280

7381
/*
7482
* Update the offset to return the offset for the next symbol on
7583
* the compressed stream.
7684
*/
77-
off += len + 1;
78-
79-
/* If zero, it is a "big" symbol, so a two byte length follows. */
80-
if (len == 0) {
81-
len = (data[0] << 8) | data[1];
82-
data += 2;
83-
off += len + 2;
84-
}
85+
off += len;
8586

8687
/*
8788
* For every byte on the compressed symbol data, copy the table

scripts/kallsyms.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -473,33 +473,31 @@ static void write_src(void)
473473
if ((i & 0xFF) == 0)
474474
markers[i >> 8] = off;
475475

476-
/*
477-
* There cannot be any symbol of length zero -- we use that
478-
* to mark a "big" symbol (and it doesn't make sense anyway).
479-
*/
476+
/* There cannot be any symbol of length zero. */
480477
if (table[i]->len == 0) {
481478
fprintf(stderr, "kallsyms failure: "
482479
"unexpected zero symbol length\n");
483480
exit(EXIT_FAILURE);
484481
}
485482

486-
/* Only lengths that fit in up to two bytes are supported. */
487-
if (table[i]->len > 0xFFFF) {
483+
/* Only lengths that fit in up-to-two-byte ULEB128 are supported. */
484+
if (table[i]->len > 0x3FFF) {
488485
fprintf(stderr, "kallsyms failure: "
489486
"unexpected huge symbol length\n");
490487
exit(EXIT_FAILURE);
491488
}
492489

493-
if (table[i]->len <= 0xFF) {
490+
/* Encode length with ULEB128. */
491+
if (table[i]->len <= 0x7F) {
494492
/* Most symbols use a single byte for the length. */
495493
printf("\t.byte 0x%02x", table[i]->len);
496494
off += table[i]->len + 1;
497495
} else {
498-
/* "Big" symbols use a zero and then two bytes. */
499-
printf("\t.byte 0x00, 0x%02x, 0x%02x",
500-
(table[i]->len >> 8) & 0xFF,
501-
table[i]->len & 0xFF);
502-
off += table[i]->len + 3;
496+
/* "Big" symbols use two bytes. */
497+
printf("\t.byte 0x%02x, 0x%02x",
498+
(table[i]->len & 0x7F) | 0x80,
499+
(table[i]->len >> 7) & 0x7F);
500+
off += table[i]->len + 2;
503501
}
504502
for (k = 0; k < table[i]->len; k++)
505503
printf(", 0x%02x", table[i]->sym[k]);

0 commit comments

Comments
 (0)