History

objtool: Use section/symbol type helpers

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.

Wentong Tian committed 9 months ago

Commit c19c8541 parent 11439c44 files · +12 −12Browse files

Showing the changes to tools/objtool (4 of 4 files). Show all

Unified · Split

4 files
  1. tools/objtool/check.c +2 −2
  2. tools/objtool/disas.c +3 −3
  3. tools/objtool/elf.c +3 −3
  4. tools/objtool/klp-diff.c +4 −4
tools/objtool/check.c+2−2
@@ -4293,8 +4293,8 @@ static int validate_retpoline(struct objtool_file *file) · 4292 unmodified lines
42934293 list_for_each_entry(insn, &file->retpoline_call_list, call_node) {
42944294 struct symbol *sym = insn->sym;
42954295
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) {
42984298 struct instruction *prev =
42994299 prev_insn_same_sym(file, insn);
43004300
tools/objtool/disas.c+3−3
@@ -264,7 +264,7 @@ static void disas_print_addr_reloc(bfd_vma addr, struct disassemble_info *dinfo) · 263 unmodified lines
264264 * If the relocation symbol is a section name (for example ".bss")
265265 * then we try to further resolve the name.
266266 */
267− if (reloc->sym->type == STT_SECTION) {
267+ if (is_sec_sym(reloc->sym)) {
268268 str = offstr(reloc->sym->sec, reloc->sym->offset + offset);
269269 DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, str);
270270 free(str);
@@ -580,7 +580,7 @@ static size_t disas_insn_common(struct disas_context *dctx, · 309 unmodified lines
580580 */
581581 dinfo->buffer = insn->sec->data->d_buf;
582582 dinfo->buffer_vma = 0;
583− dinfo->buffer_length = insn->sec->sh.sh_size;
583+ dinfo->buffer_length = sec_size(insn->sec);
584584
585585 return disasm(insn->offset, &dctx->info);
586586 }
@@ -1231,7 +1231,7 @@ void disas_funcs(struct disas_context *dctx) · 644 unmodified lines
12311231
12321232 for_each_sec(dctx->file->elf, sec) {
12331233
1234− if (!(sec->sh.sh_flags & SHF_EXECINSTR))
1234+ if (!is_text_sec(sec))
12351235 continue;
12361236
12371237 sec_for_each_sym(sec, sym) {
tools/objtool/elf.c+3−3
@@ -614,7 +614,7 @@ static int read_symbols(struct elf *elf) · 613 unmodified lines
614614 if (elf_add_symbol(elf, sym))
615615 return -1;
616616
617− if (sym->type == STT_FILE)
617+ if (is_file_sym(sym))
618618 file = sym;
619619 else if (sym->bind == STB_LOCAL)
620620 sym->file = file;
@@ -1335,7 +1335,7 @@ unsigned int elf_add_string(struct elf *elf, struct section *strtab, const char · 714 unmodified lines
13351335 return -1;
13361336 }
13371337
1338− offset = ALIGN(strtab->sh.sh_size, strtab->sh.sh_addralign);
1338+ offset = ALIGN(sec_size(strtab), strtab->sh.sh_addralign);
13391339
13401340 if (!elf_add_data(elf, strtab, str, strlen(str) + 1))
13411341 return -1;
@@ -1377,7 +1377,7 @@ void *elf_add_data(struct elf *elf, struct section *sec, const void *data, size_ · 35 unmodified lines
13771377 sec->data->d_size = size;
13781378 sec->data->d_align = 1;
13791379
1380− offset = ALIGN(sec->sh.sh_size, sec->sh.sh_addralign);
1380+ offset = ALIGN(sec_size(sec), sec->sh.sh_addralign);
13811381 sec->sh.sh_size = offset + size;
13821382
13831383 mark_sec_changed(elf, sec, true);
tools/objtool/klp-diff.c+4−4
@@ -271,7 +271,7 @@ static bool is_uncorrelated_static_local(struct symbol *sym) · 270 unmodified lines
271271 */
272272 static bool is_clang_tmp_label(struct symbol *sym)
273273 {
274− return sym->type == STT_NOTYPE &&
274+ return is_notype_sym(sym) &&
275275 is_text_sec(sym->sec) &&
276276 strstarts(sym->name, ".Ltmp") &&
277277 isdigit(sym->name[5]);
@@ -480,7 +480,7 @@ static unsigned long find_sympos(struct elf *elf, struct symbol *sym) · 202 unmodified lines
480480 if (sym->bind != STB_LOCAL)
481481 return 0;
482482
483− if (vmlinux && sym->type == STT_FUNC) {
483+ if (vmlinux && is_func_sym(sym)) {
484484 /*
485485 * HACK: Unfortunately, symbol ordering can differ between
486486 * 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
10461046 sec->name, offset, patched_sym->name, \
10471047 addend >= 0 ? "+" : "-", labs(addend), \
10481048 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), \
10511051 is_undef_sym(patched_sym) ? " UNDEF" : "", \
10521052 export ? " EXPORTED" : "", \
10531053 klp ? " KLP" : "")

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t