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
106106 #define for_each_insn(file, insn) \
107107 for (struct section *__sec, *__fake = (struct section *)1; \
108108 __fake; __fake = NULL) \
109− for_each_sec(file, __sec) \
109+ for_each_sec(file->elf, __sec) \
110110 sec_for_each_insn(file, __sec, insn)
111111
112112 #define func_for_each_insn(file, func, insn) \
@@ -431,7 +431,7 @@ static int decode_instructions(struct objtool_file *file) · 318 unmodified lines
431431 unsigned long offset;
432432 struct instruction *insn;
433433
434− for_each_sec(file, sec) {
434+ for_each_sec(file->elf, sec) {
435435 struct instruction *insns = NULL;
436436 u8 prev_len = 0;
437437 u8 idx = 0;
@@ -857,7 +857,7 @@ static int create_cfi_sections(struct objtool_file *file) · 419 unmodified lines
857857 }
858858
859859 idx = 0;
860− for_each_sym(file, sym) {
860+ for_each_sym(file->elf, sym) {
861861 if (sym->type != STT_FUNC)
862862 continue;
863863
@@ -873,7 +873,7 @@ static int create_cfi_sections(struct objtool_file *file) · 9 unmodified lines
873873 return -1;
874874
875875 idx = 0;
876− for_each_sym(file, sym) {
876+ for_each_sym(file->elf, sym) {
877877 if (sym->type != STT_FUNC)
878878 continue;
879879
@@ -2145,7 +2145,7 @@ static int add_jump_table_alts(struct objtool_file *file) · 1265 unmodified lines
21452145 if (!file->rodata)
21462146 return 0;
21472147
2148− for_each_sym(file, func) {
2148+ for_each_sym(file->elf, func) {
21492149 if (func->type != STT_FUNC)
21502150 continue;
21512151
@@ -2451,7 +2451,7 @@ static int classify_symbols(struct objtool_file *file) · 299 unmodified lines
24512451 {
24522452 struct symbol *func;
24532453
2454− for_each_sym(file, func) {
2454+ for_each_sym(file->elf, func) {
24552455 if (func->type == STT_NOTYPE && strstarts(func->name, ".L"))
24562456 func->local_label = true;
24572457
@@ -2496,7 +2496,7 @@ static void mark_rodata(struct objtool_file *file) · 38 unmodified lines
24962496 *
24972497 * .rodata.str1.* sections are ignored; they don't contain jump tables.
24982498 */
2499− for_each_sec(file, sec) {
2499+ for_each_sec(file->elf, sec) {
25002500 if ((!strncmp(sec->name, ".rodata", 7) &&
25012501 !strstr(sec->name, ".str1.")) ||
25022502 !strncmp(sec->name, ".data.rel.ro", 12)) {
@@ -4178,7 +4178,7 @@ static int add_prefix_symbols(struct objtool_file *file) · 1675 unmodified lines
41784178 struct section *sec;
41794179 struct symbol *func;
41804180
4181− for_each_sec(file, sec) {
4181+ for_each_sec(file->elf, sec) {
41824182 if (!(sec->sh.sh_flags & SHF_EXECINSTR))
41834183 continue;
41844184
@@ -4270,7 +4270,7 @@ static int validate_functions(struct objtool_file *file) · 85 unmodified lines
42704270 struct section *sec;
42714271 int warnings = 0;
42724272
4273− for_each_sec(file, sec) {
4273+ for_each_sec(file->elf, sec) {
42744274 if (!(sec->sh.sh_flags & SHF_EXECINSTR))
42754275 continue;
42764276
@@ -4449,7 +4449,7 @@ static int validate_ibt(struct objtool_file *file) · 172 unmodified lines
44494449 for_each_insn(file, insn)
44504450 warnings += validate_ibt_insn(file, insn);
44514451
4452− for_each_sec(file, sec) {
4452+ for_each_sec(file->elf, sec) {
44534453
44544454 /* Already done by validate_ibt_insn() */
44554455 if (sec->sh.sh_flags & SHF_EXECINSTR)
@@ -4610,7 +4610,7 @@ static void disas_warned_funcs(struct objtool_file *file) · 154 unmodified lines
46104610 struct symbol *sym;
46114611 char *funcs = NULL, *tmp;
46124612
4613− for_each_sym(file, sym) {
4613+ for_each_sym(file->elf, sym) {
46144614 if (sym->warned) {
46154615 if (!funcs) {
46164616 funcs = malloc(strlen(sym->name) + 1);
@@ -4650,7 +4650,7 @@ static int check_abs_references(struct objtool_file *file) · 33 unmodified lines
46504650 struct reloc *reloc;
46514651 int ret = 0;
46524652
4653− for_each_sec(file, sec) {
4653+ for_each_sec(file->elf, sec) {
46544654 /* absolute references in non-loadable sections are fine */
46554655 if (!(sec->sh.sh_flags & SHF_ALLOC))
46564656 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
325325 reloc->_sym_next_reloc = (unsigned long)next | bit;
326326 }
327327
328−#define for_each_sec(file, sec) \
329− list_for_each_entry(sec, &file->elf->sections, list)
328+#define for_each_sec(elf, sec) \
329+ list_for_each_entry(sec, &elf->sections, list)
330330
331331 #define sec_for_each_sym(sec, sym) \
332332 list_for_each_entry(sym, &sec->symbol_list, list)
333333
334−#define for_each_sym(file, sym) \
334+#define for_each_sym(elf, sym) \
335335 for (struct section *__sec, *__fake = (struct section *)1; \
336336 __fake; __fake = NULL) \
337− for_each_sec(file, __sec) \
337+ for_each_sec(elf, __sec) \
338338 sec_for_each_sym(__sec, sym)
339339
340340 #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
5757
5858 /* Build a deduplicated list of ORC entries: */
5959 INIT_LIST_HEAD(&orc_list);
60− for_each_sec(file, sec) {
60+ for_each_sec(file->elf, sec) {
6161 struct orc_entry orc, prev_orc = {0};
6262 struct instruction *insn;
6363 bool empty = true;