1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
From 00362d12edf1b7fde723b041a4569dc659e65ad1 Mon Sep 17 00:00:00 2001
From: Jani Nurminen <jani.nurminen@windriver.com>
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 <jani.nurminen@windriver.com>
Upstream-Status: Pending
Signed-off-by: He Zhe <zhe.he@windriver.com>
---
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
|