From 0ab3c5c2505dcfa684fd4a3961f24345de7e1d6f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 3 Nov 2021 13:23:59 -0700 Subject: [PATCH] QPluginLoader/ELF: fix Clang ASan builds Clang aligns the object at 32-byte boundaries even though we specifically asked for alignof(void*), so tell it not to sanitize the address of the plugin object. Tested with Clang 12 and 13. GCC seems not to be affected, even when ASan is enabled. If this doesn't work, we may need to accept reading a note that is improperly aligned. I don't think the output will be actually a correct note because the intra-note alignment will be wrong (I carefully chose the ELF note name so it would not require alignment, but that's only valid up to 8-byte alignments). Fixes: QTBUG-97941 Change-Id: Ice04365c72984d07a64dfffd16b422fe074d8a70 Reviewed-by: Andrei Golubev Reviewed-by: Lars Knoll --- src/corelib/plugin/qplugin.h | 10 +++++++++- tests/auto/corelib/plugin/qpluginloader/fakeplugin.cpp | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/corelib/plugin/qplugin.h b/src/corelib/plugin/qplugin.h index 5f4ef81bb6..35af6205cc 100644 --- a/src/corelib/plugin/qplugin.h +++ b/src/corelib/plugin/qplugin.h @@ -199,7 +199,15 @@ template class QPluginMetaDataV2 # define QT_PLUGIN_METADATAV2_SECTION using Payload = StaticPayload; #elif defined(Q_OF_ELF) -# define QT_PLUGIN_METADATAV2_SECTION __attribute__((section(".note.qt.metadata"), used, aligned(alignof(void*)))) +# ifdef Q_CC_CLANG +// the metadata section doesn't work well with clang's sanitizer - QTBUG-97941 +# define QT_PLUGIN_METADATAV2_SECTION \ + __attribute__((section(".note.qt.metadata"), used, aligned(alignof(void *)), \ + no_sanitize("address"))) +# else +# define QT_PLUGIN_METADATAV2_SECTION \ + __attribute__((section(".note.qt.metadata"), used, aligned(alignof(void *)))) +# endif using Payload = ElfNotePayload; #else # define QT_PLUGIN_METADATAV2_SECTION QT_PLUGIN_METADATA_SECTION diff --git a/tests/auto/corelib/plugin/qpluginloader/fakeplugin.cpp b/tests/auto/corelib/plugin/qpluginloader/fakeplugin.cpp index 6d758f23c9..c1b939bf3e 100644 --- a/tests/auto/corelib/plugin/qpluginloader/fakeplugin.cpp +++ b/tests/auto/corelib/plugin/qpluginloader/fakeplugin.cpp @@ -50,7 +50,9 @@ static constexpr bool IsDebug = false; #endif #if defined(__ELF__) && PLUGIN_VERSION >= 1 -__attribute__((section(".note.qt.metadata"), used, aligned(4))) +// GCC will produce: +// fakeplugin.cpp:64:3: warning: ‘no_sanitize_address’ attribute ignored [-Wattributes] +__attribute__((section(".note.qt.metadata"), used, no_sanitize("address"), aligned(sizeof(void*)))) static const struct { unsigned n_namesz = sizeof(name); unsigned n_descsz = sizeof(payload);