diff options
author | Malcolm Bechard <malcolm@derivative.ca> | 2023-02-13 18:15:00 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-02-14 14:11:45 (GMT) |
commit | f513781bc51e99ceb003ac11c93639bb09e05cf4 (patch) | |
tree | d12e5b38cdc43816bdb7ac931343570decd89c1e | |
parent | 8a73af36b04723f1967c88d95f692c93f267b485 (diff) | |
download | CMake-f513781bc51e99ceb003ac11c93639bb09e05cf4.zip CMake-f513781bc51e99ceb003ac11c93639bb09e05cf4.tar.gz CMake-f513781bc51e99ceb003ac11c93639bb09e05cf4.tar.bz2 |
WINDOWS_EXPORT_ALL_SYMBOLS: Export vftable symbol
`pybind11` requires access to this symbol to link in some cases.
Include this symbol when generating automatic exports via
`CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS`.
Fixes: #24406
-rw-r--r-- | Source/bindexplib.cxx | 4 | ||||
-rw-r--r-- | Tests/RunCMake/AutoExportDll/hello.cxx | 9 | ||||
-rw-r--r-- | Tests/RunCMake/AutoExportDll/hello.h | 17 | ||||
-rw-r--r-- | Tests/RunCMake/AutoExportDll/say.cxx | 3 |
4 files changed, 32 insertions, 1 deletions
diff --git a/Source/bindexplib.cxx b/Source/bindexplib.cxx index 52e200c..7b74264 100644 --- a/Source/bindexplib.cxx +++ b/Source/bindexplib.cxx @@ -281,6 +281,7 @@ public: // the symbol const char* scalarPrefix = "??_G"; const char* vectorPrefix = "??_E"; + const char* vftablePrefix = "??_7"; // The original code had a check for // symbol.find("real@") == std::string::npos) // but this disallows member functions with the name "real". @@ -302,7 +303,8 @@ public: this->DataSymbols.insert(symbol); } else { if (pSymbolTable->Type || !(SectChar & IMAGE_SCN_MEM_READ) || - (SectChar & IMAGE_SCN_MEM_EXECUTE)) { + (SectChar & IMAGE_SCN_MEM_EXECUTE) || + (symbol.compare(0, 4, vftablePrefix) == 0)) { this->Symbols.insert(symbol); } } diff --git a/Tests/RunCMake/AutoExportDll/hello.cxx b/Tests/RunCMake/AutoExportDll/hello.cxx index 74e7a4e..35ccbb7 100644 --- a/Tests/RunCMake/AutoExportDll/hello.cxx +++ b/Tests/RunCMake/AutoExportDll/hello.cxx @@ -12,3 +12,12 @@ void hello() } void Hello::operator delete[](void*){}; void Hello::operator delete(void*){}; + +#ifdef HELLO_VFTABLE +HelloVFTable::HelloVFTable() +{ +} +HelloVFTable::~HelloVFTable() +{ +} +#endif diff --git a/Tests/RunCMake/AutoExportDll/hello.h b/Tests/RunCMake/AutoExportDll/hello.h index 7192f65..410ffab 100644 --- a/Tests/RunCMake/AutoExportDll/hello.h +++ b/Tests/RunCMake/AutoExportDll/hello.h @@ -16,3 +16,20 @@ public: static void operator delete[](void*); static void operator delete(void*); }; + +// In the MSVC ABI, a delegating constructor references the vftable. +#if __cplusplus >= 201103L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L) +# define HELLO_VFTABLE +#endif +#ifdef HELLO_VFTABLE +class HelloVFTable +{ +public: + HelloVFTable(); + HelloVFTable(int) + : HelloVFTable() + { + } + virtual ~HelloVFTable(); +}; +#endif diff --git a/Tests/RunCMake/AutoExportDll/say.cxx b/Tests/RunCMake/AutoExportDll/say.cxx index 8fc768a..a9459a9 100644 --- a/Tests/RunCMake/AutoExportDll/say.cxx +++ b/Tests/RunCMake/AutoExportDll/say.cxx @@ -53,5 +53,8 @@ int main() #ifdef HAS_JUSTNOP justnop(); #endif +#ifdef HELLO_VFTABLE + HelloVFTable helloVFTable(1); +#endif return 0; } |