mD.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include <cstdlib>
  2. #include <cstdio>
  3. #include <iostream>
  4. static void
  5. bye_main()
  6. {
  7. std::cout << "mD " << __FUNCTION__ << std::endl;
  8. }
  9. static void
  10. bye_setup()
  11. {
  12. std::cout << "mD " << __FUNCTION__ << std::endl;
  13. }
  14. static void
  15. bye_func()
  16. {
  17. std::cout << "mD " << __FUNCTION__ << std::endl;
  18. }
  19. void
  20. func3() __attribute__((__import_module__("mE"), __import_name__("func1")));
  21. void
  22. func4() __attribute__((__import_module__("mE"), __import_name__("func2")));
  23. void
  24. func1()
  25. {
  26. std::printf("mD %s\n", __FUNCTION__);
  27. if (std::atexit(bye_func) != 0) {
  28. std::perror("register an atexit handler failed");
  29. }
  30. func3();
  31. }
  32. void
  33. func2()
  34. {
  35. std::printf("mD %s\n", __FUNCTION__);
  36. func4();
  37. }
  38. __attribute__((constructor)) void
  39. setup()
  40. {
  41. std::cout << "mD " << __FUNCTION__ << std::endl;
  42. if (std::atexit(bye_setup) != 0) {
  43. std::perror("register an atexit handler failed");
  44. }
  45. }
  46. __attribute__((destructor)) void
  47. teardown()
  48. {
  49. std::cout << "mD " << __FUNCTION__ << std::endl;
  50. }
  51. int
  52. main()
  53. {
  54. std::printf("mD %s\n", __FUNCTION__);
  55. if (std::atexit(bye_main) != 0) {
  56. std::perror("register an atexit handler failed");
  57. return EXIT_FAILURE;
  58. }
  59. func1();
  60. func2();
  61. return EXIT_SUCCESS;
  62. }