Skip to contentSkip to conversation

protobuf: Fix static init fiasco on 3.15.2

PATCH In review He Zhe 1 participant 3 messages Jan 12, 2022 – Jan 19, 2022 2 messages not in the archive

lore
Share & tools
lore

He Zhe

author
#0 lore raw

PATCH 1/1 protobuf: Fix static init fiasco on 3.15.2

The protobuf 3.15.2 suffers from the C++ "Static Initialization Fiasco" issue. This patches makes the extension attributes have a higher priority than the attributes, so there's no possibility of random initialization orders.

Upstream-Status: Pending

---
 ...r-init-prio-for-extension-attributes.patch | 81 +++++++++++++++++++
 .../protobuf/protobuf_3.15.2.bb               |  1 +
 2 files changed, 82 insertions(+)
 create mode 100644 meta-oe/recipes-devtools/protobuf/protobuf/0001-Lower-init-prio-for-extension-attributes.patch
meta-oe/recipes-devtools/protobuf/protobuf/0001-Lower-init-prio-for-extension-attributes.patch new file +81 -0
new file mode 100644
index 0000000000..9f4fd71796
@@ -0,0 +1,81 @@
+From 00362d12edf1b7fde723b041a4569dc659e65ad1 Mon Sep 17 00:00:00 2001
+From: Jani Nurminen <[email protected]>
+Date: Fri, 24 Sep 2021 09:56:11 +0200
+Subject: Lower init prio for extension attributes
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Added PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY in
+code generation for extension attributes.
+It has lower prio than PROTOBUF_ATTRIBUTE_INIT_PRIORITY to
+ensure that extension attributes are initialized after
+other attribute.
+This is needed in some applications to avoid segmentation fault.
+
+Reported by Karl-Herman Näslund.
+
+Signed-off-by: Jani Nurminen <[email protected]>
+
+Upstream-Status: Pending
+
+Signed-off-by: He Zhe <[email protected]>
+---
+ src/google/protobuf/compiler/cpp/cpp_extension.cc | 2 +-
+ src/google/protobuf/port_def.inc                  | 7 +++++++
+ src/google/protobuf/port_undef.inc                | 1 +
+ 3 files changed, 9 insertions(+), 1 deletion(-)
+
+diff --git a/src/google/protobuf/compiler/cpp/cpp_extension.cc b/src/google/protobuf/compiler/cpp/cpp_extension.cc
+index 3792db81a..cbec19d30 100644
+--- a/src/google/protobuf/compiler/cpp/cpp_extension.cc
++++ b/src/google/protobuf/compiler/cpp/cpp_extension.cc
+@@ -174,7 +174,7 @@ void ExtensionGenerator::GenerateDefinition(io::Printer* printer) {
+   }
+ 
+   format(
+-      "PROTOBUF_ATTRIBUTE_INIT_PRIORITY "
++      "PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY "
+       "::$proto_ns$::internal::ExtensionIdentifier< $extendee$,\n"
+       "    ::$proto_ns$::internal::$type_traits$, $field_type$, $packed$ >\n"
+       "  $scoped_name$($constant_name$, $1$);\n",
+diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc
+index ae9fef425..f1d203707 100644
+--- a/src/google/protobuf/port_def.inc
++++ b/src/google/protobuf/port_def.inc
+@@ -154,6 +154,9 @@
+ #ifdef PROTOBUF_ATTRIBUTE_INIT_PRIORITY
+ #error PROTOBUF_ATTRIBUTE_INIT_PRIORITY was previously defined
+ #endif
++#ifdef PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY
++#error PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY was previously defined
++#endif
+ #ifdef PROTOBUF_PRAGMA_INIT_SEG
+ #error PROTOBUF_PRAGMA_INIT_SEG was previously defined
+ #endif
+@@ -596,6 +599,10 @@
+ // Highest priority is 101. We use 102 to allow code that really wants to
+ // higher priority to still beat us.
+ #define PROTOBUF_ATTRIBUTE_INIT_PRIORITY __attribute__((init_priority((102))))
++// Some embedded systems get a segmentation fault if extension attributes are
++// initialized with higher or equal priority as other attributes. This gives
++// extension attributes high priority, but lower than other attributes.
++#define PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY __attribute__((init_priority((103))))
+ #else
+ #define PROTOBUF_ATTRIBUTE_INIT_PRIORITY
+ #endif
+diff --git a/src/google/protobuf/port_undef.inc b/src/google/protobuf/port_undef.inc
+index daef09bc4..d0c613b55 100644
+--- a/src/google/protobuf/port_undef.inc
++++ b/src/google/protobuf/port_undef.inc
+@@ -77,6 +77,7 @@
+ #undef PROTOBUF_ATTRIBUTE_WEAK
+ #undef PROTOBUF_ATTRIBUTE_NO_DESTROY
+ #undef PROTOBUF_ATTRIBUTE_INIT_PRIORITY
++#undef PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY
+ #undef PROTOBUF_PRAGMA_INIT_SEG
+ 
+ // Restore macro that may have been #undef'd in port_def.inc.
+-- 
+2.17.1
+
meta-oe/recipes-devtools/protobuf/protobuf_3.15.2.bb +1 -0
index 62c6ee0159..ac4e1ad84b 100644
@@ -17,6 +17,7 @@ SRC_URI = "git://github.com/protocolbuffers/protobuf.git;branch=master;protocol=
            file://0001-protobuf-fix-configure-error.patch \
            file://0001-Makefile.am-include-descriptor.cc-when-building-libp.patch \
            file://0001-examples-Makefile-respect-CXX-LDFLAGS-variables-fix-.patch \
+           file://0001-Lower-init-prio-for-extension-attributes.patch \
 "
 S = "${WORKDIR}/git"
 
Signature · 1 line
2.17.1

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#2 lore raw
Quoted 7 lines · On 1/15/22 10:22 PM, akuster808 wrote:
Quoted 5 lines · He Zhe

The protobuf 3.15.2 suffers from the C++ "Static Initialization Fiasco" issue. This patches makes the extension attributes have a higher priority than the attributes, so there's no possibility of random initialization orders.

Quoted 5 lines
Quoted 3 lines

Upstream-Status: Pending

Since this indicates "Pending", does this issue need to be fixed in Master too?

Thanks for reminding. Just sent one for master.

Zhe

Quoted 117 lines

-armin

Quoted 115 lines
---
 ...r-init-prio-for-extension-attributes.patch | 81 +++++++++++++++++++
 .../protobuf/protobuf_3.15.2.bb               |  1 +
 2 files changed, 82 insertions(+)
 create mode 100644 meta-oe/recipes-devtools/protobuf/protobuf/0001-Lower-init-prio-for-extension-attributes.patch
meta-oe/recipes-devtools/protobuf/protobuf/0001-Lower-init-prio-for-extension-attributes.patch new file +81 -0
new file mode 100644
index 0000000000..9f4fd71796
@@ -0,0 +1,81 @@
+From 00362d12edf1b7fde723b041a4569dc659e65ad1 Mon Sep 17 00:00:00 2001
+From: Jani Nurminen <[email protected]>
+Date: Fri, 24 Sep 2021 09:56:11 +0200
+Subject: Lower init prio for extension attributes
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Added PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY in
+code generation for extension attributes.
+It has lower prio than PROTOBUF_ATTRIBUTE_INIT_PRIORITY to
+ensure that extension attributes are initialized after
+other attribute.
+This is needed in some applications to avoid segmentation fault.
+
+Reported by Karl-Herman Näslund.
+
+Signed-off-by: Jani Nurminen <[email protected]>
+
+Upstream-Status: Pending
+
+Signed-off-by: He Zhe <[email protected]>
+---
+ src/google/protobuf/compiler/cpp/cpp_extension.cc | 2 +-
+ src/google/protobuf/port_def.inc                  | 7 +++++++
+ src/google/protobuf/port_undef.inc                | 1 +
+ 3 files changed, 9 insertions(+), 1 deletion(-)
+
+diff --git a/src/google/protobuf/compiler/cpp/cpp_extension.cc b/src/google/protobuf/compiler/cpp/cpp_extension.cc
+index 3792db81a..cbec19d30 100644
+--- a/src/google/protobuf/compiler/cpp/cpp_extension.cc
++++ b/src/google/protobuf/compiler/cpp/cpp_extension.cc
+@@ -174,7 +174,7 @@ void ExtensionGenerator::GenerateDefinition(io::Printer* printer) {
+   }
+ 
+   format(
+-      "PROTOBUF_ATTRIBUTE_INIT_PRIORITY "
++      "PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY "
+       "::$proto_ns$::internal::ExtensionIdentifier< $extendee$,\n"
+       "    ::$proto_ns$::internal::$type_traits$, $field_type$, $packed$ >\n"
+       "  $scoped_name$($constant_name$, $1$);\n",
+diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc
+index ae9fef425..f1d203707 100644
+--- a/src/google/protobuf/port_def.inc
++++ b/src/google/protobuf/port_def.inc
+@@ -154,6 +154,9 @@
+ #ifdef PROTOBUF_ATTRIBUTE_INIT_PRIORITY
+ #error PROTOBUF_ATTRIBUTE_INIT_PRIORITY was previously defined
+ #endif
++#ifdef PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY
++#error PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY was previously defined
++#endif
+ #ifdef PROTOBUF_PRAGMA_INIT_SEG
+ #error PROTOBUF_PRAGMA_INIT_SEG was previously defined
+ #endif
+@@ -596,6 +599,10 @@
+ // Highest priority is 101. We use 102 to allow code that really wants to
+ // higher priority to still beat us.
+ #define PROTOBUF_ATTRIBUTE_INIT_PRIORITY __attribute__((init_priority((102))))
++// Some embedded systems get a segmentation fault if extension attributes are
++// initialized with higher or equal priority as other attributes. This gives
++// extension attributes high priority, but lower than other attributes.
++#define PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY __attribute__((init_priority((103))))
+ #else
+ #define PROTOBUF_ATTRIBUTE_INIT_PRIORITY
+ #endif
+diff --git a/src/google/protobuf/port_undef.inc b/src/google/protobuf/port_undef.inc
+index daef09bc4..d0c613b55 100644
+--- a/src/google/protobuf/port_undef.inc
++++ b/src/google/protobuf/port_undef.inc
+@@ -77,6 +77,7 @@
+ #undef PROTOBUF_ATTRIBUTE_WEAK
+ #undef PROTOBUF_ATTRIBUTE_NO_DESTROY
+ #undef PROTOBUF_ATTRIBUTE_INIT_PRIORITY
++#undef PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY
+ #undef PROTOBUF_PRAGMA_INIT_SEG
+ 
+ // Restore macro that may have been #undef'd in port_def.inc.
+-- 
+2.17.1
+
meta-oe/recipes-devtools/protobuf/protobuf_3.15.2.bb +1 -1
index 62c6ee0159..ac4e1ad84b 100644
@@ -17,6 +17,7 @@ SRC_URI = "git://github.com/protocolbuffers/protobuf.git;branch=master;protocol=
            file://0001-protobuf-fix-configure-error.patch \
            file://0001-Makefile.am-include-descriptor.cc-when-building-libp.patch \
            file://0001-examples-Makefile-respect-CXX-LDFLAGS-variables-fix-.patch \
+           file://0001-Lower-init-prio-for-extension-attributes.patch \
 "
 S = "${WORKDIR}/git"
 
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#94779): https://lists.openembedded.org/g/openembedded-devel/message/94779
Mute This Topic: https://lists.openembedded.org/mt/88369203/3616698
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#4 lore raw
Quoted 8 lines · He Zhe
Quoted 6 lines · On 1/15/22 10:22 PM, akuster808 wrote:
Quoted 5 lines · He Zhe

The protobuf 3.15.2 suffers from the C++ "Static Initialization Fiasco" issue. This patches makes the extension attributes have a higher priority than the attributes, so there's no possibility of random initialization orders.

Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

Upstream-Status: Pending

Since this indicates "Pending", does this issue need to be fixed in Master too?

Thanks for reminding. Just sent one for master.

This has been merged in master. Can it be merged in hardknott?

Thanks,
Zhe

Quoted 122 lines

Zhe

Quoted 102 lines

-armin

Quoted 101 lines
---
 ...r-init-prio-for-extension-attributes.patch | 81 +++++++++++++++++++
 .../protobuf/protobuf_3.15.2.bb               |  1 +
 2 files changed, 82 insertions(+)
 create mode 100644 meta-oe/recipes-devtools/protobuf/protobuf/0001-Lower-init-prio-for-extension-attributes.patch
meta-oe/recipes-devtools/protobuf/protobuf/0001-Lower-init-prio-for-extension-attributes.patch new file +81 -0
new file mode 100644
index 0000000000..9f4fd71796
@@ -0,0 +1,81 @@
+From 00362d12edf1b7fde723b041a4569dc659e65ad1 Mon Sep 17 00:00:00 2001
+From: Jani Nurminen <[email protected]>
+Date: Fri, 24 Sep 2021 09:56:11 +0200
+Subject: Lower init prio for extension attributes
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Added PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY in
+code generation for extension attributes.
+It has lower prio than PROTOBUF_ATTRIBUTE_INIT_PRIORITY to
+ensure that extension attributes are initialized after
+other attribute.
+This is needed in some applications to avoid segmentation fault.
+
+Reported by Karl-Herman Näslund.
+
+Signed-off-by: Jani Nurminen <[email protected]>
+
+Upstream-Status: Pending
+
+Signed-off-by: He Zhe <[email protected]>
+---
+ src/google/protobuf/compiler/cpp/cpp_extension.cc | 2 +-
+ src/google/protobuf/port_def.inc                  | 7 +++++++
+ src/google/protobuf/port_undef.inc                | 1 +
+ 3 files changed, 9 insertions(+), 1 deletion(-)
+
+diff --git a/src/google/protobuf/compiler/cpp/cpp_extension.cc b/src/google/protobuf/compiler/cpp/cpp_extension.cc
+index 3792db81a..cbec19d30 100644
+--- a/src/google/protobuf/compiler/cpp/cpp_extension.cc
++++ b/src/google/protobuf/compiler/cpp/cpp_extension.cc
+@@ -174,7 +174,7 @@ void ExtensionGenerator::GenerateDefinition(io::Printer* printer) {
+   }
+ 
+   format(
+-      "PROTOBUF_ATTRIBUTE_INIT_PRIORITY "
++      "PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY "
+       "::$proto_ns$::internal::ExtensionIdentifier< $extendee$,\n"
+       "    ::$proto_ns$::internal::$type_traits$, $field_type$, $packed$ >\n"
+       "  $scoped_name$($constant_name$, $1$);\n",
+diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc
+index ae9fef425..f1d203707 100644
+--- a/src/google/protobuf/port_def.inc
++++ b/src/google/protobuf/port_def.inc
+@@ -154,6 +154,9 @@
+ #ifdef PROTOBUF_ATTRIBUTE_INIT_PRIORITY
+ #error PROTOBUF_ATTRIBUTE_INIT_PRIORITY was previously defined
+ #endif
++#ifdef PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY
++#error PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY was previously defined
++#endif
+ #ifdef PROTOBUF_PRAGMA_INIT_SEG
+ #error PROTOBUF_PRAGMA_INIT_SEG was previously defined
+ #endif
+@@ -596,6 +599,10 @@
+ // Highest priority is 101. We use 102 to allow code that really wants to
+ // higher priority to still beat us.
+ #define PROTOBUF_ATTRIBUTE_INIT_PRIORITY __attribute__((init_priority((102))))
++// Some embedded systems get a segmentation fault if extension attributes are
++// initialized with higher or equal priority as other attributes. This gives
++// extension attributes high priority, but lower than other attributes.
++#define PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY __attribute__((init_priority((103))))
+ #else
+ #define PROTOBUF_ATTRIBUTE_INIT_PRIORITY
+ #endif
+diff --git a/src/google/protobuf/port_undef.inc b/src/google/protobuf/port_undef.inc
+index daef09bc4..d0c613b55 100644
+--- a/src/google/protobuf/port_undef.inc
++++ b/src/google/protobuf/port_undef.inc
+@@ -77,6 +77,7 @@
+ #undef PROTOBUF_ATTRIBUTE_WEAK
+ #undef PROTOBUF_ATTRIBUTE_NO_DESTROY
+ #undef PROTOBUF_ATTRIBUTE_INIT_PRIORITY
++#undef PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY
+ #undef PROTOBUF_PRAGMA_INIT_SEG
+ 
+ // Restore macro that may have been #undef'd in port_def.inc.
+-- 
+2.17.1
+
meta-oe/recipes-devtools/protobuf/protobuf_3.15.2.bb +0 -0
index 62c6ee0159..ac4e1ad84b 100644
@@ -17,6 +17,7 @@ SRC_URI = "git://github.com/protocolbuffers/protobuf.git;branch=master;protocol=
            file://0001-protobuf-fix-configure-error.patch \
            file://0001-Makefile.am-include-descriptor.cc-when-building-libp.patch \
Quoted 8 lines

meta-oe/recipes-devtools/protobuf/protobuf_3.15.2.bb SRC_URI = "git://github.com/protocolbuffers/protobuf.git;branch=master;protocol= · line 23

Quoted 8 lines
meta-oe/recipes-devtools/protobuf/protobuf_3.15.2.bb +1 -0
            file://0001-examples-Makefile-respect-CXX-LDFLAGS-variables-fix-.patch \
+           file://0001-Lower-init-prio-for-extension-attributes.patch \
 "
 S = "${WORKDIR}/git"
 

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#94894): https://lists.openembedded.org/g/openembedded-devel/message/94894
Mute This Topic: https://lists.openembedded.org/mt/88369203/3617042
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-