Skip to content

Commit a077224

Browse files
Ard BiesheuvelRussell King
authored andcommitted
ARM: 8429/1: disable GCC SRA optimization
While working on the 32-bit ARM port of UEFI, I noticed a strange corruption in the kernel log. The following snprintf() statement (in drivers/firmware/efi/efi.c:efi_md_typeattr_format()) snprintf(pos, size, "|%3s|%2s|%2s|%2s|%3s|%2s|%2s|%2s|%2s]", was producing the following output in the log: | | | | | |WB|WT|WC|UC] | | | | | |WB|WT|WC|UC] | | | | | |WB|WT|WC|UC] |RUN| | | | |WB|WT|WC|UC]* |RUN| | | | |WB|WT|WC|UC]* | | | | | |WB|WT|WC|UC] |RUN| | | | |WB|WT|WC|UC]* | | | | | |WB|WT|WC|UC] |RUN| | | | | | | |UC] |RUN| | | | | | | |UC] As it turns out, this is caused by incorrect code being emitted for the string() function in lib/vsprintf.c. The following code if (!(spec.flags & LEFT)) { while (len < spec.field_width--) { if (buf < end) *buf = ' '; ++buf; } } for (i = 0; i < len; ++i) { if (buf < end) *buf = *s; ++buf; ++s; } while (len < spec.field_width--) { if (buf < end) *buf = ' '; ++buf; } when called with len == 0, triggers an issue in the GCC SRA optimization pass (Scalar Replacement of Aggregates), which handles promotion of signed struct members incorrectly. This is a known but as yet unresolved issue. (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65932). In this particular case, it is causing the second while loop to be executed erroneously a single time, causing the additional space characters to be printed. So disable the optimization by passing -fno-ipa-sra. Cc: <[email protected]> Acked-by: Nicolas Pitre <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Russell King <[email protected]>
1 parent 3939f33 commit a077224

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

arch/arm/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ AS += -EL
5454
LD += -EL
5555
endif
5656

57+
#
58+
# The Scalar Replacement of Aggregates (SRA) optimization pass in GCC 4.9 and
59+
# later may result in code being generated that handles signed short and signed
60+
# char struct members incorrectly. So disable it.
61+
# (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65932)
62+
#
63+
KBUILD_CFLAGS += $(call cc-option,-fno-ipa-sra)
64+
5765
# This selects which instruction set is used.
5866
# Note that GCC does not numerically define an architecture version
5967
# macro, but instead defines a whole series of macros which makes

0 commit comments

Comments
 (0)