Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp830967imm; Wed, 10 Oct 2018 05:08:17 -0700 (PDT) X-Google-Smtp-Source: ACcGV62mQSxG7Yx3tzWoO+agSOc4eitfM4mwo0j2tfB9/TJXWt4otZmspzVZyVe9m2ZMWNt76QTG X-Received: by 2002:a62:9b9a:: with SMTP id e26-v6mr35675423pfk.181.1539173297635; Wed, 10 Oct 2018 05:08:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539173297; cv=none; d=google.com; s=arc-20160816; b=DYF3rGoOgmOBGeIK36oG9UmmNiDtZsB3UxgSoW43DIfBiMyNVfbHck2J9NlkW7d/os sMO04f9p3Y1QRWEAkn8tw3BazHNZv2mzsgIU0q+AxI7JdFgft3cpvn6uJncyZV8RIK9V Xh1ToL0dwNg9iTivA0wK7uJSBxaKp2dFY+bpXdzqPjCyhssS8eRtxCw1iGqdmhg5bla7 SmnFzphqyPsu5YDCB+nUq895WP9xsdW+oYE6o7TQOrtrnRejz29ohDfLRkXMDDXGyOVA 5allKk/kemMfxGD7DwPkE+R6uG7winTElJSFYgYAA5pTVPj24jRfQwr1olgpXp0vQM0X svCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :organization:in-reply-to:subject:cc:to:from; bh=yq0z+yB4l/LGqs98a/NKm9UXN6OEmiyAq7qKtdZO59A=; b=Xijg9/piheD9IfiVJ6tGWy4CQYZolqKu2SPc/1fEgCGW1V7jVrgada6UPtyPY+5EAq qkzlZ6f4O16sRDm37WDPmX3zDiFZ7cnR9EFQrVMVgNdSlp5KmVNvilFfUaDIxwEVEOtb x04megnqs/LdaAMfMnQuYh33WUOdwLYlIuayu89IXgbJE+nvKUtX4NJWPfLew624Flff 98Ohnw3576RYldEY18bLF1i+EnxwuNYoy+teaSDjduJwsvvytwyZRNWHO+uceQp6+39c arDY1XzPwH+fjjQBq8y8l9/qNsFdUWTmDQFoY/lHAEvi0GBz19rBN0RIUQwtcPbZg3sG f+Hg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 31-v6si26494371plj.160.2018.10.10.05.08.02; Wed, 10 Oct 2018 05:08:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726728AbeJJT2H (ORCPT + 99 others); Wed, 10 Oct 2018 15:28:07 -0400 Received: from mga17.intel.com ([192.55.52.151]:5317 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726206AbeJJT2G (ORCPT ); Wed, 10 Oct 2018 15:28:06 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Oct 2018 05:06:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,364,1534834800"; d="scan'208";a="97942193" Received: from jnikula-mobl3.fi.intel.com (HELO localhost) ([10.237.72.61]) by fmsmga001.fm.intel.com with ESMTP; 10 Oct 2018 05:01:51 -0700 From: Jani Nikula To: Nick Desaulniers , Nathan Chancellor Cc: joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, LKML , lukas.bulwahn@gmail.com Subject: Re: [PATCH] drm/i915: Convert _print_param to a macro In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20181009171401.14980-1-natechancellor@gmail.com> Date: Wed, 10 Oct 2018 15:01:40 +0300 Message-ID: <87woqqm2mz.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 09 Oct 2018, Nick Desaulniers wrote: > On Tue, Oct 9, 2018 at 10:14 AM Nathan Chancellor > wrote: >> >> When building the kernel with Clang with defconfig and CONFIG_64BIT >> disabled, vmlinux fails to link because of the BUILD_BUG in >> _print_param. >> >> ld: drivers/gpu/drm/i915/i915_params.o: in function `i915_params_dump': >> i915_params.c:(.text+0x56): undefined reference to >> `__compiletime_assert_191' >> >> This function is semantically invalid unless the code is first inlined >> then constant folded, which doesn't work for Clang because semantic >> analysis happens before optimization/inlining. Converting this function >> to a macro avoids this problem and allows Clang to properly remove the >> BUILD_BUG during optimization. > > Thanks Nathan for the patch. To provide more context, Clang does > semantic analysis before optimization, where as GCC does these > together (IIUC). So the above link error is from the naked > BUILD_BUG(). Clang can't evaluate the __builtin_strcmp's statically > until inlining has occurred, but that optimization happens after > semantic analysis. To do the inlining before semantic analysis, we > MUST leverage the preprocessor, which runs before the compiler starts > doing semantic analysis. I suspect this code is not valid for GCC > unless optimizations are enabled (the kernel only does compile with > optimizations turned on). This change allows us to build this > translation unit with Clang. > > Acked-by: Nick Desaulniers > (Note: this is the change I suggested, so not sure whether Acked-by or > Reviewed-by is more appropriate). *Sad trombone* I'd rather see us converting more macros to static inlines than the other way round. I'll let others chime in if they have any better ideas, otherwise I'll apply this one. BR, Jani. > >> >> The output of 'objdump -D' is identically before and after this change >> for GCC regardless of if CONFIG_64BIT is set and allows Clang to link >> the kernel successfully with or without CONFIG_64BIT set. >> >> Link: https://github.com/ClangBuiltLinux/linux/issues/191 >> Suggested-by: Nick Desaulniers >> Signed-off-by: Nathan Chancellor >> --- >> drivers/gpu/drm/i915/i915_params.c | 29 +++++++++++++---------------- >> 1 file changed, 13 insertions(+), 16 deletions(-) >> >> diff --git a/drivers/gpu/drm/i915/i915_params.c b/drivers/gpu/drm/i915/i915_params.c >> index 295e981e4a39..a0f20b9b6f2d 100644 >> --- a/drivers/gpu/drm/i915/i915_params.c >> +++ b/drivers/gpu/drm/i915/i915_params.c >> @@ -174,22 +174,19 @@ i915_param_named(enable_dpcd_backlight, bool, 0600, >> i915_param_named(enable_gvt, bool, 0400, >> "Enable support for Intel GVT-g graphics virtualization host support(default:false)"); >> >> -static __always_inline void _print_param(struct drm_printer *p, >> - const char *name, >> - const char *type, >> - const void *x) >> -{ >> - if (!__builtin_strcmp(type, "bool")) >> - drm_printf(p, "i915.%s=%s\n", name, yesno(*(const bool *)x)); >> - else if (!__builtin_strcmp(type, "int")) >> - drm_printf(p, "i915.%s=%d\n", name, *(const int *)x); >> - else if (!__builtin_strcmp(type, "unsigned int")) >> - drm_printf(p, "i915.%s=%u\n", name, *(const unsigned int *)x); >> - else if (!__builtin_strcmp(type, "char *")) >> - drm_printf(p, "i915.%s=%s\n", name, *(const char **)x); >> - else >> - BUILD_BUG(); >> -} >> +#define _print_param(p, name, type, x) \ >> +do { \ >> + if (!__builtin_strcmp(type, "bool")) \ >> + drm_printf(p, "i915.%s=%s\n", name, yesno(*(const bool *)x)); \ >> + else if (!__builtin_strcmp(type, "int")) \ >> + drm_printf(p, "i915.%s=%d\n", name, *(const int *)x); \ >> + else if (!__builtin_strcmp(type, "unsigned int")) \ >> + drm_printf(p, "i915.%s=%u\n", name, *(const unsigned int *)x); \ >> + else if (!__builtin_strcmp(type, "char *")) \ >> + drm_printf(p, "i915.%s=%s\n", name, *(const char **)x); \ >> + else \ >> + BUILD_BUG(); \ >> +} while (0) >> >> /** >> * i915_params_dump - dump i915 modparams >> -- >> 2.19.0 >> -- Jani Nikula, Intel Open Source Graphics Center