Force PIE on bootgen to fix PDI-generation segfault#3327
Merged
Conversation
bootgen has no dependency on MLIR/LLVM (it only links OpenSSL::SSL and its own bootgen-lib), but it's configured as part of the same CMake invocation as the rest of mlir-aie, so it silently inherits whatever global compiler/linker defaults find_package(MLIR)/ include(HandleLLVMOptions) set for that run. Building against the ROCm-built MLIR wheel (see the rocm-mlir-distro migration) flips bootgen from a PIE executable to a non-PIE one, while it still declares dynamic NEEDED libs and an RPATH. auditwheel repair's patchelf-based RPATH rewrite (needed to point at vendored/renamed OpenSSL libs) then corrupts that non-standard layout: the resulting binary SIGSEGVs (SEGV_ACCERR) jumping into its own non-executable DYNAMIC segment before main() even runs, on real Ryzen AI hardware, not just in a sandbox. This broke PDI/xclbin generation for nearly every programming_examples/*.lit test in #3323. Pin POSITION_INDEPENDENT_CODE ON directly on bootgen-lib and bootgen so their ELF layout no longer depends on whatever the MLIR/LLVM package happens to set globally. Verified locally: before the fix, `bootgen -help` segfaults immediately (even under LD_TRACE_LOADED_OBJECTS=1, i.e. before bootgen's own code runs); after, it links as a normal PIE executable and runs correctly. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the build configuration for the bootgen host tool so its ELF type/layout is stable across different top-level MLIR/LLVM build flag configurations (notably ROCm wheel builds), preventing a reproducible segfault during PDI generation after auditwheel repair rewrites RPATHs.
Changes:
- Forces
POSITION_INDEPENDENT_CODE ONonbootgen-libto ensure it is compiled as PIC. - Forces
POSITION_INDEPENDENT_CODE ONon thebootgenexecutable target to ensure it is built as PIE (where supported by the toolchain/CMake). - Adds in-file rationale documenting why target-local PIE/PIC is required (avoids inheriting MLIR/LLVM global flags).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
andrej
approved these changes
Jul 13, 2026
andrej
left a comment
Collaborator
There was a problem hiding this comment.
Looks good. Did make the comment a bit more terse. I just left a similar comment on a recent PR from Erika -- I feel like AI tends to create too many/too verbose comments that fill up my human context window.
Co-authored-by: André Rösti <an.roesti@gmail.com>
6 tasks
2 tasks
jgmelber
added a commit
that referenced
this pull request
Jul 13, 2026
…e CMake property Same fix as #3333 (against main), carried forward here since this branch replaces bootgen's CMakeLists.txt with the 2026.1 upstream-source layout. The POSITION_INDEPENDENT_CODE property set on bootgen-lib/bootgen doesn't actually force PIE: this project never calls check_pie_supported(), which CMake's CMP0083 needs to turn that property into real -fPIE/-pie flags for an executable target. Confirmed via readelf + strace that the wheel built from #3327's own commit (main's earlier attempt at this) still ships a non-PIE `bootgen` and segfaults (SIGSEGV/SEGV_ACCERR jumping into its own non-executable DYNAMIC segment) once auditwheel repair patches in an RPATH for vendored OpenSSL -- manylinux_2_28's gcc-toolset doesn't default to PIE the way a distro's system gcc does. Pass -fPIC/-fPIE/-pie explicitly, last, so they win over any inherited -fno-pie/-fno-PIC via ordinary last-flag-wins compiler semantics. Verified locally under a forced -fno-pie -fno-PIC -no-pie global configuration that this reliably produces a true PIE (ET_DYN) bootgen, unlike the property-only approach. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a real, hardware-reproducible crash found while validating #3323 (ROCm mlir_aie wheel on Ryzen AI self-hosted runners): nearly every
programming_examples/test failed with```
RuntimeError: [aiecc] Compilation failed with exit code 1:
Error: Command failed with exit code -2
Error message: Segmentation fault (core dumped)
Error generating PDI
```
on both `aie2-4col` and `aie2p-8col` — see full diagnosis in this comment.
Root cause: `bootgen` has no dependency on MLIR/LLVM (it only links `OpenSSL::SSL` + its own `bootgen-lib`), but it's configured as part of the same top-level CMake invocation as everything else, so it silently inherits whatever global compiler/linker defaults `find_package(MLIR)`/`include(HandleLLVMOptions)` set for that run. Building against the ROCm-built MLIR wheel flips `bootgen` from a PIE executable to a non-PIE one, while it still declares dynamic `NEEDED` libs and an `RPATH`. `auditwheel repair`'s `patchelf`-based RPATH rewrite (needed to point at vendored/renamed OpenSSL libs) then corrupts that non-standard layout — the binary `SIGSEGV`s (`SEGV_ACCERR`) jumping into its own non-executable `DYNAMIC` segment before `main()` even runs.
Confirmed via `strace`:
```
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_ACCERR, si_addr=0x4020c8} ---
```
`readelf -l` shows `0x4020c8` falls inside the `DYNAMIC` segment, which is mapped `RW` only — something is jumping there to execute code.
Fix: pin `POSITION_INDEPENDENT_CODE ON` directly on the `bootgen-lib` and `bootgen` CMake targets, so their ELF layout no longer depends on whatever the linked MLIR/LLVM package happens to set globally.
Verified locally:
This blocks #3323 and #3326 (which depends on #3323 passing) — once merged, #3323 should be re-run against a wheel built with this fix.
Test plan
programming_examplespass🤖 Generated with Claude Code