Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp168462imm; Tue, 9 Oct 2018 15:51:09 -0700 (PDT) X-Google-Smtp-Source: ACcGV639YRyoTw1k/GQhH1EJ8BPefJEDk6jAnMym0HYvgAQtNoqVmEGjga47X5omzAleuOqUjWY9 X-Received: by 2002:a63:9c01:: with SMTP id f1-v6mr26758161pge.156.1539125469201; Tue, 09 Oct 2018 15:51:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539125469; cv=none; d=google.com; s=arc-20160816; b=nIG2NFoemV6p1fKLyJyNaFXTzluWumib29CHnWi/BJ6c57cuU3vyGdH5EQpz92Q4u9 pe0fCR4wu6snKxn1usaW2/WJOV62mC53AZ0AvBffBaYNvS9f8UJaLnMWTTYyB1d+KRqj jhcXdlbLhMe484CLaMtlrcZvq9SUrUAu0VynnWIUgY1OfS4g64SJMdNz2KKC7XjA05n8 h6UOtHh0r4iTicj6HLojFuj7zF7oU2fXX88iFppViFHm5JbbGQ1HxBVMnsfbK6DMlWLY ovhShxh/Xl5q5T3VT+UvMvoDFx8kSmMrGS29+lS3YnFXPtTM4YZo07NZjyDIpo/TaM37 IC9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=MUFbe82C/k6S3DVjMlr3VrKKaUcbXfLekMWSnkDrvYg=; b=cItr+ab5ZLa4BmzjvX0Aq56kvzyCoudObCK8tascfhspeO5N5dhws3x4otsQhN7GJj lKLKI1MQqpUkpdAf1v/jR/lmULWIVaBNqroJISDDL7KxljopAJcugXNdgsOylRnqImhe l7CNkADnvgMdl6yqNobuFMIIbTbFTPHN6pFdmZ/gYUpBdmYatjZSRqyEV2LSWyrFbu0P wkfl0tDteKIE0/2GxkVLZZUr9OBA1jximjvKPNzhGIokMoIdZLIez/4vDjKCJ9OXMniK OA827zEs9BPMNtr6CT1qIPU2NguYhlTUd+zp4UWlooxLIY2kucGdkVZQ0vq2r9oY7Ph+ 9HzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ol3fiJnC; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b6-v6si23003511pls.349.2018.10.09.15.50.54; Tue, 09 Oct 2018 15:51:09 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=ol3fiJnC; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727500AbeJJESq (ORCPT + 99 others); Wed, 10 Oct 2018 00:18:46 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:40795 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725748AbeJJESq (ORCPT ); Wed, 10 Oct 2018 00:18:46 -0400 Received: by mail-pf1-f196.google.com with SMTP id s5-v6so1459302pfj.7 for ; Tue, 09 Oct 2018 13:59:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MUFbe82C/k6S3DVjMlr3VrKKaUcbXfLekMWSnkDrvYg=; b=ol3fiJnCiaBwiP16Pm78h7Z/J46/+URdUUJLJQOc95PeUeBafEV7cnQilGymDLxkQf 0TSBEHOEErZiDAYK5w6ktGnoX+ReAM5osbAVT/ByB5+RC2+jrzODonv2bpVychTWEnc0 bNt9MD/cZ4eJGw4QI5zhiVxmvfF6X07QB5KoVhfmibfW7bWcMidfMZdKZmhC7uA8kyx8 vGqFzPkEdHGfivnGzYjaTR+XjioEvP0fRMYQUHiHl54Ha8fdjPNEP7PSVyONEFnV2RCf +Yz5FQavU/jbvNiCUJwauxmUoJYsoYVJBpaaCpUAkr0kcmK876GVS46dw8PVbDwwhLZV Km6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MUFbe82C/k6S3DVjMlr3VrKKaUcbXfLekMWSnkDrvYg=; b=LUhsJZB6WhMbop51BIYJ6ySHAH8Ea1dufg5PE7EbPCGnw7GIgKkUueCf399PfIqOg1 U5N4yhmu0LH9pktXvQR/zvtd9oIxXQf1EmHVNJl4GzTqSlkapzWSMc+RteGlWxotXFfJ XZP33WsyGA7g2NVeQbdFqCLPhWdejWvVFL1+Qf3bbLofHTK3NkPwfC1LDycEm4HOT9YJ HcjrykMxpmy5rHxp2dRzBLHOGXXAB8f0p18lsIj/U7t6o/MJO/n4Z/0suZJWO3dDW4/V oXZK1woPJuyDNfNUwtIGkW++Fq341tOLgtbCfE6S3Q4vvWDI/ymU0PDwU/lXhZ0G7wY6 /tOA== X-Gm-Message-State: ABuFfoijJKhnk4/UIoug9+c1G/vpVox2qqTi1grGJUeQQ4YZ7/orP3mS QwUtEbx5xApeutBlGa9cC0Op0/1YxSbkU0LrRlx2HA== X-Received: by 2002:a62:8559:: with SMTP id u86-v6mr31825392pfd.32.1539118797873; Tue, 09 Oct 2018 13:59:57 -0700 (PDT) MIME-Version: 1.0 References: <20181009171401.14980-1-natechancellor@gmail.com> In-Reply-To: <20181009171401.14980-1-natechancellor@gmail.com> From: Nick Desaulniers Date: Tue, 9 Oct 2018 13:59:46 -0700 Message-ID: Subject: Re: [PATCH] drm/i915: Convert _print_param to a macro To: Nathan Chancellor Cc: jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, LKML , lukas.bulwahn@gmail.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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). > > 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 > -- Thanks, ~Nick Desaulniers