Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

objtool: Print addresses with alternative instructions

All alternatives are disassemble side-by-side when using the --disas
option. However the address of each instruction is not printed because
instructions from different alternatives are not necessarily aligned.

Change this behavior to print the address of each instruction. Spaces
will appear between instructions from the same alternative when
instructions from different alternatives do not have the same alignment.

Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>
Link: https://patch.msgid.link/20251121095340.464045-22-alexandre.chartre@oracle.com

authored by

Alexandre Chartre and committed by
Peter Zijlstra
15e7ad86 a4f15996

+23 -12
+23 -12
tools/objtool/disas.c
··· 47 47 struct alternative *alt; /* alternative or NULL if default code */ 48 48 char *name; /* name for this alternative */ 49 49 int width; /* formatting width */ 50 - char *insn[DISAS_ALT_INSN_MAX]; /* alternative instructions */ 50 + struct { 51 + char *str; /* instruction string */ 52 + int offset; /* instruction offset */ 53 + } insn[DISAS_ALT_INSN_MAX]; /* alternative instructions */ 54 + int insn_idx; /* index of the next instruction to print */ 51 55 }; 52 56 53 57 #define DALT_DEFAULT(dalt) (!(dalt)->alt) ··· 365 361 disas_print_insn(stdout, dctx, insn, depth, "\n") 366 362 367 363 /* 368 - * Print a message in the instruction flow. If insn is not NULL then 369 - * the instruction address is printed in addition of the message, 370 - * otherwise only the message is printed. In all cases, the instruction 371 - * itself is not printed. 364 + * Print a message in the instruction flow. If sec is not NULL then the 365 + * address at the section offset is printed in addition of the message, 366 + * otherwise only the message is printed. 372 367 */ 373 368 static int disas_vprint(FILE *stream, struct section *sec, unsigned long offset, 374 369 int depth, const char *format, va_list ap) ··· 610 607 { 611 608 dalt->orig_insn = orig_insn; 612 609 dalt->alt = alt; 610 + dalt->insn_idx = 0; 613 611 dalt->name = alt ? disas_alt_name(alt) : strdup("DEFAULT"); 614 612 if (!dalt->name) 615 613 return -1; ··· 619 615 return 0; 620 616 } 621 617 622 - static int disas_alt_add_insn(struct disas_alt *dalt, int index, char *insn_str) 618 + static int disas_alt_add_insn(struct disas_alt *dalt, int index, char *insn_str, 619 + int offset) 623 620 { 624 621 int len; 625 622 ··· 631 626 } 632 627 633 628 len = strlen(insn_str); 634 - dalt->insn[index] = insn_str; 629 + dalt->insn[index].str = insn_str; 630 + dalt->insn[index].offset = offset; 635 631 if (len > dalt->width) 636 632 dalt->width = len; 637 633 ··· 647 641 { 648 642 struct objtool_file *file; 649 643 struct instruction *insn; 644 + int offset; 650 645 char *str; 651 646 int count; 652 647 int err; 653 648 654 649 file = dctx->file; 655 650 count = 0; 651 + offset = 0; 656 652 657 653 alt_for_each_insn(file, DALT_GROUP(dalt), insn) { 658 654 ··· 663 655 if (!str) 664 656 return -1; 665 657 666 - err = disas_alt_add_insn(dalt, count, str); 658 + err = disas_alt_add_insn(dalt, count, str, offset); 667 659 if (err) 668 660 break; 661 + offset += insn->len; 669 662 count++; 670 663 } 671 664 ··· 694 685 str = strdup(disas_result(dctx)); 695 686 if (!str) 696 687 return -1; 697 - err = disas_alt_add_insn(dalt, 0, str); 688 + err = disas_alt_add_insn(dalt, 0, str, 0); 698 689 if (err) 699 690 return -1; 700 691 ··· 719 710 for (i = 0; i < alt_count; i++) { 720 711 printf("%*s= %s\n", len, "", dalts[i].name); 721 712 for (j = 0; j < insn_count; j++) { 722 - if (!dalts[i].insn[j]) 713 + if (!dalts[i].insn[j].str) 723 714 break; 724 - printf("%*s| %s\n", len, "", dalts[i].insn[j]); 715 + disas_print(stdout, orig_insn->sec, 716 + orig_insn->offset + dalts[i].insn[j].offset, 0, 717 + "| %s\n", dalts[i].insn[j].str); 725 718 } 726 719 printf("%*s|\n", len, ""); 727 720 } ··· 822 811 for (i = 0; i < alt_count; i++) { 823 812 free(dalts[i].name); 824 813 for (j = 0; j < insn_count; j++) 825 - free(dalts[i].insn[j]); 814 + free(dalts[i].insn[j].str); 826 815 } 827 816 828 817 free(alt_name);