The reason is that: if we add -flto option, link time optimization is invoked. And the lto need to call the function run_gcc(unsigned argc, char *argv[]) in lto-wrapper.c. The options in *argv[] are filtered by the following commands:
if(!(cl_options[option->opt_index].flags & (CL_COMMON | CL_TARGET | CL_DRIVER | CL_LTO)))
continue;
So all the options which do not belong to the CL_COMMON|CL_TARGET|CL_DRIVER|CL_LTO groups will be ignored by LTO. And -fno-short-enums is one of these options.
I think it is a bug of LTO. Because the option flag_short_enums can change the enum size in the generated object file. We should allow the users to disable this optimization as they like.
I suggest we can add the option flag_short_enums to the CL_COMMON group(or CL_LTO group, I am not sure which group is more reasonable). And I have confirmed that this change works.
I have got a command from Richard Biener on GCC Bugzilla: All ABI changing options should be also enabled for LTO and they also deserve handling in lto-opts.c (always stream, not only if explicitely set) and lto-wrapper.c (diagnose mismatches and force a setting for the link stage). At least enabling them for LTO is minimally required, like you suggest.
So I will continue to analyze all the similar options that can change ABI, and add them to the LTO group to solve this problem.
The reason is that: if we add -flto option, link time optimization is invoked. And the lto need to call the function run_gcc(unsigned argc, char *argv[]) in lto-wrapper.c. The options in *argv[] are filtered by the following commands: !(cl_options[ option- >opt_index] .flags & (CL_COMMON | CL_TARGET | CL_DRIVER | CL_LTO))) CL_TARGET| CL_DRIVER| CL_LTO groups will be ignored by LTO. And -fno-short-enums is one of these options.
if(
continue;
So all the options which do not belong to the CL_COMMON|
I think it is a bug of LTO. Because the option flag_short_enums can change the enum size in the generated object file. We should allow the users to disable this optimization as they like.
I suggest we can add the option flag_short_enums to the CL_COMMON group(or CL_LTO group, I am not sure which group is more reasonable). And I have confirmed that this change works.
I have got a command from Richard Biener on GCC Bugzilla: All ABI changing options should be also enabled for LTO and they also deserve handling in lto-opts.c (always stream, not only if explicitely set) and lto-wrapper.c (diagnose mismatches and force a setting for the link stage). At least enabling them for LTO is minimally required, like you suggest.
So I will continue to analyze all the similar options that can change ABI, and add them to the LTO group to solve this problem.
Thanks very much.