mirror of
https://github.com/dynup/kpatch
synced 2025-02-27 23:40:32 +00:00
s/sybmols/symbols/ in create-diff-object
Signed-off-by: Seth Jennings <sjenning@redhat.com>
This commit is contained in:
parent
8656355291
commit
62bb62f409
@ -125,7 +125,7 @@ struct rela {
|
|||||||
struct kpatch_elf {
|
struct kpatch_elf {
|
||||||
Elf *elf;
|
Elf *elf;
|
||||||
struct table sections;
|
struct table sections;
|
||||||
struct table sybmols;
|
struct table symbols;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*******************
|
/*******************
|
||||||
@ -248,7 +248,7 @@ void kpatch_create_rela_table(struct kpatch_elf *kelf, struct section *sec)
|
|||||||
rela->addend = rela->rela.r_addend;
|
rela->addend = rela->rela.r_addend;
|
||||||
rela->offset = rela->rela.r_offset;
|
rela->offset = rela->rela.r_offset;
|
||||||
symndx = GELF_R_SYM(rela->rela.r_info);
|
symndx = GELF_R_SYM(rela->rela.r_info);
|
||||||
rela->sym = find_symbol_by_index(&kelf->sybmols, symndx);
|
rela->sym = find_symbol_by_index(&kelf->symbols, symndx);
|
||||||
if (!rela->sym)
|
if (!rela->sym)
|
||||||
ERROR("could not find rela entry symbol\n");
|
ERROR("could not find rela entry symbol\n");
|
||||||
if (rela->sym->sec && (rela->sym->sec->sh.sh_flags & SHF_STRINGS)) {
|
if (rela->sym->sec && (rela->sym->sec->sh.sh_flags & SHF_STRINGS)) {
|
||||||
@ -334,14 +334,14 @@ void kpatch_create_symbol_table(struct kpatch_elf *kelf)
|
|||||||
|
|
||||||
symbols_nr = symtab->sh.sh_size / symtab->sh.sh_entsize;
|
symbols_nr = symtab->sh.sh_size / symtab->sh.sh_entsize;
|
||||||
|
|
||||||
alloc_table(&kelf->sybmols, sizeof(struct symbol), symbols_nr);
|
alloc_table(&kelf->symbols, sizeof(struct symbol), symbols_nr);
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
printf("\n=== symbol table (%d entries) ===\n", symbols_nr);
|
printf("\n=== symbol table (%d entries) ===\n", symbols_nr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* iterator i declared in for_each_entry() macro */
|
/* iterator i declared in for_each_entry() macro */
|
||||||
for_each_symbol(i, sym, &kelf->sybmols) {
|
for_each_symbol(i, sym, &kelf->symbols) {
|
||||||
if (i == 0) /* skip symbol 0 */
|
if (i == 0) /* skip symbol 0 */
|
||||||
continue;
|
continue;
|
||||||
sym->index = i;
|
sym->index = i;
|
||||||
@ -670,7 +670,7 @@ void kpatch_correlate_elfs(struct kpatch_elf *kelf1, struct kpatch_elf *kelf2)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
kpatch_correlate_sections(&kelf1->sections, &kelf2->sections);
|
kpatch_correlate_sections(&kelf1->sections, &kelf2->sections);
|
||||||
kpatch_correlate_symbols(&kelf1->sybmols, &kelf2->sybmols);
|
kpatch_correlate_symbols(&kelf1->symbols, &kelf2->symbols);
|
||||||
|
|
||||||
/* at this point, sections are correlated, we can use sec->twin */
|
/* at this point, sections are correlated, we can use sec->twin */
|
||||||
for_each_section(i, sec, &kelf1->sections)
|
for_each_section(i, sec, &kelf1->sections)
|
||||||
@ -686,7 +686,7 @@ void kpatch_compare_correlated_elements(struct kpatch_elf *kelf)
|
|||||||
|
|
||||||
/* tables are already correlated at this point */
|
/* tables are already correlated at this point */
|
||||||
kpatch_compare_correlated_sections(&kelf->sections);
|
kpatch_compare_correlated_sections(&kelf->sections);
|
||||||
kpatch_compare_correlated_symbols(&kelf->sybmols);
|
kpatch_compare_correlated_symbols(&kelf->symbols);
|
||||||
|
|
||||||
for_each_section(i, sec, &kelf->sections)
|
for_each_section(i, sec, &kelf->sections)
|
||||||
if (is_rela_section(sec))
|
if (is_rela_section(sec))
|
||||||
@ -763,7 +763,7 @@ void kpatch_dump_kelf(struct kpatch_elf *kelf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("\n=== Symbols ===\n");
|
printf("\n=== Symbols ===\n");
|
||||||
for_each_symbol(i, sym, &kelf->sybmols) {
|
for_each_symbol(i, sym, &kelf->symbols) {
|
||||||
if (i == 0) /* ugh */
|
if (i == 0) /* ugh */
|
||||||
continue;
|
continue;
|
||||||
printf("sym %02d, type %d=%d, bind %d=%d, ndx %02d, name %s (%s)",
|
printf("sym %02d, type %d=%d, bind %d=%d, ndx %02d, name %s (%s)",
|
||||||
@ -780,7 +780,7 @@ int kpatch_find_changed_functions(struct kpatch_elf *kelf)
|
|||||||
struct symbol *sym;
|
struct symbol *sym;
|
||||||
int i, changed = 0;
|
int i, changed = 0;
|
||||||
|
|
||||||
for_each_symbol(i, sym, &kelf->sybmols) {
|
for_each_symbol(i, sym, &kelf->symbols) {
|
||||||
if (sym->type != STT_FUNC)
|
if (sym->type != STT_FUNC)
|
||||||
continue;
|
continue;
|
||||||
if (sym->status == CHANGED) {
|
if (sym->status == CHANGED) {
|
||||||
@ -837,7 +837,7 @@ void kpatch_validate_reachability(struct kpatch_elf *kelf)
|
|||||||
struct section *sec;
|
struct section *sec;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for_each_symbol(i, sym, &kelf->sybmols)
|
for_each_symbol(i, sym, &kelf->symbols)
|
||||||
if (!sym->reachable && sym->status != SAME &&
|
if (!sym->reachable && sym->status != SAME &&
|
||||||
sym->type == STT_FUNC)
|
sym->type == STT_FUNC)
|
||||||
kpatch_reachable_symbol(sym);
|
kpatch_reachable_symbol(sym);
|
||||||
@ -878,7 +878,7 @@ void kpatch_generate_output(struct kpatch_elf *kelf, struct kpatch_elf **kelfout
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* count output symbols */
|
/* count output symbols */
|
||||||
for_each_symbol(i, sym, &kelf->sybmols) {
|
for_each_symbol(i, sym, &kelf->symbols) {
|
||||||
if (i == 0 || sym->status != SAME)
|
if (i == 0 || sym->status != SAME)
|
||||||
symbols_nr++;
|
symbols_nr++;
|
||||||
}
|
}
|
||||||
@ -894,7 +894,7 @@ void kpatch_generate_output(struct kpatch_elf *kelf, struct kpatch_elf **kelfout
|
|||||||
|
|
||||||
/* allocate tables */
|
/* allocate tables */
|
||||||
alloc_table(&out->sections, sizeof(struct section), sections_nr);
|
alloc_table(&out->sections, sizeof(struct section), sections_nr);
|
||||||
alloc_table(&out->sybmols, sizeof(struct symbol), symbols_nr);
|
alloc_table(&out->symbols, sizeof(struct symbol), symbols_nr);
|
||||||
|
|
||||||
/* copy to output kelf sections, link to kelf, and reindex */
|
/* copy to output kelf sections, link to kelf, and reindex */
|
||||||
index = 0;
|
index = 0;
|
||||||
@ -911,11 +911,11 @@ void kpatch_generate_output(struct kpatch_elf *kelf, struct kpatch_elf **kelfout
|
|||||||
|
|
||||||
/* copy to output kelf symbols, link to kelf, and reindex */
|
/* copy to output kelf symbols, link to kelf, and reindex */
|
||||||
index = 0;
|
index = 0;
|
||||||
for_each_symbol(i, sym, &kelf->sybmols) {
|
for_each_symbol(i, sym, &kelf->symbols) {
|
||||||
if (i != 0 && sym->status == SAME)
|
if (i != 0 && sym->status == SAME)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
symout = &((struct symbol *)(out->sybmols.data))[index];
|
symout = &((struct symbol *)(out->symbols.data))[index];
|
||||||
*symout = *sym;
|
*symout = *sym;
|
||||||
symout->index = index;
|
symout->index = index;
|
||||||
symout->twino = sym;
|
symout->twino = sym;
|
||||||
@ -929,7 +929,7 @@ void kpatch_generate_output(struct kpatch_elf *kelf, struct kpatch_elf **kelfout
|
|||||||
symout->sym.st_shndx = sym->sec->twino->index;
|
symout->sym.st_shndx = sym->sec->twino->index;
|
||||||
}
|
}
|
||||||
|
|
||||||
for_each_symbol(i, sym, &out->sybmols) {
|
for_each_symbol(i, sym, &out->symbols) {
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
continue;
|
continue;
|
||||||
/*
|
/*
|
||||||
@ -1076,7 +1076,7 @@ void kpatch_create_strtab(struct kpatch_elf *kelf)
|
|||||||
|
|
||||||
/* determine size of string table */
|
/* determine size of string table */
|
||||||
size = 1; /* for initial NULL terminator */
|
size = 1; /* for initial NULL terminator */
|
||||||
for_each_symbol(i, sym, &kelf->sybmols) {
|
for_each_symbol(i, sym, &kelf->symbols) {
|
||||||
if (i == 0 || sym->type == STT_SECTION)
|
if (i == 0 || sym->type == STT_SECTION)
|
||||||
continue;
|
continue;
|
||||||
size += strlen(sym->name) + 1; /* include NULL terminator */
|
size += strlen(sym->name) + 1; /* include NULL terminator */
|
||||||
@ -1090,7 +1090,7 @@ void kpatch_create_strtab(struct kpatch_elf *kelf)
|
|||||||
|
|
||||||
/* populate string table and link with section header */
|
/* populate string table and link with section header */
|
||||||
offset = 1;
|
offset = 1;
|
||||||
for_each_symbol(i, sym, &kelf->sybmols) {
|
for_each_symbol(i, sym, &kelf->symbols) {
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
continue;
|
continue;
|
||||||
if (sym->type == STT_SECTION) {
|
if (sym->type == STT_SECTION) {
|
||||||
@ -1116,7 +1116,7 @@ void kpatch_create_strtab(struct kpatch_elf *kelf)
|
|||||||
print_strtab(buf, size);
|
print_strtab(buf, size);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
for_each_symbol(i, sym, &kelf->sybmols)
|
for_each_symbol(i, sym, &kelf->symbols)
|
||||||
printf("%s @ strtab offset %d\n",sym->name,sym->sym.st_name);
|
printf("%s @ strtab offset %d\n",sym->name,sym->sym.st_name);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -1134,13 +1134,13 @@ void kpatch_create_symtab(struct kpatch_elf *kelf)
|
|||||||
ERROR("find_section_by_name");
|
ERROR("find_section_by_name");
|
||||||
|
|
||||||
/* create new symtab buffer */
|
/* create new symtab buffer */
|
||||||
size = kelf->sybmols.nr * symtab->sh.sh_entsize;
|
size = kelf->symbols.nr * symtab->sh.sh_entsize;
|
||||||
buf = malloc(size);
|
buf = malloc(size);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
ERROR("malloc");
|
ERROR("malloc");
|
||||||
memset(buf, 0, size);
|
memset(buf, 0, size);
|
||||||
|
|
||||||
for_each_symbol(i, sym, &kelf->sybmols) {
|
for_each_symbol(i, sym, &kelf->symbols) {
|
||||||
memcpy(buf + (i * symtab->sh.sh_entsize), &sym->sym,
|
memcpy(buf + (i * symtab->sh.sh_entsize), &sym->sym,
|
||||||
symtab->sh.sh_entsize);
|
symtab->sh.sh_entsize);
|
||||||
}
|
}
|
||||||
@ -1162,19 +1162,19 @@ void kpatch_link_symtab_vmlinux(struct kpatch_elf *kelf, struct kpatch_elf *vmke
|
|||||||
char kstrbuf[BUFSIZE];
|
char kstrbuf[BUFSIZE];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for_each_symbol(i, sym, &kelf->sybmols) {
|
for_each_symbol(i, sym, &kelf->symbols) {
|
||||||
if (GELF_ST_BIND(sym->sym.st_info) != STB_GLOBAL)
|
if (GELF_ST_BIND(sym->sym.st_info) != STB_GLOBAL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* figure out if symbol is exported by the kernel */
|
/* figure out if symbol is exported by the kernel */
|
||||||
snprintf(kstrbuf, BUFSIZE, "%s%s", "__ksymtab_", sym->name);
|
snprintf(kstrbuf, BUFSIZE, "%s%s", "__ksymtab_", sym->name);
|
||||||
printf("looking for %s\n",kstrbuf);
|
printf("looking for %s\n",kstrbuf);
|
||||||
vmsym = find_symbol_by_name(&vmkelf->sybmols, kstrbuf);
|
vmsym = find_symbol_by_name(&vmkelf->symbols, kstrbuf);
|
||||||
if (vmsym)
|
if (vmsym)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* it is not, lookup address in vmlinux */
|
/* it is not, lookup address in vmlinux */
|
||||||
vmsym = find_symbol_by_name(&vmkelf->sybmols, sym->name);
|
vmsym = find_symbol_by_name(&vmkelf->symbols, sym->name);
|
||||||
if (!vmsym)
|
if (!vmsym)
|
||||||
ERROR("symbol not found in vmlinux");
|
ERROR("symbol not found in vmlinux");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user