GRUB warning level increase
Hello, all. I have increased the warning level in GRUB. This is done for quicker discovery and correction of the bugs which would be otherwise hard to track. Mostly it enabled warnings regarding guidelines which are already followed by GRUB.
Most important one is -Wcast-align. x86 doesn't enforce any alignment but the other platforms do. And since platform-independent code is usually written and tested on x86, it's important to ensure that it's properly aligned. The invariants checked by -Wcast-align give the necessary guarantee as long as void * isn't involved. Some code is difficult to write in a way to satisfy the warning and/or is platform-specific, in this case #pragma exceptions can be done.
For imported code we can add -Wno-* to module cflags for less important (mostly stylistic) warnings.
Also if some warnings are too annoying we can drop them.
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 4 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Hello, all. I have increased the warning level in GRUB. This is done for quicker discovery and correction of the bugs which would be otherwise hard to track. Mostly it enabled warnings regarding guidelines which are already followed by GRUB.
On Debian GNU/Linux amd64 with GCC 4.6.2, I get a number of warnings triggered by -Wunsafe-loop-optimizations. The first one is:
commands/lsacpi.c: In function 'grub_cmd_lsacpi':commands/lsacpi.c:135:3: error: cannot optimize loop, the loop counter may overflow [-Werror=unsafe-loop-optimizations] commands/lsacpi.c:166:3: error: cannot optimize loop, the loop counter may overflow [-Werror=unsafe-loop-optimizations]
cc1: all warnings being treated as errors
The attached patch fixes it. The remaining ones are, afaics, either false positives or potential overflows in loops of the form:
for (i = 1; i <= foo; i++) { ... }where i and foo have the same type (e.g., int). I'm not sure how to properly fix those (declare i with a wider type? replace i by i+1 in the whole loop to make the condition become i < foo?).
Grégoire
=== modified file 'grub-core/commands/lsacpi.c'
commands/lsacpi.c +2 -2
@@ -132,7 +132,7 @@ disp_acpi_xsdt_table (struct grub_acpi_tdisp_acpi_table (t); len = t->length -sizeof (*t); desc = (grub_uint64_t *) (t +1 ); -for (; len >0 ; desc++, len -=sizeof (*desc)) +for (; len >=sizeof (*desc); desc++, len -=sizeof (*desc)) {#if GRUB_CPU_SIZEOF_VOID_P ==4 if (*desc >= (1ULL <<32 ))
@@ -163,7 +163,7 @@ disp_acpi_rsdt_table (struct grub_acpi_tdisp_acpi_table (t); len = t->length -sizeof (*t); desc = (grub_uint32_t *) (t +1 ); -for (; len >0 ; desc++, len -=sizeof (*desc)) +for (; len >=sizeof (*desc); desc++, len -=sizeof (*desc)) { t = (struct grub_acpi_table_header *) (grub_addr_t) *desc;