Skip to content

Commit

Permalink
scripts/kallsyms: set relative_base more effectively
Browse files Browse the repository at this point in the history
Currently, record_relative_base() iterates over the entire table to
find the minimum address, but it is not efficient because we sort
the table anyway.

After sort_symbol(), the table is sorted by address. (kallsyms parses
the 'nm -n' output, so the data is already sorted by address, but this
commit does not rely on it.)

Move record_relative_base() after sort_symbols(), and take the first
non-absolute symbol value.
  • Loading branch information
b1ad3runn3r committed Sep 9, 2021
1 parent 1559be2 commit 38c3a90
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions scripts/kallsyms.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,11 +746,15 @@ static void record_relative_base(void)
{
unsigned int i;

relative_base = -1ULL;
for (i = 0; i < table_cnt; i++)
if (!symbol_absolute(&table[i]) &&
table[i].addr < relative_base)
if (!symbol_absolute(&table[i])) {
/*
* The table is sorted by address.
* Take the first non-absolute symbol value.
*/
relative_base = table[i].addr;
return;
}
}

int main(int argc, char **argv)
Expand All @@ -774,9 +778,9 @@ int main(int argc, char **argv)
shrink_table();
if (absolute_percpu)
make_percpus_absolute();
sort_symbols();
if (base_relative)
record_relative_base();
sort_symbols();
optimize_token_table();
write_src();

Expand Down

0 comments on commit 38c3a90

Please sign in to comment.