Skip to content

Commit c803ce5

Browse files
jgmelberclaude
andcommitted
Force PIE on bootgen to fix non-deterministic PDI-generation segfault
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>
1 parent 696ba5a commit c803ce5

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

tools/bootgen/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ string(REPLACE "#include \"openssl/ms/applink.c\"" "" FILE_CONTENTS "${FILE_CONT
107107
file(WRITE ${BOOTGEN_SOURCE}/main.cpp "${FILE_CONTENTS}")
108108

109109
add_library(bootgen-lib STATIC ${libsources})
110+
# Force PIE/PIC explicitly rather than inheriting whatever the top-level
111+
# project's global flags happen to be: bootgen has no dependency on
112+
# MLIR/LLVM, but it's configured as part of the same CMake invocation, so it
113+
# silently inherits global compiler/linker defaults set by
114+
# find_package(MLIR)/include(HandleLLVMOptions) upstream. When those global
115+
# defaults produce a non-PIE bootgen executable that still declares dynamic
116+
# NEEDED libs and an RPATH, auditwheel repair's patchelf-based RPATH rewrite
117+
# has been observed to corrupt the binary (jumps into the non-executable
118+
# DYNAMIC segment at runtime -- SIGSEGV/SEGV_ACCERR before main() even
119+
# runs). Pinning PIE here keeps bootgen's ELF layout the standard one
120+
# patchelf actually exercises, independent of what MLIR/LLVM sets globally.
121+
set_target_properties(bootgen-lib PROPERTIES POSITION_INDEPENDENT_CODE ON)
110122
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
111123
set(bootgen_warning_ignores
112124
-Wno-cast-qual
@@ -154,6 +166,7 @@ install(
154166
DESTINATION include)
155167

156168
add_executable(bootgen ${BOOTGEN_SOURCE}/main.cpp)
169+
set_target_properties(bootgen PROPERTIES POSITION_INDEPENDENT_CODE ON)
157170
target_include_directories(bootgen PUBLIC ${BOOTGEN_SOURCE} ${OPENSSL_INCLUDE_DIR}
158171
${CMAKE_CURRENT_BINARY_DIR}/include)
159172
target_compile_options(bootgen PRIVATE ${bootgen_warning_ignores})

0 commit comments

Comments
 (0)