scripts/kallsyms: set relative_base more effectively
authorMasahiro Yamada <yamada.masahiro@socionext.com>
Sat, 23 Nov 2019 16:04:32 +0000 (01:04 +0900)
committerMasahiro Yamada <yamada.masahiro@socionext.com>
Mon, 25 Nov 2019 12:02:18 +0000 (21:02 +0900)
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 <yamada.masahiro@socionext.com>
scripts/kallsyms.c

index de986ed..c9efb67 100644 (file)
@@ -739,11 +739,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)
@@ -767,9 +771,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();