Skip to content

Commit

Permalink
Merge pull request torvalds#529 from nbdd0121/rust
Browse files Browse the repository at this point in the history
kallsyms: use ULEB128 for big symbols
  • Loading branch information
ojeda authored Oct 26, 2021
2 parents 0c07aeb + ce50901 commit 597bee0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
17 changes: 9 additions & 8 deletions kernel/kallsyms.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,20 @@ static unsigned int kallsyms_expand_symbol(unsigned int off,
data = &kallsyms_names[off];
len = *data;
data++;
off++;

/* If MSB is 1, it is a "big" symbol, so needs an additional byte. */
if ((len & 0x80) != 0) {
len = (len & 0x7F) | (*data << 7);
data++;
off++;
}

/*
* Update the offset to return the offset for the next symbol on
* the compressed stream.
*/
off += len + 1;

/* If zero, it is a "big" symbol, so a two byte length follows. */
if (len == 0) {
len = (data[0] << 8) | data[1];
data += 2;
off += len + 2;
}
off += len;

/*
* For every byte on the compressed symbol data, copy the table
Expand Down
22 changes: 10 additions & 12 deletions scripts/kallsyms.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,33 +473,31 @@ static void write_src(void)
if ((i & 0xFF) == 0)
markers[i >> 8] = off;

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

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

if (table[i]->len <= 0xFF) {
/* Encode length with ULEB128. */
if (table[i]->len <= 0x7F) {
/* Most symbols use a single byte for the length. */
printf("\t.byte 0x%02x", table[i]->len);
off += table[i]->len + 1;
} else {
/* "Big" symbols use a zero and then two bytes. */
printf("\t.byte 0x00, 0x%02x, 0x%02x",
(table[i]->len >> 8) & 0xFF,
table[i]->len & 0xFF);
off += table[i]->len + 3;
/* "Big" symbols use two bytes. */
printf("\t.byte 0x%02x, 0x%02x",
(table[i]->len & 0x7F) | 0x80,
(table[i]->len >> 7) & 0x7F);
off += table[i]->len + 2;
}
for (k = 0; k < table[i]->len; k++)
printf(", 0x%02x", table[i]->sym[k]);
Expand Down

0 comments on commit 597bee0

Please sign in to comment.