Force PIE on bootgen with explicit compiler/linker flags, not just the CMake property#3333
Merged
Conversation
…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>
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>
Contributor
There was a problem hiding this comment.
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
-fPICforbootgen-libon GNU/Clang toolchains to ensure PIC objects regardless of CMake PIE-property behavior. - Add explicit
-fPIE(compile) and-pie(link) for thebootgenexecutable to force a PIE binary even under hostile global flags.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- 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
commented
Jul 13, 2026
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>
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
Follow-up to #3327, which set
POSITION_INDEPENDENT_CODE ONon thebootgen/bootgen-libCMake targets to keepbootgen's ELF layout PIE regardless of what the linked MLIR/LLVM package sets globally. That's needed becauseauditwheel repair's patchelf-based RPATH rewrite (required to point at vendored/renamed OpenSSL libs) corrupts a non-PIEbootgen: the binarySIGSEGVs (SEGV_ACCERR) jumping into its own non-executableDYNAMICsegment beforemain()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_COMMITin the #3323 build) still ships a non-PIEbootgen:(
0x4020f0falls inside that binary'sDYNAMICsegment,0x401fc8-0x4021f8-- exact same failure mode as before, reproduced by downloading the actualrocm-wheel-ryzenai-validationartifact 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'sCMP0083machinery needs in order to translate thePOSITION_INDEPENDENT_CODEtarget property into actual-fPIE/-piecompiler/linker flags for an executable target. Without that, the property is a no-op here. Compounding it:manylinux_2_28'sgcc-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(onbootgen-lib) and-fPIE/-pie(onbootgen) as explicittarget_compile_options/target_link_options, placed last so they win via ordinary compiler "last flag wins" semantics over any-fno-pie/-fno-PICinherited from the linked MLIR/LLVM package's own build configuration -- independent of the property/policy machinery.Verified locally: built
bootgenunder a forced-fno-pie -fno-PIC -no-pieglobal configuration (reproducing the manylinux/ROCm environment). Confirmed the old (#3327) property-only approach still yields a non-PIEEXECbinary under those conditions, while this change reliably produces a true PIE (ET_DYN)bootgenthat runs correctly.Test plan
readelf -hon the shippedbootgenshowsDYN, andprogramming_examplespass🤖 Generated with Claude Code