disable LTO by default

Date: Fri, 28 Mar 2014 16:03:21 -0600 (MDT)
From: Joel Dice <joel.dice@gmail.com>
To: avian@googlegroups.com
Subject: Re: Building example swt for Win64

On Tue, 25 Mar 2014, Paganen So wrote:

> I posted earlier but couldn't find my post after refreshing so I am
> posting
> again...

Posts from non-members are moderated before posting to avoid spam.

> I have been trying to get swt example to work for win64.  Make produces
> the
> executable but it will force close as soon as I run.
>
> * linux32 and win32 works find.
> * tested on both win 8 x64 and win7 x64 for that problem
>
> Do you have any suggestions?

Looks like GCC is miscompiling shared libraries with -flto.  I stepped
through execution in GDB, and found that it was crashing soon after creating
an instance of x86::MyArchitecture due to an invalid vtable pointer.  The
vtable pointer is retrieved from a global table referenced relative to %rip,
but it ends up being 0x10 instead of a valid pointer.  I don't see how this
could be an Avian bug, especially considering it happens immediately after
the VM starts up (i.e. before it has a chance to do anything weird and
clobber memory, and the code segment is read-only anyway, so it couldn't
clobber that).  Disabling -flto fixes the problem.

Disabling lzma also fixes the problem because the non-lzma executable is
self-contained and does not involve a dynamic library, whereas the lzma
version consists of a bootstrap executable with an embedded LZMA-compressed
shared library which is extracted and loaded at runtime. You can also
reproduce the bug without lzma by running e.g.
"./build/windows-x86_64/avian-dynamic.exe -cp build/windows-x86_64/test
Hello".

I'm tempted to just disable use-lto by default in the Avian makefile and
avian-swt-example's app.mk.  It slows the builds down considerably without
providing a noticable speed or size improvement, plus we now have a known
issue with it on 64-bit Windows.  Anyone else have an opinion?