http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61123
Bug ID: 61123 Summary: With LTO, -fno-short-enums is ignored, resulting in ABI mis-matching in linking. Product: gcc Version: lto Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: Hale.Wang at arm dot com I have two trivial source files obj1.cc: int x(int y) { return y - 10; } obj2.cc: int foo(int bar) { return bar*10; } If I link them without -flto, link time optimization is not invoked, and I get an object file marked as having int-sized enums: $ arm-none-eabi-g++ -fno-short-enums -mcpu=arm946e-s obj1.cc obj2.cc -Wl,-Ur -o partial_link_result.o -nostdlib -Os $ arm-none-eabi-readelf -a partial_link_result.o | grep enum Tag_ABI_enum_size: int But if I simply add -flto to the linker invocation, the output claims that it has small enums: $ arm-none-eabi-g++ -fno-short-enums -mcpu=arm946e-s obj1.cc obj2.cc -Wl,-Ur -o partial_link_result.o -nostdlib -Os -flto $ arm-none-eabi-readelf -a partial_link_result.o | grep enum Tag_ABI_enum_size: small It sure looks to me like something removed `-fno-short-enums` from `COLLECT_GCC_OPTIONS` during the LTO step. I have reproduced the same behavior on several different gcc 4.8 distributions (Mentor's Sourcery 4.8.1, Ubuntu's 4.8.2, and now the gcc-arm-embedded 4.8.3). (The commands above are from Bobby Moretti) 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. There are several other options that are similar with flag_short_enums which may change the ABI interface. And these options may cause the similar failure in LTO. So how should we deal with these options? Should we develop a new option group which could not be ignored by LTO?