linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Heads up: gcc miscompiling initramfs zlib decompression code at -O3
@ 2021-04-30 20:46 Vineet Gupta
  2021-04-30 22:06 ` Linus Torvalds
  2021-05-03 17:41 ` Linus Torvalds
  0 siblings, 2 replies; 8+ messages in thread
From: Vineet Gupta @ 2021-04-30 20:46 UTC (permalink / raw)
  To: Arnd Bergmann, Peter Zijlstra, Masahiro Yamada, Linus Torvalds,
	Jann Horn
  Cc: lkml, arcml, linux-arch

Hi,

I've hit a mainline gcc 10.2 (also gcc 9.3) bug which triggers at -O3 
causing wrong codegen.

  Config needs to have initramfs + gzip compressed.

	CONFIG_HAVE_KERNEL_GZIP=y
	CONFIG_KERNEL_GZIP=y
	CONFIG_DECOMPRESS_GZIP=y
	CONFIG_INITRAMFS_COMPRESSION_GZIP=y

  lib/zlib_inflate/inffast.c

     if (dist > 2) {
	unsigned short *sfrom;

	sfrom = (unsigned short *)(from);
	loops = len >> 1;
	do
	    *sout++ = *sfrom++;
              ^^^^^^    ^^^^^^^^
	while (--loops);
	out = (unsigned char *)sout;
	from = (unsigned char *)sfrom;
     }
     ...

The gist of issue is that despite use of unsigned short pointers, gcc is 
generating wider load/stores (8-byte LDD/STD on arcv2 and 16-byte on 
aarch64) causing extraneous bytes to copied into inflated gzip binaries
manifesting later as corrupted fragments in the binaries.

I've opened a gcc bug at:
   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100363

The workaround is to build lib/zlib_inflate/inffast.c with -O2, although 
I reckon not many arches build with -O3 as default. I'll be proposing an 
ARC only patch to build this file with -O2, unless people think it needs 
to be generalized.

Also problem originally seen on 5.6 kernel, although I confirm it shows 
on latest mainline as well.

Unraveling this pretty fun, gory details for those interested at:

 
https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/issues/372


Thx,
-Vineet

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-05-05 17:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-30 20:46 Heads up: gcc miscompiling initramfs zlib decompression code at -O3 Vineet Gupta
2021-04-30 22:06 ` Linus Torvalds
2021-04-30 22:44   ` Vineet Gupta
2021-04-30 22:52     ` Linus Torvalds
2021-05-01 21:03   ` Oleksandr Natalenko
2021-05-03 17:41 ` Linus Torvalds
2021-05-03 19:18   ` Vineet Gupta
2021-05-05 17:44   ` Heiko Carstens

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).