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
4293 list_for_each_entry(insn, &file->retpoline_call_list, call_node) {4293 list_for_each_entry(insn, &file->retpoline_call_list, call_node) {
4294 struct symbol *sym = insn->sym;4294 struct symbol *sym = insn->sym;
4295 4295
4296 if (sym && (sym->type == STT_NOTYPE ||4296 if (sym && (is_notype_sym(sym) ||
4297 sym->type == STT_FUNC) && !sym->nocfi) {4297 is_func_sym(sym)) && !sym->nocfi) {
4298 struct instruction *prev =4298 struct instruction *prev =
4299 prev_insn_same_sym(file, insn);4299 prev_insn_same_sym(file, insn);
4300 4300
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
264 * If the relocation symbol is a section name (for example ".bss")264 * If the relocation symbol is a section name (for example ".bss")
265 * then we try to further resolve the name.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 str = offstr(reloc->sym->sec, reloc->sym->offset + offset);268 str = offstr(reloc->sym->sec, reloc->sym->offset + offset);
269 DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, str);269 DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, str);
270 free(str);270 free(str);
@@ -580,7 +580,7 @@ static size_t disas_insn_common(struct disas_context *dctx, · 309 unmodified lines
580 */580 */
581 dinfo->buffer = insn->sec->data->d_buf;581 dinfo->buffer = insn->sec->data->d_buf;
582 dinfo->buffer_vma = 0;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 return disasm(insn->offset, &dctx->info);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 for_each_sec(dctx->file->elf, sec) {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 continue;1235 continue;
1236 1236
1237 sec_for_each_sym(sec, sym) {1237 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
614 if (elf_add_symbol(elf, sym))614 if (elf_add_symbol(elf, sym))
615 return -1;615 return -1;
616 616
617 if (sym->type == STT_FILE)617 if (is_file_sym(sym))
618 file = sym;618 file = sym;
619 else if (sym->bind == STB_LOCAL)619 else if (sym->bind == STB_LOCAL)
620 sym->file = file;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 return -1;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 if (!elf_add_data(elf, strtab, str, strlen(str) + 1))1340 if (!elf_add_data(elf, strtab, str, strlen(str) + 1))
1341 return -1;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 sec->data->d_size = size;1377 sec->data->d_size = size;
1378 sec->data->d_align = 1;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 sec->sh.sh_size = offset + size;1381 sec->sh.sh_size = offset + size;
1382 1382
1383 mark_sec_changed(elf, sec, true);1383 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
271 */271 */
272static bool is_clang_tmp_label(struct symbol *sym)272static bool is_clang_tmp_label(struct symbol *sym)
273{273{
274 return sym->type == STT_NOTYPE &&274 return is_notype_sym(sym) &&
275 is_text_sec(sym->sec) &&275 is_text_sec(sym->sec) &&
276 strstarts(sym->name, ".Ltmp") &&276 strstarts(sym->name, ".Ltmp") &&
277 isdigit(sym->name[5]);277 isdigit(sym->name[5]);
@@ -480,7 +480,7 @@ static unsigned long find_sympos(struct elf *elf, struct symbol *sym) · 202 unmodified lines
480 if (sym->bind != STB_LOCAL)480 if (sym->bind != STB_LOCAL)
481 return 0;481 return 0;
482 482
483 if (vmlinux && sym->type == STT_FUNC) {483 if (vmlinux && is_func_sym(sym)) {
484 /*484 /*
485 * HACK: Unfortunately, symbol ordering can differ between485 * HACK: Unfortunately, symbol ordering can differ between
486 * vmlinux.o and vmlinux due to the linker script emitting486 * 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 sec->name, offset, patched_sym->name, \1046 sec->name, offset, patched_sym->name, \
1047 addend >= 0 ? "+" : "-", labs(addend), \1047 addend >= 0 ? "+" : "-", labs(addend), \
1048 sym_type(patched_sym), \1048 sym_type(patched_sym), \
1049 patched_sym->type == STT_SECTION ? "" : " ", \1049 is_sec_sym(patched_sym) ? "" : " ", \
1050 patched_sym->type == STT_SECTION ? "" : sym_bind(patched_sym), \1050 is_sec_sym(patched_sym) ? "" : sym_bind(patched_sym), \
1051 is_undef_sym(patched_sym) ? " UNDEF" : "", \1051 is_undef_sym(patched_sym) ? " UNDEF" : "", \
1052 export ? " EXPORTED" : "", \1052 export ? " EXPORTED" : "", \
1053 klp ? " KLP" : "")1053 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