about summary refs log tree commit diff
path: root/sysdeps/x86_64/dl-machine.h
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2004-12-22 20:10:10 +0000
committerUlrich Drepper <drepper@redhat.com>2004-12-22 20:10:10 +0000
commita334319f6530564d22e775935d9c91663623a1b4 (patch)
treeb5877475619e4c938e98757d518bb1e9cbead751 /sysdeps/x86_64/dl-machine.h
parent0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (diff)
downloadglibc-a334319f6530564d22e775935d9c91663623a1b4.tar.gz
glibc-a334319f6530564d22e775935d9c91663623a1b4.tar.xz
glibc-a334319f6530564d22e775935d9c91663623a1b4.zip
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
Diffstat (limited to 'sysdeps/x86_64/dl-machine.h')
-rw-r--r--sysdeps/x86_64/dl-machine.h176
1 files changed, 145 insertions, 31 deletions
diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
index 73e271775a..b932f51d15 100644
--- a/sysdeps/x86_64/dl-machine.h
+++ b/sysdeps/x86_64/dl-machine.h
@@ -1,5 +1,5 @@
 /* Machine-dependent ELF dynamic relocation inline functions.  x86-64 version.
-   Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Andreas Jaeger <aj@suse.de>.
 
@@ -55,7 +55,7 @@ elf_machine_dynamic (void)
 static inline Elf64_Addr __attribute__ ((unused))
 elf_machine_load_address (void)
 {
-  Elf64_Addr addr;
+  register Elf64_Addr addr, tmp;
 
   /* The easy way is just the same as on x86:
        leaq _dl_start, %0
@@ -66,18 +66,15 @@ elf_machine_load_address (void)
 
      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 ("leaq _dl_start(%%rip), %0\n\t"
-       "subq 1f(%%rip), %0\n\t"
-       ".section\t.data.rel.ro\n"
+     an RIP relative addressing mode.  */
+
+  asm ("movq 1f(%%rip), %1\n"
+       "0:\tleaq _dl_start(%%rip), %0\n\t"
+       "subq %1, %0\n\t"
+       ".section\t.data\n"
        "1:\t.quad _dl_start\n\t"
        ".previous\n\t"
-       : "=r" (addr) : : "cc");
+       : "=r" (addr), "=r" (tmp) : : "cc");
 
   return addr;
 }
@@ -119,8 +116,7 @@ elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
 	{
 	  got[2] = (Elf64_Addr) &_dl_runtime_profile;
 
-	  if (GLRO(dl_profile) != NULL
-	      && _dl_name_match_p (GLRO(dl_profile), l))
+	  if (_dl_name_match_p (GLRO(dl_profile), l))
 	    /* This is the object we are looking for.  Say that we really
 	       want profiling and the timers are started.  */
 	    GL(dl_profile_map) = l;
@@ -134,6 +130,128 @@ elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
   return lazy;
 }
 
