From patchwork Mon Jan 9 17:31:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 713963 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from helium.openadk.org (helium.openadk.org [IPv6:2a00:1828:2000:679::23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tzLLt4sb6z9t15 for ; Thu, 12 Jan 2017 07:38:13 +1100 (AEDT) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id 3E73410106; Wed, 11 Jan 2017 21:38:06 +0100 (CET) X-Original-To: devel@uclibc-ng.org Delivered-To: devel@helium.openadk.org Received: from smtprelay.synopsys.com (us01smtprelay-2.synopsys.com [198.182.47.9]) by helium.openadk.org (Postfix) with ESMTPS id D01A4100B4 for ; Mon, 9 Jan 2017 18:31:34 +0100 (CET) Received: from mailhost.synopsys.com (mailhost1.synopsys.com [10.12.238.239]) by smtprelay.synopsys.com (Postfix) with ESMTP id F2BD124E041B; Mon, 9 Jan 2017 09:31:31 -0800 (PST) Received: from mailhost.synopsys.com (localhost [127.0.0.1]) by mailhost.synopsys.com (Postfix) with ESMTP id CF073B5A; Mon, 9 Jan 2017 09:31:31 -0800 (PST) Received: from US01WEHTC2.internal.synopsys.com (us01wehtc2-vip.internal.synopsys.com [10.12.239.238]) by mailhost.synopsys.com (Postfix) with ESMTP id 7BA73B44; Mon, 9 Jan 2017 09:31:31 -0800 (PST) Received: from IN01WEHTCA.internal.synopsys.com (10.144.199.104) by US01WEHTC2.internal.synopsys.com (10.12.239.237) with Microsoft SMTP Server (TLS) id 14.3.266.1; Mon, 9 Jan 2017 09:31:31 -0800 Received: from IN01WEHTCB.internal.synopsys.com (10.144.199.105) by IN01WEHTCA.internal.synopsys.com (10.144.199.103) with Microsoft SMTP Server (TLS) id 14.3.266.1; Mon, 9 Jan 2017 23:01:30 +0530 Received: from vineetg-Latitude-E7450.internal.synopsys.com (10.10.161.54) by IN01WEHTCB.internal.synopsys.com (10.144.199.243) with Microsoft SMTP Server (TLS) id 14.3.266.1; Mon, 9 Jan 2017 23:01:29 +0530 From: Vineet Gupta To: Date: Mon, 9 Jan 2017 09:31:19 -0800 Message-ID: <1483983079-28539-1-git-send-email-vgupta@synopsys.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.10.161.54] Cc: Cupertino.Miranda@synopsys.com, linux-snps-arc@lists.infradead.org, Vineet Gupta , Alexey.Brodkin@synopsys.com, Claudiu Zissulescu Subject: [uclibc-ng-devel] [PATCH] ARC: ldso: don't use _DYNAMIC@gotpc construct to refer to GOT X-BeenThere: devel@uclibc-ng.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: uClibc-ng Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: devel-bounces@uclibc-ng.org Sender: "devel" Historically we've used a special construct _DYNAMIC@gotpc to refer to base address of GOT This has been done with a special hack in binutils which tools guys now wish to get rid off. So rewrite the 2 callers of this construct to use the simpler and more obvious constructs. There's existing _GLOBAL_OFFSET_TABLE symbols provided by linker which can be used for same purposes. Signed-off-by: Vineet Gupta --- ldso/ldso/arc/dl-sysdep.h | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/ldso/ldso/arc/dl-sysdep.h b/ldso/ldso/arc/dl-sysdep.h index c6086e68e5c6..361a9bb9c0c3 100644 --- a/ldso/ldso/arc/dl-sysdep.h +++ b/ldso/ldso/arc/dl-sysdep.h @@ -119,37 +119,26 @@ extern unsigned __udivmodsi4(unsigned, unsigned) attribute_hidden; | (((type) == R_ARC_COPY) * ELF_RTYPE_CLASS_COPY)) /* - * Get the runtime address of GOT[0] + * Get build time address of .dynamic as setup in GOT[0] + * This is called very early in _dl_start() so it has not been relocated to + * runtime value */ static __always_inline Elf32_Addr elf_machine_dynamic(void) { - Elf32_Addr dyn; - - __asm__("ld %0,[pcl,_DYNAMIC@gotpc]\n\t" : "=r" (dyn)); - return dyn; + /* Declaring this hidden ensures that a PC-relative reference is used. */ + extern const Elf32_Addr _GLOBAL_OFFSET_TABLE_[] attribute_hidden; + return _GLOBAL_OFFSET_TABLE_[0]; } /* Return the run-time load address of the shared object. */ static __always_inline Elf32_Addr elf_machine_load_address(void) { - /* To find the loadaddr we subtract the runtime addr of a non-local symbol - * say _DYNAMIC from it's build-time addr. - * N.B., gotpc loads get optimized by the linker if it finds the symbol - * is resolved locally. - * A more robust - and efficient - solution would be to use a symbol - * set by the linker. To make it actually save space, we'd have to - * suppress the unwanted text relocation in the linked dso, though. - * (I.e. in ldso.so.*, though it's just another dso as far as bfd/ld - * are concerned.) - */ - Elf32_Addr addr, tmp; - __asm__ ( - "ld %1, [pcl, _DYNAMIC@gotpc] ;build addr of _DYNAMIC" "\n" - "add %0, pcl, _DYNAMIC@pcl ;runtime addr of _DYNAMIC" "\n" - "sub %0, %0, %1 ;delta" "\n" - : "=&r" (addr), "=r"(tmp) - ); - return addr; + Elf32_Addr build_addr, run_addr; + + build_addr = elf_machine_dynamic(); + __asm__ ("add %0, pcl, _DYNAMIC@pcl \n" : "=r" (run_addr)); + + return run_addr - build_addr; } static __always_inline void