Skip to content

Take the address of a dllimport slot at run time - #1421

Merged
wjakob merged 1 commit into
wjakob:masterfrom
yosh-matsuda:fix-dllimport-slot
Aug 23, 2026
Merged

Take the address of a dllimport slot at run time#1421
wjakob merged 1 commit into
wjakob:masterfrom
yosh-matsuda:fix-dllimport-slot

Conversation

@yosh-matsuda

Copy link
Copy Markdown
Contributor

Take the address of a dllimport slot at run time

NB_SLOT_ALIAS initializes a constexpr pointer with the address of a CPython function (nb_backend.h:615):

#define NB_SLOT_ALIAS(ret, name, args, target) \
    inline constexpr ret (*name) args = ⌖

Windows declares a CPython function with __declspec(dllimport), so its address is the content of an import slot that the loader fills, and not a constant expression. Clang rejects the initializer:

// The declaration that Python.h produces on Windows
extern "C" __declspec(dllimport) int PyObject_Vectorcall(int);
inline constexpr int (*vectorcall)(int) = &PyObject_Vectorcall;
> clang-cl /std:c++17 /c repro.cpp
repro.cpp(2,24): error: constexpr variable 'vectorcall' must be initialized by a constant expression

Every Windows target of Clang fails, both --target=x86_64-pc-windows-msvc and --target=x86_64-w64-windows-gnu, so no extension builds with clang-cl. MSVC accepts the initializer as an extension, which is why the windows-2022 job of the CI stays green.

The macro arrived with the vector call slots in 9219167 and reached its first release in 3.0.0.

Fix

Make the pointer const instead of constexpr:

-    inline constexpr ret (*name) args = ⌖
+    inline ret (*const name) args = ⌖

Tests

The error appears at compile time on one platform, so the test is a CI job. .github/workflows/ci.yml gains a clang-cl job.

'NB_SLOT_ALIAS' initialized a 'constexpr' pointer with the address of a
CPython function. Windows declares such a function with
'__declspec(dllimport)', so its address is the content of an import slot
and not a constant expression. Clang rejects the initializer in every
Windows target, which stops the build of any extension with clang-cl.
MSVC accepts it as an extension, so the existing Windows job of the CI
never saw the error.

The pointer is now 'const' instead of 'constexpr'. It is only ever
called, so no other place needs a constant expression. A clang-cl job
covers the target.
@wjakob

wjakob commented Aug 23, 2026

Copy link
Copy Markdown
Owner

Thank you. I will trim back some of the comments of these changes, I think they are overkill. The commit history and PR description is enough to look into the detailed rationale.

@wjakob
wjakob merged commit ef80255 into wjakob:master Aug 23, 2026
40 checks passed
KKyang added a commit to ROCm/rocm-libraries that referenced this pull request Aug 24, 2026
Fixes #11170

## Problem

nanobind **3.0.0** (released 2026-08-22) does not build with clang on
Windows. `NB_SLOT_ALIAS` constexpr-initialises a function pointer to the
`dllimport`'d `PyObject_Vectorcall`, and the address of a dllimport
symbol is not a constant expression there:

```
nanobind/nb_backend_slots.h:581:27: error: constexpr variable 'vectorcall' must be
                                    initialized by a constant expression
nanobind/nb_backend.h:616:28: note: expanded from macro 'NB_SLOT_ALIAS'
  616 |     inline constexpr ret (*name) args = ⌖
```

Every nanobind TU fails, so `pip install
projects/hipblaslt/tensilelite/rocisa` dies during build isolation and
takes the **rocISA / Windows** job with it. It started the same day
3.0.0 landed on PyPI, because every nanobind requirement in these trees
was unbounded — `nanobind>=2.0`, or in two places just `nanobind`.

