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: Add mark_sec_changed()

Ensure elf->changed always gets set when sec->changed gets set.

Link: https://lore.kernel.org/r/9a810a8d2e28af6ba07325362d0eb4703bb09d3a.1685464332.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>

+29 -16
+16 -15
tools/objtool/elf.c
··· 562 562 elf_hash_add(reloc, &reloc->hash, reloc_hash(reloc)); 563 563 564 564 sec->rsec->sh.sh_size += sec->rsec->sh.sh_entsize; 565 - sec->rsec->changed = true; 565 + 566 + mark_sec_changed(elf, sec->rsec, true); 566 567 567 568 return 0; 568 569 } ··· 578 577 struct reloc *reloc; 579 578 580 579 list_for_each_entry(reloc, &sym->reloc_list, sym_reloc_entry) 581 - reloc->sec->changed = true; 580 + mark_sec_changed(elf, reloc->sec, true); 582 581 } 583 582 584 583 /* ··· 655 654 symtab_data->d_align = 1; 656 655 symtab_data->d_type = ELF_T_SYM; 657 656 658 - symtab->changed = true; 657 + mark_sec_changed(elf, symtab, true); 659 658 symtab->truncate = true; 660 659 661 660 if (t) { ··· 670 669 shndx_data->d_align = sizeof(Elf32_Word); 671 670 shndx_data->d_type = ELF_T_WORD; 672 671 673 - symtab_shndx->changed = true; 672 + mark_sec_changed(elf, symtab_shndx, true); 674 673 symtab_shndx->truncate = true; 675 674 } 676 675 ··· 774 773 } 775 774 776 775 symtab->sh.sh_size += symtab->sh.sh_entsize; 777 - symtab->changed = true; 776 + mark_sec_changed(elf, symtab, true); 778 777 779 778 if (symtab_shndx) { 780 779 symtab_shndx->sh.sh_size += sizeof(Elf32_Word); 781 - symtab_shndx->changed = true; 780 + mark_sec_changed(elf, symtab_shndx, true); 782 781 } 783 782 784 783 return sym; ··· 1041 1040 1042 1041 len = strtab->sh.sh_size; 1043 1042 strtab->sh.sh_size += data->d_size; 1044 - strtab->changed = true; 1043 + 1044 + mark_sec_changed(elf, strtab, true); 1045 1045 1046 1046 return len; 1047 1047 } ··· 1077 1075 } 1078 1076 1079 1077 sec->idx = elf_ndxscn(s); 1080 - sec->changed = true; 1081 1078 1082 1079 sec->data = elf_newdata(s); 1083 1080 if (!sec->data) { ··· 1123 1122 elf_hash_add(section, &sec->hash, sec->idx); 1124 1123 elf_hash_add(section_name, &sec->name_hash, str_hash(sec->name)); 1125 1124 1126 - elf->changed = true; 1125 + mark_sec_changed(elf, sec, true); 1127 1126 1128 1127 return sec; 1129 1128 } ··· 1209 1208 } 1210 1209 1211 1210 memcpy(data->d_buf + offset, insn, len); 1212 - elf_flagdata(data, ELF_C_SET, ELF_F_DIRTY); 1213 1211 1214 - elf->changed = true; 1212 + mark_sec_changed(elf, sec, true); 1215 1213 1216 1214 return 0; 1217 1215 } ··· 1235 1235 return -1; 1236 1236 } 1237 1237 1238 - elf->changed = true; 1238 + mark_sec_changed(elf, rsec, true); 1239 1239 1240 1240 return 0; 1241 1241 } ··· 1307 1307 if (sec->truncate) 1308 1308 elf_truncate_section(elf, sec); 1309 1309 1310 - if (sec->changed) { 1310 + if (sec_changed(sec)) { 1311 1311 s = elf_getscn(elf->elf, sec->idx); 1312 1312 if (!s) { 1313 1313 WARN_ELF("elf_getscn"); 1314 1314 return -1; 1315 1315 } 1316 + 1317 + /* Note this also flags the section dirty */ 1316 1318 if (!gelf_update_shdr(s, &sec->sh)) { 1317 1319 WARN_ELF("gelf_update_shdr"); 1318 1320 return -1; ··· 1326 1324 return -1; 1327 1325 } 1328 1326 1329 - sec->changed = false; 1330 - elf->changed = true; 1327 + mark_sec_changed(elf, sec, false); 1331 1328 } 1332 1329 } 1333 1330
+13 -1
tools/objtool/include/objtool/elf.h
··· 39 39 Elf_Data *data; 40 40 char *name; 41 41 int idx; 42 - bool changed, text, rodata, noinstr, init, truncate; 42 + bool _changed, text, rodata, noinstr, init, truncate; 43 43 struct reloc *reloc_data; 44 44 }; 45 45 ··· 162 162 static inline bool is_reloc_sec(struct section *sec) 163 163 { 164 164 return sec->sh.sh_type == SHT_RELA || sec->sh.sh_type == SHT_REL; 165 + } 166 + 167 + static inline bool sec_changed(struct section *sec) 168 + { 169 + return sec->_changed; 170 + } 171 + 172 + static inline void mark_sec_changed(struct elf *elf, struct section *sec, 173 + bool changed) 174 + { 175 + sec->_changed = changed; 176 + elf->changed |= changed; 165 177 } 166 178 167 179 #define for_each_sec(file, sec) \