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: 986179 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bdxn6H1Nz9s8T for ; Fri, 19 Oct 2018 06:13:49 +1100 (AEDT) Received: from localhost ([::1]:44033 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDDjv-00057E-FR for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 15:13:47 -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+incoming=patchwork.ozlabs.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(-) 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)