Index | Thread | Search

From:
Theo Buehler <tb@theobuehler.org>
Subject:
[sparc64] build fix for abseil-cpp with gcc/15
To:
ports@openbsd.org
Cc:
Andrew Krasavin <noiseless-ak@yandex.ru>, Klemens Nanni <kn@openbsd.org>
Date:
Sat, 8 Nov 2025 16:51:07 +0100

Download raw body.

Thread
Just in case someone is interested in this diff. It builds with gcc/15
(no for need gnu++17 CXXFLAGS). It errors out building some test with
gcc/8. That can likely be fixed but I won't be the one debugging that.
I haven't tried with gcc/11 at all.

It is a somewhat intrusive patch adapted from
https://github.com/abseil/abseil-cpp/issues/1634#issuecomment-2576011026

Since upstream doesn't seem keen on fixing this, I'm not sure we would
really want this (once we switch to a newer gcc). The constant churn
happening in abseil makes it likely that it needs fixing and adapting on
every update. That's going to be tedious albeit rather straightforward.

I also have no idea why we need this when others seem to run into this
problem only when enabling some sanitiers.

Tests look reasonable on sparc64 and arm64.

Index: Makefile
===================================================================
RCS file: /cvs/ports/devel/abseil-cpp/Makefile,v
diff -u -p -r1.41 Makefile
--- Makefile	23 Sep 2025 18:46:30 -0000	1.41
+++ Makefile	7 Nov 2025 12:41:28 -0000
@@ -1,10 +1,9 @@
-BROKEN-sparc64 = is not a constant expression
-
 COMMENT =	abseil common libraries (C++)
 CATEGORIES =	devel
 
 V =		20250814.1
 DISTNAME =	abseil-cpp-${V}
+REVISION =	0
 
 HOMEPAGE =	https://abseil.io/
 SITES =		https://github.com/abseil/abseil-cpp/releases/download/${V}/
@@ -57,6 +56,8 @@ WANTLIB += ${COMPILER_LIBCXX} execinfo g
 COMPILER =		base-clang ports-gcc
 COMPILER_LANGS =	c++
 MODULES =		devel/cmake
+
+CXXFLAGS_ports-gcc =	-std=gnu++17
 
 CONFIGURE_ARGS =	-DBUILD_SHARED_LIBS=ON \
 			-DABSL_USE_EXTERNAL_GOOGLETEST=${LOCALBASE}/include/gtest \
