Skip to content

MinGW: support building with the Clang/lld toolchain - #5

Open
maleadt wants to merge 1 commit into
mainfrom
tb/mingw-clang-lld
Open

maleadt wants to merge 1 commit into
mainfrom
tb/mingw-clang-lld

Conversation

@maleadt

@maleadt maleadt commented Oct 26, 2026

Copy link
Copy Markdown
Member

Lets libpocl be built for MinGW with the Clang/lld toolchain. GNU ld takes tens of minutes to link the static LLVM/Clang archives into a PE/COFF DLL; ld.lld is much faster, but its COFF driver lacks --exclude-libs, which libpocl used to keep the static libraries' symbols out of its auto-generated export table. Auto-exporting all of LLVM overflows the 64K PE export-ordinal limit.

MinGW now uses the MSVC-style export model, which works with both GNU ld and lld: __declspec(dllexport) on the OpenCL API for any Windows toolchain, EXPORT_POCL_LIB/IMPORT_POCL_LIB for any WIN32 shared build, and --exclude-all-symbols instead of --exclude-libs. The catch is that libpocl only exports its public API, so loadable driver modules can no longer reach its internals: builds have to use ENABLE_LOADABLE_DRIVERS=OFF. That's why this isn't proposed upstream. The spirv_fix_atomic_compare_exchange helper now compiles its own copy of spirv_parser.cc in the non-ICD case too, as it already did for ICD builds, instead of relying on libpocl exporting SPIRVParser.

The JuliaGPU PoCL JLLs build Windows this way; this is the first patch of their series (Yggdrasil P/pocl, 0001 in both pocl and pocl_next).

GNU ld is pathologically slow at linking the static LLVM/Clang archives
into a PE/COFF DLL (tens of minutes for libpocl). ld.lld is far faster,
but its COFF driver doesn't implement GNU ld's --exclude-libs, which
libpocl used to keep the static-lib symbols out of its auto-generated
export table. Without that, auto-exporting the whole static LLVM blob
overflows the 64K PE export-ordinal limit.

Switch MinGW to the MSVC-style export model, which works with both GNU ld
and lld:

- stamp __declspec(dllexport) on the OpenCL API for any Windows toolchain
  (defined(_WIN32)), not just _MSC_VER;
- define EXPORT_POCL_LIB / IMPORT_POCL_LIB for any WIN32 shared build, not
  just MSVC;
- export only the dllexport'd symbols (--exclude-all-symbols) instead of
  auto-export-minus-static-libs (--exclude-libs).

Because libpocl now exports only its public API, its internal symbols are
no longer visible to separately-dlopen'd driver modules, so consumers must
build with ENABLE_LOADABLE_DRIVERS=OFF (drivers linked into libpocl).

Also make the spirv_fix_atomic_compare_exchange helper compile its own copy
of spirv_parser.cc in the non-ICD case, mirroring the ICD branch, so it no
longer relies on SPIRVParser being exported from libpocl.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant