From 9543e101ac102ffd50a48136d265741398d55646 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Fri, 27 Jan 2023 15:25:50 +0900 Subject: [PATCH] GH-33701: [C++] Add support for LTO (link time optimization) build (#33847) ### Rationale for this change Some base type classes don't have hidden method implementations. It may define these classes in each translation unit. It may cause one-definition-rule violation with `-flto`. ### What changes are included in this PR? Define at least one hidden method to prevent defining these base type classes in each translation unit. ### Are these changes tested? How to reproduce: ```bash CFLAGS="-flto" CXXFLAGS="-flto" cmake ... cmake --build ... ``` This reports link errors without this change. ### Are there any user-facing changes? No. * Closes: #33701 Authored-by: Sutou Kouhei Signed-off-by: Yibo Cai --- cpp/src/arrow/type.cc | 18 ++++++++++++++++++ cpp/src/arrow/type.h | 27 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/cpp/src/arrow/type.cc b/cpp/src/arrow/type.cc index cc31735512b..2091bfbeb8c 100644 --- a/cpp/src/arrow/type.cc +++ b/cpp/src/arrow/type.cc @@ -454,6 +454,16 @@ std::string TypeHolder::ToString(const std::vector& types) { // ---------------------------------------------------------------------- +FixedWidthType::~FixedWidthType() {} + +PrimitiveCType::~PrimitiveCType() {} + +NumberType::~NumberType() {} + +IntegerType::~IntegerType() {} + +FloatingPointType::~FloatingPointType() {} + FloatingPointType::Precision HalfFloatType::precision() const { return FloatingPointType::HALF; } @@ -478,6 +488,12 @@ std::ostream& operator<<(std::ostream& os, return os; } +NestedType::~NestedType() {} + +BaseBinaryType::~BaseBinaryType() {} + +BaseListType::~BaseListType() {} + std::string ListType::ToString() const { std::stringstream s; s << "list<" << value_field()->ToString() << ">"; @@ -589,6 +605,8 @@ std::string FixedSizeBinaryType::ToString() const { return ss.str(); } +TemporalType::~TemporalType() {} + // ---------------------------------------------------------------------- // Date types diff --git a/cpp/src/arrow/type.h b/cpp/src/arrow/type.h index 05fcb3d615b..536874392c9 100644 --- a/cpp/src/arrow/type.h +++ b/cpp/src/arrow/type.h @@ -288,24 +288,36 @@ std::shared_ptr GetPhysicalType(const std::shared_ptr& type) class ARROW_EXPORT FixedWidthType : public DataType { public: using DataType::DataType; + // This is only for preventing defining this class in each + // translation unit to avoid one-definition-rule violation. + ~FixedWidthType() override; }; /// \brief Base class for all data types representing primitive values class ARROW_EXPORT PrimitiveCType : public FixedWidthType { public: using FixedWidthType::FixedWidthType; + // This is only for preventing defining this class in each + // translation unit to avoid one-definition-rule violation. + ~PrimitiveCType() override; }; /// \brief Base class for all numeric data types class ARROW_EXPORT NumberType : public PrimitiveCType { public: using PrimitiveCType::PrimitiveCType; + // This is only for preventing defining this class in each + // translation unit to avoid one-definition-rule violation. + ~NumberType() override; }; /// \brief Base class for all integral data types class ARROW_EXPORT IntegerType : public NumberType { public: using NumberType::NumberType; + // This is only for preventing defining this class in each + // translation unit to avoid one-definition-rule violation. + ~IntegerType() override; virtual bool is_signed() const = 0; }; @@ -313,6 +325,9 @@ class ARROW_EXPORT IntegerType : public NumberType { class ARROW_EXPORT FloatingPointType : public NumberType { public: using NumberType::NumberType; + // This is only for preventing defining this class in each + // translation unit to avoid one-definition-rule violation. + ~FloatingPointType() override; enum Precision { HALF, SINGLE, DOUBLE }; virtual Precision precision() const = 0; }; @@ -323,6 +338,9 @@ class ParametricType {}; class ARROW_EXPORT NestedType : public DataType, public ParametricType { public: using DataType::DataType; + // This is only for preventing defining this class in each + // translation unit to avoid one-definition-rule violation. + ~NestedType() override; }; /// \brief The combination of a field name and data type, with optional metadata @@ -650,6 +668,9 @@ class ARROW_EXPORT DoubleType class ARROW_EXPORT BaseBinaryType : public DataType { public: using DataType::DataType; + // This is only for preventing defining this class in each + // translation unit to avoid one-definition-rule violation. + ~BaseBinaryType() override; }; constexpr int64_t kBinaryMemoryLimit = std::numeric_limits::max() - 1; @@ -893,6 +914,9 @@ class ARROW_EXPORT Decimal256Type : public DecimalType { class ARROW_EXPORT BaseListType : public NestedType { public: using NestedType::NestedType; + // This is only for preventing defining this class in each + // translation unit to avoid one-definition-rule violation. + ~BaseListType() override; const std::shared_ptr& value_field() const { return children_[0]; } std::shared_ptr value_type() const { return children_[0]->type(); } @@ -1209,6 +1233,9 @@ class ARROW_EXPORT DenseUnionType : public UnionType { class ARROW_EXPORT TemporalType : public FixedWidthType { public: using FixedWidthType::FixedWidthType; + // This is only for preventing defining this class in each + // translation unit to avoid one-definition-rule violation. + ~TemporalType() override; DataTypeLayout layout() const override { return DataTypeLayout(