Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 18 Apr 2024 15:27:13 +0000
From:      Wei Hu <weh@microsoft.com>
To:        Warner Losh <imp@bsdimp.com>
Cc:        "freebsd-hackers@FreeBSD.org" <freebsd-hackers@freebsd.org>
Subject:   RE: How to add a -W flag in local Makefile
Message-ID:  <TYZP153MB039998D645FD84C28A9A057EBB0E2@TYZP153MB0399.APCP153.PROD.OUTLOOK.COM>
In-Reply-To: <CANCZdfoJD1gb1SVb9xiyUAPe8mWL1SZBB%2BtJ3ZOASMWxO6nmbg@mail.gmail.com>
References:  <TYZP153MB0399580B98D5F790C0A551C3BB0E2@TYZP153MB0399.APCP153.PROD.OUTLOOK.COM> <CANCZdfoJD1gb1SVb9xiyUAPe8mWL1SZBB%2BtJ3ZOASMWxO6nmbg@mail.gmail.com>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
I added something like:

diff --git a/sys/dev/hyperv/vmbus/vmbus_var.h b/sys/dev/hyperv/vmbus/vmbus_var.h
index b598f782947e..6e3b7b040827 100644
--- a/sys/dev/hyperv/vmbus/vmbus_var.h
+++ b/sys/dev/hyperv/vmbus/vmbus_var.h
@@ -193,4 +193,17 @@ struct hyperv_tlb_flush {
uint64_t        hv_vm_tlb_flush(pmap_t pmap, vm_offset_t addr1,
                                vm_offset_t addr2, cpuset_t mask);

+struct hv_vpset {
+       uint64_t format;
+       uint64_t valid_bank_mask;
+       uint64_t bank_contents[];
+} __packed;
+
+struct hv_tlb_flush_ex {
+       uint64_t address_space;
+       uint64_t flags;
+       struct hv_vpset hv_vp_set;
+       uint64_t gva_list[];
+} __packed;
+
#endif /* !_VMBUS_VAR_H_ */

So, the struct hv_vpset is the second last member of struct hv_tlb_flush_ex. The member bank_contents[] in struct hv_vpset is of variable length. This would makes the last two members of struct hv_tlb_flush_ex both variable length. Therefore, the flag '-Wno-gnu-variable-sized-type-not-at-end' is needed, otherwise it would complain about this with errors like:

In file included from /work/freebsd-src/sys/dev/hyperv/vmbus/vmbus.c:69:
/work/freebsd-src/sys/dev/hyperv/vmbus/vmbus_var.h:203:25: error: field 'hv_vp_set'
with variable sized type 'struct hv_vpset' not at the end of a struct or class is a
GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]
  203 |         struct hv_vpset hv_vp_set;

I did add the flag at the end of the local Makefile, after .include, like following:

diff --git a/sys/modules/hyperv/vmbus/Makefile b/sys/modules/hyperv/vmbus/Makefile
index 1659d5186493..870ff71299d0 100644
--- a/sys/modules/hyperv/vmbus/Makefile
+++ b/sys/modules/hyperv/vmbus/Makefile
@@ -42,3 +42,7 @@ CFLAGS+= -I${SRCTOP}/sys/dev/hyperv/include \
EXPORT_SYMS=   YES

.include <bsd.kmod.mk>
+
+CWARNFLAGS += -Wno-gnu-variable-sized-type-not-at-end

Thanks,
Wei


From: Warner Losh <imp@bsdimp.com>
Sent: Thursday, April 18, 2024 10:47 PM
To: Wei Hu <weh@microsoft.com>
Cc: freebsd-hackers@FreeBSD.org
Subject: Re: How to add a -W flag in local Makefile


On Thu, Apr 18, 2024, 7:04 AM Wei Hu <weh@microsoft.com<mailto:weh@microsoft.com>> wrote:
Hi,

I am trying to add a -W flag to local Makefile so it would only be effective for the local source files. But it seems not working when I build the entire kernel.

For example, I added a structure in sys/dev/hyperv/vmbus/vmbus_var.h. The structure requires adding a -W flag ( -Wno-gnu-variable-sized-type-not-at-end ) to build successfully for all .c files included this header file.


What does this type look like?

Maybe the right answer is changing it?

What I did was I add this line in sys/modules/hyperv/vmbus/Makefile:

CWARNFLAGS += -Wno-gnu-variable-sized-type-not-at-end

Where did you add it? I think it needs to be after the .includes

Warner


This seems working fine if I build the module by typing 'make' under sys/modules/hyperv/vmbus subdir. But it seems having no effect when building the kernel by using 'make buildkernel' under global directory. Those .c files still fail to build due to lacking this flag.

If I add this flag in the global sys/conf/kern.mk<http://kern.mk/>, it seems to be working. However, I don't like to add it globally as only a few source files under hyperv/vmbus need it. What did I do wrong? Do you know what the proper way to add this flag?

Thanks,
Wei


[-- Attachment #2 --]
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:等线;
	panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Aptos;}
