Skip to content

Commit b448990

Browse files
masahir0yarter97
authored andcommitted
scripts/kallsyms: set relative_base more effectively
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. Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 0f70e89 commit b448990

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Diff for: scripts/kallsyms.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -763,11 +763,15 @@ static void record_relative_base(void)
763763
{
764764
unsigned int i;
765765

766-
relative_base = -1ULL;
767766
for (i = 0; i < table_cnt; i++)
768-
if (!symbol_absolute(&table[i]) &&
769-
table[i].addr < relative_base)
767+
if (!symbol_absolute(&table[i])) {
768+
/*
769+
* The table is sorted by address.
770+
* Take the first non-absolute symbol value.
771+
*/
770772
relative_base = table[i].addr;
773+
return;
774+
}
771775
}
772776

773777
int main(int argc, char **argv)
@@ -797,9 +801,9 @@ int main(int argc, char **argv)
797801
shrink_table();
798802
if (absolute_percpu)
799803
make_percpus_absolute();
804+
sort_symbols();
800805
if (base_relative)
801806
record_relative_base();
802-
sort_symbols();
803807
optimize_token_table();
804808
write_src();
805809

0 commit comments

Comments
 (0)