dl-startup.h 2.0 KB

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