diff --git a/libs/core/config/CMakeLists.txt b/libs/core/config/CMakeLists.txt index 1373f6631388..32c3f6ab9fc8 100644 --- a/libs/core/config/CMakeLists.txt +++ b/libs/core/config/CMakeLists.txt @@ -27,6 +27,7 @@ set(config_macro_headers hpx/config/forward.hpp hpx/config/manual_profiling.hpp hpx/config/move.hpp + hpx/config/static_linker_check.hpp hpx/config/threads_stack.hpp hpx/config/warnings_prefix.hpp hpx/config/warnings_suffix.hpp diff --git a/libs/core/config/include/hpx/config/static_linker_check.hpp b/libs/core/config/include/hpx/config/static_linker_check.hpp new file mode 100644 index 000000000000..d1e5b795cc07 --- /dev/null +++ b/libs/core/config/include/hpx/config/static_linker_check.hpp @@ -0,0 +1,31 @@ +// Copyright (c) 2020-2026 The STE||AR-Group +// +// SPDX-License-Identifier: BSL-1.0 +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +/// \file hpx/config/static_linker_check.hpp +/// \brief Compile-time safety check for the -Wl,-wrap=main linker flag. +/// +/// On Linux, when HPX is statically linked with dynamic main wrapping +/// enabled, the linker requires -Wl,-wrap=main to intercept main() and +/// bootstrap the HPX runtime. Without it, programs crash at startup. +/// +/// This header emits a #warning when those conditions are detected and +/// the HPX_HAVE_WRAP_MAIN_CONFIGURED define is absent. CMake consumers +/// get the define injected automatically via the hpx_wrap target's +/// INTERFACE compile definitions, so they never see this warning. + +#pragma once + +#include + +#if defined(__linux__) && defined(HPX_HAVE_DYNAMIC_HPX_MAIN) && \ + defined(HPX_HAVE_STATIC_LINKING) && \ + !defined(HPX_HAVE_WRAP_MAIN_CONFIGURED) +// clang-format off +#warning \ + "HPX: -Wl,-wrap=main not detected. " \ + "Link via HPX::wrap_main or add flag manually." +// clang-format on +#endif diff --git a/libs/core/include_local/tests/unit/CMakeLists.txt b/libs/core/include_local/tests/unit/CMakeLists.txt index 2f7420810a42..71fa49350983 100644 --- a/libs/core/include_local/tests/unit/CMakeLists.txt +++ b/libs/core/include_local/tests/unit/CMakeLists.txt @@ -1,5 +1,26 @@ -# Copyright (c) 2020-2021 The STE||AR-Group +# Copyright (c) 2020-2026 The STE||AR-Group # # SPDX-License-Identifier: BSL-1.0 # Distributed under the Boost Software License, Version 1.0. (See accompanying # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +set(tests local_header) + +set(local_header_FLAGS NOLIBS DEPENDENCIES hpx_core) + +foreach(test ${tests}) + set(sources ${test}.cpp) + + source_group("Source Files" FILES ${sources}) + + set(folder_name "Tests/Unit/Modules/Core/IncludeLocal") + + add_hpx_executable( + ${test}_test INTERNAL_FLAGS + SOURCES ${sources} ${${test}_FLAGS} + EXCLUDE_FROM_ALL + FOLDER ${folder_name} + ) + + add_hpx_unit_test("modules.include_local" ${test} ${${test}_PARAMETERS}) +endforeach() diff --git a/libs/core/include_local/tests/unit/local_header.cpp b/libs/core/include_local/tests/unit/local_header.cpp new file mode 100644 index 000000000000..a8da18cf9ffd --- /dev/null +++ b/libs/core/include_local/tests/unit/local_header.cpp @@ -0,0 +1,21 @@ +// Copyright (c) 2020-2026 The STE||AR-Group +// +// SPDX-License-Identifier: BSL-1.0 +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// Verify that the local headers are self-contained and provide access to the +// Standard Parallel Toolkit types: parallel algorithms, numeric algorithms, +// execution policies, and futures. +// +// This is a compile-and-link sanity check only. It does NOT start the HPX +// runtime, so it has no dependency on the wrap module (hpx_main.hpp) or on +// any specific HPX link target beyond hpx_core. + +#include + +int main() +{ + hpx::execution::parallel_policy p; + return 0; +} diff --git a/wrap/CMakeLists.txt b/wrap/CMakeLists.txt index 143952466006..d2d9bf230103 100644 --- a/wrap/CMakeLists.txt +++ b/wrap/CMakeLists.txt @@ -134,7 +134,11 @@ endif() if(HPX_WITH_DYNAMIC_HPX_MAIN) if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") target_link_libraries(hpx_wrap INTERFACE "-Wl,-wrap=main") + target_compile_definitions(hpx_wrap INTERFACE HPX_HAVE_WRAP_MAIN_CONFIGURED) target_link_libraries(hpx_auto_wrap INTERFACE "-Wl,-wrap=main") + target_compile_definitions( + hpx_auto_wrap INTERFACE HPX_HAVE_WRAP_MAIN_CONFIGURED + ) elseif(APPLE) target_link_libraries(hpx_wrap INTERFACE "-Wl,-e,_initialize_main") target_link_libraries(hpx_auto_wrap INTERFACE "-Wl,-e,_initialize_main") diff --git a/wrap/include/hpx/hpx_main.hpp b/wrap/include/hpx/hpx_main.hpp index 9b4077bba341..155f217fef9d 100644 --- a/wrap/include/hpx/hpx_main.hpp +++ b/wrap/include/hpx/hpx_main.hpp @@ -7,6 +7,7 @@ #pragma once +#include #include #if defined(HPX_HAVE_RUN_MAIN_EVERYWHERE)