vtv_stubs.cc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Copyright (C) 2012-2022 Free Software Foundation, Inc.
  2. //
  3. // This file is part of the GNU ISO C++ Library. This library is free
  4. // software; you can redistribute it and/or modify it under the
  5. // terms of the GNU General Public License as published by the
  6. // Free Software Foundation; either version 3, or (at your option)
  7. // any later version.
  8. // This library is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. // Under Section 7 of GPL version 3, you are granted additional
  13. // permissions described in the GCC Runtime Library Exception, version
  14. // 3.1, as published by the Free Software Foundation.
  15. // You should have received a copy of the GNU General Public License and
  16. // a copy of the GCC Runtime Library Exception along with this program;
  17. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. // <http://www.gnu.org/licenses/>.
  19. /* This is part of the vtable verification runtime library. For more
  20. information about this feature, see the comments in libvtv/vtv_rts.cc. */
  21. /* The functions in this file are used to create the libvtv_stubs
  22. library, as part of the vtable verification feature. When building
  23. a binary without vtable verification, and linking it with a
  24. (possibly pre-built third-party) library that was built with
  25. verification, it is possible that vtable verification will fail due
  26. to incomplete data (rather than due to corrupt vtable pointers). In
  27. this case we need to give programmers a way of turning off the
  28. vtable verification in their libraries. They can do so by linking
  29. with the libvtv_stubs library, which (as you can see) will replace
  30. the real verification functions with a set of functions that do
  31. nothing (so no more verification failures/aborts). */
  32. #include <cstddef>
  33. /* weak symbols on Windows work differently than on Linux. To be able
  34. to switch vtv on and off on Windows two dlls are built. One with
  35. the sources from libvtv, the other from these stubs. Depending on
  36. which dll is placed in the folder of the executable the functions
  37. from libvtv or the stubs functions are used. */
  38. #if defined (__CYGWIN__) || defined (__MINGW32__)
  39. extern "C"
  40. void
  41. __VLTChangePermission(int);
  42. void
  43. __VLTRegisterSet(void**, const void*, std::size_t, std::size_t,
  44. void**);
  45. void
  46. __VLTRegisterPair(void**, const void*, std::size_t,
  47. const void*);
  48. const void*
  49. __VLTVerifyVtablePointer(void**, const void*);
  50. void
  51. __VLTRegisterSetDebug(void**, const void*, std::size_t, std::size_t,
  52. void**);
  53. void
  54. __VLTRegisterPairDebug(void**, const void*, std::size_t, const void*,
  55. const char*, const char*);
  56. const void*
  57. __VLTVerifyVtablePointerDebug(void**, const void*, const char*,
  58. const char*);
  59. #else
  60. // Declare as weak for libsupc++, strong definitions are in libvtv.
  61. #if __GXX_WEAK__
  62. extern "C"
  63. void
  64. __VLTChangePermission(int) __attribute__((weak));
  65. void
  66. __VLTRegisterSet(void**, const void*, std::size_t, std::size_t,
  67. void**) __attribute__((weak));
  68. void
  69. __VLTRegisterPair(void**, const void*, std::size_t,
  70. const void*) __attribute__((weak));
  71. const void*
  72. __VLTVerifyVtablePointer(void**, const void*) __attribute__((weak));
  73. void
  74. __VLTRegisterSetDebug(void**, const void*, std::size_t, std::size_t,
  75. void**) __attribute__((weak));
  76. void
  77. __VLTRegisterPairDebug(void**, const void*, std::size_t, const void*,
  78. const char*, const char*) __attribute__((weak));
  79. const void*
  80. __VLTVerifyVtablePointerDebug(void**, const void*, const char*,
  81. const char*) __attribute__((weak));
  82. #endif
  83. #endif
  84. // Stub definitions.
  85. extern "C"
  86. void
  87. __VLTChangePermission(int)
  88. { }
  89. void
  90. __VLTRegisterSet(void**, const void*, std::size_t, std::size_t, void**)
  91. { }
  92. void
  93. __VLTRegisterPair(void**, const void*, std::size_t, const void*)
  94. { }
  95. const void*
  96. __VLTVerifyVtablePointer(void**, const void* vtable_ptr)
  97. { return vtable_ptr; }
  98. void
  99. __VLTRegisterSetDebug(void**, const void*, std::size_t, std::size_t, void**)
  100. { }
  101. void
  102. __VLTRegisterPairDebug(void**, const void*, std::size_t, const void*,
  103. const char*, const char*)
  104. { }
  105. const void*
  106. __VLTVerifyVtablePointerDebug(void**, const void* vtable_ptr, const char*,
  107. const char*)
  108. { return vtable_ptr; }