Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/core/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions libs/core/config/include/hpx/config/static_linker_check.hpp
Original file line number Diff line number Diff line change
@@ -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 <hpx/config/defines.hpp>

#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
23 changes: 22 additions & 1 deletion libs/core/include_local/tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
21 changes: 21 additions & 0 deletions libs/core/include_local/tests/unit/local_header.cpp
Original file line number Diff line number Diff line change
@@ -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 <hpx/execution.hpp>

int main()
{
hpx::execution::parallel_policy p;
return 0;
}
4 changes: 4 additions & 0 deletions wrap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions wrap/include/hpx/hpx_main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#pragma once

#include <hpx/config/static_linker_check.hpp>
#include <hpx/wrap_main.hpp>

#if defined(HPX_HAVE_RUN_MAIN_EVERYWHERE)
Expand Down
Loading