Built a bleeding-edge arm-gcc toolchain. It works fine but when I tried newlib built with -flto I got a crash in lto1. $ arm-none-eabi-g++ -o main.elf -Wl,--relax -mthumb -mcpu=cortex-m4 -O3 during IPA pass: icf In function '__retarget_lock_acquire_recursive': lto1: internal compiler error: Segmentation fault #0 __strchr_avx2 () at ../sysdeps/x86_64/multiarch/strchr-avx2.S:57 #1 0x00000000014de71a in strchr (__c=43, __s=0x0) at /usr/include/string.h:220 #2 arm_parse_cpu_option_name (list=0x1ab3400 <all_cores>, optname=optname@entry=0x18704ba "-mcpu", target=0x0, complain=complain@entry=true) at gcc-10-20190512/gcc/common/config/arm/arm-common.c:349 #3 0x0000000000f8545d in arm_configure_build_target (target=0x1e7b500 <arm_active_target>, opts=0x7fffff3e2a00, opts_set=0x1e81100 <global_options_set>, warn_compatible=<optimized out>) at gcc-10-20190512/gcc/config/arm/arm.c:3147 #4 0x0000000000fa5b68 in arm_set_current_function (fndecl=<optimized out>) at gcc-10-20190512/gcc/tree.h:3186 #5 0x000000000097da22 in invoke_set_current_function_hook (fndecl=0x7fffff402400) at gcc-10-20190512/gcc/function.c:4629 #6 0x0000000000984a48 in invoke_set_current_function_hook (fndecl=0x7fffff402400) at gcc-10-20190512/gcc/function.c:4788 #7 allocate_struct_function (fndecl=0x7fffff402400, abstract_p=<optimized out>) at gcc-10-20190512/gcc/function.c:4742 #8 0x0000000000afc5ed in input_function (ib_cfg=0x7ffffffed9c0, ib=0x7ffffffed9a0, data_in=0x1f8c510, fn_decl=0x7fffff402400) at gcc-10-20190512/gcc/lto-streamer-in.c:1066 #9 lto_read_body_or_constructor (file_data=0x7fffff3ec960, data=<optimized out>, node=<optimized out>, section_type=LTO_section_function_body) at gcc-10-20190512/gcc/lto-streamer-in.c:1296 #10 0x000000000083d38b in cgraph_node::get_untransformed_body (this=0x7fffff418708) at gcc-10-20190512/gcc/cgraph.c:3570 #11 0x000000000144762f in ipa_icf::sem_function::init (this=0x1f61230) at gcc-10-20190512/gcc/cgraph.h:2008 #12 0x0000000001441d12 in ipa_icf::sem_item_optimizer::parse_nonsingleton_classes (this=this@entry=0x1eca870) at gcc-10-20190512/gcc/ipa-icf.c:2776 #13 0x000000000144d730 in ipa_icf::sem_item_optimizer::execute (this=0x1eca870) at gcc-10-20190512/gcc/ipa-icf.c:2577 #14 0x000000000144e9b7 in ipa_icf::ipa_icf_driver () at gcc-10-20190512/gcc/ipa-icf.c:3698 #15 ipa_icf::pass_ipa_icf::execute (this=<optimized out>) at gcc-10-20190512/gcc/ipa-icf.c:3745 #16 0x0000000000b777ea in execute_one_pass (pass=0x1ec0940) at gcc-10-20190512/gcc/passes.c:2473 #17 0x0000000000b78517 in execute_ipa_pass_list (pass=0x1ec0940) at gcc-10-20190512/gcc/passes.c:2913 #18 0x00000000007ab461 in do_whole_program_analysis () at gcc-10-20190512/gcc/context.h:48 #19 lto_main () at gcc-10-20190512/gcc/lto/lto.c:628 #20 0x0000000000c472af in compile_file () at gcc-10-20190512/gcc/toplev.c:456 #21 0x000000000077b1e6 in do_compile () at gcc-10-20190512/gcc/toplev.c:2205 #22 toplev::main (this=this@entry=0x7ffffffedd86, argc=<optimized out>, argc@entry=24, argv=<optimized out>, argv@entry=0x7ffffffede88) at gcc-10-20190512/gcc/toplev.c:2340 #23 0x000000000077d9dc in main (argc=24, argv=0x7ffffffede88) at gcc-10-20190512/gcc/main.c:39 I'm not sure how to reduce this.
So this one must be null: https://github.com/gcc-mirror/gcc/blob/65af043/gcc/config/arm/arm.c#L3148
See also PR 87076, which has a reduced testcase and some root-cause analysis (likely a duplicate).
Possible, gcc was built with --disable-multilib --with-arch=armv7e-m --with-mode=thumb --with-float=soft. And if I replace -mcpu=cortex-m4 with -march=armv7e-m in my test command there's no crash.
The callstacks are slightly different but probably it's still a duplicate. *** This bug has been marked as a duplicate of bug 87076 ***