Commit a196e171 authored by Josh Poimboeuf's avatar Josh Poimboeuf Committed by Ingo Molnar

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: default avatarJosh 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.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent e2a5f18a
...@@ -60,7 +60,7 @@ struct alternative { ...@@ -60,7 +60,7 @@ struct alternative {
struct objtool_file { struct objtool_file {
struct elf *elf; struct elf *elf;
struct list_head insns; struct list_head insn_list;
}; };
const char *objname; const char *objname;
...@@ -71,7 +71,7 @@ static struct instruction *find_insn(struct objtool_file *file, ...@@ -71,7 +71,7 @@ static struct instruction *find_insn(struct objtool_file *file,
{ {
struct instruction *insn; struct instruction *insn;
list_for_each_entry(insn, &file->insns, list) list_for_each_entry(insn, &file->insn_list, list)
if (insn->sec == sec && insn->offset == offset) if (insn->sec == sec && insn->offset == offset)
return insn; return insn;
...@@ -83,18 +83,18 @@ static struct instruction *next_insn_same_sec(struct objtool_file *file, ...@@ -83,18 +83,18 @@ static struct instruction *next_insn_same_sec(struct objtool_file *file,
{ {
struct instruction *next = list_next_entry(insn, list); struct instruction *next = list_next_entry(insn, list);
if (&next->list == &file->insns || next->sec != insn->sec) if (&next->list == &file->insn_list || next->sec != insn->sec)
return NULL; return NULL;
return next; return next;
} }
#define for_each_insn(file, insn) \ #define for_each_insn(file, insn) \
list_for_each_entry(insn, &file->insns, list) list_for_each_entry(insn, &file->insn_list, list)
#define func_for_each_insn(file, func, insn) \ #define func_for_each_insn(file, func, insn) \
for (insn = find_insn(file, func->sec, func->offset); \ for (insn = find_insn(file, func->sec, func->offset); \
insn && &insn->list != &file->insns && \ insn && &insn->list != &file->insn_list && \
insn->sec == func->sec && \ insn->sec == func->sec && \
insn->offset < func->offset + func->len; \ insn->offset < func->offset + func->len; \
insn = list_next_entry(insn, list)) insn = list_next_entry(insn, list))
...@@ -117,7 +117,7 @@ static bool ignore_func(struct objtool_file *file, struct symbol *func) ...@@ -117,7 +117,7 @@ static bool ignore_func(struct objtool_file *file, struct symbol *func)
/* check for STACK_FRAME_NON_STANDARD */ /* check for STACK_FRAME_NON_STANDARD */
macro_sec = find_section_by_name(file->elf, "__func_stack_frame_non_standard"); macro_sec = find_section_by_name(file->elf, "__func_stack_frame_non_standard");
if (macro_sec && macro_sec->rela) if (macro_sec && macro_sec->rela)
list_for_each_entry(rela, &macro_sec->rela->relas, list) list_for_each_entry(rela, &macro_sec->rela->rela_list, list)
if (rela->sym->sec == func->sec && if (rela->sym->sec == func->sec &&
rela->addend == func->offset) rela->addend == func->offset)
return true; return true;
...@@ -240,7 +240,7 @@ static int dead_end_function(struct objtool_file *file, struct symbol *func) ...@@ -240,7 +240,7 @@ static int dead_end_function(struct objtool_file *file, struct symbol *func)
/* /*
* Call the arch-specific instruction decoder for all the instructions and add * Call the arch-specific instruction decoder for all the instructions and add
* them to the global insns list. * them to the global instruction list.
*/ */
static int decode_instructions(struct objtool_file *file) static int decode_instructions(struct objtool_file *file)
{ {
...@@ -275,7 +275,7 @@ static int decode_instructions(struct objtool_file *file) ...@@ -275,7 +275,7 @@ static int decode_instructions(struct objtool_file *file)
return -1; return -1;
} }
list_add_tail(&insn->list, &file->insns); list_add_tail(&insn->list, &file->insn_list);
} }
} }
...@@ -285,14 +285,14 @@ static int decode_instructions(struct objtool_file *file) ...@@ -285,14 +285,14 @@ static int decode_instructions(struct objtool_file *file)
/* /*
* Warnings shouldn't be reported for ignored functions. * Warnings shouldn't be reported for ignored functions.
*/ */
static void get_ignores(struct objtool_file *file) static void add_ignores(struct objtool_file *file)
{ {
struct instruction *insn; struct instruction *insn;
struct section *sec; struct section *sec;
struct symbol *func; struct symbol *func;
list_for_each_entry(sec, &file->elf->sections, list) { list_for_each_entry(sec, &file->elf->sections, list) {
list_for_each_entry(func, &sec->symbols, list) { list_for_each_entry(func, &sec->symbol_list, list) {
if (func->type != STT_FUNC) if (func->type != STT_FUNC)
continue; continue;
...@@ -308,7 +308,7 @@ static void get_ignores(struct objtool_file *file) ...@@ -308,7 +308,7 @@ static void get_ignores(struct objtool_file *file)
/* /*
* Find the destination instructions for all jumps. * Find the destination instructions for all jumps.
*/ */
static int get_jump_destinations(struct objtool_file *file) static int add_jump_destinations(struct objtool_file *file)
{ {
struct instruction *insn; struct instruction *insn;
struct rela *rela; struct rela *rela;
...@@ -365,7 +365,7 @@ static int get_jump_destinations(struct objtool_file *file) ...@@ -365,7 +365,7 @@ static int get_jump_destinations(struct objtool_file *file)
/* /*
* Find the destination instructions for all calls. * Find the destination instructions for all calls.
*/ */
static int get_call_destinations(struct objtool_file *file) static int add_call_destinations(struct objtool_file *file)
{ {
struct instruction *insn; struct instruction *insn;
unsigned long dest_off; unsigned long dest_off;
...@@ -534,7 +534,7 @@ static int handle_jump_alt(struct objtool_file *file, ...@@ -534,7 +534,7 @@ static int handle_jump_alt(struct objtool_file *file,
* instruction(s) has them added to its insn->alts list, which will be * instruction(s) has them added to its insn->alts list, which will be
* traversed in validate_branch(). * traversed in validate_branch().
*/ */
static int get_special_section_alts(struct objtool_file *file) static int add_special_section_alts(struct objtool_file *file)
{ {
struct list_head special_alts; struct list_head special_alts;
struct instruction *orig_insn, *new_insn; struct instruction *orig_insn, *new_insn;
...@@ -604,10 +604,10 @@ static int get_special_section_alts(struct objtool_file *file) ...@@ -604,10 +604,10 @@ static int get_special_section_alts(struct objtool_file *file)
* section which contains a list of addresses within the function to jump to. * section which contains a list of addresses within the function to jump to.
* This finds these jump tables and adds them to the insn->alts lists. * This finds these jump tables and adds them to the insn->alts lists.
*/ */
static int get_switch_alts(struct objtool_file *file) static int add_switch_table_alts(struct objtool_file *file)
{ {
struct instruction *insn, *alt_insn; struct instruction *insn, *alt_insn;
struct rela *rodata_rela, *rela; struct rela *rodata_rela, *text_rela;
struct section *rodata; struct section *rodata;
struct symbol *func; struct symbol *func;
struct alternative *alt; struct alternative *alt;
...@@ -616,9 +616,9 @@ static int get_switch_alts(struct objtool_file *file) ...@@ -616,9 +616,9 @@ static int get_switch_alts(struct objtool_file *file)
if (insn->type != INSN_JUMP_DYNAMIC) if (insn->type != INSN_JUMP_DYNAMIC)
continue; continue;
rodata_rela = find_rela_by_dest_range(insn->sec, insn->offset, text_rela = find_rela_by_dest_range(insn->sec, insn->offset,
insn->len); insn->len);
if (!rodata_rela || strcmp(rodata_rela->sym->name, ".rodata")) if (!text_rela || strcmp(text_rela->sym->name, ".rodata"))
continue; continue;
rodata = find_section_by_name(file->elf, ".rodata"); rodata = find_section_by_name(file->elf, ".rodata");
...@@ -626,13 +626,13 @@ static int get_switch_alts(struct objtool_file *file) ...@@ -626,13 +626,13 @@ static int get_switch_alts(struct objtool_file *file)
continue; continue;
/* common case: jmpq *[addr](,%rax,8) */ /* common case: jmpq *[addr](,%rax,8) */
rela = find_rela_by_dest(rodata, rodata_rela->addend); rodata_rela = find_rela_by_dest(rodata, text_rela->addend);
/* rare case: jmpq *[addr](%rip) */ /* rare case: jmpq *[addr](%rip) */
if (!rela) if (!rodata_rela)
rela = find_rela_by_dest(rodata, rodata_rela = find_rela_by_dest(rodata,
rodata_rela->addend + 4); text_rela->addend + 4);
if (!rela) if (!rodata_rela)
continue; continue;
func = find_containing_func(insn->sec, insn->offset); func = find_containing_func(insn->sec, insn->offset);
...@@ -642,17 +642,19 @@ static int get_switch_alts(struct objtool_file *file) ...@@ -642,17 +642,19 @@ static int get_switch_alts(struct objtool_file *file)
return -1; return -1;
} }
list_for_each_entry_from(rela, &rodata->rela->relas, list) { list_for_each_entry_from(rodata_rela, &rodata->rela->rela_list,
if (rela->sym->sec != insn->sec || list) {
rela->addend <= func->offset || if (rodata_rela->sym->sec != insn->sec ||
rela->addend >= func->offset + func->len) rodata_rela->addend <= func->offset ||
rodata_rela->addend >= func->offset + func->len)
break; break;
alt_insn = find_insn(file, insn->sec, rela->addend); alt_insn = find_insn(file, insn->sec,
rodata_rela->addend);
if (!alt_insn) { if (!alt_insn) {
WARN("%s: can't find instruction at %s+0x%x", WARN("%s: can't find instruction at %s+0x%x",
rodata->rela->name, insn->sec->name, rodata->rela->name, insn->sec->name,
rela->addend); rodata_rela->addend);
return -1; return -1;
} }
...@@ -678,21 +680,21 @@ static int decode_sections(struct objtool_file *file) ...@@ -678,21 +680,21 @@ static int decode_sections(struct objtool_file *file)
if (ret) if (ret)
return ret; return ret;
get_ignores(file); add_ignores(file);
ret = get_jump_destinations(file); ret = add_jump_destinations(file);
if (ret) if (ret)
return ret; return ret;
ret = get_call_destinations(file); ret = add_call_destinations(file);
if (ret) if (ret)
return ret; return ret;
ret = get_special_section_alts(file); ret = add_special_section_alts(file);
if (ret) if (ret)
return ret; return ret;
ret = get_switch_alts(file); ret = add_switch_table_alts(file);
if (ret) if (ret)
return ret; return ret;
...@@ -901,7 +903,7 @@ static bool is_gcov_insn(struct instruction *insn) ...@@ -901,7 +903,7 @@ static bool is_gcov_insn(struct instruction *insn)
sec = rela->sym->sec; sec = rela->sym->sec;
offset = rela->addend + insn->offset + insn->len - rela->offset; offset = rela->addend + insn->offset + insn->len - rela->offset;
list_for_each_entry(sym, &sec->symbols, list) { list_for_each_entry(sym, &sec->symbol_list, list) {
if (sym->type != STT_OBJECT) if (sym->type != STT_OBJECT)
continue; continue;
...@@ -968,7 +970,7 @@ static int validate_functions(struct objtool_file *file) ...@@ -968,7 +970,7 @@ static int validate_functions(struct objtool_file *file)
int ret, warnings = 0; int ret, warnings = 0;
list_for_each_entry(sec, &file->elf->sections, list) { list_for_each_entry(sec, &file->elf->sections, list) {
list_for_each_entry(func, &sec->symbols, list) { list_for_each_entry(func, &sec->symbol_list, list) {
if (func->type != STT_FUNC) if (func->type != STT_FUNC)
continue; continue;
...@@ -986,7 +988,7 @@ static int validate_functions(struct objtool_file *file) ...@@ -986,7 +988,7 @@ static int validate_functions(struct objtool_file *file)
} }
list_for_each_entry(sec, &file->elf->sections, list) { list_for_each_entry(sec, &file->elf->sections, list) {
list_for_each_entry(func, &sec->symbols, list) { list_for_each_entry(func, &sec->symbol_list, list) {
if (func->type != STT_FUNC) if (func->type != STT_FUNC)
continue; continue;
...@@ -1028,7 +1030,7 @@ static void cleanup(struct objtool_file *file) ...@@ -1028,7 +1030,7 @@ static void cleanup(struct objtool_file *file)
struct instruction *insn, *tmpinsn; struct instruction *insn, *tmpinsn;
struct alternative *alt, *tmpalt; struct alternative *alt, *tmpalt;
list_for_each_entry_safe(insn, tmpinsn, &file->insns, list) { list_for_each_entry_safe(insn, tmpinsn, &file->insn_list, list) {
list_for_each_entry_safe(alt, tmpalt, &insn->alts, list) { list_for_each_entry_safe(alt, tmpalt, &insn->alts, list) {
list_del(&alt->list); list_del(&alt->list);
free(alt); free(alt);
...@@ -1067,7 +1069,7 @@ int cmd_check(int argc, const char **argv) ...@@ -1067,7 +1069,7 @@ int cmd_check(int argc, const char **argv)
return 1; return 1;
} }
INIT_LIST_HEAD(&file.insns); INIT_LIST_HEAD(&file.insn_list);
ret = decode_sections(&file); ret = decode_sections(&file);
if (ret < 0) if (ret < 0)
......
...@@ -59,7 +59,7 @@ static struct symbol *find_symbol_by_index(struct elf *elf, unsigned int idx) ...@@ -59,7 +59,7 @@ static struct symbol *find_symbol_by_index(struct elf *elf, unsigned int idx)
struct symbol *sym; struct symbol *sym;
list_for_each_entry(sec, &elf->sections, list) list_for_each_entry(sec, &elf->sections, list)
list_for_each_entry(sym, &sec->symbols, list) list_for_each_entry(sym, &sec->symbol_list, list)
if (sym->idx == idx) if (sym->idx == idx)
return sym; return sym;
...@@ -70,7 +70,7 @@ struct symbol *find_symbol_by_offset(struct section *sec, unsigned long offset) ...@@ -70,7 +70,7 @@ struct symbol *find_symbol_by_offset(struct section *sec, unsigned long offset)
{ {
struct symbol *sym; struct symbol *sym;
list_for_each_entry(sym, &sec->symbols, list) list_for_each_entry(sym, &sec->symbol_list, list)
if (sym->type != STT_SECTION && if (sym->type != STT_SECTION &&
sym->offset == offset) sym->offset == offset)
return sym; return sym;
...@@ -86,7 +86,7 @@ struct rela *find_rela_by_dest_range(struct section *sec, unsigned long offset, ...@@ -86,7 +86,7 @@ struct rela *find_rela_by_dest_range(struct section *sec, unsigned long offset,
if (!sec->rela) if (!sec->rela)
return NULL; return NULL;
list_for_each_entry(rela, &sec->rela->relas, list) list_for_each_entry(rela, &sec->rela->rela_list, list)
if (rela->offset >= offset && rela->offset < offset + len) if (rela->offset >= offset && rela->offset < offset + len)
return rela; return rela;
...@@ -102,7 +102,7 @@ struct symbol *find_containing_func(struct section *sec, unsigned long offset) ...@@ -102,7 +102,7 @@ struct symbol *find_containing_func(struct section *sec, unsigned long offset)
{ {
struct symbol *func; struct symbol *func;
list_for_each_entry(func, &sec->symbols, list) list_for_each_entry(func, &sec->symbol_list, list)
if (func->type == STT_FUNC && offset >= func->offset && if (func->type == STT_FUNC && offset >= func->offset &&
offset < func->offset + func->len) offset < func->offset + func->len)
return func; return func;
...@@ -135,8 +135,8 @@ static int read_sections(struct elf *elf) ...@@ -135,8 +135,8 @@ static int read_sections(struct elf *elf)
} }
memset(sec, 0, sizeof(*sec)); memset(sec, 0, sizeof(*sec));
INIT_LIST_HEAD(&sec->symbols); INIT_LIST_HEAD(&sec->symbol_list);
INIT_LIST_HEAD(&sec->relas); INIT_LIST_HEAD(&sec->rela_list);
list_add_tail(&sec->list, &elf->sections); list_add_tail(&sec->list, &elf->sections);
...@@ -244,8 +244,8 @@ static int read_symbols(struct elf *elf) ...@@ -244,8 +244,8 @@ static int read_symbols(struct elf *elf)
sym->len = sym->sym.st_size; sym->len = sym->sym.st_size;
/* sorted insert into a per-section list */ /* sorted insert into a per-section list */
entry = &sym->sec->symbols; entry = &sym->sec->symbol_list;
list_for_each_prev(tmp, &sym->sec->symbols) { list_for_each_prev(tmp, &sym->sec->symbol_list) {
struct symbol *s; struct symbol *s;
s = list_entry(tmp, struct symbol, list); s = list_entry(tmp, struct symbol, list);
...@@ -298,7 +298,7 @@ static int read_relas(struct elf *elf) ...@@ -298,7 +298,7 @@ static int read_relas(struct elf *elf)
} }
memset(rela, 0, sizeof(*rela)); memset(rela, 0, sizeof(*rela));
list_add_tail(&rela->list, &sec->relas); list_add_tail(&rela->list, &sec->rela_list);
if (!gelf_getrela(sec->elf_data, i, &rela->rela)) { if (!gelf_getrela(sec->elf_data, i, &rela->rela)) {
perror("gelf_getrela"); perror("gelf_getrela");
...@@ -382,11 +382,11 @@ void elf_close(struct elf *elf) ...@@ -382,11 +382,11 @@ void elf_close(struct elf *elf)
struct rela *rela, *tmprela; struct rela *rela, *tmprela;
list_for_each_entry_safe(sec, tmpsec, &elf->sections, list) { list_for_each_entry_safe(sec, tmpsec, &elf->sections, list) {
list_for_each_entry_safe(sym, tmpsym, &sec->symbols, list) { list_for_each_entry_safe(sym, tmpsym, &sec->symbol_list, list) {
list_del(&sym->list); list_del(&sym->list);
free(sym); free(sym);
} }
list_for_each_entry_safe(rela, tmprela, &sec->relas, list) { list_for_each_entry_safe(rela, tmprela, &sec->rela_list, list) {
list_del(&rela->list); list_del(&rela->list);
free(rela); free(rela);
} }
......
...@@ -25,8 +25,8 @@ ...@@ -25,8 +25,8 @@
struct section { struct section {
struct list_head list; struct list_head list;
GElf_Shdr sh; GElf_Shdr sh;
struct list_head symbols; struct list_head symbol_list;
struct list_head relas; struct list_head rela_list;
struct section *base, *rela; struct section *base, *rela;
struct symbol *sym; struct symbol *sym;
Elf_Data *elf_data; Elf_Data *elf_data;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment