summaryrefslogtreecommitdiffstats
path: root/tools/objtool
diff options
context:
space:
mode:
authorJosh Poimboeuf <jpoimboe@redhat.com>2016-03-09 01:06:57 -0500
committerIngo Molnar <mingo@kernel.org>2016-03-09 04:48:09 -0500
commita196e17198224cacd2d992f12cb6d81d354de82f (patch)
treeca10c5454682ffc63764c667c6c32fc6a4877dfc /tools/objtool
parente2a5f18a1ba11e8b1e9ee53b6fca4be12bb5749e (diff)
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>
Diffstat (limited to 'tools/objtool')
-rw-r--r--tools/objtool/builtin-check.c80
-rw-r--r--tools/objtool/elf.c22
-rw-r--r--tools/objtool/elf.h4
3 files changed, 54 insertions, 52 deletions
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index a974f295dc42..cdbdd7d9333a 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -60,7 +60,7 @@ struct alternative {
60 60
61struct objtool_file { 61struct objtool_file {
62 struct elf *elf; 62 struct elf *elf;
63 struct list_head insns; 63 struct list_head insn_list;
64}; 64};
65 65
66const char *objname; 66const char *objname;
@@ -71,7 +71,7 @@ static struct instruction *find_insn(struct objtool_file *file,
71{ 71{
72 struct instruction *insn; 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 if (insn->sec == sec && insn->offset == offset) 75 if (insn->sec == sec && insn->offset == offset)
76 return insn; 76 return insn;
77 77
@@ -83,18 +83,18 @@ static struct instruction *next_insn_same_sec(struct objtool_file *file,
83{ 83{
84 struct instruction *next = list_next_entry(insn, list); 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 return NULL; 87 return NULL;
88 88
89 return next; 89 return next;
90} 90}
91 91
92#define for_each_insn(file, insn) \ 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#define func_for_each_insn(file, func, insn) \ 95#define func_for_each_insn(file, func, insn) \
96 for (insn = find_insn(file, func->sec, func->offset); \ 96 for (insn = find_insn(file, func->sec, func->offset); \
97 insn && &insn->list != &file->insns && \ 97 insn && &insn->list != &file->insn_list && \
98 insn->sec == func->sec && \ 98 insn->sec == func->sec && \
99 insn->offset < func->offset + func->len; \ 99 insn->offset < func->offset + func->len; \
100 insn = list_next_entry(insn, list)) 100 insn = list_next_entry(insn, list))
@@ -117,7 +117,7 @@ static bool ignore_func(struct objtool_file *file, struct symbol *func)
117 /* check for STACK_FRAME_NON_STANDARD */ 117 /* check for STACK_FRAME_NON_STANDARD */
118 macro_sec = find_section_by_name(file->elf, "__func_stack_frame_non_standard"); 118 macro_sec = find_section_by_name(file->elf, "__func_stack_frame_non_standard");
119 if (macro_sec && macro_sec->rela) 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 if (rela->sym->sec == func->sec && 121 if (rela->sym->sec == func->sec &&
122 rela->addend == func->offset) 122 rela->addend == func->offset)
123 return true; 123 return true;
@@ -240,7 +240,7 @@ static int dead_end_function(struct objtool_file *file, struct symbol *func)
240 240
241/* 241/*
242 * Call the arch-specific instruction decoder for all the instructions and add 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 */
245static int decode_instructions(struct objtool_file *file) 245static int decode_instructions(struct objtool_file *file)
246{ 246{
@@ -275,7 +275,7 @@ static int decode_instructions(struct objtool_file *file)
275 return -1; 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,14 +285,14 @@ static int decode_instructions(struct objtool_file *file)
285/* 285/*
286 * Warnings shouldn't be reported for ignored functions. 286 * Warnings shouldn't be reported for ignored functions.
287 */ 287 */
288static void get_ignores(struct objtool_file *file) 288static void add_ignores(struct objtool_file *file)
289{ 289{
290 struct instruction *insn; 290 struct instruction *insn;
291 struct section *sec; 291 struct section *sec;
292 struct symbol *func; 292 struct symbol *func;
293 293
294 list_for_each_entry(sec, &file->elf->sections, list) { 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 if (func->type != STT_FUNC) 296 if (func->type != STT_FUNC)
297 continue; 297 continue;
298 298
@@ -308,7 +308,7 @@ static void get_ignores(struct objtool_file *file)
308/* 308/*
309 * Find the destination instructions for all jumps. 309 * Find the destination instructions for all jumps.
310 */ 310 */
311static int get_jump_destinations(struct objtool_file *file) 311static int add_jump_destinations(struct objtool_file *file)
312{ 312{
313 struct instruction *insn; 313 struct instruction *insn;
314 struct rela *rela; 314 struct rela *rela;
@@ -365,7 +365,7 @@ static int get_jump_destinations(struct objtool_file *file)
365/* 365/*
366 * Find the destination instructions for all calls. 366 * Find the destination instructions for all calls.
367 */ 367 */
368static int get_call_destinations(struct objtool_file *file) 368static int add_call_destinations(struct objtool_file *file)
369{ 369{
370 struct instruction *insn; 370 struct instruction *insn;
371 unsigned long dest_off; 371 unsigned long dest_off;
@@ -534,7 +534,7 @@ static int handle_jump_alt(struct objtool_file *file,
534 * instruction(s) has them added to its insn->alts list, which will be 534 * instruction(s) has them added to its insn->alts list, which will be
535 * traversed in validate_branch(). 535 * traversed in validate_branch().
536 */ 536 */
537static int get_special_section_alts(struct objtool_file *file) 537static int add_special_section_alts(struct objtool_file *file)
538{ 538{
539 struct list_head special_alts; 539 struct list_head special_alts;
540 struct instruction *orig_insn, *new_insn; 540 struct instruction *orig_insn, *new_insn;
@@ -604,10 +604,10 @@ out:
604 * section which contains a list of addresses within the function to jump to. 604 * section which contains a list of addresses within the function to jump to.
605 * This finds these jump tables and adds them to the insn->alts lists. 605 * This finds these jump tables and adds them to the insn->alts lists.
606 */ 606 */
607static int get_switch_alts(struct objtool_file *file) 607static int add_switch_table_alts(struct objtool_file *file)
608{ 608{
609 struct instruction *insn, *alt_insn; 609 struct instruction *insn, *alt_insn;
610 struct rela *rodata_rela, *rela; 610 struct rela *rodata_rela, *text_rela;
611 struct section *rodata; 611 struct section *rodata;
612 struct symbol *func; 612 struct symbol *func;
613 struct alternative *alt; 613 struct alternative *alt;
@@ -616,9 +616,9 @@ static int get_switch_alts(struct objtool_file *file)
616 if (insn->type != INSN_JUMP_DYNAMIC) 616 if (insn->type != INSN_JUMP_DYNAMIC)
617 continue; 617 continue;
618 618
619 rodata_rela = find_rela_by_dest_range(insn->sec, insn->offset, 619 text_rela = find_rela_by_dest_range(insn->sec, insn->offset,
620 insn->len); 620 insn->len);
621 if (!rodata_rela || strcmp(rodata_rela->sym->name, ".rodata")) 621 if (!text_rela || strcmp(text_rela->sym->name, ".rodata"))
622 continue; 622 continue;
623 623
624 rodata = find_section_by_name(file->elf, ".rodata"); 624 rodata = find_section_by_name(file->elf, ".rodata");
@@ -626,13 +626,13 @@ static int get_switch_alts(struct objtool_file *file)
626 continue; 626 continue;
627 627
628 /* common case: jmpq *[addr](,%rax,8) */ 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 /* rare case: jmpq *[addr](%rip) */ 631 /* rare case: jmpq *[addr](%rip) */
632 if (!rela) 632 if (!rodata_rela)
633 rela = find_rela_by_dest(rodata, 633 rodata_rela = find_rela_by_dest(rodata,
634 rodata_rela->addend + 4); 634 text_rela->addend + 4);
635 if (!rela) 635 if (!rodata_rela)
636 continue; 636 continue;
637 637
638 func = find_containing_func(insn->sec, insn->offset); 638 func = find_containing_func(insn->sec, insn->offset);
@@ -642,17 +642,19 @@ static int get_switch_alts(struct objtool_file *file)
642 return -1; 642 return -1;
643 } 643 }
644 644
645 list_for_each_entry_from(rela, &rodata->rela->relas, list) { 645 list_for_each_entry_from(rodata_rela, &rodata->rela->rela_list,
646 if (rela->sym->sec != insn->sec || 646 list) {
647 rela->addend <= func->offset || 647 if (rodata_rela->sym->sec != insn->sec ||
648 rela->addend >= func->offset + func->len) 648 rodata_rela->addend <= func->offset ||
649 rodata_rela->addend >= func->offset + func->len)
649 break; 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 if (!alt_insn) { 654 if (!alt_insn) {
653 WARN("%s: can't find instruction at %s+0x%x", 655 WARN("%s: can't find instruction at %s+0x%x",
654 rodata->rela->name, insn->sec->name, 656 rodata->rela->name, insn->sec->name,
655 rela->addend); 657 rodata_rela->addend);
656 return -1; 658 return -1;
657 } 659 }
658 660
@@ -678,21 +680,21 @@ static int decode_sections(struct objtool_file *file)
678 if (ret) 680 if (ret)
679 return ret; 681 return ret;
680 682
681 get_ignores(file); 683 add_ignores(file);
682 684
683 ret = get_jump_destinations(file); 685 ret = add_jump_destinations(file);
684 if (ret) 686 if (ret)
685 return ret; 687 return ret;
686 688
687 ret = get_call_destinations(file); 689 ret = add_call_destinations(file);
688 if (ret) 690 if (ret)
689 return ret; 691 return ret;
690 692
691 ret = get_special_section_alts(file); 693 ret = add_special_section_alts(file);
692 if (ret) 694 if (ret)
693 return ret; 695 return ret;
694 696
695 ret = get_switch_alts(file); 697 ret = add_switch_table_alts(file);
696 if (ret) 698 if (ret)
697 return ret; 699 return ret;
698 700
@@ -901,7 +903,7 @@ static bool is_gcov_insn(struct instruction *insn)
901 sec = rela->sym->sec; 903 sec = rela->sym->sec;
902 offset = rela->addend + insn->offset + insn->len - rela->offset; 904 offset = rela->addend + insn->offset + insn->len - rela->offset;
903 905
904 list_for_each_entry(sym, &sec->symbols, list) { 906 list_for_each_entry(sym, &sec->symbol_list, list) {
905 if (sym->type != STT_OBJECT) 907 if (sym->type != STT_OBJECT)
906 continue; 908 continue;
907 909
@@ -968,7 +970,7 @@ static int validate_functions(struct objtool_file *file)
968 int ret, warnings = 0; 970 int ret, warnings = 0;
969 971
970 list_for_each_entry(sec, &file->elf->sections, list) { 972 list_for_each_entry(sec, &file->elf->sections, list) {
971 list_for_each_entry(func, &sec->symbols, list) { 973 list_for_each_entry(func, &sec->symbol_list, list) {
972 if (func->type != STT_FUNC) 974 if (func->type != STT_FUNC)
973 continue; 975 continue;
974 976
@@ -986,7 +988,7 @@ static int validate_functions(struct objtool_file *file)
986 } 988 }
987 989
988 list_for_each_entry(sec, &file->elf->sections, list) { 990 list_for_each_entry(sec, &file->elf->sections, list) {
989 list_for_each_entry(func, &sec->symbols, list) { 991 list_for_each_entry(func, &sec->symbol_list, list) {
990 if (func->type != STT_FUNC) 992 if (func->type != STT_FUNC)
991 continue; 993 continue;
992 994
@@ -1028,7 +1030,7 @@ static void cleanup(struct objtool_file *file)
1028 struct instruction *insn, *tmpinsn; 1030 struct instruction *insn, *tmpinsn;
1029 struct alternative *alt, *tmpalt; 1031 struct alternative *alt, *tmpalt;
1030 1032
1031 list_for_each_entry_safe(insn, tmpinsn, &file->insns, list) { 1033 list_for_each_entry_safe(insn, tmpinsn, &file->insn_list, list) {
1032 list_for_each_entry_safe(alt, tmpalt, &insn->alts, list) { 1034 list_for_each_entry_safe(alt, tmpalt, &insn->alts, list) {
1033 list_del(&alt->list); 1035 list_del(&alt->list);
1034 free(alt); 1036 free(alt);
@@ -1067,7 +1069,7 @@ int cmd_check(int argc, const char **argv)
1067 return 1; 1069 return 1;
1068 } 1070 }
1069 1071
1070 INIT_LIST_HEAD(&file.insns); 1072 INIT_LIST_HEAD(&file.insn_list);
1071 1073
1072 ret = decode_sections(&file); 1074 ret = decode_sections(&file);
1073 if (ret < 0) 1075 if (ret < 0)
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index d547e3f6e0ee..7de243f0a7be 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -59,7 +59,7 @@ static struct symbol *find_symbol_by_index(struct elf *elf, unsigned int idx)
59 struct symbol *sym; 59 struct symbol *sym;
60 60
61 list_for_each_entry(sec, &elf->sections, list) 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 if (sym->idx == idx) 63 if (sym->idx == idx)
64 return sym; 64 return sym;
65 65
@@ -70,7 +70,7 @@ struct symbol *find_symbol_by_offset(struct section *sec, unsigned long offset)
70{ 70{
71 struct symbol *sym; 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 if (sym->type != STT_SECTION && 74 if (sym->type != STT_SECTION &&
75 sym->offset == offset) 75 sym->offset == offset)
76 return sym; 76 return sym;
@@ -86,7 +86,7 @@ struct rela *find_rela_by_dest_range(struct section *sec, unsigned long offset,
86 if (!sec->rela) 86 if (!sec->rela)
87 return NULL; 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 if (rela->offset >= offset && rela->offset < offset + len) 90 if (rela->offset >= offset && rela->offset < offset + len)
91 return rela; 91 return rela;
92 92
@@ -102,7 +102,7 @@ struct symbol *find_containing_func(struct section *sec, unsigned long offset)
102{ 102{
103 struct symbol *func; 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 if (func->type == STT_FUNC && offset >= func->offset && 106 if (func->type == STT_FUNC && offset >= func->offset &&
107 offset < func->offset + func->len) 107 offset < func->offset + func->len)
108 return func; 108 return func;
@@ -135,8 +135,8 @@ static int read_sections(struct elf *elf)
135 } 135 }
136 memset(sec, 0, sizeof(*sec)); 136 memset(sec, 0, sizeof(*sec));
137 137
138 INIT_LIST_HEAD(&sec->symbols); 138 INIT_LIST_HEAD(&sec->symbol_list);
139 INIT_LIST_HEAD(&sec->relas); 139 INIT_LIST_HEAD(&sec->rela_list);
140 140
141 list_add_tail(&sec->list, &elf->sections); 141 list_add_tail(&sec->list, &elf->sections);
142 142
@@ -244,8 +244,8 @@ static int read_symbols(struct elf *elf)
244 sym->len = sym->sym.st_size; 244 sym->len = sym->sym.st_size;
245 245
246 /* sorted insert into a per-section list */ 246 /* sorted insert into a per-section list */
247 entry = &sym->sec->symbols; 247 entry = &sym->sec->symbol_list;
248 list_for_each_prev(tmp, &sym->sec->symbols) { 248 list_for_each_prev(tmp, &sym->sec->symbol_list) {
249 struct symbol *s; 249 struct symbol *s;
250 250
251 s = list_entry(tmp, struct symbol, list); 251 s = list_entry(tmp, struct symbol, list);
@@ -298,7 +298,7 @@ static int read_relas(struct elf *elf)
298 } 298 }
299 memset(rela, 0, sizeof(*rela)); 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 if (!gelf_getrela(sec->elf_data, i, &rela->rela)) { 303 if (!gelf_getrela(sec->elf_data, i, &rela->rela)) {
304 perror("gelf_getrela"); 304 perror("gelf_getrela");
@@ -382,11 +382,11 @@ void elf_close(struct elf *elf)
382 struct rela *rela, *tmprela; 382 struct rela *rela, *tmprela;
383 383
384 list_for_each_entry_safe(sec, tmpsec, &elf->sections, list) { 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 list_del(&sym->list); 386 list_del(&sym->list);
387 free(sym); 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 list_del(&rela->list); 390 list_del(&rela->list);
391 free(rela); 391 free(rela);
392 } 392 }
diff --git a/tools/objtool/elf.h b/tools/objtool/elf.h
index 66919de57e68..57e4653f8383 100644
--- a/tools/objtool/elf.h
+++ b/tools/objtool/elf.h
@@ -25,8 +25,8 @@
25struct section { 25struct section {
26 struct list_head list; 26 struct list_head list;
27 GElf_Shdr sh; 27 GElf_Shdr sh;
28 struct list_head symbols; 28 struct list_head symbol_list;
29 struct list_head relas; 29 struct list_head rela_list;
30 struct section *base, *rela; 30 struct section *base, *rela;
31 struct symbol *sym; 31 struct symbol *sym;
32 Elf_Data *elf_data; 32 Elf_Data *elf_data;