Skip to content

Commit ad6406c

Browse files
ashvardanianWX\shixiCrazyboyQCD
authored
Fix: Dispatch table initialization on MSVC (#180)
Closes #178 --------- Co-authored-by: WX\shixi <[email protected]> Co-authored-by: CrazyboyQCD <[email protected]>
2 parents cc88ada + c7235f8 commit ad6406c

File tree

1 file changed

+2
-19
lines changed

1 file changed

+2
-19
lines changed

c/lib.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
* @date January 16, 2024
66
* @copyright Copyright (c) 2024
77
*/
8-
#if defined(_WIN32) || defined(__CYGWIN__)
9-
#include <windows.h> // `DllMain`
10-
#endif
118

129
// When enabled, this library will override the symbols usually provided by the C standard library.
1310
// It's handy if you want to use the `LD_PRELOAD` trick for non-intrusive profiling and replacing
@@ -232,22 +229,8 @@ static void sz_dispatch_table_init(void) {
232229
}
233230

234231
#if defined(_MSC_VER)
235-
BOOL WINAPI DllMain(HINSTANCE hints, DWORD forward_reason, LPVOID lp) {
236-
switch (forward_reason) {
237-
case DLL_PROCESS_ATTACH: sz_dispatch_table_init(); return TRUE;
238-
case DLL_THREAD_ATTACH: return TRUE;
239-
case DLL_THREAD_DETACH: return TRUE;
240-
case DLL_PROCESS_DETACH: return TRUE;
241-
}
242-
}
243-
244-
#if SZ_AVOID_LIBC
245-
BOOL WINAPI _DllMainCRTStartup(HINSTANCE hints, DWORD forward_reason, LPVOID lp) {
246-
DllMain(hints, forward_reason, lp);
247-
return TRUE;
248-
}
249-
#endif
250-
232+
#pragma section(".CRT$XCU", read)
233+
__declspec(allocate(".CRT$XCU")) void (*_sz_dispatch_table_init)() = sz_dispatch_table_init;
251234
#else
252235
__attribute__((constructor)) static void sz_dispatch_table_init_on_gcc_or_clang(void) { sz_dispatch_table_init(); }
253236
#endif

0 commit comments

Comments
 (0)