@font-face
	{font-family:"\@等线";
	panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	font-size:12.0pt;
	font-family:"Aptos",sans-serif;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
span.EmailStyle18
	{mso-style-type:personal-reply;
	font-family:"Aptos",sans-serif;
	color:windowtext;}
span.EmailStyle19
	{mso-style-type:personal;
	font-family:"Aptos",sans-serif;
	color:windowtext;}
.MsoChpDefault
	{mso-style-type:export-only;}
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">I added something like:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">diff --git a/sys/dev/hyperv/vmbus/vmbus_var.h b/sys/dev/hyperv/vmbus/vmbus_var.h<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">index b598f782947e..6e3b7b040827 100644<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">--- a/sys/dev/hyperv/vmbus/vmbus_var.h<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">+++ b/sys/dev/hyperv/vmbus/vmbus_var.h<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">@@ -193,4 +193,17 @@ struct hyperv_tlb_flush {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">uint64_t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hv_vm_tlb_flush(pmap_t pmap, vm_offset_t addr1,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vm_offset_t addr2, cpuset_t mask);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">+struct hv_vpset {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uint64_t format;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uint64_t valid_bank_mask;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uint64_t bank_contents[];<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">+} __packed;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">+<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">+struct hv_tlb_flush_ex {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uint64_t address_space;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uint64_t flags;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; struct hv_vpset hv_vp_set;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uint64_t gva_list[];<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">+} __packed;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">+<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">#endif /* !_VMBUS_VAR_H_ */<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">So, the struct hv_vpset is the second last member of struct hv_tlb_flush_ex. The member bank_contents[] in struct hv_vpset is of variable length. This would makes the last
 two members of struct hv_tlb_flush_ex both variable length. Therefore, the flag '-Wno-gnu-variable-sized-type-not-at-end' is needed, otherwise it would complain about this with errors like:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">In file included from /work/freebsd-src/sys/dev/hyperv/vmbus/vmbus.c:69:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">/work/freebsd-src/sys/dev/hyperv/vmbus/vmbus_var.h:203:25<span style="color:red">: error: field 'hv_vp_set'
<o:p></o:p></span></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:red">with variable sized type 'struct hv_vpset' not at the end of a struct or class is a
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;color:red">GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">&nbsp; 203 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; struct hv_vpset hv_vp_set;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">I did add the flag at the end of the local Makefile, after .include, like following:
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">diff --git a/sys/modules/hyperv/vmbus/Makefile b/sys/modules/hyperv/vmbus/Makefile<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">index 1659d5186493..870ff71299d0 100644<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">--- a/sys/modules/hyperv/vmbus/Makefile<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">+++ b/sys/modules/hyperv/vmbus/Makefile<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">@@ -42,3 +42,7 @@ CFLAGS+= -I${SRCTOP}/sys/dev/hyperv/include \<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">EXPORT_SYMS=&nbsp;&nbsp; YES<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">.include &lt;bsd.kmod.mk&gt;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">+<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">+CWARNFLAGS += -Wno-gnu-variable-sized-type-not-at-end<o:p></o:p></span></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal">Wei<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"> Warner Losh &lt;imp@bsdimp.com&gt;
<br>
<b>Sent:</b> Thursday, April 18, 2024 10:47 PM<br>
<b>To:</b> Wei Hu &lt;weh@microsoft.com&gt;<br>
<b>Cc:</b> freebsd-hackers@FreeBSD.org<br>
<b>Subject:</b> Re: How to add a -W flag in local Makefile<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p>&nbsp;</o:p></p>
<div>
<div>
<p class="MsoNormal">On Thu, Apr 18, 2024, 7:04<span style="font-family:&quot;Times New Roman&quot;,serif"> </span>AM Wei Hu &lt;<a href="mailto:weh@microsoft.com">weh@microsoft.com</a>&gt; wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<p class="MsoNormal">Hi,<br>
<br>
I am trying to add a -W flag to local Makefile so it would only be effective for the local source files. But it seems not working when I build the entire kernel.<br>
<br>
For example, I added a structure in sys/dev/hyperv/vmbus/vmbus_var.h. The structure requires adding a -W flag ( -Wno-gnu-variable-sized-type-not-at-end ) to build successfully for all .c files included this header file.<o:p></o:p></p>
</blockquote>
</div>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">What does this type look like?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">Maybe the right answer is changing it?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<p class="MsoNormal">What I did was I add this line in sys/modules/hyperv/vmbus/Makefile:<br>
<br>
CWARNFLAGS += -Wno-gnu-variable-sized-type-not-at-end<o:p></o:p></p>
</blockquote>
</div>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">Where did you add it? I think it needs to be after the .includes<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">Warner&nbsp;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<p class="MsoNormal" style="margin-bottom:12.0pt">This seems working fine if I build the module by typing 'make' under sys/modules/hyperv/vmbus subdir. But it seems having no effect when building the kernel by using 'make buildkernel' under global directory.
 Those .c files still fail to build due to lacking this flag. <br>
<br>
If I add this flag in the global sys/conf/<a href="http://kern.mk/" target="_blank">kern.mk</a>, it seems to be working. However, I don't like to add it globally as only a few source files under hyperv/vmbus need it. What did I do wrong? Do you know what the
 proper way to add this flag?<br>
<br>
Thanks,<br>
Wei<br>
<br>
<o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?TYZP153MB039998D645FD84C28A9A057EBB0E2>