From patchwork Fri Feb 20 03:26:36 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: 441826 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from fraxinus.osuosl.org (fraxinus.osuosl.org [140.211.166.137]) by ozlabs.org (Postfix) with ESMTP id 2697214010F for ; Fri, 20 Feb 2015 14:26:38 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 0AD85A397F; Fri, 20 Feb 2015 03:26:38 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5vgdrQ9O7psR; Fri, 20 Feb 2015 03:26:37 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id 6B477A396C; Fri, 20 Feb 2015 03:26:37 +0000 (UTC) X-Original-To: uclibc@lists.busybox.net Delivered-To: uclibc@osuosl.org Received: from hemlock.osuosl.org (hemlock.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 5F08E1C27DE for ; Fri, 20 Feb 2015 03:26:36 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 5C43E94C55 for ; Fri, 20 Feb 2015 03:26:36 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5C-rH6WGTql9 for ; Fri, 20 Feb 2015 03:26:35 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pa0-f48.google.com (mail-pa0-f48.google.com [209.85.220.48]) by hemlock.osuosl.org (Postfix) with ESMTPS id BABA489CDB for ; Fri, 20 Feb 2015 03:26:35 +0000 (UTC) Received: by padbj1 with SMTP id bj1so4710729pad.5 for ; Thu, 19 Feb 2015 19:26:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:mime-version:message-id:content-type; bh=PBkL0UPzRdxbDUz/F2cvEsJXjh6jit4iEJMgFewZtpA=; b=Bnr/r8NqTfTk5/2CLa6fWbQHCkQefK5ABKIYbSVA/Ii3nQGz73Bjp206pLwvXeGm2n QGDrYqvKPu+2bj3EYmvVwxrSvCVhIe/rpuE9ibkExulcWSZKoroqEudE1iKRF38I94FP UafMqlMD8THNEMQOdvlL15Gy1/SxkQYVzDXzLQZR0pE7tJM23bgazUNrsOiQ+Q1lVy98 MMPZzPzCv5BHodH6C1M2cgsfvxz3uQLmYcOMEkEWEcGO7uycjrAxwbaiZbYZWKH9Ze8u 6vlbqvDR+VUk6aS9OI2SL1XZexZyIjPnCx8kOtWdAnqvD6BLgZc4EgoGKTEVSd/+WHjM 3Cdg== X-Received: by 10.70.130.69 with SMTP id oc5mr13288791pdb.160.1424402795386; Thu, 19 Feb 2015 19:26:35 -0800 (PST) Received: from jean ([112.5.121.137]) by mx.google.com with ESMTPSA id pa6sm15390254pac.45.2015.02.19.19.26.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Feb 2015 19:26:34 -0800 (PST) Date: Fri, 20 Feb 2015 11:26:36 +0800 From: "xiaoyur347@gmail.com" To: uclibc Subject: [PATCH]mips: ldso: dlopen with flag RTLD_NOW should look up the symbols X-Priority: 3 X-GUID: EF349C03-C893-4166-A2B9-8457373581D6 X-Has-Attach: no X-Mailer: Foxmail 7, 1, 3, 48[cn] Mime-Version: 1.0 Message-ID: <201502201126341129631@gmail.com> X-Content-Filtered-By: Mailman/MimeDel 2.1.18-1 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" Reason: MIPS ELF strategy is so different from other architectures like x86 and arm. When fPIC enabled in x86 and arm, ".rel.plt" section is generated after ".rel.dyn" section, and the dependency of the library (like the function and object) . But MIPS only generates ".rel.dyn" section for the library when fPIC, and ".rel.dyn" section can only be generated in non-PIC executable. This leads to a bug which other architectures will not have. Description: If you dlopen a library, uclibc only check the symbols defined in ".rel.dyn" section. And ".rel.dyn" section has no outer dependency, most flags have the type "R_MIPS_REL32". Only ".rel.plt" section generates call to R_MIPS_JUMP_SLOT and R_MIPS_COPY. In my environment, I almost see the cplusplus virtual functions in ".rel.dyn". Bug Demo: use mipsel-linux-readelf -aW libxx.so to view the dependency. 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(+) strtab = (char *) tpnt->dynamic_info[DT_STRTAB]; got = (unsigned long *) tpnt->dynamic_info[DT_PLTGOT]; + /* strtab always layout after symtab */ + symtab_size = ((unsigned long)strtab - (unsigned long)symtab) + / tpnt->dynamic_info[DT_SYMENT]; + for (i = 0, psym = symtab; i < symtab_size; ++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) { + return 1; + } + } for (i = 0; i < rel_size; i++, rpnt++) { reloc_addr = (unsigned long *) (tpnt->loadaddr + xiaoyur347@gmail.com diff --git a/ldso/ldso/mips/elfinterp.c b/ldso/ldso/mips/elfinterp.c index dfe37c5..00b136a 100644 --- a/ldso/ldso/mips/elfinterp.c +++ b/ldso/ldso/mips/elfinterp.c @@ -162,6 +162,8 @@ int _dl_parse_relocation_information(struct dyn_elf *xpnt, #endif struct symbol_ref sym_ref; + unsigned long symtab_size = 0; + ElfW(Sym) *psym = NULL; /* Now parse the relocation information */ rel_size = rel_size / sizeof(ElfW(Rel)); rpnt = (ELF_RELOC *) rel_addr; @@ -170,6 +172,32 @@ int _dl_parse_relocation_information(struct dyn_elf *xpnt,