+/* This code is used in dl-runtime.c to call the `fixup' function
+   and then redirect to the address it returns.  */
+#ifndef PROF
+# define ELF_MACHINE_RUNTIME_TRAMPOLINE asm ("\n\
+	.text\n\
+	.globl _dl_runtime_resolve\n\
+	.type _dl_runtime_resolve, @function\n\
+	.align 16\n\
+	" CFI_STARTPROC "\n\
+_dl_runtime_resolve:\n\
+	subq $56,%rsp\n\
+	" CFI_ADJUST_CFA_OFFSET(72)" # Incorporate PLT\n\
+	movq %rax,(%rsp)	# Preserve registers otherwise clobbered.\n\
+	movq %rcx,8(%rsp)\n\
+	movq %rdx,16(%rsp)\n\
+	movq %rsi,24(%rsp)\n\
+	movq %rdi,32(%rsp)\n\
+	movq %r8,40(%rsp)\n\
+	movq %r9,48(%rsp)\n\
+	movq 64(%rsp), %rsi	# Copy args pushed by PLT in register.\n\
+	movq %rsi,%r11		# Multiply by 24\n\
+	addq %r11,%rsi\n\
+	addq %r11,%rsi\n\
+	shlq $3, %rsi\n\
+	movq 56(%rsp), %rdi	# %rdi: link_map, %rsi: reloc_offset\n\
+	call fixup		# Call resolver.\n\
+	movq %rax, %r11		# Save return value\n\
+	movq 48(%rsp),%r9	# Get register content back.\n\
+	movq 40(%rsp),%r8\n\
+	movq 32(%rsp),%rdi\n\
+	movq 24(%rsp),%rsi\n\
+	movq 16(%rsp),%rdx\n\
+	movq 8(%rsp),%rcx\n\
+	movq (%rsp),%rax\n\
+	addq $72,%rsp		# Adjust stack(PLT did 2 pushes)\n\
+	" CFI_ADJUST_CFA_OFFSET(-72)" \n\
+	jmp *%r11		# Jump to function address.\n\
+	" CFI_ENDPROC "\n\
+	.size _dl_runtime_resolve, .-_dl_runtime_resolve\n\
+\n\
+	.globl _dl_runtime_profile\n\
+	.type _dl_runtime_profile, @function\n\
+	.align 16\n\
+	" CFI_STARTPROC "\n\
+_dl_runtime_profile:\n\
+	subq $56,%rsp\n\
+	" CFI_ADJUST_CFA_OFFSET(72)" # Incorporate PLT\n\
+	movq %rax,(%rsp)	# Preserve registers otherwise clobbered.\n\
+	movq %rcx,8(%rsp)\n\
+	movq %rdx,16(%rsp)\n\
+	movq %rsi,24(%rsp)\n\
+	movq %rdi,32(%rsp)\n\
+	movq %r8,40(%rsp)\n\
+	movq %r9,48(%rsp)\n\
+	movq 72(%rsp), %rdx	# Load return address if needed\n\
+	movq 64(%rsp), %rsi	# Copy args pushed by PLT in register.\n\
+	movq %rsi,%r11		# Multiply by 24\n\
+	addq %r11,%rsi\n\
+	addq %r11,%rsi\n\
+	shlq $3, %rsi\n\
+	movq 56(%rsp), %rdi	# %rdi: link_map, %rsi: reloc_offset\n\
+	call profile_fixup	# Call resolver.\n\
+	movq %rax, %r11		# Save return value\n\
+	movq 48(%rsp),%r9	# Get register content back.\n\
+	movq 40(%rsp),%r8\n\
+	movq 32(%rsp),%rdi\n\
+	movq 24(%rsp),%rsi\n\
+	movq 16(%rsp),%rdx\n\
+	movq 8(%rsp),%rcx\n\
+	movq (%rsp),%rax\n\
+	addq $72,%rsp		# Adjust stack\n\
+	" CFI_ADJUST_CFA_OFFSET(-72)"\n\
+	jmp *%r11		# Jump to function address.\n\
+	" CFI_ENDPROC "\n\
+	.size _dl_runtime_profile, .-_dl_runtime_profile\n\
+	.previous\n\
+");
+#else
+# define ELF_MACHINE_RUNTIME_TRAMPOLINE asm ("\n\
+	.text\n\
+	.globl _dl_runtime_resolve\n\
+	.globl _dl_runtime_profile\n\
+	.type _dl_runtime_resolve, @function\n\
+	.type _dl_runtime_profile, @function\n\
+	.align 16\n\
+	" CFI_STARTPROC "\n\
+_dl_runtime_resolve:\n\
+_dl_runtime_profile:\n\
+	subq $56,%rsp\n\
+	" CFI_ADJUST_CFA_OFFSET(72)" # Incorporate PLT\n\
+	movq %rax,(%rsp)	# Preserve registers otherwise clobbered.\n\
+	movq %rcx,8(%rsp)\n\
+	movq %rdx,16(%rsp)\n\
+	movq %rsi,24(%rsp)\n\
+	movq %rdi,32(%rsp)\n\
+	movq %r8,40(%rsp)\n\
+	movq %r9,48(%rsp)\n\
+	movq 64(%rsp), %rsi	# Copy args pushed by PLT in register.\n\
+	movq %rsi,%r11		# Multiply by 24\n\
+	addq %r11,%rsi\n\
+	addq %r11,%rsi\n\
+	shlq $3, %rsi\n\
+	movq 56(%rsp), %rdi	# %rdi: link_map, %rsi: reloc_offset\n\
+	call fixup		# Call resolver.\n\
+	movq %rax, %r11		# Save return value\n\
+	movq 48(%rsp),%r9	# Get register content back.\n\
+	movq 40(%rsp),%r8\n\
+	movq 32(%rsp),%rdi\n\
+	movq 24(%rsp),%rsi\n\
+	movq 16(%rsp),%rdx\n\
+	movq 8(%rsp),%rcx\n\
+	movq (%rsp),%rax\n\
+	addq $72,%rsp		# Adjust stack\n\
+	" CFI_ADJUST_CFA_OFFSET(-72)"\n\
+	jmp *%r11		# Jump to function address.\n\
+	" CFI_ENDPROC "\n\
+	.size _dl_runtime_resolve, .-_dl_runtime_resolve\n\
+	.size _dl_runtime_profile, .-_dl_runtime_profile\n\
+	.previous\n\
+");
+#endif
+
 /* Initial entry point code for the dynamic linker.
    The C function `_dl_start' is the real entry point;
    its return value is the user program's entry point.  */
