public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug lto/55102] New: The options -flto and -On do not behave as described in GCC docs
@ 2012-10-27 19:27 d.g.gorbachev at gmail dot com
  2012-10-29 14:39 ` [Bug lto/55102] " rguenth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: d.g.gorbachev at gmail dot com @ 2012-10-27 19:27 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55102

             Bug #: 55102
           Summary: The options -flto and -On do not behave as described
                    in GCC docs
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: lto
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: d.g.gorbachev@gmail.com


> Additionally, the optimization flags used to compile
> individual files are not necessarily related to those
> used at link time.  For instance,
>
>         gcc -c -O0 -flto foo.c
>         gcc -c -O0 -flto bar.c
>         gcc -o myprog -flto -O3 foo.o bar.o
>
> This produces individual object files with unoptimized
> assembler code, but the resulting binary myprog is
> optimized at -O3.  If, instead, the final binary is
> generated without -flto, then myprog is not optimized.

In fact, when you use -O3 when linking the .o files, it is already too late,
the resulting binary will not be fully optimized. You need to compile the .c
files with at least -O1. Thus, there is a bug either in GCC itself or in the
documentation.

====== 8< ======
int foo(void)
{
  return 0;
}

int main(void)
{
  return foo();
}
====== >8 ======

$ gcc -flto -O0 -c foo.c -o foo-O0.o
$ gcc -flto -O1 -c foo.c -o foo-O1.o
$ gcc -flto -O0 foo-O0.o -o prog-O0-O0
$ gcc -flto -O3 foo-O0.o -o prog-O0-O3
$ gcc -flto -O0 foo-O1.o -o prog-O1-O0
$ gcc -flto -O3 foo-O1.o -o prog-O1-O3
$ nm -A prog-O0-O0 prog-O0-O3 prog-O1-O0 prog-O1-O3 | grep foo
prog-O0-O0:080483f0 t foo.2337
prog-O0-O3:080483f0 t foo.2337
prog-O1-O0:080483f0 t foo.2337

GCC 4.6 gives a slight different result:

$ nm -A prog-O0-O0 prog-O0-O3 prog-O1-O0 prog-O1-O3 | grep foo
prog-O0-O0:08048381 t foo.1988
prog-O0-O3:08048380 t foo.1988

(GCC 4.5 crashes.)


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

end of thread, other threads:[~2013-03-27 13:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-27 19:27 [Bug lto/55102] New: The options -flto and -On do not behave as described in GCC docs d.g.gorbachev at gmail dot com
2012-10-29 14:39 ` [Bug lto/55102] " rguenth at gcc dot gnu.org
2013-03-26 20:51 ` ebotcazou at gcc dot gnu.org
2013-03-27 12:47 ` hubicka at gcc dot gnu.org
2013-03-27 13:09 ` rguenther at suse dot de

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).