From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 374 invoked by alias); 1 Sep 2012 05:11:37 -0000 Received: (qmail 366 invoked by uid 22791); 1 Sep 2012 05:11:35 -0000 X-SWARE-Spam-Status: No, hits=-3.7 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,KHOP_THREADED,TW_DD,TW_OV X-Spam-Check-By: sourceware.org Received: from localhost (HELO sourceware.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 01 Sep 2012 05:11:22 +0000 From: "hjl.tools at gmail dot com" To: glibc-bugs@sources.redhat.com Subject: [Bug dynamic-link/14538] Complicated x86-64 elf_machine_dynamic/elf_machine_load_address Date: Sat, 01 Sep 2012 05:11:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: dynamic-link X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hjl.tools at gmail dot com X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sourceware.org X-SW-Source: 2012-09/txt/msg00001.txt.bz2 http://sourceware.org/bugzilla/show_bug.cgi?id=14538 --- Comment #1 from H.J. Lu 2012-09-01 05:11:21 UTC --- The new version: /* Return the link-time address of _DYNAMIC. Conveniently, this is the first element of the GOT. This must be inlined in a function which uses global data. */ static inline ElfW(Addr) __attribute__ ((unused)) elf_machine_dynamic (void) { /* This produces a PC32 reloc that resolves to zero at link time, so in fact just loads from the GOT register directly. By doing it without an asm we can let the compiler choose any register. */ extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_[] attribute_hidden; return _GLOBAL_OFFSET_TABLE_[0]; } /* Return the run-time load address of the shared object. */ static inline ElfW(Addr) __attribute__ ((unused)) elf_machine_load_address (void) { /* Compute the difference between the runtime address of _DYNAMIC as seen by a PC32 reference, and the link-time address found in the special unrelocated first GOT entry. */ extern ElfW(Dyn) bygotoff[] asm ("_DYNAMIC") attribute_hidden; return (ElfW(Addr)) &bygotoff - elf_machine_dynamic (); } It generates: movq _DYNAMIC(%rip), %rax movq %rdx, start_time(%rip) leaq _DYNAMIC(%rip), %rdx movq %rdx, %r13 subq _GLOBAL_OFFSET_TABLE_(%rip), %r13 testq %rax, %rax movq %rdx, 2472+_rtld_local(%rip) movq %r13, 2456+_rtld_local(%rip) je .L993 instead of #APP # 75 "../sysdeps/x86_64/dl-machine.h" 1 lea _dl_start(%rip), %r13 sub 1f(%rip), %r13 .section .data.rel.ro 1: .quad _dl_start .previous # 0 "" 2 #NO_APP movq %rdx, start_time(%rip) movq %r13, %rdx addq _DYNAMIC@GOTPCREL(%rip), %rdx movq %r13, 2456+_rtld_local(%rip) movq (%rdx), %rax movq %rdx, 2472+_rtld_local(%rip) testq %rax, %rax je .L994 The new one avoids one load and reduces one GOT entry. -- Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.