dl-startup.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (C) 2013 Synopsys, Inc. (www.synopsys.com)
  3. *
  4. * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
  5. */
  6. /*
  7. * vineetg: Refactoring/cleanup of loader entry point
  8. * Removed 6 useless insns
  9. * Joern Improved it even further:
  10. * -better insn scheduling
  11. * -no need for conditional code for _dl_skip_args
  12. * -use of assembler .&2 expressions vs. @gotpc refs (avoids need for GP)
  13. *
  14. * What this code does:
  15. * -ldso starts execution here when kernel returns from execve()
  16. * -calls into generic ldso entry point _dl_start( )
  17. * -optionally adjusts argc for executable if exec passed as cmd
  18. * -calls into app main with address of finaliser
  19. */
  20. __asm__(
  21. ".section .text \n"
  22. ".align 4 \n"
  23. ".global _start \n"
  24. ".hidden _start \n"
  25. ".type _start,@function \n"
  26. "_start: \n"
  27. " ; ldso entry point, returns app entry point \n"
  28. " bl.d _dl_start \n"
  29. " mov_s r0, sp ; pass ptr to aux vector tbl \n"
  30. " ; If ldso ran as cmd with executable file nm as arg \n"
  31. " ; skip the extra args calc by dl_start() \n"
  32. " ld_s r1, [sp] ; orig argc from aux-vec Tbl \n"
  33. #ifdef __UCLIBC_HAS_THREADS_NATIVE__
  34. " ld r12, [pcl, _dl_skip_args@pcl] \n"
  35. " add r2, pcl, _dl_fini@pcl ; finalizer \n"
  36. #else
  37. " add r12, pcl, _dl_skip_args-.+(.&2) \n"
  38. " ld r12, [r12] \n"
  39. " add r2, pcl, _dl_fini-.+(.&2) ; finalizer \n"
  40. #endif
  41. " add2 sp, sp, r12 ; discard argv entries from stack\n"
  42. " sub_s r1, r1, r12 ; adjusted argc, on stack \n"
  43. " st_s r1, [sp] \n"
  44. " j_s.d [r0] ; app entry point \n"
  45. " mov_s r0, r2 ; ptr to finalizer _dl_fini \n"
  46. ".size _start,.-_start \n"
  47. ".previous \n"
  48. );
  49. /*
  50. * Get a pointer to the argv array. On many platforms this can be just
  51. * the address if the first argument, on other platforms we need to
  52. * do something a little more subtle here.
  53. */
  54. #define GET_ARGV(ARGVP, ARGS) ARGVP = ((unsigned long*) ARGS + 1)
  55. /*
  56. * Dynamic loader bootstrapping:
  57. * The only relocations that should be found are either R_ARC_RELATIVE for
  58. * data relocations (.got, etc) or R_ARC_JMP_SLOT for code relocations
  59. * (.plt). It is safe to assume that all of these relocations are word
  60. * aligned.
  61. * @RELP is the reloc entry being processed
  62. * @REL is the pointer to the address we are relocating.
  63. * @SYMBOL is the symbol involved in the relocation
  64. * @LOAD is the load address.
  65. */
  66. #define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD,SYMTAB) \
  67. do { \
  68. int type = ELF32_R_TYPE((RELP)->r_info); \
  69. if (likely(type == R_ARC_RELATIVE)) \
  70. *REL += (unsigned long) LOAD; \
  71. else if (type == R_ARC_JMP_SLOT) \
  72. *REL = SYMBOL; \
  73. else \
  74. _dl_exit(1); \
  75. }while(0)
  76. /*
  77. * This will go away once we have DT_RELACOUNT
  78. */
  79. #define ARCH_NEEDS_BOOTSTRAP_RELOCS
  80. /* we dont need to spit out argc, argv etc for debugging */
  81. #define NO_EARLY_SEND_STDERR 1