From patchwork Fri Mar 20 23:06:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Bennett X-Patchwork-Id: 452826 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 F16C9140142 for ; Sat, 21 Mar 2015 10:07:01 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 3B80E926B4; Fri, 20 Mar 2015 23:07:00 +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 oVx6SAxytPYr; Fri, 20 Mar 2015 23:06:58 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 80253926A2; Fri, 20 Mar 2015 23:06:58 +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 B810C1C16C1 for ; Fri, 20 Mar 2015 23:06:57 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id AEB7933065 for ; Fri, 20 Mar 2015 23:06:57 +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 buS+qtrJkLnk for ; Fri, 20 Mar 2015 23:06:56 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mailapp01.imgtec.com (mailapp01.imgtec.com [195.59.15.196]) by silver.osuosl.org (Postfix) with ESMTP id 257FF32210 for ; Fri, 20 Mar 2015 23:06:56 +0000 (UTC) Received: from KLMAIL01.kl.imgtec.org (unknown [192.168.5.35]) by Websense Email Security Gateway with ESMTPS id E91178F9C8D29; Fri, 20 Mar 2015 23:06:49 +0000 (GMT) Received: from LEMAIL01.le.imgtec.org (192.168.152.62) by KLMAIL01.kl.imgtec.org (192.168.5.35) with Microsoft SMTP Server (TLS) id 14.3.195.1; Fri, 20 Mar 2015 23:06:53 +0000 Received: from LEMAIL01.le.imgtec.org ([fe80::5ae:ee16:f4b9:cda9]) by LEMAIL01.le.imgtec.org ([fe80::5ae:ee16:f4b9:cda9%17]) with mapi id 14.03.0210.002; Fri, 20 Mar 2015 23:06:52 +0000 From: Andrew Bennett To: Jean Lee , Bernhard Reutner-Fischer Subject: RE: [PATCH]mips: ldso: dlopen with flag RTLD_NOW should look up the symbols Thread-Topic: [PATCH]mips: ldso: dlopen with flag RTLD_NOW should look up the symbols Thread-Index: AQHQTL0OzZLnOeKf+kiEx/gEkLyjF5z5YIWAgAGkjYCAA1tMMIAAc1IAgAAvEgCAARS2AIAAvS4AgABGNACAAMqL8IAayuSAgADp7ICAASBqAIAAI8gAgAcuZuA= Date: Fri, 20 Mar 2015 23:06:51 +0000 Message-ID: <0DA23CC379F5F945ACB41CF394B9827720F88CA3@LEMAIL01.le.imgtec.org> 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> In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.168.152.89] MIME-Version: 1.0 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" Hi Jean, Many thanks for the patch. If my reading of your patch is correct it looks as if it will not respect lazy function binding, as it always resolves the function entries. You will therefore need to predicate this to happen only if RTLD_NOW is used. Having saying this I am not sure if the fix is in the correct place. The issue here is about how the dynamic loader loads different types of ELF files and then deals with resolving the ELF's symbols. I would therefore be happier if the fix was made to the core dynamic loader code to handle this case. Finally, it would be good if your testcase could be added to the tests in tests/dlopen so that we can check for this issue in the future. Many thanks, Andrew From: Jean Lee [mailto:xiaoyur347@gmail.com] Sent: 16 March 2015 07:37 To: Bernhard Reutner-Fischer Cc: Andrew Bennett; Florian Fainelli; Gregory Fong; uclibc Subject: Re: [PATCH]mips: ldso: dlopen with flag RTLD_NOW should look up the symbols 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(+) 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));   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)) { + continue003B + } + 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 +