Underlying compiler behaviour:
[llvm/llvm-project#125952](llvm/llvm-project#125952).
Same code is fine on Linux/macOS.

## Fix

Upstream fixed it in
[wjakob/nanobind#1421](wjakob/nanobind#1421)
(merged 2026-08-23) by dropping the `constexpr`. So exclude the single
bad release with `!=3.0.0` rather than capping the 3.x line — 3.0.1 gets
picked up automatically with no follow-up change:

| version | |
|---|---|
| 2.15.0 | allowed |
| **3.0.0** | **excluded** |
| 3.0.1 | allowed |
| 3.1.0 | allowed |

Applied to all five pip-resolved requirements:

- `projects/hipblaslt/tensilelite/pyproject.toml`
- `projects/hipblaslt/tensilelite/requirements.txt`
- `projects/hipblaslt/tensilelite/rocisa/pyproject.toml`
- `shared/stinkytofu/pyproject.toml`
- `shared/stinkytofu/requirements.txt`

The CMake `FetchContent` fallbacks are already pinned (rocisa v2.6.1,
hipdnn v2.12.0, origami v2.0.0) and are unaffected.

## Test plan

- [x] Specifier verified: `>=2.0,!=3.0.0` admits 2.15.0 / 3.0.1 / 3.1.0,
rejects 3.0.0 and 1.9.0
- [x] Grep confirms no unbounded nanobind requirement remains in either
tree
- [ ] rocISA / Windows green in CI (the real check)
Jinp800125 pushed a commit to Jinp800125/rocm-libraries that referenced this pull request Aug 27, 2026
Fixes ROCm#11170

## Problem

nanobind **3.0.0** (released 2026-08-22) does not build with clang on
Windows. `NB_SLOT_ALIAS` constexpr-initialises a function pointer to the
`dllimport`'d `PyObject_Vectorcall`, and the address of a dllimport
symbol is not a constant expression there:

```
nanobind/nb_backend_slots.h:581:27: error: constexpr variable 'vectorcall' must be
                                    initialized by a constant expression
nanobind/nb_backend.h:616:28: note: expanded from macro 'NB_SLOT_ALIAS'
  616 |     inline constexpr ret (*name) args = ⌖
```

Every nanobind TU fails, so `pip install
projects/hipblaslt/tensilelite/rocisa` dies during build isolation and
takes the **rocISA / Windows** job with it. It started the same day
3.0.0 landed on PyPI, because every nanobind requirement in these trees
was unbounded — `nanobind>=2.0`, or in two places just `nanobind`.

Underlying compiler behaviour:
[llvm/llvm-project#125952](llvm/llvm-project#125952).
Same code is fine on Linux/macOS.

## Fix

Upstream fixed it in
[wjakob/nanobind#1421](wjakob/nanobind#1421)
(merged 2026-08-23) by dropping the `constexpr`. So exclude the single
bad release with `!=3.0.0` rather than capping the 3.x line — 3.0.1 gets
picked up automatically with no follow-up change:

| version | |
|---|---|
| 2.15.0 | allowed |
| **3.0.0** | **excluded** |
| 3.0.1 | allowed |
| 3.1.0 | allowed |

Applied to all five pip-resolved requirements:

- `projects/hipblaslt/tensilelite/pyproject.toml`
- `projects/hipblaslt/tensilelite/requirements.txt`
- `projects/hipblaslt/tensilelite/rocisa/pyproject.toml`
- `shared/stinkytofu/pyproject.toml`
- `shared/stinkytofu/requirements.txt`

The CMake `FetchContent` fallbacks are already pinned (rocisa v2.6.1,
hipdnn v2.12.0, origami v2.0.0) and are unaffected.

## Test plan

- [x] Specifier verified: `>=2.0,!=3.0.0` admits 2.15.0 / 3.0.1 / 3.1.0,
rejects 3.0.0 and 1.9.0
- [x] Grep confirms no unbounded nanobind requirement remains in either
tree
- [ ] rocISA / Windows green in CI (the real check)
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.

2 participants