Skip to content

Commit 404bad7

Browse files
committed
scripts/kallsyms: change the output order
Currently, this tool outputs symbol data in the following order. (1) kallsyms_addressed / kallsyms_offsets (2) kallsyms_relative_base (3) kallsyms_num_syms (4) kallsyms_names (5) kallsyms_markers (6) kallsyms_seq_of_names (7) kallsyms_token_table (8) kallsyms_token_index This commit changes the order as follows: (1) kallsyms_num_syms (2) kallsyms_names (3) kallsyms_markers (4) kallsyms_token_table (5) kallsyms_token_index (6) kallsyms_addressed / kallsyms_offsets (7) kallsyms_relative_base (8) kallsyms_seq_of_names The motivation is to decrease the number of function calls to expand_symbol() and cleanup_symbol_name(). The compressed names are only required for writing 'kallsyms_names'. If you do this first, we can restore the original symbol names. You do not need to repeat the same operation over again. The actual refactoring will happen in the next commit. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
1 parent 320e7c9 commit 404bad7

1 file changed

Lines changed: 59 additions & 59 deletions

File tree

scripts/kallsyms.c

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -412,56 +412,6 @@ static void write_src(void)
412412

413413
printf("\t.section .rodata, \"a\"\n");
414414

415-
if (!base_relative)
416-
output_label("kallsyms_addresses");
417-
else
418-
output_label("kallsyms_offsets");
419-
420-
for (i = 0; i < table_cnt; i++) {
421-
if (base_relative) {
422-
/*
423-
* Use the offset relative to the lowest value
424-
* encountered of all relative symbols, and emit
425-
* non-relocatable fixed offsets that will be fixed
426-
* up at runtime.
427-
*/
428-
429-
long long offset;
430-
int overflow;
431-
432-
if (!absolute_percpu) {
433-
offset = table[i]->addr - relative_base;
434-
overflow = (offset < 0 || offset > UINT_MAX);
435-
} else if (symbol_absolute(table[i])) {
436-
offset = table[i]->addr;
437-
overflow = (offset < 0 || offset > INT_MAX);
438-
} else {
439-
offset = relative_base - table[i]->addr - 1;
440-
overflow = (offset < INT_MIN || offset >= 0);
441-
}
442-
if (overflow) {
443-
fprintf(stderr, "kallsyms failure: "
444-
"%s symbol value %#llx out of range in relative mode\n",
445-
symbol_absolute(table[i]) ? "absolute" : "relative",
446-
table[i]->addr);
447-
exit(EXIT_FAILURE);
448-
}
449-
expand_symbol(table[i]->sym, table[i]->len, buf);
450-
printf("\t.long\t%#x /* %s */\n", (int)offset, buf);
451-
} else if (!symbol_absolute(table[i])) {
452-
output_address(table[i]->addr);
453-
} else {
454-
printf("\tPTR\t%#llx\n", table[i]->addr);
455-
}
456-
}
457-
printf("\n");
458-
459-
if (base_relative) {
460-
output_label("kallsyms_relative_base");
461-
output_address(relative_base);
462-
printf("\n");
463-
}
464-
465415
output_label("kallsyms_num_syms");
466416
printf("\t.long\t%u\n", table_cnt);
467417
printf("\n");
@@ -521,15 +471,6 @@ static void write_src(void)
521471

522472
free(markers);
523473

524-
sort_symbols_by_name();
525-
output_label("kallsyms_seqs_of_names");
526-
for (i = 0; i < table_cnt; i++)
527-
printf("\t.byte 0x%02x, 0x%02x, 0x%02x\n",
528-
(unsigned char)(table[i]->seq >> 16),
529-
(unsigned char)(table[i]->seq >> 8),
530-
(unsigned char)(table[i]->seq >> 0));
531-
printf("\n");
532-
533474
output_label("kallsyms_token_table");
534475
off = 0;
535476
for (i = 0; i < 256; i++) {
@@ -544,6 +485,65 @@ static void write_src(void)
544485
for (i = 0; i < 256; i++)
545486
printf("\t.short\t%d\n", best_idx[i]);
546487
printf("\n");
488+
489+
if (!base_relative)
490+
output_label("kallsyms_addresses");
491+
else
492+
output_label("kallsyms_offsets");
493+
494+
for (i = 0; i < table_cnt; i++) {
495+
if (base_relative) {
496+
/*
497+
* Use the offset relative to the lowest value
498+
* encountered of all relative symbols, and emit
499+
* non-relocatable fixed offsets that will be fixed
500+
* up at runtime.
501+
*/
502+
503+
long long offset;
504+
int overflow;
505+
506+
if (!absolute_percpu) {
507+
offset = table[i]->addr - relative_base;
508+
overflow = (offset < 0 || offset > UINT_MAX);
509+
} else if (symbol_absolute(table[i])) {
510+
offset = table[i]->addr;
511+
overflow = (offset < 0 || offset > INT_MAX);
512+
} else {
513+
offset = relative_base - table[i]->addr - 1;
514+
overflow = (offset < INT_MIN || offset >= 0);
515+
}
516+
if (overflow) {
517+
fprintf(stderr, "kallsyms failure: "
518+
"%s symbol value %#llx out of range in relative mode\n",
519+
symbol_absolute(table[i]) ? "absolute" : "relative",
520+
table[i]->addr);
521+
exit(EXIT_FAILURE);
522+
}
523+
expand_symbol(table[i]->sym, table[i]->len, buf);
524+
printf("\t.long\t%#x /* %s */\n", (int)offset, buf);
525+
} else if (!symbol_absolute(table[i])) {
526+
output_address(table[i]->addr);
527+
} else {
528+
printf("\tPTR\t%#llx\n", table[i]->addr);
529+
}
530+
}
531+
printf("\n");
532+
533+
if (base_relative) {
534+
output_label("kallsyms_relative_base");
535+
output_address(relative_base);
536+
printf("\n");
537+
}
538+
539+
sort_symbols_by_name();
540+
output_label("kallsyms_seqs_of_names");
541+
for (i = 0; i < table_cnt; i++)
542+
printf("\t.byte 0x%02x, 0x%02x, 0x%02x\n",
543+
(unsigned char)(table[i]->seq >> 16),
544+
(unsigned char)(table[i]->seq >> 8),
545+
(unsigned char)(table[i]->seq >> 0));
546+
printf("\n");
547547
}
548548

549549

0 commit comments

Comments
 (0)