archive mirror
 help / color / mirror / Atom feed
From: Vineet Gupta <>
To: Arnd Bergmann <>,
	Peter Zijlstra <>,
	Masahiro Yamada <>,
	Linus Torvalds <>,
	Jann Horn <>
Cc: lkml <>,
	arcml <>,
	"" <>
Subject: Heads up: gcc miscompiling initramfs zlib decompression code at -O3
Date: Fri, 30 Apr 2021 20:46:16 +0000	[thread overview]
Message-ID: <> (raw)


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.



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

	sfrom = (unsigned short *)(from);
	loops = len >> 1;
	    *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:

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:


             reply	other threads:[~2021-04-30 20:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-30 20:46 Vineet Gupta [this message]
2021-04-30 22:06 ` Heads up: gcc miscompiling initramfs zlib decompression code at -O3 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).