Index: patches/patch-absl_container_flat_hash_map_h
===================================================================
RCS file: patches/patch-absl_container_flat_hash_map_h
diff -N patches/patch-absl_container_flat_hash_map_h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-absl_container_flat_hash_map_h	7 Nov 2025 12:41:10 -0000
@@ -0,0 +1,27 @@
+https://github.com/abseil/abseil-cpp/issues/1634#issuecomment-2576011026
+
+Index: absl/container/flat_hash_map.h
+--- absl/container/flat_hash_map.h.orig
++++ absl/container/flat_hash_map.h
+@@ -34,6 +34,7 @@
+ 
+ #include <cstddef>
+ #include <memory>
++#include <optional>
+ #include <type_traits>
+ #include <utility>
+ 
+@@ -661,10 +662,10 @@ struct FlatHashMapPolicy {
+   }
+ 
+   template <class Hash, bool kIsDefault>
+-  static constexpr HashSlotFn get_hash_slot_fn() {
++  static constexpr std::optional<HashSlotFn> get_hash_slot_fn() {
+     return memory_internal::IsLayoutCompatible<K, V>::value
+-               ? &TypeErasedApplyToSlotFn<Hash, K, kIsDefault>
+-               : nullptr;
++               ? std::optional<HashSlotFn>(&TypeErasedApplyToSlotFn<Hash, K, kIsDefault>)
++               : std::nullopt;
+   }
+ 
+   static size_t space_used(const slot_type*) { return 0; }
Index: patches/patch-absl_container_flat_hash_set_h
===================================================================
RCS file: patches/patch-absl_container_flat_hash_set_h
diff -N patches/patch-absl_container_flat_hash_set_h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-absl_container_flat_hash_set_h	7 Nov 2025 12:41:10 -0000
@@ -0,0 +1,24 @@
+https://github.com/abseil/abseil-cpp/issues/1634#issuecomment-2576011026
+
+Index: absl/container/flat_hash_set.h
+--- absl/container/flat_hash_set.h.orig
++++ absl/container/flat_hash_set.h
+@@ -34,6 +34,7 @@
+ 
+ #include <cstddef>
+ #include <memory>
++#include <optional>
+ #include <type_traits>
+ #include <utility>
+ 
+@@ -559,8 +560,8 @@ struct FlatHashSetPolicy {
+   static size_t space_used(const T*) { return 0; }
+ 
+   template <class Hash, bool kIsDefault>
+-  static constexpr HashSlotFn get_hash_slot_fn() {
+-    return &TypeErasedApplyToSlotFn<Hash, T, kIsDefault>;
++  static constexpr std::optional<HashSlotFn> get_hash_slot_fn() {
++    return std::optional<HashSlotFn>(&TypeErasedApplyToSlotFn<Hash, T, kIsDefault>);
+   }
+ };
+ }  // namespace container_internal
Index: patches/patch-absl_container_internal_hash_policy_traits_h
===================================================================
RCS file: patches/patch-absl_container_internal_hash_policy_traits_h
diff -N patches/patch-absl_container_internal_hash_policy_traits_h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-absl_container_internal_hash_policy_traits_h	7 Nov 2025 12:41:10 -0000
@@ -0,0 +1,17 @@
+https://github.com/abseil/abseil-cpp/issues/1634#issuecomment-2576011026
+
+Index: absl/container/internal/hash_policy_traits.h
+--- absl/container/internal/hash_policy_traits.h.orig
++++ absl/container/internal/hash_policy_traits.h
+@@ -155,9 +155,9 @@ struct hash_policy_traits : common_policy_traits<Polic
+ // silent error: the address of * will never be NULL [-Werror=address]
+ #pragma GCC diagnostic ignored "-Waddress"
+ #endif
+-    return Policy::template get_hash_slot_fn<Hash, kIsDefault>() == nullptr
++    return !Policy::template get_hash_slot_fn<Hash, kIsDefault>().has_value()
+                ? &hash_slot_fn_non_type_erased<Hash, kIsDefault>
+-               : Policy::template get_hash_slot_fn<Hash, kIsDefault>();
++               : Policy::template get_hash_slot_fn<Hash, kIsDefault>().value();
+ #if defined(__GNUC__) && !defined(__clang__)
+ #pragma GCC diagnostic pop
+ #endif
Index: patches/patch-absl_container_internal_hash_policy_traits_test_cc
===================================================================
RCS file: patches/patch-absl_container_internal_hash_policy_traits_test_cc
diff -N patches/patch-absl_container_internal_hash_policy_traits_test_cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-absl_container_internal_hash_policy_traits_test_cc	7 Nov 2025 12:41:10 -0000
@@ -0,0 +1,46 @@
+https://github.com/abseil/abseil-cpp/issues/1634#issuecomment-2576011026
+
+Index: absl/container/internal/hash_policy_traits_test.cc
+--- absl/container/internal/hash_policy_traits_test.cc.orig
++++ absl/container/internal/hash_policy_traits_test.cc
+@@ -18,6 +18,7 @@
+ #include <functional>
+ #include <memory>
+ #include <new>
++#include <optional>
+ 
+ #include "gmock/gmock.h"
+ #include "gtest/gtest.h"
+@@ -46,8 +47,8 @@ struct PolicyWithoutOptionalOps {
+   static std::function<Slot&(Slot*)> value;
+ 
+   template <class Hash, bool kIsDefault>
+-  static constexpr HashSlotFn get_hash_slot_fn() {
+-    return nullptr;
++  static constexpr std::optional<HashSlotFn> get_hash_slot_fn() {
++    return std::nullopt;
+   }
+ };
+ 
+@@ -100,8 +101,8 @@ struct PolicyNoHashFn {
+   }
+ 
+   template <class Hash, bool kIsDefault>
+-  static constexpr HashSlotFn get_hash_slot_fn() {
+-    return nullptr;
++  static constexpr std::optional<HashSlotFn> get_hash_slot_fn() {
++    return std::nullopt;
+   }
+ };
+ 
+@@ -109,8 +110,8 @@ size_t* PolicyNoHashFn::apply_called_count;
+ 
+ struct PolicyCustomHashFn : PolicyNoHashFn {
+   template <class Hash, bool kIsDefault>
+-  static constexpr HashSlotFn get_hash_slot_fn() {
+-    return &TypeErasedApplyToSlotFn<Hash, int, kIsDefault>;
++  static constexpr std::optional<HashSlotFn> get_hash_slot_fn() {
++    return std::optional<HashSlotFn>(&TypeErasedApplyToSlotFn<Hash, int, kIsDefault>);
+   }
+ };
+ 
Index: patches/patch-absl_container_internal_raw_hash_set_allocator_test_cc
===================================================================
RCS file: patches/patch-absl_container_internal_raw_hash_set_allocator_test_cc
diff -N patches/patch-absl_container_internal_raw_hash_set_allocator_test_cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-absl_container_internal_raw_hash_set_allocator_test_cc	7 Nov 2025 12:41:10 -0000
@@ -0,0 +1,24 @@
+https://github.com/abseil/abseil-cpp/issues/1634#issuecomment-2576011026
+
+Index: absl/container/internal/raw_hash_set_allocator_test.cc
+--- absl/container/internal/raw_hash_set_allocator_test.cc.orig
++++ absl/container/internal/raw_hash_set_allocator_test.cc
+@@ -17,6 +17,7 @@
+ #include <functional>
+ #include <limits>
+ #include <memory>
++#include <optional>
+ #include <ostream>
+ #include <set>
+ #include <type_traits>
+@@ -181,8 +182,8 @@ struct Policy {
+   static slot_type& element(slot_type* slot) { return *slot; }
+ 
+   template <class Hash, bool kIsDefault>
+-  static constexpr HashSlotFn get_hash_slot_fn() {
+-    return nullptr;
++  static constexpr std::optional<HashSlotFn> get_hash_slot_fn() {
++    return std::nullopt;
+   }
+ };
+ 
Index: patches/patch-absl_container_internal_raw_hash_set_benchmark_cc
===================================================================
RCS file: patches/patch-absl_container_internal_raw_hash_set_benchmark_cc
diff -N patches/patch-absl_container_internal_raw_hash_set_benchmark_cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-absl_container_internal_raw_hash_set_benchmark_cc	7 Nov 2025 12:41:10 -0000
@@ -0,0 +1,35 @@
+https://github.com/abseil/abseil-cpp/issues/1634#issuecomment-2576011026
+
+Index: absl/container/internal/raw_hash_set_benchmark.cc
+--- absl/container/internal/raw_hash_set_benchmark.cc.orig
++++ absl/container/internal/raw_hash_set_benchmark.cc
+@@ -18,6 +18,7 @@
+ #include <cstddef>
+ #include <cstdint>
+ #include <limits>
++#include <optional>
+ #include <numeric>
+ #include <random>
+ #include <string>
+@@ -65,8 +66,8 @@ struct IntPolicy {
+   }
+ 
+   template <class Hash, bool kIsDefault>
+-  static constexpr HashSlotFn get_hash_slot_fn() {
+-    return nullptr;
++  static constexpr std::optional<HashSlotFn> get_hash_slot_fn() {
++    return std::nullopt;
+   }
+ };
+ 
+@@ -128,8 +129,8 @@ class StringPolicy {
+   }
+ 
+   template <class Hash, bool kIsDefault>
+-  static constexpr HashSlotFn get_hash_slot_fn() {
+-    return nullptr;
++  static constexpr std::optional<HashSlotFn> get_hash_slot_fn() {
++    return std::nullopt;
+   }
+ };
+ 
Index: patches/patch-absl_container_internal_raw_hash_set_probe_benchmark_cc
===================================================================
RCS file: patches/patch-absl_container_internal_raw_hash_set_probe_benchmark_cc
diff -N patches/patch-absl_container_internal_raw_hash_set_probe_benchmark_cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-absl_container_internal_raw_hash_set_probe_benchmark_cc	7 Nov 2025 12:41:10 -0000
@@ -0,0 +1,22 @@
+https://github.com/abseil/abseil-cpp/issues/1634#issuecomment-2576011026
+
+Index: absl/container/internal/raw_hash_set_probe_benchmark.cc
+--- absl/container/internal/raw_hash_set_probe_benchmark.cc.orig
++++ absl/container/internal/raw_hash_set_probe_benchmark.cc
+@@ -16,6 +16,7 @@
+ // distributions, all using the default hash function for swisstable.
+ 
+ #include <memory>
++#include <optional>
+ #include <regex>  // NOLINT
+ #include <vector>
+ 
+@@ -73,7 +74,7 @@ struct Policy {
+ 
+   template <class Hash, bool kIsDefault>
+   static constexpr auto get_hash_slot_fn() {
+-    return nullptr;
++    return std::nullopt;
+   }
+ };
+ 
Index: patches/patch-absl_container_internal_raw_hash_set_test_cc
===================================================================
RCS file: patches/patch-absl_container_internal_raw_hash_set_test_cc
diff -N patches/patch-absl_container_internal_raw_hash_set_test_cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-absl_container_internal_raw_hash_set_test_cc	7 Nov 2025 12:41:10 -0000
@@ -0,0 +1,46 @@
+https://github.com/abseil/abseil-cpp/issues/1634#issuecomment-2576011026
+
+Index: absl/container/internal/raw_hash_set_test.cc
+--- absl/container/internal/raw_hash_set_test.cc.orig
++++ absl/container/internal/raw_hash_set_test.cc
+@@ -31,6 +31,7 @@
+ #include <map>
+ #include <memory>
+ #include <numeric>
++#include <optional>
+ #include <ostream>
+ #include <random>
+ #include <set>
+@@ -387,8 +388,8 @@ struct ValuePolicy {
+   }
+ 
+   template <class Hash, bool kIsDefault>
+-  static constexpr HashSlotFn get_hash_slot_fn() {
+-    return nullptr;
++  static constexpr std::optional<HashSlotFn> get_hash_slot_fn() {
++    return std::nullopt;
+   }
+ 
+   static constexpr bool soo_enabled() { return kSoo; }
+@@ -535,8 +536,8 @@ class StringPolicy {
+   }
+ 
+   template <class Hash, bool kIsDefault>
+-  static constexpr HashSlotFn get_hash_slot_fn() {
+-    return nullptr;
++  static constexpr std::optional<HashSlotFn> get_hash_slot_fn() {
++    return std::nullopt;
+   }
+ };
+ 
+@@ -1132,8 +1133,8 @@ struct DecomposePolicy {
+   }
+ 
+   template <class Hash, bool kIsDefault>
+-  static constexpr HashSlotFn get_hash_slot_fn() {
+-    return nullptr;
++  static constexpr std::optional<HashSlotFn> get_hash_slot_fn() {
++    return std::nullopt;
+   }
+ };
+ 
Index: patches/patch-absl_container_node_hash_map_h
===================================================================
RCS file: patches/patch-absl_container_node_hash_map_h
diff -N patches/patch-absl_container_node_hash_map_h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-absl_container_node_hash_map_h	7 Nov 2025 12:41:10 -0000
@@ -0,0 +1,27 @@
+https://github.com/abseil/abseil-cpp/issues/1634#issuecomment-2576011026
+
+Index: absl/container/node_hash_map.h
+--- absl/container/node_hash_map.h.orig
++++ absl/container/node_hash_map.h
+@@ -40,6 +40,7 @@
+ 
+ #include <cstddef>
+ #include <memory>
++#include <optional>
+ #include <type_traits>
+ #include <utility>
+ 
+@@ -664,10 +665,10 @@ class NodeHashMapPolicy
+   static const Value& value(const value_type* elem) { return elem->second; }
+ 
+   template <class Hash, bool kIsDefault>
+-  static constexpr HashSlotFn get_hash_slot_fn() {
++  static constexpr std::optional<HashSlotFn> get_hash_slot_fn() {
+     return memory_internal::IsLayoutCompatible<Key, Value>::value
+-               ? &TypeErasedDerefAndApplyToSlotFn<Hash, Key, kIsDefault>
+-               : nullptr;
++               ? std::optional<HashSlotFn>(&TypeErasedDerefAndApplyToSlotFn<Hash, Key, kIsDefault>)
++               : std::nullopt;
+   }
+ };
+ }  // namespace container_internal
Index: patches/patch-absl_container_node_hash_set_h
===================================================================
RCS file: patches/patch-absl_container_node_hash_set_h
diff -N patches/patch-absl_container_node_hash_set_h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-absl_container_node_hash_set_h	7 Nov 2025 12:41:10 -0000
@@ -0,0 +1,24 @@
+https://github.com/abseil/abseil-cpp/issues/1634#issuecomment-2576011026
+
+Index: absl/container/node_hash_set.h
+--- absl/container/node_hash_set.h.orig
++++ absl/container/node_hash_set.h
+@@ -39,6 +39,7 @@
+ 
+ #include <cstddef>
+ #include <memory>
++#include <optional>
+ #include <type_traits>
+ 
+ #include "absl/algorithm/container.h"
+@@ -558,8 +559,8 @@ struct NodeHashSetPolicy
+   static size_t element_space_used(const T*) { return sizeof(T); }
+ 
+   template <class Hash, bool kIsDefault>
+-  static constexpr HashSlotFn get_hash_slot_fn() {
+-    return &TypeErasedDerefAndApplyToSlotFn<Hash, T, kIsDefault>;
++  static constexpr std::optional<HashSlotFn> get_hash_slot_fn() {
++    return std::optional<HashSlotFn>(&TypeErasedDerefAndApplyToSlotFn<Hash, T, kIsDefault>);
+   }
+ };
+ }  // namespace container_internal