kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Randy Dunlap <rdunlap@infradead.org>
To: "Blower, Melanie" <melanie.blower@intel.com>,
	"'tglx@linutronix.de'" <tglx@linutronix.de>,
	"'mingo@redhat.com'" <mingo@redhat.com>,
	"'hpa@zytor.com'" <hpa@zytor.com>,
	"'avi@redhat.com'" <avi@redhat.com>
Cc: "'x86@kernel.org'" <x86@kernel.org>,
	"'kvm@vger.kernel.org'" <kvm@vger.kernel.org>,
	"'linux-kernel@vger.kernel.org'" <linux-kernel@vger.kernel.org>
Subject: Re: PROBLEM: compilation issue, Incorrect C usage in drivers/block/null_blk.c causes kernel compilation failure with Intel c++ compiler
Date: Wed, 13 Jan 2016 11:35:40 -0800	[thread overview]
Message-ID: <5696A70C.6080700@infradead.org> (raw)
In-Reply-To: <B3584E72CFEBED439A3ECA9BCE67A4EF40273D8A@fmsmsx116.amr.corp.intel.com>

On 01/13/16 11:22, Blower, Melanie wrote:
> [1.]  Incorrect C usage in drivers/block/null_blk.c causes kernel compilation failure with Intel c++ compiler
> [2.] Full description of the problem/report:
> Using icc,
>     drivers/block/null_blk.c(569): error: variable "null_lnvm_dev_ops" was declared with a never-completed type
>     static struct nvm_dev_ops null_lnvm_dev_ops; 
> 
> Clark Nelson, one of Intel's C++ language lawyers, explains why this declaration is illegal:
> 
>  Discussion:
>  Here is the problematic declaration, which appears near line 585 of file drivers/block/null_blk.c:
>  
>       static struct nvm_dev_ops null_lnvm_dev_ops;


or with gcc when building linux-next-20160111:

../drivers/block/null_blk.c:569:27: error: storage size of €˜'null_lnvm_dev_ops€'™ isn'€™t known
 static struct nvm_dev_ops null_lnvm_dev_ops;
                           ^


>  This clearly violates 6.9.2 paragraph 3 of the C standard:
>  
>  If the declaration of an identifier for an object is a tentative definition and has internal linkage, the declared type shall not be an  incomplete type.
>  
>  The declaration is a tentative definition because it has no  initializer, it has internal linkage because the static keyword is  used, and yet the type is definitely an incomplete type.
>  
>  In general, the problem with such a declaration is that the compiler is expected to allocate memory for it in some data section, but the  compiler is given no idea how much memory to allocate.
>  
>  As it turns out, the only way this variable is used is to take its  address and pass it to an inline function, which doesn't use the  corresponding pointer parameter at all. So after inlining and dead  code elimination, no reference to the variable survives, so it doesn't  need to be allocated after all, so it doesn't matter that the size of the allocation isn't known.
>  
>  When optimization isn't used, and the variable isn't discovered to be  unnecessary, GCC also reports an error for this declaration.
>  
>  However, it's fairly obvious that GCC wasn't carefully and  consistently designed to allow this sort of thing. If the same  declaration appears in a block scope, without the static keyword, GCC  reports an error regardless of the optimization level, even if the  variable is never referenced at all, even if the declaration appears  in a static function that is never used. The logic by which the original static declaration is accepted would suggest that the auto declaration should also be accepted, but it isn't.
>  
>  The simple fix would be to add an empty member list to the declaration:
>  
>  static struct nvm_dev_ops {} null_lnvm_dev_ops;
>  
>  That would still not conform to the C standard, which doesn't allow an empty member list. But support for an empty member list is much more  stable and predictable than support for optimizing out unused invalid  variable declarations.
> 
> 
> [3.] Keywords : kernel
> [4.] Kernel version (from /proc/version): 
>  We're building linux-4.4-rc8.tar.xz with the Intel compiler
> Here's host information where the Kernel build occurs:
> Linux version 3.10.0-229.el7.x86_64 (mockbuild@x86-035.build.eng.bos.redhat.com) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-7) (GCC) ) #1 SMP Thu Jan 29 18:37:38 EST 2015
> [5.] Output of Oops.. message (if applicable) with symbolic information 
>      resolved (see Documentation/oops-tracing.txt)
> n/a
> [6.] A small shell script or example program which triggers the
>      problem (if possible)
> Compile kernel linux-4.4-rc8.tar.xz with Intel C++ compiler for Linux version 16.0 update 1
> [7.] Environment
> I'm not going to include the environment details since they're irrelevant.
> [7.1.] Software (add the output of the ver_linux script here)
> [7.2.] Processor information (from /proc/cpuinfo):
> [7.3.] Module information (from /proc/modules):
> [7.4.] Loaded driver and hardware information (/proc/ioports, /proc/iomem)
> [7.5.] PCI information ('lspci -vvv' as root)
> [7.6.] SCSI information (from /proc/scsi/scsi)
> [7.7.] Other information that might be relevant to the problem
>        (please look in /proc and include all information that you
>        think to be relevant):
> [X.] Other notes, patches, fixes, workarounds:
> 
> Please cc: me on replies to this message. Thanks and regards, Melanie Blower (Intel C++ compiler team)
> 


-- 
~Randy

  reply	other threads:[~2016-01-13 19:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-13 19:22 PROBLEM: compilation issue, Incorrect C usage in drivers/block/null_blk.c causes kernel compilation failure with Intel c++ compiler Blower, Melanie
2016-01-13 19:35 ` Randy Dunlap [this message]
2016-01-13 19:37   ` Randy Dunlap
2016-01-13 20:01     ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5696A70C.6080700@infradead.org \
    --to=rdunlap@infradead.org \
    --cc=avi@redhat.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=melanie.blower@intel.com \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).