Commit 25eac74b6bdb ("objtool: Add section/symbol type helpers") introduced several helper macros to improve code readability. Update the remaining open-coded checks in check.c, disas.c, elf.c, and klp-diff.c to use these new helpers.
Unified · Split
| @@ -4293,8 +4293,8 @@ static int validate_retpoline(struct objtool_file *file) · 4292 unmodified lines | ||
| 4293 | 4293 | list_for_each_entry(insn, &file->retpoline_call_list, call_node) { |
| 4294 | 4294 | struct symbol *sym = insn->sym; |
| 4295 | 4295 | |
| 4296 | − if (sym && (sym->type == STT_NOTYPE || | |
| 4297 | − sym->type == STT_FUNC) && !sym->nocfi) { | |
| 4296 | + if (sym && (is_notype_sym(sym) || | |
| 4297 | + is_func_sym(sym)) && !sym->nocfi) { | |
| 4298 | 4298 | struct instruction *prev = |
| 4299 | 4299 | prev_insn_same_sym(file, insn); |
| 4300 | 4300 | |
| @@ -264,7 +264,7 @@ static void disas_print_addr_reloc(bfd_vma addr, struct disassemble_info *dinfo) · 263 unmodified lines | ||
| 264 | 264 | * If the relocation symbol is a section name (for example ".bss") |
| 265 | 265 | * then we try to further resolve the name. |
| 266 | 266 | */ |
| 267 | − if (reloc->sym->type == STT_SECTION) { | |
| 267 | + if (is_sec_sym(reloc->sym)) { | |
| 268 | 268 | str = offstr(reloc->sym->sec, reloc->sym->offset + offset); |
| 269 | 269 | DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, str); |
| 270 | 270 | free(str); |
| @@ -580,7 +580,7 @@ static size_t disas_insn_common(struct disas_context *dctx, · 309 unmodified lines | ||
| 580 | 580 | */ |
| 581 | 581 | dinfo->buffer = insn->sec->data->d_buf; |
| 582 | 582 | dinfo->buffer_vma = 0; |
| 583 | − dinfo->buffer_length = insn->sec->sh.sh_size; | |
| 583 | + dinfo->buffer_length = sec_size(insn->sec); | |
| 584 | 584 | |
| 585 | 585 | return disasm(insn->offset, &dctx->info); |
| 586 | 586 | } |
| @@ -1231,7 +1231,7 @@ void disas_funcs(struct disas_context *dctx) · 644 unmodified lines | ||
| 1231 | 1231 | |
| 1232 | 1232 | for_each_sec(dctx->file->elf, sec) { |
| 1233 | 1233 | |
| 1234 | − if (!(sec->sh.sh_flags & SHF_EXECINSTR)) | |
| 1234 | + if (!is_text_sec(sec)) | |
| 1235 | 1235 | continue; |
| 1236 | 1236 | |
| 1237 | 1237 | sec_for_each_sym(sec, sym) { |
| @@ -614,7 +614,7 @@ static int read_symbols(struct elf *elf) · 613 unmodified lines | ||
| 614 | 614 | if (elf_add_symbol(elf, sym)) |
| 615 | 615 | return -1; |
| 616 | 616 | |
| 617 | − if (sym->type == STT_FILE) | |
| 617 | + if (is_file_sym(sym)) | |
| 618 | 618 | file = sym; |
| 619 | 619 | else if (sym->bind == STB_LOCAL) |
| 620 | 620 | sym->file = file; |
| @@ -1335,7 +1335,7 @@ unsigned int elf_add_string(struct elf *elf, struct section *strtab, const char · 714 unmodified lines | ||
| 1335 | 1335 | return -1; |
| 1336 | 1336 | } |
| 1337 | 1337 | |
| 1338 | − offset = ALIGN(strtab->sh.sh_size, strtab->sh.sh_addralign); | |
| 1338 | + offset = ALIGN(sec_size(strtab), strtab->sh.sh_addralign); | |
| 1339 | 1339 | |
| 1340 | 1340 | if (!elf_add_data(elf, strtab, str, strlen(str) + 1)) |
| 1341 | 1341 | return -1; |
| @@ -1377,7 +1377,7 @@ void *elf_add_data(struct elf *elf, struct section *sec, const void *data, size_ · 35 unmodified lines | ||
| 1377 | 1377 | sec->data->d_size = size; |
| 1378 | 1378 | sec->data->d_align = 1; |
| 1379 | 1379 | |
| 1380 | − offset = ALIGN(sec->sh.sh_size, sec->sh.sh_addralign); | |
| 1380 | + offset = ALIGN(sec_size(sec), sec->sh.sh_addralign); | |
| 1381 | 1381 | sec->sh.sh_size = offset + size; |
| 1382 | 1382 | |
| 1383 | 1383 | mark_sec_changed(elf, sec, true); |
| @@ -271,7 +271,7 @@ static bool is_uncorrelated_static_local(struct symbol *sym) · 270 unmodified lines | ||
| 271 | 271 | */ |
| 272 | 272 | static bool is_clang_tmp_label(struct symbol *sym) |
| 273 | 273 | { |
| 274 | − return sym->type == STT_NOTYPE && | |
| 274 | + return is_notype_sym(sym) && | |
| 275 | 275 | is_text_sec(sym->sec) && |
| 276 | 276 | strstarts(sym->name, ".Ltmp") && |
| 277 | 277 | isdigit(sym->name[5]); |
| @@ -480,7 +480,7 @@ static unsigned long find_sympos(struct elf *elf, struct symbol *sym) · 202 unmodified lines | ||
| 480 | 480 | if (sym->bind != STB_LOCAL) |
| 481 | 481 | return 0; |
| 482 | 482 | |
| 483 | − if (vmlinux && sym->type == STT_FUNC) { | |
| 483 | + if (vmlinux && is_func_sym(sym)) { | |
| 484 | 484 | /* |
| 485 | 485 | * HACK: Unfortunately, symbol ordering can differ between |
| 486 | 486 | * vmlinux.o and vmlinux due to the linker script emitting |
| @@ -1046,8 +1046,8 @@ static int clone_reloc_klp(struct elfs *e, struct reloc *patched_reloc, · 559 unmodified lines | ||
| 1046 | 1046 | sec->name, offset, patched_sym->name, \ |
| 1047 | 1047 | addend >= 0 ? "+" : "-", labs(addend), \ |
| 1048 | 1048 | sym_type(patched_sym), \ |
| 1049 | − patched_sym->type == STT_SECTION ? "" : " ", \ | |
| 1050 | − patched_sym->type == STT_SECTION ? "" : sym_bind(patched_sym), \ | |
| 1049 | + is_sec_sym(patched_sym) ? "" : " ", \ | |
| 1050 | + is_sec_sym(patched_sym) ? "" : sym_bind(patched_sym), \ | |
| 1051 | 1051 | is_undef_sym(patched_sym) ? " UNDEF" : "", \ |
| 1052 | 1052 | export ? " EXPORTED" : "", \ |
| 1053 | 1053 | klp ? " KLP" : "") |