pt-initfini.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* Special .init and .fini section support. Linuxthread version.
  2. Copyright (C) 1995, 1996, 1997, 2000, 2001 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it
  5. and/or modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. In addition to the permissions in the GNU Lesser General Public
  9. License, the Free Software Foundation gives you unlimited
  10. permission to link the compiled version of this file with other
  11. programs, and to distribute those programs without any restriction
  12. coming from the use of this file. (The Lesser General Public
  13. License restrictions do apply in other respects; for example, they
  14. cover modification of the file, and distribution when not linked
  15. into another program.)
  16. The GNU C Library is distributed in the hope that it will be
  17. useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  18. of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU Lesser General Public License for more details.
  20. You should have received a copy of the GNU Lesser General Public
  21. License along with the GNU C Library; see the file COPYING.LIB. If not,
  22. write to the Free Software Foundation, 59 Temple Place - Suite 330,
  23. Boston, MA 02111-1307, USA. */
  24. /* This file is compiled into assembly code which is then munged by a sed
  25. script into two files: crti.s and crtn.s.
  26. * crti.s puts a function prologue at the beginning of the
  27. .init and .fini sections and defines global symbols for
  28. those addresses, so they can be called as functions.
  29. * crtn.s puts the corresponding function epilogues
  30. in the .init and .fini sections. */
  31. #include <stdlib.h>
  32. /* We use embedded asm for .section unconditionally, as this makes it
  33. easier to insert the necessary directives into crtn.S. */
  34. #define SECTION(x) __asm__ (".section " x )
  35. /* Embed an #include to pull in the alignment and .end directives. */
  36. __asm__ ("\n#include \"defs.h\"");
  37. /* The initial common code ends here. */
  38. __asm__ ("\n/*@HEADER_ENDS*/");
  39. /* To determine whether we need .end and .align: */
  40. __asm__ ("\n/*@TESTS_BEGIN*/");
  41. extern void dummy (void (*foo) (void));
  42. void
  43. dummy (void (*foo) (void))
  44. {
  45. if (foo)
  46. (*foo) ();
  47. }
  48. __asm__ ("\n/*@TESTS_END*/");
  49. /* The beginning of _init: */
  50. __asm__ ("\n/*@_init_PROLOG_BEGINS*/");
  51. static void
  52. call_initialize_minimal (void)
  53. {
  54. extern void __pthread_initialize_minimal (void);
  55. __pthread_initialize_minimal ();
  56. }
  57. SECTION (".init");
  58. extern void _init (void);
  59. void
  60. _init (void)
  61. {
  62. /* The very first thing we must do is to set up the registers. */
  63. call_initialize_minimal ();
  64. __asm__ ("ALIGN");
  65. __asm__("END_INIT");
  66. /* Now the epilog. */
  67. __asm__ ("\n/*@_init_PROLOG_ENDS*/");
  68. __asm__ ("\n/*@_init_EPILOG_BEGINS*/");
  69. SECTION(".init");
  70. }
  71. __asm__ ("END_INIT");
  72. /* End of the _init epilog, beginning of the _fini prolog. */
  73. __asm__ ("\n/*@_init_EPILOG_ENDS*/");
  74. __asm__ ("\n/*@_fini_PROLOG_BEGINS*/");
  75. SECTION (".fini");
  76. extern void _fini (void);
  77. void
  78. _fini (void)
  79. {
  80. /* End of the _fini prolog. */
  81. __asm__ ("ALIGN");
  82. __asm__ ("END_FINI");
  83. __asm__ ("\n/*@_fini_PROLOG_ENDS*/");
  84. {
  85. /* Let GCC know that _fini is not a leaf function by having a dummy
  86. function call here. We arrange for this call to be omitted from
  87. either crt file. */
  88. extern void i_am_not_a_leaf (void);
  89. i_am_not_a_leaf ();
  90. }
  91. /* Beginning of the _fini epilog. */
  92. __asm__ ("\n/*@_fini_EPILOG_BEGINS*/");
  93. SECTION (".fini");
  94. }
  95. __asm__ ("END_FINI");
  96. /* End of the _fini epilog. Any further generated assembly (e.g. .ident)
  97. is shared between both crt files. */
  98. __asm__ ("\n/*@_fini_EPILOG_ENDS*/");
  99. __asm__ ("\n/*@TRAILER_BEGINS*/");
  100. /* End of file. */