From bac2279c47faa71371e0890f82dd908aacecd67b Mon Sep 17 00:00:00 2001 From: yinchuang Date: Thu, 1 Dec 2022 22:31:27 +0800 Subject: [PATCH] Add cache for relocation Signed-off-by: yinchuang --- porting/linux/user/ldso/dynlink.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/porting/linux/user/ldso/dynlink.c b/porting/linux/user/ldso/dynlink.c index c72da6e2..b4009034 100644 --- a/porting/linux/user/ldso/dynlink.c +++ b/porting/linux/user/ldso/dynlink.c @@ -112,6 +112,10 @@ struct dso { /* mark the dso status */ unsigned int flags; + int cache_sym_index; + struct dso *cache_dso; + Sym *cache_sym; + Phdr *phdr; int phnum; size_t phentsize; @@ -954,10 +958,18 @@ static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stri ctx = type==REL_COPY ? head->syms_next : head; struct verinfo vinfo = { .s = name, .v = "" }; vinfo.use_vna_hash = get_vna_hash(dso, sym_index, &vinfo.vna_hash); - def = (sym->st_info>>4) == STB_LOCAL - ? (struct symdef){ .dso = dso, .sym = sym } - : dso != &ldso ? find_sym_by_saved_so_list(type, ctx, &vinfo, type==REL_PLT, dso) - : find_sym2(ctx, &vinfo, type==REL_PLT, 0, dso->namespace); + if (dso->cache_sym_index == sym_index) { + def = (struct symdef){ .dso = dso->cache_dso, .sym = dso->cache_sym }; + } else { + def = (sym->st_info>>4) == STB_LOCAL + ? (struct symdef){ .dso = dso, .sym = sym } + : dso != &ldso ? find_sym_by_saved_so_list(type, ctx, &vinfo, type==REL_PLT, dso) + : find_sym2(ctx, &vinfo, type==REL_PLT, 0, dso->namespace); + dso->cache_sym_index = sym_index; + dso->cache_dso = def.dso; + dso->cache_sym = def.sym; + } + if (!def.sym && (sym->st_shndx != SHN_UNDEF || sym->st_info>>4 != STB_WEAK)) { if (dso->lazy && (type==REL_PLT || type==REL_GOT)) { -- GitLab