pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: "devel/protobuf" build fails on netbsd-9/i386



> It's of course great to figure out what's going on.  

https://github.com/protocolbuffers/protobuf/blame/656d0ea62b1016b0d45546053f5a20b8ea2f9e1b/src/google/protobuf/arenastring.cc#L51
---
namespace  {

// Enforce that allocated data aligns to at least 8 bytes, and that
// the alignment of the global const string value does as well.
// The alignment guaranteed by `new std::string` depends on both:
// - new align = __STDCPP_DEFAULT_NEW_ALIGNMENT__ / max_align_t
// - alignof(std::string)
#ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
constexpr size_t kNewAlign = __STDCPP_DEFAULT_NEW_ALIGNMENT__;
#elif (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40900
constexpr size_t kNewAlign = alignof(::max_align_t);
#else
constexpr size_t kNewAlign = alignof(std::max_align_t);
#endif
constexpr size_t kStringAlign = alignof(std::string);

static_assert((kStringAlign > kNewAlign ? kStringAlign : kNewAlign) >= 8, "");
static_assert(alignof(ExplicitlyConstructedArenaString) >= 8, "");

}  // namespace
---

Google search says __STDCPP_DEFAULT_NEW_ALIGNMENT__ is introduced
in C++17:
 https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0035r4.html

Per grep'ing gcc(1) man page, it also has '-faligned-new' options:
---
       -faligned-new
           Enable support for C++17 "new" of types that require more alignment
           than "void* ::operator new(std::size_t)" provides.  A numeric
           argument such as "-faligned-new=32" can be used to specify how much
           alignment (in bytes) is provided by that function, but few users
           will need to override the default of "alignof(std::max_align_t)".
---

and it looks the following another dumb patch also works around
on NetBSD/i386 9.2 (no idea which gcc version / if clang support it):
---
Index: Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/devel/protobuf/Makefile,v
retrieving revision 1.56
diff -u -p -r1.56 Makefile
--- Makefile	22 Apr 2022 10:13:33 -0000	1.56
+++ Makefile	1 Jul 2022 20:53:10 -0000
@@ -39,6 +39,10 @@ SET_LIBDIR=	yes
 # configure: error: *** A compiler with support for C++11 language features is required.
 GCC_REQD+=	4.8
 
+.if ${MACHINE_ARCH} == "i386"
+CXXFLAGS+=	-faligned-new=8
+.endif
+
 # included in third_party
 #.include "../../devel/googletest/buildlink3.mk"
 BUILDLINK_API_DEPENDS.zlib+=	zlib>=1.2.0.4

---

These results imply newer protobuf requires the "new" expression
feature for "over-aligned data" introduced in C++17 (but I'm not
a programmer so someone could explain it more properly).

---
Izumi Tsutsui


Home | Main Index | Thread Index | Old Index