From patchwork Thu Oct 18 19:00:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 149190 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp2373464lji; Thu, 18 Oct 2018 12:15:25 -0700 (PDT) X-Google-Smtp-Source: ACcGV63B4jdMe8XGKwRdK6fKkbSCbRiRVl02Y6fo1CM5Tsfwx2j/TRXHJ4O5b4F2bAGaA38QYTRY X-Received: by 2002:a0c:f24c:: with SMTP id z12mr24189980qvl.134.1539890125190; Thu, 18 Oct 2018 12:15:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539890125; cv=none; d=google.com; s=arc-20160816; b=OHxNjQ439d75GJMrSBf7RGbuxQCvELYkm5tbYT8BDhvj//W1bD1NYaeWRzjt8nZ+2t bH/GZ747E/nsj4KPssoBr2soP3e83SK5/pFcCGuQGUROfEIOL++6zRaJ2Q2g7ZrelOTQ Da8k8HMduBGp17BkjKXBUSyeBbD23WEyE1uCmzEqIK3XV2xUvpXYiZ3LC0uMpKDTcwmD t2mHnnsBcnvH3UoVzywNUeckXrbdjT/jEJNwIo5kSiNkKYzJ5KK2H/FlIiFSxaDtv11a Pnl72rZP4w1kxzS4hJflOrMLV74RhJhEgh/zXiovRQ9BQ9VMHgcVPC8Rvvxt0W+J2Deq 7pFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from; bh=pk5e2RN48LgxWnoSphX2vAmVV146nugWF2bXS4AIGco=; b=jcmPJW0vwQUPhhKr/1MVcGlFpmrtc6Cg0sOP0wFfoTXEJg6OLiATDub/dV3QFywXPK yoOSfY34Nef/nwX+D8WvM9mQ0Fjp3Yey1gkL7wYAXup1ipDOUKb+kHSxs0VB/s4ow0a+ cTVxIm+9IdGfxTpnA6EE5PQ5fA54ewMXq9vQ22XVlj1P+c1YpfUiAIw8yQjKkPgUN4Cd 5TIQfj9RisFN/eHhZHR4t1NCyqj/Kdg66o+dYUp4kvmMlPrqFCSL6LW2BbMsFauTZmz+ hudkFtSOzG+OjYkvCOW6+nesde7F2QRdWCH64lx+7xdJL0yzaBTcAkQiRI78aQK7UvS2 4jSA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id o6-v6si1551147qtj.204.2018.10.18.12.15.24 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 18 Oct 2018 12:15:25 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:44043 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDDlU-0007vF-E8 for patch@linaro.org; Thu, 18 Oct 2018 15:15:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47907) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDDXn-0004cH-Ld for qemu-devel@nongnu.org; Thu, 18 Oct 2018 15:01:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDDXj-00010i-G9 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 15:01:15 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:40881) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDDXj-0000zH-62 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 15:01:11 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.183]) with ESMTPSA (Nemesis) id 1Mo73N-1fpicu24eB-00pdBw; Thu, 18 Oct 2018 21:00:31 +0200 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.183]) with ESMTPSA (Nemesis) id 1Mo73N-1fpicu24eB-00pdBw; Thu, 18 Oct 2018 21:00:31 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 21:00:25 +0200 Message-Id: <20181018190026.9494-2-laurent@vivier.eu> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181018190026.9494-1-laurent@vivier.eu> References: <20181018190026.9494-1-laurent@vivier.eu> X-Provags-ID: V03:K1:efUa1GbK81/9CdIOexOtgnneTW9mNTCrIybthZC1tAmkhRHoJ0e GyoTeM4GbyYYaZXGpXit9Px26dzEYYvuA2s9oa4YxlgknbLspWhqsBabTMW9Jl49MggxXXJ yPRvG3U7d9+xMpngFSfSpQh1A83TY7SCE+8fsy1dwfSpjbnoeV0ww8Rbw2hnTdWJjiPLnX7 Js6G4jKALe1Ty/pz4TkCQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:mTnHxwi4VtY=:1F8Xd93sv2ks/6UR2kTsK/ O5nNV31ACPsjwtfMwuXKY+WL0xkBIfZeMQtaTkTyYajnSC3W7LQfuPNkw4m5zJoH/qjL8+Beq k3eoaifRS0cHkd8UtegM7YXGPiDb2VF8NmXJm5iDSZBq+yfZWztvinm79+E+h4z0HFyImTegL 3IeaIJEyQRBGoHEe7xFULyIE6y/IJ1OYC7A1vdOVwFOIjNJU1DcuyManmXKY/bSq0el/AfXSD I7wrAzLWgue7xg1Z3iaq2sTQJfQcUaUrh5kXVPhwUFdLxP9pwEFvPlrZoh81MXdpGZ68778UO ZErXvp5I5wDw7judJs6pAMPL1oUMJsvbwcl7mgHA4oJqDc7ID7mVASzdn8TFxiow1bZejfpTO 1MKdmMKJwoPjkHaE0UlfixbZK1rCNEZqrXS8+i8Sva191jWAXwxpycZy1MMoEwEVkNpTQ3Wlx yJnmgSMA1wda4Szy+j0acjbdhOmOB3PjwwPxfUrqODUJAycGupc+mLEHLgBS64oPu2fykAeQl 6nrAc7R2y9dZYIUiaIVlxWw54u/570Y9yHBfyePtRvl3K1WcB19QA6ZXlsTZgnshAZ2EWUZmX ZA/ZxywIQsKcywgS856VcpC8+/GJ3zGqlaxpNLIxOu5njzjK1XFk7xCxI8FPsBI8DzeAByOwI /iYWycUlaGlAQK34vmWjniD+J3GK9ckOv8Zeij4mErlaW+Z+kb9+AGFfogSISkoPzAtE= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.17.13 Subject: [Qemu-devel] [2 1/2] linux-user: Suppress address-of-packed-member warnings in __get/put_user_e X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Riku Voipio , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell Our __get_user_e() and __put_user_e() macros cause newer versions of clang to generate false-positive -Waddress-of-packed-member warnings if they are passed the address of a member of a packed struct (see https://bugs.llvm.org/show_bug.cgi?id=39113). Suppress these using the _Pragma() operator. Unfortunately _Pragma() support in gcc is broken in some gcc versions and in some usage contexts, so we limit the pragma usage here to clang. To put in the pragmas we need to convert the macros from expressions to statements, but all the callsites effectively treat them as statements already so this is OK. Signed-off-by: Peter Maydell Reviewed-by: Laurent Vivier Reviewed-by: Richard Henderson Message-Id: <20181009161814.21257-1-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/qemu.h | 74 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 21 deletions(-) -- 2.17.2 diff --git a/linux-user/qemu.h b/linux-user/qemu.h index b4959e41c6..1beb6a2cfc 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -461,27 +461,59 @@ static inline int access_ok(int type, abi_ulong addr, abi_ulong size) These are usually used to access struct data members once the struct has been locked - usually with lock_user_struct. */ -/* Tricky points: - - Use __builtin_choose_expr to avoid type promotion from ?:, - - Invalid sizes result in a compile time error stemming from - the fact that abort has no parameters. - - It's easier to use the endian-specific unaligned load/store - functions than host-endian unaligned load/store plus tswapN. */ - -#define __put_user_e(x, hptr, e) \ - (__builtin_choose_expr(sizeof(*(hptr)) == 1, stb_p, \ - __builtin_choose_expr(sizeof(*(hptr)) == 2, stw_##e##_p, \ - __builtin_choose_expr(sizeof(*(hptr)) == 4, stl_##e##_p, \ - __builtin_choose_expr(sizeof(*(hptr)) == 8, stq_##e##_p, abort)))) \ - ((hptr), (x)), (void)0) - -#define __get_user_e(x, hptr, e) \ - ((x) = (typeof(*hptr))( \ - __builtin_choose_expr(sizeof(*(hptr)) == 1, ldub_p, \ - __builtin_choose_expr(sizeof(*(hptr)) == 2, lduw_##e##_p, \ - __builtin_choose_expr(sizeof(*(hptr)) == 4, ldl_##e##_p, \ - __builtin_choose_expr(sizeof(*(hptr)) == 8, ldq_##e##_p, abort)))) \ - (hptr)), (void)0) +/* + * Tricky points: + * - Use __builtin_choose_expr to avoid type promotion from ?:, + * - Invalid sizes result in a compile time error stemming from + * the fact that abort has no parameters. + * - It's easier to use the endian-specific unaligned load/store + * functions than host-endian unaligned load/store plus tswapN. + * - The pragmas are necessary only to silence a clang false-positive + * warning: see https://bugs.llvm.org/show_bug.cgi?id=39113 . + * - We have to disable -Wpragmas warnings to avoid a complaint about + * an unknown warning type from older compilers that don't know about + * -Waddress-of-packed-member. + * - gcc has bugs in its _Pragma() support in some versions, eg + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83256 -- so we only + * include the warning-suppression pragmas for clang + */ +#ifdef __clang__ +#define PRAGMA_DISABLE_PACKED_WARNING \ + _Pragma("GCC diagnostic push"); \ + _Pragma("GCC diagnostic ignored \"-Wpragmas\""); \ + _Pragma("GCC diagnostic ignored \"-Waddress-of-packed-member\"") + +#define PRAGMA_REENABLE_PACKED_WARNING \ + _Pragma("GCC diagnostic pop") + +#else +#define PRAGMA_DISABLE_PACKED_WARNING +#define PRAGMA_REENABLE_PACKED_WARNING +#endif + +#define __put_user_e(x, hptr, e) \ + do { \ + PRAGMA_DISABLE_PACKED_WARNING; \ + (__builtin_choose_expr(sizeof(*(hptr)) == 1, stb_p, \ + __builtin_choose_expr(sizeof(*(hptr)) == 2, stw_##e##_p, \ + __builtin_choose_expr(sizeof(*(hptr)) == 4, stl_##e##_p, \ + __builtin_choose_expr(sizeof(*(hptr)) == 8, stq_##e##_p, abort)))) \ + ((hptr), (x)), (void)0); \ + PRAGMA_REENABLE_PACKED_WARNING; \ + } while (0) + +#define __get_user_e(x, hptr, e) \ + do { \ + PRAGMA_DISABLE_PACKED_WARNING; \ + ((x) = (typeof(*hptr))( \ + __builtin_choose_expr(sizeof(*(hptr)) == 1, ldub_p, \ + __builtin_choose_expr(sizeof(*(hptr)) == 2, lduw_##e##_p, \ + __builtin_choose_expr(sizeof(*(hptr)) == 4, ldl_##e##_p, \ + __builtin_choose_expr(sizeof(*(hptr)) == 8, ldq_##e##_p, abort)))) \ + (hptr)), (void)0); \ + PRAGMA_REENABLE_PACKED_WARNING; \ + } while (0) + #ifdef TARGET_WORDS_BIGENDIAN # define __put_user(x, hptr) __put_user_e(x, hptr, be)