From 632c039aeaf4556f37c02b03a102aaa667fa517c Mon Sep 17 00:00:00 2001 From: Yukun He <23156053+hyukn@users.noreply.github.com> Date: Thu, 12 Feb 2026 09:54:58 +0800 Subject: [PATCH] [TRTLLM-10793][feat] Add BOLT compatible build flags for further experimental usage. (#11297) Signed-off-by: Yukun He <23156053+hyukn@users.noreply.github.com> --- cpp/CMakeLists.txt | 23 +++++++++++++++++++ .../nixl_utils/CMakeLists.txt | 9 +++++++- cpp/tensorrt_llm/nanobind/CMakeLists.txt | 7 +++++- scripts/build_wheel.py | 12 ++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 06ddbe0435..ba66a866a6 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -369,6 +369,29 @@ if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-relax") endif() +# ==== BOLT Compatible Flags ==== +# These flags enable LLVM BOLT binary compatible: +# -fno-reorder-blocks-and-partition: Prevents compiler from splitting hot/cold +# blocks -fno-plt: Removes PLT stubs for additional performance +# -Wl,--emit-relocs (or -Wl,-q): Preserves relocation info for BOLT Note: +# Binaries should NOT be stripped for BOLT to work Usage: cmake +# -DENABLE_BOLT_COMPATIBLE=ON ... +option(ENABLE_BOLT_COMPATIBLE "Enable BOLT-compatible build flags" OFF) +if(ENABLE_BOLT_COMPATIBLE AND NOT WIN32) + message(STATUS "BOLT compatible flags enabled") + # Compiler flags for C/C++ + add_compile_options(-fno-reorder-blocks-and-partition -fno-plt) + # Linker flags - applies to shared, module, and executable targets + add_link_options(-Wl,--emit-relocs) + # Disable stripping - required for BOLT (affects pybind11 POST_BUILD strip) + set(CMAKE_STRIP + "" + CACHE STRING "Disabled for BOLT compatibility" FORCE) + message(STATUS "BOLT: Disabled CMAKE_STRIP to prevent binary stripping") +endif() +# Note: For nanobind modules, use NOSTRIP option in nanobind_add_module() +# ==== End BOLT Compatible Flags ==== + # Disable deprecated declarations warnings if(NOT WIN32) set(CMAKE_CXX_FLAGS "-Wno-deprecated-declarations ${CMAKE_CXX_FLAGS}") diff --git a/cpp/tensorrt_llm/executor/cache_transmission/nixl_utils/CMakeLists.txt b/cpp/tensorrt_llm/executor/cache_transmission/nixl_utils/CMakeLists.txt index 8b99e698f0..7700c64a90 100644 --- a/cpp/tensorrt_llm/executor/cache_transmission/nixl_utils/CMakeLists.txt +++ b/cpp/tensorrt_llm/executor/cache_transmission/nixl_utils/CMakeLists.txt @@ -67,7 +67,14 @@ if(NIXL_ENABLED OR MOONCAKE_ENABLED) set(AGENT_BINDING_SOURCES "") list(APPEND AGENT_BINDING_SOURCES agentBindings.cpp) - nanobind_add_module(${TRANSFER_AGENT_BINDING_TARGET} ${AGENT_BINDING_SOURCES}) + # NOSTRIP: Disable stripping for BOLT compatibility (requires --emit-relocs) + if(ENABLE_BOLT_COMPATIBLE) + nanobind_add_module(${TRANSFER_AGENT_BINDING_TARGET} NOSTRIP + ${AGENT_BINDING_SOURCES}) + else() + nanobind_add_module(${TRANSFER_AGENT_BINDING_TARGET} + ${AGENT_BINDING_SOURCES}) + endif() message(STATUS "Building tensorrt_llm_transfer_agent_binding with nanobind") target_compile_options(${TRANSFER_AGENT_BINDING_TARGET} PRIVATE -Wno-error) diff --git a/cpp/tensorrt_llm/nanobind/CMakeLists.txt b/cpp/tensorrt_llm/nanobind/CMakeLists.txt index a47f8dd1d4..999c2b736c 100755 --- a/cpp/tensorrt_llm/nanobind/CMakeLists.txt +++ b/cpp/tensorrt_llm/nanobind/CMakeLists.txt @@ -29,7 +29,12 @@ set(SRCS include_directories(${PROJECT_SOURCE_DIR}/include) -nanobind_add_module(${TRTLLM_NB_MODULE} ${SRCS}) +# NOSTRIP: Disable stripping for BOLT compatibility (requires --emit-relocs) +if(ENABLE_BOLT_COMPATIBLE) + nanobind_add_module(${TRTLLM_NB_MODULE} NOSTRIP ${SRCS}) +else() + nanobind_add_module(${TRTLLM_NB_MODULE} ${SRCS}) +endif() set_property(TARGET ${TRTLLM_NB_MODULE} PROPERTY POSITION_INDEPENDENT_CODE ON) diff --git a/scripts/build_wheel.py b/scripts/build_wheel.py index f61b99466a..6dbfc64740 100755 --- a/scripts/build_wheel.py +++ b/scripts/build_wheel.py @@ -598,6 +598,18 @@ def main(*, if nvrtc_dynamic_linking: cmake_def_args.append(f"-DNVRTC_DYNAMIC_LINKING=ON") + # BOLT compatibility: Force dynamic linking for NVIDIA libraries + # Static NVIDIA libraries (libnvrtc_static.a, etc.) lack --emit-relocs, + # which BOLT requires for proper binary optimization. + bolt_enabled = any("ENABLE_BOLT_COMPATIBLE=ON" in var + for var in extra_cmake_vars) + if bolt_enabled: + if not nvrtc_dynamic_linking: + cmake_def_args.append("-DNVRTC_DYNAMIC_LINKING=ON") + print( + "-- BOLT: Forcing NVRTC_DYNAMIC_LINKING=ON (static NVIDIA libs lack relocations)" + ) + targets = ["tensorrt_llm", "nvinfer_plugin_tensorrt_llm"] if cpp_only: