Use hash tables for instruction and rela lookups (and keep the linked
lists around for sequential access).
Also cache the section struct for the "__func_stack_frame_non_standard"
section.
With this change, "objtool check net/wireless/nl80211.o" goes from:
real 0m1.168s
user 0m1.163s
sys 0m0.005s
to:
real 0m0.059s
user 0m0.042s
sys 0m0.017s
for a 20x speedup.
With the same object, it should be noted that the memory heap usage grew
from 8MB to 62MB. Reducing the memory usage is on the TODO list.
Reported-by: Ingo Molnar <mingo@kernel.org>
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/dd0d8e1449506cfa7701b4e7ba73577077c44253.1457502970.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
#include "arch.h"
#include "warn.h"
#include "arch.h"
#include "warn.h"
+#include <linux/hashtable.h>
+
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define STATE_FP_SAVED 0x1
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define STATE_FP_SAVED 0x1
struct instruction {
struct list_head list;
struct instruction {
struct list_head list;
+ struct hlist_node hash;
struct section *sec;
unsigned long offset;
unsigned int len, state;
struct section *sec;
unsigned long offset;
unsigned int len, state;
struct objtool_file {
struct elf *elf;
struct list_head insn_list;
struct objtool_file {
struct elf *elf;
struct list_head insn_list;
- struct section *rodata;
+ DECLARE_HASHTABLE(insn_hash, 16);
+ struct section *rodata, *whitelist;
{
struct instruction *insn;
{
struct instruction *insn;
- list_for_each_entry(insn, &file->insn_list, list)
+ hash_for_each_possible(file->insn_hash, insn, hash, offset)
if (insn->sec == sec && insn->offset == offset)
return insn;
if (insn->sec == sec && insn->offset == offset)
return insn;
*/
static bool ignore_func(struct objtool_file *file, struct symbol *func)
{
*/
static bool ignore_func(struct objtool_file *file, struct symbol *func)
{
- struct section *macro_sec;
struct rela *rela;
struct instruction *insn;
/* check for STACK_FRAME_NON_STANDARD */
struct rela *rela;
struct instruction *insn;
/* check for STACK_FRAME_NON_STANDARD */
- macro_sec = find_section_by_name(file->elf, "__func_stack_frame_non_standard");
- if (macro_sec && macro_sec->rela)
- list_for_each_entry(rela, ¯o_sec->rela->rela_list, list)
+ if (file->whitelist && file->whitelist->rela)
+ list_for_each_entry(rela, &file->whitelist->rela->rela_list, list)
if (rela->sym->sec == func->sec &&
rela->addend == func->offset)
return true;
if (rela->sym->sec == func->sec &&
rela->addend == func->offset)
return true;
+ hash_add(file->insn_hash, &insn->hash, insn->offset);
list_add_tail(&insn->list, &file->insn_list);
}
}
list_add_tail(&insn->list, &file->insn_list);
}
}
+ file->whitelist = find_section_by_name(file->elf, "__func_stack_frame_non_standard");
file->rodata = find_section_by_name(file->elf, ".rodata");
ret = decode_instructions(file);
file->rodata = find_section_by_name(file->elf, ".rodata");
ret = decode_instructions(file);
free(alt);
}
list_del(&insn->list);
free(alt);
}
list_del(&insn->list);
free(insn);
}
elf_close(file->elf);
free(insn);
}
elf_close(file->elf);
}
INIT_LIST_HEAD(&file.insn_list);
}
INIT_LIST_HEAD(&file.insn_list);
+ hash_init(file.insn_hash);
ret = decode_sections(&file);
if (ret < 0)
ret = decode_sections(&file);
if (ret < 0)
struct symbol *sym;
list_for_each_entry(sec, &elf->sections, list)
struct symbol *sym;
list_for_each_entry(sec, &elf->sections, list)
- list_for_each_entry(sym, &sec->symbol_list, list)
+ hash_for_each_possible(sec->symbol_hash, sym, hash, idx)
if (sym->idx == idx)
return sym;
if (sym->idx == idx)
return sym;
unsigned int len)
{
struct rela *rela;
unsigned int len)
{
struct rela *rela;
if (!sec->rela)
return NULL;
if (!sec->rela)
return NULL;
- list_for_each_entry(rela, &sec->rela->rela_list, list)
- if (rela->offset >= offset && rela->offset < offset + len)
- return rela;
+ for (o = offset; o < offset + len; o++)
+ hash_for_each_possible(sec->rela->rela_hash, rela, hash, o)
+ if (rela->offset == o)
+ return rela;
INIT_LIST_HEAD(&sec->symbol_list);
INIT_LIST_HEAD(&sec->rela_list);
INIT_LIST_HEAD(&sec->symbol_list);
INIT_LIST_HEAD(&sec->rela_list);
+ hash_init(sec->rela_hash);
+ hash_init(sec->symbol_hash);
list_add_tail(&sec->list, &elf->sections);
list_add_tail(&sec->list, &elf->sections);
}
}
list_add(&sym->list, entry);
}
}
list_add(&sym->list, entry);
+ hash_add(sym->sec->symbol_hash, &sym->hash, sym->idx);
}
memset(rela, 0, sizeof(*rela));
}
memset(rela, 0, sizeof(*rela));
- list_add_tail(&rela->list, &sec->rela_list);
-
if (!gelf_getrela(sec->elf_data, i, &rela->rela)) {
perror("gelf_getrela");
return -1;
if (!gelf_getrela(sec->elf_data, i, &rela->rela)) {
perror("gelf_getrela");
return -1;
symndx, sec->name);
return -1;
}
symndx, sec->name);
return -1;
}
+
+ list_add_tail(&rela->list, &sec->rela_list);
+ hash_add(sec->rela_hash, &rela->hash, rela->offset);
+
list_for_each_entry_safe(sec, tmpsec, &elf->sections, list) {
list_for_each_entry_safe(sym, tmpsym, &sec->symbol_list, list) {
list_del(&sym->list);
list_for_each_entry_safe(sec, tmpsec, &elf->sections, list) {
list_for_each_entry_safe(sym, tmpsym, &sec->symbol_list, list) {
list_del(&sym->list);
free(sym);
}
list_for_each_entry_safe(rela, tmprela, &sec->rela_list, list) {
list_del(&rela->list);
free(sym);
}
list_for_each_entry_safe(rela, tmprela, &sec->rela_list, list) {
list_del(&rela->list);
free(rela);
}
list_del(&sec->list);
free(rela);
}
list_del(&sec->list);
#include <stdio.h>
#include <gelf.h>
#include <linux/list.h>
#include <stdio.h>
#include <gelf.h>
#include <linux/list.h>
+#include <linux/hashtable.h>
struct section {
struct list_head list;
GElf_Shdr sh;
struct list_head symbol_list;
struct section {
struct list_head list;
GElf_Shdr sh;
struct list_head symbol_list;
+ DECLARE_HASHTABLE(symbol_hash, 8);
struct list_head rela_list;
struct list_head rela_list;
+ DECLARE_HASHTABLE(rela_hash, 16);
struct section *base, *rela;
struct symbol *sym;
Elf_Data *elf_data;
struct section *base, *rela;
struct symbol *sym;
Elf_Data *elf_data;
struct symbol {
struct list_head list;
struct symbol {
struct list_head list;
+ struct hlist_node hash;
GElf_Sym sym;
struct section *sec;
char *name;
GElf_Sym sym;
struct section *sec;
char *name;
unsigned char bind, type;
unsigned long offset;
unsigned int len;
unsigned char bind, type;
unsigned long offset;
unsigned int len;
struct rela {
struct list_head list;
struct rela {
struct list_head list;
+ struct hlist_node hash;
GElf_Rela rela;
struct symbol *sym;
unsigned int type;
GElf_Rela rela;
struct symbol *sym;
unsigned int type;
int fd;
char *name;
struct list_head sections;
int fd;
char *name;
struct list_head sections;
+ DECLARE_HASHTABLE(rela_hash, 16);