From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3811 invoked by alias); 6 May 2013 21:14:01 -0000 Mailing-List: contact libc-ports-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: libc-ports-owner@sourceware.org Received: (qmail 3800 invoked by uid 89); 6 May 2013 21:14:00 -0000 X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.1 Received: from toast.topped-with-meat.com (HELO topped-with-meat.com) (204.197.218.159) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 06 May 2013 21:13:59 +0000 Received: by topped-with-meat.com (Postfix, from userid 5281) id 0B96D2C061; Mon, 6 May 2013 14:13:58 -0700 (PDT) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit From: Roland McGrath To: libc-ports@sourceware.org Subject: [PATCH roland/arm-elf_machine_dynamic] ARM: Rewrite elf_machine_dynamic in pure C. Message-Id: <20130506211358.0B96D2C061@topped-with-meat.com> Date: Mon, 06 May 2013 21:14:00 -0000 X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=LYSvtFvi c=1 sm=1 tr=0 a=WkljmVdYkabdwxfqvArNOQ==:117 a=14OXPxybAAAA:8 a=j5Y_peH5iS4A:10 a=Z6MIti7PxpgA:10 a=kj9zAlcOel0A:10 a=hOe2yjtxAAAA:8 a=Xag6iWuAtfcA:10 a=21j1AEVPBajZIu6ij1kA:9 a=CjuIK1q_8ugA:10 X-SW-Source: 2013-05/txt/msg00031.txt.bz2 I don't know the history of why it was ever anything but this. Today, the compiler produces code for both -marm and -mthumb that is just about identical to what we had hand-written here. Perhaps it dates from a time when attribute_hidden wasn't available or wasn't reliable? For new variants like arm-nacl, using C leverages the compiler's knowledge of special requirements and avoids having to get another variant defined by hand. Is there any reason not to use C everywhere? Thanks, Roland ports/ChangeLog.arm * sysdeps/arm/dl-machine.h (elf_machine_dynamic): Use a plain C reference to _GLOBAL_OFFSET_TABLE_ with an STV_HIDDEN declaration. --- a/ports/sysdeps/arm/dl-machine.h +++ b/ports/sysdeps/arm/dl-machine.h @@ -39,30 +39,13 @@ elf_machine_matches_host (const Elf32_Ehdr *ehdr) /* Return the link-time address of _DYNAMIC. Conveniently, this is the - first element of the GOT. We used to use the PIC register to do this - without a constant pool reference, but GCC 4.2 will use a pseudo-register - for the PIC base, so it may not be in r10. */ + first element of the GOT. */ static inline Elf32_Addr __attribute__ ((unused)) elf_machine_dynamic (void) { - Elf32_Addr dynamic; -#ifdef __thumb2__ - long tmp; - asm ("ldr\t%0, 1f\n\t" - "adr\t%1, 1f\n\t" - "ldr\t%0, [%0, %1]\n\t" - "b 2f\n" - ".align 2\n" - "1: .word _GLOBAL_OFFSET_TABLE_ - 1b\n" - "2:" : "=r" (dynamic), "=r"(tmp)); -#else - asm ("ldr %0, 2f\n" - "1: ldr %0, [pc, %0]\n" - "b 3f\n" - "2: .word _GLOBAL_OFFSET_TABLE_ - (1b+8)\n" - "3:" : "=r" (dynamic)); -#endif - return dynamic; + /* 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]; }