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