dl-startup.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Architecture specific code used by dl-startup.c
  4. * Copyright (C) 2000-2005 by Erik Andersen <andersen@codepoet.org>
  5. * Copyright (C) 2005 by Mike Frysinger <vapier@gentoo.org>
  6. *
  7. * Parts taken from glibc/sysdeps/x86_64/dl-machine.h
  8. */
  9. __asm__ (
  10. " .text\n"
  11. " .global _start\n"
  12. " .type _start,%function\n"
  13. " .hidden _start\n"
  14. "_start:\n"
  15. " movq %rsp, %rdi\n"
  16. " call _dl_start\n"
  17. " # Save the user entry point address in %r12.\n"
  18. " movq %rax, %r12\n"
  19. " # See if we were run as a command with the executable file\n"
  20. " # name as an extra leading argument.\n"
  21. " movl _dl_skip_args(%rip), %eax\n"
  22. " # Pop the original argument count.\n"
  23. " popq %rdx\n"
  24. " # Adjust the stack pointer to skip _dl_skip_args words.\n"
  25. " leaq (%rsp,%rax,8), %rsp\n"
  26. " # Subtract _dl_skip_args from argc.\n"
  27. " subl %eax, %edx\n"
  28. " # Push argc back on the stack.\n"
  29. " pushq %rdx\n"
  30. " # Pass our finalizer function to the user in %rdx, as per ELF ABI.\n"
  31. " leaq _dl_fini(%rip), %rdx\n"
  32. " # Jump to the user's entry point.\n"
  33. " jmp *%r12\n"
  34. " .size _start,.-_start\n"
  35. " .previous\n"
  36. );
  37. /* Get a pointer to the argv array. On many platforms this can be just
  38. * the address of the first argument, on other platforms we need to
  39. * do something a little more subtle here. */
  40. #define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long*) ARGS)+1)
  41. /* Handle relocation of the symbols in the dynamic loader. */
  42. static __always_inline
  43. void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, ElfW(Addr) *reloc_addr,
  44. ElfW(Addr) symbol_addr, ElfW(Addr) load_addr, ElfW(Sym) *sym)
  45. {
  46. switch (ELF_R_TYPE(rpnt->r_info)) {
  47. case R_X86_64_GLOB_DAT:
  48. case R_X86_64_JUMP_SLOT:
  49. *reloc_addr = symbol_addr + rpnt->r_addend;
  50. break;
  51. case R_X86_64_DTPMOD64:
  52. *reloc_addr = 1;
  53. break;
  54. case R_X86_64_NONE:
  55. case R_X86_64_DTPOFF64:
  56. break;
  57. case R_X86_64_TPOFF64:
  58. *reloc_addr = sym->st_value + rpnt->r_addend - symbol_addr;
  59. break;
  60. /*TODO: case R_X86_64_RELATIVE:
  61. *reloc_addr = load_addr + rpnt->r_addend;
  62. break; */
  63. default:
  64. _dl_exit(1);
  65. }
  66. }