From c11d108da4cee0e88b0872153629b392f806ef71 Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Tue, 24 Nov 2026 17:59:27 -0600 Subject: [PATCH 1/4] Put the full version into the SONAME of the HPX libraries HPX keeps no ABI compatibility between releases, but the SONAME of its libraries held only the major version (libhpx.so.2). The dynamic loader therefore accepted the libraries of any 2.x release for a binary built against another one, which then ran with a mismatched ABI. Use the full version (libhpx.so.2.1.0), as Boost does: a binary built against another release now fails to start instead. Signed-off-by: Hartmut Kaiser --- CMakeLists.txt | 6 +++++- docs/sphinx/api.rst | 5 ++++- docs/sphinx/releases/whats_new_2_1_0.rst | 6 ++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 97531b187040..8290cd6b741b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,7 +75,11 @@ set(HPX_VERSION_FULL ) set(HPX_LIBRARY_VERSION "${HPX_VERSION}") -set(HPX_SOVERSION ${HPX_VERSION_MAJOR}) +# HPX does not keep its ABI stable between any two releases, so the SONAME of +# its libraries holds the full version: a binary built against one release +# doesn't start with the libraries of another, instead of silently using a +# mismatched ABI +set(HPX_SOVERSION "${HPX_VERSION}") set(HPX_PACKAGE_NAME HPX) # To keep track of the hpx_root when other subprojects are declared set(HPX_SOURCE_DIR "${PROJECT_SOURCE_DIR}") diff --git a/docs/sphinx/api.rst b/docs/sphinx/api.rst index ae9bd890b0aa..252830e1af54 100644 --- a/docs/sphinx/api.rst +++ b/docs/sphinx/api.rst @@ -16,7 +16,10 @@ two minor releases. In rare cases do we outright remove old and unused functionality without a deprecation period. We do not provide any ABI compatibility guarantees between any versions, debug -and release builds, and builds with different C++ standards. +and release builds, and builds with different C++ standards. The shared +libraries of |hpx| therefore carry the full version in their SONAME (for +instance ``libhpx.so.2.1.0``): an application built against one release does +not start with the libraries of another release, it has to be rebuilt. .. We follow |semver|_ for our API (starting from |hpx| 2.0.0). This means that diff --git a/docs/sphinx/releases/whats_new_2_1_0.rst b/docs/sphinx/releases/whats_new_2_1_0.rst index 6d6087c339a2..9b0228e9770f 100644 --- a/docs/sphinx/releases/whats_new_2_1_0.rst +++ b/docs/sphinx/releases/whats_new_2_1_0.rst @@ -83,6 +83,12 @@ Breaking changes ``hpx/hpx_main.hpp`` has to link ``HPX::wrap_main`` (or ``HPX::auto_wrap_main``), which was previously avoidable by setting the option to ``OFF``. +- The SONAME of the |hpx| libraries now holds the full version (for instance + ``libhpx.so.2.1.0`` instead of ``libhpx.so.2``), as |hpx| keeps no ABI + compatibility between releases. Applications and libraries built against an + earlier release no longer start with the libraries of this one, instead of + running with a mismatched ABI; rebuild them. This also applies to the + components and plugins of |hpx|. Windows is not affected. Supervision Module ================== From 01513a7505040f4683875d44ac93e94f9008aafa Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Tue, 24 Nov 2026 18:29:25 -0600 Subject: [PATCH 2/4] Make the version check work, also on Windows libhpx_core had no version in its SONAME at all, give it the same version as the other libraries. Every translation unit outside the core library was meant to refer to hpx_check_version__ exported from the core library, so that a binary built against another version doesn't load. The reference sat in an unused function that the compiler removed, so no binary carried it. The symbol now holds the full version, has C linkage, and the reference survives: GCC and Clang keep a variable marked 'used', MSVC includes the symbol through a linker directive. A binary built against another release now fails to load on Windows as well (entry point not found), where DLL names carry no version. Signed-off-by: Hartmut Kaiser --- docs/sphinx/api.rst | 4 +- docs/sphinx/releases/whats_new_2_1_0.rst | 11 ++-- libs/CMakeLists.txt | 6 +++ .../cmake/templates/config_version.hpp.in | 50 ++++++++++++------- 4 files changed, 48 insertions(+), 23 deletions(-) diff --git a/docs/sphinx/api.rst b/docs/sphinx/api.rst index 252830e1af54..f5d514c82a98 100644 --- a/docs/sphinx/api.rst +++ b/docs/sphinx/api.rst @@ -18,7 +18,9 @@ functionality without a deprecation period. We do not provide any ABI compatibility guarantees between any versions, debug and release builds, and builds with different C++ standards. The shared libraries of |hpx| therefore carry the full version in their SONAME (for -instance ``libhpx.so.2.1.0``): an application built against one release does +instance ``libhpx.so.2.1.0``), and every binary built against |hpx| refers to +a symbol of the core library that names the full version (for instance +``hpx_check_version_2_1_0``): an application built against one release does not start with the libraries of another release, it has to be rebuilt. .. diff --git a/docs/sphinx/releases/whats_new_2_1_0.rst b/docs/sphinx/releases/whats_new_2_1_0.rst index 9b0228e9770f..e073846df0a4 100644 --- a/docs/sphinx/releases/whats_new_2_1_0.rst +++ b/docs/sphinx/releases/whats_new_2_1_0.rst @@ -85,10 +85,13 @@ Breaking changes option to ``OFF``. - The SONAME of the |hpx| libraries now holds the full version (for instance ``libhpx.so.2.1.0`` instead of ``libhpx.so.2``), as |hpx| keeps no ABI - compatibility between releases. Applications and libraries built against an - earlier release no longer start with the libraries of this one, instead of - running with a mismatched ABI; rebuild them. This also applies to the - components and plugins of |hpx|. Windows is not affected. + compatibility between releases. ``libhpx_core`` had no version in its + SONAME before. In addition, every binary built against |hpx| now refers to + the symbol ``hpx_check_version_2_1_0`` of the core library, also on + Windows. Applications and libraries built against an earlier release no + longer start with the libraries of this one, instead of running with a + mismatched ABI; rebuild them. Defining ``HPX_NO_VERSION_CHECK`` before + including any |hpx| header leaves out the reference to that symbol. Supervision Module ================== diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index 718ada7e3f02..88783d0ab62b 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -399,6 +399,12 @@ foreach(lib ${HPX_LIBS}) target_compile_definitions(hpx_${lib} PRIVATE HPX_${uppercase_lib}_EXPORTS) set_target_properties(hpx_${lib} PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(hpx_${lib} PROPERTIES FOLDER "Core") + if(DEFINED HPX_LIBRARY_VERSION AND DEFINED HPX_SOVERSION) + set_target_properties( + hpx_${lib} PROPERTIES VERSION ${HPX_LIBRARY_VERSION} SOVERSION + ${HPX_SOVERSION} + ) + endif() add_subdirectory(${lib}) diff --git a/libs/core/config/cmake/templates/config_version.hpp.in b/libs/core/config/cmake/templates/config_version.hpp.in index 4f44f57cca0c..57a5b35ac999 100644 --- a/libs/core/config/cmake/templates/config_version.hpp.in +++ b/libs/core/config/cmake/templates/config_version.hpp.in @@ -50,11 +50,15 @@ #endif /////////////////////////////////////////////////////////////////////////////// -// The version check enforces the major and minor version numbers to match for -// every compilation unit to be compiled. +// The name of the symbol the version check refers to, it holds the full +// version (for instance hpx_check_version_2_1_0): HPX keeps no ABI +// compatibility between releases. #define HPX_CHECK_VERSION \ HPX_PP_CAT(hpx_check_version_, \ - HPX_PP_CAT(HPX_VERSION_MAJOR, HPX_PP_CAT(_, HPX_VERSION_MINOR))) \ + HPX_PP_CAT(HPX_VERSION_MAJOR, \ + HPX_PP_CAT(_, \ + HPX_PP_CAT(HPX_VERSION_MINOR, \ + HPX_PP_CAT(_, HPX_VERSION_SUBMINOR))))) \ /**/ // The version check enforces the major and minor version numbers to match for @@ -66,27 +70,37 @@ /////////////////////////////////////////////////////////////////////////////// namespace hpx { // Helper data structures allowing to automatically detect version problems - // between applications and the core libraries. - HPX_CORE_EXPORT extern char const HPX_CHECK_VERSION[]; + // between applications and the core libraries. C linkage keeps the symbol + // name undecorated for the linker directive below. + extern "C" HPX_CORE_EXPORT char const HPX_CHECK_VERSION[]; HPX_CORE_EXPORT extern char const HPX_CHECK_BOOST_VERSION[]; } // namespace hpx /////////////////////////////////////////////////////////////////////////////// #if !defined(HPX_CORE_EXPORTS) && !defined(HPX_NO_VERSION_CHECK) -// This is instantiated for each translation unit outside the HPX core -// library, forcing to resolve the variable HPX_CHECK_VERSION. -namespace { - // Note: this function is never executed. -#if defined(__GNUG__) || defined(__clang__) - __attribute__((unused)) +// Every binary built from a translation unit outside the HPX core library +// refers to HPX_CHECK_VERSION. Such a binary doesn't load with the core +// library of another release (the loader reports the missing symbol), instead +// of running with a mismatched ABI. The reference has to survive optimization. +#if defined(_MSC_VER) +// MSVC has no attribute that keeps an unreferenced variable: let the linker +// include the symbol instead (32-bit x86 prefixes C names with '_') +#if defined(_M_IX86) +#define HPX_CHECK_VERSION_SYMBOL "_" HPX_PP_STRINGIZE(HPX_CHECK_VERSION) +#else +#define HPX_CHECK_VERSION_SYMBOL HPX_PP_STRINGIZE(HPX_CHECK_VERSION) #endif - char const* - check_hpx_version() - { - char const* versions[] = { - hpx::HPX_CHECK_VERSION, hpx::HPX_CHECK_BOOST_VERSION}; - return versions[0]; - } +#if !defined(HPX_MODULE_STATIC_LINKING) && !defined(HPX_HAVE_STATIC_LINKING) +#pragma comment(linker, "/include:__imp_" HPX_CHECK_VERSION_SYMBOL) +#else +#pragma comment(linker, "/include:" HPX_CHECK_VERSION_SYMBOL) +#endif +#undef HPX_CHECK_VERSION_SYMBOL +#elif defined(__GNUC__) || defined(__clang__) +namespace { + __attribute__((used)) char const* const hpx_check_version_reference = + hpx::HPX_CHECK_VERSION; } // namespace #endif +#endif From a8c5378df0ba3c6799c7e74103ea163b3fb7a32d Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Tue, 24 Nov 2026 18:30:53 -0600 Subject: [PATCH 3/4] Export the version check symbol from the core C++ module Signed-off-by: Hartmut Kaiser --- libs/core/config/cmake/templates/config_version.hpp.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/core/config/cmake/templates/config_version.hpp.in b/libs/core/config/cmake/templates/config_version.hpp.in index 57a5b35ac999..70de5e057ebb 100644 --- a/libs/core/config/cmake/templates/config_version.hpp.in +++ b/libs/core/config/cmake/templates/config_version.hpp.in @@ -72,7 +72,8 @@ namespace hpx { // Helper data structures allowing to automatically detect version problems // between applications and the core libraries. C linkage keeps the symbol // name undecorated for the linker directive below. - extern "C" HPX_CORE_EXPORT char const HPX_CHECK_VERSION[]; + HPX_CXX_CORE_EXPORT extern "C" HPX_CORE_EXPORT char const + HPX_CHECK_VERSION[]; HPX_CORE_EXPORT extern char const HPX_CHECK_BOOST_VERSION[]; } // namespace hpx From 26647a2c0e9c0e32f8dcf4cabf34d58747951651 Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Tue, 24 Nov 2026 19:53:50 -0600 Subject: [PATCH 4/4] Address review comments on the version check - Docs: the SONAME holds the full version only on platforms with SONAMEs (not Windows and Android); the version symbol is referenced everywhere. - Docs: binaries and libraries of earlier releases are not protected, remove an earlier installation before installing into the same prefix. - Mark the reference to the version symbol 'retain' on ELF where supported, so that --gc-sections doesn't drop it. Signed-off-by: Hartmut Kaiser --- docs/sphinx/api.rst | 16 ++++++++----- docs/sphinx/releases/whats_new_2_1_0.rst | 23 +++++++++++-------- .../cmake/templates/config_version.hpp.in | 13 ++++++++++- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/docs/sphinx/api.rst b/docs/sphinx/api.rst index f5d514c82a98..4367d7179902 100644 --- a/docs/sphinx/api.rst +++ b/docs/sphinx/api.rst @@ -16,12 +16,16 @@ two minor releases. In rare cases do we outright remove old and unused functionality without a deprecation period. We do not provide any ABI compatibility guarantees between any versions, debug -and release builds, and builds with different C++ standards. The shared -libraries of |hpx| therefore carry the full version in their SONAME (for -instance ``libhpx.so.2.1.0``), and every binary built against |hpx| refers to -a symbol of the core library that names the full version (for instance -``hpx_check_version_2_1_0``): an application built against one release does -not start with the libraries of another release, it has to be rebuilt. +and release builds, and builds with different C++ standards. Every binary +built against |hpx| therefore refers to a symbol of the core library that names +the full version (for instance ``hpx_check_version_2_1_0``), and on platforms +with SONAMEs (Linux, macOS and other Unix systems, but not Android) the shared +libraries of |hpx| carry the full version in their SONAME (for instance +``libhpx.so.2.1.0``): an application built against one release does not start +with the libraries of another release, it has to be rebuilt. This protects +only binaries built against |hpx| V2.1.0 or later. Remove an installation of +an earlier release before installing |hpx| into the same location, and rebuild +the binaries built against it. .. We follow |semver|_ for our API (starting from |hpx| 2.0.0). This means that diff --git a/docs/sphinx/releases/whats_new_2_1_0.rst b/docs/sphinx/releases/whats_new_2_1_0.rst index e073846df0a4..435cd6919b45 100644 --- a/docs/sphinx/releases/whats_new_2_1_0.rst +++ b/docs/sphinx/releases/whats_new_2_1_0.rst @@ -83,15 +83,20 @@ Breaking changes ``hpx/hpx_main.hpp`` has to link ``HPX::wrap_main`` (or ``HPX::auto_wrap_main``), which was previously avoidable by setting the option to ``OFF``. -- The SONAME of the |hpx| libraries now holds the full version (for instance - ``libhpx.so.2.1.0`` instead of ``libhpx.so.2``), as |hpx| keeps no ABI - compatibility between releases. ``libhpx_core`` had no version in its - SONAME before. In addition, every binary built against |hpx| now refers to - the symbol ``hpx_check_version_2_1_0`` of the core library, also on - Windows. Applications and libraries built against an earlier release no - longer start with the libraries of this one, instead of running with a - mismatched ABI; rebuild them. Defining ``HPX_NO_VERSION_CHECK`` before - including any |hpx| header leaves out the reference to that symbol. +- Every binary built against |hpx| now refers to the symbol + ``hpx_check_version_2_1_0`` of the core library, on all platforms. On + platforms with SONAMEs (not Windows and Android), the SONAME of the |hpx| + libraries now holds the full version as well (for instance + ``libhpx.so.2.1.0`` instead of ``libhpx.so.2``); ``libhpx_core`` had no + version in its SONAME before. |hpx| keeps no ABI compatibility between + releases: a binary built against one release no longer starts with the + libraries of another one, instead of running with a mismatched ABI. + Binaries built against earlier releases don't carry this check, and the + libraries of those releases still find the new core library under its + unversioned name: remove an earlier installation before installing this + release into the same location, and rebuild the binaries built against it. + Defining ``HPX_NO_VERSION_CHECK`` before including any |hpx| header leaves + out the reference to the symbol. Supervision Module ================== diff --git a/libs/core/config/cmake/templates/config_version.hpp.in b/libs/core/config/cmake/templates/config_version.hpp.in index 70de5e057ebb..a9a6efe09a3b 100644 --- a/libs/core/config/cmake/templates/config_version.hpp.in +++ b/libs/core/config/cmake/templates/config_version.hpp.in @@ -99,9 +99,20 @@ namespace hpx { #endif #undef HPX_CHECK_VERSION_SYMBOL #elif defined(__GNUC__) || defined(__clang__) +// 'used' keeps the variable from the compiler, 'retain' (ELF only) keeps its +// section from the linker's garbage collection (--gc-sections) +#if defined(__ELF__) && defined(__has_attribute) +#if __has_attribute(retain) +#define HPX_CHECK_VERSION_KEEP __attribute__((used, retain)) +#endif +#endif +#if !defined(HPX_CHECK_VERSION_KEEP) +#define HPX_CHECK_VERSION_KEEP __attribute__((used)) +#endif namespace { - __attribute__((used)) char const* const hpx_check_version_reference = + HPX_CHECK_VERSION_KEEP char const* const hpx_check_version_reference = hpx::HPX_CHECK_VERSION; } // namespace +#undef HPX_CHECK_VERSION_KEEP #endif #endif