public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/61123] New: With LTO, -fno-short-enums is ignored, resulting in ABI mis-matching in linking.
@ 2014-05-09  6:10 Hale.Wang at arm dot com
  2014-05-09 11:04 ` [Bug lto/61123] " rguenth at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Hale.Wang at arm dot com @ 2014-05-09  6:10 UTC (permalink / raw)
  To: gcc-bugs

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?


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-07-29  7:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-09  6:10 [Bug c/61123] New: With LTO, -fno-short-enums is ignored, resulting in ABI mis-matching in linking Hale.Wang at arm dot com
2014-05-09 11:04 ` [Bug lto/61123] " rguenth at gcc dot gnu.org
2014-05-28  2:42 ` Hale.Wang at arm dot com
2014-05-30  4:45 ` Hale.Wang at arm dot com
2014-06-20  4:52 ` zqchen at gcc dot gnu.org
2014-06-20  6:12 ` Hale.Wang at arm dot com
2014-06-23 10:26 ` rguenth at gcc dot gnu.org
2014-07-29  7:11 ` xguo at gcc dot gnu.org

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 read-only IMAP folder(s) and NNTP newsgroup(s).