Skip to content

Commit

Permalink
build: Add support for Clang-CL
Browse files Browse the repository at this point in the history
  • Loading branch information
lhmouse committed Nov 15, 2024
1 parent 8d5c31b commit f436c95
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
20 changes: 12 additions & 8 deletions mcfgthread/gthr_aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,25 @@ __MCF_gthr_do_call_once_seh_take_over(_MCF_once* once, __MCF_cxa_dtor_any_ init_
" push esi \n"
" push ebp \n"
" mov ebp, esp \n"
/* Install an SEH handler. */
" sub esp, 20 \n"
/* Initialize the constant zero. */
" xor esi, esi \n"
" push OFFSET _do_call_once_seh_uhandler \n"
" push fs:[esi] \n"
" mov fs:[esi], esp \n"
/* Install an SEH handler. */
" mov eax, fs:[esi] \n"
" lea ecx, [ebp - 8] \n"
" mov [ecx], eax \n"
" mov eax, OFFSET _do_call_once_seh_uhandler \n"
" mov [ecx + 4], eax \n"
" mov fs:[esi], ecx \n"
/* Make the call `(*init_proc) (arg)`. The argument is passed
* both via the ECX register and on the stack, to allow both
* `__cdecl` and `__thiscall` functions to work properly. */
" mov ecx, [ebp + 20] \n"
" sub esp, 8 \n"
" push ecx \n"
" mov [ebp - 20], ecx \n"
" call [ebp + 16] \n"
" add esp, 12 \n"
/* Dismantle the SEH handler. */
" pop fs:[esi] \n"
" mov eax, [ebp - 8] \n"
" mov fs:[esi], eax \n"
/* Disarm the once flag with a tail call. */
" leave \n"
" pop esi \n"
Expand Down
12 changes: 9 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,15 @@ mcfgthread_version_o = import('windows').compile_resources(
lib_mcfgthread_c_args = [
'-ffreestanding', '-fasynchronous-unwind-tables' ]

lib_mcfgthread_dll_link_args = [
'-nostdlib', '-Wl,-enable-auto-image-base', '-Wl,-subsystem,windows:6.1',
'-Wl,-exclude-all-symbols', '-Wl,-kill-at', '-Wl,-gc-sections' ]
if cc.get_linker_id() in [ 'link', 'lld-link' ]
lib_mcfgthread_dll_link_args = [
'-Wl,-nodefaultlib', '-Wl,-dynamicbase', '-Wl,-opt:ref', '-Wl,-opt:icf',
'-Xlinker', '-subsystem:windows,6.1' ]
else
lib_mcfgthread_dll_link_args = [
'-nostdlib', '-Wl,-enable-auto-image-base', '-Wl,-gc-sections',
'-Wl,-subsystem,windows:6.1', '-Wl,-exclude-all-symbols', '-Wl,-kill-at' ]
endif

lib_mcfgthread_minimal_dll = shared_library('mcfgthread-minimal',
c_pch: 'mcfgthread/xprecompiled.h',
Expand Down
9 changes: 9 additions & 0 deletions meson.native.clang-cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[built-in options]
cpp_std = 'c++14'

[binaries]
c = 'clang'
cpp = 'clang++'
ar = 'llvm-ar'
strip = 'llvm-strip'
windres = 'llvm-rc'

0 comments on commit f436c95

Please sign in to comment.