public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug dynamic-link/14538] New: Complicated x86-64 elf_machine_dynamic/elf_machine_load_address
@ 2012-09-01 5:00 hjl.tools at gmail dot com
2012-09-01 5:11 ` [Bug dynamic-link/14538] " hjl.tools at gmail dot com
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: hjl.tools at gmail dot com @ 2012-09-01 5:00 UTC (permalink / raw)
To: glibc-bugs
http://sourceware.org/bugzilla/show_bug.cgi?id=14538
Bug #: 14538
Summary: Complicated x86-64
elf_machine_dynamic/elf_machine_load_address
Product: glibc
Version: 2.17
Status: NEW
Severity: normal
Priority: P2
Component: dynamic-link
AssignedTo: unassigned@sourceware.org
ReportedBy: hjl.tools@gmail.com
Classification: Unclassified
Target: x86-64
x86-64 has
/* 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)
{
ElfW(Addr) addr;
/* This works because we have our GOT address available in the small PIC
model. */
addr = (ElfW(Addr)) &_DYNAMIC;
return addr;
}
/* Return the run-time load address of the shared object. */
static inline ElfW(Addr) __attribute__ ((unused))
elf_machine_load_address (void)
{
ElfW(Addr) addr;
/* The easy way is just the same as on x86:
leaq _dl_start, %0
leaq _dl_start(%%rip), %1
subq %0, %1
but this does not work with binutils since we then have
a R_X86_64_32S relocation in a shared lib.
Instead we store the address of _dl_start in the data section
and compare it with the current value that we can get via
an RIP relative addressing mode. Note that this is the address
of _dl_start before any relocation performed at runtime. In case
the binary is prelinked the resulting "address" is actually a
load offset which is zero if the binary was loaded at the address
it is prelinked for. */
asm ("lea _dl_start(%%rip), %0\n\t"
"sub 1f(%%rip), %0\n\t"
".section\t.data.rel.ro\n"
"1:\t" ASM_ADDR " _dl_start\n\t"
".previous\n\t"
: "=r" (addr) : : "cc");
return addr;
}
while i386 has
/* Return the link-time address of _DYNAMIC. Conveniently, this is the
first element of the GOT, a special entry that is never relocated. */
static inline Elf32_Addr __attribute__ ((unused, const))
elf_machine_dynamic (void)
{
/* This produces a GOTOFF 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 Elf32_Addr _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
return _GLOBAL_OFFSET_TABLE_[0];
}
/* Return the run-time load address of the shared object. */
static inline Elf32_Addr __attribute__ ((unused))
elf_machine_load_address (void)
{
/* Compute the difference between the runtime address of _DYNAMIC as seen
by a GOTOFF reference, and the link-time address found in the special
unrelocated first GOT entry. */
extern Elf32_Dyn bygotoff[] asm ("_DYNAMIC") attribute_hidden;
return (Elf32_Addr) &bygotoff - elf_machine_dynamic ();
}
i386 version is straight forward and easy to understand.
--
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug dynamic-link/14538] Complicated x86-64 elf_machine_dynamic/elf_machine_load_address
2012-09-01 5:00 [Bug dynamic-link/14538] New: Complicated x86-64 elf_machine_dynamic/elf_machine_load_address hjl.tools at gmail dot com
@ 2012-09-01 5:11 ` hjl.tools at gmail dot com
2012-09-01 12:49 ` hjl.tools at gmail dot com
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: hjl.tools at gmail dot com @ 2012-09-01 5:11 UTC (permalink / raw)
To: glibc-bugs
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug dynamic-link/14538] Complicated x86-64 elf_machine_dynamic/elf_machine_load_address
2012-09-01 5:00 [Bug dynamic-link/14538] New: Complicated x86-64 elf_machine_dynamic/elf_machine_load_address hjl.tools at gmail dot com
2012-09-01 5:11 ` [Bug dynamic-link/14538] " hjl.tools at gmail dot com
@ 2012-09-01 12:49 ` 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
3 siblings, 0 replies; 5+ messages in thread
From: hjl.tools at gmail dot com @ 2012-09-01 12:49 UTC (permalink / raw)
To: glibc-bugs
http://sourceware.org/bugzilla/show_bug.cgi?id=14538
H.J. Lu <hjl.tools at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
URL| |http://sourceware.org/ml/li
| |bc-alpha/2012-09/msg00009.h
| |tml
Target Milestone|--- |2.17
--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> 2012-09-01 12:49:44 UTC ---
A patch is posted at
http://sourceware.org/ml/libc-alpha/2012-09/msg00009.html
--
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug dynamic-link/14538] Complicated x86-64 elf_machine_dynamic/elf_machine_load_address
2012-09-01 5:00 [Bug dynamic-link/14538] New: Complicated x86-64 elf_machine_dynamic/elf_machine_load_address hjl.tools at gmail dot com
2012-09-01 5:11 ` [Bug dynamic-link/14538] " hjl.tools at gmail dot com
2012-09-01 12:49 ` 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
3 siblings, 0 replies; 5+ messages in thread
From: hjl.tools at gmail dot com @ 2012-09-02 18:09 UTC (permalink / raw)
To: glibc-bugs
http://sourceware.org/bugzilla/show_bug.cgi?id=14538
H.J. Lu <hjl.tools at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
--- Comment #3 from H.J. Lu <hjl.tools at gmail dot com> 2012-09-02 18:08:57 UTC ---
Fixed.
--
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug dynamic-link/14538] Complicated x86-64 elf_machine_dynamic/elf_machine_load_address
2012-09-01 5:00 [Bug dynamic-link/14538] New: Complicated x86-64 elf_machine_dynamic/elf_machine_load_address hjl.tools at gmail dot com
` (2 preceding siblings ...)
2012-09-02 18:09 ` hjl.tools at gmail dot com
@ 2014-06-17 4:47 ` fweimer at redhat dot com
3 siblings, 0 replies; 5+ messages in thread
From: fweimer at redhat dot com @ 2014-06-17 4:47 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=14538
Florian Weimer <fweimer at redhat dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Flags| |security-
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-06-17 4:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-01 5:00 [Bug dynamic-link/14538] New: Complicated x86-64 elf_machine_dynamic/elf_machine_load_address hjl.tools at gmail dot com
2012-09-01 5:11 ` [Bug dynamic-link/14538] " hjl.tools at gmail dot com
2012-09-01 12:49 ` 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
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).