@@ -162,24 +280,16 @@ _dl_start_user:\n\
 	# Call _dl_init (struct link_map *main_map, int argc, char **argv, char **env)\n\
 	# argc -> rsi\n\
 	movq %rdx, %rsi\n\
-	# Save %rsp value in %r13.\n\
-	movq %rsp, %r13\n\
-	# And align stack for the _dl_init_internal call. \n\
-	andq $-16, %rsp\n\
 	# _dl_loaded -> rdi\n\
 	movq _rtld_local(%rip), %rdi\n\
 	# env -> rcx\n\
-	leaq 16(%r13,%rdx,8), %rcx\n\
+	leaq 16(%rsp,%rdx,8), %rcx\n\
 	# argv -> rdx\n\
-	leaq 8(%r13), %rdx\n\
-	# Clear %rbp to mark outermost frame obviously even for constructors.\n\
-	xorl %ebp, %ebp\n\
+	leaq 8(%rsp), %rdx\n\
 	# Call the function to run the initializers.\n\
 	call _dl_init_internal@PLT\n\
 	# Pass our finalizer function to the user in %rdx, as per ELF ABI.\n\
 	leaq _dl_fini(%rip), %rdx\n\
-	# And make sure %rsp points to argc stored on the stack.\n\
-	movq %r13, %rsp\n\
 	# Jump to the user's entry point.\n\
 	jmp *%r12\n\
 .previous\n\
@@ -238,14 +348,9 @@ elf_machine_plt_value (struct link_map *map, const Elf64_Rela *reloc,
   return value;
 }
 
-
-/* Names of the architecture-specific auditing callback functions.  */
-#define ARCH_LA_PLTENTER x86_64_gnu_pltenter
-#define ARCH_LA_PLTEXIT x86_64_gnu_pltexit
-
 #endif /* !dl_machine_h */
 
-#ifdef RESOLVE_MAP
+#ifdef RESOLVE
 
 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
    MAP is the object containing the reloc.  */
@@ -285,9 +390,18 @@ elf_machine_rela (struct link_map *map, const Elf64_Rela *reloc,
 #ifndef RTLD_BOOTSTRAP
       const Elf64_Sym *const refsym = sym;
 #endif
+#if defined USE_TLS && !defined RTLD_BOOTSTRAP
       struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
       Elf64_Addr value = (sym == NULL ? 0
 			  : (Elf64_Addr) sym_map->l_addr + sym->st_value);
+#else
+      Elf64_Addr value = RESOLVE (&sym, version, r_type);
+
+# ifndef RTLD_BOOTSTRAP
+      if (sym != NULL)
+# endif
+	value += sym->st_value;
+#endif
 
 #if defined RTLD_BOOTSTRAP && !USE___THREAD
       assert (r_type == R_X86_64_GLOB_DAT || r_type == R_X86_64_JUMP_SLOT);
@@ -439,4 +553,4 @@ elf_machine_lazy_rel (struct link_map *map,
     _dl_reloc_bad_type (map, r_type, 1);
 }
 
-#endif /* RESOLVE_MAP */
+#endif /* RESOLVE */