public inbox for libc-ports@sourceware.org
 help / color / mirror / Atom feed
* aarch64 prelink issue
@ 2013-06-24 16:41 Mark Salter
  2013-06-24 17:18 ` Richard Henderson
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Salter @ 2013-06-24 16:41 UTC (permalink / raw)
  To: marcus.shawcroft; +Cc: libc-ports

I'm trying to get prelink working for aarch64 and ran into a problem
in the aarch64 elf_machine_dynamic() function which is simply:

/* Return the link-time address of _DYNAMIC.  Conveniently, this is the
   first element of the GOT. */
static inline ElfW(Addr) __attribute__ ((unused))
elf_machine_dynamic (void)
{
  ElfW(Addr) addr = (ElfW(Addr)) &_DYNAMIC;
  return addr;
}

This routine is only used early before rtld has relocated itself and is
expected to return the static link address of the .dynamic section. The
problem is that the above code generates a got entry + reloc for the
reference to &_DYNAMIC. When the rtld is prelinked, the early startup
code in rtld adds the load address to an already relocated value and
then segfaults as soon as it uses the bogus result.

I worked around this with:

diff --git a/ports/sysdeps/aarch64/dl-machine.h b/ports/sysdeps/aarch64/dl-machine.h
index 94f1108..f69c618 100644
--- a/ports/sysdeps/aarch64/dl-machine.h
+++ b/ports/sysdeps/aarch64/dl-machine.h
@@ -36,7 +36,14 @@ elf_machine_matches_host (const ElfW(Ehdr) *ehdr)
 static inline ElfW(Addr) __attribute__ ((unused))
 elf_machine_dynamic (void)
 {
-  ElfW(Addr) addr = (ElfW(Addr)) &_DYNAMIC;
+  ElfW(Addr) addr;
+
+  asm ("					\n\
+        ldr	%w0, 1f				\n\
+        b	2f                              \n\
+1:	 .word	_DYNAMIC			\n\
+2:						\n\
+       " : "=r" (addr));
   return addr;
 }
 
I suppose the prelink tool could work around this itself which would
allow it to work on all versions of glibc. Even in that case, the
above patch still saves an unnecessary got+reloc.

--Mark


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-06-26 16:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-24 16:41 aarch64 prelink issue Mark Salter
2013-06-24 17:18 ` Richard Henderson
2013-06-26 12:43   ` Mark Salter
2013-06-26 15:36     ` Marcus Shawcroft
2013-06-26 16:48       ` Richard Henderson

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).