RE: How to add a -W flag in local Makefile

From: Wei Hu <weh_at_microsoft.com>
Date: Thu, 18 Apr 2024 15:27:13 UTC
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