Skip to content

Commit c24bbeb

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 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. Add an explicit ABI assertion, because auditwheel does not fail on a too-new symbol: it silently selects a laxer tag. A regression to GLIBCXX_3.4.30 would still yield a valid manylinux_2_35 wheel and pass CI unnoticed. The new step fails unless every wheel is tagged manylinux_2_28 or lower, and logs the highest GLIBCXX/CXXABI versions imported plus the C++ runtime references. 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 c24bbeb

3 files changed

Lines changed: 131 additions & 17 deletions

File tree

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

Lines changed: 108 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
@@ -116,3 +159,58 @@ runs:
116159
pip install --force-reinstall {project} &&
117160
pytest {project}/addons/tvm_ffi_orcjit/tests -v &&
118161
python {project}/addons/tvm_ffi_orcjit/examples/quick-start/run.py --lang c
162+
163+
# ---- ABI floor assertion (Linux) ----
164+
# libstdc++ is linked dynamically, so the wheel's manylinux tag is now a real
165+
# signal about the LLVM prefix's ABI. Assert it explicitly: auditwheel does NOT
166+
# fail on a too-new symbol, it silently picks a laxer tag (e.g. GLIBCXX_3.4.30
167+
# would still produce a valid manylinux_2_35 wheel), which would let an ABI
168+
# regression in the prebuilt LLVM pass CI unnoticed.
169+
- name: Assert manylinux ABI floor (Linux)
170+
if: runner.os == 'Linux'
171+
shell: bash
172+
run: |
173+
set -euo pipefail
174+
shopt -s nullglob
175+
wheels=(wheelhouse/*.whl)
176+
[ ${#wheels[@]} -gt 0 ] || { echo "::error::no wheel built"; exit 1; }
177+
rc=0
178+
for whl in "${wheels[@]}"; do
179+
name="$(basename "$whl")"
180+
# manylinux_<major>_<minor>: require <= 2_28, the image we build in.
181+
if [[ "$name" =~ manylinux_([0-9]+)_([0-9]+)_ ]]; then
182+
major="${BASH_REMATCH[1]}"; minor="${BASH_REMATCH[2]}"
183+
if [ "$major" -gt 2 ] || { [ "$major" -eq 2 ] && [ "$minor" -gt 28 ]; }; then
184+
echo "::error::$name exceeds the manylinux_2_28 floor -- the LLVM prefix"\
185+
"imports too-recent GLIBCXX/CXXABI symbols."
186+
rc=1
187+
else
188+
echo "OK: $name is within the manylinux_2_28 floor"
189+
fi
190+
else
191+
echo "::error::$name carries no manylinux platform tag"; rc=1
192+
fi
193+
done
194+
# Report the C++ ABI symbol versions the .so actually imports, so the log
195+
# documents the floor instead of only asserting it.
196+
tmp="$(mktemp -d)"
197+
# python rather than unzip: it is guaranteed present on the runner, and a
198+
# missing tool here would abort the step and hide the result above.
199+
python3 -c "import sys,zipfile; zipfile.ZipFile(sys.argv[1]).extractall(sys.argv[2])" \
200+
"${wheels[0]}" "$tmp"
201+
for so in $(find "$tmp" -name '*orcjit*.so'); do
202+
echo "--- $(basename "$so") ---"
203+
syms="$(readelf --dyn-syms --wide "$so")"
204+
for prefix in GLIBCXX CXXABI; do
205+
echo " max ${prefix} imported: $(printf '%s\n' "$syms" \
206+
| grep -oE "${prefix}_[0-9.]+" | sort -uV | tail -1)"
207+
done
208+
echo " C++ runtime refs (expect UND -> served by the process libstdc++):"
209+
printf '%s\n' "$syms" \
210+
| grep -E ' UND +(_Znwm|__cxa_throw|__gxx_personality_v0)\b' \
211+
| awk '{print " " $8}' | sort -u
212+
echo " defined dynamic exports: $(printf '%s\n' "$syms" \
213+
| awk '$4~/FUNC|OBJECT/ && $5~/GLOBAL|WEAK/ && $7!="UND"' | wc -l)"
214+
done
215+
rm -rf "$tmp"
216+
exit $rc

‎.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)