Skip to content

Commit 03f5df4

Browse files
committed
[CI][ORCJIT] Source manylinux LLVM from a release, link libstdc++ dynamically
The orcjit addon linked against conda-forge's LLVM, which is built with a newer GCC whose libstdc++ carries GLIBCXX_3.4.29+ symbols. Those exceed the manylinux_2_28 floor the project standardized on in #675, which is why the addon carried a -static-libstdc++/-static-libgcc workaround. Build LLVM from source inside the manylinux_2_28 image instead (gcc-toolset-14, static + PIC + RTTI, native target only), publish the install prefix as a compressed release asset, and have CI download it. Because that toolchain sits at the manylinux ABI floor, the workaround is no longer needed: * Linux acquires /opt/llvm by downloading llvm-<version>-linux-<arch>.tar.zst and extracting it. macOS/Windows keep the conda-forge binaries (no GLIBCXX floor); their actions/cache step is split out so their install gating is unchanged. Everything downstream is unchanged -- same /opt/llvm, same LLVM_PREFIX, same bind-mount into the build container. * Drop -static-libstdc++/-static-libgcc, so the addon no longer bakes in a private copy of the C++ runtime. The repaired wheels are tagged manylinux_2_27/manylinux_2_28, confirming the prefix stays under the floor, and the addon's exported dynamic symbols drop from ~965 to ~30 -- it no longer re-exports a private libstdc++ that could interpose with a host's own copy. The by-name --exclude-libs list is deliberately kept rather than collapsed to --exclude-libs,ALL. The embedded liborc_rt.a is linked by the JIT at run time and resolves its C++ runtime through the process, including archive-only helpers such as _ZSt28__throw_bad_array_new_lengthv that libstdc++.so does not export; ALL localizes those and the ORC platform fails to materialize. That is true whether libstdc++ is static or dynamic, so the comment there is corrected accordingly. Prebuilt LLVM is produced out-of-band, so this removes the ~50 minute from-source build from the CI path; the Linux orcjit jobs now spend a few minutes downloading.
1 parent 135c2e8 commit 03f5df4

3 files changed

Lines changed: 76 additions & 17 deletions

File tree

‎.github/actions/build-orcjit-wheel/action.yml‎

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ inputs:
3030
checkout_ref:
3131
description: "Branch, tag, or SHA to check out before building"
3232
required: true
33+
llvm_version:
34+
description: "LLVM version (selects the release tag / conda pin)"
35+
default: "22.1.0"
36+
required: false
37+
llvm_release_repo:
38+
description: >
39+
GitHub repo hosting the prebuilt LLVM release assets (Linux only). The
40+
asset llvm-<version>-linux-<arch>.tar.zst is downloaded from the
41+
llvm-<version> tag. Point at a fork to validate before the canonical repo.
42+
default: "mlc-ai/package"
43+
required: false
3344

3445
runs:
3546
using: "composite"
@@ -43,25 +54,52 @@ runs:
4354
- uses: ./.github/actions/detect-env-vars
4455
id: env_vars
4556

46-
# ---- Cache LLVM prefix ----
47-
- name: Cache LLVM
57+
# ---- Acquire LLVM prefix ----
58+
# Linux: downloaded as a prebuilt tarball from a GitHub Release (built from
59+
# source with the manylinux gcc-toolset so the ABI stays under the floor)
60+
# and extracted to /opt/llvm. Permanent storage -- no actions/cache lifetime.
61+
# macOS/Windows: no GLIBCXX floor -- keep the conda-forge binaries, cached.
62+
- name: Cache LLVM (macOS/Windows)
63+
if: runner.os != 'Linux'
4864
uses: actions/cache@v4
4965
id: llvm-cache
5066
with:
5167
path: ${{ runner.os == 'Windows' && 'C:/opt/llvm' || '/opt/llvm' }}
52-
key: llvm-22.1.0-${{ runner.os }}-${{ inputs.arch }}-v3
68+
key: llvm-${{ inputs.llvm_version }}-${{ runner.os }}-${{ inputs.arch }}-v4
5369

