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

objtool: Rename some variables and functions

Rename some list heads to distinguish them from hash node heads, which
are added later in the patch series.

Also rename the get_*() functions to add_*(), which is more descriptive:
they "add" data to the objtool_file struct.

Also rename rodata_rela and text_rela to be clearer:
- text_rela refers to a rela entry in .rela.text.
- rodata_rela refers to a rela entry in .rela.rodata.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Bernd Petrovitsch <bernd@petrovitsch.priv.at>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Chris J Arges <chris.j.arges@canonical.com>
Cc: Jiri Slaby <jslaby@suse.cz>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Michal Marek <mmarek@suse.cz>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Pedro Alves <palves@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: live-patching@vger.kernel.org
Link: http://lkml.kernel.org/r/ee0eca2bba8482aa45758958c5586c00a7b71e62.1457502970.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Josh Poimboeuf and committed by
Ingo Molnar
a196e171 e2a5f18a

+54 -52
+41 -39
tools/objtool/builtin-check.c
··· 60 60 61 61 struct objtool_file { 62 62 struct elf *elf; 63 - struct list_head insns; 63 + struct list_head insn_list; 64 64 }; 65 65 66 66 const char *objname; ··· 71 71 { 72 72 struct instruction *insn; 73 73 74 - list_for_each_entry(insn, &file->insns, list) 74 + list_for_each_entry(insn, &file->insn_list, list) 75 75 if (insn->sec == sec && insn->offset == offset) 76 76 return insn; 77 77 ··· 83 83 { 84 84 struct instruction *next = list_next_entry(insn, list); 85 85 86 - if (&next->list == &file->insns || next->sec != insn->sec) 86 + if (&next->list == &file->insn_list || next->sec != insn->sec) 87 87 return NULL; 88 88 89 89 return next; 90 90 } 91 91 92 92 #define for_each_insn(file, insn) \ 93 - list_for_each_entry(insn, &file->insns, list) 93 + list_for_each_entry(insn, &file->insn_list, list) 94 94 95 95 #define func_for_each_insn(file, func, insn) \ 96 96 for (insn = find_insn(file, func->sec, func->offset); \ 97 - insn && &insn->list != &file->insns && \ 97 + insn && &insn->list != &file->insn_list && \ 98 98 insn->sec == func->sec && \ 99 99 insn->offset < func->offset + func->len; \ 100 100 insn = list_next_entry(insn, list)) ··· 117 117 /* check for STACK_FRAME_NON_STANDARD */ 118 118 macro_sec = find_section_by_name(file->elf, "__func_stack_frame_non_standard"); 119 119 if (macro_sec && macro_sec->rela) 120 - list_for_each_entry(rela, &macro_sec->rela->relas, list) 120 + list_for_each_entry(rela, &macro_sec->rela->rela_list, list) 121 121 if (rela->sym->sec == func->sec && 122 122 rela->addend == func->offset) 123 123 return true; ··· 240 240 241 241 /* 242 242 * Call the arch-specific instruction decoder for all the instructions and add 243 - * them to the global insns list. 243 + * them to the global instruction list. 244 244 */ 245 245 static int decode_instructions(struct objtool_file *file) 246 246 { ··· 275 275 return -1; 276 276 } 277 277 278 - list_add_tail(&insn->list, &file->insns); 278 + list_add_tail(&insn->list, &file->insn_list); 279 279 } 280 280 } 281 281 ··· 285 285 /* 286 286 * Warnings shouldn't be reported for ignored functions. 287 287 */ 288 - static void get_ignores(struct objtool_file *file) 288 + static void add_ignores(struct objtool_file *file) 289 289 { 290 290 struct instruction *insn; 291 291 struct section *sec; 292 292 struct symbol *func; 293 293 294 294 list_for_each_entry(sec, &file->elf->sections, list) { 295 - list_for_each_entry(func, &sec->symbols, list) { 295 + list_for_each_entry(func, &sec->symbol_list, list) { 296 296 if (func->type != STT_FUNC) 297 297 continue; 298 298 ··· 308 308 /* 309 309 * Find the destination instructions for all jumps. 310 310 */ 311 - static int get_jump_destinations(struct objtool_file *file) 311 + static int add_jump_destinations(struct objtool_file *file) 312 312 { 313 313 struct instruction *insn; 314 314 struct rela *rela; ··· 365 365 /* 366 366 * Find the destination instructions for all calls. 367 367 */ 368 - static int get_call_destinations(struct objtool_file *file) 368 + static int add_call_destinations(struct objtool_file *file) 369 369 { 370 370 struct instruction *insn; 371 371 unsigned long dest_off; ··· 534 534 * instruction(s) has them added to its insn->alts list, which will be 535 535 * traversed in validate_branch(). 536 536 */ 537 - static int get_special_section_alts(struct objtool_file *file) 537 + static int add_special_section_alts(struct objtool_file *file) 538 538 { 539 539 struct list_head special_alts; 540 540 struct instruction *orig_insn, *new_insn; ··· 604 604 * section which contains a list of addresses within the function to jump to. 605 605 * This finds these jump tables and adds them to the insn->alts lists. 606 606 */ 607 - static int get_switch_alts(struct objtool_file *file) 607 + static int add_switch_table_alts(struct objtool_file *file) 608 608 { 609 609 struct instruction *insn, *alt_insn; 610 - struct rela *rodata_rela, *rela; 610 + struct rela *rodata_rela, *text_rela; 611 611 struct section *rodata; 612 612 struct symbol *func; 613 613 struct alternative *alt; ··· 616 616 if (insn->type != INSN_JUMP_DYNAMIC) 617 617 continue; 618 618 619 - rodata_rela = find_rela_by_dest_range(insn->sec, insn->offset, 620 - insn->len); 621 - if (!rodata_rela || strcmp(rodata_rela->sym->name, ".rodata")) 619 + text_rela = find_rela_by_dest_range(insn->sec, insn->offset, 620 + insn->len); 621 + if (!text_rela || strcmp(text_rela->sym->name, ".rodata")) 622 622 continue; 623 623 624 624 rodata = find_section_by_name(file->elf, ".rodata"); ··· 626 626 continue; 627 627 628 628 /* common case: jmpq *[addr](,%rax,8) */ 629 - rela = find_rela_by_dest(rodata, rodata_rela->addend); 629 + rodata_rela = find_rela_by_dest(rodata, text_rela->addend); 630 630 631 631 /* rare case: jmpq *[addr](%rip) */ 632 - if (!rela) 633 - rela = find_rela_by_dest(rodata, 634 - rodata_rela->addend + 4); 635 - if (!rela) 632 + if (!rodata_rela) 633 + rodata_rela = find_rela_by_dest(rodata, 634 + text_rela->addend + 4); 635 + if (!rodata_rela) 636 636 continue; 637 637 638 638 func = find_containing_func(insn->sec, insn->offset); ··· 642 642 return -1; 643 643 } 644 644 645 - list_for_each_entry_from(rela, &rodata->rela->relas, list) { 646 - if (rela->sym->sec != insn->sec || 647 - rela->addend <= func->offset || 648 - rela->addend >= func->offset + func->len) 645 + list_for_each_entry_from(rodata_rela, &rodata->rela->rela_list, 646 + list) { 647 + if (rodata_rela->sym->sec != insn->sec || 648 + rodata_rela->addend <= func->offset || 649 + rodata_rela->addend >= func->offset + func->len) 649 650 break; 650 651 651 - alt_insn = find_insn(file, insn->sec, rela->addend); 652 + alt_insn = find_insn(file, insn->sec, 653 + rodata_rela->addend); 652 654 if (!alt_insn) { 653 655 WARN("%s: can't find instruction at %s+0x%x", 654 656 rodata->rela->name, insn->sec->name, 655 - rela->addend); 657 + rodata_rela->addend); 656 658 return -1; 657 659 } 658 660 ··· 680 678 if (ret) 681 679 return ret; 682 680 683 - get_ignores(file); 681 + add_ignores(file); 684 682 685 - ret = get_jump_destinations(file); 683 + ret = add_jump_destinations(file); 686 684 if (ret) 687 685 return ret; 688 686 689 - ret = get_call_destinations(file); 687 + ret = add_call_destinations(file); 690 688 if (ret) 691 689 return ret; 692 690 693 - ret = get_special_section_alts(file); 691 + ret = add_special_section_alts(file); 694 692 if (ret) 695 693 return ret; 696 694 697 - ret = get_switch_alts(file); 695 + ret = add_switch_table_alts(file); 698 696 if (ret) 699 697 return ret; 700 698 ··· 903 901 sec = rela->sym->sec; 904 902 offset = rela->addend + insn->offset + insn->len - rela->offset; 905 903 906 - list_for_each_entry(sym, &sec->symbols, list) { 904 + list_for_each_entry(sym, &sec->symbol_list, list) { 907 905 if (sym->type != STT_OBJECT) 908 906 continue; 909 907 ··· 970 968 int ret, warnings = 0; 971 969 972 970 list_for_each_entry(sec, &file->elf->sections, list) { 973 - list_for_each_entry(func, &sec->symbols, list) { 971 + list_for_each_entry(func, &sec->symbol_list, list) { 974 972 if (func->type != STT_FUNC) 975 973 continue; 976 974 ··· 988 986 } 989 987 990 988 list_for_each_entry(sec, &file->elf->sections, list) { 991 - list_for_each_entry(func, &sec->symbols, list) { 989 + list_for_each_entry(func, &sec->symbol_list, list) { 992 990 if (func->type != STT_FUNC) 993 991 continue; 994 992 ··· 1030 1028 struct instruction *insn, *tmpinsn; 1031 1029 struct alternative *alt, *tmpalt; 1032 1030 1033 - list_for_each_entry_safe(insn, tmpinsn, &file->insns, list) { 1031 + list_for_each_entry_safe(insn, tmpinsn, &file->insn_list, list) { 1034 1032 list_for_each_entry_safe(alt, tmpalt, &insn->alts, list) { 1035 1033 list_del(&alt->list); 1036 1034 free(alt); ··· 1069 1067 return 1; 1070 1068 } 1071 1069 1072 - INIT_LIST_HEAD(&file.insns); 1070 + INIT_LIST_HEAD(&file.insn_list); 1073 1071 1074 1072 ret = decode_sections(&file); 1075 1073 if (ret < 0)
+11 -11
tools/objtool/elf.c
··· 59 59 struct symbol *sym; 60 60 61 61 list_for_each_entry(sec, &elf->sections, list) 62 - list_for_each_entry(sym, &sec->symbols, list) 62 + list_for_each_entry(sym, &sec->symbol_list, list) 63 63 if (sym->idx == idx) 64 64 return sym; 65 65 ··· 70 70 { 71 71 struct symbol *sym; 72 72 73 - list_for_each_entry(sym, &sec->symbols, list) 73 + list_for_each_entry(sym, &sec->symbol_list, list) 74 74 if (sym->type != STT_SECTION && 75 75 sym->offset == offset) 76 76 return sym; ··· 86 86 if (!sec->rela) 87 87 return NULL; 88 88 89 - list_for_each_entry(rela, &sec->rela->relas, list) 89 + list_for_each_entry(rela, &sec->rela->rela_list, list) 90 90 if (rela->offset >= offset && rela->offset < offset + len) 91 91 return rela; 92 92 ··· 102 102 { 103 103 struct symbol *func; 104 104 105 - list_for_each_entry(func, &sec->symbols, list) 105 + list_for_each_entry(func, &sec->symbol_list, list) 106 106 if (func->type == STT_FUNC && offset >= func->offset && 107 107 offset < func->offset + func->len) 108 108 return func; ··· 135 135 } 136 136 memset(sec, 0, sizeof(*sec)); 137 137 138 - INIT_LIST_HEAD(&sec->symbols); 139 - INIT_LIST_HEAD(&sec->relas); 138 + INIT_LIST_HEAD(&sec->symbol_list); 139 + INIT_LIST_HEAD(&sec->rela_list); 140 140 141 141 list_add_tail(&sec->list, &elf->sections); 142 142 ··· 244 244 sym->len = sym->sym.st_size; 245 245 246 246 /* sorted insert into a per-section list */ 247 - entry = &sym->sec->symbols; 248 - list_for_each_prev(tmp, &sym->sec->symbols) { 247 + entry = &sym->sec->symbol_list; 248 + list_for_each_prev(tmp, &sym->sec->symbol_list) { 249 249 struct symbol *s; 250 250 251 251 s = list_entry(tmp, struct symbol, list); ··· 298 298 } 299 299 memset(rela, 0, sizeof(*rela)); 300 300 301 - list_add_tail(&rela->list, &sec->relas); 301 + list_add_tail(&rela->list, &sec->rela_list); 302 302 303 303 if (!gelf_getrela(sec->elf_data, i, &rela->rela)) { 304 304 perror("gelf_getrela"); ··· 382 382 struct rela *rela, *tmprela; 383 383 384 384 list_for_each_entry_safe(sec, tmpsec, &elf->sections, list) { 385 - list_for_each_entry_safe(sym, tmpsym, &sec->symbols, list) { 385 + list_for_each_entry_safe(sym, tmpsym, &sec->symbol_list, list) { 386 386 list_del(&sym->list); 387 387 free(sym); 388 388 } 389 - list_for_each_entry_safe(rela, tmprela, &sec->relas, list) { 389 + list_for_each_entry_safe(rela, tmprela, &sec->rela_list, list) { 390 390 list_del(&rela->list); 391 391 free(rela); 392 392 }
+2 -2
tools/objtool/elf.h
··· 25 25 struct section { 26 26 struct list_head list; 27 27 GElf_Shdr sh; 28 - struct list_head symbols; 29 - struct list_head relas; 28 + struct list_head symbol_list; 29 + struct list_head rela_list; 30 30 struct section *base, *rela; 31 31 struct symbol *sym; 32 32 Elf_Data *elf_data;