rebuild the bink import library on every toolchain, not just cross ones

binkw32.lib as shipped is a long-format ordinal import library built in
2002, and link.exe is the only linker left that binds it. lld-link takes
it without complaint and writes an import descriptor with an empty thunk
table, so every Bink call reaches whatever the stale IAT slot holds. The
first one is BinkSoundUseDirectSound, reached from BinkInitialize during
EnterIntroScreen, which is unconditional -- Intro.cpp constructs its
VideoPlayer with VT_SMK|VT_BINK in every application, so a Smacker-only
gamedir still runs the Bink init path. The process dies before the splash
with an access violation executing an unmapped address.

clang-cl.cmake and mingw.cmake already rebuilt the library from
binkw32.def for exactly this reason, but they are toolchain files, so the
rebuild only happened when someone cross-compiled. Which linker is in use
is not a cross-compilation question: a preset that points
CMAKE_CXX_COMPILER at clang-cl -- how you use it from Visual Studio --
loads no toolchain file and linked the broken library instead. The test
was a proxy for "is this lld-link", correct until it wasn't.

So the rebuild moves to the top-level CMakeLists and runs unconditionally,
and clang-cl.cmake loses its copy: it already sets CMAKE_AR to llvm-lib,
which is the same binary the new code invokes with the same arguments.
mingw.cmake keeps its own, because GNU ar cannot build an import library
at all and dlltool takes different flags.

Only the name shape differs between archivers. lib.exe prepends the x86
leading underscore to every name in the .def; llvm-lib and llvm-dlltool
take the name as written. The checked-in file keeps the underscore for the
llvm tools and the MSVC path strips it back off.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Marco Antonio J. Costa
2026-07-28 07:13:52 -03:00
committed by majcosta
co-authored by Claude Opus 5
parent ee183510d3
commit 8b80466a7d
4 changed files with 40 additions and 26 deletions
+1 -14
View File
@@ -32,7 +32,7 @@ set(_sdk_lib "${MSVC_SDK}/kits/10/lib/${_sdk_version}")
# Find every tool here rather than trusting PATH, so the choice of compiler,
# linker and rc is the toolchain file's alone.
foreach(tool clang-cl lld-link llvm-rc llvm-lib llvm-mt llvm-dlltool)
foreach(tool clang-cl lld-link llvm-rc llvm-lib llvm-mt)
string(TOUPPER "${tool}" _variable)
string(REPLACE "-" "_" _variable "${_variable}")
# An absolute path: CMake resolves a bare name against the source directory.
@@ -76,16 +76,3 @@ set(CMAKE_RC_FLAGS_INIT "${_rc_flags}")
set(CMAKE_EXE_LINKER_FLAGS_INIT
"/libpath:${_msvc}/lib/x86 /libpath:${_sdk_lib}/ucrt/x86 /libpath:${_sdk_lib}/um/x86")
# lld-link cannot bind the Bink import library the game ships, so rebuild a
# bindable one from binkw32.def (which explains why) and hand it to the top-level
# CMakeLists through binkw32_lib. MSVC keeps using the shipped library.
execute_process(
COMMAND "${LLVM_DLLTOOL}" -m i386 --no-leading-underscore
-d "${CMAKE_CURRENT_LIST_DIR}/../../binkw32.def"
-l "${CMAKE_BINARY_DIR}/binkw32.lib"
RESULT_VARIABLE _binkw32DlltoolResult)
if(NOT _binkw32DlltoolResult EQUAL 0)
message(FATAL_ERROR "llvm-dlltool failed to build the binkw32 import library")
endif()
set(binkw32_lib "${CMAKE_BINARY_DIR}/binkw32.lib")
+1 -1
View File
@@ -30,7 +30,7 @@ set(CMAKE_CXX_COMPILER_TARGET ${triple})
# GNU ld cannot bind the Bink import library the game ships either, so rebuild a
# bindable one from binkw32.def (which explains why) and hand it to the top-level
# CMakeLists through binkw32_lib. MSVC keeps using the shipped library.
# CMakeLists through binkw32_lib.
execute_process(
COMMAND "${MINGW_DLLTOOL}" -m i386
-d "${CMAKE_CURRENT_LIST_DIR}/../../binkw32.def"