54-
# ---- Install LLVM via conda (cache miss only) ----
70+
- name: Download prebuilt LLVM (Linux)
71+
if: runner.os == 'Linux'
72+
shell: bash
73+
run: |
74+
set -euo pipefail
75+
asset="llvm-${{ inputs.llvm_version }}-linux-${{ inputs.arch }}.tar.zst"
76+
base="https://github.com/${{ inputs.llvm_release_repo }}/releases/download"
77+
url="${base}/llvm-${{ inputs.llvm_version }}/${asset}"
78+
echo "Downloading $url"
79+
curl -fL --retry 5 --retry-all-errors -o "$RUNNER_TEMP/$asset" "$url"
80+
sudo mkdir -p /opt/llvm
81+
sudo tar --zstd -xf "$RUNNER_TEMP/$asset" -C /opt/llvm
82+
sudo chown -R "$(id -u):$(id -g)" /opt/llvm
83+
84+
- name: Verify LLVM prefix (Linux)
85+
if: runner.os == 'Linux'
86+
shell: bash
87+
run: |
88+
test -x /opt/llvm/bin/llvm-config \
89+
|| { echo "::error::LLVM prefix missing; the release download must succeed first"; exit 1; }
90+
/opt/llvm/bin/llvm-config --version
91+
92+
# ---- Install LLVM via conda (macOS/Windows, cache miss only) ----
5593
- name: Setup conda
56-
if: steps.llvm-cache.outputs.cache-hit != 'true'
94+
if: steps.llvm-cache.outputs.cache-hit != 'true' && runner.os != 'Linux'
5795
uses: conda-incubator/setup-miniconda@fc2d68f6413eb2d87b895e92f8584b5b94a10167 # v3.3.0
5896
continue-on-error: true
5997
id: conda1
6098
with:
6199
miniforge-version: latest
62100

63101
- name: Setup conda (retry with tar.bz2)
64-
if: steps.llvm-cache.outputs.cache-hit != 'true' && steps.conda1.outcome == 'failure'
102+
if: steps.llvm-cache.outputs.cache-hit != 'true' && runner.os != 'Linux' && steps.conda1.outcome == 'failure'
65103
uses: conda-incubator/setup-miniconda@fc2d68f6413eb2d87b895e92f8584b5b94a10167 # v3.3.0
66104
with:
67105
miniforge-version: latest
@@ -72,19 +110,20 @@ runs:
72110
shell: bash
73111
run: sudo mkdir -p /opt/llvm && sudo chown -R $(whoami) /opt/llvm
74112

75-
- name: Install LLVM (Unix)
76-
if: steps.llvm-cache.outputs.cache-hit != 'true' && runner.os != 'Windows'
113+
- name: Install LLVM (macOS)
114+
if: steps.llvm-cache.outputs.cache-hit != 'true' && runner.os == 'macOS'
77115
shell: bash -l {0}
78116
run: |
79117
conda create -q -p /opt/llvm -c conda-forge \
80-
llvmdev=22.1.0 clangdev=22.1.0 compiler-rt=22.1.0 zlib zstd-static \
118+
llvmdev=${{ inputs.llvm_version }} clangdev=${{ inputs.llvm_version }} \
119+
compiler-rt=${{ inputs.llvm_version }} zlib zstd-static \
81120
-y
82121
83122
- name: Install LLVM (Windows)
84123
if: steps.llvm-cache.outputs.cache-hit != 'true' && runner.os == 'Windows'
85124
shell: cmd /C call {0}
86125
run: |
87-
conda create -q -p C:\opt\llvm -c conda-forge llvmdev=22.1.0 zlib zstd-static -y
126+
conda create -q -p C:\opt\llvm -c conda-forge llvmdev=${{ inputs.llvm_version }} zlib zstd-static -y
88127
89128
# ---- Build and test wheels ----
90129
- name: Build and test wheels
@@ -97,6 +136,10 @@ runs:
97136
CIBW_ARCHS_LINUX: ${{ inputs.arch }}
98137
CIBW_ARCHS_MACOS: ${{ inputs.arch }}
99138
CIBW_ARCHS_WINDOWS: ${{ inputs.arch }}
139+
# Link inside manylinux_2_28 -- the same image family the downloaded LLVM
140+
# was built in (gcc-toolset-14). An older image couldn't consume its libs.
141+
CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_28
142+
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux_2_28
100143
CIBW_BUILD_VERBOSITY: 1
101144
CMAKE_BUILD_PARALLEL_LEVEL: ${{ steps.env_vars.outputs.cpu_count }}
102145
CIBW_ENVIRONMENT: LLVM_PREFIX=/opt/llvm

