diff options
| author | He Zhe <zhe.he@windriver.com> | 2022-01-12 16:11:06 +0800 |
|---|---|---|
| committer | Armin Kuster <akuster808@gmail.com> | 2022-01-30 15:13:01 -0800 |
| commit | d70ce432de0cb3cd9737b0af61f92132896f06db (patch) | |
| tree | 9c4d1d1ce55a615f7b5451df3ada95f0ed76a864 | |
| parent | 6704d6d3d7549c8170d050d36ee4a3b345cf6aa6 (diff) | |
| download | meta-openembedded-d70ce432de0cb3cd9737b0af61f92132896f06db.tar.gz | |
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.
Signed-off-by: Jani Nurminen <jani.nurminen@windriver.com>
Upstream-Status: Pending
Signed-off-by: He Zhe <zhe.he@windriver.com>
Signed-off-by: Armin Kuster <akuster808@gmail.com>
| -rw-r--r-- | meta-oe/recipes-devtools/protobuf/protobuf/0001-Lower-init-prio-for-extension-attributes.patch | 81 | ||||
| -rw-r--r-- | meta-oe/recipes-devtools/protobuf/protobuf_3.15.2.bb | 1 |
2 files changed, 82 insertions, 0 deletions
diff --git a/meta-oe/recipes-devtools/protobuf/protobuf/0001-Lower-init-prio-for-extension-attributes.patch b/meta-oe/recipes-devtools/protobuf/protobuf/0001-Lower-init-prio-for-extension-attributes.patch new file mode 100644 index 0000000000..9f4fd71796 --- /dev/null +++ b/meta-oe/recipes-devtools/protobuf/protobuf/0001-Lower-init-prio-for-extension-attributes.patch | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | From 00362d12edf1b7fde723b041a4569dc659e65ad1 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Jani Nurminen <jani.nurminen@windriver.com> | ||
| 3 | Date: Fri, 24 Sep 2021 09:56:11 +0200 | ||
| 4 | Subject: Lower init prio for extension attributes | ||
| 5 | MIME-Version: 1.0 | ||
| 6 | Content-Type: text/plain; charset=UTF-8 | ||
| 7 | Content-Transfer-Encoding: 8bit | ||
| 8 | |||
| 9 | Added PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY in | ||
| 10 | code generation for extension attributes. | ||
| 11 | It has lower prio than PROTOBUF_ATTRIBUTE_INIT_PRIORITY to | ||
| 12 | ensure that extension attributes are initialized after | ||
| 13 | other attribute. | ||
| 14 | This is needed in some applications to avoid segmentation fault. | ||
| 15 | |||
| 16 | Reported by Karl-Herman Näslund. | ||
| 17 | |||
| 18 | Signed-off-by: Jani Nurminen <jani.nurminen@windriver.com> | ||
| 19 | |||
| 20 | Upstream-Status: Pending | ||
| 21 | |||
| 22 | Signed-off-by: He Zhe <zhe.he@windriver.com> | ||
| 23 | --- | ||
| 24 | src/google/protobuf/compiler/cpp/cpp_extension.cc | 2 +- | ||
| 25 | src/google/protobuf/port_def.inc | 7 +++++++ | ||
| 26 | src/google/protobuf/port_undef.inc | 1 + | ||
| 27 | 3 files changed, 9 insertions(+), 1 deletion(-) | ||
| 28 | |||
| 29 | diff --git a/src/google/protobuf/compiler/cpp/cpp_extension.cc b/src/google/protobuf/compiler/cpp/cpp_extension.cc | ||
| 30 | index 3792db81a..cbec19d30 100644 | ||
| 31 | --- a/src/google/protobuf/compiler/cpp/cpp_extension.cc | ||
| 32 | +++ b/src/google/protobuf/compiler/cpp/cpp_extension.cc | ||
| 33 | @@ -174,7 +174,7 @@ void ExtensionGenerator::GenerateDefinition(io::Printer* printer) { | ||
| 34 | } | ||
| 35 | |||
| 36 | format( | ||
| 37 | - "PROTOBUF_ATTRIBUTE_INIT_PRIORITY " | ||
| 38 | + "PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY " | ||
| 39 | "::$proto_ns$::internal::ExtensionIdentifier< $extendee$,\n" | ||
| 40 | " ::$proto_ns$::internal::$type_traits$, $field_type$, $packed$ >\n" | ||
| 41 | " $scoped_name$($constant_name$, $1$);\n", | ||
| 42 | diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc | ||
| 43 | index ae9fef425..f1d203707 100644 | ||
| 44 | --- a/src/google/protobuf/port_def.inc | ||
| 45 | +++ b/src/google/protobuf/port_def.inc | ||
| 46 | @@ -154,6 +154,9 @@ | ||
| 47 | #ifdef PROTOBUF_ATTRIBUTE_INIT_PRIORITY | ||
| 48 | #error PROTOBUF_ATTRIBUTE_INIT_PRIORITY was previously defined | ||
| 49 | #endif | ||
| 50 | +#ifdef PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY | ||
| 51 | +#error PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY was previously defined | ||
| 52 | +#endif | ||
| 53 | #ifdef PROTOBUF_PRAGMA_INIT_SEG | ||
| 54 | #error PROTOBUF_PRAGMA_INIT_SEG was previously defined | ||
| 55 | #endif | ||
| 56 | @@ -596,6 +599,10 @@ | ||
| 57 | // Highest priority is 101. We use 102 to allow code that really wants to | ||
| 58 | // higher priority to still beat us. | ||
| 59 | #define PROTOBUF_ATTRIBUTE_INIT_PRIORITY __attribute__((init_priority((102)))) | ||
| 60 | +// Some embedded systems get a segmentation fault if extension attributes are | ||
| 61 | +// initialized with higher or equal priority as other attributes. This gives | ||
| 62 | +// extension attributes high priority, but lower than other attributes. | ||
| 63 | +#define PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY __attribute__((init_priority((103)))) | ||
| 64 | #else | ||
| 65 | #define PROTOBUF_ATTRIBUTE_INIT_PRIORITY | ||
| 66 | #endif | ||
| 67 | diff --git a/src/google/protobuf/port_undef.inc b/src/google/protobuf/port_undef.inc | ||
| 68 | index daef09bc4..d0c613b55 100644 | ||
| 69 | --- a/src/google/protobuf/port_undef.inc | ||
| 70 | +++ b/src/google/protobuf/port_undef.inc | ||
| 71 | @@ -77,6 +77,7 @@ | ||
| 72 | #undef PROTOBUF_ATTRIBUTE_WEAK | ||
| 73 | #undef PROTOBUF_ATTRIBUTE_NO_DESTROY | ||
| 74 | #undef PROTOBUF_ATTRIBUTE_INIT_PRIORITY | ||
| 75 | +#undef PROTOBUF_EXTENSION_ATTRIBUTE_INIT_PRIORITY | ||
| 76 | #undef PROTOBUF_PRAGMA_INIT_SEG | ||
| 77 | |||
| 78 | // Restore macro that may have been #undef'd in port_def.inc. | ||
| 79 | -- | ||
| 80 | 2.17.1 | ||
| 81 | |||
diff --git a/meta-oe/recipes-devtools/protobuf/protobuf_3.15.2.bb b/meta-oe/recipes-devtools/protobuf/protobuf_3.15.2.bb index 62c6ee0159..ac4e1ad84b 100644 --- a/meta-oe/recipes-devtools/protobuf/protobuf_3.15.2.bb +++ b/meta-oe/recipes-devtools/protobuf/protobuf_3.15.2.bb | |||
| @@ -17,6 +17,7 @@ SRC_URI = "git://github.com/protocolbuffers/protobuf.git;branch=master;protocol= | |||
| 17 | file://0001-protobuf-fix-configure-error.patch \ | 17 | file://0001-protobuf-fix-configure-error.patch \ |
| 18 | file://0001-Makefile.am-include-descriptor.cc-when-building-libp.patch \ | 18 | file://0001-Makefile.am-include-descriptor.cc-when-building-libp.patch \ |
| 19 | file://0001-examples-Makefile-respect-CXX-LDFLAGS-variables-fix-.patch \ | 19 | file://0001-examples-Makefile-respect-CXX-LDFLAGS-variables-fix-.patch \ |
| 20 | file://0001-Lower-init-prio-for-extension-attributes.patch \ | ||
| 20 | " | 21 | " |
| 21 | S = "${WORKDIR}/git" | 22 | S = "${WORKDIR}/git" |
| 22 | 23 | ||
