Skip to content

Force PIE on bootgen with explicit compiler/linker flags, not just the CMake property#3333

Merged
jgmelber merged 4 commits into
mainfrom
fix-bootgen-pie-explicit-flags
Jul 13, 2026
Merged

Force PIE on bootgen with explicit compiler/linker flags, not just the CMake property#3333
jgmelber merged 4 commits into
mainfrom
fix-bootgen-pie-explicit-flags

Conversation

@jgmelber

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #3327, which set POSITION_INDEPENDENT_CODE ON on the bootgen/bootgen-lib CMake targets to keep bootgen's ELF layout PIE regardless of what the linked MLIR/LLVM package sets globally. That's needed because auditwheel repair's patchelf-based RPATH rewrite (required to point at vendored/renamed OpenSSL libs) corrupts a non-PIE bootgen: the binary SIGSEGVs (SEGV_ACCERR) jumping into its own non-executable DYNAMIC segment before main() runs, breaking PDI/xclbin generation on real Ryzen AI hardware -- this is what's still failing in #3323.

#3327's fix doesn't actually work. The wheel built from that exact commit (27433d63, AIE_PROJECT_COMMIT in the #3323 build) still ships a non-PIE bootgen:

$ readelf -h mlir_aie/bin/bootgen | grep Type
  Type:                              EXEC (Executable file)
$ strace -f ./mlir_aie/bin/bootgen -help
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_ACCERR, si_addr=0x4020f0} ---

(0x4020f0 falls inside that binary's DYNAMIC segment, 0x401fc8-0x4021f8 -- exact same failure mode as before, reproduced by downloading the actual rocm-wheel-ryzenai-validation artifact from the #3323 CI run and running it directly, no hardware needed.)

Root cause of why the property doesn't work: this project never calls include(CheckPIESupported) / check_pie_supported(), which CMake's CMP0083 machinery needs in order to translate the POSITION_INDEPENDENT_CODE target property into actual -fPIE/-pie compiler/linker flags for an executable target. Without that, the property is a no-op here. Compounding it: manylinux_2_28's gcc-toolset-14 (used to build release wheels) doesn't default to PIE the way a distro's system GCC does, so there's no free fallback either.

Fix: pass -fPIC (on bootgen-lib) and -fPIE/-pie (on bootgen) as explicit target_compile_options/target_link_options, placed last so they win via ordinary compiler "last flag wins" semantics over any -fno-pie/-fno-PIC inherited from the linked MLIR/LLVM package's own build configuration -- independent of the property/policy machinery.

Verified locally: built bootgen under a forced -fno-pie -fno-PIC -no-pie global configuration (reproducing the manylinux/ROCm environment). Confirmed the old (#3327) property-only approach still yields a non-PIE EXEC binary under those conditions, while this change reliably produces a true PIE (ET_DYN) bootgen that runs correctly.

Test plan

🤖 Generated with Claude Code

…e CMake property

PR #3327 set POSITION_INDEPENDENT_CODE ON on the bootgen/bootgen-lib
targets to keep bootgen's ELF layout PIE regardless of what the linked
MLIR/LLVM package sets globally (needed because auditwheel repair's
patchelf-based RPATH rewrite corrupts a non-PIE bootgen -- SIGSEGV
SEGV_ACCERR jumping into the non-executable DYNAMIC segment before
main() runs, breaking PDI/xclbin generation on real hardware).

That fix didn't actually take effect: this project never calls
check_pie_supported()/wires up CMP0083, so the POSITION_INDEPENDENT_CODE
property has no effect on GCC's linking of the bootgen executable. The
wheel built from #3327's own commit still ships a non-PIE `bootgen`
(confirmed via `readelf -h` and reproduced the SIGSEGV via `strace` on
the exact artifact CI produced), because manylinux_2_28's gcc-toolset
doesn't default to PIE the way a distro's system gcc does.

Pass -fPIC/-fPIE/-pie explicitly instead, placed last so they win over
any inherited -fno-pie/-fno-PIC (compilers apply last-flag-wins for
these). Verified locally under a forced -fno-pie -fno-PIC -no-pie
global configuration (reproducing the manylinux/ROCm build environment)
that the previous property-only approach still yields a non-PIE `EXEC`
binary, while this change reliably produces a true PIE (`ET_DYN`)
bootgen that runs correctly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 13, 2026 21:21
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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens bootgen’s PIE/PIC behavior by adding explicit compiler/linker flags in tools/bootgen so the resulting wheel reliably ships a PIE bootgen binary even when global LLVM/MLIR-derived flags would otherwise disable PIE/PIC.

Changes:

  • Add explicit -fPIC for bootgen-lib on GNU/Clang toolchains to ensure PIC objects regardless of CMake PIE-property behavior.
  • Add explicit -fPIE (compile) and -pie (link) for the bootgen executable to force a PIE binary even under hostile global flags.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tools/bootgen/CMakeLists.txt Outdated
Comment thread tools/bootgen/CMakeLists.txt Outdated
Comment thread tools/bootgen/CMakeLists.txt Outdated
- Guard the new -fPIC/-fPIE blocks with NOT MSVC too: clang-cl reports
  CMAKE_CXX_COMPILER_ID "Clang" but uses the MSVC-style driver, which
  doesn't accept these GNU-style flags.
- Drop -fPIE from target_link_options(bootgen ...); it's a compile-only
  flag, and passing it at link time can break toolchains where linking
  doesn't go through the compiler driver. Only -pie belongs there.

Re-verified locally under the same forced -fno-pie -fno-PIC -no-pie
global configuration as before: bootgen still links as a true PIE
(ET_DYN) binary and runs correctly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@jgmelber jgmelber enabled auto-merge July 13, 2026 21:41
@jgmelber jgmelber disabled auto-merge July 13, 2026 21:56
Comment thread tools/bootgen/CMakeLists.txt Outdated
@jgmelber jgmelber enabled auto-merge July 13, 2026 22:22
@jgmelber jgmelber disabled auto-merge July 13, 2026 22:22
@jgmelber jgmelber enabled auto-merge July 13, 2026 22:33
@jgmelber jgmelber disabled auto-merge July 13, 2026 23:16
@jgmelber jgmelber merged commit bfbc658 into main Jul 13, 2026
65 checks passed
@jgmelber jgmelber deleted the fix-bootgen-pie-explicit-flags branch July 13, 2026 23:57
jgmelber added a commit that referenced this pull request Jul 14, 2026
The bootgen PIE fix (#3333) is confirmed working: the shipped bootgen
is now a true PIE binary and no longer segfaults during PDI generation.
That unmasked a second, unrelated failure: most programming_examples/
CMakeLists.txt files require CMake >= 3.30 for their host-code build,
but the self-hosted Ryzen AI runners only have system CMake 3.28.3,
so `Run programming_examples against the wheel` fails uniformly with
"CMake 3.30 or higher is required" once PDI generation stops being the
first thing to fail.

Install cmake via pip into the test venv instead of relying on the
runner's system package -- same version pin already used in
python/requirements_dev.txt for the from-source build path. Venv
activation puts wheel-test-venv/bin ahead of the system PATH, so this
shadows the outdated system cmake without needing to touch anything on
the runners themselves.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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