public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hjl.tools at gmail dot com" <sourceware-bugzilla@sourceware.org>
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	[thread overview]
Message-ID: <bug-14538-131-Gd64Zzcne4@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-14538-131@http.sourceware.org/bugzilla/>

http://sourceware.org/bugzilla/show_bug.cgi?id=14538

--- Comment #1 from H.J. Lu <hjl.tools at gmail dot com> 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.


  reply	other threads:[~2012-09-01  5:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-01  5:00 [Bug dynamic-link/14538] New: " hjl.tools at gmail dot com
2012-09-01  5:11 ` hjl.tools at gmail dot com [this message]
2012-09-01 12:49 ` [Bug dynamic-link/14538] " hjl.tools at gmail dot com
2012-09-02 18:09 ` hjl.tools at gmail dot com
2014-06-17  4:47 ` fweimer at redhat dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-14538-131-Gd64Zzcne4@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).