Skip to content

Commit e82b320

Browse files
committed
two of the three guards that would have excluded this target never arrive
mimalloc's prim-tls.h:176 enables `__builtin_thread_pointer()` for x86_64 with clang >= 14 unless `__APPLE__`, `__CYGWIN__` or `MI_LIBC_MUSL` says otherwise. Two of those three describe this target and neither reaches it: mcpp suppresses `__CYGWIN__` deliberately, because source must not read the realisation triple as a statement about Cygwin, and `MI_LIBC_MUSL` is a build option upstream expects the packager to set ("Enable this when linking with musl libc", CMakeLists.txt:39) rather than something it detects. So the guard passes and LLVM has no lowering for the builtin on this OS: fatal error: error in backend: Target OS doesn't support __builtin_thread_pointer() yet. which arrives as a backend crash with no source location, and reaches the compatibility results as the bare line "error: build failed". prim-tls.h:176 opens with `#if !defined(MI_USE_BUILTIN_THREAD_POINTER) /* allow user override */`, so the fix is to give it one. It goes in the Windows branch, where a Win32 target never reads it — `_WIN32` selects `NtCurrentTeb()` three arms earlier — so it changes only the target that has no `_WIN32`. Measured: `runs` on x86_64-windows-gnu and unchanged `runs` on x86_64-linux-gnu.
1 parent c1b4b3e commit e82b320

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎pkgs/c/compat.mimalloc.lua‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,30 @@ package = {
112112
runtime = {
113113
libraries = { "psapi", "shell32", "user32", "advapi32", "bcrypt" },
114114
},
115+
116+
-- `__builtin_thread_pointer()` IS NOT AVAILABLE FOR EVERY OS THE
117+
-- TRIPLE CAN NAME, AND THE FAILURE IS A BACKEND CRASH.
118+
--
119+
-- prim-tls.h:176 turns the builtin on for x86_64 with clang >= 14
120+
-- unless `__APPLE__`, `__CYGWIN__` or `MI_LIBC_MUSL` says
121+
-- otherwise. Two of those three would have excluded this target
122+
-- and neither reaches it: mcpp suppresses `__CYGWIN__` on purpose,
123+
-- because source must not read the realisation triple as a
124+
-- statement about Cygwin, and `MI_LIBC_MUSL` is a build option
125+
-- upstream expects the packager to set ("Enable this when linking
126+
-- with musl libc", CMakeLists.txt:39) rather than something it
127+
-- detects. So the guard passes, and LLVM has no lowering for the
128+
-- builtin on this OS:
129+
--
130+
-- fatal error: error in backend: Target OS doesn't support
131+
-- __builtin_thread_pointer() yet.
132+
--
133+
-- prim-tls.h:176 opens with `#if !defined(...) /* allow user
134+
-- override */`, so the answer is to give it one. This is the
135+
-- Windows branch, and on a Win32 target the setting is not read at
136+
-- all --- `_WIN32` selects `NtCurrentTeb()` three arms earlier ---
137+
-- so it changes only the target that has no `_WIN32`.
138+
cflags = { "-DMI_USE_BUILTIN_THREAD_POINTER=0" },
115139
},
116140
},
117141
}

0 commit comments

Comments
 (0)