Bug 14490

Summary: gcc ICE building grub with LTO
Product: [Build System, Metadata & Runtime] OE-Core Reporter: Tony Battersby <tonyb>
Component: devtools / tool chainAssignee: Tony Battersby <tonyb>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: Medium+ CC: meta.mr.watcher, meta.watcher, randy.macleod
Version: 3.4   
Target Milestone: 3.4 M3   
Hardware: x86   
OS: x86_64   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)

Description Tony Battersby 2021-07-23 22:14:52 UTC
When building grub with Link Time Optimization enabled, gcc crashes with an internal compiler error.

Distro is current poky master (Yocto 3.4, gcc 11.1); last commit was 17aabc012743 on 2021-07-22.

local.conf:
MACHINE = "genericx86-64"
require conf/distro/include/lto.inc
DISTRO_FEATURES_append = " lto"

bitbake grub
...
| during IPA pass: inline
| lto1: internal compiler error: Segmentation fault
...
| 0x14ff7ae internal_error(char const*, ...)
| 	???:0
| 0x8a0b1e modref_tree<int>::merge(modref_tree<int>*, vec<modref_parm_map, va_heap, vl_ptr>*)
| 	???:0
| 0x897feb ipa_merge_modref_summary_after_inlining(cgraph_edge*)
| 	???:0
| 0x88a956 inline_call(cgraph_edge*, bool, vec<cgraph_edge*, va_heap, vl_ptr>*, int*, bool, bool*)
| 	???:0
| Please submit a full bug report,
| with preprocessed source if appropriate.
| Please include the complete backtrace with any bug report.
| See <https://gcc.gnu.org/bugs/> for instructions.
| lto-wrapper: fatal error: x86_64-poky-linux-gcc returned 1 exit status
| compilation terminated.
| make[3]: *** [Makefile:31565: zstd.module] Error 1
Comment 1 Tony Battersby 2021-07-26 15:47:11 UTC
I just reproduced the same problem with gcc 11.1.1 from current git outside of Yocto.  I will submit an upstream bug report.

Regarding grub, we already know that grub doesn't like being compiled with -O2:
https://bugzilla.yoctoproject.org/show_bug.cgi?id=14367
https://lists.yoctoproject.org/g/yocto/message/53321

With gcc 10.2 under Hardknott, compiling with -flto makes the /usr/lib/grub/i386-pc/*.mod files not binary reproducible:
https://bugzilla.yoctoproject.org/show_bug.cgi?id=14481

So for now a good workaround is to disable LTO for grub with the following:
LTO_pn-grub = ""

I will submit a patch for that as part of my patch set to make reproducible LTO builds.
Comment 2 Tony Battersby 2021-07-26 16:48:19 UTC
Upstream bug report:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101625
Comment 3 Tony Battersby 2021-09-15 21:42:26 UTC
Resolved by poky commit a7762efa03b9113f039c682eb066a623ca02ebb1 ("lto.inc: disable LTO for grub").