Skip to content

build(before-code-freeze): Export the stub's dynamic symbols when libpython is static (#451) - #453

Merged
mc-nv merged 1 commit into
mainfrom
mchornyi/TRI-1691/before-ngc-release-advance-master-branch-to-next-upstream-release
Sep 2, 2026
Merged

build(before-code-freeze): Export the stub's dynamic symbols when libpython is static (#451)#453
mc-nv merged 1 commit into
mainfrom
mchornyi/TRI-1691/before-ngc-release-advance-master-branch-to-next-upstream-release

Conversation

@mc-nv

@mc-nv mc-nv commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

What does the PR do?

  • Carries the stub export fix forward from r26.08 onto main.
  • The manylinux base builds CPython with --disable-shared, so Py_* symbols live in the stub executable; extension modules are dlopen'ed and can only bind against its dynamic symbol table.
  • Gated on the resolved library being an archive, so the Debian build is unaffected.

Checklist

  • PR title reflects the change and is of format <commit_type>: <Title>
  • Changes are described in the pull request.
  • Related issues are referenced.
  • Populated github labels field
  • Added test plan and verified test passes.
  • Verified that the PR passes existing CI.
  • Verified copyright is correct on all changed files.
  • Added succinct git squash message before merging ref.
  • All template sections are filled out.
  • Optional: Additional screenshots for behavior/output changes with before/after.

Commit Type:

Check the conventional commit type
box here and add the label to the github PR.

  • build
  • ci
  • docs
  • feat
  • fix
  • perf
  • refactor
  • revert
  • style
  • test

Related PRs:

Where should the reviewer start?

CMakeLists.txt — the ENABLE_EXPORTS condition.

Test plan:

  • Full CI run on the internal pipeline at TRITON_CONTAINER_VERSION=26.09dev_user, with TRITON_NIGHTLY=1 and TRITON_SBSA=1.

  • Local verification: per-repo pre-commit run --files <changed> passes with no auto-fixes.

  • CI Pipeline ID:

Caveats:

  • Do not merge before the model-repository mount point is rotated: TRITON_SERVER_MODEL_REPO_VERSION derives from TRITON_CONTAINER_VERSION, so 26.09dev must exist on the share first.

Background

Post-release step of the 26.08 train: the default branches move onto the same upstream containers as the just-released r26.08, and pick up the fixes that landed only on the release branch while it stabilised.

Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)

  • Relates to: TRI-1691

…python is static (#451)

* build: Export the stub's dynamic symbols when libpython is static

The manylinux base container builds CPython with --disable-shared, so on
that platform triton_python_backend_stub links libpython3.x.a and the
Py_* symbols live in the executable rather than a shared library. Python
C extension modules are dlopen'ed and deliberately leave Py_* undefined
-- every one of the 77 lib-dynload modules in the image does, math.so
alone with 63 undefined symbols and no libpython in DT_NEEDED -- so they
can only bind against the stub's dynamic symbol table. Without the
export the stub links and starts, then fails on the first `import math`.

Set ENABLE_EXPORTS, which makes CMake add the platform's flag
(-Wl,--export-dynamic on Linux, per Platform/Linux.cmake), matching how
CPython links its own interpreter.

Gate it on the resolved library being an archive rather than on the
platform. A shared libpython needs no export, so the Debian build is
unaffected, and the condition stays correct if a target moves between
the two linkage modes.

The condition reads PYTHON_LIBRARY, not PYTHON_LIBRARIES: pybind11
arrives through FetchContent_MakeAvailable, which uses add_subdirectory,
so only the cache entry find_library creates crosses back into this
scope. PYTHON_LIBRARIES is a plain variable in pybind11's directory and
is empty here, which would have made this a silent no-op.

* docs: Correct the stale RHEL_BUILD rationale

The comment said RHEL_BUILD existed because pybind would otherwise pick
up Python 3.6 in the RHEL base container, so PYBIND11_PYTHON_VERSION was
set to force 3.12. That pin has been dropped from build.py -- pybind11
prefers the newest entry of its own Python_ADDITIONAL_VERSIONS list, and
the manylinux base container puts a single interpreter first on PATH.

RHEL_BUILD itself stays: it still selects the stub's link settings
further down. Only the justification was wrong.

(cherry picked from commit 96d6021)
@greptile-apps

greptile-apps Bot commented Sep 1, 2026

Copy link
Copy Markdown

Greptile Summary

This PR conditionally exports symbols from the Python backend stub when it links against a static libpython, allowing dynamically loaded Python extension modules to resolve Py_* symbols while leaving shared-libpython builds unchanged.

  • Detects static Python linkage through the resolved PYTHON_LIBRARY archive path.
  • Enables CMake’s executable-export behavior only for the static-link case.
  • Updates the build-file copyright year and Python-discovery commentary.

Confidence Score: 5/5

The PR appears safe to merge, with the export behavior narrowly limited to static-libpython builds.

The new condition enables executable symbol exports for the stub only when Python discovery resolves an archive, while shared-library builds retain their existing linkage behavior.

Important Files Changed

Filename Overview
CMakeLists.txt Adds a narrowly gated executable-export property for static libpython builds; no actionable defect was identified.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  C[CMake config] --> D{PYTHON_LIBRARY ends in .a?}
  D -- Yes --> E[Enable executable exports]
  E --> S[Stub dynamic symbol table exposes Py_*]
  S --> M[dlopen'ed extension modules resolve Python symbols]
  D -- No --> L[Use shared libpython for symbol resolution]
Loading

Reviews (1): Last reviewed commit: "build(before-code-freeze): Export the st..." | Re-trigger Greptile

@mc-nv
mc-nv merged commit 765bf14 into main Sep 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Build system or external dependencies (build: PRs) cherry-pick Cherry-picked from another branch

Development

Successfully merging this pull request may close these issues.

2 participants