Commit ead165f
objtool: Fix symbol creation
Nathan reported objtool failing with the following messages:
warning: objtool: no non-local symbols !?
warning: objtool: gelf_update_symshndx: invalid section index
The problem is due to commit 4abff6d ("objtool: Fix code relocs
vs weak symbols") failing to consider the case where an object would
have no non-local symbols.
The problem that commit tries to address is adding a STB_LOCAL symbol
to the symbol table in light of the ELF spec's requirement that:
In each symbol table, all symbols with STB_LOCAL binding preced the
weak and global symbols. As ``Sections'' above describes, a symbol
table section's sh_info section header member holds the symbol table
index for the first non-local symbol.
The approach taken is to find this first non-local symbol, move that
to the end and then re-use the freed spot to insert a new local symbol
and increment sh_info.
Except it never considered the case of object files without global
symbols and got a whole bunch of details wrong -- so many in fact that
it is a wonder it ever worked :/
Specifically:
- It failed to re-hash the symbol on the new index, so a subsequent
find_symbol_by_index() would not find it at the new location and a
query for the old location would now return a non-deterministic
choice between the old and new symbol.
- It failed to appreciate that the GElf wrappers are not a valid disk
format (it works because GElf is basically Elf64 and we only
support x86_64 atm.)
- It failed to fully appreciate how horrible the libelf API really is
and got the gelf_update_symshndx() call pretty much completely
wrong; with the direct consequence that if inserting a second
STB_LOCAL symbol would require moving the same STB_GLOBAL symbol
again it would completely come unstuck.
Write a new elf_update_symbol() function that wraps all the magic
required to update or create a new symbol at a given index.
Specifically, gelf_update_sym*() require an @ndx argument that is
relative to the @DaTa argument; this means you have to manually
iterate the section data descriptor list and update @ndx.
Fixes: 4abff6d ("objtool: Fix code relocs vs weak symbols")
Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Cc: <stable@vger.kernel.org>
Link: https://lkml.kernel.org/r/YoPCTEYjoPqE4ZxB@hirez.programming.kicks-ass.net1 parent 1d1a0e7 commit ead165f
1 file changed
Lines changed: 129 additions & 69 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
374 | 374 | | |
375 | 375 | | |
376 | 376 | | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
377 | 380 | | |
378 | 381 | | |
379 | 382 | | |
| |||
438 | 441 | | |
439 | 442 | | |
440 | 443 | | |
441 | | - | |
442 | | - | |
443 | 444 | | |
444 | 445 | | |
445 | 446 | | |
| |||
603 | 604 | | |
604 | 605 | | |
605 | 606 | | |
606 | | - | |
607 | | - | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
608 | 613 | | |
609 | | - | |
610 | | - | |
| 614 | + | |
| 615 | + | |
611 | 616 | | |
612 | | - | |
613 | | - | |
614 | | - | |
615 | | - | |
616 | | - | |
617 | | - | |
618 | | - | |
619 | | - | |
620 | | - | |
621 | | - | |
622 | | - | |
623 | | - | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
624 | 622 | | |
625 | 623 | | |
626 | 624 | | |
627 | 625 | | |
628 | 626 | | |
629 | 627 | | |
630 | 628 | | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
635 | 635 | | |
636 | 636 | | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
641 | 642 | | |
642 | | - | |
643 | | - | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
644 | 646 | | |
645 | | - | |
646 | | - | |
647 | | - | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
648 | 652 | | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
653 | 688 | | |
654 | 689 | | |
655 | 690 | | |
656 | | - | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
657 | 713 | | |
658 | | - | |
| 714 | + | |
659 | 715 | | |
660 | 716 | | |
| 717 | + | |
661 | 718 | | |
662 | | - | |
663 | | - | |
664 | | - | |
665 | | - | |
666 | | - | |
667 | | - | |
668 | | - | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
669 | 722 | | |
670 | 723 | | |
671 | | - | |
| 724 | + | |
672 | 725 | | |
673 | 726 | | |
674 | 727 | | |
675 | 728 | | |
676 | 729 | | |
677 | 730 | | |
678 | | - | |
679 | | - | |
680 | | - | |
| 731 | + | |
| 732 | + | |
681 | 733 | | |
682 | 734 | | |
683 | 735 | | |
684 | 736 | | |
685 | | - | |
686 | | - | |
687 | 737 | | |
688 | 738 | | |
689 | 739 | | |
690 | 740 | | |
691 | 741 | | |
692 | | - | |
| 742 | + | |
693 | 743 | | |
694 | 744 | | |
695 | 745 | | |
696 | 746 | | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | 747 | | |
705 | 748 | | |
706 | 749 | | |
| |||
710 | 753 | | |
711 | 754 | | |
712 | 755 | | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
717 | | - | |
718 | | - | |
719 | | - | |
720 | | - | |
721 | | - | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
722 | 774 | | |
723 | 775 | | |
| 776 | + | |
| 777 | + | |
724 | 778 | | |
725 | 779 | | |
726 | | - | |
727 | | - | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
728 | 783 | | |
729 | 784 | | |
730 | 785 | | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
731 | 791 | | |
732 | 792 | | |
733 | 793 | | |
| |||
0 commit comments