‎.github/workflows/ci_test.yml‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ jobs:
209209
run: |
210210
cargo test
211211
212+
# Build + test the orcjit wheel. On Linux the action downloads a prebuilt LLVM
213+
# tarball from a GitHub Release (built from source under the manylinux
214+
# gcc-toolset so the ABI stays under the floor); macOS/Windows install LLVM via
215+
# conda inside the action. The LLVM release is produced out-of-band (rarely, on
216+
# version bump) by mlc-ai/package's build_llvm workflow -- not on every CI run.
212217
orcjit:
213218
needs: [lint, prepare]
214219
if: >
@@ -217,6 +222,12 @@ jobs:
217222
needs.prepare.outputs.should_skip_ci_docs_only != 'true'
218223
name: orcjit ${{ matrix.os }} (${{ matrix.arch }})
219224
runs-on: ${{ matrix.os }}
225+
env:
226+
LLVM_VERSION: "22.1.0"
227+
# Repo hosting the prebuilt LLVM release assets consumed on Linux. Built
228+
# out-of-band from source in a manylinux image so the ABI stays under the
229+
# manylinux_2_28 floor; see that repo's build_llvm workflow.
230+
LLVM_RELEASE_REPO: "mlc-ai/package"
220231
strategy:
221232
fail-fast: false
222233
matrix:
@@ -237,6 +248,8 @@ jobs:
237248
arch: ${{ matrix.arch }}
238249
build: ${{ matrix.build }}
239250
checkout_ref: ${{ github.sha }}
251+
llvm_version: ${{ env.LLVM_VERSION }}
252+
llvm_release_repo: ${{ env.LLVM_RELEASE_REPO }}
240253

241254
- uses: actions/upload-artifact@v4
242255
with:

‎addons/tvm_ffi_orcjit/CMakeLists.txt‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,20 @@ if (APPLE)
148148
$<TARGET_FILE:tvm_ffi_orcjit>
149149
COMMENT "Fixing libc++ rpath to use system library"
150150
)
151-
elseif (UNIX AND NOT WIN32)
152-
# Static libstdc++/libgcc: the conda LLVM toolchain's libstdc++ is newer than the manylinux ABI
153-
# floor, so linking it dynamically would import too-recent GLIBCXX_* symbols and fail auditwheel.
154-
target_link_options(tvm_ffi_orcjit PRIVATE -static-libstdc++ -static-libgcc)
155151
endif ()
156152

153+
# libstdc++/libgcc are linked DYNAMICALLY on Linux. The prebuilt LLVM this addon links against is
154+
# built inside the manylinux image with its gcc-toolset, so the toolchain already sits at the
155+
# manylinux ABI floor and no too-recent GLIBCXX_* symbol is imported -- the -static-libstdc++
156+
# workaround the older conda-forge LLVM required is no longer needed.
157+
157158
# Hide symbols pulled from static archives so they are not re-exported and cannot interpose with a
158159
# host process's own copies (e.g. PyTorch's bundled LLVM). Exclude LLVM/zlib/zstd by name -- NOT
159-
# --exclude-libs,ALL, which would also hide the static libstdc++ symbols (operator new, __throw_*,
160-
# ...) that liborc_rt and JIT'd C++ code resolve from this .so at run time. The LLVM list is derived
161-
# from llvm-config so it tracks the toolchain version.
160+
# --exclude-libs,ALL. The embedded liborc_rt.a is linked by the JIT at run time and resolves its C++
161+
# runtime through the process (dlsym), including archive-only helpers such as
162+
# _ZSt28__throw_bad_array_new_lengthv that libstdc++.so does not export; ALL localizes those and the
163+
# ORC platform then fails to materialize. This holds whether libstdc++ is static or dynamic. The
164+
# LLVM list is derived from llvm-config so it tracks the toolchain version.
162165
if (CMAKE_SYSTEM_NAME MATCHES "Linux|Android|FreeBSD|NetBSD|OpenBSD" AND CMAKE_CXX_COMPILER_ID
163166
MATCHES "GNU|Clang"
164167
)

0 commit comments

Comments
 (0)