History

objtool: Convert elf iterator macros to use 'struct elf'

'struct objtool_file' is specific to the check code and doesn't belong in the elf code which is supposed to be objtool_file-agnostic. Convert the elf iterator macros to use 'struct elf' instead.

Josh Poimboeuf committed 1 year ago

Commit 96eceff1 parent 72e4b6b3 files · +17 −17Browse files

Unified · Split

3 files
  1. tools/objtool/check.c +12 −12
  2. tools/objtool/include/objtool/elf.h +4 −4
  3. tools/objtool/orc_gen.c +1 −1
tools/objtool/check.c+12−12
@@ -106,7 +106,7 @@ static struct instruction *prev_insn_same_sym(struct objtool_file *file, · 105 unmodified lines
106#define for_each_insn(file, insn) \106#define for_each_insn(file, insn) \
107 for (struct section *__sec, *__fake = (struct section *)1; \107 for (struct section *__sec, *__fake = (struct section *)1; \
108 __fake; __fake = NULL) \108 __fake; __fake = NULL) \
109 for_each_sec(file, __sec) \109 for_each_sec(file->elf, __sec) \
110 sec_for_each_insn(file, __sec, insn)110 sec_for_each_insn(file, __sec, insn)
111 111
112#define func_for_each_insn(file, func, insn) \112#define func_for_each_insn(file, func, insn) \
@@ -431,7 +431,7 @@ static int decode_instructions(struct objtool_file *file) · 318 unmodified lines
431 unsigned long offset;431 unsigned long offset;
432 struct instruction *insn;432 struct instruction *insn;
433 433
434 for_each_sec(file, sec) {434 for_each_sec(file->elf, sec) {
435 struct instruction *insns = NULL;435 struct instruction *insns = NULL;
436 u8 prev_len = 0;436 u8 prev_len = 0;
437 u8 idx = 0;437 u8 idx = 0;
@@ -857,7 +857,7 @@ static int create_cfi_sections(struct objtool_file *file) · 419 unmodified lines
857 }857 }
858 858
859 idx = 0;859 idx = 0;
860 for_each_sym(file, sym) {860 for_each_sym(file->elf, sym) {
861 if (sym->type != STT_FUNC)861 if (sym->type != STT_FUNC)
862 continue;862 continue;
863 863
@@ -873,7 +873,7 @@ static int create_cfi_sections(struct objtool_file *file) · 9 unmodified lines
873 return -1;873 return -1;
874 874
875 idx = 0;875 idx = 0;
876 for_each_sym(file, sym) {876 for_each_sym(file->elf, sym) {
877 if (sym->type != STT_FUNC)877 if (sym->type != STT_FUNC)
878 continue;878 continue;
879 879
@@ -2145,7 +2145,7 @@ static int add_jump_table_alts(struct objtool_file *file) · 1265 unmodified lines
2145 if (!file->rodata)2145 if (!file->rodata)
2146 return 0;2146 return 0;
2147 2147
2148 for_each_sym(file, func) {2148 for_each_sym(file->elf, func) {
2149 if (func->type != STT_FUNC)2149 if (func->type != STT_FUNC)
2150 continue;2150 continue;
2151 2151
@@ -2451,7 +2451,7 @@ static int classify_symbols(struct objtool_file *file) · 299 unmodified lines
2451{2451{
2452 struct symbol *func;2452 struct symbol *func;
2453 2453
2454 for_each_sym(file, func) {2454 for_each_sym(file->elf, func) {
2455 if (func->type == STT_NOTYPE && strstarts(func->name, ".L"))2455 if (func->type == STT_NOTYPE && strstarts(func->name, ".L"))
2456 func->local_label = true;2456 func->local_label = true;
2457 2457
@@ -2496,7 +2496,7 @@ static void mark_rodata(struct objtool_file *file) · 38 unmodified lines
2496 *2496 *
2497 * .rodata.str1.* sections are ignored; they don't contain jump tables.2497 * .rodata.str1.* sections are ignored; they don't contain jump tables.
2498 */2498 */
2499 for_each_sec(file, sec) {2499 for_each_sec(file->elf, sec) {
2500 if ((!strncmp(sec->name, ".rodata", 7) &&2500 if ((!strncmp(sec->name, ".rodata", 7) &&
2501 !strstr(sec->name, ".str1.")) ||2501 !strstr(sec->name, ".str1.")) ||
2502 !strncmp(sec->name, ".data.rel.ro", 12)) {2502 !strncmp(sec->name, ".data.rel.ro", 12)) {
@@ -4178,7 +4178,7 @@ static int add_prefix_symbols(struct objtool_file *file) · 1675 unmodified lines
4178 struct section *sec;4178 struct section *sec;
4179 struct symbol *func;4179 struct symbol *func;
4180 4180
4181 for_each_sec(file, sec) {4181 for_each_sec(file->elf, sec) {
4182 if (!(sec->sh.sh_flags & SHF_EXECINSTR))4182 if (!(sec->sh.sh_flags & SHF_EXECINSTR))
4183 continue;4183 continue;
4184 4184
@@ -4270,7 +4270,7 @@ static int validate_functions(struct objtool_file *file) · 85 unmodified lines
4270 struct section *sec;4270 struct section *sec;
4271 int warnings = 0;4271 int warnings = 0;
4272 4272
4273 for_each_sec(file, sec) {4273 for_each_sec(file->elf, sec) {
4274 if (!(sec->sh.sh_flags & SHF_EXECINSTR))4274 if (!(sec->sh.sh_flags & SHF_EXECINSTR))
4275 continue;4275 continue;
4276 4276
@@ -4449,7 +4449,7 @@ static int validate_ibt(struct objtool_file *file) · 172 unmodified lines
4449 for_each_insn(file, insn)4449 for_each_insn(file, insn)
4450 warnings += validate_ibt_insn(file, insn);4450 warnings += validate_ibt_insn(file, insn);
4451 4451
4452 for_each_sec(file, sec) {4452 for_each_sec(file->elf, sec) {
4453 4453
4454 /* Already done by validate_ibt_insn() */4454 /* Already done by validate_ibt_insn() */
4455 if (sec->sh.sh_flags & SHF_EXECINSTR)4455 if (sec->sh.sh_flags & SHF_EXECINSTR)
@@ -4610,7 +4610,7 @@ static void disas_warned_funcs(struct objtool_file *file) · 154 unmodified lines
4610 struct symbol *sym;4610 struct symbol *sym;
4611 char *funcs = NULL, *tmp;4611 char *funcs = NULL, *tmp;
4612 4612
4613 for_each_sym(file, sym) {4613 for_each_sym(file->elf, sym) {
4614 if (sym->warned) {4614 if (sym->warned) {
4615 if (!funcs) {4615 if (!funcs) {
4616 funcs = malloc(strlen(sym->name) + 1);4616 funcs = malloc(strlen(sym->name) + 1);
@@ -4650,7 +4650,7 @@ static int check_abs_references(struct objtool_file *file) · 33 unmodified lines
4650 struct reloc *reloc;4650 struct reloc *reloc;
4651 int ret = 0;4651 int ret = 0;
4652 4652
4653 for_each_sec(file, sec) {4653 for_each_sec(file->elf, sec) {
4654 /* absolute references in non-loadable sections are fine */4654 /* absolute references in non-loadable sections are fine */
4655 if (!(sec->sh.sh_flags & SHF_ALLOC))4655 if (!(sec->sh.sh_flags & SHF_ALLOC))
4656 continue;4656 continue;
tools/objtool/include/objtool/elf.h+4−4
@@ -325,16 +325,16 @@ static inline void set_sym_next_reloc(struct reloc *reloc, struct reloc *next) · 324 unmodified lines
325 reloc->_sym_next_reloc = (unsigned long)next | bit;325 reloc->_sym_next_reloc = (unsigned long)next | bit;
326}326}
327 327
328#define for_each_sec(file, sec) \328#define for_each_sec(elf, sec) \
329 list_for_each_entry(sec, &file->elf->sections, list)329 list_for_each_entry(sec, &elf->sections, list)
330 330
331#define sec_for_each_sym(sec, sym) \331#define sec_for_each_sym(sec, sym) \
332 list_for_each_entry(sym, &sec->symbol_list, list)332 list_for_each_entry(sym, &sec->symbol_list, list)
333 333
334#define for_each_sym(file, sym) \334#define for_each_sym(elf, sym) \
335 for (struct section *__sec, *__fake = (struct section *)1; \335 for (struct section *__sec, *__fake = (struct section *)1; \
336 __fake; __fake = NULL) \336 __fake; __fake = NULL) \
337 for_each_sec(file, __sec) \337 for_each_sec(elf, __sec) \
338 sec_for_each_sym(__sec, sym)338 sec_for_each_sym(__sec, sym)
339 339
340#define for_each_reloc(rsec, reloc) \340#define for_each_reloc(rsec, reloc) \
tools/objtool/orc_gen.c+1−1
@@ -57,7 +57,7 @@ int orc_create(struct objtool_file *file) · 56 unmodified lines
57 57
58 /* Build a deduplicated list of ORC entries: */58 /* Build a deduplicated list of ORC entries: */
59 INIT_LIST_HEAD(&orc_list);59 INIT_LIST_HEAD(&orc_list);
60 for_each_sec(file, sec) {60 for_each_sec(file->elf, sec) {
61 struct orc_entry orc, prev_orc = {0};61 struct orc_entry orc, prev_orc = {0};
62 struct instruction *insn;62 struct instruction *insn;
63 bool empty = true;63 bool empty = true;