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

objtool: Clean up elf_write() condition

With there being multiple ways to change the ELF data, let's more
concisely track modification.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>

+18 -6
+3 -1
tools/objtool/check.c
··· 2740 2740 2741 2741 objname = _objname; 2742 2742 2743 - file.elf = elf_open_read(objname, orc ? O_RDWR : O_RDONLY); 2743 + file.elf = elf_open_read(objname, O_RDWR); 2744 2744 if (!file.elf) 2745 2745 return 1; 2746 2746 ··· 2801 2801 ret = create_orc_sections(&file); 2802 2802 if (ret < 0) 2803 2803 goto out; 2804 + } 2804 2805 2806 + if (file.elf->changed) { 2805 2807 ret = elf_write(file.elf); 2806 2808 if (ret < 0) 2807 2809 goto out;
+11 -2
tools/objtool/elf.c
··· 713 713 elf_hash_add(elf->section_hash, &sec->hash, sec->idx); 714 714 elf_hash_add(elf->section_name_hash, &sec->name_hash, str_hash(sec->name)); 715 715 716 + elf->changed = true; 717 + 716 718 return sec; 717 719 } 718 720 ··· 748 746 return sec; 749 747 } 750 748 751 - int elf_rebuild_rela_section(struct section *sec) 749 + int elf_rebuild_rela_section(struct elf *elf, struct section *sec) 752 750 { 753 751 struct rela *rela; 754 752 int nr, idx = 0, size; ··· 764 762 perror("malloc"); 765 763 return -1; 766 764 } 765 + 766 + sec->changed = true; 767 + elf->changed = true; 767 768 768 769 sec->data->d_buf = relas; 769 770 sec->data->d_size = size; ··· 784 779 return 0; 785 780 } 786 781 787 - int elf_write(const struct elf *elf) 782 + int elf_write(struct elf *elf) 788 783 { 789 784 struct section *sec; 790 785 Elf_Scn *s; ··· 801 796 WARN_ELF("gelf_update_shdr"); 802 797 return -1; 803 798 } 799 + 800 + sec->changed = false; 804 801 } 805 802 } 806 803 ··· 814 807 WARN_ELF("elf_update"); 815 808 return -1; 816 809 } 810 + 811 + elf->changed = false; 817 812 818 813 return 0; 819 814 }
+3 -2
tools/objtool/elf.h
··· 76 76 Elf *elf; 77 77 GElf_Ehdr ehdr; 78 78 int fd; 79 + bool changed; 79 80 char *name; 80 81 struct list_head sections; 81 82 DECLARE_HASHTABLE(symbol_hash, ELF_HASH_BITS); ··· 119 118 struct section *elf_create_section(struct elf *elf, const char *name, size_t entsize, int nr); 120 119 struct section *elf_create_rela_section(struct elf *elf, struct section *base); 121 120 void elf_add_rela(struct elf *elf, struct rela *rela); 122 - int elf_write(const struct elf *elf); 121 + int elf_write(struct elf *elf); 123 122 void elf_close(struct elf *elf); 124 123 125 124 struct section *find_section_by_name(const struct elf *elf, const char *name); ··· 131 130 struct rela *find_rela_by_dest_range(const struct elf *elf, struct section *sec, 132 131 unsigned long offset, unsigned int len); 133 132 struct symbol *find_func_containing(struct section *sec, unsigned long offset); 134 - int elf_rebuild_rela_section(struct section *sec); 133 + int elf_rebuild_rela_section(struct elf *elf, struct section *sec); 135 134 136 135 #define for_each_sec(file, sec) \ 137 136 list_for_each_entry(sec, &file->elf->sections, list)
+1 -1
tools/objtool/orc_gen.c
··· 222 222 } 223 223 } 224 224 225 - if (elf_rebuild_rela_section(ip_relasec)) 225 + if (elf_rebuild_rela_section(file->elf, ip_relasec)) 226 226 return -1; 227 227 228 228 return 0;