package/libabseil-cpp: add patch to fix build with gcc <= 12

libabseil-cpp headers can break some packages build, like protobuf,
when compiled with gcc 12. See [1] [2]. The issue has been reported
in protobuf upstream, in [3].

The issue is due to gcc <= 12 not supporting the mix of standard
C++ attributes with GNU attributes. See [4].

Gcc 12 has been removed from Buildroot internal toolchains in
commit [5], but gcc 12 can still be present in external toolchains
or on the host. This is currently the case of the Buildroot Docker
reference image, based on Debian 12 (Bookworm).

This commit fixes the issue by adding a package patch.

Fixes:
- [1] [2] and many more.

[1] https://gitlab.com/buildroot.org/buildroot/-/jobs/13904066346
[2] https://autobuild.buildroot.org/results/33f6cfd37cb48c15a53b3e7123d5ce8388a0f2ab
[3] https://github.com/protocolbuffers/protobuf/issues/26383
[4] https://gcc.gnu.org/PR69585
[5] 58cf7c51da
[6] https://github.com/abseil/abseil-cpp/pull/2044

Signed-off-by: Julien Olivain <ju.o@free.fr>
Signed-off-by: Romain Naour <romain.naour@smile.fr>
(cherry picked from commit 955fb2f7c4)
Signed-off-by: Thomas Perale <thomas.perale@mind.be>
This commit is contained in:
Julien Olivain
2026-04-27 22:16:06 +02:00
committed by Thomas Perale
parent 843b2dffcb
commit 2ebb05124c

View File

@@ -0,0 +1,55 @@
From 77326826119439c06e341c9d090633ecd9b520d6 Mon Sep 17 00:00:00 2001
From: Julien Olivain <ju.o@free.fr>
Date: Mon, 27 Apr 2026 19:38:19 +0200
Subject: [PATCH] base: fix ABSL_ATTRIBUTE_WARN_UNUSED with gcc <= 12
Gcc <= 12 does not support mixing standard C++ attributes with
GNU attributes. See [1].
This can lead to build failures such as [2] [3] and [4]. In those
situations, the compilation fails with error such as:
/usr/include/absl/base/attributes.h:1076:36: error: expected identifier before '[' token
Gcc maintainers mentioned in [1] comment 9 that this bugfix will
not be backported in Gcc 12. Gcc 12 is still used in LTS
distributions. For example, it is included in Debian 12 (Bookworm),
which is still supported until 2028. See [5].
This commit adds a workaround for gcc <= 12 which uses
__attribute__ in that case, which fixes the compilation failure.
[1] https://gcc.gnu.org/PR69585
[2] https://github.com/protocolbuffers/protobuf/issues/26383
[3] https://autobuild.buildroot.org/results/33f6cfd37cb48c15a53b3e7123d5ce8388a0f2ab/build-end.log
[4] https://gitlab.com/buildroot.org/buildroot/-/jobs/13904066346
[5] https://www.debian.org/releases/bookworm/
Upstream: https://github.com/abseil/abseil-cpp/pull/2044
Signed-off-by: Julien Olivain <ju.o@free.fr>
---
absl/base/attributes.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/absl/base/attributes.h b/absl/base/attributes.h
index 5887fcaf..a26143e1 100644
--- a/absl/base/attributes.h
+++ b/absl/base/attributes.h
@@ -1092,7 +1092,14 @@ struct AbslInternal_YouForgotToExplicitlyInitializeAField {
// See https://clang.llvm.org/docs/AttributeReference.html#warn-unused and
// https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html#index-warn_005funused-type-attribute
#if ABSL_HAVE_CPP_ATTRIBUTE(gnu::warn_unused)
+// Only GCC >= 13 allows mixing standard and gnu attributes.
+// In case of gcc < 13, fallback on using __attribute__.
+// https://gcc.gnu.org/PR69585
+#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 13
+#define ABSL_ATTRIBUTE_WARN_UNUSED __attribute__((warn_unused))
+#else
#define ABSL_ATTRIBUTE_WARN_UNUSED [[gnu::warn_unused]]
+#endif
#else
#define ABSL_ATTRIBUTE_WARN_UNUSED
#endif
--
2.54.0