Skip to content

Commit

Permalink
create-klp-module: group .kpatch.symbols with like-scope
Browse files Browse the repository at this point in the history
From Oracle's Linker and Libraries Guide [1]:

"The symbols in a symbol table are written in the following order ...
The global symbols immediately follow the local symbols in the symbol
table. The first global symbol is identified by the symbol table sh_info
value. Local and global symbols are always kept separate in this manner,
and cannot be mixed together."

[1] https://docs.oracle.com/cd/E19120-01/open.solaris/819-0690/chapter6-79797/index.html

Fixes dynup#854.
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
  • Loading branch information
joe-lawrence committed May 29, 2018
1 parent ba5f3a9 commit de10550
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
21 changes: 20 additions & 1 deletion kpatch-build/create-klp-module.c
Expand Up @@ -81,7 +81,7 @@ static struct symbol *find_or_add_ksym_to_symbols(struct kpatch_elf *kelf,
return sym;
}

ALLOC_LINK(sym, &kelf->symbols);
ALLOC_LINK(sym, NULL);
sym->name = strdup(buf);
if (!sym->name)
ERROR("strdup");
Expand All @@ -93,6 +93,25 @@ static struct symbol *find_or_add_ksym_to_symbols(struct kpatch_elf *kelf,
*/
sym->sym.st_shndx = SHN_LIVEPATCH;
sym->sym.st_info = GELF_ST_INFO(sym->bind, sym->type);
/*
* Figure out where to put the new symbol:
* a) locals need to be grouped together, before globals
* b) globals can be tacked into the end of the list
*/
if (is_local_sym(sym)) {
struct list_head *head;
struct symbol *s;

head = &kelf->symbols;
list_for_each_entry(s, &kelf->symbols, list) {
if (!is_local_sym(s))
break;
head = &s->list;
}
list_add_tail(&sym->list, head);
} else {
list_add_tail(&sym->list, &kelf->symbols);
}

return sym;
}
Expand Down
3 changes: 2 additions & 1 deletion kpatch-build/kpatch-elf.h
Expand Up @@ -128,7 +128,8 @@ struct rela *find_rela_by_offset(struct section *relasec, unsigned int offset);
ERROR("malloc"); \
memset((_new), 0, sizeof(*(_new))); \
INIT_LIST_HEAD(&(_new)->list); \
list_add_tail(&(_new)->list, (_list)); \
if (_list) \
list_add_tail(&(_new)->list, (_list)); \
}

int offset_of_string(struct list_head *list, char *name);
Expand Down

0 comments on commit de10550

Please sign in to comment.