1From f6b67c71be078d5f58042882e801b9af6634e483 Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin@martin.st>
3Date: Fri, 20 Aug 2021 12:10:25 +0300
4Subject: [PATCH] tst_QPluginLoader: Simplify creating a fake pointer in
5 fakeplugin.cpp
6
7When assigning multiple variables to a specific section, both GCC
8and Clang legitimately error out if those variables wouldn't end
9up in the same section (e.g. if one of them is going to a read-only
10section while the other one is going to a read-write section).
11
12In C++, when a seemingly const variable needs dynamic initialization,
13it needs to be stored in a read-write section.
14
15Clang 13 changed internals for how some constants are materialized.
16Now, when a variable is initialized with an expression containing
17plain old fashioned casts, it is considered to be potentially
18runtime initialized (at the point when section assignment conflicts
19is evaluated). Therefore, Clang 13 errors out on fakeplugin.cpp
20with errors like:
21
22    fakeplugin.cpp:36:39: error: 'message' causes a section type conflict with 'pluginSection'
23    QT_PLUGIN_METADATA_SECTION const char message[] = "QTMETADATA";
24                                          ^
25    fakeplugin.cpp:32:40: note: declared here
26    QT_PLUGIN_METADATA_SECTION void *const pluginSection = (void*)(0xc0ffeec0ffeeL);
27                                           ^
28
29See https://bugs.llvm.org/show_bug.cgi?id=51442 for discussion
30on the matter in Clang.
31
32To simplify things, just initialize the fake pointers as regular
33uintptr_t instead, avoiding the whole matter. This produces the
34exact same contents in the section as before.
35
36For what it's worth, the actual manually constructed metadata in
37fakeplugin.cpp doesn't seem to have any effect on running the
38QPluginLoader tests on either ELF or MachO right now.
39
40Upstream-Status: Backport [https://codereview.qt-project.org/c/qt/qtbase/+/366218]
41Change-Id: Ib84a2ceb20cb8e3a1bb5132a5715538e08049616
42Pick-to: 6.2 6.1
43Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
44Signed-off-by: Khem Raj <raj.khem@gmail.com>
45---
46 tests/auto/corelib/plugin/qpluginloader/fakeplugin.cpp | 4 ++--
47 1 file changed, 2 insertions(+), 2 deletions(-)
48
49diff --git a/tests/auto/corelib/plugin/qpluginloader/fakeplugin.cpp b/tests/auto/corelib/plugin/qpluginloader/fakeplugin.cpp
50index 9e7a1f750b..a6d53f350f 100644
51--- a/tests/auto/corelib/plugin/qpluginloader/fakeplugin.cpp
52+++ b/tests/auto/corelib/plugin/qpluginloader/fakeplugin.cpp
53@@ -29,8 +29,8 @@
54 #include <QtCore/qplugin.h>
55
56 #if QT_POINTER_SIZE == 8
57-QT_PLUGIN_METADATA_SECTION void *const pluginSection = (void*)(0xc0ffeec0ffeeL);
58+QT_PLUGIN_METADATA_SECTION const uintptr_t pluginSection = 0xc0ffeec0ffeeULL;
59 #else
60-QT_PLUGIN_METADATA_SECTION void *const pluginSection = (void*)0xc0ffee;
61+QT_PLUGIN_METADATA_SECTION const uintptr_t pluginSection = 0xc0ffee;
62 #endif
63 QT_PLUGIN_METADATA_SECTION const char message[] = "QTMETADATA";
64