From patchwork Mon Mar 16 07:36:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "xiaoyur347@gmail.com" X-Patchwork-Id: 450403 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ozlabs.org (Postfix) with ESMTP id 3C55E14009B for ; Mon, 16 Mar 2015 18:36:47 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="verification failed; unprotected key" header.d=gmail.com header.i=@gmail.com header.b=zGILOS9b; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 8D85B91AE4; Mon, 16 Mar 2015 07:36:45 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8g9aqQeOYWtK; Mon, 16 Mar 2015 07:36:44 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 6719091ADC; Mon, 16 Mar 2015 07:36:44 +0000 (UTC) X-Original-To: uclibc@lists.busybox.net Delivered-To: uclibc@osuosl.org Received: from silver.osuosl.org (silver.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id 772601C21D3 for ; Mon, 16 Mar 2015 07:36:43 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 6A2503339E for ; Mon, 16 Mar 2015 07:36:43 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iCGr3-OirZmB for ; Mon, 16 Mar 2015 07:36:42 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com [209.85.217.179]) by silver.osuosl.org (Postfix) with ESMTPS id 31B6233096 for ; Mon, 16 Mar 2015 07:36:42 +0000 (UTC) Received: by lbcgn8 with SMTP id gn8so14647262lbc.2 for ; Mon, 16 Mar 2015 00:36:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=bOyXeGv9od3+5LCoS4u5ACp4+S7Gkxg8QI+B/ZRYHsI=; b=zGILOS9bZAf6KWqa3uF43n4uK5qi8gNTQ8kvDsK+XMdJfyqCDi/QbMV+uj92RMTVsz riBK8wSLebR1WgHcLGegKXXYmOJj1xnIKlGOe9kfvNvaSwXgZE8aX0HSY7S++GlZG0a6 Utnghm+A++/OBtvgscrZmVOzi8uO1rJZxW8eiP7w5NcBGF56AzxKzU84emrIqudFUjsw DHrHbMm2MYGPY9Tc+yuAGUm6SsQ34EnkDB7La490VsdZOqtu1U4ZM+i/lY3Jyh5OeAbh Tw46T4u/e9OWtyqdFiOPVICBCAR95xAA7Xt7ne3aJPB8N1f6mcaCy5Fx2J6VTPIAPGoo dMgA== MIME-Version: 1.0 X-Received: by 10.152.23.233 with SMTP id p9mr9351028laf.123.1426491400123; Mon, 16 Mar 2015 00:36:40 -0700 (PDT) Received: by 10.152.106.210 with HTTP; Mon, 16 Mar 2015 00:36:40 -0700 (PDT) In-Reply-To: References: <201502201126341129631@gmail.com> <0DA23CC379F5F945ACB41CF394B9827720F6144B@LEMAIL01.le.imgtec.org> <0DA23CC379F5F945ACB41CF394B9827720F62508@LEMAIL01.le.imgtec.org> <4E4388C4-298E-4122-83DF-1254A24EDBAD@gmail.com> <0DA23CC379F5F945ACB41CF394B9827720F637AD@LEMAIL01.le.imgtec.org> Date: Mon, 16 Mar 2015 15:36:40 +0800 Message-ID: Subject: Re: [PATCH]mips: ldso: dlopen with flag RTLD_NOW should look up the symbols From: Jean Lee To: Bernhard Reutner-Fischer X-Content-Filtered-By: Mailman/MimeDel 2.1.18-1 Cc: uclibc X-BeenThere: uclibc@uclibc.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "Discussion and development of uClibc \(the embedded C library\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: uclibc-bounces@uclibc.org Sender: "uClibc" After reading eglibc code, I find it's much similar to uclibc ldso/ldso/mips/elfinterp.c:_dl_perform_mips_global_got_relocations. See " http://www.eglibc.org/svn/branches/eglibc-2_18/libc/ports/sysdeps/mips/dl-machine.h" elf_machine_got_rel function for more inspect. I slightly modify my last patch to speed the fixup function. Last patch: Go through the whole symtab. This patch: Go through symtab[tpnt->dynamic_info[DT_MIPS_GOTSYM_IDX], the last item of symtab]. Actually this is the .got section. And .got section is subset of symtab. [PATCH] MIPS: Scan the symtab for the dependency of the library to avoid runtime empty function pointer. The dependency = SHN_UNDEF && STB_GLOBAL && (STT_FUNC || STT_OBJECT) Signed-off-by: Jean Lee --- ldso/ldso/mips/elfinterp.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) rpnt = (ELF_RELOC *) rel_addr; @@ -170,6 +171,33 @@ int _dl_parse_relocation_information(struct dyn_elf *xpnt, strtab = (char *) tpnt->dynamic_info[DT_STRTAB]; got = (unsigned long *) tpnt->dynamic_info[DT_PLTGOT]; + i = tpnt->dynamic_info[DT_MIPS_SYMTABNO_IDX] - + tpnt->dynamic_info[DT_MIPS_GOTSYM_IDX]; + psym = symtab + tpnt->dynamic_info[DT_MIPS_GOTSYM_IDX]; + for (; i != 0; --i, ++psym) { + if (psym->st_name == 0) { + continue; + } + + if (psym->st_shndx != SHN_UNDEF + || ELF_ST_BIND(psym->st_info) != STB_GLOBAL + || (ELF_ST_TYPE(psym->st_info) != STT_FUNC + && ELF_ST_TYPE(psym->st_info) != STT_OBJECT)) { + continue; + } + symname = strtab + psym->st_name; + + sym_ref.tpnt = NULL; + sym_ref.sym = psym; + symbol_addr = (unsigned long)_dl_find_hash(symname, + scope, + tpnt, + ELF_RTYPE_CLASS_PLT, &sym_ref); + if (symbol_addr == 0) { + _dl_dprintf (2, "%s: undefined symbol: %s\n",tpnt->libname, symname); + return 1; + } + } for (i = 0; i < rel_size; i++, rpnt++) { reloc_addr = (unsigned long *) (tpnt->loadaddr + diff --git a/ldso/ldso/mips/elfinterp.c b/ldso/ldso/mips/elfinterp.c index dfe37c5..a83da8d 100644 --- a/ldso/ldso/mips/elfinterp.c +++ b/ldso/ldso/mips/elfinterp.c @@ -162,6 +162,7 @@ int _dl_parse_relocation_information(struct dyn_elf *xpnt, #endif struct symbol_ref sym_ref; + ElfW(Sym) *psym = NULL; /* Now parse the relocation information */ rel_size = rel_size / sizeof(ElfW(Rel));