code_junkie

C++ ctor question (linux)

Nov 13th, 2011
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. constructor (priority)
  2.  
  3. constructor (priority)
  4.  
  5. constructor (priority)
  6.  
  7. .ctors :
  8. {
  9. /* gcc uses crtbegin.o to find the start of
  10. the constructors, so we make sure it is
  11. first. Because this is a wildcard, it
  12. doesn't matter if the user does not
  13. actually link against crtbegin.o; the
  14. linker won't look for a file to match a
  15. wildcard. The wildcard also means that it
  16. doesn't matter which directory crtbegin.o
  17. is in. */
  18. KEEP (*crtbegin.o(.ctors))
  19. KEEP (*crtbegin?.o(.ctors))
  20. /* We don't want to include the .ctor section from
  21. the crtend.o file until after the sorted ctors.
  22. The .ctor section from the crtend file contains the
  23. end of ctors marker and it must be last */
  24. KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
  25. KEEP (*(SORT(.ctors.*)))
  26. KEEP (*(.ctors))
  27. }
  28.  
  29. func_ptr *p;
  30. for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
  31. (*p) ();
  32.  
  33. void dothat() { }
  34. struct f {
  35. f() { dothat(); }
  36. } f_;
  37. void doit() __attribute__((constructor (0)));
  38. void doit() { }
  39. int main() { }
  40.  
  41. .ctors 0x080494f4 0x10
  42. *crtbegin.o(.ctors)
  43. .ctors 0x080494f4 0x4 /usr/lib/gcc/i686-pc-linux-gnu/4.3.2/crtbegin.o
  44. *crtbegin?.o(.ctors)
  45. *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
  46. .ctors 0x080494f8 0x4 /tmp/ccyzWBjs.o
  47. *(SORT(.ctors.*))
  48. .ctors.65535 0x080494fc 0x4 /tmp/ccyzWBjs.o
  49. *(.ctors)
  50. .ctors 0x08049500 0x4 /usr/lib/gcc/i686-pc-linux-gnu/4.3.2/crtend.o
  51.  
  52. E.g Mixing: int p [] = { 1,2,3 };
  53. And: extern int * p;
Add Comment
Please, Sign In to add comment