diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2022-04-07 12:31:13 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2022-04-11 07:15:33 +0000 |
commit | 967b5e73a5c157a0b650dd389722d4bc2cec03e5 (patch) | |
tree | f182040e8d891a82aa756b8b7fd23d41bf87456c /share | |
parent | f0800b40df8ee152d522a1cd40b7ad1a8cf03f4b (diff) | |
download | qbs-967b5e73a5c157a0b650dd389722d4bc2cec03e5.tar.gz |
Add module for providing AddressSanitizer support
Change-Id: Id34e57a59ad21961ee32da1bf93f6a55596d95aa
Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
Diffstat (limited to 'share')
-rw-r--r-- | share/qbs/module-providers/Qt/templates/core.qbs | 6 | ||||
-rw-r--r-- | share/qbs/modules/Sanitizers/address/asan.qbs | 75 |
2 files changed, 79 insertions, 2 deletions
diff --git a/share/qbs/module-providers/Qt/templates/core.qbs b/share/qbs/module-providers/Qt/templates/core.qbs index fd81930ba..50d68d3a1 100644 --- a/share/qbs/module-providers/Qt/templates/core.qbs +++ b/share/qbs/module-providers/Qt/templates/core.qbs @@ -18,6 +18,7 @@ Module { && qbs.targetPlatform === targetPlatform + "-simulator" Depends { name: "cpp" } + Depends { name: "Sanitizers.address" } Depends { name: "Qt.android_support"; condition: qbs.targetOS.contains("android") } Properties { @@ -118,6 +119,9 @@ Module { property bool lreleaseMultiplexMode: false property stringList moduleConfig: @moduleConfig@ + + Sanitizers.address.enabled: config.contains("sanitize_address") + Properties { condition: moduleConfig.contains("use_gold_linker") cpp.linkerVariant: "gold" @@ -151,8 +155,6 @@ Module { cpp.driverFlags: { var flags = []; if (qbs.toolchain.contains("gcc")) { - if (config.contains("sanitize_address")) - flags.push("-fsanitize=address"); if (config.contains("sanitize_undefined")) flags.push("-fsanitize=undefined"); if (config.contains("sanitize_thread")) diff --git a/share/qbs/modules/Sanitizers/address/asan.qbs b/share/qbs/modules/Sanitizers/address/asan.qbs new file mode 100644 index 000000000..39605ef4e --- /dev/null +++ b/share/qbs/modules/Sanitizers/address/asan.qbs @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qbs. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +import qbs.Utilities + +Module { + Depends { name: "cpp" } + + property bool enabled: true + readonly property bool _supported: qbs.toolchain.contains("gcc") + || qbs.toolchain.contains("clang-cl") + || (qbs.toolchain.contains("msvc") + && Utilities.versionCompare(cpp.compilerVersion, "19.28.29500.0") >= 0) + readonly property bool _enabled: enabled && _supported + + property string detectUseAfterReturn: "always" + PropertyOptions { + name: "detectUseAfterReturn" + description: "Whether to detect problems with stack use after return from a function" + allowedValues: ["never", "runtime", "always"] + } + + property bool detectUseAfterScope: true + + cpp.driverFlags: { + var flags = []; + if (!_enabled) + return flags; + if (qbs.toolchain.contains("msvc") && !qbs.toolchain.contains("clang-cl")) { + flags.push("/fsanitize=address"); + if (detectUseAfterReturn !== "never") + flags.push("/fsanitize-address-use-after-return"); + return flags; + } + flags.push("-fsanitize=address", "-fno-omit-frame-pointer"); + if (detectUseAfterScope) + flags.push("-fsanitize-address-use-after-scope"); + if (detectUseAfterReturn) { + if (qbs.toolchain.contains("llvm")) { + if (Utilities.versionCompare(cpp.compilerVersion, "13") >= 0) + flags.push("-fsanitize-address-use-after-return=" + detectUseAfterReturn); + } else if (detectUseAfterReturn === "never") { + flags.push("--param", "asan-use-after-return=0"); + } + } + return flags; + } +} |